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
|
---|---|---|---|---|---|---|
def merge(A, left, mid, right):
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.append(1000000001)
R.append(1000000001)
i = 0
j = 0
for k in xrange(left, right):
global cnt
cnt += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[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)
return A
n = int(raw_input())
S = map(int, raw_input().split())
cnt = 0
A = mergeSort(S, 0, n)
for i in xrange(len(A)-1):
print(A[i]),
print A[len(A) - 1]
print cnt | S = input()
ans = 0
flag = False #繰り上がりありならTrue
flag2 = False #前が5ならTrue
for k in range(len(S)):
n = int(S[-k-1])
if flag2:
if n < 5:
flag = False
else:
flag = True
if flag:
n += 1
if n == 5:
ans += 5
flag2 = True
flag = False
elif n < 5:
ans += n
flag2 = False
flag = False
else:
ans += 10-n
flag2 = False
flag = True
if flag:
ans += 1
print(ans) | 0 | null | 35,560,993,813,180 | 26 | 219 |
import math
n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
p1 = 0
p2 = 0
p3 = 0
pinf = 0
for i in range(n):
D = abs(x[i] - y[i])
p1 += D
p2 += D**2
p3 += D**3
if pinf < D:
pinf = D
p2 = math.sqrt(p2)
p3 = p3**(1/3)
print("{0:.6f}".format(p1))
print("{0:.6f}".format(p2))
print("{0:.6f}".format(p3))
print("{0:.6f}".format(pinf))
| N = int(input())
X = [int(_) for _ in input().split()]
Y = [int(_) for _ in input().split()]
def calc_dist_mink(list_x, list_y, p):
list_xy = [abs(list_x[i] - list_y[i]) for i in range(len(list_x))]
list_xy_p = [i ** p for i in list_xy]
ans = sum(list_xy_p) ** (1 / p)
return(ans)
list_ans = []
ans_1 = calc_dist_mink(X, Y, 1)
list_ans.append(ans_1)
ans_2 = calc_dist_mink(X, Y, 2)
list_ans.append(ans_2)
ans_3 = calc_dist_mink(X, Y, 3)
list_ans.append(ans_3)
ans_4 = max([abs(X[i] - Y[i]) for i in range(N)])
list_ans.append(ans_4)
for ans in list_ans:
print(f"{ans:.5f}")
| 1 | 210,638,144,928 | null | 32 | 32 |
a,b,c=map(int,input().split(" "))
print((a//b+(a%b>0))*c) | a,b,c=map(int, input().split())
#たこ焼きが余るかの場合分け
if a%b==0:
Q=a//b
#ちょうど焼ききる
else:
Q=a//b+1
#余る
print(Q*c)#回数×時間
#完了
| 1 | 4,303,870,875,630 | null | 86 | 86 |
n = int(input())
xlist = list(map(int,input().split()))
sum = 0
for i in range(n):
for j in range(i+1,n):
sum+=xlist[i]*xlist[j]
print(sum) | H = int(input())
W = int(input())
N = int(input())
ans = n = 0
while n < N:
if H<W:
n += W
H -= 1
else:
n += H
W -= 1
ans += 1
print(ans) | 0 | null | 128,547,091,514,702 | 292 | 236 |
total, max, time=map(int, input().split())
print (time*int(total/max) if total%max==0 else time*(int(total/max)+1))
| n, m, k = map(int, input().split())
#Union-Find
def find(x):
if par[x] < 0:
return x
else:
par[x] = find(par[x])
return par[x]
def unite(x, y):
p = find(x)
q = find(y)
if p == q:
return None
if p > q:
p,q = q,p
par[p] += par[q]
par[q] = p
def same(x, y):
return find(x) == find(y)
def size(x):
return -par[find(x)]
par = [-1 for i in range(n)]
l = [0] * n
for i in range(m):
a, b = map(int, input().split())
unite(a-1, b-1)
l[a-1] += 1
l[b-1] += 1
for i in range(k):
c, d = map(int, input().split())
if same(c-1, d-1):
l[c-1] += 1
l[d-1] += 1
for i in range(n):
print(size(i) - l[i] - 1, end=" ") | 0 | null | 33,157,078,346,368 | 86 | 209 |
import sys
def main():
cnt = {}
for i in range(97,123):
cnt[chr(i)] = 0
# print(cnt)
for passages in sys.stdin:
for psg in passages:
psglower = psg.lower()
for s in psglower:
if s.isalpha():
cnt[s] += 1
for i in range(97,123):
s = chr(i)
print(s, ':', cnt[s])
if __name__ == '__main__':
main()
| alphabet = 'abcdefghijklmnopqrstuvwxyz'
from collections import defaultdict
import sys
adict = defaultdict(int)
for l in sys.stdin:
for c in l.lower():
adict[c] += 1
for k in alphabet:
print('%s : %i' %(k, adict[k])) | 1 | 1,671,330,662,606 | null | 63 | 63 |
lis = list(map(int,input().split(" ")))
print(lis[0] * lis[1])
| import sys
stdin = sys.stdin
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))
def naa(N): return [na() for _ in range(N)]
def ns(): return stdin.readline().rstrip() # ignore trailing spaces
A, B = na()
print(A * B)
| 1 | 15,774,437,934,650 | null | 133 | 133 |
# -*-coding:utf-8
lineNum = int(input())
for i in range(lineNum):
line = input()
tokens = list(map(int, line.strip().split()))
tokens.sort()
a, b, c = tokens[0], tokens[1], tokens[2]
if pow(a,2)+pow(b,2) == pow(c,2):
print('YES')
else:
print('NO') | #!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline().strip()
h, w = [int(x) for x in input().split()]
g = [input() for _ in range(h)]
ans = 0
for si in range(h):
for sj in range(w):
if g[si][sj] != '#':
d = [[-1 for j in range(w)] for i in range(h)]
d[si][sj] = 0
q = [(si, sj)]
for i, j in q:
ans = max(ans, d[i][j])
for di, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
ni, nj = i + di, j + dj
if 0 <= ni < h and 0 <= nj < w and g[ni][nj] != '#' and d[ni][nj] == -1:
d[ni][nj] = d[i][j] + 1
q.append((ni, nj))
print(ans)
| 0 | null | 47,104,723,598,660 | 4 | 241 |
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))
flag = [False] * 2000
for i in range(2 ** n):
total = 0
for j in range(n):
if((i >> j) & 1):
total += A[j]
flag[total] = True
for m in M:
print('yes' if flag[m] else 'no')
| n = int(input())
a = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
value = []
for i in range(2 ** n):
ans = 0
for j in range(n): # このループが一番のポイント
if ((i >> j) & 1): # 順に右にシフトさせ最下位bitのチェックを行う
ans += a[j]
value.append(ans)
for mm in range(len(m)):
if m[mm] in value:
print("yes")
else:
print("no")
| 1 | 100,674,430,688 | null | 25 | 25 |
n,k =map(int, input().split())
h = list(map(int, input().split()))
# n = int(input())
# s = [map(int, input()) for i in range(3)]
count = 0
for i in range (0,n):
if h[i] < k:
count+=1
print(n-count)
| n = int(input())
ans = 0
music = {}
for i in range(n):
a, b = input().split()
ans += int(b)
music[a] = ans
print(ans-music[input()])
| 0 | null | 138,402,167,420,650 | 298 | 243 |
inList = input().split()
stack = []
for i in inList:
if i in ['+', '-', '*']:
b, a = stack.pop(), stack.pop()
if i == '+':
stack.append(b + a)
if i == '-':
stack.append(a - b)
if i == '*':
stack.append(b * a)
else:
stack.append(int(i))
print(stack.pop()) | # coding: UTF-8
from collections import deque
operators = {'+','*','-'}
def operate(L,R,C):
if C == '+':
return L + R
elif C == '*':
return L * R
else: #<=>if C == '-'
return L - R
raw = input().split()
stack = deque()
for C in raw:
if C in operators:
R = stack.pop()
L = stack.pop()
stack.append(operate(L,R,C))
else:
stack.append(int(C))
print(stack.pop())
| 1 | 35,991,791,832 | null | 18 | 18 |
X = int(input())
year = 0
deposit = 100
while deposit < X:
deposit += int(str(deposit)[0: -2])
year += 1
print(year) | def input_list():
return list(map(int, input().split()))
def main():
s = list(input())
k = int(input())
if len(set(s)) == 1:
print(int(len(s)*(k/2)))
exit()
sw = [s[0]]
num = 0
numbers = [num]
for i in range(1, len(s)):
if s[i-1] != s[i]:
num += 1
numbers.append(num)
if num == 0 and sw[0] == s[i]:
sw.append(s[i])
num = 0
end_w = s[-1]
ew = []
for i in range(len(s)-1, -1, -1):
if end_w != s[i]:
num += 1
if num == 0 and end_w == s[i]:
ew.append(s[i])
nc = collections.Counter(numbers)
a = 0
for n,c in nc.items():
if c == 1:
continue
if c % 2 == 0:
a += c // 2
else:
a += (c-1)//2
ans = a * k
b = 0
if ew[0] == sw[0]:
haji = len(sw) + len(ew)
if haji % 2 == 0:
print(a * k + (k-1))
exit()
print(ans - b)
import math
import fractions
import collections
import itertools
from functools import reduce
main() | 0 | null | 100,692,876,740,000 | 159 | 296 |
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])) | from collections import defaultdict
def dfs(edges, n, d, f, time):
if n in d:
return
time[0] += 1
d[n] = time[0]
for to in edges[n]:
dfs(edges, to, d, f, time)
time[0] += 1
f[n] = time[0]
N = int(input())
edges = defaultdict(list)
for _ in range(N):
l = list(map(int, input().split()))
fr = l[0]
degree = l[1]
edges[fr] = l[2:]
d = {} # discover time
f = {} # finish time
time = [0]
for n in range(1, N+1):
dfs(edges, n, d, f, time)
for n in range(1, N+1):
print('%d %d %d' % (n, d[n], f[n]))
| 1 | 2,744,381,760 | null | 8 | 8 |
Ds = ['SUN','MON','TUE','WED','THU','FRI','SAT']
Ss = input().rstrip()
ans = 7 - Ds.index(Ss)
print(ans)
| print(['SUN','MON','TUE','WED','THU','FRI','SAT'][::-1].index(input())+1) | 1 | 132,535,745,378,862 | null | 270 | 270 |
list1 = range(1,10)
list2 = list1
for i in list1 :
for j in list2 :
print str(i) + "x" + str(j) + "=" + str(i*j) | for a in range(1,10):
for b in range(1,10):
print(str(a)+"x"+str(b)+"="+str(a*b))
| 1 | 2,571,492 | null | 1 | 1 |
in_sec = int(raw_input())
sec = in_sec%60
in_sec = (in_sec-sec)/60
min = in_sec%60
h = (in_sec-min)/60
print str(h) + ":" + str(min) + ":" + str(sec) | S = int(input())
s = (S % 60)
m = (S % 3600 // 60)
h = (S // 3600)
print(h, ':', m, ':', s, sep='')
| 1 | 324,385,021,558 | null | 37 | 37 |
i = 1
while True:
factor = input()
if factor == '0':
break
print('Case ', i, ': ', factor, sep='')
i += 1
| c = 1
while True:
a = int(raw_input())
if a == 0:
break
print "Case %d: %d" % (c,a)
c = c + 1 | 1 | 494,758,375,290 | null | 42 | 42 |
n1 = int(input())
nums1 = list(map(int, input().split()))
n2 = int(input())
nums2 = list(map(int, input().split()))
def linear_search(nums1, n1, key):
nums1[n1] = key
index = 0
while nums1[index] != key:
index += 1
return index != n1
output = 0
nums1.append(None)
for key in nums2:
if linear_search(nums1, n1, key):
output += 1
print(output)
| n =int(input())
S = list(map(int, input().split(' ')))
q = int(input())
T = list(map(int, input().split(' ')))
count = 0
for t in T:
if t in S:
count += 1
print(count)
| 1 | 67,016,242,650 | null | 22 | 22 |
n = int(input())
s = input()
sl = list(s)
answer = ""
for i in s:
t = ord(i)+n
if t <= 90:
answer += chr(t)
else :
answer += chr(ord("A") + abs(t-90)-1)
print(answer) | t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if a[0]>b[0]:
a,b=b,a
p=t[0]*(a[0]-b[0])
q=t[1]*(a[1]-b[1])
if p+q==0:
print('infinity')
elif p+q<0:
print(0)
else:
k=-p//(p+q)
if -p%(p+q)==0:
print(2*k)
else:
print(2*k+1)
| 0 | null | 133,191,666,768,252 | 271 | 269 |
def check(n,k):
r=[]
while n>0:
r.append(n%k)
n//=k
return len(r)
n,k=map(int,input().split())
print(check(n,k)) | from calendar import day_name
s = input()
for i in range(7):
if s == day_name[i][:3].upper():
ans = 6 - i
if ans == 0: ans += 7
print(ans)
break
| 0 | null | 98,540,971,295,780 | 212 | 270 |
n = int(input())
array = [input().split() for i in range(n)]
S = []
H = []
C = []
D = []
for i in range(1,14):
S.append(i)
H.append(i)
C.append(i)
D.append(i)
for i in range(n):
if array[i][0] == "S":
S[int(array[i][1])-1]=" "
elif array[i][0] == "H":
H[int(array[i][1])-1]=" "
elif array[i][0] == "C":
C[int(array[i][1])-1]=" "
else:
D[int(array[i][1])-1]=" "
for i in range(13):
if S[i] != " ":
print("S "+str(S[i]))
for i in range(13):
if H[i] != " ":
print("H "+str(H[i]))
for i in range(13):
if C[i] != " ":
print("C "+str(C[i]))
for i in range(13):
if D[i] != " ":
print("D "+str(D[i])) | cards = list()
pattern = ["S", "H", "C","D"]
n = int(input())
for i in range(n) :
s, r = input().split() #文字列として読み込み
r = int(r) #sは文字列、rは数値
if(s == "S") :
cards.append(0 + r)
elif(s == "H") :
cards.append(13 + r)
elif(s == "C") :
cards.append(26 + r)
else :
cards.append(39 + r)
for i in range(1, 53) :
if not(i in cards) :
print(pattern[(i - 1) // 13], (i - 1) % 13 + 1)
| 1 | 1,023,238,014,528 | null | 54 | 54 |
n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
for i in range(n-k):
if a[i]<a[i+k]:
print("Yes")
else:
print("No") | d = {chr(i):i-96 for i in range(97,123)}
D = {val:key for key,val in d.items()}
N = int(input())
x = ""
while N>0:
a = N%26
if a!=0:
x += D[a]
N = N//26
else:
x += "z"
N = N//26
N -= 1
print(x[::-1]) | 0 | null | 9,597,482,840,592 | 102 | 121 |
import sys
counter = {k: 0 for k in "abcdefghijklmnopqrstuvwxyz"}
while True:
try:
line = raw_input()
except:
break
for i in line.lower():
if i in counter.keys():
counter[i] += 1
for k in sorted(counter.keys()):
print "{} : {}".format(k,counter[k]) | s, w = [int(i) for i in input().split()]
ans = 'safe' if s > w else 'unsafe'
print(ans) | 0 | null | 15,291,138,989,152 | 63 | 163 |
from collections import deque
deq = deque()
n = int(input())
for _ in range(n):
operation = input()
if operation == "deleteFirst":
deq.popleft()
elif operation == "deleteLast":
deq.pop()
else:
command, value = operation.split()
if command == "insert":
deq.appendleft(int(value))
elif command == "delete":
try:
deq.remove(int(value))
except ValueError:
pass
print(*deq)
| a, b = map(int, input().split())
print('a ', end='')
if a < b:
print('<', end='')
elif a > b:
print('>', end='')
elif a == b:
print('==', end='')
print(' b') | 0 | null | 203,572,234,206 | 20 | 38 |
N,M = map(int,input().split())
if N%2==1:
for i in range(M):
print(str(i+1) + " " + str(N-(i+1)))
else:
flag = False
l = 1
r = N-1
cnt = 0
while cnt < M and l < r:
if not flag and r-l <= N//2:
r -= 1
flag = True
print(str(l) + " " + str(r))
l += 1
r -= 1
cnt += 1 |
import sys
MOD = 998244353
def main():
input = sys.stdin.buffer.readline
n, s = map(int, input().split())
a = list(map(int, input().split()))
dp = [[None] * (s + 1) for _ in range(n + 1)]
# dp[i][j]:=集合{1..i}の空でない部分集合T全てについて,和がjとなる部分集合の個数の和
for i in range(n + 1):
for j in range(s + 1):
if i == 0 or j == 0:
dp[i][j] = 0
continue
if j > a[i - 1]:
dp[i][j] = dp[i - 1][j] * 2 + dp[i - 1][j - a[i - 1]]
elif j == a[i - 1]:
dp[i][j] = dp[i - 1][j] * 2 + pow(2, i - 1, MOD)
else:
dp[i][j] = dp[i - 1][j] * 2
dp[i][j] %= MOD
print(dp[n][s])
if __name__ == '__main__':
main()
| 0 | null | 22,997,058,758,788 | 162 | 138 |
a, b, c, k = map(int, input().split())
if k <= a:
print(k)
if a < k <= a+b:
print(a)
if a+b < k <= a+b+c:
print(a+(-1)*(k-a-b))
| def main():
a,b,c,k = list(map(int,input().split()))
if k<=a:
print(k)
elif k<=a+b:
print(a)
elif k < a+b+c:
print(a-(k-(a+b)))
else:
print(a-c)
main() | 1 | 21,678,758,060,868 | null | 148 | 148 |
arr = map(int, raw_input().split())
arr.sort()
str_arr = map(str,arr)
print(" ".join(str_arr)) | from sys import exit
for i in input():
if i == '7':
print('Yes')
exit()
print('No')
| 0 | null | 17,459,781,282,400 | 40 | 172 |
def resolve():
s, t = input().split()
a, b = list(map(int, input().split()))
u = input()
if u == s:
a -= 1
elif u == t:
b -= 1
print(a, b)
resolve() | N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
At = [0]*(N+1)
Bt = [0]*(M+1)
for i in range(N):
At[i+1] = At[i] + A[i]
for i in range(M):
Bt[i+1] = Bt[i] + B[i]
j = M
ans = 0
for i in range(N+1):
if At[i] > K:
break
while At[i] + Bt[j] > K:
j = j - 1
if ans < i + j:
ans = i+j
print(ans) | 0 | null | 41,216,388,078,368 | 220 | 117 |
#coing:utf-8
def distance(a,b):
dst = pow(a,2) + pow(b,2)
return dst
def isTriangle(lines):
idxList = [[0,1,2],[1,0,2],[2,0,1]]
flag = False
for i in idxList:
if not flag and pow(lines[i[0]],2) == distance(lines[i[1]], lines[i[2]]):
flag = True
return flag
if __name__ == '__main__':
num = int(input())
results = []
for i in range(num):
lines = [int(item) for item in input().split(" ")]
results.append(isTriangle(lines))
for r in results:
if r:
print("YES")
else :
print("NO") |
def check(a, b, c):
a2 = a ** 2
b2 = b ** 2
c2 = c ** 2
if (a2 + b2) == c2:
return True
else:
return False
n = int(input())
for c in range(n):
line = input()
datas = map(int, line.split())
li = list(datas)
a = li[0]
b = li[1]
c = li[2]
if check(a, b, c) or check(b, c, a) or check(c, a, b):
print("YES")
else:
print("NO") | 1 | 298,618,450 | null | 4 | 4 |
Ia = input().split()
n = int(Ia[0])
m = int(Ia[1])
a = [[0 for midx in range(m)] for nidx in range(n)]
for nidx in range(n):
A = input().split()
for midx in range(m):
a[nidx][midx] = int(A[midx])
b = m * [0]
for bidx in range(m):
b[bidx] = int(input())
c = n * [0]
for i in range(n):
for j in range(m):
c[i] += a[i][j] * b[j]
for i in range(n):
print(c[i]) | n,m = map(int, raw_input().split())
A = []
B = []
for i in range(n):
A.append(map(int, raw_input().split()))
for i in range(m):
B.append(input())
for i in range(n):
answer = 0
for j in range(m):
answer += A[i][j] * B[j]
print answer | 1 | 1,184,792,251,368 | null | 56 | 56 |
n, m = map(int, input().split(" "))
if n <= 9:
print(m + (100 * (10 - n)))
else:
print(m) | def main():
n,r = map(int, input().split())
if n < 10:
print(r + 100*(10 - n))
else:
print(r)
return
main()
| 1 | 63,445,171,727,040 | null | 211 | 211 |
data = list(map(int, list(input().split())))
row = data[0]
column = data[1]
matrix = [[0 for i in range(column)] for j in range(row)]
vector = [[0] for k in range(column)]
vector_multi = [[0] for l in range(row)]
for i in range(row):
data_row = list(map(int, list(input().split())))
for j in range(column):
matrix[i][j] = data_row[j]
for i in range(column):
vector[i] = int(input())
for i in range(row):
element = 0
for j in range(column):
element += matrix[i][j] * vector[j]
vector_multi[i][0] = element
for i in vector_multi:
print(i[0])
| G = []
cnt = 0
def insertionSort(A, n, g):
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
global cnt
cnt += 1
A[j+g] = A[j]
j -= g
A[j+g] = v
def shellSort(n, A):
m = 1
while m <= n / 9:
m = m * 3 + 1
while 0 < m:
global G
G.append(m)
insertionSort(A, n, m)
m = int(m / 3)
A = []
n = int(input())
for i in range(n):
A.append(int(input()))
shellSort(n, A)
print(len(G))
print(*G)
print(cnt)
for i in range(n):
print(A[i])
| 0 | null | 612,332,000,376 | 56 | 17 |
s = input()
n = len(s)
cnt = 0
i = 0
j = -1
d = 0
while d != n//2:
if s[i] != s[j]:
cnt += 1
i+=1
j-=1
d+=1
print(cnt) | from itertools import combinations
N = int(input())
L = list(map(int, input().split()))
count = 0
for C in combinations(L, 3):
l_list = list(C)
l_list.sort()
if l_list[2] > l_list[1] and l_list[1] > l_list[0]:
if l_list[2] < l_list[1] + l_list[0]:
count += 1
print(count) | 0 | null | 62,865,402,707,480 | 261 | 91 |
x, n = map(int, input().split())
p = list(map(int,input().split()))
if x not in p:
y = x
else:
i = 1
y = x
while y == x:
if x - i not in p:
y = x - i
elif x + i not in p:
y = x + i
i += 1
print(y) | x,n=[int(x) for x in input().split()]
if n!=0:
p=[int(x) for x in input().split()]
l=list(range(110))
for i in p:
l.remove(i)
L=[]
for i in l:
L.append(abs(i-x))
m=min(L)
print(l[L.index(m)])
else:
print(x) | 1 | 14,150,259,857,510 | null | 128 | 128 |
a=[0]*26
w='abcdefghijklmnopqrstuvwxyz'
try:
while True:
s=list(input().upper())
for i in s:
if i=='A':
a[0]+=1
elif i=='B':
a[1]+=1
elif i=='C':
a[2]+=1
elif i=='D':
a[3]+=1
elif i=='E':
a[4]+=1
elif i=='F':
a[5]+=1
elif i=='G':
a[6]+=1
elif i=='H':
a[7]+=1
elif i=='I':
a[8]+=1
elif i=='J':
a[9]+=1
elif i=='K':
a[10]+=1
elif i=='L':
a[11]+=1
elif i=='M':
a[12]+=1
elif i=='N':
a[13]+=1
elif i=='O':
a[14]+=1
elif i=='P':
a[15]+=1
elif i=='Q':
a[16]+=1
elif i=='R':
a[17]+=1
elif i=='S':
a[18]+=1
elif i=='T':
a[19]+=1
elif i=='U':
a[20]+=1
elif i=='V':
a[21]+=1
elif i=='W':
a[22]+=1
elif i=='X':
a[23]+=1
elif i=='Y':
a[24]+=1
elif i=='Z':
a[25]+=1
except EOFError:
pass
for i in range(26):
print(w[i:i+1], ':', str(a[i])) | # import itertools
# import math
# import sys
import numpy as np
# N = int(input())
# S = input()
# n, *a = map(int, open(0))
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# S = input()
# d = sorted(d.items(), key=lambda x:x[0]) # keyでsort
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement([i for i in range(1, M + 1)], N))
# print(a[0][0])
# print(conditions[0])
A = np.array(A)
B = np.array(B)
cum_A = np.cumsum(A)
cum_A = np.insert(cum_A, 0, 0)
cum_B = np.cumsum(B)
cum_B = np.insert(cum_B, 0, 0)
j = M
max_num = 0
for i in range(N + 1):
while(True):
# j -= 1
if j < 0:
break
minute = cum_A[i] + cum_B[j]
if minute <= K:
if i + j > max_num:
max_num = i + j
break
j -= 1
print(max_num) | 0 | null | 6,261,192,657,720 | 63 | 117 |
import time
def sum_A(A, n):
dic = {}
#A_ = A
#n_ = n
def solve(i, m):
if (i, m) in dic:
return dic[(i, m)]
if m == 0:
dic[(i, m)] = True
elif i >= n:
dic[(i, m)] = False
elif solve(i+1, m):
dic[(i, m)] = True
elif solve(i+1, m-A[i]):
dic[(i, m)] = True
else:
dic[(i, m)] = False
return dic[(i, m)]
return solve
if __name__ == '__main__':
n = int(raw_input())
A = map(int, raw_input().split())
q = int(raw_input())
m = map(int, raw_input().split())
#A = sorted(A)
start = time.time()
solve = sum_A(A, n)
for m_i in m:
print "yes" if solve(0, m_i) else "no"
end = time.time()
#print end - start | #!/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 | 103,832,125,650 | null | 25 | 25 |
while True:
x, y = map(int, input().split())
if x == 0 and y == 0:
break
else:
a = [x, y]
a.sort()
print(a[0], a[1]) | import sys
a,b,c = map(int, sys.stdin.readline().rstrip().split(' '))
print('Yes' if (a<b<c) else 'No') | 0 | null | 454,999,630,176 | 43 | 39 |
n = int(input())
s, t = map(str, input().split())
new_word_list = []
for i in range(n):
new_word_list.append(s[i])
new_word_list.append(t[i])
print(''.join(new_word_list))
| #!/usr/bin/env python3
def solve(S: int, W: int):
if W >= S:
return "unsafe"
return "safe"
def main():
S, W = map(int, input().split())
answer = solve(S, W)
print(answer)
if __name__ == "__main__":
main()
| 0 | null | 70,404,589,300,342 | 255 | 163 |
S = input()
if S == 'MON':
print("6")
elif S == 'TUE':
print("5")
elif S == 'WED':
print("4")
elif S == 'THU':
print("3")
elif S == 'FRI':
print("2")
elif S == 'SAT':
print("1")
elif S == 'SUN':
print("7")
| a, b = map(int, input().split())
if b * 2 >= a:
print('0')
else:
print(a - b * 2) | 0 | null | 149,768,077,853,852 | 270 | 291 |
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
a,b = LI()
a_b = str(a)*b
b_a = str(b)*a
print(sorted([a_b,b_a])[0])
main()
| N = int(input())
for i in range(N):
triangle = sorted([int(n) for n in input().split()])
if triangle[0]**2 + triangle[1]**2 == triangle[2]**2:
print('YES')
else:
print('NO')
| 0 | null | 42,362,646,416,310 | 232 | 4 |
n = int(input())
print(int(sum([k*(n//k+1)*(n//k)/2 for k in range(1,n+1)]))) | N = int(input())
As = list(map(int, input().split()))
Q = int(input())
sumAs = 0
dictAs = [0] * 100000
for i in range(len(As)):
sumAs += As[i]
dictAs[As[i] - 1] += 1
for _ in range(Q):
b, c = map(int, input().split())
sumAs += dictAs[b - 1] * (c - b)
dictAs[c - 1] += dictAs[b - 1]
dictAs[b - 1] = 0
print(sumAs) | 0 | null | 11,596,912,668,542 | 118 | 122 |
import sys
def main():
input = sys.stdin.buffer.readline
n, k = map(int, input().split())
i = 1
while k ** i <= n:
i += 1
print(i)
if __name__ == "__main__":
main()
| n,k = map(int, input().split())
ans = 0
while n > 0:
n /= k
n = int(n)
ans += 1
print(ans)
| 1 | 64,278,493,761,972 | null | 212 | 212 |
n = input()
for i in range(n):
s = map(int, raw_input().split())
s.sort()
if s[2]**2 == (s[0]**2) + (s[1]**2): print "YES"
else: print "NO" | import sys
input()
for e in sys.stdin:
a,b,c=sorted(map(int,e.split()))
print(['NO','YES'][a*a+b*b==c*c])
| 1 | 274,899,180 | null | 4 | 4 |
a,b = map(int,input().split())
print("%d %d %.10f"%(a/b,a%b,a/b))
| a, b = map(int, input().split())
d = a // b
r = a % b
f = a / b
print(d, r, '{:.5f}'.format(f))
| 1 | 601,818,552,260 | null | 45 | 45 |
n=int(input())
res=0
for i in range(1,n+1):
if int(i*1.08)==n:
res=i
if res != 0:
print(res)
else:
print(":(") | s = input()
if len(s) % 2 == 1:
print("No")
exit()
for i in range(0, len(s)-1, 2):
if s[i] + s[i+1] != "hi":
print("No")
exit()
print("Yes")
| 0 | null | 89,687,653,981,450 | 265 | 199 |
Q = 10**9+7
def main():
N, K = map( int, input().split())
ANS = [0]*(K+1)
for x in range(K,0,-1):
ans = pow(K//x,N,Q)
for i in range(2, K+1):
if x*i > K:
break
ans -= ANS[x*i]
ANS[x] = ans%Q
print( sum( [ANS[i]*i%Q for i in range(K+1)])%Q)
if __name__ == '__main__':
main()
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7
N, K = map(int, input().split())
lst = [0] * (K + 1)
for i in range(K, 0, -1):
a = K // i
tmp = pow(a, N, MOD)
for j in range(i + i, K + 1, i):
tmp -= lst[j]
lst[i] = tmp
ans = 0
for i in range(K + 1):
ans += i * lst[i]
ans %= MOD
print (ans) | 1 | 36,565,811,574,160 | null | 176 | 176 |
s = int(input())
MOD = 10**9 + 7
b3 = 1; b2 = 0; now = 0 # now == b1
for _ in range(s-2):
b1 = now
now = (b1 + b3) % MOD
b3, b2 = b2, b1
print(now)
| S = int(input())
dp = (S+1)*[0]
for n in range(S+1):
if 0<=n<=2:
dp[n] = 0
elif 3<=n<=5:
dp[n] = 1
else:
dp[n] = (dp[n-3]+dp[n-1])%(10**9+7)
print(dp[S]) | 1 | 3,275,297,019,012 | null | 79 | 79 |
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])
| import sys, os, math \
# , bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque
# import copy
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
MOD = 10 ** 9 + 7
MAX = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
A = il()
Q = ii()
M = il()
num_set = set()
for i in range(1 << N):
num = 0
for n in range(N):
if i >> n & 1:
num += A[n]
num_set.add(num)
for m in M:
if m in num_set:
print('yes')
else:
print('no')
if __name__ == '__main__':
main()
| 1 | 101,511,946,040 | null | 25 | 25 |
from math import sqrt
def isprime(inlst, chk, sq):
for i in range(3, sq, 2):
inlst = [x for x in inlst if x%i > 0 or x == i]
i += 2
return inlst
n = int(input())
inlst = [input() for i in range(n)]
inlst = [int(i) for i in inlst]
inlst = [x for x in inlst if x%2 > 0 or x == 2]
inlst = isprime(inlst, 3, int(sqrt(max(inlst))) + 1)
print(len(inlst)) | n,r=map(int,input().split())
def rate(n,r):
if n>=10:
return r
else:
return r+100*(10-n)
print(rate(n,r)) | 0 | null | 31,698,156,791,332 | 12 | 211 |
h,w,k = map(int, input().split())
item = [[0 for _ in range(w)] for _ in range(h)]
for i in range(k):
y,x,v = list(map(int,input().split()))
item[y-1][x-1]=v
dp = [[[0 for _ in range(w)] for _ in range(h)] for _ in range(4)]
for y in range(h):
for x in range(w):
for i in range(4):
if y<h-1:
dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x])
if x<w-1:
dp[i][y][x+1]=max(dp[i][y][x+1],dp[i][y][x])
if item[y][x]>0:
for i in range(3):
if y<h-1:
dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x] + item[y][x])
if x<w-1:
dp[i+1][y][x+1]=max(dp[i+1][y][x+1],dp[i][y][x] + item[y][x])
ans=[dp[0][-1][-1] + item[-1][-1],
dp[1][-1][-1] + item[-1][-1],
dp[2][-1][-1] + item[-1][-1],
dp[3][-1][-1]]
print(max(ans)) | import sys
import math
from collections import defaultdict
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def make_grid_int(h, w, num): return [[int(num)] * w for _ in range(h)]
def main():
R, C, K = NMI()
grid = make_grid_int(R, C, 0)
for i in range(K):
r, c, v = NMI()
grid[r-1][c-1] = v
dp = [[[0 for _ in range(C+2)] for _ in range(R+2)] for _ in range(4)]
for r in range(R+1):
for c in range(C+1):
for i in range(4):
now = dp[i][r][c]
try:
val = grid[r][c]
except:
val = 0
if i == 3:
# 取らずに下
dp[0][r + 1][c] = max(now, dp[0][r + 1][c])
continue
# 取って下
dp[0][r+1][c] = max(now + val, dp[0][r+1][c])
# 取らずに下
dp[0][r+1][c] = max(now, dp[0][r+1][c])
# 取って横
dp[i+1][r][c+1] = max(now + val, dp[i+1][r][c+1])
# 取らずに横
dp[i][r][c+1] = max(now, dp[i][r][c+1])
print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]))
if __name__ == "__main__":
main()
| 1 | 5,550,635,193,298 | null | 94 | 94 |
"""A."""
import sys
input = sys.stdin.readline # noqa: A001
D, T, S = map(int, input()[:-1].split(' '))
print('Yes' if T * S >= D else 'No')
| import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
def main():
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
z_max = 0
z_min = 2 * 10 **9
w_max = - 10 ** 9
w_min = 10 ** 9
for i in range(N):
z = xy[i][0] + xy[i][1]
w = xy[i][0] - xy[i][1]
z_max = max(z_max,z)
z_min = min(z_min,z)
w_max = max(w_max,w)
w_min = min(w_min,w)
res = max(z_max-z_min,w_max-w_min)
print(res)
main()
| 0 | null | 3,510,308,520,840 | 81 | 80 |
#!/usr/bin/env python
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
def main():
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())
dx = abs(A-B)
dv = V-W
if dv*T >= dx:
print("YES")
else:
print("NO")
if __name__ == "__main__":
main() | import sys
import resource
sys.setrecursionlimit(10000)
n,k=map(int,input().rstrip().split())
p=list(map(int,input().rstrip().split()))
c=list(map(int,input().rstrip().split()))
def find(start,now,up,max,sum,count,flag):
if start==now:
flag+=1
if start==now and flag==2:
return [max,sum,count]
elif count==up:
return [max,sum,count]
else:
count+=1
sum+=c[p[now-1]-1]
if max<sum:
max=sum
return find(start,p[now-1],up,max,sum,count,flag)
result=-10000000000
for i in range(1,n+1):
m=find(i,i,n,c[p[i-1]-1],0,0,0)
if m[2]>=k:
m=find(i,i,k,c[p[i-1]-1],0,0,0)
if m[0]>result:
result=m[0]
ans=result
elif m[1]<=0:
if m[0]>result:
result=m[0]
ans=result
else:
w=k%m[2]
if w==0:
w=m[2]
spe=find(i,i,w,c[p[i-1]-1],0,0,0)[0]
if m[1]+spe>m[0] and m[1]*(k-w)//m[2]+spe>result:
result=m[1]*(k-w)//m[2]+spe
elif m[1]+spe<=m[0] and m[1]*((k-w)//m[2]-1)+m[0]>result:
result=m[1]*((k-w)//m[2]-1)+m[0]
ans=result
print(ans) | 0 | null | 10,274,095,894,510 | 131 | 93 |
n = int(input())
a = [0,0,0]
mod = 1000000007
su=0
for i in range(3,n+1):
su=(su+a[i-3])%mod
a.append((su+1)%mod)
print(a[n]) | out = 0
inp = list(map(int, input().split()))
while 0<len(inp):
out += inp.pop(0)
if out <= 21:
print('win')
else:
print('bust') | 0 | null | 61,141,817,009,090 | 79 | 260 |
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N,K = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))
uf = UnionFind(N)
ans = -10**9
for i in range(N):
uf.union(i,P[i]-1)
for group in uf.all_group_members().values():
size = len(group)
SUM = 0
for i in group:
SUM += C[i]
if SUM < 0:
SUM = 0
for i in group:
cur = i
current_sum = 0
remain = K
for _ in range(size):
cur = P[cur]-1
current_sum += C[cur]
remain -= 1
if remain < 0:
break
ans = max(ans,current_sum+SUM*(remain//size))
print(ans) | N,K=map(int,input().split())
P=list(map(int,input().split()))
P=list(map(lambda x:x-1,P))
C=list(map(int,input().split()))
ans=-float("inf")
for i in range(N):
st=i
tmp=0
for j in range(K):
st=P[st]
tmp+=C[st]
ans=max(ans,tmp)
if i==st:
break
s,v=divmod(K,j+1)
if s>1 and v==0:
s-=1
v=j+1
tmp*=s
ans=max(ans,tmp)
for j in range(v):
st=P[st]
tmp+=C[st]
ans=max(ans,tmp)
print(ans) | 1 | 5,464,516,631,640 | null | 93 | 93 |
N,X,Y = map(int, input().split())
X,Y = X-1,Y-1
ans = [0] * N
for i in range(N):
for j in range(i+1,N):
dist = min(abs(i-j), abs(i-X) + 1 + abs(Y-j))
ans[dist] += 1
print(*ans[1:], sep='\n') | n = int(input())
s = set()
for i in range(n):
a,b = input().strip().split()
if a == 'insert':
s.add(b)
if a == 'find':
if b in s:
print('yes')
else:
print('no')
| 0 | null | 22,217,477,231,742 | 187 | 23 |
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
l = [A[0]]
for i in range(1, N):
l.append(A[i])
l.append(A[i])
print(sum(l[:N-1])) | X= int(input())
if(X>=400 and X<=599):
print(8)
elif(X>599 and X<800):
print(7)
elif(X>=800 and X<1000):
print(6)
elif(X>=1000 and X<1200):
print(5)
elif(X>=1200 and X<1400):
print(4)
elif(X>=1400 and X<1600):
print(3)
elif(X>=1600 and X<1800):
print(2)
elif(X>=1800 and X<2000):
print(1) | 0 | null | 7,905,609,967,828 | 111 | 100 |
fib = [1]*100
for i in range(2,100):
fib[i] = fib[i-1] + fib[i-2]
print(fib[int(input())])
| #!/usr/bin/python3
# main
n = int(input()) - 1
fib = [1, 2]
for i in range(2, n + 1):
fib.append(fib[i - 1] + fib[i - 2])
print(fib[n]) | 1 | 1,600,979,124 | null | 7 | 7 |
input = input()
print(input.replace('?','D')) | t = list(input())
t.reverse()
tmptmp = "P"
for i in range(len(t)):
if i == 0:
tmp = t[i]
continue
if tmp == "?" and tmptmp != "D":
t[i-1] = "D"
elif tmp == "?" and tmptmp == "D" and t[i] != "D":
t[i-1] = "D"
elif tmp == "?" and tmptmp == "D" and t[i] == "D":
t[i-1] = "P"
tmptmp = t[i-1]
tmp = t[i]
t.reverse()
if len(t) > 1:
if t[0] == "?" and t[1] == "D":
t[0] = "P"
elif t[0] == "?" and t[1] == "P":
t[0] = "D"
if len(t) == 1:
t[0] = "D"
t = "".join(t)
print(t)
| 1 | 18,628,054,394,080 | null | 140 | 140 |
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
def main():
INF = 10**9
H, W = input_nums()
ss = [input() for _ in range(H)]
dp = [[0]*W for _ in range(H)]
if ss[0][0] == '#': dp[0][0] = 1
for h in range(H):
for w in range(W):
if (h, w) == (0, 0): continue
u = l = INF
if h-1>=0:
u = dp[h-1][w]
if ss[h][w] == '#' and ss[h-1][w] == '.': u += 1
if w-1>=0:
l = dp[h][w-1]
if ss[h][w] == '#' and ss[h][w-1] == '.': l += 1
dp[h][w] = min(u, l)
print(dp[H-1][W-1])
if __name__ == '__main__':
main()
| import numpy as np
H, W = map(int, input().split())
masu = [input() for i in range(H)]
#temp = [list(input().replace("#","0").replace(".","1")) for i in range(H)]
#masu = [[int(temp[i][j]) for j in range(W)] for i in range(H)]
#dp = np.zeros((H, W))
dp = [[0]*W for i in range(H)]
if masu[0][0] == "#":
dp[0][0] = 1
for i in range(0,H):
for j in range(0,W):
if i == 0:
a = 100000
else:
if masu[i][j] == "#" and masu[i-1][j] == ".":
a = dp[i-1][j] + 1
else:
a = dp[i-1][j]
if j == 0:
b = 100000
else:
if masu[i][j] == "#" and masu[i][j-1] == ".":
b = dp[i][j-1] + 1
else:
b = dp[i][j-1]
if a != 100000 or b != 100000:
dp[i][j] = min([a, b])
print(int(dp[H-1][W-1]))
| 1 | 49,142,323,840,640 | null | 194 | 194 |
n = int(input())
x, y = [list(map(float,input().split()))for i in range(2)]
print("%.6f"%sum([abs(x[i]-y[i])for i in range(n)]))
print("%.6f"%pow(sum([abs(x[i]-y[i])**2 for i in range(n)]), 1/2))
print("%.6f"%pow(sum([abs(x[i]-y[i])**3 for i in range(n)]), 1/3))
print(*max([abs(x[i]-y[i])] for i in range(n)))
| n = int(input())
a = list(map(int, input().split()))
leaf = sum(a) - 1
now = 1
ans = 0
for i, num in enumerate(a):
ans += now
now -= num
if leaf >= now:
leaf -= now
now *= 2
elif leaf > 0:
now += leaf
leaf = 0
if now < 0:
print(-1)
exit()
print(ans)
| 0 | null | 9,584,958,056,362 | 32 | 141 |
s = input()
t = input()
ls = len(s)
lt = len(t)
min_count = 1000
for i in range(ls-lt+1):
count = 0
for j in range(lt):
if s[i:i+lt][j] != t[j]:
count += 1
if min_count > count:
min_count = count
print(min_count)
| def main():
X = int(input())
if X >=30: return "Yes"
return "No"
if __name__ == '__main__':
print(main())
| 0 | null | 4,779,514,947,830 | 82 | 95 |
n,k = map(int,input().split())
a = list(map(lambda x: (int(x)-1)%k ,input().split()))
sum_a = sum(a)%k
left = [0] * (n+1)
right = [0] * (n+1)
for i,num in enumerate(a,1):
left[i] = (left[i-1] + num)%k
for i,num in enumerate(a[::-1],1):
right[-i-1] = (right[-i] + num)%k
from collections import defaultdict
right_d = defaultdict(int)
right_d_over = defaultdict(int)
ans = 0
for i in range(n,-1,-1):
ans += right_d[(sum_a - left[i])%k] - right_d_over[(sum_a - left[i])%k]
right_d[right[i]] += 1
if( (n-i+1) >= k ):
right_d_over[right[i+k-1]] += 1
print(ans) | n, k = map(int, input().split())
nums = list(map(int, input().split()))
# (sums[j] - sums[i]) % K = j - i
# (sums[j] - j) % K = (sums[i] - i) % K
# 1, 4, 2, 3, 5
# 0, 1, 5, 7, 10, 15
# 0, 0, 3, 0, 2, 2
sums = [0]
for x in nums:
sums.append(sums[-1] + x)
a = [(sums[i] - i) % k for i in range(len(sums))]
res = 0
memo = {}
i = 0
for j in range(len(a)):
memo[a[j]] = memo.get(a[j], 0) + 1
if j - i + 1 > k:
memo[a[i]] -= 1
i += 1
res += memo[a[j]] - 1
print(res) | 1 | 137,363,872,939,090 | null | 273 | 273 |
import sys
input = sys.stdin.readline
a, b, c = map(int, input().split())
check = c - a - b
if check ** 2 > 4 * a * b and check > 0:
ans = 'Yes'
else:
ans = 'No'
print(ans)
| a,b,c = map(int,input().split())
ab= (a*b)*4
C= (c-a-b)**2
if c-a-b>=0:
if ab<C:
print("Yes")
else :
print("No")
else :
print("No")
| 1 | 51,624,620,045,060 | null | 197 | 197 |
n=int(input())
a=[]
for i in range(1,n+1):
if not(i%3==0 or i%5==0):
a.append(i)
print(sum(a)) | N = int(input())
A = []
for i in range(N+1):
if i % 3 == 0:
pass
elif i % 5 == 0:
pass
else:
A.append(i)
print(sum(A)) | 1 | 34,861,212,999,872 | null | 173 | 173 |
n, m = map(int, input().split())
if m >= n:
print("Yes")
else:
print('No') | n,m=input().split();print("YNeos"[n!=m::2]) | 1 | 83,189,117,065,792 | null | 231 | 231 |
N = int(input())
G = [[0] * N for _ in range(N)]
time = 0
times = [{'s': 0, 'f': 0} for _ in range(N)]
for _ in range(N):
u, n, *K = map(int, input().split())
for k in K:
G[u - 1][k - 1] = 1
def dfs(u):
global time
time += 1
times[u]['s'] = time
for i in range(N):
if G[u][i] == 1 and times[i]['s'] == 0:
dfs(i)
else:
time += 1
times[u]['f'] = time
for i in range(N):
if times[i]['s'] == 0:
dfs(i)
for i, time in enumerate(times):
print(i + 1, *time.values())
| N = int(input())
edge = [[] for _ in range(N+1)]
d = [0] * (N+1)
f = [0] * (N+1)
for i in range(N):
t = list(map(int, input().split()))
for j in range(t[1]):
edge[t[0]].append(t[j+2])
#print(1)
def dfs(v, t):
if d[v] == 0:
d[v] = t
t += 1
else:
return t
for nv in edge[v]:
t = dfs(nv, t)
if f[v] == 0:
f[v] = t
t += 1
return t
t = 1
for i in range(1,1+N):
if d[i] == 0:
t = dfs(i, t)
for i in range(1,1+N):
print(i, d[i], f[i])
| 1 | 3,307,040,990 | null | 8 | 8 |
k=int(input())
a=list(map(int,input().split()))
ans=[0 for x in range (2*(10**5))]
for i in range(k-1):
ans[(a[i]-1)]+=1
for i in range(k):
print(ans[i]) |
w1, w2 = input().split()
a,b = map(int,input().split())
c = input()
l = [[w1,a],[w2,b]]
ans = ""
for i in range(2):
x,y = l[i][0],l[i][1]
if x==c:
ans += str(y-1)
else:
ans += str(y)
if i==0:
ans += ' '
print(ans) | 0 | null | 51,946,829,769,250 | 169 | 220 |
# 2butan renshuu 0812
def f(m):
cut=0
for aa in a:
cut+=(aa-1)//m
if cut > k:
return False
return True
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=0
r=10**9+1
while r-l>1:
m=(l+r)//2
# right move
if f(m):
r=m
else:
l=m
print(r)
| import math
N, K = map(int,input().split())
logs = list(map(int,input().split()))
a = 0
b = max(logs)
b_memo = set()
count=0
flg =0
while math.ceil(a) != math.ceil(b):
c = (a+b)/2
times = []
for i in logs:
times.append(math.floor(i/c))
if sum(times) > K:
a = c
else:
b = c
if b - a < 0.001:
count +=1
if count >20:
flg+=1
break
if flg == 0:
print(math.ceil(b))
else:
a = math.ceil(a)
times = []
for j in logs:
times.append(math.floor(i/a))
if sum(times) > K:
print(math.ceil(b))
else:
print(math.ceil(a)) | 1 | 6,469,861,404,820 | null | 99 | 99 |
n,m = map(int,input().split())
a = [1]*(n+1)
b = [0]*(n+1)
for i in range(m):
x,y = map(int,input().split())
u = x
while a[u]==0:
u = b[u]
v = y
while a[v]==0:
v = b[v]
if u!=v:
b[v] = u
b[y] = u
b[x] = u
a[u] += a[v]
a[v] = 0
print(max(a)) | # coding: utf-8
# Your code here!
class UnionFind:
def __init__(self, size):
self.rank = [0 for i in range(size)]
self.parent = [-1 for i in range(size)]
self.children = [[i] for i in range(size)]
def Find(self, x):
parent = self.parent[x]
while parent >= 0:
x = parent
parent = self.parent[x]
return x
def Union(self, x, y):
root_x = self.Find(x)
root_y = self.Find(y)
if root_x == root_y:
return
else:
if self.rank[root_x] >= self.rank[root_y]:
self.parent[root_x] += self.parent[root_y]
self.parent[root_y] = root_x
self.rank[root_x] = max(self.rank[root_y] + 1, self.rank[root_x])
self.children[root_x] += self.children[root_y]
else:
self.parent[root_y] += self.parent[root_x]
self.parent[root_x] = root_y
self.rank[root_y] = max(self.rank[root_x] + 1, self.rank[root_y])
self.children[root_y] += self.children[root_x]
def Same(self, x, y):
return self.Find(x) == self.Find(y)
def FindRootAndSizeAndChildren(self):
return [(idx, -val, self.children[idx]) for idx, val in enumerate(self.parent) if val<0 ]
def print_lists(self):
print(self.rank)
print(self.parent)
print()
N, M = map(int, input().split())
unionfind = UnionFind(N)
for i in range(M):
a, b = map(int, input().split())
unionfind.Union(a-1, b-1)
max_size = 0
for idx, size, children in unionfind.FindRootAndSizeAndChildren():
if size > max_size:
max_size = size
print(max_size)
| 1 | 4,027,485,747,208 | null | 84 | 84 |
n = int(input())
times_ls = [0] * (n+1)
for base in range(1,n+1):
for j in range(1,n+1):
if base * j <= n:
times_ls[base * j] += 1
else:
break
ans = 0
for i in range(1,n+1):
ans += i * times_ls[i]
print(ans)
| N= int(input())
ans = 0
for j in range(1,N+1):
N_j = N//j
ans += j*(1+N_j)*N_j//2
print(ans) | 1 | 11,034,338,993,340 | null | 118 | 118 |
N = int(input())
def isnot_fizzbuzz(number: int) -> bool:
if (number) % 3 != 0 and (number) % 5 != 0:
return True
return False
def main():
sum = 0
for number in range(1, N + 1):
if isnot_fizzbuzz(number) == True:
sum += number
print(sum)
if __name__ == "__main__":
main() | a,b,c = map(int, raw_input().split())
count = 0
while 1:
if c % a == 0:
count += 1
if a == b:
break
a += 1
print count | 0 | null | 17,727,459,368,032 | 173 | 44 |
X,Y = map(int, input().split())
ans = "No"
for turtle in range(X+1):
crain = X - turtle
if 2 * crain + 4 * turtle == Y:
ans = "Yes"
print(ans) | a,b = map(int,input().split())
low = a*2
high = a*4
if b%2 != 0:
print("No")
elif b<low or b>high:
print("No")
else:
print("Yes") | 1 | 13,645,577,169,602 | null | 127 | 127 |
def main():
a,b = map(int,input().split())
if a > b:
print('a > b')
elif a < b:
print('a < b')
elif a == b:
print('a == b')
else:
print('error')
if __name__=="__main__":
main()
| #!usr/bin/env python3
def string_two_numbers_spliter():
a, b = [int(i) for i in input().split()]
return a, b
def main():
a, b = string_two_numbers_spliter()
if a < b:
print('a < b')
elif a > b:
print('a > b')
else:
print('a == b')
if __name__ == '__main__':
main() | 1 | 353,685,929,412 | null | 38 | 38 |
class Dice:
def __init__(self,numbers):
self.surface=numbers
def roll_E(self):
self.surface[0],self.surface[2],self.surface[3],self.surface[5]=self.surface[3],self.surface[0],self.surface[5],self.surface[2]
def roll_N(self):
self.surface[0],self.surface[1],self.surface[4],self.surface[5]=self.surface[1],self.surface[5],self.surface[0],self.surface[4]
def roll_S(self):
self.surface[0],self.surface[1],self.surface[4],self.surface[5]=self.surface[4],self.surface[0],self.surface[5],self.surface[1]
def roll_W(self):
self.surface[0],self.surface[2],self.surface[3],self.surface[5]=self.surface[2],self.surface[5],self.surface[0],self.surface[3]
def result(self):
return self.surface[0]
dice=Dice(input().split())
orders=input()
for i in orders:
if i=='E':
dice.roll_E()
if i=='N':
dice.roll_N()
if i=='S':
dice.roll_S()
if i=='W':
dice.roll_W()
print(int(dice.result()))
| # ['表面', '南面', '東面', '西面', '北面', '裏面']
dice = input().split()
com = [c for c in input()]
rolling = {
'E': [3, 1, 0, 5, 4, 2],
'W': [2, 1, 5, 0, 4, 3],
'S': [4, 0, 2, 3, 5, 1],
'N': [1, 5, 2, 3, 0, 4]
}
for c in com:
dice = [dice[i] for i in rolling[c]]
print(dice[0])
| 1 | 234,383,480,150 | null | 33 | 33 |
n,k = map(int,input().split())
MOD = 10**9+7
# g[i]:gcd(A1,A2,,,An)=iとなる数列の個数
g = [0 for _ in range(k)]
for i in range(k,0,-1):
g[i-1] = pow(k//i,n,MOD)
#ここまででg[x]=gcdがxの倍数となる数列の個数となっているので、
#ここからgcdが2x,3x,,,となる数列の個数を引いていく。
for j in range(2,k+1):
if i*j > k:
break
g[i-1] -= g[i*j-1]
g[i-1] %= MOD
#print(g)
ans = 0
for i in range(k):
ans += (i+1)*g[i]
ans %= MOD
print(ans)
| n,m = map(int,input().split())
v1 = [ list(map(int,input().split())) for i in range(n) ]
v2 = [ int(input()) for i in range(m) ]
for v in v1:
print( sum([ v[i] * v2[i] for i in range(m) ])) | 0 | null | 18,936,296,996,162 | 176 | 56 |
s = input()
if ("A" in s) and ("B" in s):
print("Yes")
else:
print("No") | class diceClass:
def __init__(self, valuelist):
self.valuelist = valuelist
self.t = valuelist[0]
self.b = valuelist[5]
self.n = valuelist[4]
self.s = valuelist[1]
self.e = valuelist[2]
self.w = valuelist[3]
def throw(self, direction):
# N,S,W,E
if direction == 'N':
self.t, self.s, self.b, self.n = self.s, self.b, self.n, self.t
elif direction == 'S':
self.t, self.s, self.b, self.n = self.n, self.t, self.s, self.b
elif direction == 'W':
self.t, self.e, self.b, self.w = self.e, self.b, self.w, self.t
elif direction == 'E':
self.t, self.e, self.b, self.w = self.w, self.t, self.e, self.b
arrinput = list(map(int, input().split()))
dirinput = input()
dice = diceClass(arrinput)
for s in dirinput:
dice.throw(s)
print(dice.t)
| 0 | null | 27,525,326,871,488 | 201 | 33 |
n = int(input())
slimes = input()
fusion = [slimes[0]]
cnt = 0
for i in range(1,n):
if fusion[cnt] != slimes[i]:
fusion.append(slimes[i])
cnt += 1
print(cnt+1) | t = input()
s = [i for i in t]
if s[0] == "?":
s[0] = "D"
for i in range(1, len(t) - 1):
if s[i] == "?":
if s[i-1] == "D" and s[i+1] == "D":
s[i] = "P"
elif s[i-1] == "p" and s[i+1] == "P":
s[i] = "D"
elif s[i-1] == "D" and s[i+1] == "?":
s[i] = "P"
elif s[i-1] == "P" and s[i+1] == "?":
s[i] = "D"
else:
s[i] = "D"
if s[-1] == "?":
s[-1] = "D"
print("".join(s)) | 0 | null | 94,266,756,554,208 | 293 | 140 |
def gcd(a,b):
# assume a,b are +ve integers.
if a>b:
a,b = b,a
if b%a==0:
return a
return gcd(a,b%a)
print(360//(gcd(360,int(input())))) | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
A = LIST()
if reduce(gcd, A) != 1:
print("not coprime")
exit()
ma = max(A)
p = list(range(ma+1))
for x in range(2, int(ma ** 0.5) + 1):
if p[x]:
# xは素数,それがpの要素にあるうちは続ける
for i in range(2 * x, ma + 1, x):
p[i] = x
s = [set() for _ in range(N)]
t = set()
for i, x in enumerate(A):
while x != 1:
s[i].add(x)
t.add(x)
# 割り続けるとs[i]にその素数がたまっていく
x //= p[x]
l = sum(len(x) for x in s)
print("pairwise coprime" if l == len(t) else "setwise coprime")
| 0 | null | 8,680,311,929,948 | 125 | 85 |
import math
K = int(input())
ans = 0
for i in range(K):
for t in range(K):
for j in range(K):
gcd1 = math.gcd(i+1,t+1)
gcd2 = math.gcd(gcd1,j+1)
ans += gcd2
print(ans) | import math
K = int(input())
g = []
for i in range(1, K+1):
for j in range(1, K+1):
g.append(math.gcd(i, j))
result = 0
for i in range(1, K+1):
for t in g:
result += math.gcd(i, t)
print(result)
| 1 | 35,441,052,395,638 | null | 174 | 174 |
from itertools import product
N=int(input())
datas=[]
for i in range(N):
A=int(input())
for j in range(A):
x,y=map(int,input().split())
datas.append((i,x-1,y)) #誰が 誰に どう判断した?
#print(datas)
ans=0
for i in product([0,1],repeat=N):
ok=True
for j in datas:
if i[j[0]]==1 and i[j[1]]!=j[2]:
ok=False
break
if ok:
ans=max(ans,sum(i))
print(ans) | N = int(input())
evidences = [[] for _ in range(N)]
for i in range(N):
A = int(input())
for _ in range(A):
x, y = map(int, input().split())
evidences[i].append((x - 1, y))
ans = 0
for i in range(1, 2 ** N):
consistent = True
for j in range(N):
if (i >> j) & 1 == 0:
continue
for x, y in evidences[j]:
if (i >> x) & 1 != y:
consistent = False
break
#if not consistent:
#break
if consistent:
ans = max(ans, bin(i)[2:].count('1'))
print(ans) | 1 | 121,842,384,969,672 | null | 262 | 262 |
def linearSearch(A, key):
i = 0
A.append(key)
while A[i] != key:
i += 1
if i == len(A)-1:
A.pop()
return 'Not_found'
A.pop()
return i
if __name__ == '__main__':
c = 0
n = int(input())
hoge1 = [int(x) for x in input().split()]
q = int(input())
for key in (int(x) for x in input().split()):
if linearSearch(hoge1, key) == 'Not_found':
continue
else:
c += 1
print (c)
| def Check_Num(n):
for i in range(1,n + 1):
x = i
if (x % 3 == 0):
print(' {}'.format(i),end = '')
continue
elif (x % 10 == 3):
print(' {}'.format(i),end = '')
continue
x //= 10
while (x > 0):
if (x % 10 == 3):
print(' {}'.format(i),end = '')
break
x //= 10
print()
if __name__ == '__main__':
n = int(input())
Check_Num(n)
| 0 | null | 498,316,128,688 | 22 | 52 |
n = int(input())
k = 0
num_list = [0] * 12
for i in range(12):
num_list[i] = 26**(i+1)
if n <= sum(num_list[:i]):
k = i
break
'print(num_list)'
'''print('k=' , k)'''
diff = n - (sum(num_list[:k-1]) + 1)
'''print(diff)'''
ans = ['a']*(k)
arr = [0] * (k)
for i in range(len(ans)):
arr[i] = diff // 26**(len(ans)-1-i)%26
'''print('arr = ',i,' ', arr[i])'''
'''print('ans = ',i,' ', ord(ans[i]))'''
ans[i] = (chr((ord(ans[i]) + arr[i])))
print(''.join(ans)) | import numpy as np
n = int(input())
count = np.zeros(n, dtype=np.int)
for d in range(1, n):
count[d::d] += 1
print(count.sum()) | 0 | null | 7,218,233,928,612 | 121 | 73 |
n = int(input())
a = list(map(int, input().split()))
leaf = sum(a) - 1
now = 1
ans = 0
for i, num in enumerate(a):
ans += now
now -= num
if leaf >= now:
leaf -= now
now *= 2
elif leaf > 0:
now += leaf
leaf = 0
if now < 0:
print(-1)
exit()
print(ans)
| from math import ceil
n = int(input())
A = list(map(int,input().split()))[::-1]
mn,mx = A[0], A[0]
step = [[mn,mx]]
for i in range(1, n+1):
mn = ceil(mn/2) + A[i]
mx = mx + A[i]
step.append([mn,mx])
if not mn<=1 and 1<=mx:
print(-1)
else:
step = step[::-1]
A = A[::-1]
now = 1
ans = 1
for i in range(1, n+1):
now = min(step[i][1],
(now-A[i-1])*2)
ans += now
print(ans) | 1 | 18,983,560,921,202 | null | 141 | 141 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N = int(input())
XY = [list(mapint()) for _ in range(N)]
XY.sort(key=lambda x:x[0]+x[1])
ans_1 = abs(XY[0][0]-XY[-1][0])+abs(XY[0][1]-XY[-1][1])
XY.sort(key=lambda x:x[0]-x[1])
ans_2 = abs(XY[0][0]-XY[-1][0])+abs(XY[0][1]-XY[-1][1])
print(max(ans_1, ans_2)) | n = int(input())
x = [None]*n
y = [None]*n
for i in range(n):
x[i],y[i] = map(int,input().split())
#y=x+k1 <=> x-y=-k1
k1 = [0]*n
#y=-x+k2 <=> x+y=k2
k2 = [0]*n
for i in range(n):
k1[i] = -(x[i]-y[i])
k2[i] = x[i]+y[i]
print(max(max(k1)-min(k1),max(k2)-min(k2))) | 1 | 3,418,381,495,144 | null | 80 | 80 |
from heapq import *
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
def main():
n=II()
ss=[SI() for _ in range(n)]
ms1=[]
ms2=[]
for s in ss:
mn=0
now=0
for c in s:
if c=="(":now+=1
else:now-=1
if now<mn:mn=now
if now>0:ms1.append((mn,now))
else:ms2.append((mn-now,-now))
#print(ms1)
#print(ms2)
cnt=0
for mn,s in sorted(ms1,reverse=True):
if cnt+mn<0:
print("No")
exit()
cnt+=s
cnt2=0
for mn,s in sorted(ms2,reverse=True):
if cnt2+mn<0:
print("No")
exit()
cnt2+=s
if cnt==cnt2:print("Yes")
else:print("No")
main() | import sys
import heapq
input = sys.stdin.readline
N = int(input())
forward = []
backward = []
for _ in range(N):
pos = 0
Min = 0
for c in input()[:-1]:
if c == '(':
pos += 1
else:
pos -= 1
Min = min(Min, pos)
if pos >= 0:
heapq.heappush(forward, (-Min, pos))
else:
heapq.heappush(backward, (pos-Min, -pos))
ansflg = True
pos1 = 0
while forward:
down, pos = heapq.heappop(forward)
if pos1 >= down:
pos1 += pos
else:
ansflg = False
break
pos2 = 0
if ansflg:
while backward:
down, pos = heapq.heappop(backward)
if pos2 >= down:
pos2 += pos
else:
ansflg = False
break
if pos1 != pos2:
ansflg = False
if ansflg:
print("Yes")
else:
print("No")
| 1 | 23,665,890,856,300 | null | 152 | 152 |
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(buff_readline())
def read_int_n():
return list(map(int, buff_readline().split()))
def read_float():
return float(buff_readline())
def read_float_n():
return list(map(float, buff_readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
class Mod:
def __init__(self, m):
self.m = m
def add(self, a, b):
return (a + b) % self.m
def sub(self, a, b):
return (a - b) % self.m
def mul(self, a, b):
return ((a % self.m) * (b % self.m)) % self.m
def div(self, a, b):
return self.mul(a, pow(b, self.m-2, self.m))
def pow(self, a, b):
return pow(a, b, self.m)
class Bisect:
def __init__(self, func):
self.__func = func
def bisect_left(self, x, lo, hi):
while lo < hi:
mid = (lo+hi)//2
if self.__func(mid) < x:
lo = mid+1
else:
hi = mid
return lo
def bisect_right(self, x, lo, hi):
while lo < hi:
mid = (lo+hi)//2
if x < self.__func(mid):
hi = mid
else:
lo = mid+1
return lo
@mt
def slv(N, M, S):
from functools import lru_cache
@lru_cache(maxsize=None)
def dfs(x):
if x == 0:
return []
for i in range(M, 0, -1):
if 0 <= x-i and S[x-i] == '0':
r = dfs(x-i)
if r is not None:
r.append(i)
return r
return None
ans = dfs(N)
if ans is None:
ans = [-1]
return ans
def main():
N, M = read_int_n()
S = read_str()
print(*slv(N, M, S))
if __name__ == '__main__':
main()
| n = int(raw_input())
N = 100
WHITE = 0
GRAY = 1
BLACK = 2
Color = [WHITE for i in range(n)]
#M = [[0 for i in range(N)] for j in range(N)]
tt = 0
d = [0 for i in range(n)]
f = [0 for i in range(n)]
def dfs_visit(u):
Color[u] = GRAY
global tt
tt += 1
d[u] = tt
for v in range(n):
if M[u][v] == 0:
continue
if Color[v] == WHITE:
dfs_visit(v)
Color[u] = BLACK
tt += 1
f[u] = tt
def dfs():
#Color = [WHITE for i in range(n)]
tt = 0
for u in range(n):
if Color[u] == WHITE:
dfs_visit(u)
for u in range(n):
print "%d %d %d" %(u + 1, d[u], f[u])
M = [[0 for j in range(n)] for i in range(n)]
for i in range(n):
tmp = map(int, raw_input().split())
u = tmp[0]
k = tmp[1]
u -= 1
for j in range(k):
v = tmp[j + 2]
v -= 1
M[u][v] = 1
dfs() | 0 | null | 69,458,232,729,180 | 274 | 8 |
while True:
try:
a,b=[int(i) for i in input().split()]
print(len(str(a+b)))
except:
break
| #!/usr/bin/env python3
import sys
import collections as cl
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
N = II()
print((N/3)**3)
main()
| 0 | null | 23,445,260,967,300 | 3 | 191 |
N = int(input())
import math
y = int(math.sqrt(N))
ans = 10 ** 12
for i in range(1,y + 2):
if N % i == 0:
x = N // i + i - 2
ans = min(ans,x)
print(ans)
| y = 1
while y<10:
x = 1
while x<10:
print str(y)+'x'+str(x)+'='+str(y*x)
x += 1
y += 1 | 0 | null | 81,165,866,717,962 | 288 | 1 |
def readinput():
n,m=map(int,input().split())
tries=[]
for _ in range(m):
p,s=input().split()
p=int(p)
tries.append((p,s))
return n,m,tries
def main(n,m,tries):
point=[[0,0] for i in range(n+1)]
for i in range(m):
p,s=tries[i]
if s=='WA':
if point[p][0]>0:
continue
else:
point[p][1]+=1
else:
point[p][0]+=1
ac=0
wa=0
for i in range(1,n+1):
if point[i][0]>0:
ac+=1
wa+=point[i][1]
return ac,wa
if __name__=='__main__':
n,m,tries=readinput()
ans=main(n,m,tries)
print(' '.join(map(str,ans)))
| N,M = map(int,input().split())
wa_list= [0]*(N+2)
ac_list=[-1]*(N+2)
for i in range(M):
p,a = map(str,input().split())
p = int(p)
if a =='WA':
wa_list[p]+=1
if a =='AC' and ac_list[p] == -1:
ac_list[p]+=(wa_list[p]+1)
count = 0;count2 = 0
for i in ac_list:
if i>=0:
count+=1
count2+=i
print(count,count2)
| 1 | 93,678,063,836,918 | null | 240 | 240 |
MOD=10**9+7
N=int(input())
ans=pow(10,N,MOD)
ans-=2*pow(9,N,MOD)
ans+=pow(8,N,MOD)
ans%=MOD
print(ans) | import collections
n = int(input())
a = list(map(int, input().split()))
l = []
r = []
for i in range(n):
l.append(i+a[i])
r.append(i-a[i])
count_l = collections.Counter(l)
count_r = collections.Counter(r)
ans = 0
for i in count_l:
ans += count_r.get(i,0) * count_l[i]
print(ans) | 0 | null | 14,602,502,034,068 | 78 | 157 |
def mod_fact(N,p):
mod=1
for n in range(1,N+1):
mod = (mod*(n%p))%p
mod = mod%p
return mod
X,Y = list(map(int,input().split()))
Z = X+Y
ans=0
if Z%3 != 0:
ans=0
elif min(X,Y) >= Z//3:
b=0
for z in range(Z//3,((Z//3)*2)+1):
if z == X:
break
b+=1
a = Z//3 - b
p=(10**9)+7
Z_= mod_fact(Z//3 , p)
a_= mod_fact(a , p)
b_= mod_fact(b , p)
a_= pow(a_,p-2,p)
b_= pow(b_,p-2,p)
ans=(Z_*(a_*b_))%p
print(ans)
| n,k,s=map(int,input().split())
a=[1 for i in range(n)]
for i in range(k):
a[i]=s
for i in range(k,n):
if s!=10**9:
a[i]+=s
else:
a[i]=1
if k==0:
if s!=10**9:
a=[10**9 for i in range(n)]
else:
a=[1 for i in range(n)]
print(*a) | 0 | null | 120,542,238,971,830 | 281 | 238 |
H, W, M = map(int, input().split())
h_list = [0 for i in range(H)]
w_list = [0 for i in range(W)]
point = {}
for _ in range(M):
h, w = map(int, input().split())
h_list[h - 1] += 1
w_list[w - 1] += 1
point[(h - 1, w - 1)] = 1
hmax = 0
wmax = 0
hmap = {}
wmap = {}
for i, h in enumerate(h_list):
if hmax <= h:
hmax = h
hmap.setdefault(h, []).append(i)
for i, w in enumerate(w_list):
if wmax <= w:
wmax = w
wmap.setdefault(w, []).append(i)
# print(hmap)
# print(wmap)
# hmax = max(h_list)
# wmax = max(w_list)
h_index = h_list.index(hmax)
w_index = w_list.index(wmax)
for h in hmap[hmax]:
for w in wmap[wmax]:
if (h, w) not in point:
print(hmax + wmax)
exit(0)
print(hmax + wmax - 1) | #!/usr/bin/env python
# encoding: utf-8
class Solution:
@staticmethod
def selection_sort():
# write your code here
array_length = int(input())
unsorted_array = [int(x) for x in input().split()]
count = 0
for i in range(array_length):
min_j = i
for j in range(i, array_length):
if unsorted_array[j] < unsorted_array[min_j]:
min_j = j
unsorted_array[i], unsorted_array[min_j] = unsorted_array[min_j], unsorted_array[i]
if i != min_j:
count += 1
print(" ".join(map(str, unsorted_array)))
print(str(count))
if __name__ == '__main__':
solution = Solution()
solution.selection_sort() | 0 | null | 2,345,581,368,582 | 89 | 15 |
n,p = map(int,input().split())
s = list(map(int, list(input())))
def solve():
total = 0
if 10%p == 0:
for i in range(n):
if s[i] % p == 0: total += i + 1
return total
cnt = [0]*p
r = 0
ten = 1
for i in range(n-1, 0-1, -1):
cnt[r] += 1
r = (r + s[i]*ten) % p
total += cnt[r]
ten = ten * 10 % p
return total
print(solve()) | import sys
def selectionSort(x_list, y):
a = 0
for i in range(y):
minj = i
for j in range(i, y):
if x_list[j] < x_list[minj]:
minj = j
x_list[i], x_list[minj] = x_list[minj], x_list[i]
if x_list[i] != x_list[minj]:
a += 1
return a
y = sys.stdin.readline()
y = int(y)
x = sys.stdin.readline()
x_list = x.split(" ")
for i in range(y):
x_list[i] = int(x_list[i])
a = selectionSort(x_list, y)
for k in range(0, y):
print x_list[k],
print
print a | 0 | null | 29,257,971,099,060 | 205 | 15 |
N, X, M = map(int, input().split())
ls = [False]*M
ls_mod = []
x = X
for m in range(M+1):
if ls[x] == False:
ls_mod.append(x)
ls[x] = m
x = (x**2)%M
else:
last = m
fast = ls[x]
diff = last - fast
break
if M == 1:
print(0)
else:
if last > N:
print(sum(ls_mod[:N]))
else:
shou = (N-fast) // diff
amari = (N-fast) % diff
print(sum(ls_mod[:fast])+sum(ls_mod[fast:])*shou+sum(ls_mod[fast:fast+amari]))
| N,X,M = map(int,input().split())
ls = [X]
for i in range(M):
Ai = ls[-1]**2 % M
if Ai in ls:
loop = ls[ls.index(Ai):]
lenloop = len(loop)
sumloop = sum(loop)
startls = ls[:ls.index(Ai)]
break
ls.append(Ai)
if N <= len(startls):
ans = sum(startls[:N])
else:
ans = sum(startls) + ((N-len(startls))//lenloop)*sumloop + sum(loop[:(N-len(startls))%lenloop])
print(ans)
| 1 | 2,807,824,707,388 | null | 75 | 75 |
import sys
def main():
input = sys.stdin.readline
N,P = map(int, input().split())
S = input().rstrip()
D = list(map(int, S))
ans = 0
if P == 2:
for i, d in enumerate(D):
if d&1 == 0: ans += i + 1
return ans
if P == 5:
for i, d in enumerate(D):
if d == 0 or d == 5: ans += i + 1
return ans
A = [0] * P
num = Mint(0, P)
for i in range(N):
num += Mint(D[-1-i], P) * pow(10, i, P)
A[num.value] += 1
for a in A:
ans += a * (a-1) // 2
ans += A[0]
return ans
class Mint:
def __init__(self, value=0, mod=10**9+7):
self.value = ((value % mod) + mod) % mod
self.mod = mod
@staticmethod
def get_value(x): return x.value if isinstance(x, Mint) else x
def inverse(self):
a, b = self.value, self.mod
u, v = 1, 0
while b:
t = a // b
b, a = a - t * b, b
v, u = u - t * v, v
return (u + self.mod) % self.mod
def __repr__(self): return str(self.value)
def __eq__(self, other): return self.value == other.value
def __neg__(self): return Mint(-self.value, self.mod)
def __hash__(self): return hash(self.value)
def __bool__(self): return self.value != 0
def __iadd__(self, other):
self.value = (self.value + Mint.get_value(other)) % self.mod
return self
def __add__(self, other):
new_obj = Mint(self.value, self.mod)
new_obj += other
return new_obj
__radd__ = __add__
def __isub__(self, other):
self.value = (self.value - Mint.get_value(other) + self.mod) % self.mod
return self
def __sub__(self, other):
new_obj = Mint(self.value, self.mod)
new_obj -= other
return new_obj
def __rsub__(self, other):
new_obj = Mint(Mint.get_value(other), self.mod)
new_obj -= self
return new_obj
def __imul__(self, other):
self.value = self.value * Mint.get_value(other) % self.mod
return self
def __mul__(self, other):
new_obj = Mint(self.value, self.mod)
new_obj *= other
return new_obj
__rmul__ = __mul__
def __ifloordiv__(self, other):
other = other if isinstance(other, Mint) else Mint(other, self.mod)
self *= other.inverse
return self
def __floordiv__(self, other):
new_obj = Mint(self.value, self.mod)
new_obj //= other
return new_obj
def __rfloordiv__(self, other):
new_obj = Mint(Mint.get_value(other), self.mod)
new_obj //= self
return new_obj
if __name__ == '__main__':
ans = main()
print(ans) | import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
def main():
inf=10**9
h,w=MI()
ss=[SI() for _ in range(h)]
cc=[[0]*w for _ in range(h)]
if ss[0][0]=="#":cc[0][0]=1
for i in range(h):
for j in range(w):
if (i,j)==(0,0):continue
u=l=inf
if i-1>=0:
u=cc[i-1][j]
if ss[i][j]=="#" and ss[i-1][j]==".":u+=1
if j-1>=0:
l=cc[i][j-1]
if ss[i][j]=="#" and ss[i][j-1]==".":l+=1
cc[i][j]=min(u,l)
print(cc[h-1][w-1])
main() | 0 | null | 53,746,030,709,020 | 205 | 194 |
class findroop:
def __init__(self, n, nex):
self.n = n
self.next = nex
#遷移start回でループに入る、end回でループする
#A->B->C->D->B: return=(1, 4)
#C->D->B->C : return=(0, 3)
#O(n)
def findroop(self, start):
roopstart = -1
roopend = -1
visited = [False for i in range(self.n)]
visitlist = []
now = start
for i in range(self.n):
if visited[now]:
roopend = i
break
else:
visited[now] = True
visitlist.append(now)
now = self.next(now)
for i in range(len(visitlist)):
if visitlist[i] == now:
roopstart = i
return (roopstart, roopend)
N,X,M = list(map(int, input().split()))
fr = findroop(M, lambda x: x**2 % M)
roopstart, roopend = fr.findroop(X)
ans = 0
if N <= roopstart:
for i in range(N):
ans += X
X = (X**2)%M
else:
for i in range(roopstart):
ans += X
X = (X**2)%M
N -= roopstart
roopsum = 0
for i in range(roopend-roopstart):
roopsum += X
X = (X**2) % M
ans += (N // (roopend-roopstart)) * roopsum
N = N % (roopend-roopstart)
for i in range(N):
ans += X
X = (X**2) % M
print(ans) | h,n=map(int,input().split())
c=[list(map(int,input().split()))for _ in range(n)]
d=[0]+[0]*20001
for i in range(h):
d[i]=min(d[i-a]+b for a,b in c)
print(d[h-1]) | 0 | null | 42,050,258,731,040 | 75 | 229 |
def main():
S = input()
T = input()
l_s = len(S)
l_t = len(T)
cnt_list = []
for i in range(l_s - l_t + 1):
cnt = 0
S_ = S[i: i+l_t]
for j in range(l_t):
if S_[j] != T[j]:
cnt += 1
cnt_list.append(cnt)
ans = min(cnt_list)
print(ans)
return
if __name__ == '__main__':
main()
| n=int(input())
j,k=map(int,input().split())
f=1
if k-j>=n:
print('OK')
f=0
else:
for i in range(j,k+1):
if i%n==0:
print('OK')
f=0
break
if f==1:
print("NG") | 0 | null | 15,171,235,223,168 | 82 | 158 |
import itertools
N, M, Q = map(int,input().split())
ans = 0
A = []
B = []
C = []
D = []
for _ in range(Q):
a, b, c, d = map(int,input().split())
A.append(a-1)
B.append(b-1)
C.append(c)
D.append(d)
ans = 0
for seq in itertools.combinations_with_replacement(range(M),N):
tmp = 0
for i in range(Q):
if seq[B[i]] - seq[A[i]] == C[i]:
tmp += D[i]
ans = max(ans,tmp)
print(ans) | import sys, math
input = sys.stdin.readline
MAX = 2e9
def merge(A, left, mid, right):
n1 = mid - left
n2 = right - mid
L = A[left:mid]
L.append(MAX)
R = A[mid:right]
R.append(MAX)
merged = []
index_L = 0
index_R = 0
comp_cnt = 0
for _ in range(n1+n2):
cand_L = L[index_L]
cand_R = R[index_R]
comp_cnt += 1
if (cand_L < cand_R):
merged.append(cand_L)
index_L += 1
else:
merged.append(cand_R)
index_R += 1
A[left:right] = merged
return comp_cnt
def merge_sort(A, left, right):
comp_cnt = 0
if (left + 1 < right):
# Devide
mid = (left + right) // 2
# Solve
_, cnt = merge_sort(A, left, mid)
comp_cnt += cnt
_, cnt = merge_sort(A, mid, right)
comp_cnt += cnt
# Conquer
comp_cnt += merge(A, left, mid, right)
return A, comp_cnt
def main():
N = int(input())
S = list(map(int, input().split()))
left = 0
right = len(S)
merged, cnt = merge_sort(S, left, right)
print(" ".join([str(x) for x in merged]))
print(cnt)
if __name__ == "__main__":
main()
| 0 | null | 13,973,924,345,228 | 160 | 26 |
import sys
n = int(sys.stdin.readline())
for _ in range(n):
a, b, c = sorted(list(map(int, sys.stdin.readline().split())))
print('YES' if a * a + b * b == c * c else 'NO') | import math
n = input()
for i in range(n):
flag = 0
a = map(int, raw_input().split())
if(pow(a[0],2)+pow(a[1],2) == pow(a[2],2)):
flag = 1
if(pow(a[1],2)+pow(a[2],2) == pow(a[0],2)):
flag = 1
if(pow(a[2],2)+pow(a[0],2) == pow(a[1],2)):
flag = 1
if flag == 1:
print "YES"
else:
print "NO" | 1 | 220,100,430 | null | 4 | 4 |
X,N=map(int,input().split())
if N>0:
P=list(map(int,input().split()))
for i in range(N+1):
if X-i not in P:
print(X-i)
break
elif X+i not in P:
print(X+i)
break
else:
print(X) |
MOD = 998244353
class mint:
def __init__(self, x):
if isinstance(x, int):
self.x = x % MOD
elif isinstance(x, mint):
self.x = x.x
else:
self.x = int(x) % MOD
def __str__(self):
return str(self.x)
__repr__ = __str__
def __iadd__(self, other):
self.x += other.x if isinstance(other, mint) else other
self.x -= MOD if self.x >= MOD else 0
return self
def __isub__(self, other):
self.x += MOD-other.x if isinstance(other, mint) else MOD-other
self.x -= MOD if self.x >= MOD else 0
return self
def __imul__(self, other):
self.x *= other.x if isinstance(other, mint) else other
self.x %= MOD
return self
def __add__(self, other):
return (
mint(self.x + other.x) if isinstance(other, mint) else
mint(self.x + other)
)
def __sub__(self, other):
return (
mint(self.x - other.x) if isinstance(other, mint) else
mint(self.x - other)
)
def __mul__(self, other):
return (
mint(self.x * other.x) if isinstance(other, mint) else
mint(self.x * other)
)
def __floordiv__(self, other):
return (
mint(
self.x * pow(other.x, MOD - 2, MOD)
) if isinstance(other, mint) else
mint(self.x * pow(other, MOD - 2, MOD))
)
def __pow__(self, other):
return (
mint(pow(self.x, other.x, MOD)) if isinstance(other, mint) else
mint(pow(self.x, other, MOD))
)
__radd__ = __add__
def __rsub__(self, other):
return (
mint(other.x - self.x) if isinstance(other, mint) else
mint(other - self.x)
)
__rmul__ = __mul__
def __rfloordiv__(self, other):
return (
mint(
other.x * pow(self.x, MOD - 2, MOD)
) if isinstance(other, mint) else
mint(other * pow(self.x, MOD - 2, MOD))
)
def __rpow__(self, other):
return (
mint(pow(other.x, self.x, MOD)) if isinstance(other, mint) else
mint(pow(other, self.x, MOD))
)
n,s = map(int, input().split())
a = list(map(int, input().split()))
import copy
dp = [[0 for _ in range(s+1)] for _ in range(n+1)]
dp[0][0]=pow(2,n,MOD)
div=pow(2,MOD-2,MOD)
for i in range(n):
for j in range(s+1):
dp[i+1][j]=dp[i][j]
if j-a[i]>=0:
dp[i+1][j]+=dp[i][j-a[i]]*div
dp[i+1][j]%=MOD
print(dp[n][s]) | 0 | null | 15,929,022,156,610 | 128 | 138 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.