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
|
---|---|---|---|---|---|---|
n, m = map(int, input().split())
c = list(map(int, input().split()))
dp = [[10**8]*(n+1) for i in range(m+1)]
dp[0][0] = 0
for i in range(m):
for j in range(n+1):
dp[i+1][j] = min(dp[i][j], dp[i+1][j])
if j + c[i] <= n:
dp[i+1][j+c[i]] = min(dp[i+1][j]+1, dp[i+1][j+c[i]])
print(dp[m][n])
|
n, m = map(int, input().split())
c = list(map(int, input().split()))
c.sort() # sortしなくてもこのアルゴリズムは有効
dp = [50001 for i in range(n + 1)]
dp[0] = 0
for i in c:
for j in range(i, n + 1):
dp[j] = min(dp[j], dp[j - i] + 1)
print(dp[n])
| 1 | 147,600,696,728 | null | 28 | 28 |
def check(s, p):
for i in range(len(s)):
count = 0
for j in range(len(p)):
if s[(i+j) % len(s)] != p[j]:
break
count += 1
if count == len(p):
return True
return False
s = raw_input()
p = raw_input()
flag = check(s, p)
if flag:
print("Yes")
else:
print("No")
|
r=input()
a=input()
if a in r+r:
print('Yes')
else:
print('No')
| 1 | 1,745,264,360,200 | null | 64 | 64 |
h, n = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
#(a,b):=(ダメージ,消費魔力)
dp = [float('inf')] * (h + 1)
dp[0] = 0
for i in range(h + 1):
for j in range(n):
if dp[i] == float('inf'):continue
temp_a = i + ab[j][0] if i + ab[j][0] < h else h
temp_b = dp[i] + ab[j][1]
dp[temp_a] = min(dp[temp_a], temp_b)
print(dp[-1])
#print(dp)
|
#!usr/bin/env python3
def string_two_numbers_spliter():
a, b, c = [int(i) for i in input().split()]
return a, b, c
def count_nums_of_divisors_of_c_in_a_and_b(a, b, c):
count = 0
for i in range(1, c+1):
if (c % i == 0):
if i >= a and i <= b:
count += 1
return count
def main():
a, b, c = string_two_numbers_spliter()
print(count_nums_of_divisors_of_c_in_a_and_b(a, b, c))
if __name__ == '__main__':
main()
| 0 | null | 40,602,823,451,900 | 229 | 44 |
##以下ググった(https://at274.hatenablog.com/entry/2020/01/24/060000)
n = int( input() )
cnt = [ [ 0 for i in range( 10 ) ] for j in range( 10 ) ]
# cnt[ i ][ j ] = 先頭がi,末尾がjである,n以下の整数の個数
for k in range( n + 1 ):
head = int( str( k )[ 0 ] )
foot = int( str( k )[ -1 ] )
cnt[ head ][ foot ] += 1
ans = 0
for i in range( 1, 10 ):
for j in range( 1, 10 ):
ans += cnt[ i ][ j ] * cnt[ j ][ i ]
print( ans )
|
n = int(input())
a = [[0 for j in range(10)] for i in range(10)]
for i in range(1, n+1):
if i >= 10**5:
tmp1 = i//10**5
elif i >= 10**4:
tmp1 = i//10**4
elif i >= 10**3:
tmp1 = i//10**3
elif i >= 10**2:
tmp1 = i//10**2
elif i >= 10:
tmp1 = i//10
else :
tmp1 = i
tmp2 = i % 10
a[tmp1][tmp2] += 1
cnt = 0
for i in range(1, 10):
for j in range(1, 10):
cnt += a[i][j] * a[j][i]
print(cnt)
| 1 | 86,916,571,493,740 | null | 234 | 234 |
#!/usr/bin/env python3
import sys
INF = float("inf")
def solve(N: int, T: int, A: "List[int]", B: "List[int]"):
# DP1
# 1からi番目の料理でj分以内に完食できる美味しさの合計の最大値
DP1 = [[0 for _ in range(T+1)] for __ in range(N+1)]
for i in range(1, N+1):
for j in range(1, T+1):
if j-A[i-1] >= 0:
DP1[i][j] = max(DP1[i][j], DP1[i-1][j-A[i-1]]+B[i-1])
DP1[i][j] = max(DP1[i][j], DP1[i-1][j], DP1[i][j-1])
# DP2
# i番目からN番目の料理でj分以内に完食できる美味しさの合計の最大値
DP2 = [[0 for _ in range(T+1)] for __ in range(N+2)]
for i in range(N, 0, -1):
for j in range(1, T+1):
if j-A[i-1] >= 0:
DP2[i][j] = max(DP2[i][j], DP2[i+1][j-A[i-1]]+B[i-1])
DP2[i][j] = max(DP2[i][j], DP2[i+1][j], DP2[i][j-1])
# i番目以外の料理でT-1分以内に完食できる美味しさの合計の最大値
ans = 0
for i in range(1, N+1):
bns = 0
for j in range(T):
bns = max(bns, DP1[i-1][j] + DP2[i+1][T-j-1])
ans = max(ans, bns+B[i-1])
print(ans)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
T = int(next(tokens)) # type: int
A = [int()] * (N) # type: "List[int]"
B = [int()] * (N) # type: "List[int]"
for i in range(N):
A[i] = int(next(tokens))
B[i] = int(next(tokens))
solve(N, T, A, B)
if __name__ == '__main__':
main()
|
h = int(input())
ans = 1
num = 1
while h>1:
h//=2
num*=2
ans+=num
print(ans)
| 0 | null | 116,110,094,767,268 | 282 | 228 |
a = input()
print('A' if a.upper() == a else 'a')
|
a = input()
print('a' if ord(a) >= ord('a') and ord(a)<=ord('z') else 'A')
| 1 | 11,398,806,402,050 | null | 119 | 119 |
n,m=map(int,input().split())
i=0
i+=n*(n-1)/2
i+=m*(m-1)/2
print(int(i))
|
n, m = map(int, input().split())
ans = 0
for i in range(1, n):
ans += i
for i in range(1, m):
ans += i
print(ans)
| 1 | 45,694,217,538,762 | null | 189 | 189 |
def main():
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(A[K-1])
if __name__ == '__main__':
main()
|
n = int(input())
d = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(d[n-1])
| 1 | 49,924,797,637,270 | null | 195 | 195 |
N,A,B=map(int,input().split());C=B-A;print(C//2+C%2*min(A,N-B+1))
|
while True:
h=[]
S=input()
if S=="-":
break
m=int(input())
for i in range(m):
h=int(input())
if len(S)==h:
pass
else:
S=S[h:]+S[:h]
print(S)
| 0 | null | 55,515,734,376,388 | 253 | 66 |
# coding:utf-8
# Doubly Linked List
from collections import deque
def main():
n = int(input())
dll = deque()
for _ in range(n):
operation = input().split(' ')
if operation[0] in ["insert", "delete"]:
key = operation[1]
if operation[0] == "insert":
dll.appendleft(key)
else:
try:
dll.remove(key)
except:
pass
else:
if operation[0][6] == 'F':
dll.popleft()
else:
dll.pop()
print(' '.join(dll))
if __name__ == "__main__":
main()
|
# -*- coding: utf-8 -*-
from sys import stdin
input = stdin.readline
s = input()
print(s[0:3])
| 0 | null | 7,470,576,020,970 | 20 | 130 |
x, y, z = input().split()
a = int(x)
b = int(y)
c = int(z)
count = 0
num = a
while num <= b:
if c % num == 0:
count += 1
else:
pass
num += 1
print(count)
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from copy import deepcopy
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
# divisors.sort()
return divisors
n = int(readline())
ans = len(make_divisors(n - 1))
for check in make_divisors(n):
if check == 1:
continue
nn = deepcopy(n)
while nn % check == 0:
nn //= check
if nn % check == 1:
ans += 1
print(ans - 1)
| 0 | null | 20,921,387,635,410 | 44 | 183 |
n, k = (int(x) for x in input().split())
A = list(int(x) for x in input().split())
MOD = 10**9 + 7
A.sort()
l = 0
r = n - 1
sign = 1 # 1 or -1
ans = 1
if k % 2 == 1:
ans = A[r]
r -= 1
k -= 1
if ans < 0:
sign = -1
while k:
x = A[l] * A[l + 1]
y = A[r] * A[r - 1]
if x * sign > y * sign:
ans *= x % MOD
ans %= MOD
l += 2
else:
ans *= y % MOD
ans %= MOD
r -= 2
k -= 2
print(ans)
|
n, m = map(int, input().split())
c = list(map(int, input().split()))
dp = [[10**8]*(n+1) for i in range(m+1)]
dp[0][0] = 0
for i in range(m):
for j in range(n+1):
dp[i+1][j] = min(dp[i][j], dp[i+1][j])
if j + c[i] <= n:
dp[i+1][j+c[i]] = min(dp[i+1][j]+1, dp[i+1][j+c[i]])
print(dp[m][n])
| 0 | null | 4,795,166,337,728 | 112 | 28 |
h = int(input())
w = int(input())
n = int(input())
all_cell = 0
count = 0
while all_cell < n:
if h > w:
all_cell += h
w -= 1
else:
all_cell += w
h -= 1
count += 1
print(count)
|
import sys
from io import StringIO
import unittest
import copy
# 検索用タグ、バージョンによる相違点(pypy)
def resolve():
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(key=lambda xx: -xx)
q.sort(key=lambda xx: -xx)
r.sort(key=lambda xx: -xx)
# 着色を一切行わない場合の値
# pypy3(2.4.0)ではlist.copy()が未実装。copy をインポートする必要がある。
def_red = copy.copy(p[0:x])
def_grren = copy.copy(q[0:y])
# 無職のリンゴに置換していく・・
redcnt = -1
grncnt = -1
def_red_cnt = len(def_red)
def_grren_cnt = len(def_grren)
for i in range(len(r)):
if not (r[i] > def_red[redcnt] or r[i] > def_grren[grncnt]):
continue
if def_red[redcnt] > def_grren[grncnt] and r[i] > def_grren[grncnt]:
# 透明のリンゴを緑に着色して、置き換える。
def_grren[grncnt] = r[i]
if grncnt is not -def_grren_cnt:
grncnt -= 1
else:
# 透明のリンゴを赤に着色して、置き換える。
def_red[redcnt] = r[i]
if redcnt is not -def_red_cnt:
redcnt -= 1
print(sum(def_red) + sum(def_grren))
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """1 2 2 2 1
2 4
5 1
3"""
output = """12"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """2 2 2 2 2
8 6
9 1
2 1"""
output = """25"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4"""
output = """74"""
self.assertIO(input, output)
# def test_自作成_1(self):
# input = """1 1 1 1 1
# 10
# 20
# 90"""
# output = """110"""
# self.assertIO(input, output)
# このパターンで「list index out of range」が発生。
# def test_自作成_2(self):
# input = """1 1 1 1 2
# 10
# 20
# 90 110"""
# output = """200"""
# self.assertIO(input, output)
if __name__ == "__main__":
# unittest.main()
resolve()
| 0 | null | 66,879,503,836,000 | 236 | 188 |
#d
n=int(input())
x=input()
def popcount(m):
return bin(m).count("1")
intx = int( "0b"+x ,0 )
popcount0 = x.count("1")
intx_mod_pp1 = intx %(popcount0+1)
if popcount0!=1:
intx_mod_pm1 = intx %(popcount0-1)
jisho = ["yet"]*n
# pow2ip = .5
# pow2im = .5
for i in range(n):
if x[i]=="1" and popcount0==1:
print(0)
continue
pow2ip = pow(2,n-i-1,popcount0+1)
if popcount0!=1:
pow2im = pow(2,n-i-1,popcount0-1)
if False:
pass
else:
intxi=1
c=0
while intxi!=0:
if c==0:
if x[i]=="0":
pop = popcount0+1
intxi = (intx_mod_pp1 + pow2ip%pop )%pop
else:
pop = popcount0-1
intxi = (intx_mod_pm1 - pow2im%pop )%pop
else:
if jisho[intxi]=="yet":
togo = intxi%popcount(intxi)
jisho[intxi]= togo
intxi = togo
else:
intxi =jisho[intxi]
#print(intxi)
c+=1
print(c)
#print()
# print("f(n)=",c)
|
H, W = map(int, input().split())
arr = [input().rstrip() for h in range(H)]
ans = [[0] * W for _ in range(H)]
for h, row in enumerate(arr):
for w, val in enumerate(row):
if h == 0 and w == 0:
if arr[h][w] == "#":
ans[h][w] = 1
continue
nv = 1e+9
if h > 0:
nv = ans[h-1][w]
if arr[h-1][w] == "." and val == "#":
nv += 1
if w > 0:
tmp = ans[h][w-1]
if arr[h][w-1] == "." and val == "#":
tmp += 1
nv = min(nv, tmp)
ans[h][w] = nv
print(ans[-1][-1])
| 0 | null | 28,929,664,481,312 | 107 | 194 |
def calc_matrix(A, B, size):
n, m, l = size
# print(n, m, l)
results = []
for i in range(n):
row_data = []
for j in range(l):
products = []
for k in range(m):
products.append(A[i][k] * B[k][j])
# print('C[{0}][{1}] = {2}'.format(i, j, sum(products)))
row_data.append(sum(products))
results.append(row_data)
return results
if __name__ == '__main__':
# ??????????????\???
A = []
B = []
# A.append([1, 2])
# A.append([0, 3])
# A.append([4, 5])
# B.append([1, 2, 1])
# B.append([0, 3, 2])
n, m, l = [int(x) for x in input().split(' ')]
for i in range(n):
A.append([int(x) for x in input().split(' ')])
for i in range(m):
B.append([int(x) for x in input().split(' ')])
# ???????????????
results = calc_matrix(A, B, (n, m, l))
# ???????????????
for row in results:
print(' '.join(map(str, row)))
|
H, W, K = map(int, input().split())
S = [list(map(int, list(input()))) for _ in range(H)]
ans = H*W
def countWhite(ytop, ybottom, xleft, xright):
ret = sum([sum(s[xleft:xright]) for s in S[ytop:ybottom]])
return ret
for h_div in range(1 << H-1):
count = 0
cut = [0]
for i in range(H):
if h_div >> i & 1:
cut.append(i+1)
count += 1
cut.append(H)
if count > ans:
continue
left = 0
# ここどんなふうに縦に切っても条件を満たさない場合がある
for right in range(1, W+1):
white = 0
for i in range(len(cut)-1):
white = max(white, countWhite(cut[i], cut[i+1], left, right))
if white > K:
if left == right - 1: # 条件を満たす縦の切り方がなかった場合
break
left = right - 1
count += 1
if count > ans:
break
else:
if count < ans:
ans = count
print(ans)
| 0 | null | 24,859,714,902,098 | 60 | 193 |
n = int(input())
s = [str(input()) for i in range(n)]
a = s.count(('AC'))
b = s.count(('WA'))
c = s.count(('TLE'))
d = s.count(('RE'))
print("AC x {}".format(a))
print("WA x {}".format(b))
print("TLE x {}".format(c))
print("RE x {}".format(d))
|
S=input()
T=input()
len_s=len(S)
len_t=len(T)
ans=0
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 = max(ans,cnt)
print(len_t-ans)
| 0 | null | 6,195,694,620,402 | 109 | 82 |
H_1, M_1, H_2, M_2, K = list(map(int, input().split(' ')))
print((H_2-H_1)*60+(M_2-M_1)-K)
|
h, m, h2, m2, k = map(int, input().split())
ans = (h2 * 60 + m2) - (h * 60 + m) - k
print(ans)
| 1 | 18,085,444,849,068 | null | 139 | 139 |
S = input()
res = [0] * (len(S) + 1)
for i in range(len(S)):
if S[i] == "<":
res[i + 1] = res[i] + 1
for i in range(len(S)-1, -1, -1):
if S[i]=='>':
res[i] = max(res[i], res[i + 1] + 1)
print(sum(res))
|
# A, Can'tWait for Holiday
# 今日の曜日を表す文字列Sが与えられます。
# Sは'SUN','MON','TUE','WED','THU','FRI','SAT'のいずれかであり、それぞれ日曜日、月曜日、火曜日。水曜日、木曜日、金曜日、土曜日を表します。
# 月の日曜日(あす以降)が何日後か求めてください。
# Sは'SUN','MON','TUE','WED','THU','FRI','SAT'のいずれか。
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)
else:print(7)
| 0 | null | 145,082,375,257,368 | 285 | 270 |
n = int(input())
a = list(map(int, input().split(" ")))
res = 0
ruiseki = 0
for j in range(n):
if j == 0:
continue
ruiseki += a[j-1]
res = res + a[j]*ruiseki
print(res % ((10 **9)+7))
|
N = int(input())
A = list(map(int, input().split()))
sa = sum(A)
INF = 10**9+7
ans = 0
for i in range(N):
sa -= A[i]
ans += (A[i]*sa)%INF
print(ans%INF)
| 1 | 3,850,341,321,920 | null | 83 | 83 |
x = list(map(int, input().split()))
x = list(map(int, input().split()))
if x[1] == 1:
print(1)
else:
print(0)
|
N=int(input())
*L,=map(int,input().split())
L.sort()
from bisect import*
i=0
ans=0
while i<N:
j=i+1
while j<N:
ans+=bisect_left(L,L[i]+L[j])-j-1
j+=1
i+=1
print(ans)
| 0 | null | 148,703,579,948,352 | 264 | 294 |
from collections import deque
import math
import copy
#https://qiita.com/ophhdn/items/fb10c932d44b18d12656
def max_dist(input_maze,startx,starty,mazex,mazey):
input_maze[starty][startx]=0
que=deque([[starty,startx]])
# print(que)
while que:
# print(que,input_maze)
y,x=que.popleft()
for i,j in [(1,0),(0,1),(-1,0),(0,-1)]:
nexty,nextx=y+i,x+j
if (nexty>=0) & (nextx>=0) & (nextx<mazex) & (nexty<mazey):
dist=input_maze[nexty][nextx]
if dist!=-1:
if (dist>input_maze[y][x]+1) & (dist > 0):
input_maze[nexty][nextx]=input_maze[y][x]+1
que.append([nexty,nextx])
# print(que)
# print(max(list(map(lambda x: max(x),copy_maze))))
return max(list(map(lambda x: max(x),copy_maze)))
h,w =list(map(int,input().split()))
maze=[list(input()) for l in range(h)]
# Maze preprocess
for y in range(h):
for x in range(w):
if maze[y][x]=='.':
maze[y][x]=math.inf
elif maze[y][x] == '#':
maze[y][x]=int(-1)
results = []
for y in range(h):
for x in range(w):
if maze[y][x]==math.inf:
copy_maze = copy.deepcopy(maze)
max_dist_result = max_dist(copy_maze,x,y,w,h)
results.append(int(max_dist_result))
#print(max_dist_result)
print(max(results))
|
import sys
import math
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(h, w, num): return [[int(num)] * w for _ in range(h)]
def main():
H, W = NMI()
grid = [SI() for _ in range(H)]
DH = [-1, 1, 0, 0]
DW = [0, 0, -1, 1]
def bfs(sh, sw):
queue = deque()
seen = make_grid(H, W, -1)
queue.append([sh, sw])
seen[sh][sw] = 0
while queue:
now_h, now_w = queue.popleft()
for dh, dw in zip(DH, DW):
next_h = now_h + dh
next_w = now_w + dw
if not(0 <= next_h < H and 0 <= next_w < W):
continue
if seen[next_h][next_w] != -1 or grid[next_h][next_w] == "#":
continue
queue.append([next_h, next_w])
seen[next_h][next_w] = seen[now_h][now_w] + 1
return max([max(l) for l in seen])
ans = 0
for h in range(H):
for w in range(W):
if grid[h][w] == ".":
ans = max(ans, bfs(h, w))
print(ans)
if __name__ == "__main__":
main()
| 1 | 94,632,670,124,356 | null | 241 | 241 |
while True:
s = input()
if s == "-":
break
m = int(input())
for n in range(m):
h = int(input())
t = s[0:h]
u = s[h:]
s = u + t
print(s)
|
while True:
C = input()
if C == "-":
break
count = int(input())
shuffle = [int(input()) for i in range(count)]
for h in shuffle:
C = C[h:] + C[:h]
print(C)
| 1 | 1,914,553,319,732 | null | 66 | 66 |
string = input()
for i in range(int(input())):
lst = list(map(str, input().split()))
if lst[0] == "replace":
string = string[:int(lst[1])] + lst[3] + string[int(lst[2])+1:]
if lst[0] == "reverse":
rev_str = str(string[int(lst[1]):int(lst[2])+1])
string = string[:int(lst[1])] + rev_str[::-1] + string[int(lst[2])+1:]
if lst[0] == "print":
print(string[int(lst[1]):int(lst[2])+1])
|
S = list(input())
q = int(input())
for i in range(q):
cmd, a, b, *c = input().split()
a = int(a)
b = int(b)
if cmd == "replace":
S[a:b+1] = c[0]
elif cmd == "reverse":
S[a:b+1] = reversed(S[a:b+1])
else:
print(*S[a:b+1], sep='')
| 1 | 2,091,994,699,748 | null | 68 | 68 |
n=int(input())
x=0--n//2
print(x/n)
|
N = int(input())
ans = (N - (N//2)) / N
print(ans)
| 1 | 177,122,950,677,696 | null | 297 | 297 |
import numpy as np
import itertools as it
H,W,N = [int(i) for i in input().split()]
dat = np.array([list(input()) for i in range(H)], dtype=str)
emp_r = ["." for i in range(W)]
emp_c = ["." for i in range(H)]
def plot(dat, dict):
for y in dict["row"]:
dat[y,:] = emp_r
for x in dict["col"]:
dat[:,x] = emp_c
return dat
def is_sat(dat):
count = 0
for y in range(W):
for x in range(H):
if dat[x, y] == "#":
count += 1
if count == N:
return True
else:
return False
# def get_one_idx(bi, digit_num):
# tmp = []
# for j in range(digit_num):
# if (bi >> j) == 1:
# tmp.append()
# plot(dat, dict={"row": [], "col":[0, 1]})
combs = it.product([bin(i) for i in range(2**H-1)], [bin(i) for i in range(2**W-1)])
count = 0
for comb in combs:
rows = comb[0]
cols = comb[1]
rc_dict = {"row": [], "col": []}
for j in range(H):
if (int(rows, 0) >> j) & 1 == 1:
rc_dict["row"].append(j)
for j in range(W):
if (int(cols, 0) >> j) & 1 == 1:
rc_dict["col"].append(j)
dat_c = plot(dat.copy(), rc_dict)
if is_sat(dat_c):
count += 1
print(count)
|
h,w,k=map(int,input().split())
ans = 0
def get(sta):
ret = set()
for i in range(6):
if sta & 1:
ret.add(i)
sta //= 2
return ret
grd=[input() for i in range(h)]
for i in range(2**h):
hs=get(i)
for j in range(2**w):
ws=get(j)
chk = 0
for a in range(h):
for b in range(w):
if a in hs or b in ws or grd[a][b]==".":continue
chk += 1
if chk == k:
ans += 1
print(ans)
| 1 | 8,996,506,877,370 | null | 110 | 110 |
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
a_rev = a[::-1]
ok, ng = 1, 200001
while ng-ok > 1:
x = (ok+ng)//2
num = 0
cur = 0
for i in range(n-1, -1, -1):
while cur < n and a[i] + a[cur] >= x:
cur += 1
num += cur
if num < m:
ng = x
else:
ok = x
just = ok
ans = 0
larger_cnt = 0
cur = 0
a_cum = [0]
for i in range(n):
a_cum.append(a_cum[-1] + a[i])
for i in range(n):
while cur < n and a[i] + a_rev[cur] <= just:
cur += 1
larger_cnt += n - cur
ans += (n - cur) * a[i] + a_cum[n - cur]
ans += just * (m - larger_cnt)
print(ans)
|
N = int(input())
print(N//2 if N%2==0 else N//2+1)
| 0 | null | 83,290,920,329,760 | 252 | 206 |
s = input()
ans = ''
for i in range(len(s)):
ans = ans + 'x'
print(ans)
|
s = input()
t = len(s)
print('x'*t)
| 1 | 72,935,190,999,046 | null | 221 | 221 |
n, q = map(int, input().split())
l = []
for i in range(n):
t = []
for j in input().split():
t += [j]
t[1] = int(t[1])
l += [t]
c = 0
while len(l) > 0:
if l[0][1] > q:
l[0][1] -= q
l += [l[0]]
l.pop(0)
c += q
else:
c += l[0][1]
print(l[0][0], c)
l.pop(0)
|
class Queue():
def __init__(self, size=10):
self.queue = [None] * size
self.head = self.tail = 0
self.MAX = size
self.num_items = 0
def is_empty(self):
return self.num_items == 0
def is_full(self):
return self.num_items == self.MAX
def enqueue(self, x):
if self.is_full():
raise IndexError
self.queue[self.tail] = x
self.num_items += 1
if self.tail+1 == self.MAX:
self.tail = 0
else:
self.tail += 1
def dequeue(self):
if self.is_empty():
raise IndexError
x = self.queue[self.head]
self.num_items -= 1
if self.head+1 == self.MAX:
self.head = 0
else:
self.head += 1
return x
class Process:
def __init__(self, name, time):
self.name = name
self.time = time
def print_time(self):
return self.time
def print_name(self):
return self.name
def main():
n, q = map(int, input().split())
qq = Queue(n)
t = 0
for i in range(n):
name, time = input().split()
p = Process(name, int(time))
qq.enqueue(p)
while not qq.is_empty():
p = qq.dequeue()
if p.time - q <= 0:
t += p.time
print("{} {}".format(p.name, t))
else:
p.time -= q
t += q
qq.enqueue(p)
if __name__ == '__main__':
main()
| 1 | 41,431,565,620 | null | 19 | 19 |
import sys
sys.setrecursionlimit(10**9)
def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))
INF=10**20
def main():
X=ii()
i = 1
yen = 100
while yen < X:
r = yen // 100
yen += r
i += 1
print(i-1)
if __name__ == "__main__":
main()
|
X = int(input())
a = 100
year = 0
import math
while True:
a = a*101//100
year += 1
if a >= X:
break
print(year)
| 1 | 26,965,970,820,380 | null | 159 | 159 |
n,k=map(int,input().split())
a=list(map(int,input().split()))
for l in range(k):
if a==[n]*n:
break
imos = [0]*(n+1)
for i in range(n):
imos[max(0,i-a[i]) ]+=1
imos[min(n-1,i+a[i])+1 ]-=1
a=[0]*n
a[0]=imos[0]
for i in range(1,n):
a[i] = a[i-1]+imos[i]
print(*a)
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(min(k, 100)):
new_a = [0]*n
for i in range(n):
d = a[i]
new_a[max(i-d, 0)] += 1
if i+d+1 <= n-1:
new_a[i+d+1] -= 1
for i in range(n-1):
new_a[i+1] += new_a[i]
a = new_a
print(*a)
| 1 | 15,554,302,162,250 | null | 132 | 132 |
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal
class Scanner():
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [Scanner.string() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [Scanner.int() for i in range(n)]
def pop_count(x):
x = x - ((x >> 1) & 0x5555555555555555)
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
x = x + (x >> 32)
return x & 0x0000007f
def solve():
N, K = Scanner.map_int()
MOD = int(1e09) + 7
MAX = 200010
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX
fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1
for i in range(2, MAX):
fac[i] = fac[i - 1] * i % MOD
inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
def cmb(n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
ans = 0
for m in range(0, min(K, N - 1) + 1):
a = cmb(N, m)
b = cmb(N - 1, m)
ans += a * b
ans %= MOD
print(ans)
def main():
# sys.setrecursionlimit(1000000)
# sys.stdin = open("sample.txt")
# T = Scanner.int()
# for _ in range(T):
# solve()
# print('YNeos'[not solve()::2])
solve()
if __name__ == "__main__":
main()
|
a,b,c,d=map(float,input().split())
import math
x=math.sqrt((c-a)**2+(d-b)**2)
print("{:.5f}".format(x))
| 0 | null | 33,776,012,173,400 | 215 | 29 |
import numpy as np
N, K = map(int,input().split())
A = tuple(map(int,input().split()))
for p in range(1,N-K+1):
if A[K+p-1] > A[p-1]:
print("Yes")
else:
print("No")
|
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
dd = defaultdict(int)
ans = 0
for i, num in enumerate(a, start = 1):
dd[i + num] += 1
for i, num in enumerate(a, start = 1):
ans += dd[i - num]
print(ans)
| 0 | null | 16,569,089,969,448 | 102 | 157 |
A, B, N = map(int, input().split())
if (B-1) >= N:
Max = ((A*N) // B) - A*(N // B)
elif (B-1) < N:
Max = ((A*(B-1)) // B) - A*((B-1) // B)
print(Max)
|
A,B,N = map(int,input().split())
if N >= B:
N = B - 1
ans = int(A * N / B) - A * int(N / B)
print(ans)
| 1 | 28,016,113,922,848 | null | 161 | 161 |
import os, sys, re, math
N = int(input())
S = []
for i in range(N):
S.append(input())
d = {}
for s in S:
if not s in d:
d[s] = 0
d[s] += 1
d = sorted(d.items(), key=lambda x:x[1], reverse=True)
names = [v[0] for v in d if v[1] == d[0][1]]
for name in sorted(names):
print(name)
|
n = int(input())
d = {}
t = 0
for i in range(n):
s = input()
d[s] = d.get(s, 0) + 1
t = max(t, d[s])
for key in sorted(d):
if d[key] == t:
print(key)
| 1 | 70,095,297,452,988 | null | 218 | 218 |
def fibonacci(n, memo=None):
if memo==None:
memo = [None]*n
if n<=1:
return 1
else:
if memo[n-2]==None:
memo[n-2] = fibonacci(n-2, memo)
if memo[n-1]==None:
memo[n-1] = fibonacci(n-1, memo)
return memo[n-1] + memo[n-2]
n = int(input())
print(fibonacci(n))
|
n = int(input())
a = []
for i in range(n):
s = str(input())
a.append(s)
b = set(a)
print(len(b))
| 0 | null | 15,006,239,380,160 | 7 | 165 |
# coding: utf-8
a, b = map(int, input().split())
ans = -1
if a < 10 and b < 10:
ans = a * b
print(ans)
|
X,Y,Z=map(int, input().split())
A=[Z,X,Y]
print(*A,end='')
| 0 | null | 98,595,883,586,476 | 286 | 178 |
list_len = int(input().rstrip())
num_list = list(map(int, input().rstrip().split()))
for i in range(list_len):
v = num_list[i]
j = i - 1
while j >= 0 and num_list[j] > v:
num_list[j + 1] = num_list[j]
j -= 1
num_list[j+1] = v
output_str = ' '.join(map(str, num_list))
print(output_str)
|
def resolve():
x = int(input())
dp = [0] * (x+1+105)
dp[0] = 1
for i in range(x):
if dp[i] == 1:
for j in range(100, 106):
dp[i+j] = 1
print(dp[x])
resolve()
| 0 | null | 63,916,757,450,792 | 10 | 266 |
n = int(input())
d = set()
for i in range(n):
com = input().split()
if com[0] == "insert":
d.add(com[1])
else:
print("yes" if com[1] in d else "no")
|
n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
if i in d: d[i] += 1
else: d[i] = 1
ans = 0
for i in d.values(): ans += i*(i-1)//2
for i in a:
print(ans - (d[i]-1))
| 0 | null | 23,786,729,942,888 | 23 | 192 |
def main():
n = int(input())
s = input()
ans = 0
for i in range(n):
if i == 0:
ans += 1
mae = s[i]
else:
if s[i] != mae:
ans += 1
mae = s[i]
print(ans)
if __name__ == "__main__":
main()
|
n = int(input())
d = input()
x = d[0]
count = 1
for i in d:
if i != x:
count += 1
x = i
print(count)
| 1 | 170,043,229,184,008 | null | 293 | 293 |
n = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(n):
mini = i + a[i:].index(min(a[i:]))
if mini != i:
a[i], a[mini] = a[mini], a[i]
count += 1
print(' '.join(map(str, a)))
print(count)
|
# Selection Sort
length = int(input())
array = [int(i) for i in input().rstrip().split()]
count = 0
for i in range(length):
minj = i
for j in range(i, length):
if array[j] < array[minj]:
minj = j
if minj != i:
count += 1
array[i], array[minj] = array[minj], array[i]
for i in range(length):
if i < length - 1:
print(array[i], end = " ")
else:
print(array[i])
print(count)
| 1 | 21,455,082,180 | null | 15 | 15 |
def fibonacci(f, n):
if n == 0 or n == 1:
f[n] = 1
return f[n]
if f[n]:
return f[n]
f[n] = fibonacci(f, n - 2) + fibonacci(f, n - 1)
return f[n]
n = int(input())
f = [None for i in range(n + 1)]
print(fibonacci(f, n))
|
x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
import heapq as hp
s = x+y
u = []
hp.heapify(u)
for i in range(a):
hp.heappush(u,[-p[i],'r'])
for i in range(c):
hp.heappush(u,[-r[i],'m'])
v = []
hp.heapify(v)
for i in range(b):
hp.heappush(v,[-q[i],'g'])
for i in range(c):
hp.heappush(v,[-r[i],'m'])
z = []
ans = 0
hp.heapify(z)
for i in range(a):
hp.heappush(z,[-p[i],'r'])
for i in range(b):
hp.heappush(z,[-q[i],'g'])
for i in range(c):
hp.heappush(z,[-r[i],'m'])
while s and x and y:
t = hp.heappop(z)
ans += -t[0]
if t[1] == 'r':
x -= 1
s -=1
elif t[1] == 'g':
y -= 1
s -= 1
else:
s -= 1
if s > 0 and x > 0:
while s:
t = hp.heappop(z)
if t[1] == 'g':
continue
else:
ans += -t[0]
s -= 1
elif s > 0 and y > 0:
while s:
t = hp.heappop(z)
if t[1] == 'r':
continue
else:
ans += -t[0]
s -= 1
print(ans)
| 0 | null | 22,298,087,113,944 | 7 | 188 |
n,m=map(int,input().split())
C=list(map(int,input().split()))
dp=[[float('inf')]*(n+1) for i in range(m+1)]
for i in range(m+1):
dp[i][0]=0
for i in range(1,m+1):
c=C[i-1]
for j in range(1,n+1):
dp[i][j]=dp[i-1][j]
if j>=c:
dp[i][j]=min(dp[i][j],dp[i-1][j-c]+1,dp[i][j-c]+1)
print(dp[m][n])
|
mod = 10 ** 9 + 7
n, k = map(int, input().split())
binomial = [1]
cum = 1
for i in range(1, n + 2):
cum *= i
cum = cum % mod
binomial.append(cum)
inv = []
tmp = pow(cum, mod - 2, mod)
inv.append(tmp)
for j in range(n + 1, 0, -1):
tmp = j * tmp % mod
inv.append(tmp)
inv.reverse()
def comb(n, k):
return binomial[n] * inv[n - k] % mod * inv[k] % mod if n >= k else 0
k = min(k, n - 1)
ans = 0
for m in range(k + 1):
tmp = comb(n, m) * binomial[n - 1] * inv[n - 1 - m] * inv[m]
ans += tmp % mod
ans %= mod
print(ans)
| 0 | null | 33,671,349,905,850 | 28 | 215 |
import sys
s = input().strip()
if s[2] == s[3] and s[4] == s[5]:
print("Yes")
else : print("No")
|
N = int(input())
A = [int(i) for i in input().split()]
L, R = [A[-1]], [A[-1]]
for i in range(1, N+1):
L.append((L[-1]+1)//2+A[-1-i])
R.append((R[-1]+A[-1-i]))
L = L[::-1]
R = R[::-1]
if L[0] >= 2:
print(-1)
exit()
ans = 1
p = 1
for i in range(1, N+1):
ans += min(p*2, R[i])
p = min(p*2, R[i])-A[i]
print(ans)
| 0 | null | 30,598,406,978,088 | 184 | 141 |
s,w=map(int,input().split())
if w>=s:
ans='unsafe'
else:
ans='safe'
print(ans)
|
mod_val = 10**9+7
n, k = map(int, input().split())
factorials = [1]*(n+1) # values 0 to n
for i in range(2, n+1):
factorials[i] = (factorials[i-1]*i)%mod_val
def mod_binomial(a, b):
numerator = factorials[a]
denominator = (factorials[b]*factorials[a-b])%mod_val
invert = pow(denominator, mod_val-2, mod_val)
return (numerator*invert)%mod_val
partial = 0
# m is number of rooms with no people
for m in range(min(k+1, n)):
# m places within n to place the 'no people' rooms
# put n-(n-m) people in n-m rooms (n-m) must be placed to be non-empty
partial = (partial + (mod_binomial(n, m) * mod_binomial(n-1, m))%mod_val)%mod_val
print(partial)
| 0 | null | 48,062,884,750,978 | 163 | 215 |
while True:
hw = [int(x) for x in input().split()]
h, w = hw[0], hw[1]
if h == 0 and w == 0:
break
for hh in range(h):
for ww in range(w):
if hh == 0 or hh == h - 1 or ww == 0 or ww == w - 1:
print('#', end = '')
else:
print('.', end = '')
print('')
print('')
|
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 | 1,683,072,508,672 | 50 | 73 |
N, M = map(int, input().split())
ans = []
if M % 2 != 0:
for i in range((M + 1)//2):
ans.append((1 + i, M + 1 - i))
for j in range((M - 1)//2):
ans.append((M + 2 + j, 2*M + 1 - j))
else:
for i in range(M//2):
ans.append((1 + i, M + 1 - i))
ans.append((M + 2 + i, 2*M + 1 - i))
for i in range(M):
print(*ans[i])
|
from sys import stdin
from collections import defaultdict, Counter
N, P = map(int, stdin.readline().split())
S, = stdin.readline().split()
ans = 0
# 2 cases
if P == 2 or P == 5:
digitdiv = []
for i in range(N):
if int(S[i]) % P == 0:
ans += i + 1
else:
#
count = Counter()
prefix = []
ten = 1
mod = 0
for i in range(N):
x = (int(S[N - i - 1])*ten + mod) % P
prefix.append(x)
count[x] += 1
ten = (ten * 10) % P
mod = x
prefix.append(0)
count[0] += 1
for val in count.values():
ans += val*(val - 1)//2
print (ans)
| 0 | null | 43,640,892,641,090 | 162 | 205 |
from collections import defaultdict
def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
S = [0] * (N + 1) # 累積和
for i in range(1, N + 1):
S[i] = S[i - 1] + A[i - 1]
T = [(s - i) % K for i, s in enumerate(S)]
counter = defaultdict(int)
ans = 0
for j in range(N + 1):
if j >= K:
counter[T[j - K]] -= 1
ans += counter[T[j]]
counter[T[j]] += 1
print(ans)
if __name__ == '__main__':
main()
|
import sys
input = sys.stdin.readline
from collections import deque
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [0]
for a in A:
b = (B[-1] + (a-1)) % K
B.append(b)
ans = 0
dic = {}
for i, b in enumerate(B):
if b in dic:
dic[b].append(i)
else:
dic[b] = deque()
dic[b].append(i)
while len(dic[b]) > 0 and dic[b][0] <= i - K:
dic[b].popleft()
ans += len(dic[b])-1
print(ans)
| 1 | 137,530,608,992,506 | null | 273 | 273 |
from math import ceil
def main():
N, K = map(int,input().split())
A = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse=True)
C.sort()
def chk(x):
cnt = 0
for i in range(N):
cnt += max(ceil(A[i]-x/C[i]), 0)
if cnt > K:
return False
return True
ng, ok = -1, 10**12
while ok - ng > 1:
m = (ok+ng)//2
if chk(m):
ok = m
else:
ng = m
print(ok)
if __name__ == "__main__":
main()
|
# -*- 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
def f(n):
r = 1
for i in range(1, n+1):
r *= i
return r
@mt
def slv(N, K, A, F):
A.sort()
F.sort(reverse=True)
def f(x):
y = 0
for a, f in zip(A, F):
b = a - x//f
if b > 0:
y += b
if y <= K:
return 1
return 0
return Bisect(f).bisect_left(1, 0, 10**18)
def main():
N, K = read_int_n()
A = read_int_n()
F = read_int_n()
print(slv(N, K, A, F))
if __name__ == '__main__':
main()
| 1 | 164,552,330,340,094 | null | 290 | 290 |
import math
a,b = map(int,input().split())
if b>a:
a,b = b,a
l = (a*b)//(math.gcd(a,b))
print(l)
|
import os, sys, re, math
from functools import reduce
def lcm(vals):
return reduce((lambda x, y: (x * y) // math.gcd(x, y)), vals, 1)
(A, B) = [int(n) for n in input().split()]
print(lcm([A, B]))
| 1 | 113,445,393,163,680 | null | 256 | 256 |
n=int(input())
hoge=[]
for i in range(n):
hoge.append(input())
huga=list(set(hoge))
print(len(huga))
|
n = int(input())
num = [input() for _ in range(n)]
print(len(set(num)))
| 1 | 30,285,853,183,520 | null | 165 | 165 |
n, k = list(map(int, input().split()))
MOD = (10 ** 9) + 7
ans = 0
min_val = 0
max_val = n
p = 1
for i in range(n + 1):
# print(min_val, max_val)
if i + 1 >= k:
ans += max_val - min_val + 1
ans = ans % MOD
min_val += p
max_val += n - p
p += 1
print(ans)
|
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, K = mapint()
mod = 10**9+7
ans = 0
for i in range(K, N+2):
ans += (N+(N-i+1))*i//2-(i*(i-1)//2)+1
ans %= mod
print(ans)
| 1 | 33,098,532,577,614 | null | 170 | 170 |
import math
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
a,b=MI()
print(max(0,a-2*b))
|
x=list(map(int, input().split()))
if x[1]*2>x[0]:
print(0)
else:
print(x[0]-x[1]*2)
| 1 | 166,724,494,538,272 | null | 291 | 291 |
d = {}
for _ in range(int(input())):
d[input()] = ""
print(len(d))
|
n = int(input())
s = [input() for _ in range(n)]
uniq = set(s)
print(len(uniq))
| 1 | 30,204,484,054,108 | null | 165 | 165 |
import itertools
h, w, k = map(int, input().split())
a = []
for i in range(h):
s = input()
a.append(s)
s = [[0 for i in range(w)] for i in range(h)]
ans = h+w
for grid in itertools.product([0,1], repeat=h-1):
ary = [[0]]
for i in range(h-1):
if grid[i] == 1:
ary.append([i+1])
else:
ary[-1].append(i+1)
# print (grid, ary)
wk = 0
for i in grid:
if i == 1:
wk += 1
# print (wk)
cnt = [0] * len(ary)
for j in range(w):
for ii, g in enumerate(ary):
for b in g:
if a[b][j] == '1':
cnt[ii] += 1
if any(W > k for W in cnt):
wk += 1
cnt = [0] * len(ary)
for ii, g in enumerate(ary):
for jj in g:
if a[jj][j] == '1':
cnt[ii] += 1
if any(W > k for W in cnt):
wk = h+w
break
ans = min(ans, wk)
print (ans)
|
H,W,K=map(int,input().split())
S=[[int(s) for s in input()] for i in range(H)]
ans=1000000
for i in range(2**(H-1)):
tmp=0
L=[]
for j in range(H-1):
if i>>j&1:
L.append(j)
tmp+=len(L)
L.append(H-1)
c=[0]*len(L)
for k in range(W):
h=0
c1=[0]*len(L)
for l in range(len(L)):
for m in range(h,L[l]+1):
c1[l]+=S[m][k]
h=L[l]+1
p=0
for l in range(len(L)):
if c1[l]>K:
p=2
break
elif c[l]+c1[l]>K:
p=1
else:
c[l]+=c1[l]
if p==2:
break
elif p==1:
c=[i for i in c1]
tmp+=1
else:
ans=min(ans,tmp)
print(ans)
| 1 | 48,664,838,304,740 | null | 193 | 193 |
n=int(input())
a=list(map(int,input().split()))
q=int(input())
s=sum(a)
data=[0]*10**5
for i in a:
data[i-1]+=1
for i in range(q):
b,c=map(int,input().split())
s+=(c-b)*data[b-1]
print(s)
data[c-1]+=data[b-1]
data[b-1]=0
|
lst = [True for i in range(52)]
n = int(input())
for i in range (n):
suit, rank = input().split()
rankn = int(rank)
if suit == 'S':
lst[rankn-1] = False
elif suit == 'H':
lst[rankn+12] = False
elif suit == 'C':
lst[rankn+25] = False
else:
lst[rankn+38] = False
for i in range(52):
tf = lst[i]
if i <= 12 and tf:
print ('S %d' % (i+1))
elif 12 < i <= 25 and tf:
print ('H %d' % (i-12))
elif 25 < i <= 38 and tf:
print ('C %d' % (i-25))
elif tf:
print ('D %d' % (i-38))
| 0 | null | 6,662,288,288,836 | 122 | 54 |
import math
n,k=map(int,input().split())
a=[0]*n
ans=[0]*n
a=list(map(int,input().split()))
check=math.ceil(math.log2(n))+1
if (k>=42):
a=[n]*n
print(" ".join(map(str,a)))
else:
for _ in range(k):
ans=[0]*n
table=[0]*n
for i in range(n):
left=max(0,i-a[i])
right=min(n-1,i+a[i])
table[left]+=1
if (right+1<n):
table[right+1]-=1
#print(left,right)
#for j in range(left,right+1):
# ans[j]+=1
#print(table)
for i in range(1,n):
table[i]+=table[i-1]
a=table
print(" ".join(map(str,a)))
|
string = input()
height = 0
height_list = [[0, False]]
for s in string:
if s == '\\':
height += -1
elif s == '/':
height += 1
else:
pass
height_list.append([height, False])
highest = 0
for i in range(1, len(height_list)):
if height_list[i-1][0] < height_list[i][0] <= highest:
height_list[i][1] = True
highest = max(highest, height_list[i][0])
puddles = []
area = 0
surface_level = None
for i in range(len(height_list)-1, -1, -1):
if surface_level != None:
area += surface_level - height_list[i][0]
if surface_level == height_list[i][0]:
puddles += [area]
surface_level = None
area = 0
if surface_level == None and height_list[i][1]:
surface_level = height_list[i][0]
puddles = puddles[::-1]
print(sum(puddles))
print(len(puddles), *puddles)
| 0 | null | 7,803,979,003,212 | 132 | 21 |
mod=998244353
class Combination:
def __init__(self,size):
self.size = size + 2
self.fact = [1, 1] + [0] * size
self.factInv = [1, 1] + [0] * size
self.inv = [0, 1] + [0] * size
for i in range(2, self.size):
self.fact[i] = self.fact[i - 1] * i % mod
self.inv[i] = -self.inv[mod % i] * (mod//i) % mod
self.factInv[i] = self.factInv[i - 1] * self.inv[i] % mod
def npk(self,n,k):
if n < k or n < 0 or k < 0:
return 0
return self.fact[n] * self.factInv[n - k] % mod
def nck(self,n,k):
if n < k or n < 0 or k < 0:
return 0
return self.fact[n] * (self.factInv[k] * self.factInv[n - k] % mod) % mod
def nhk(self,n,k):
return self.nck(n + k - 1, n - 1)
n,m,k=map(int,input().split())
comb=Combination(n+k)
res=0
for i in range(k+1):
res+=((comb.nhk(n-i,i))*m)%mod*(pow(m-1,n-1-i,mod))
res%=mod
print(res)
|
def xgcd(a, b):
x0, y0, x1, y1 = 1, 0, 0, 1
while b != 0:
q, a, b = a // b, b, a % b
x0, x1 = x1, x0 - q * x1
y0, y1 = y1, y0 - q * y1
return a, x0, y0
def invmod(a, m):
g, x, y = xgcd(a, m)
if g != 1:
raise Exception('modular inverse does not exist')
else:
return x % m
n, m, k = map(int, input().split())
ans = 0
c = 998244353
ans = m * pow(m-1, n-1, mod=c)
temp = 1
for i in range(1, k+1):
temp = temp*(n-i) % c
temp = temp*invmod(i, c) % c
ans += temp * m * pow(m-1, n-1-i, mod=c)
ans = ans % c
print(ans%c)
| 1 | 23,224,885,415,410 | null | 151 | 151 |
def resolve():
'''
code here
'''
H, W = [int(item) for item in input().split()]
if H == 1 or W == 1:
res = 1
elif H % 2 == 1 and W % 2 == 1:
res = H * W // 2 +1
else:
res = H * W // 2
print(res)
if __name__ == "__main__":
resolve()
|
r=input()
a=input()
if a in r+r:
print('Yes')
else:
print('No')
| 0 | null | 26,467,994,300,748 | 196 | 64 |
n=int(input())
a=list(map(int,input().split()))[::-1]
number=2
if 1 not in a: print(-1);exit()
count=n-len(a[:a.index(1)+1])
a=a[:a.index(1)][::-1]
for i in a:
if i==number:
number+=1
else:
count+=1
print(count)
|
a=int(input())
b=list(map(int,input().split()))
n=1
result=0
for i in range(a):
if b[i]!=n:
result+=1
elif b[i]==n:
n+=1
if result==a:
print(-1)
else:
print(result)
| 1 | 114,529,475,436,908 | null | 257 | 257 |
print input() ** 3
|
def solve():
n = int(input())
print((n+1)//2)
solve()
| 0 | null | 29,516,351,393,088 | 35 | 206 |
S = list(str(input()))
T = list(str(input()))
tt = 0
cnt = 0
for i in S:
if i != T[tt]:
cnt += 1
tt += 1
print(cnt)
|
import sys
for line in sys.stdin:
x, y = map(int, line.split())
print(len(str(x+y)))
| 0 | null | 5,228,223,242,542 | 116 | 3 |
X,N = map(int,input().split())
p = list(map(int,input().split()))
diff = 1
if(X not in p):
print(X)
exit()
while(diff < 200):
if(X-diff not in p):
print(X-diff)
exit()
elif(X+diff not in p):
print(X+diff)
exit()
diff += 1
|
while True:
H,W = map(int, raw_input().split(" "))
if H == 0 and W == 0:
break
else:
for h in xrange(H):
sw = True if (h % 2) == 0 else False
s = ""
for w in xrange(W):
s += "#" if sw else "."
sw = not sw
print s
print ""
| 0 | null | 7,521,337,983,834 | 128 | 51 |
# -*- coding: utf-8 -*-
l = input()
S1, S2 = [], []
sum = 0
n = len(l)
for i in range(n):
if l[i] == "\\":
S1.append(i)
elif l[i] == "/" and S1:
j = S1.pop()
a = i - j
sum += a
while S2 and S2[-1][0] > j:
a += S2.pop()[1]
S2.append([j, a])
print(sum)
print(len(S2), *(a for j, a in S2))
|
# -*- coding: utf-8 -*-
def main():
input_string = raw_input().strip()
down_positions = []
ponds = []
for index, value in enumerate(input_string):
if value == '\\':
down_positions.append(index)
elif value == '/' and down_positions:
right = index
left = down_positions.pop()
area = right - left
candidate_pond = []
while ponds and left < ponds[-1][0]:
candidate_pond.append(ponds.pop(-1))
new_pond = (left, area + sum([x[1] for x in candidate_pond]))
ponds.append(new_pond)
print sum(x[1] for x in ponds)
print len(ponds),
for pond in ponds:
print pond[1],
if __name__ == '__main__':
main()
| 1 | 61,303,725,428 | null | 21 | 21 |
n = int(input())
s = [input() for _ in range(n)]
s_sort = sorted(s)
s_num = [1]*n
for i in range(1,n):
if s_sort[i] == s_sort[i-1]:
s_num[i] += s_num[i-1]
Maxnum = max(s_num)
index_num = [n for n, v in enumerate(s_num) if v == Maxnum]
[print(s_sort[i]) for i in index_num]
|
N = int(input())
l = []
for i in range(N):
l.append(input())
l.sort()
a = l[0]
k = [1]
n = [str(l[0])]
for i in range(1,N):
if a == l[i]:
k[-1] += 1
else:
a = l[i]
k.append(1)
n.append(l[i])
m = max(k)
ans = []
for i in range(len(k)):
if k[i] == m:
ans.append(n[i])
ans.sort()
for i in range(len(ans)):
print(ans[i])
| 1 | 70,355,865,042,624 | null | 218 | 218 |
'''
問題:
高橋君は金色の硬貨が好きです。
自分が持っている 500円硬貨 1枚につき 1000、
5円硬貨 1枚につき 5の嬉しさ を得ます。
高橋君は X 円を持っています。
これを高橋君の嬉しさが最大になるように両替したとき、高橋君の嬉しさはいくらになりますか?
(なお、利用できる硬貨は 500 円玉、100 円玉、50 円玉、10 円玉、5円玉、1 円玉の 6 種類とします。)
'''
'''
Xは整数
0 ≦ X ≦ 1,000,000,000
'''
class Yorokobi:
def __init__(self, money, yorokobi):
self.money = money
self.yorokobi = yorokobi
def calc_yorokobi(self, credit): # credit (残金?)を入力として受け取り、喜びを計算して返す
return (credit // self.money) * self.yorokobi
# 標準入力から X の値を取得する
input_x = int(input())
yorokobi_500 = Yorokobi(500, 1000)
yorokobi_5 = Yorokobi(5, 5)
result = 0 # 結果格納用
if input_x >= 500:
result += yorokobi_500.calc_yorokobi(input_x) # 高橋君 500円の喜び
result += yorokobi_5.calc_yorokobi(input_x % 500) # 高橋君 5円の喜び
else:
result += yorokobi_5.calc_yorokobi(input_x)
print(result)
# ret1 = input_x // 500 # 500円で割った商
# ret2 = ret1 * 1000 # 高橋君 500円の喜び
# ret3 = input_x - (ret1 * 500) # X円から500円の枚数分を引いたお金
# ret4 = ret3 // 5 # (X円から500円の枚数分を引いたお金)÷ 5
# ret5 = ret4 * 5 # 高橋君 5円の喜び
# print(ret2 + ret5)
|
import sys
def read_heights():
current = 0
heights = [current]
for c in sys.stdin.read().strip():
current += {
'/': 1,
'\\': -1,
'_': 0
}[c]
heights.append(current)
return heights
heights = read_heights()
height_index = {}
for i, h in enumerate(heights):
height_index.setdefault(h, []).append(i)
flooded = [False] * len(heights)
floods = []
# search from highest points
for h in sorted(height_index.keys(), reverse=True):
indexes = height_index[h]
for i in range(len(indexes) - 1):
start = indexes[i]
stop = indexes[i + 1]
if start + 1 == stop or flooded[start] or flooded[stop]:
continue
if any(heights[j] >= h for j in range(start + 1, stop)):
continue
# flood in (start..stop)
floods.append((start, stop))
for j in range(start, stop):
flooded[j] = True
floods.sort()
areas = []
for start, stop in floods:
area = 0
top = heights[start]
for i in range(start + 1, stop + 1):
h = heights[i]
area += top - h + (heights[i - 1] - h) * 0.5
areas.append(int(area))
print(sum(areas))
print(' '.join([str(v) for v in [len(areas)] + areas]))
| 0 | null | 21,435,042,909,172 | 185 | 21 |
n = int(input())
a = []
x = []
y = []
for i in range(n):
ai = int(input())
a.append(ai)
xi = []
yi = []
for j in range(ai):
xij, yij = map(int, input().split(' '))
xi.append(xij)
yi.append(yij)
x.append(xi)
y.append(yi)
ans = 0
for case in range(2**n):
truth_t = 0 #正直者の真の数
truth = 0 #正直者の確認した数
for i in range(n): #人ごとに矛盾が生じないか確認
if (case>>i)&1: #正直者であれば証言に矛盾がないか確認
truth_t+=1
proof=0
for j in range(a[i]):
if ((case>>(x[i][j]-1))&1)==y[i][j]:
proof+=1
if proof==a[i]:
truth += 1
if truth==truth_t:
if ans<truth:
ans = truth
print(ans)
|
#!/usr/bin/env python3
import sys
from itertools import chain
from itertools import product
def check(N, ptn, m_assert):
for i in range(N):
if ptn[i] == 1:
for j in range(i + 1, N):
if ptn[j] == 1:
if m_assert[i][j] == 0:
return False
if m_assert[j][i] == 0:
return False
else:
if m_assert[i][j] == 1:
return False
else:
for j in range(i + 1, N):
if ptn[j] == 1:
if m_assert[j][i] == 1:
return False
return True
def solve(N, m_assert):
ans = 0
for ptn in product([1, 0], repeat=N):
if check(N, ptn, m_assert):
ans = max(sum(ptn), ans)
return ans
def main():
N = int(input())
m_assert = [[-1] * N for _ in range(N)]
for n in range(N):
A = int(input())
for a in range(A):
x, y = map(int, input().split())
m_assert[n][x - 1] = y
answer = solve(N, m_assert)
print(answer)
if __name__ == "__main__":
main()
| 1 | 121,675,219,741,440 | null | 262 | 262 |
n,m=map(int,raw_input().split())
A = [[0 for j in range(m)] for i in range(n)]
b = [0 for j in range(m)]
for i in range(n):
A[i]=map(int, raw_input().split())
for j in range(m):
b[j]=input()
for i in range(n):
c=0
for j in range(m):
c+=A[i][j]*b[j]
print(c)
|
n,m=map(int,input().split())
lst=[[]for i in range(n)]
for i in range(n):
lst[i]=list(map(int,input().split()))
lst2=[[]*1 for i in range(m)]
for i in range(m):
lst2[i]=int(input())
for i in range(n):
x=0
for j in range(m):
x=x+lst[i][j]*lst2[j]
print("%d"%(x))
| 1 | 1,162,992,663,026 | null | 56 | 56 |
a,b=input().split()
a=int(a)
b=int(b)
e=a
d=b
c=1
if a>b:
for i in range(1,e):
if a%(e-i)==0 and b%(e-i)==0:
a=a/(e-i)
b=b/(e-i)
c=c*(e-i)
print(int(a*b*c))
if a<b:
for i in range(1,d):
if a%(d-i)==0 and b%(d-i)==0:
a=a/(d-i)
b=b/(d-i)
c=c*(d-i)
print(int(a*b*c))
|
n = int(input())
lst = [int(i) for i in input().split()]
dic = {}
for i in range(n):
if lst[i] not in dic:
dic[lst[i]] = [1, 0, 0]
else:
dic[lst[i]][0] += 1
dic[lst[i]][1] = dic[lst[i]][0] * (dic[lst[i]][0] - 1) // 2
dic[lst[i]][2] = (dic[lst[i]][0] - 1) * (dic[lst[i]][0] - 2) // 2
#print(dic)
count = 0
for value in dic.values():
count += value[1]
for i in range(n):
m = lst[i]
count -= dic[m][1]
count += dic[m][2]
print(count)
count += dic[m][1]
count -= dic[m][2]
| 0 | null | 80,542,226,664,412 | 256 | 192 |
n = int(input())
arr_a = list(map(int, input().split()))
mod = 10**9 + 7
memo = {}
for i in range(n):
if i == 0:
memo[n-i-1] = 0
else:
memo[n-i-1] = (memo[n-i] + arr_a[n-i]) % mod
ans = 0
for i in range(n):
ans += arr_a[i] * memo[i]
ans = ans % mod
print(ans)
|
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
k = int((10**9 + 8)/2)
sum = 0
sum_1 = 0
for i in range(N):
sum += A[i]
sum = (sum**2)%mod
for j in range(N):
sum_1 += A[j]**2
sum_1 = (sum_1)%mod
ans = sum - sum_1
ans = (ans*k)%mod
print(ans)
| 1 | 3,834,506,584,932 | null | 83 | 83 |
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
n = int(input())
now = 0
for _ in range(n):
x, y = map(int, input().split())
if x == y:
now += 1
else:
now = 0
if now == 3:
print("Yes")
return
print("No")
resolve()
|
#coding: UTF-8
l = raw_input().split()
l.sort()
a = int(l[0])
b = int(l[1])
c = int(l[2])
print "%d %d %d" %(a, b, c)
| 0 | null | 1,432,858,700,790 | 72 | 40 |
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
for k in range(N):
B = int(input())
for l in range(3):
for m in range(3):
if A[l][m] == B:
A[l][m] = 0
if (A[0][0] == A[0][1] == A[0][2] == 0) or (A[1][0] == A[1][1] == A[1][2] == 0) or (A[2][0] == A[2][1] == A[2][2] == 0):
print ("Yes")
elif (A[0][0] == A[1][0] == A[2][0] == 0) or (A[0][1] == A[1][1] == A[2][1] == 0) or (A[0][2] == A[1][2] == A[2][2] == 0):
print ("Yes")
elif (A[0][0] == A[1][1] == A[2][2] == 0) or (A[0][2] == A[1][1] == A[2][0] == 0):
print ("Yes")
else:
print ("No")
|
import numpy as np
A=[]
for i in range(3):
A.append(list(map(int,input().split())))
A=np.array(A)
n=int(input())
for i in range(n):
b=int(input())
if b in A:
A=np.where(A==b,0,A)
cross=0
if A[0][0]+A[1][1]+A[2][2]==0 or A[2][0]+A[1][1]+A[0][2]==0:
cross=1
print("NYoe s"[0 in np.sum(A,axis=0) or 0 in np.sum(A,axis=1) or cross ::2])
| 1 | 59,865,341,548,580 | null | 207 | 207 |
import sys
import math
for n in [int(math.log10(float(int(line.split()[0])+int(line.split()[1]))))+1 for line in sys.stdin]:
print n
|
import math
digit = []
while True:
try:
a,b =raw_input().split()
c = int(a)+int(b)
digit.append(int(math.log10(c) + 1))
except:
break
for i in range(0,len(digit)):
print digit[i]
| 1 | 130,912,132 | null | 3 | 3 |
import math
from collections import deque
n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]
xh.sort(key=lambda x:x[0])
xh = deque(xh)
xh_field = deque()
cnt = 0
now_damage = 0
while xh:
pos, hp = xh.popleft()
if xh_field:
while (xh_field and xh_field[0][0] < pos) :
now_damage -= a * xh_field[0][1]
xh_field.popleft()
if hp <= now_damage:
pass
elif hp > now_damage:
atk_cnt = math.ceil((hp - now_damage) / a)
cnt += atk_cnt
now_damage += atk_cnt * a
xh_field.append((2*d + pos, atk_cnt))
print(cnt)
|
N = [int(i) for i in input()]
dp = [0, float('inf')]
# dp = [桁上げしてない, 桁上げあった]
for n in N :
ndp = [0] * 2
ndp[0] = min(dp[0] + n, dp[1] + n)
ndp[1] = min(dp[0] + 11 - n, dp[1] + 9 - n)
dp = ndp
print(min(dp[0], dp[1]))
| 0 | null | 76,228,689,370,570 | 230 | 219 |
n = int(input())
S = 100000
for i in range(n):
S = int(S*1.05)
slist = list(str(S))
if slist[-3:] == ['0','0','0'] :
S = S
else:
S = S - int(slist[-3])*100 - int(slist[-2])*10 - int(slist[-1])*1 + 1000
print(S)
|
n = int(input())
max_div_num = 1
for i in range(2, int(n**(1/2) + 1)):
if n % i == 0:
max_div_num = i
x = max_div_num
y = n // max_div_num
print(x + y - 2)
| 0 | null | 80,543,793,545,752 | 6 | 288 |
s = input()
if s in "abcdefghijklmnopqrstuvwxyz":
print("a")
else:
print("A")
|
from collections import Counter
n, p = map(int, input().split())
s = input()
ans = 0
if p in {2, 5}:
lst = set(i for i in range(0, 10, p))
for i, num in enumerate(s):
if int(num) in lst:
ans += i + 1
else:
num = [0]
for i in range(len(s)):
tmp = num[-1] + pow(10, i, p) * int(s[-i - 1])
num.append(tmp % p)
mod = [0] * p
for i in num:
ans += mod[i]
mod[i] += 1
print(ans)
| 0 | null | 34,545,005,274,868 | 119 | 205 |
# ABC162
# FizzBuzz Sum
n = int(input())
ct = 0
for i in range(n + 1):
if i % 3 != 0:
if i % 5 != 0:
ct += i
else:
continue
print(ct)
|
import math
def lcm(a, b):
return int(a * b/ math.gcd(a, b))
a, b = map(int, input().split())
print(lcm(a,b))
| 0 | null | 73,873,194,361,682 | 173 | 256 |
r=input().split()
H=int(r[0])
N=int(r[1])
data_pre=input().split()
data=[int(s) for s in data_pre]
if sum(data)>=H:
print("Yes")
else:
print("No")
|
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
B = [0]*Q
C = [0]*Q
for i in range(Q):
B[i], C[i] = map(int,input().split())
num = [0]*100001
for i in A:
num[i] += 1
S = [0]*(Q+1)
S[0] = sum(A)
change = 0
for i in range(Q):
change = num[B[i]]
S[i+1] = S[i] + change*(C[i]-B[i])
num[B[i]] -= change
num[C[i]] += change
for i in S[1:]:
print(i)
| 0 | null | 45,166,227,423,328 | 226 | 122 |
S,T = open(0).read().split()
print(T+S)
|
s1 = input()
s2 = input()
while len(s1) <= 100:
s1 = s1 + s1
if s2 in s1:
print("Yes")
else:
print("No")
| 0 | null | 52,112,181,114,058 | 248 | 64 |
N, K, C = map(int, input().split())
S = input()
mae = [0] * (2 * N)
ato = [0] * (2 * N)
cnt = 0
n = 0 - N - 100
for i in range(N):
if i - n <= C:
continue
if S[i] == 'o':
mae[cnt] = i
cnt += 1
n = i
cnt = K - 1
n = 2 * N + 100
for i in range(N-1, -1, -1):
if n - i <= C:
continue
if S[i] == 'o':
ato[cnt] = i
cnt -= 1
n = i
for i in range(K):
if mae[i] == ato[i]:
print(mae[i]+1)
|
a, b = map(int, input().split())
n = max([a - 2 * b, 0])
print(n)
| 0 | null | 103,756,732,549,848 | 182 | 291 |
n, k, c = map(int, input().split())
c += 1
s = list(input())
a = []
i = 0
while i < len(s) and len(a) < k:
if s[i] == 'x':
i += 1
continue
a.append(i)
i += c
b = []
j = len(s)-1
while j > -1 and len(b) < k:
if s[j] == 'x':
j -= 1
continue
b.append(j)
j -= c
b = b[::-1]
for i in range(len(a)):
if a[i] == b[i]:
print(a[i] + 1)
|
from numpy import average
from decimal import Decimal, ROUND_HALF_UP
n=int(input())
x=list(map(int,input().split()))
p=Decimal(str(average(x))).quantize(Decimal('1'),rounding=ROUND_HALF_UP)
ans=0
for i in x:
ans+=((i-p)**2)
print(ans)
| 0 | null | 52,759,909,841,422 | 182 | 213 |
nums = input().split(' ')
a = int(nums[0])
b = int(nums[1])
c = int(nums[2])
d = int(nums[3])
multi = []
multi.append(a * c)
multi.append(a * d)
multi.append(b * c)
multi.append(b * d)
ans = - 10 ** 18
for i in range(4):
if multi[i] > ans:
ans = multi[i]
print(ans)
|
K = int(input())
A,B = map(int,input().split())
if (B//K *K)>=A:
print("OK")
else:
print("NG")
| 0 | null | 14,777,894,724,762 | 77 | 158 |
class Sequence:
def __init__(self,num, seq):
self.n = num
self.sequence = seq
def LinearSearch(A, n, key):
i=0
A[n] = key
while A[i] != key:
i += 1
if i==n:
return "NOT_FOUND"
return i
if __name__ == "__main__":
n = int(raw_input())
x = map(int, raw_input().split())
x.append(" ")
A = Sequence(n, x)
n = int(raw_input())
x = map(int, raw_input().split())
x.append(" ")
B = Sequence(n, x)
C_num = 0
for i in range(B.n):
res = LinearSearch(A.sequence, A.n, B.sequence[i])
if res != "NOT_FOUND":
C_num += 1
print(C_num)
|
n = int(input())
str = input().split(" ")
S = [int(str[i]) for i in range(n)]
q = int(input())
str = input().split(" ")
T = [int(str[i]) for i in range(q)]
S_set = set(S)
S = list(S_set)
T.sort()
result = 0
for s in S:
for t in T:
if s == t:
result += 1
break
print(result)
| 1 | 68,888,190,474 | null | 22 | 22 |
S = input()
T = input()
print('Yes' if T.startswith(S) else 'No')
|
import sys
s, t = [line.rstrip("\n") for line in sys.stdin.readlines()]
if s == t[:-1]:
print("Yes")
else:
print("No")
| 1 | 21,548,186,618,960 | null | 147 | 147 |
s = input()
t = input()
if (len(t)-len(s)==1) and (t[:-1]==s):
print("Yes")
else:
print("No")
|
S=input()
T=input()
T=T[:-1]
if S==T:
print('Yes')
else:
print('No')
| 1 | 21,331,122,746,872 | null | 147 | 147 |
from collections import Counter
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
N = int(input())
edge = [[] for _ in range(N + 1)]
for i in range(N - 1):
x, y = map(int, input().split())
edge[x].append((y, i))
edge[y].append((x, i))
color = [-1] * (N - 1)
def dfs(s, p=-1, pc=-1):
c = 0
for t, x in edge[s]:
if color[x] != -1:
continue
if t == p:
continue
c += 1
if c == pc:
c += 1
color[x] = c
dfs(t, s, c)
dfs(1)
print(len(Counter(color)))
print(*color, sep="\n")
|
import sys
from math import *
readline = sys.stdin.readline
def isPrime(x):
if x == 2 or x == 3:
return True
elif x % 2 == 0 or x % 3 == 0:
return False
s = ceil(sqrt(x))
for i in range(5, s + 1, 2):
if x % i == 0:
return False
return True
print(sum(isPrime(int(readline())) for _ in range(int(input()))))
| 0 | null | 68,182,094,071,730 | 272 | 12 |
a,b=map(int,input().split())
dic={1:3*10**5,2:2*10**5,3:1*10**5}
c=0
if a in dic and b in dic:
if a==1 and b==1:
c+=dic[a]+dic[b]+4*10**5
print(c)
else:
c+=dic[a]+dic[b]
print(c)
elif a in dic and b not in dic:
c+=dic[a]
print(c)
elif b in dic and a not in dic:
c+=dic[b]
print(c)
else:
print(c)
|
MOD = 10**9+7
n, k = map(int, input().split())
a = list(map(int, input().split()))
p, q = [], []
for x in a:
if x >= 0: p.append(x)
else: q.append(x)
lp, lq = len(p), len(q)
def sp():
p.sort(reverse=True)
q.sort()
ans = p[0] if k % 2 else 1
s = []
for i in range(0, lq-1, 2):
s.append(q[i]*q[i+1])
for i in range(k % 2, lp-1, 2):
s.append(p[i]*p[i+1])
s.sort(reverse=True)
for i in range(k//2):
ans *= s[i]
ans %= MOD
print(ans)
def sq():
a.sort(key=lambda x: abs(x))
ans = 1
for i in range(k):
ans *= a[i]
ans %= MOD
print(ans)
if k % 2 and not p: sq()
elif n == k and lq % 2: sq()
else: sp()
| 0 | null | 74,902,206,251,972 | 275 | 112 |
n = int(input())
a = list(map(int, input().split()))
result = [0] * n
for i in range(len(a)):
result[a[i] - 1] += 1
for i in range(len(result)):
print(result[i])
|
#!/usr/bin/env python3
import sys
from itertools import chain
def solve(N: int, A: "List[int]"):
s = [0 for _ in range(N)]
for Ai in A:
s[Ai - 1] += 1
return "\n".join(map(str, s))
def main():
tokens = chain(*(line.split() for line in sys.stdin))
N = int(next(tokens)) # type: int
A = [
int(next(tokens)) for _ in range(N - 2 + 1)
] # type: "List[int]"
answer = solve(N, A)
print(answer)
if __name__ == "__main__":
main()
| 1 | 32,463,516,027,928 | null | 169 | 169 |
import sys
input = sys.stdin.readline
N, M, L = map(int, input().split())
INF = float('inf')
VD = [[INF] * N for _ in range(N)]
for _ in range(M):
a, b, c = map(int, input().split())
a -= 1
b -= 1
VD[a][b] = c
VD[b][a] = c
for i in range(N):
VD[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
if VD[i][j] > VD[i][k] + VD[k][j]:
VD[i][j] = VD[i][k] + VD[k][j]
WD = [[INF] * N for _ in range(N)]
for i in range(N):
WD[i][i] = 0
for j in range(i+1,N):
d = VD[i][j]
if d <= L:
WD[i][j] = 1
WD[j][i] = 1
for k in range(N):
for i in range(N):
for j in range(N):
if WD[i][j] > WD[i][k] + WD[k][j]:
WD[i][j] = WD[i][k] + WD[k][j]
Q = int(input())
for _ in range(Q):
s, t = map(int, input().split())
print(WD[s-1][t-1]-1 if WD[s-1][t-1] < INF else -1)
|
import sys
import math
input = sys.stdin.readline
def warshall_floyd(d):
for k in range(len(d)):
for i in range(len(d)):
for j in range(len(d)):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
N, M, L = map(int, input().split())
d = [[math.inf] * N for _ in range(N)]
for i in range(N):
d[i][i] = 0
for _ in range(M):
a, b, c = map(int, input().split())
a -= 1
b -= 1
d[a][b] = c
d[b][a] = c
warshall_floyd(d)
for i in range(N):
for j in range(N):
d[i][j] = 1 if d[i][j] <= L else math.inf
for i in range(N):
d[i][i] = 0
warshall_floyd(d)
Q = int(input())
for _ in range(Q):
s, t = map(int, input().split())
s -= 1
t -= 1
if s == t:
print(0)
elif d[s][t] == math.inf:
print(-1)
else:
print(d[s][t]-1)
| 1 | 173,382,603,311,828 | null | 295 | 295 |
list = input().split()
print(list[2],list[0],list[1])
|
hp, dmg = map(int, input().split())
if hp % dmg == 0: print(int(hp//dmg))
else: print(int(hp//dmg) + 1)
| 0 | null | 57,446,871,647,034 | 178 | 225 |
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n,m = list(map(int, input().split()))
s = input()
c = n
ans = []
while c>0:
val = None
for i in range(1,m+1):
if c-i>=0 and s[c-i]=="0":
val = i
if val is None:
ans = -1
break
c = c-val
ans.append(val)
if ans==-1:
print(ans)
else:
write(" ".join(map(str, ans[::-1])))
|
import sys
input = lambda: sys.stdin.readline().rstrip()
n, m = map(int, input().split())
s = input()
ans = []
s = s[::-1]
now = 0
while True:
for i in range(m, -1, -1):
if i == 0:
print(-1)
sys.exit()
if now + i <= n and s[now + i] == "0":
now += i
ans.append(i)
if now == n:
print(*ans[::-1])
sys.exit()
else:
break
| 1 | 139,248,737,102,916 | null | 274 | 274 |
w = ["SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"]
s = input()
print((w.index(s)+1)%8)
|
A=[]
for i in range(3):
A.append(list(map(int,input().split())))
N=int(input())
for i in range(N):
x=int(input())
for row in A:
for num in range(len(row)):
if x==row[num]:
row[num]=0
for i in A:
if i==[0,0,0]:
print("Yes")
exit(0)
for i in range(3):
if A[0][i]==0 and A[1][i]==0 and A[2][i]==0:
print("Yes")
exit(0)
if A[0][0]==0 and A[1][1]==0 and A[2][2]==0:
print("Yes")
exit(0)
if A[2][0]==0 and A[1][1]==0 and A[0][2]==0:
print("Yes")
exit(0)
print("No")
| 0 | null | 96,781,757,683,908 | 270 | 207 |
X = int(input())
deposit = 100
y_later = 0
while deposit < X:
y_later += 1
deposit += deposit // 100
print(y_later)
|
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
inf = float("inf")
a = l()
a = list(set(a))
if len(a) == 2:
print("Yes")
else:
print("No")
| 0 | null | 47,481,816,586,248 | 159 | 216 |
import sys
s = input()
p = input()
ss = s + s
if ( p in ss ) ==True:
print("Yes")
else:
print('No')
|
from collections import Counter
from itertools import combinations
N, X, Y = map(int, input().split(' '))
c = Counter()
for i, j in combinations(range(1, N + 1), r=2):
c[min(j - i, abs(X - i) + 1 + abs(j - Y))] += 1
for n in range(1, N):
print(c[n])
| 0 | null | 22,937,474,588,340 | 64 | 187 |
s=list(input())
ans=0
for i in range(len(s)//2):
if s[i]==s[len(s)-1-i]:
continue
ans+=1
print(ans)
|
s = input()
p = input()
for e, i in enumerate(s):
if i == p[0]:
temp = s[e:] + s[:e]
if p in temp:
print('Yes')
break
else:
print('No')
| 0 | null | 60,969,080,136,720 | 261 | 64 |
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n, k = map(int, readline().split())
p = list(map(int, readline().split()))
tmp = [(i+1)/2 for i in p]
cs = list(np.cumsum(tmp))
if n == k:
print(cs[-1])
exit()
ans = 0
for i in range(n - k):
ans = max(ans, cs[i + k] - cs[i])
print(ans)
|
n,m = map(int, raw_input().split())
a = []
b = [0]*m
for i in xrange(n):
x = map(int,raw_input().split(" "))
a.append(x)
for i in xrange(m):
b[i] = input()
result = [0]*n
for i in xrange(n):
for j in xrange(m):
result[i] += a[i][j]*b[j]
print result[i]
| 0 | null | 38,255,877,710,730 | 223 | 56 |
a, b, c, k = map(int, input().split())
if k <= a:
ans = k
elif k <= a + b:
ans = a
else:
ans = a * 2 + b - k # a-(k-(a+b))
print(ans)
|
a, b, c = [int(i) for i in input().split()]
print('Yes' if len(set([a, b, c])) == 2 else 'No')
| 0 | null | 44,844,437,745,136 | 148 | 216 |
a,b = map(int,input().split())
c,d = map(int,input().split())
if ((a+1)==c or (a==12 and c==1)):
if d ==1:
print(1)
else:
print(0)
|
m1,_ = map(int,input().split())
m2,_ = map(int,input().split())
if m1 < m2:
print(1)
else:
print(0)
| 1 | 124,099,658,650,698 | null | 264 | 264 |
N = int(input())
S = set(input() for _ in range(N))
print(len(S))
|
from itertools import accumulate
from bisect import bisect_left,bisect_right
def main():
n,m,k=map(int,input().split())
a=[0]+list(accumulate(map(int,input().split())))
b=[0]+list(accumulate(map(int,input().split())))
result = 0
for i in range(n+1):
tmp = k - a[i]
if tmp < 0:
continue
tmpNum = i + bisect_right(b, tmp) - 1
if tmpNum > result:
result = tmpNum
print(result)
if __name__ == "__main__":
main()
| 0 | null | 20,592,068,893,758 | 165 | 117 |
S = input()
if S[-1] != "s" :
print(S + "s")
elif S[-1] == "s" :
print(S + "es")
else :
print(" ")
|
word = input()
if word[-1] == 's':
print(word + 'es')
else:print(word + 's')
| 1 | 2,391,834,109,418 | null | 71 | 71 |
N = int(input())
a = (N + 2 - 1) // 2
print(a)
|
#!/usr/bin/env python3
def main():
N = int(input())
print(-(-N // 2))
main()
| 1 | 58,838,425,810,418 | null | 206 | 206 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.