code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
from functools import lru_cache
@lru_cache(maxsize=None)
def Fib(n):
if n==0:
return 1
elif n==1:
return 1
else:
return Fib(n-1)+Fib(n-2)
n=int(input())
print(Fib(n))
| s = input()
t = input()
count = 0
for ss, tt in zip(s, t):
if ss != tt:
count += 1
print(count) | 0 | null | 5,302,766,223,172 | 7 | 116 |
def main():
k,n = map(int, input().split())
s = list(map(int, input().split()))
l = []
for i in range(n):
if i == 0:
l.append(k - (s[-1] - s[0]))
else:
a = s[i] - s[i-1]
l.append(a)
print(k - max(l))
if __name__ == '__main__':
main()
| K,N=map(int,input().split())
A=[int(i) for i in input().split()]
dlist=[]
for i in range(1,N):
d=A[i]-A[i-1]
dlist.append(d)
dlist.append(A[0]+K-A[N-1])
print(K-max(dlist)) | 1 | 43,167,349,896,580 | null | 186 | 186 |
x, n = map(int, input().split())
p = list(map(int, input().split()))
i = 0
while True:
if x-i not in p:
print(x-i)
break
if x+i not in p:
print(x+i)
break
i += 1 | import sys
x,n = map(int,input().split())
p = list(map(int,input().split()))
if p.count(x) == 0:
print(x)
else:
for i in range(1,110):
if p.count(x-i) == 0:
print(x-i)
sys.exit()
elif p.count(x+i) == 0:
print(x+i)
sys.exit()
| 1 | 14,022,439,072,420 | null | 128 | 128 |
import sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()
N = I()
ST = [tuple(map(str,S().split())) for _ in range(N)]
X = S()
ans = 0
for i in range(N):
s,t = ST[i]
ans += int(t)
if s == X:
break
print(sum(int(ST[i][1]) for i in range(N))-ans)
| from math import gcd;print(360//gcd(int(input()),360)) | 0 | null | 55,212,595,830,028 | 243 | 125 |
length = int(input())
nums = input().split()
print(" ".join(nums[::-1])) | n = input()
data = list(map(str, input().split()))
print(*data[::-1]) | 1 | 974,712,366,728 | null | 53 | 53 |
#!/usr/bin/env python3
s = input()
a = 0
for i in range(len(s)//2):
a += s[i] != s[-i-1]
print(a) | S = input()
n = len(S)
c = 0
for i in range(n // 2):
if S[i] != S[n - i - 1]:
c += 1
print(c) | 1 | 120,003,280,150,820 | null | 261 | 261 |
n,m = map(int, input().split())
d = list(map(int, input().split()))
inf = float('inf')
dp = [inf for i in range(n+1)]
dp[0] = 0
for i in range(m):
for j in range(d[i], n+1):
dp[j] = min(dp[j], dp[j-d[i]]+1)
print(dp[-1])
| INF = 100 ** 7
def main():
n, m = map(int, input().split())
c_list = list(map(int, input().split()))
dp = [INF] * (n + 1)
dp[0] = 0
for c in c_list:
for i in range(len(dp)):
if dp[i] != INF and i + c < len(dp):
dp[i + c] = min(dp[i + c], dp[i] + 1)
print(dp[n])
if __name__ == '__main__':
main() | 1 | 140,229,472,222 | null | 28 | 28 |
n = int(input())
x = []
for i in range(n):
a, b = map(int, input().split())
x.append([a, b])
ans = 0
for i in range(len(x) - 1):
for j in range(i+1, len(x)):
ans += ((x[i][0]-x[j][0])**2 + (x[i][1]-x[j][1])**2)**0.5
print((2*ans)/n) | print("\n".join(map(str,sorted([int(input())for _ in[0]*10])[:-4:-1]))) | 0 | null | 73,987,511,693,852 | 280 | 2 |
import queue
k = int(input())
q = queue.Queue()
for i in range(1, 10):
q.put(i)
for i in range(k):
x = q.get()
if i == k-1:
print(x)
break
if x%10 != 0:
q.put(10*x+(x%10)-1)
q.put(10*x+x%10)
if x%10 != 9:
q.put(10*x+(x%10)+1)
| A, B = map(int, input().split())
x = 0
while int(x * 0.08) <= A or int(x * 0.1) <= B:
x += 1
if int(x * 0.08) == A and int(x * 0.1) == B:
print(x)
exit()
print(-1)
| 0 | null | 48,345,278,030,372 | 181 | 203 |
def insertion(A,n):
for i in range(0,n):
tmp = A[i]
j = i - 1
while(A[j] > tmp and j >= 0):
A[j+1] = A[j]
j-=1
A[j+1] = tmp
printList(A)
def printList(A):
print(" ".join(str(x) for x in A))
n = int(input())
A = [int(x) for x in input().split()]
insertion(A,n) | INF = 10 ** 20
n, m = map(int, input().split())
c_lst = list(map(int, input().split()))
dp = [INF for _ in range(n + 1)]
dp[0] = 0
for coin in c_lst:
for price in range(coin, n + 1):
dp[price] = min(dp[price], dp[price - coin] + 1)
print(dp[n])
| 0 | null | 70,556,832,430 | 10 | 28 |
n = int(input())
x = list(input().split())
x.reverse()
print(" ".join(x))
| h,n=map(int,input().split())
a,b=[],[]
for i in range(n):
A,B=map(int,input().split())
a.append(A)#ダメージ量
b.append(B)#消費魔力
dp=[float('inf')]*(h+1)
dp[0]=0
for i in range(h):
for j in range(n):
next=i+a[j] if i+a[j]<=h else h
dp[next]=min(dp[next],dp[i]+b[j])
print(dp[-1])
| 0 | null | 40,919,251,603,090 | 53 | 229 |
n=int(input())
s='ACL'
print(s*n) | # -*- coding: utf-8 -*-
"""
Created on Sat Sep 26 21:02:43 2020
@author: liang
"""
K = int(input())
ans = ""
for i in range(K):
ans += "ACL"
print(ans) | 1 | 2,178,465,729,116 | null | 69 | 69 |
a1,a2,a3=(int(x) for x in input().split())
if a1+a2+a3>=22:
print("bust")
else:
print("win")
| n,k,*A=map(int,open(0).read().split());e=enumerate
for _ in '_'*min(k,99):
S=[0]*(n+1)
B=[0]*(n+1)
for i,a in e(A):S[max(0,i-a)]+=1;S[min(n,i+a+1)]-=1
for i,s in e(S[:-1]):B[i+1]=B[i]+s
A=B[1:]
print(*A) | 0 | null | 67,524,943,354,080 | 260 | 132 |
def main():
s = input()
if s == 'ABC':
print('ARC')
else:
print('ABC')
if __name__ == "__main__":
main()
| from itertools import product
n = int(input())
n_num = [[0] * 10 for _ in range(10)]
for i in range(n + 1):
a, b = int(str(i)[0]), i % 10
n_num[a][b] += 1
answer = sum(n_num[a][b] * n_num[b][a] for a, b in product(range(1, 10), repeat=2))
print(answer)
| 0 | null | 55,135,526,773,348 | 153 | 234 |
n=str(input())
a=list(n)
b=0
for i in a:
b=b+int(i)
if b%9==0:
print("Yes")
else:
print("No") | a, b, m = list(map(int, input().split()))
refrigerator_list = list(map(int, input().split()))
microwave_list = list(map(int, input().split()))
coupon_list = list()
for _ in range(m):
coupon_list.append(list(map(int, input().split())))
ans = min(refrigerator_list) + min(microwave_list)
for coupon in coupon_list:
ans = min(refrigerator_list[coupon[0] - 1] + microwave_list[coupon[1] - 1] - coupon[2], ans)
print(ans)
| 0 | null | 29,089,500,709,412 | 87 | 200 |
a, b, c, k = map(int, raw_input().split())
if k <= a:
print(k)
elif k <= a + b:
print(a)
else:
print(a - (k - a - b)) | x,k,d = map(int,input().split())
count = abs(x)//d
if x<0:
before_border = x+d*count
after_border = x+d*(count+1)
else:
before_border = x-d*count
after_border = x-d*(count+1)
if count >= k:
if x<0:
print(abs(x+d*k))
else:
print(abs(x-d*k))
else:
if (count-k)%2 == 0:
print(abs(before_border))
else:
print(abs(after_border)) | 0 | null | 13,454,276,966,240 | 148 | 92 |
N,K = map(int,input().split())
p = list(map(int,input().split()))
ans = sum(p[0:K])
s = ans
for i in range(1,N-K+1):
s += p[i+K-1]-p[i-1]
ans = max(ans,s)
print((K+ans)/2) | import bisect
N, M = map(int, input().split())
S = input()
ok = True
cnt = 0
for c in S:
if c == "1":
cnt += 1
if cnt == M:
ok = False
break
else:
cnt = 0
# 後ろから見て、各マスからもっとも近い右側の0の位置を格納(S[i]=0ならi)
ngo_pos = [0 for _ in range(N+1)]
most_neighbor_zero_pos = N
for i in range(N, -1, -1):
if S[i] == "0":
ngo_pos[i] = i
most_neighbor_zero_pos = i
else:
ngo_pos[i] = most_neighbor_zero_pos
if not ok:
print(-1)
else:
ans = []
pos = N
while pos > 0:
npos = ngo_pos[max(0, pos-M)]
ans.append(pos-npos)
pos = npos
print(" ".join(map(str, ans[::-1])))
| 0 | null | 106,947,589,457,298 | 223 | 274 |
# coding: utf-8
def main():
_ = int(input())
A = list(map(int, input().split()))
ans = 0
tmp = 0
total = sum(A)
for a in A:
tmp += a
if tmp >= total // 2:
ans = min(2 * tmp - total, total - 2 * (tmp - a))
break
print(ans)
if __name__ == "__main__":
main()
| import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
from collections import defaultdict
import bisect
def main():
N, K = MI()
ans = 0
p = 1
while p <= N:
p *= K
ans += 1
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 102,978,737,510,196 | 276 | 212 |
import os, sys, re, math
N = int(input())
X = [int(n) for n in input().split()]
d = [i ** 2 for i in range(101)]
min_v = 100 ** 2 * 100
for i in range(1, 101):
min_v = min(min_v, sum(d[abs(x - i)] for x in X))
print(min_v)
| import math
n = float(input())
area = "%.6f" % float(n **2 * math.pi)
circ = "%.6f" % float(n * 2 * math.pi)
print(area, circ) | 0 | null | 33,030,508,181,198 | 213 | 46 |
def culc(x):
a = x % 10
b = x
while x:
b = x
x //= 10
return a, b
n = int(input())
l = [[0 for i in range(9)] for j in range(9)]
ans = 0
for i in range(1,n+1):
a,b = culc(i)
if a != 0 and b != 0:
l[a-1][b-1] += 1
for i in range(1,n+1):
a,b = culc(i)
if a != 0 and b != 0:
ans += l[b-1][a-1]
print(ans) | import math
def makelist(n, m):
return [[0 for _ in range(m)] for _ in range(n)]
N = int(input())
sN = str(N)
l = len(sN)
ans = 0
for n in range(1, min(10, N+1)):
sn = str(n)
ans += 1
cnt = 1
for i in range(2, l):
ans += cnt
cnt *= 10
if l == 2:
if sN >= sn[-1] + sn[0]:
ans += 1
elif l > 2 and sN[0] >= sn[-1]:
if sN[0] == sn[-1]:
hoge = int(sN[1:-1])
if sN[-1] < sn[0]:
hoge -= 1
ans += hoge + 1
elif sN[0] > sn[-1]:
ans += cnt
for n in range(11, N+1):
sn = str(n)
if sn[-1] != "0":
if n > 10 and sn[0] == sn[-1]:
ans += 1
cnt = 1
for i in range(2, l):
ans += cnt
cnt *= 10
if l == 2:
if sN >= sn[-1] + sn[0]:
ans += 1
elif l > 2 and sN[0] >= sn[-1]:
if sN[0] == sn[-1]:
hoge = int(sN[1:-1])
if sN[-1] < sn[0]:
hoge -= 1
ans += hoge + 1
elif sN[0] > sn[-1]:
ans += cnt
print(ans)
| 1 | 86,502,749,699,372 | null | 234 | 234 |
S = int(input())
h = S//3600
m = S%3600//60
s = S%60
print(f"{h}:{m}:{s}")
| S = int(input())
print (S//3600, (S%3600)//60, S%60, sep = ":")
| 1 | 330,376,949,410 | null | 37 | 37 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10 ** 9 +7
K = int(readline())
S = readline().decode().rstrip()
s = len(S)-1
n = s+K
fact = [1] * (n+1)
fact_inv = [1] * (n+1)
for i in range(1,n+1):
fact[i] = fact[i-1] * i % mod
fact_inv[n] = pow(fact[n],mod-2,mod)
for i in range(n,0,-1):
fact_inv[i-1] = (i * fact_inv[i]) % mod
def comb(n,r):
return fact[n] * fact_inv[r] * fact_inv[n-r] % mod
ans = 0
for i in range(K+1):
ans += (comb(i+s,s) * pow(25,i,mod) % mod * pow(26,K-i,mod)) % mod
print(ans%mod) | K=int(input())
L=len(input())
from numba import*
@njit(cache=1)
def f():
m=10**9+7
max_n=2*10**6
fac=[1]*(max_n+1)
inv=[1]*(max_n+1)
ifac=[1]*(max_n+1)
for n in range(2,max_n+1):
fac[n]=(fac[n-1]*n)%m
inv[n]=m-inv[m%n]*(m//n)%m
ifac[n]=(ifac[n-1]*inv[n])%m
d=[1]*(K+1)
d2=[1]*(K+1)
for i in range(K):
d[i+1]=d[i]*25%m
d2[i+1]=d2[i]*26%m
a=0
for i in range(K+1):
a=(a+fac[L+i-1]*ifac[i]%m*ifac[L-1]%m*d[i]%m*d2[K-i]%m)%m
return a
print(f()) | 1 | 12,761,062,226,880 | null | 124 | 124 |
h1,m1,h2,m2,k = list(map(int,input().split()))
h_m = (h2 - h1)*60
m = m2 - m1
tz = h_m + m
print(tz-k)
| a = input().split()
print((int(a[2]) - int(a[0])) * 60 + (int(a[3]) - int(a[1])) - int(a[4]) ) | 1 | 18,133,223,657,120 | null | 139 | 139 |
s, t = input().split()
a, b = map(int, input().split())
u = input()
bnum = {s: a, t: b}
bnum[u] -= 1
print('{} {}'.format(bnum[s], bnum[t]))
| n, s = open(0).read().split()
s = list(map(int, list(s)))
from itertools import product,repeat
ans = 0
for a,b,c in product(range(10), range(10), range(10)):
abc = [a,b,c]
tmp = 0
for dig in s:
if dig == abc[tmp]:
tmp += 1
if tmp == 3:
ans += 1
break
print(ans) | 0 | null | 100,342,790,982,238 | 220 | 267 |
N = int(input())
for i in range(10):
if i==0:
continue
else:
i_pair = N / i
if N % i == 0 and i_pair < 10:
print("Yes")
exit()
print("No") | def main():
n = int(input())
L = []
for _ in range(n):
x,l = map(int,input().split())
L.append([x+l,x-l])
L.sort()
cnt = 0
right = -10**9
for r,l in L:
if right <= l:
cnt += 1
right = r
print(cnt)
main() | 0 | null | 125,188,629,736,570 | 287 | 237 |
line = input()
for _ in range(int(input())):
x = input().split()
order = x[0]
a = int(x[1])
b = int(x[2])+1
if order == "print":
print(line[a:b])
elif order == "reverse":
line = line[:a] + line[a:b][::-1] + line[b:]
elif order == "replace":
line = line[:a] + x[3] + line[b:]
| def run():
s=input()
command_num=int(input())
for i in range(command_num):
command = input().split()
command = list(map(lambda x: int(x) if x.isdigit() else x,command))
# print(s)
if command[0] == "print":
a=command[1]
b=command[2]
print(s[a:b+1])
elif command[0] == "reverse":
a=command[1]
b=command[2]
rev=s[a:b+1]
rev=rev[::-1]
#境界処理がめんどくさい
pre= "" if a==0 else s[0:a]
post="" if b==len(s)-1 else s[b+1:]
s=pre+rev+post
elif command[0] == "replace":
a=command[1]
b=command[2]
p=command[3]
#境界処理がめんどくさい
pre= "" if a==0 else s[0:a]
post="" if b==len(s)-1 else s[b+1:]
s=pre+p+post
else:
assert False
run()
| 1 | 2,089,544,069,572 | null | 68 | 68 |
a = list(map(int, input().split()))
b = a[0]
while b % a[1] != 0:
b += a[0]
print(b)
| a, b =map(int, input().split())
m = a*b
lst = []
for i in range(1, b+1):
if m < a*i:
break
lst.append(a*i)
for j in lst:
if j%b == 0:
print(j)
break | 1 | 112,883,881,329,910 | null | 256 | 256 |
S=input()
ch=""
for i in range(len(S)):
ch+="x"
print(ch) | def kougeki(H):
if H == 1:
return 1
else:
return 2 * kougeki(H//2) + 1
H = int(input())
print(kougeki(H)) | 0 | null | 76,469,867,870,308 | 221 | 228 |
#!python3
import sys
from collections import defaultdict
from math import gcd
iim = lambda: map(int, input().rstrip().split())
def resolve():
N = input()
it = map(int, sys.stdin.read().split())
mod = 10**9 + 7
d1 = [defaultdict(int), defaultdict(int)]
z0 = 0
for ai, bi in zip(it, it):
if ai == 0 and bi == 0:
z0 += 1
continue
ci = gcd(ai, bi)
ai, bi = ai // ci, bi // ci
t = ai * bi < 0
if ai < 0:
ai, bi = -ai ,-bi
elif ai == 0:
bi = -1
t = 1
d1[t][(ai, bi)] += 1
a1, a2 = d1
ans = 1
z1 = 0
for (ai, bi), v in a1.items():
k2 = (bi, -ai)
if k2 in a2:
v2 = a2[k2]
ans *= pow(2, v, mod) + pow(2, v2, mod) - 1
ans %= mod
else:
z1 += v
for (ai, bi), v in a2.items():
k2 = (-bi, ai)
if k2 in a1: continue
z1 += v
ans *= pow(2, z1, mod)
print((ans-1+z0) % mod)
if __name__ == "__main__":
resolve()
| a = list(map(int,input().split()))
print(15-sum(a)) | 0 | null | 17,324,742,992,008 | 146 | 126 |
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,K = map(int,readline().split())
H = list(map(int,readline().split()))
ans = 0
for h in H:
if h >= K:
ans += 1
print(ans) | class Node:
def __init__(self,v):
self.v = v
self.next = None
class Queue:
def __init__(self):
self.head = None
self.tail = None
self.size = 0
def enqueue(self,v):
self.size += 1
n = Node(v)
if self.tail == None:
self.tail = n
else:
self.tail.next = n
self.tail = n
if self.head == None:
self.head = self.tail
def dequeue(self):
if self.size == 0:
print 'underflow'
exit()
self.size -= 1
v = self.head.v
self.head = self.head.next
if self.head == None:
self.tail = None
return v
#class Queue:
# def __init__(self,l):
# self.values = []
# self.l = l
# for _ in range(l):
# self.values.append(None)
# self.head = 0
# self.tail = 0
# def inc(self,n):
# if n+1 >= self.l:
# return 0
# else:
# return n+1
# def enqueue(self,v):
# if self.inc(self.head) == self.tail:
# print 'overflow'
# exit()
# self.values[self.head] = v
# self.head = self.inc(self.head)
# def dequeue(self):
# if self.head == self.tail:
# print 'underflow'
# exit()
# v = self.values[self.tail]
# self.tail = self.inc(self.tail)
# return v
# def size(self):
# if self.head >= self.tail:
# return self.head-self.tail
# else:
# self.head + (self.l-self.tail)
n,q = map(int,raw_input().split(' '))
queue = Queue()
for _ in range(n):
n,t = raw_input().split(' ')
t = int(t)
queue.enqueue((n,t))
c = 0
while queue.size>0:
n,t = queue.dequeue()
if t <= q:
c += t
print n,c
else:
queue.enqueue((n,t-q))
c += q | 0 | null | 89,593,060,670,788 | 298 | 19 |
import sys
from collections import deque
input = sys.stdin.readline
def main():
n = int( input() )
input_a = list ( map( int, input().split() ) )
a = deque( input_a )
while( len(a) != 1 ):
x = a.popleft()
y = a.popleft()
z = x ^ y
a.append(z)
sum = a.popleft()
ans = []
for i in input_a:
x = i ^ sum
ans.append(x)
for i in ans:
print( i , end = ' ' )
main() | s = input().split('S')
m = 0
for i in s:
if len(i) > m:
m = len(i)
print(m)
| 0 | null | 8,655,569,568,100 | 123 | 90 |
S = list(input())
print('YNeos'[S[2::2]!=S[3::2]::2])
| S=str(input())
print('Yes' if S[2]==S[3] and S[4]==S[5] else 'No') | 1 | 41,935,121,236,700 | null | 184 | 184 |
input = input()
L, R, d = [int(n) for n in input.split()]
count = 0
for n in range(L, R+1):
if n % d == 0:
count += 1
print(count) | L,R,d = list(map(int, input().split()))
count = 0
for i in range(L,R+1):
count += (i%d == 0)
print(count) | 1 | 7,632,328,000,452 | null | 104 | 104 |
N = int(input())
A = input().split()
num_even = 0
num_approved = 0
for i in range(N):
if int(A[i]) % 2 == 0:
num_even += 1
if int(A[i]) % 3 == 0 or int(A[i]) % 5 == 0:
num_approved += 1
if num_even == num_approved:
print("APPROVED")
else:
print("DENIED")
| N = int(input())
S = list(map(int,input().split()))
B= list()
X = list()
for i in S:
if i % 2== 0:
B.append(i)
for n in B:
if n % 3 == 0 or n % 5 == 0:
X.append(n)
if len(B) == len(X):
print('APPROVED')
else:
print('DENIED')
| 1 | 68,805,470,559,668 | null | 217 | 217 |
class Queue:
def __init__(self, n):
self.values = [None]*n
self.n = n
self.s = 0
self.t = 0
def next(self, p):
ret = p+1
if ret >= self.n:
ret = 0
return ret
def enqueue(self, x):
if self.next(self.s) == self.t:
raise Exception("Overflow")
self.values[self.s] = x
self.s = self.next(self.s)
def dequeue(self):
if self.s == self.t:
raise Exception("Underflow")
ret = self.values[self.t]
self.t = self.next(self.t)
return ret
n, q = map(int, raw_input().split(' '))
queue = Queue(n+1)
for _ in range(n):
name, time = raw_input().split(' ')
time = int(time)
queue.enqueue((name, time))
completed = []
cur = 0
while len(completed) < n:
name, time = queue.dequeue()
res = time-q
if res <= 0:
cur += time
completed.append((name, cur))
else:
cur += q
queue.enqueue((name, res))
for name, time in completed:
print name, time | import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
n, k = LI()
N = 10**9+7
ans = 0
start = sum([i for i in range(0,k-1)])
goal = sum([i for i in range(n,n-k+1,-1)])
for i, j in zip(range(k-1,n+1), range(n-k+1,-1,-1)):
start += i
goal += j
cnt = (goal-start+1)%N
ans += cnt
ans %= N
print(ans)
main() | 0 | null | 16,719,233,196,028 | 19 | 170 |
N=int(input())
if N%1000==0:
print("0")
else:
n=((N-(N%1000))/1000)+1
print(int((1000*n)-N)) | pay = int(input())
if pay % 1000 == 0:
print(0)
else:
print(1000 - pay % 1000) | 1 | 8,464,856,548,720 | null | 108 | 108 |
from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
def f(x):
cnt = 0
for a in A:
cnt += ceil(a / x) - 1
return True if cnt <= K else False
OK, NG = 10**9, 0
while OK - NG > 1:
mid = (OK + NG) // 2
if f(mid):
OK = mid
else:
NG = mid
print(OK)
| import math
N, K = map(int, input().split())
a = list(map(int, input().split()))
def cal(x):
s = 0
for aa in a:
s += math.ceil(aa / x) - 1
if s <= K: return True
else: return False
l = 0
r = max(a)
while r - l > 1:
mid = (l + r) // 2
if cal(mid):
r = mid
else:
l = mid
print(r) | 1 | 6,562,801,695,160 | null | 99 | 99 |
a,b = map(int, input().split())
ans = 0
for i in range(10000):
x = int(i*0.08)
y = int(i*0.10)
if x == a and y == b:
ans = i
break
if ans == 0:
print(-1)
exit()
print(ans)
| MOD = 998244353
N,K = map(int,input().split())
l = []
dp = [0]*N
sdp = [0]*(N+1)
for i in range(K):
L,R = map(int,input().split())
l.append([L,R])
dp[0] = 1
sdp[1] = 1
for i in range(1,N):
for L, R in l:
dp[i] += sdp[max(0,i - L+1)] - sdp[max(0,i - R)]
dp[i] %= MOD
sdp[i+1] = sdp[i] + dp[i]
sdp[i+1] %= MOD
print(dp[N-1]) | 0 | null | 29,564,110,925,012 | 203 | 74 |
import sys
input = sys.stdin.readline
import bisect
import math
# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
a, b, n = input_list()
x = min(b-1, n)
aa = math.floor((a*x)/b) - (a * math.floor(x/b))
print(aa)
def bi(num, a, b, x):
print((a * num) + (b * len(str(b))))
if (a * num) + (b * len(str(b))) <= x:
return False
return True
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| import sys
def input():
return sys.stdin.readline()[:-1]
def main():
A, B, N = map(int,input().split())
if B - 1 <= N:
print(A * (B - 1) // B)
else:
print(A * N // B)
if __name__ == "__main__":
main() | 1 | 27,986,338,934,820 | null | 161 | 161 |
N = int(input())
a_list = list(map(int, input().split()))
#print(a_list)
myans = 0
for a, b in enumerate(a_list):
#print(a,b)
if (a+1)%2 != 0 and b%2 != 0:
myans += 1
print(myans) | a, b, c = map(int, input().split())
if a / c <= b:
print("Yes")
else:
print("No")
| 0 | null | 5,607,437,678,478 | 105 | 81 |
# パナソニック2020D
import sys
def write(x):
sys.stdout.write(x)
sys.stdout.write("\n")
from queue import deque
n = int(input())
q = deque([("a", "a")])
while True:
s, m = q.pop()
if len(s)==n:
write(s)
elif len(s)>=n+1:
break
for o in range(ord("a"), ord(m)+2):
if ord(m)<o:
m = chr(o)
q.appendleft((s + chr(o), m)) | n = int(input())
def dfs(s):
if len(s) == n:
print(s)
return
for i in range(ord("a"), ord(max(s))+2):
dfs(s+chr(i))
dfs("a") | 1 | 52,375,372,341,248 | null | 198 | 198 |
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
ans = [[0] * W for _ in range(H)]
cur = 1
for i in range(H):
has_st = []
for j in range(W):
if S[i][j] == "#":
has_st.append(j)
if not has_st:
continue
elif len(has_st) == 1:
ans[i] = [cur] * W
cur += 1
else:
for j in range(has_st[-1] + 1):
ans[i][j] = cur
if S[i][j] == "#":
cur += 1
ans[i][has_st[-1] + 1 :] = [cur - 1] * (W - has_st[-1] - 1)
for i in range(H - 1):
if ans[i + 1] == [0] * W:
ans[i + 1] = ans[i][:]
for i in range(H - 1, 0, -1):
if ans[i - 1] == [0] * W:
ans[i - 1] = ans[i][:]
[print(" ".join(map(str, row))) for row in ans]
| k,n = map(int,(input().split()))
a = list(map(int,input().split()))
maxDis = 0
for i in range(len(a)-1):
if i == 0:
maxDis = a[i]+k-a[i-1]
elif abs(a[i]-a[i-1]) > maxDis:
maxDis = abs(a[i]-a[i-1])
if abs(a[i]-a[i+1]) > maxDis:
maxDis = abs(a[i]-a[i+1])
print(k-maxDis)
| 0 | null | 93,761,833,608,480 | 277 | 186 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n = int(input())
a=n//2+(n%2)
print(a/n)
| n=int(input())
print(-~n//2/n) | 1 | 177,116,998,577,584 | null | 297 | 297 |
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
N = getN()
query = [getList() for i in range(N)]
r_l = []
for x, l in query:
r_l.append([x - l, x + l])
r_l.sort(key = lambda i:i[1])
cnt = 0
last = r_l[0][1]
for i in range(1, N):
if r_l[i][0] < last:
cnt += 1
else:
last = r_l[i][1]
print(N - cnt) | k,n=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
a.append(k+a[0])
b=[0]*(n)
for i in range(n):
b[i]=a[i+1]-a[i]
print(k-max(b))
| 0 | null | 66,884,723,075,520 | 237 | 186 |
n=int(input())
num_line=list(map(int,input().split()))
num_line.reverse()
print(" ".join(map(str,num_line)))
| n = int(input())
a = list(map(int, input().split()))
#print(a)
a.reverse()
print(*a)
| 1 | 963,967,019,808 | null | 53 | 53 |
# -*- coding: utf-8 -*-
def main():
s = input()
t = s[::-1]
n = len(s) // 2
count = 0
for i in range(n):
if s[i] != t[i]:
count += 1
print(count)
if __name__ == '__main__':
main()
| x = input()
a = x[::-1]
b = 0
c = 0
d = int(len(x))
while b + 1 <= d:
if x[b] == a[b]:
c = c
b = b + 1
else:
c = c + 1
b = b + 1
c = int(c/2)
print(c) | 1 | 119,718,131,692,672 | null | 261 | 261 |
N, M ,L = map(int, input().split())
print(M//L-(N-1)//L) |
def main():
S = input()
print("x"*len(S))
if __name__ == "__main__":
main() | 0 | null | 40,270,666,158,128 | 104 | 221 |
from collections import Counter
N=int(input())
A=list(map(int, input().split()))
count = Counter(A)
vals = count.values()
sum_ = 0
for v in vals:
if v >= 2: sum_ += v*(v-1)
sum_ //= 2
for k in range(N):
if count[A[k]] < 2: print(sum_)
else:print(sum_ + 1 - count[A[k]]) | from string import ascii_lowercase
N = int(input())
ans = ['a']
for i in range(1, N):
ans2 = []
for a in ans:
for b in ascii_lowercase[:len(set(a)) + 1]:
ans2 += [a + b]
ans = ans2
print('\n'.join(ans))
| 0 | null | 50,090,142,421,870 | 192 | 198 |
import math
def main():
n = int(input())
ans = 0
for i in range(n):
x = int(input())
if x == 2:
ans += 1
elif x % 2 == 0:
pass
else:
flag = True
j = 3
while j <= math.sqrt(x):
if x % j == 0:
flag = False
break
j += 2
if flag:
ans += 1
print(ans)
if __name__ == '__main__':
main()
| class dice:
directions = ['S', 'E', 'N', 'W']
def __init__(self, strlabels):
label = strlabels.split()
self.top = label[0]
self.side = label[1:5]
self.side[2], self.side[3] = self.side[3], self.side[2]
self.down = label[5]
#print(self.top, self.side, self.down)
def roll(self, direction):
tmp = self.top
self.top = self.side[(self.directions.index(direction)+2)%4]
self.side[(self.directions.index(direction)+2)%4] = self.down
self.down = self.side[self.directions.index(direction)]
self.side[self.directions.index(direction)] = tmp
#print(self.top, self.side, self.down)
def pFace(self, initial):
if initial == 'u':
print(self.top)
elif initial == 'd':
print(self.down)
else:
print(self.side[directions.index(direction)])
dice1 = dice(input())
for direction in input():
dice1.roll(direction)
dice1.pFace('u') | 0 | null | 122,307,000,110 | 12 | 33 |
n = int(input())
list = [i for i in input().split()]
list.reverse()
print(" ".join(list)) | input()
data = input().split()
data.reverse()
print(' '.join(data)) | 1 | 978,864,140,008 | null | 53 | 53 |
N, M = map(int, input().split())
H = [0] + list(map(int, input().split()))
g = [[] for _ in range(N+1)]
for i in range(M):
a, b = map(int, input().split())
g[a].append(b)
g[b].append(a)
ans = 0
for j in range(1, N+1):
for k in g[j]:
if H[j] <= H[k]:
break
else:
ans += 1
print(ans) | n = list(input())
for i in range(len(n)) :
n[i] = int(n[i])
if sum(n)%9==0 :
print("Yes")
else :
print("No") | 0 | null | 14,875,596,027,200 | 155 | 87 |
N = int(input())
XL = [tuple(map(int, input().split())) for i in range(N)]
XL.sort(key=lambda x: x[0] + x[1])
ans = 0
prev = - 10**9
for x, l in XL:
if prev <= x - l:
ans += 1
prev = x + l
print(ans)
| import math , sys
N = int( input() )
X = []
for i in range(N):
A , B = list(map(int, input().split()))
X.append([i , A-B , A , A+B])
X.sort(key=lambda x: x[3])
Y = X[0]
Ri = Y[-1]
ans = 1
j=0
for i in range(1,N):
Y = X[i]
if Y[1] >= Ri:
ans+=1
Ri = Y[-1]
print(ans)
| 1 | 89,985,588,747,110 | null | 237 | 237 |
import sys
from functools import lru_cache
from collections import defaultdict
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
return int(readline())
def reads():
return map(int, readline().split())
a,b,n=reads()
x=min(b-1,n)
print(int((a*x)/b))
| from math import floor
A,B,N=map(int,input().split())
ans=A*(B-1)//B
if N<B:
ans=A*N//B
print(ans) | 1 | 28,097,971,633,502 | null | 161 | 161 |
from collections import deque
import copy
H, W = map(int, input().split())
route = []
for _ in range(H):
route.append(input())
wall = set()
start = set()
for y, r in enumerate(route):
for x, w in enumerate(r):
if w == '.':
start.add((x, y))
score = -1
ssize = [(-1,0),(0,-1),(1,0),(0,1)]
for xy in start:
d = deque()
d.append((xy+(0,)))
step = 0
can = copy.deepcopy(start)
can.remove(xy)
while len(d) > 0:
now = d.popleft()
step = now[2]
for xs, ys in ssize:
nxt = (now[0]+xs, now[1]+ys)
if nxt in can:
d.append(nxt+(step+1,))
can.remove(nxt)
score = max(step, score)
print(score) | import sys
from io import StringIO
import unittest
import os
from collections import deque
# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)
# 実装を行う関数
def resolve(test_def_name=""):
# 数値取得サンプル
# 1行1項目 n = int(input())
# 1行2項目 h, w = map(int, input().split())
# 1行N項目 x = list(map(int, input().split()))
# N行1項目 x = [int(input()) for i in range(n)]
# N行N項目 x = [list(map(int, input().split())) for i in range(n)]
# 文字取得サンプル
# 1行1項目 x = input()
# 1行1項目(1文字ずつリストに入れる場合) x = list(input())
h, w = map(int, input().split())
maze = [list(input()) for i in range(h)]
start_list = []
for i_len, i in enumerate(range(h)):
for j_len, j in enumerate(range(w)):
route = 4
# 自分が壁なら対象外
if maze[i][j] == "#":
continue
# 上下端なら-1
route -= 1 if i_len == 0 else 0
route -= 1 if i_len + 1 == h else 0
# 上下が壁なら-1
route -= 1 if not i_len == 0 and maze[i - 1][j] == "#" else 0
route -= 1 if not i_len + 1 == h and maze[i + 1][j] == "#" else 0
# 左右端なら-1
route -= 1 if j_len == 0 else 0
route -= 1 if j_len + 1 == w else 0
# 左右が壁なら-1
route -= 1 if not j_len == 0 and maze[i][j - 1] == "#" else 0
route -= 1 if not j_len + 1 == w and maze[i][j + 1] == "#" else 0
if route <= 2:
start_list.append((i, j))
ans = 0
que = deque()
for start in start_list:
que.appendleft(start)
ed_list = [[-1 for i in range(w)] for j in range(h)]
ed_list[start[0]][start[1]] = 0
# BFS開始
while len(que) is not 0:
now = que.pop()
# 各方向に移動
for i, j in [(1, 0), (0, 1), (0, -1), (-1, 0)]:
# 処理対象の座標
target = [now[0] + i, now[1] + j]
# 処理対象のチェック
# 外なら何もしない
if not 0 <= target[0] < h or not 0 <= target[1] < w:
continue
# 距離が設定されているなら何もしない
if ed_list[target[0]][target[1]] != -1:
continue
# 壁なら何もしない
if maze[target[0]][target[1]] == "#":
continue
# 処理対象に対する処理
# キューに追加(先頭に追加するのでappendleft())
que.appendleft(target)
# 距離を設定(現在の距離+1)
ed_list[target[0]][target[1]] = ed_list[now[0]][now[1]] + 1
ans = max(ans, ed_list[target[0]][target[1]])
print(ans)
# テストクラス
class TestClass(unittest.TestCase):
def assertIO(self, assert_input, output):
stdout, sat_in = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
resolve(sys._getframe().f_back.f_code.co_name)
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, sat_in
self.assertEqual(out, output)
def test_input_1(self):
test_input = """3 3
...
...
..."""
output = """4"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """3 5
...#.
.#.#.
.#..."""
output = """10"""
self.assertIO(test_input, output)
# 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
def test_1original_1(self):
test_input = """1 2
.."""
output = """1"""
self.assertIO(test_input, output)
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
| 1 | 94,746,383,594,288 | null | 241 | 241 |
N = int(input())
A = list(map(int, input().split()))
dp = [{} for _ in range(N + 2)]
dp[0][0] = 0
dp[-1][0] = 0
for i in range(1, N + 1):
f = (i - 1) // 2
t = (i + 1) // 2
for j in range(f, t + 1):
var1 = dp[i - 2][j - 1] + A[i - 1] if j - 1 in dp[i - 2] else -float('inf')
var2 = dp[i - 1][j] if j in dp[i - 1] else -float('inf')
dp[i][j] = max(var1, var2)
print(dp[N][N // 2])
| # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().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
@mt
def slv(N, A):
m = N // 2
dp = [defaultdict(lambda: -INF)] * 2
dp[0][0] = 0
for i, a in enumerate(A):
ndp = [defaultdict(lambda: -INF)] * 2
l = m - ((N-i) // 2)
ndp[0] = dp[1]
for k, v in dp[0].items():
if k+1 >= l:
ndp[1][k+1] = max(ndp[1][k+1], v+a)
if k+2 >= l:
ndp[0][k] = max(ndp[0][k], v)
dp = ndp
return max(dp[0][m], dp[1][m])
def main():
N = read_int()
A = read_int_n()
print(slv(N, A))
if __name__ == '__main__':
main()
| 1 | 37,477,313,305,178 | null | 177 | 177 |
X,Y = map(int,input().split())
M = max(X,Y)
m = min(X,Y)
mod = 10 ** 9 + 7
con = (X + Y) // 3
dif = M - m
n = (con - dif) // 2
if (X + Y) % 3 != 0 or n < 0:
print(0)
else:
def comb(n, r):
n += 1
over = 1
under = 1
for i in range(1,r + 1):
over = over * (n - i) % mod
under = under * i % mod
#powでunder ** (mod - 2) % modを実現、逆元を求めている
return over * pow(under,mod - 2,mod) % mod
ans = comb(con,n)
print(ans) | X, Y = map(int, input().split())
MOD = 10 ** 9 + 7
S = -X + 2 * Y
T = 2 * X - Y
if S < 0 or T < 0:
print(0)
exit()
if S % 3 != 0 or T % 3 != 0:
print(0)
exit()
S //= 3
T //= 3
def cmb(n, r, p):
r = min(n - r, r)
if r == 0:
return 1
over = 1
for i in range(n, n - r, -1):
over = over * i % p
under = 1
for i in range(1, r + 1):
under = under * i % p
inv = pow(under, p - 2, p)
return over * inv % p
# print(S, T)
ans = cmb(S + T, S, MOD) % MOD
print(ans % MOD)
| 1 | 150,297,854,995,428 | null | 281 | 281 |
"""
Template written to be used by Python Programmers.
Use at your own risk!!!!
Owned by enraged(rating - 5 star at CodeChef and Specialist at Codeforces).
"""
import sys
import bisect
import heapq
# from math import *
from collections import defaultdict as dd # defaultdict(<datatype>) Free of KeyError.
from collections import deque # deque(list) append(), appendleft(), pop(), popleft() - O(1)
from collections import Counter as c # Counter(list) return a dict with {key: count}
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
# sys.setrecursionlimit(2*pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(var)
def l(): return list(map(int, data().split()))
def sl(): return list(map(str, data().split()))
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [[val for i in range(n)] for j in range(m)]
n, p = sp()
s = data()
answer = 0
if p == 2:
for i in range(n):
if (ord(s[i])-ord('0')) % 2 == 0:
answer += (i+1)
elif p == 5:
for i in range(n):
if int(s[i]) % 5 == 0:
answer += (i+1)
else:
dp = dd(int)
dp[0] += 1
a, tens = 0, 1
for i in range(n-1, -1, -1):
a = (a + int(s[i]) * tens) % p
answer += dp[a]
dp[a] += 1
tens = (tens * 10) % p
out(str(answer))
exit(0)
| N, K, C = map(int, input().split())
S = input()
length = len(S)
INF = float('inf')
Ls = [-INF]
n = 0
for i, c in enumerate(S):
if c == 'o' and i - Ls[-1] > C:
Ls.append(i)
n += 1
if n >= K: break
Rs = [INF]
n = 0
for i, c in enumerate(reversed(S)):
if c == 'o' and Rs[-1] - (length-1-i) > C:
Rs.append(length-1-i)
n += 1
if n >= K: break
Rs.reverse()
for l, r in zip(Ls[1:], Rs[:-1]):
if l == r:
print(l+1)
| 0 | null | 49,347,581,052,680 | 205 | 182 |
n,k = list(map(int,input().split()))
point = list(map(int,input().split()))
rsp = ['r', 's', 'p']
t = input()
m = [rsp[rsp.index(i)-1] for i in t]
ans = 0
for i in range(n):
if i<k :
ans += point[rsp.index(m[i])]
else:
if m[i]!=m[i-k]:
ans += point[rsp.index(m[i])]
else:
try:
m[i] = rsp[rsp.index(m[i+k])-1]
except:
pass
# print(ans)
print(ans) | # ans
N = int(input())
ans = [0] * (N + 1)
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
n = x * x + y * y + z * z + x * y + y * z + z * x
if n <= N:
ans[n] += 1
for i in range(1, len(ans)):
print(ans[i]) | 0 | null | 57,694,655,275,460 | 251 | 106 |
n = int(input())
t = 0
h = 0
for i in range(n):
tc, hc = input().split()
if tc > hc:
t += 3
elif tc < hc:
h += 3
elif tc == hc:
t += 1
h += 1
print(str(t)+' '+str(h)) | n=int(input())
a=0
b=0
for i in range(n):
c,d=input().split()
if c<d:
b+=3
elif c>d:
a+=3
else:
b+=1
a+=1
print(a,b)
| 1 | 2,000,613,581,354 | null | 67 | 67 |
N = int(input())
S, T = map(str,input().split())
for s, t in zip(S, T):
print(s+t, end='') | N = int(input())
list1, list2 = input().split()
str = ''
for i, j in zip(list1, list2):
str += f'{i}{j}'
print(str) | 1 | 112,429,822,394,120 | null | 255 | 255 |
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
from functools import lru_cache
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7
def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def main():
X = int(input())
print(X * 360 // math.gcd(360, X) // X)
if __name__ == "__main__":
main()
| n,k = map(int,input().split())
A = list(map(int,input().split()))
c = 0
from collections import Counter
d = Counter()
d[0] = 1
ans = 0
r = [0]*(n+1)
for i,x in enumerate(A):
if i>=k-1:
d[r[i-(k-1)]]-=1#ここで範囲kからはみ出たものの数を減らす
c = (c+x-1)%k
ans += d[c]
d[c] += 1
r[i+1] = c
print(ans) | 0 | null | 74,977,386,027,460 | 125 | 273 |
import collections
N = int(input())
ls = []
for i in range(N):
ls.append(input())
counter = collections.Counter(ls)
print(len(counter.keys())) | N = int(input())
S = [input() for i in range(N)]
S.sort()
cnt = 1
for i in range(1, N):
if S[i]!=S[i-1]:
cnt += 1
print(cnt) | 1 | 30,259,597,654,948 | null | 165 | 165 |
from math import sqrt
n = int(input())
p = 0
for i in range(n):
x = int(input())
ad = 1
if x>2 and x%2==0:
ad = 0
else:
j=3
while j < (int(sqrt(x))+1):
if x%j == 0:
ad = 0
break
else:
j += 2
p += ad
print(p)
| def p(x):
i=2
while i<=x**.5:
if x%i==0:return 0
i+=1
return 1
n=int(input())
print(sum([p(int(input()))for _ in range(n)])) | 1 | 10,573,635,480 | null | 12 | 12 |
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
res=0
m=1
for i in a:
b=m-i
if b<0:
print(-1)
exit(0)
res+=i
res+=b
s-=i
m=min(b*2,s)
print(res)
| s,t=raw_input().split()
print t+s | 0 | null | 61,129,749,671,980 | 141 | 248 |
N, K = map(int, input().split())
def f(x):
return( N-x*K )
def test(x):
return( f(x) >= 0 )
left = - 1 # return = right = (取り得る値の最小値) の可能性を排除しないために、-1 が必要
right = 10**18
while right - left > 1: # 最終的に (right, left, mid) = (最小値, 最小値 - 1, 最小値 - 1) に収束するため、差が 1 になったときに終了すればよい
mid = (left+right)//2
if test(mid):
left = mid
else:
right = mid
print(min(abs(N-left*K), abs(N-right*K))) | n, k = list(map(int, input().split()))
if n < k:
ans = min(n, abs(n - k))
else:
q = n // k
ans = min(abs(n - (q * k)), abs(n - (q * k) - k))
print(ans)
| 1 | 39,486,410,891,990 | null | 180 | 180 |
N = int(input())
BOX = {}
for i in range(N):
S = input()
if S in BOX:
BOX[S] = (BOX[S] + 1)
else:
BOX[S] = 0
MAX = max(BOX.values())
keys = [k for k, v in BOX.items() if v == MAX]
keys = sorted(keys)
for i in range(len(keys)):
print(keys[i])
| x = int(input())
prlist = []
n = 2
sosuu = 0
answer = 0
while n**2 < x:
for i in prlist:
if n % i == 0:
sosuu = 1
break
if sosuu == 0:
prlist.append(n)
sosuu = 0
n += 1
sosuu = 1
while answer == 0:
for j in prlist:
if x % j == 0:
sosuu = 2
break
if sosuu == 1:
answer = x
sosuu = 1
x += 1
print(answer) | 0 | null | 87,529,013,146,112 | 218 | 250 |
import math
import sys
import os
from operator import mul
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))
if os.getenv("LOCAL"):
inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
sys.stdin = open(inputFile, "r")
INF = float("inf")
a = I()
ans = a * (1+a+a**2)
print(ans) | t_hp, t_atk, a_hp, a_atk = map(int, input().split())
t_count = 0
a_count = 0
while a_hp > 0:
a_hp -= t_atk
t_count += 1
while t_hp > 0:
t_hp -= a_atk
a_count += 1
if t_count <= a_count:
print('Yes')
else:
print('No')
| 0 | null | 20,066,540,102,308 | 115 | 164 |
def main():
s = input()
n = len(s)
for i in range(n//2):
if s[i] != s[n-1-i]:
print("No")
return
s1 = s[:(n-1)//2]
s2 = s[(n+3)//2-1:]
n1 = len(s1)
for i in range(n//4):
if s1[i] != s[n1-1-i]:
print("No")
return
if s2[i] != s[n1-1-i]:
print("No")
return
print("Yes")
if __name__ == "__main__":
main() | S = input()
N = len(S)
S1 = S[0:(N-1)//2]
S2 = S[(N+3)//2-1:]
print('Yes' if S == S[::-1] and S1 == S1[::-1] and S2 == S2[::-1] else 'No') | 1 | 46,298,907,381,000 | null | 190 | 190 |
import sys
input = sys.stdin.readline
# A - Study Scheduling
h1, m1, h2, m2, k = map(int, input().split())
minute = (h2 - h1) * 60 + (m2 -m1)
print(minute - k) | import datetime
h,m,eh,em,k = map(int,input().split())
start = h*60 + m
end = eh*60 + em
if end - start > k:
print(end - k - start)
else:
print(0) | 1 | 18,018,840,455,568 | null | 139 | 139 |
S = input()
s = len(S)
ct = 0
for i in range(s):
if S[i] != S[(-i-1)]:
ct += 1
print(ct//2)
| from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
s = input()
cnt = 0
for i in range(len(s)//2):
if s[i] != s[-1-i]:
cnt += 1
print(cnt) | 1 | 120,058,170,887,630 | null | 261 | 261 |
import collections
N = int(input())
P = [[0 for _ in range(N)] for _ in range(N)]
for i in range(N):
u,k,*varray = map(int,input().split()) # u,k は数, varray は配列
for v in varray:
P[u-1][v-1] = 1
D = [-1 for _ in range(N)]
D[0] = 0 # 始点への距離は 0, 他の距離は-1
Q = collections.deque()
Q.append(0)
while len(Q) > 0:
c = Q.popleft()
for i in range(N):
if P[c][i]==1 and D[i]==-1:
D[i] = D[c]+1
Q.append(i)
for v in range(N):
print(v+1, D[v])
| import sys
input = sys.stdin.readline
s = list(input())
a = 0
#print(len(s))
for i in range((len(s) - 1) // 2):
#print(s[i], s[-2-i])
if s[i] != s[-2-i]:
a += 1
print(a) | 0 | null | 60,008,328,862,088 | 9 | 261 |
def merge(A, n, left, mid, right):
L = A[left:mid]
R = A[mid:right]
L.append(2000000000) # これをしないとマージするとき、最後の1回でリスト外アクセスでエラー。
R.append(2000000000)
global count
i, j = 0, 0
# print('left, mid, right')
# print(left, mid, right)
for k in range(left, right, 1):
count += 1
# print('i, j, k')
# print(i, j, k)
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
# print('loop end')
def merge_sort(A, n, left, right):
if right - left > 1:
mid = (left + right) // 2
merge_sort(A, n, left, mid)
merge_sort(A, n, mid, right)
merge(A, n, left, mid, right)
N = int(input())
A = list(map(int, input().split()))
count = 0
merge_sort(A, N, 0, N)
print(' '.join(map(str, A)))
print(count)
| print(int((int(input())/2)+0.6)) | 0 | null | 29,705,810,194,940 | 26 | 206 |
# coding: utf-8
def solve(*args: str) -> str:
n = int(args[0])
A = list(map(int, args[1].split()))
rem = sum(A)
cur = 1
ret = 0
for a in A:
cur = min(rem, cur)
rem -= a
ret += cur
cur = 2*(cur-a)
if cur < 0:
ret = -1
break
return str(ret)
if __name__ == "__main__":
print(solve(*(open(0).read().splitlines())))
| import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
leaf = sum(A)
ans = 0
node = 1
for i in range(N+1):
if A[i] > node or leaf == 0:
ans = -1
break
ans += node
leaf -= A[i]
node = min(2*(node-A[i]), leaf)
print(ans)
| 1 | 18,810,576,931,958 | null | 141 | 141 |
from collections import Counter
ABC = list(map(int, input().split()))
ABC = Counter(ABC)
if len(ABC) == 2:
ans = 'Yes'
else:
ans = 'No'
print(ans)
| print('NYoe s'[len(set(map(int,input().split())))==2::2]) | 1 | 67,744,582,309,808 | null | 216 | 216 |
apple = list(map(int, input().split()))
x = apple[0]
y = apple[1] #to eat
a = apple[2]
b = apple[3] #i have
c = apple[4]
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
XredApl = []
for i in range(x):
XredApl.append(p[i])
YgrnApl = []
for i in range(y):
YgrnApl.append(q[i])
fnlst = XredApl + YgrnApl + r
fnlst.sort(reverse=True)
s = 0
for i in range(x+y):
s += fnlst[i]
print(s)
| x=int(input())
X=x%100
Y=x//100
if X>5*Y:
print('0')
else:
print('1') | 0 | null | 86,174,024,710,972 | 188 | 266 |
x = int(input())
while x == 0:
x += 1
print(x)
exit(0)
while x == 1:
x -= 1
print(x)
exit(0) | print(1-int(input()))
| 1 | 2,927,867,691,142 | null | 76 | 76 |
print(input()[0:3]) | def resolve():
N, X, M = map(int,input().split())
A_list = [X]
preA = X
A_set = set(A_list)
for i in range(N-1):
A = preA**2%M
if A == 0:
answer = sum(A_list)
break
elif A in A_set:
finished_count = len(A_list)
# 何番目か確認
same_A_index = A_list.index(A)
one_loop = A_list[same_A_index:]
loop_count, part_loop = divmod(N-finished_count, len(one_loop))
answer = sum(A_list) + sum(one_loop)*loop_count + sum(one_loop[:part_loop])
break
A_list.append(A)
A_set.add(A)
preA = A
else:
answer = sum(A_list)
print(answer)
resolve() | 0 | null | 8,794,697,770,880 | 130 | 75 |
import math
x = int(input())
y = x
while True:
flg = 0
for i in range(2,math.ceil(y**0.5)):
if y%i == 0:
flg = 1
break
if flg == 0:
print(y)
break
y += 1 | 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 issame(self, x, y):
return self.find[x] == self.find(y)
'''
参考
https://qiita.com/K_SIO/items/03ff1fc1184cb39674aa#d-friends
'''
if __name__ == '__main__':
N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
A, B = map(int, input().split())
uf.union(A-1, B-1)
ans = 0
for i in range(N):
ans = max(ans, uf.size(i))
print(ans)
| 0 | null | 54,477,348,903,718 | 250 | 84 |
import sys
str = input()
if str[2] == str[3]:
if str[4] == str[5]:
print("Yes")
sys.exit()
print("No") | import queue
N=int(input())
M=[input().split()[2:]for _ in[0]*N]
q=queue.Queue();q.put(0)
d=[-1]*N;d[0]=0
while q.qsize()>0:
u=q.get()
for v in M[u]:
v=int(v)-1
if d[v]<0:d[v]=d[u]+1;q.put(v)
for i in range(N):print(i+1,d[i])
| 0 | null | 21,175,626,022,670 | 184 | 9 |
import sys
import numpy as np
n, k = map(int,input().split())
a = np.array(sorted(list(map(int, input().split()))))
f = np.array(sorted(list(map(int, input().split())), reverse=True))
asum = a.sum()
l,r = 0, 10**13
while l != r:
mid = (l+r)//2
can = (asum - np.minimum(mid//f, a).sum()) <= k
if can:
r = mid
else:
l = mid +1
print(l) | for i in range(1, 10):
for j in range(1, 10):
print (u"%dx%d=%d"%(i,j,i*j)) | 0 | null | 82,506,035,879,890 | 290 | 1 |
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/5/ALDS1_5_B
n = int(input())
A = list(map(int, input().split()))
# マージソート
def merge_sort(arr, left, right):
# merge_sort(lst, 0, len(lst))
global cnt
if right - left == 1:
return
mid = left + (right - left) // 2
merge_sort(arr, left, mid)
merge_sort(arr, mid, right)
a = [arr[i] for i in range(left, mid)] \
+ [arr[i] for i in range(right - 1, mid - 1, -1)]
iterator_left = 0
iterator_right = len(a) - 1
for i in range(left, right):
cnt += 1
if a[iterator_left] <= a[iterator_right]:
arr[i] = a[iterator_left]
iterator_left += 1
else:
arr[i] = a[iterator_right]
iterator_right -= 1
cnt = 0
merge_sort(A, 0, n)
print(*A)
print(cnt)
|
def read_input():
h, n = map(int, input().split())
magic = {}
for i in range(n):
a, b = map(int, input().split())
magic[i] = (a, b)
return h, n, magic
def submit():
h, n, magic = read_input()
dp = [float('inf') for _ in range(h + 1)]
dp[h] = 0
for i in reversed(range(1, h + 1)):
for a, b in magic.values():
# 更新する
# max(0, i - a)のHPにより少ない魔力消費量で行き着ければ更新する
rest = max(0, i - a)
if dp[rest] > dp[i] + b:
dp[rest] = dp[i] + b
print(dp[0])
submit() | 0 | null | 40,641,193,854,980 | 26 | 229 |
n = int(input())
a = list(map(int,input().split()))
b = ['0']*n
for i in range(n):
m = a[i]
b[m-1] = str(i+1)
print(' '.join(b)) | H1, M1, H2, M2, K = map(int, input().split())
s = H1*60 + M1
e = H2*60 + M2
print(e - K - s) | 0 | null | 99,571,770,261,732 | 299 | 139 |
def main():
n = int(input())
a_lst = list(map(int, input().split()))
dic = dict()
for i in range(n - 1):
if a_lst[i] in dic:
dic[a_lst[i]] += 1
else:
dic[a_lst[i]] = 1
dic_keys = dic.keys()
for i in range(1, n + 1):
if i in dic_keys:
print(dic[i])
else:
print(0)
if __name__ == "__main__":
main()
| n=int(input())
for i in range(int(n**0.5), 0, -1):
if n%i==0:
print(int(n/i+i-2))
exit() | 0 | null | 96,795,882,580,480 | 169 | 288 |
i=lambda:int(input());c=max(i(),i());print(0--i()//c) | h,w,n = int(input()),int(input()),int(input())
ans = 0
s = 0
while s < n:
s += max(h,w)
ans += 1
print(ans) | 1 | 89,092,822,372,522 | null | 236 | 236 |
S=input();N=len(S);print(sum(S[i]!=S[N-i-1] for i in range(N//2))) | i=0
xArray=[]
yArray=[]
while True:
x,y=(int(num) for num in input().split())
if x==0 and y==0:
break
else:
xArray.append(x)
yArray.append(y)
i+=1
for count in range(i):
if xArray[count] < yArray[count]:
print(xArray[count],yArray[count])
else:
print(yArray[count],xArray[count])
| 0 | null | 60,394,053,814,402 | 261 | 43 |
#cやり直し
import numpy
n = int(input())
a = list(map(int, input().split()))
ans = 0
mod = 10**9 +7
before = a[-1]
for i in range(n-1,0,-1):
ans += (a[i-1]*before)%mod
before += a[i-1]
print(ans%mod) | import sys
import math
import collections
def set_debug(debug_mode=False):
if debug_mode:
fin = open('input.txt', 'r')
sys.stdin = fin
def int_input():
return list(map(int, input().split()))
def get(s):
return str(s % 9) + '9' * (s // 9)
if __name__ == '__main__':
# set_debug(True)
# t = int(input())
t = 1
for ti in range(1, t + 1):
n = int(input())
A = int_input()
cur = 0
for x in A:
cur = x ^ cur
res = []
for x in A:
res.append(cur ^ x)
print(*res)
| 0 | null | 8,112,842,585,354 | 83 | 123 |
k = int(input())
a,b = map(int, input().split())
def judge(a,b):
for i in range(a,b+1):
if i%k == 0: return 'OK'
return 'NG'
print(judge(a,b)) | N=int(input())
X=list(map(int, input().split()))
power_min = 1e8
for P in range(1,101):
power = 0
for i in range(N):
power += (X[i]-P)**2
if power < power_min:
power_min = power
print(power_min) | 0 | null | 46,118,690,534,770 | 158 | 213 |
class ARepeatACL():
def main(self):
K = int(input())
print('ACL' * K)
if __name__ == "__main__":
this_class = ARepeatACL()
this_class.main() | #166_C
n, m = map(int, input().split())
h = list(map(int, input().split()))
a = [0] * m
b = [0] * m
v = [[] for i in range(n)]
for i in range(m):
a[i], b[i] = map(int, input().split())
a[i] -= 1
b[i] -= 1
v[a[i]].append(h[b[i]])
v[b[i]].append(h[a[i]])
ans = 0
for i in range(n):
if v[i] == []:
ans += 1
else:
v[i].sort(reverse=True)
if h[i] > v[i][0]:
ans += 1
print(ans) | 0 | null | 13,697,926,472,230 | 69 | 155 |
S = list(input())
if S[-1] == 's':
S.append('e')
S.append('s')
else:
S.append('s')
strS = ''.join(S)
print(strS) | str=input()
if str.endswith("s"):
print(str+"es")
else:
print(str+"s") | 1 | 2,370,686,252,198 | null | 71 | 71 |
import sys
n = int(input()) # ?????£?????????????????????????????°
pic_list = ['S', 'H', 'C', 'D']
card_dict = {'S':[], 'H':[], 'C':[], 'D':[]} # ?????£?????????????????\?????????????????°
lost_card_dict = {'S':[], 'H':[], 'C':[], 'D':[]} # ?¶??????????????????\?????????????????°
# ?????????????¨??????\???????????????
for i in range(n):
pic, num = input().split()
card_dict[pic].append(int(num))
# ?¶???????????????????????¨??????\????¨????
for pic in card_dict.keys():
for j in range(1, 14):
if not j in card_dict[pic]:
lost_card_dict[pic].append(j)
# ?????????????????????
for pic in card_dict.keys():
lost_card_dict[pic] = sorted(lost_card_dict[pic])
# ?¶????????????????????????????
for pic in pic_list:
for k in range(len(lost_card_dict[pic])):
print(pic, lost_card_dict[pic][k]) | '''
ITP-1_6-B
????¶???????????????????????????????
???????????±?????¨?????????????????????????????????????????¨????????¨?????????52?????????????????????????????? n ???????????????????????????????????????????????????????????? n ????????????????????\?????¨??????????¶??????????????????????????????????????????°?????????????????????????????????
???????????????????????£?????????????????????????????§??????????????????52?????????????????§??????
52??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????13??????????????????????????????
???Input
?????????????????????????????£??????????????????????????° n (n ??? 52)????????????????????????
?¶??????? n ??????????????????????????????????????????????????????????????????????????????????????§???????????????????????¨??´??°??§??????
????????????????????????????????¨?????????????????????'S'???????????????'H'???????????????'C'???????????????'D'??§??¨?????????????????????
??´??°??????????????????????????????(1 ??? 13)?????¨??????????????????
???Output
?¶??????????????????????????????????1???????????????????????????????????????????????\?????¨????§?????????????????????§???????????????????????¨??´??°??§?????????????????????????????????????????\????????¨????????¨????????????
???????????????????????????????????????????????????????????????????????§???????????????????????????
????????????????????´??????????????????????°????????????????????????????
'''
# import
# ?????°??????????????????
trumpData = {
"S": list(range(1,14)),
"H": list(range(1,14)),
"C": list(range(1,14)),
"D": list(range(1,14)),
}
taroCard = int(input())
# ??????????????§??????????????????????????????????????????
for nc in range(taroCard):
(trumpDataLostMark, trumpDataLostCnt) = input().split()
index = trumpData[trumpDataLostMark].index(int(trumpDataLostCnt))
del trumpData[trumpDataLostMark][index]
# ????¶???????????????????????????????
for trumpDataMark in ['S', 'H', 'C', 'D']:
for trumpDataCnt in trumpData[trumpDataMark]:
# Output
print(trumpDataMark, trumpDataCnt) | 1 | 1,063,672,641,788 | null | 54 | 54 |
### ----------------
### ここから
### ----------------
import sys
import math
from io import StringIO
import unittest
def yn(b):
print("Yes" if b==1 else "No")
return
def resolve():
readline=sys.stdin.readline
a,b,x=map(int, readline().rstrip().split())
if x <= a*a*b/2:
l = x*2/b/a
print(math.degrees(math.atan(b/l)))
return
l = (2*x)/(a*a)-b
print(math.degrees(math.atan((b-l)/a)))
#arr=list(map(int, readline().rstrip().split()))
#n=int(readline())
#ss=readline().rstrip()
#yn(1)
return
if 'doTest' not in globals():
resolve()
sys.exit()
### ----------------
### ここまで
### ---------------- | import math as m
EPS = 0.0000000001
def f(a, b, theta):
if theta > m.pi/2 - EPS:
return 0
if a * m.tan(theta) <= b:
ret = a * a * b - a * a * a * m.tan(theta) / 2
else:
ret = b * b / m.tan(theta) * a / 2
return ret
def solve():
a, b, x = map(int, input().split())
ok = m.pi / 2
ng = 0
for _ in range(100):
mid = (ok + ng) / 2
if f(a, b, mid) < x:
ok = mid
else:
ng = mid
print(ok * 180 / m.pi)
if __name__ == "__main__":
solve() | 1 | 163,323,567,355,130 | null | 289 | 289 |
a,b = input().split()
aaa = a * int(b)
bbb = b * int(a)
print(min(aaa, bbb)) | N, M = map(int, input().split())
if N <= 1: a = 0
else: a = N*(N-1) // 2
if M <= 1: b = 0
else: b = M*(M-1) // 2
print(a+b) | 0 | null | 64,870,637,179,700 | 232 | 189 |
n = int(input())
s = list(input())
c = 0
for i in range(1000) :
num_1 = i // 100
num_2 = (i - num_1*100) // 10
num_3 = (i - num_1*100 - num_2*10) % 100
if str(num_1) not in s :
continue
if str(num_2) not in s :
continue
if str(num_3) not in s :
continue
for j in range(n-2) :
if int(s[j]) == num_1 :
for k in range(j+1,n-1) :
if int(s[k]) == num_2 :
for l in range(k+1,n) :
if int(s[l]) == num_3 :
c += 1
break
break
break
print(c)
| i = input()
c = True
for x in range(1,len(i)):
if i[0] != i[x]:
c = False
print("Yes")
break
if c:
print("No")
| 0 | null | 91,865,641,880,060 | 267 | 201 |
h, w, k = map(int, input().split(' '))
c = [input() for x in range(h)]
cnt = 0
for maskR in range(2**h):
for maskC in range(2**w):
black = 0
for i in range(h):
for j in range(w):
if (((maskR >> i) &1) == 0
and ((maskC >> j) &1) == 0 and c[i][j] == '#'):
black += 1
if black == k:
cnt += 1
print(cnt) | N = int(input())
min_v = int(input())
r = int(input())
max_v = r - min_v
if min_v > r:
min_v = r
for _n in range(2, N):
r = int(input())
if max_v < r - min_v:
max_v = r - min_v
if min_v > r:
min_v = r
print(max_v)
| 0 | null | 4,441,163,866,388 | 110 | 13 |
import sys
input = sys.stdin.readline
S = input()
T = input()
S = S.replace('\n','')
T = T.replace('\n','')
s_list = list(S)
t_list = list(T)
itti = 0
min_count = 10**5
for i in range(len(s_list)):
if i + len(t_list) > len(s_list):
break
count = 0
for j in range(len(t_list)):
if not s_list[i+j] == t_list[j]:
count += 1
min_count = min(count,min_count)
print(min_count) | s = input()
t = input()
ans = 10**8
for i in range(len(s)-len(t)+1):
cnt = 0
for j in range(len(t)):
if s[i+j] != t[j]: cnt += 1
ans = min(ans, cnt)
print(ans)
| 1 | 3,657,661,737,730 | null | 82 | 82 |
from sys import stdin
from collections import deque
n = int(input())
d = [-1] * (n + 1)
G = [0] + [list(map(int, input().split()[2:])) for _ in range(n)]
d[1] = 0
dq = deque([1])
while len(dq) != 0:
v = dq.popleft()
for c in G[v]:
if d[c] == -1 :
d[c] = d[v] + 1
dq.append(c)
for i, x in enumerate(d[1:], start=1):
print(i, x) | from collections import deque
n = int(input())
adj = [ [] for _ in range(n+1) ]
for _ in range(n):
lst = list(map(int,input().split()))
if lst[1] > 0:
adj[lst[0]] = lst[2:]
q = deque([1])
dist = [-1] * (n+1)
dist[1] = 0
q = deque([1])
while q:
node = q.popleft()
for nei in adj[node]:
if dist[nei] != -1: continue
dist[nei] = dist[node] + 1
q.append(nei)
for i,s in enumerate(dist):
if i==0: continue
print(i, s)
| 1 | 3,941,460,274 | null | 9 | 9 |
n=int(input())
if n<600:
print(8)
exit()
if n<800:
print(7)
exit()
if n<1000:
print(6)
exit()
if n<1200:
print(5)
exit()
if n<1400:
print(4)
exit()
if n<1600:
print(3)
exit()
if n<1800:
print(2)
exit()
if n<2000:
print(1)
exit() | X = int(input())
def define_rate(X):
if X >= 1800:
return 1
elif X >= 1600:
return 2
elif X >= 1400:
return 3
elif X >= 1200:
return 4
elif X >= 1000:
return 5
elif X >= 800:
return 6
elif X >= 600:
return 7
elif X >= 400:
return 8
print(define_rate(X)) | 1 | 6,704,884,061,602 | null | 100 | 100 |
n=int(input())
print(len(set([input() for _ in range(n)]))) | a = input()
iff3 = a[2]
iff4 = a[3]
iff5 = a[4]
iff6 = a[5]
if iff3 == iff4 :
if iff5 == iff6 :
print("Yes")
else :
print("No")
else :
print("No") | 0 | null | 35,996,911,083,990 | 165 | 184 |
import math
N = int(input())
s = 0
for a in range(1, N+1):
s += (N-1)//a
print(s)
| def modpow(a, n, p):
if n == 0:
return 1
elif n == 1:
return a % p
if n % 2 == 1:
return (a * modpow(a, n-1, p)) % p
tmp = modpow(a, n//2, p)
return (tmp * tmp) % p
def modfactrial(a, p):
ret = 1
for i in range(a, 1, -1):
ret = ret * i % p
return ret
def main():
mod = 10 ** 9 + 7
n, a, b = map(int, input().split())
# まずは繰り返し2乗法によって全部の組み合わせを求める
# すべての組み合わせは、花を選ぶ/選ばないで組み合わせを決めれる
ans = (modpow(2, n, mod) - 1) % mod
# a本選んだときの数を引く
c_a = 1
for i in range(n, n-a, -1):
c_a *= i
c_a %= mod
c_a *= modpow(modfactrial(a, mod), mod-2, mod)
ans -= c_a
ans %= mod
# b本選んだときの数を引く
c_b = 1
for i in range(n, n-b, -1):
c_b *= i
c_b %= mod
c_b *= modpow(modfactrial(b, mod), mod-2, mod)
ans -= c_b
ans %= mod
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 34,371,546,505,702 | 73 | 214 |
n = input()
S = map(int,raw_input().split())
q = input()
T = map(int,raw_input().split())
ans = 0
for t in T:
if t in S:
ans+=1
print ans | from collections import defaultdict
N,K=map(int,input().split())
alist=list(map(int,input().split()))
#print(alist)
slist=[0]
for i in range(N):
slist.append(slist[-1]+alist[i])
#print(slist)
sslist=[]
for i in range(N+1):
sslist.append((slist[i]-i)%K)
#print(sslist)
answer=0
si_dic=defaultdict(int)
for i in range(N+1):
if i-K>=0:
si_dic[sslist[i-K]]-=1
answer+=si_dic[sslist[i]]
si_dic[sslist[i]]+=1
print(answer) | 0 | null | 69,000,630,158,208 | 22 | 273 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.