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=int(input())
l = [int(x) for x in input().split(' ')]
c=0
for i in range(0,len(l),2):
if((i+1)%2!=0 and l[i]%2!=0):
c+=1
print(c) | import sys
from io import StringIO
import unittest
import os
# 検索用タグ、10^9+7 組み合わせ、スプレッドシートでのトレース
# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)
def cmb(n, r):
mod = 10 ** 9 + 7
ans = 1
for i in range(r):
ans *= n - i
ans %= mod
for i in range(1, r + 1):
ans *= pow(i, mod - 2, mod)
ans %= mod
return ans
def prepare_simple(n, mod=pow(10, 9) + 7):
# n! の計算
f = 1
for m in range(1, n + 1):
f *= m
f %= mod
fn = f
# n!^-1 の計算
inv = pow(f, mod - 2, mod)
# n!^-1 - 1!^-1 の計算
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= mod
invs[m - 1] = inv
return fn, invs
def prepare(n, mod=pow(10, 9) + 7):
# 1! - n! の計算
f = 1
factorials = [1] # 0!の分
for m in range(1, n + 1):
f *= m
f %= mod
factorials.append(f)
# n!^-1 の計算
inv = pow(f, mod - 2, mod)
# n!^-1 - 1!^-1 の計算
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= mod
invs[m - 1] = inv
return factorials, invs
# 実装を行う関数
def resolve(test_def_name=""):
x, y = map(int, input().split())
all_move_count = (x + y) // 3
x_move_count = all_move_count
y_move_count = 0
x_now = all_move_count * 2
y_now = all_move_count
canMake= False
for i in range(all_move_count+1):
if x_now == x and y_now == y:
canMake = True
break
x_move_count -= 1
y_move_count += 1
x_now -= 1
y_now += 1
if not canMake:
print(0)
return
ans = cmb(all_move_count,x_move_count)
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 = """2"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """2 2"""
output = """0"""
self.assertIO(test_input, output)
def test_input_3(self):
test_input = """999999 999999"""
output = """151840682"""
self.assertIO(test_input, output)
# 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
def tes_t_1original_1(self):
test_input = """データ"""
output = """データ"""
self.assertIO(test_input, output)
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
| 0 | null | 78,909,708,602,268 | 105 | 281 |
import bisect
n,m=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
ng=-1
ok=A[-1]*2+1
B=[[0]*n for k in range(2)]
ii=0
while ok-ng>1:
mid=(ok+ng)//2
d=0
for i in range(n):
c=n-bisect.bisect_right(A,mid-A[i],lo=0,hi=len(A))
B[ii][i]=c
d=d+c
if d<m:
ok=mid
ii=(ii+1)%2
else:
ng=mid
D=[0]
for i in range(n):
D.append(D[-1]+A[n-i-1])
ans=0
for i in range(n):
x=B[(ii+1)%2][i]
ans=ans+A[i]*x+D[x]
ans=ans+(m-sum(B[(ii+1)%2]))*ok
print(ans) | A, B = input().split()
A = int(A)
B = int(B)
print(A * B) | 0 | null | 61,870,032,040,612 | 252 | 133 |
S = input().rstrip()
T = input().rstrip()
count = 0
for i in range(len(S)):
if S[i] != T[i]:
count+=1
print(count) | def resolve():
S = list(input())
T = list(input())
cnt = 0
for i in range(len(S)):
if S[i] != T[i]:
cnt += 1
print(cnt)
if '__main__' == __name__:
resolve() | 1 | 10,456,351,438,048 | null | 116 | 116 |
W,H,x,y,r=map(int,input().split())
print('Yes'if(False if x<r or W-x<r else False if y<r or H-y<r else True)else'No')
| # -*- coding: utf-8 -*-
import math
def main():
N = float(input())
print(int(math.pow(N,3)))
if __name__ == '__main__':
main() | 0 | null | 373,204,035,572 | 41 | 35 |
def solve():
N = int(input())
A = [(a, i+1) for i, a in enumerate(map(int, input().split()))]
A.sort(reverse=True)
INF = float('inf')
dp = [[-INF] * (N+1) for _ in range(N+1)]
dp[0][0] = 0
for s in range(1, N+1):
for l in range(s+1):
r = s - l
dp[l][r] = max(dp[l-1][r] + A[s-1][0] * abs(A[s-1][1]-l), dp[l][r-1] + A[s-1][0] * abs(N-r+1-A[s-1][1]))
ans = 0
for m in range(N):
if dp[m][N-m] > ans:
ans = dp[m][N-m]
print(ans)
solve() | n = int(input())
a = list(map(int,input().split()))
ans = [0]*(n+1)
a.insert(0,0)
for i in range(1,n+1):
ans[a[i]] += i
ans.pop(0)
ans = [str(ans[s]) for s in range(n)]
print(" ".join(ans)) | 0 | null | 107,452,081,164,520 | 171 | 299 |
H, W = map(int, input().split())
s = [input() for _ in range(H)]
dp = [[float('inf') for _ in range(W)] for _ in range(H)]
if s[0][0] == '#':
dp[0][0] = 1
else:
dp[0][0] = 0
dx = [0, 1]
dy = [1, 0]
for i in range(H):
for j in range(W):
for k in range(2):
ni = i + dx[k]
nj = j + dy[k]
if ni >= H or nj >= W:
continue
add = 0
# print(i, j, ni, nj)
if s[i][j] == '.' and s[ni][nj] == '#': add += 1
dp[ni][nj] = min(dp[ni][nj], dp[i][j] + add)
# print(dp)
print(dp[H-1][W-1]) | s = input()
cnt = [1] if s[0] == "<" else [0, 1]
bc = s[0]
for i in range(1, len(s)):
if s[i] == bc:
cnt[-1] += 1
else:
cnt.append(1)
bc = s[i]
if len(cnt) % 2 == 1:
cnt.append(0)
ans = 0
for i in range(0, len(cnt), 2):
ma = max(cnt[i], cnt[i + 1])
mi = min(cnt[i], cnt[i + 1])
ans += max(0, ma * (ma + 1) // 2)
ans += max(0, (mi - 1) * mi // 2)
print(ans)
| 0 | null | 102,677,433,490,478 | 194 | 285 |
x,_ = list(map(int,input().split()))
p = list(map(int,input().split()))
x_l = x
x_u = x
while(True):
if(not x_l in p):
print(x_l)
break
if(not x_u in p):
print(x_u)
break
x_l -= 1
x_u += 1 | while True:
H, W = [int(i) for i in input().split()]
if H == W == 0:
break
for h in range(H):
for w in range(W):
if (w + h) % 2 == 0 :
print('#', end='')
else:
print('.', end='')
print()
print() | 0 | null | 7,492,964,073,628 | 128 | 51 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
a,b,c = map(int, input().split())
print("{0} {1} {2}".format(c,a,b)) | X, Y, Z = list(map(str, input().split()))
print(Z+' '+X+' '+Y) | 1 | 38,053,412,147,020 | null | 178 | 178 |
a,b,c = map(int,(input().split()))
d = (a//(b+c))*b + min((a%(b+c)),b)
print(d)
| n = int(input())
print(sum((n - 1) // i for i in range(1, n))) | 0 | null | 29,149,831,729,360 | 202 | 73 |
a = input()
b = input()
res = 0
for i, char in enumerate(a):
if char != b[i]:
res += 1
print(res) |
import random
name = input()
n = random.choice(name)
while name.find(n) > len(name) - 3:
n = random.choice(name)
num = name.find(n)
for i in range(3):
print(name[num + i], end = "") | 0 | null | 12,651,713,067,512 | 116 | 130 |
H,W = map(int,input().split())
if H ==1 or W ==1:
print(1)
else:
a = H*W
if a%2 == 0:
print(int(a/2))
else:
print(int(a/2)+1) | from collections import deque
query = int(input())
l = deque()
for _ in range(query):
command = input().strip()
if command == "deleteFirst":
try:
l.popleft()
except:
pass
elif command == "deleteLast":
try:
l.pop()
except:
pass
else:
command, value = command.split(" ")
if command == "insert":
l.appendleft(int(value))
elif command == "delete":
try:
l.remove(int(value))
except:
pass
print(*l) | 0 | null | 25,374,331,222,720 | 196 | 20 |
a, b = map(int,input().split())
print(sorted([str(a)*b,str(b)*a])[0])
| N = int(input())
count = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
s = str(i)
count[int(s[0])][int(s[-1])] += 1
ans = sum(count[i][j] * count[j][i] for i in range(1, 10) for j in range(1, 10))
print(ans)
| 0 | null | 85,225,539,476,192 | 232 | 234 |
N = int(input())
R = [int(input()) for _ in range(N)]
maxv = -2000000000
minv = R[0]
for i in range(1,N):
maxv = max([maxv, R[i] - minv ])
minv = min([minv, R[i]])
print(maxv)
| a = raw_input().split(" ")
W = int(a[0])
H = int(a[1])
x = int(a[2])
y = int(a[3])
r = int(a[4])
if (x - r) >= 0 and (x + r) <= W and (y - r) >= 0 and (y + r) <= H:
print "Yes"
else:
print "No" | 0 | null | 232,677,824,772 | 13 | 41 |
N,A,B = list(map(int,input().split()))
if (B-A)%2 == 0:
print((B-A)//2)
exit()
A1 = A
B1 = B
A2 = A
B2 = B
count1 = N-B1
ans1 = 0
A1 += (N-B1)
B1 = N
if (B1-A1)%2 == 0:
ans1 = count1+(B1-A1)//2
else:
ans1 = count1+1+(B1-A1)//2
count2 = A2-1
ans2 = 0
B2 -= (A2-1)
A2 = 1
if (B2-A2)%2 == 0:
ans2 = count2+(B2-A2)//2
else:
ans2 = count2+1+(B2-A2)//2
print(min(ans1,ans2)) | s = list(map(int, input().split()))
N = s[0]
A = s[1]
B = s[2]
if (B - A) % 2 == 0:
print((B - A) // 2)
else:
print(min(A - 1,N - B) + 1 + (B - A - 1) // 2) | 1 | 109,177,956,894,238 | null | 253 | 253 |
def gcd(a,b):
while True:
if a > b:
a %= b
else:
b %= a
if a == 0 or b == 0:
return max(a,b)
def lcm(a,b,g):
return int(a*b/g)
from sys import stdin
for l in stdin:
a,b = list(map(int,l.split()))
g = gcd(a,b)
print ("%s %s"%(g,lcm(a,b,g))) | while True:
(H, W) = [int(i) for i in input().split()]
if H == W == 0:
break
print ("\n".join(["".join(["#" if i == 0 or i == W - 1 or j == 0 or j == H - 1 else "." for i in range(W)]) for j in range(H)]))
print() | 0 | null | 404,316,412,420 | 5 | 50 |
MOD = 10 ** 9 + 7
MAX = 60
n = int(input())
a = list(map(int, input().split()))
cnt = [0 for i in range(MAX)]
for i in range(n):
bit = bin(a[i])[2:].zfill(MAX)
for j in range(MAX):
cnt[j] += int(bit[j])
ans = 0
for i in range(MAX):
ans += cnt[MAX - i - 1] * (n - cnt[MAX - i - 1]) * 2 ** i
ans %= MOD
print(ans)
| num = int(input())
dp = { 0: 1, 1: 1 }
def fibonacci(n):
if not n in dp:
dp[n] = fibonacci(n - 1) + fibonacci(n - 2)
return dp[n]
print(fibonacci(num))
| 0 | null | 61,583,842,941,348 | 263 | 7 |
while True:
a, b = map(int, input().split())
if a == 0 and b == 0:
break
for n in range(a):
mark1 = "#"
mark2 = "."
outLen = ""
if n % 2 == 0 :
mark1 = "."
mark2 = "#"
for m in range(b):
if m % 2 != 0:
outLen = outLen + mark1
else:
outLen = outLen + mark2
print(outLen)
print("")
| import sys
for i in sys.stdin.readlines()[:-1]:
h,w = map(int,i.strip().split())
for i in range(h):
for j in range(w):
if (i+j) % 2 == 0:
print('#',end='')
else:
print('.',end='')
print()
print() | 1 | 895,395,917,700 | null | 51 | 51 |
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
d,t,s=nii()
print('Yes' if d/s<=t else 'No') | import sys
prm = sys.stdin.readline()
prm = prm.split()
a = int(prm[0])
b = int(prm[1])
men = a * b
syu = a + a + b + b
print men, syu | 0 | null | 1,918,885,214,848 | 81 | 36 |
import math
r = float(raw_input())
print str("{:.10f}".format(r*r*math.pi)) + ' ' + str("{:.10f}".format(2*r*math.pi)) | X = int(input())
num_item = int(X // 100)
remain = X - num_item * 100
if remain <= num_item * 5:
print(1)
else:
print(0) | 0 | null | 64,155,399,581,600 | 46 | 266 |
import sys
read = lambda: sys.stdin.readline().rstrip()
def counting_tree(N, D):
tot = 1
# cnt = collections.Counter(D)
cnt = [0]*N
for i in D:
cnt[i]+=1
for i in D[1:]:
tot = tot * cnt[i-1]%998244353
return tot if D[0]==0 else 0
def main():
N0 = int(read())
D0 = tuple(map(int, read().split()))
res = counting_tree(N0, D0)
print(res)
if __name__ == "__main__":
main() | s=input()
ans="No"
if len(s)%2==0:
if s=="hi"*(len(s)//2):
ans="Yes"
print(ans) | 0 | null | 104,477,888,249,332 | 284 | 199 |
class UnionFind:
def __init__(self, n=0):
self.d = [-1]*n
def find(self, x):
if self.d[x] < 0:
return x
else:
self.d[x] = self.find(self.d[x])
return self.d[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.d[x] > self.d[y]:
x, y = y, x
self.d[x] += self.d[y]
self.d[y] = x
return True
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.d[self.find(x)]
n, m, k = map(int, input().split())
deg = [0]*100005
uf = UnionFind(n)
for _ in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
deg[a] += 1
deg[b] += 1
uf.unite(a, b)
for _ in range(k):
c, d = map(int, input().split())
c -= 1
d -= 1
if uf.same(c, d):
deg[c] += 1
deg[d] += 1
for i in range(n):
print(uf.size(i) - 1 - deg[i], end="")
if i == n-1:
print()
else:
print(" ", end="")
| # AC: 753 msec(Python3)
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n+1)]
self.size = [1] * (n+1)
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.find(self.par[x])
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.size[x] < self.size[y]:
self.par[x] = y
self.size[y] += self.size[x]
else:
self.par[y] = x
self.size[x] += self.size[y]
def is_same(self, x, y):
return self.find(x) == self.find(y)
def get_size(self, x):
return self.size[self.find(x)]
def main():
N,M,K,*uv = map(int, read().split())
ab, cd = uv[:2*M], uv[2*M:]
uf = UnionFind(N)
friend = [[] for _ in range(N+1)]
for a, b in zip(*[iter(ab)]*2):
uf.unite(a, b)
friend[a].append(b)
friend[b].append(a)
ans = [uf.get_size(i) - 1 - len(friend[i]) for i in range(N+1)]
for c, d in zip(*[iter(cd)]*2):
if uf.is_same(c, d):
ans[c] -= 1
ans[d] -= 1
print(*ans[1:])
if __name__ == "__main__":
main()
| 1 | 61,655,749,460,800 | null | 209 | 209 |
n = int(input())
XY = []
for i in range(n):
a = int(input())
xy = []
for j in range(a):
x, y = map(int, input().split())
xy.append([x, y])
XY.append(xy)
ans = 0
for i in range(2 ** n):
s = [0] * n
cnt = 0
case = True
for j in range(n):
if (i >> j) & 1:
s[j] = 1
cnt += 1
for k in range(n):
if s[k] == 1:
for l in range(len(XY[k])):
if s[XY[k][l][0] - 1] != XY[k][l][1]:
case = False
if case is True:
ans = max(ans, cnt)
print(ans)
| def main():
n = int(input())
xy = []
for i in range(n):
a = int(input())
xy.append([tuple(map(int, input().split())) for _ in range(a)])
c = 0
for i in range(1 << n):
popcnt = bin(i).count('1')
if popcnt <= c:
continue
all_honest = True
for j in range(n):
if (1 << j) & i != 0:
for x, y in xy[j]:
x -= 1 # 人の番号をひとつずらす
if ((1 << x) & i) >> x != y:
all_honest = False
break
if not all_honest:
break
if all_honest:
c = popcnt
print(c)
if __name__ == '__main__':
main()
| 1 | 121,244,095,028,148 | null | 262 | 262 |
N = int(input())
A = list(map(int,input().split()))
def insertionSort(A,N):
for i in range(1,N):
v = A[i]
j = i -1
while j >= 0 and A[j] > v:
A[j+1] = A[j]
j -= 1
A[j+1] = v
outputNum(A)
def outputNum(A):
tmp = map(str,A)
text = " ".join(tmp)
print(text)
outputNum(A)
insertionSort(A,N)
| H, N, *AB = map(int, open(0).read().split())
A = AB[::2]
B = AB[1::2]
dp = [float("inf")] * (H + 1)
dp[0] = 0
for i in range(N):
for h in range(H):
dec_health = min(h + A[i], H)
dp[dec_health] = min(dp[dec_health], dp[h] + B[i])
print(dp[-1])
| 0 | null | 40,564,680,979,968 | 10 | 229 |
N = int(input())
ans = 0
for i in range(1, N+1):
if i % 3 == 0:
continue
if i % 5 == 0:
continue
ans += i
print(ans)
| N = int(input())
sum_num = 0
for i in range(1, N+1):
if (i%3) and (i%5):
sum_num += i
print(sum_num) | 1 | 34,723,883,001,280 | null | 173 | 173 |
str0 = raw_input()
q = int(raw_input())
for i in xrange(q):
# print "###########################"
# print "str0 = " + str0
line = raw_input().split(" ")
temp = str0[int(line[1]):int(line[2])+1]
if line[0] == "print":
print temp
elif line[0] == "reverse":
temp2 = []
# print "temp = " + temp
for j in xrange(len(temp)):
temp2.append(temp[len(temp) - j - 1])
str0 = str0[:int(line[1])] + "".join(temp2) + str0[int(line[2]) + 1:]
# print "str0 = " + str0
elif line[0] == "replace":
str0 = str0[:int(line[1])] + line[3] + str0[int(line[2]) + 1:]
# print "str0 = " + str0 | s = input()
for _ in range(int(input())):
o = list(map(str, input().split()))
a = int(o[1])
b = int(o[2])
if o[0] == "print":
print(s[a:b+1])
elif o[0] == "reverse":
s = s[:a] + s[a:b+1][::-1] + s[b+1:]
else:
s = s[:a] + o[3] + s[b+1:]
| 1 | 2,056,932,810,380 | null | 68 | 68 |
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
l,r,d = map(int,readline().split())
a = (l-1)//d
b = r//d
print(b-a) | l,r,d = [int(x) for x in input().split()]
nums = [int(x) for x in range(l,r+1)]
ans = []
for i in range(len(nums)):
if nums[i]%d == 0:
ans.append(nums[i])
print(len(ans)) | 1 | 7,515,948,802,222 | null | 104 | 104 |
kazu=int(input())
A=[int(i) for i in input().split()]
# kazu=6
# A=[5,2,4,6,1,3]
j=0
for i in range(kazu - 1):
print(A[i], end=" ")
print(A[kazu-1])
for i in range(1,kazu):
v=A[i]
j=i-1
while j>=0 and A[j] >v:
A[j+1]=A[j]
j =j -1
A[j+1]=v
for i in range(kazu-1):
print(A[i],end=" ")
print(A[kazu-1]) | N=int(input())
arr=list(map(int,input().split()))
print(' '.join(map(str,arr)))
for key in range(1,len(arr)):
temp=arr[key]
i=key-1
while i>=0 and arr[i]>temp:
arr[i+1]=arr[i]
i-=1
arr[i+1]=temp
print(' '.join(map(str,arr))) | 1 | 5,925,255,930 | null | 10 | 10 |
a, b, c = map(int, input().split())
k = int(input())
r = 0
while b <= a :
b = 2 * b
r += 1
while c <= b:
c = 2 * c
r += 1
if r <= k:
print("Yes")
else:
print("No") | a, b, c = map(int, input().split())
k = int(input())
def count(v1, v2, k):
while v1 <= v2 and k >= 0:
v1 *= 2
k -= 1
b = v1
return v1, v2, k
b, _, k = count(b, a, k)
_, _, k = count(c, b, k)
if k < 0:
print('No')
else:
print('Yes')
| 1 | 6,907,256,271,360 | null | 101 | 101 |
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_D
sample_input = list(range(3))
# sample_input[0] = '''\\//'''
# sample_input[1] = '''\\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\'''
# sample_input[2] = ''''''
sample_input[0] = '''\\\\//'''
sample_input[1] = '''\\\\///\\_/\\/\\\\\\\\/_/\\\\///__\\\\\\_\\\\/_\\/_/\\'''
sample_input[2] = ''''''
give_sample_input = None
if give_sample_input is not None:
sample_input_list = sample_input[give_sample_input].split('\n')
def input():
return sample_input_list.pop(0)
# main
# a list of tuples (h, l, r)
# h = the hight
# l, r = max of heights of points which is left (right) or equal to this point
terrain_data = []
str_input = input()
list_input = list(str_input)
height = 0
left_max_height = 0
terrain_data.append([height,left_max_height, None])
for path in list_input:
if path == '/':
height += 1
elif path == '\\':
height -= 1
left_max_height = max(left_max_height, height)
terrain_data.append([height,left_max_height, None])
right_max_height = None # dealt as negative infinity
for index in range(len(terrain_data)-1, -1, -1):
height = terrain_data[index][0]
if right_max_height is None:
right_max_height = height
else:
right_max_height = max(right_max_height, height)
terrain_data[index][2] = right_max_height
pool_left = -1
pool_right = -1
area = 0
areas = []
prev_depth = 0
for data in terrain_data:
depth = min(data[1], data[2]) - data[0]
area += (prev_depth + depth)/2
if depth == 0:
if pool_left < pool_right:
areas.append(int(area))
area = 0
pool_right += 1
pool_left = pool_right
else:
pool_right += 1
prev_depth = depth
print(sum(areas))
output = str(len(areas)) + ' '
for a in areas:
output += str(a) + ' '
print(output[:-1]) | N, K = map(int, input().split())
A = list(map(int, input().split()))
def is_ok(x):
cnt = 0
for a in A:
cnt += a // x
if a % x == 0:
cnt -= 1
return cnt <= K
ng = 0
ok = 10**9
while ok - ng > 1:
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
print(ok) | 0 | null | 3,313,219,484,526 | 21 | 99 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
a, b, c, d = map(int, input().split())
while a > 0 and c > 0:
c -= b
if c <= 0:
print('Yes')
sys.exit()
a -= d
if a <= 0:
print('No')
sys.exit()
if __name__ == '__main__':
main()
| from collections import Counter
n = int(input())
c = list(input())
num = Counter(c)
r = num["R"]
ans = ["R"]*r + ["W"]*(n-r)
cnt = 0
for i in range(n):
if c[i] != ans[i]:
cnt += 1
print(cnt//2)
| 0 | null | 18,139,839,456,630 | 164 | 98 |
def check_p(packages, n, trucks, max_p):
i = 0
for _ in range(trucks):
sum = 0
while sum + packages[i] <= max_p:
sum += packages[i]
i += 1
if i == n:
return i
return i
n, k = map(int, input().split())
packages = []
for _ in range(n):
packages.append(int(input()))
left = 0
right = 10 ** 5 * 10 ** 4
while left + 1 < right:
mid = (left + right) // 2
num = check_p(packages, n, k, mid)
if num < n:
left = mid
else:
right = mid
print(right)
| import sys
def allocate(count, weights):
"""allocate all packages of weights onto trucks.
returns maximum load of trucks.
>>> allocate(2, [1, 2, 2, 6])
6
>>> allocate(3, [8, 1, 7, 3, 9])
10
"""
def loadable_counts(maxweight):
n = 0
l = 0
c = count
for w in weights:
l += w
if l > maxweight:
l = w
c -= 1
if c <= 0:
return n
n += 1
return n
i = max(weights)
j = max(weights) * len(weights) // count
while i < j:
mid = (i + j) // 2
if loadable_counts(mid) < len(weights):
i = mid + 1
else:
j = mid
return i
def run():
k, n = [int(i) for i in input().split()]
ws = []
for i in sys.stdin:
ws.append(int(i))
print(allocate(n, ws))
if __name__ == '__main__':
run()
| 1 | 83,965,091,070 | null | 24 | 24 |
def f(x):
now = 0
for i in range(n):
now += (a[i]-1)//x
return now <= k
n, k = map(int, input().split())
a = list(map(int, input().split()))
ng = 0
ok= int(1e9)
while ok - ng > 1:
x = (ok + ng) // 2
if f(x):
ok = x
else:
ng = x
print(ok) | import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
start = 0
end = max(A)
ans = abs(end + start) // 2 + 1
while abs(start - end) > 1:
ans = abs(end + start) // 2
cnt = 0
for i in range(N):
cnt += math.floor(A[i]/ans - 0.0000000001)
if cnt > K: #ダメだったら
start = ans
break
else: #オッケーだったら
end = ans
continue
cnt = 0
for i in range(N):
cnt += math.floor((A[i] / ans) - 0.000000000001)
if cnt > K: # ダメだったら
print(ans + 1)
else: # オッケーだったら
print(ans)
| 1 | 6,543,691,235,190 | null | 99 | 99 |
n,k=map(int,input().split())
ans=0
max=0
min=0
for i in range(k,n+1):
ans+=i*(n-i+1)+1
ans%=1000000007
print(ans+1) | N, K = map(int, input().split())
A = [0]*(N+2)
for i in range(N+1):
A[i+1] += A[i] + i
ans = 0
for i in range(K, N+2):
minv = A[i]
maxv = A[N+1]-A[N-i+1]
ans += maxv-minv+1
ans %= 10**9+7
print(ans)
| 1 | 33,102,751,209,832 | null | 170 | 170 |
n, a, b = map(int, input().split())
x = int(n / (a + b))
y = n - ((a + b) * x)
if y >= a:
z = a
else:
z = y
print(int((a * x) + z)) | X= raw_input().split()
if float(X[2]) + float(X[4]) <= float(X[0])and float(X[2]) - float(X[4]) >= 0 and float(X[3]) + float(X[4]) <= float(X[1]) and float(X[3]) - float(X[4]) >= 0:
print "Yes"
else:
print "No" | 0 | null | 28,237,426,693,762 | 202 | 41 |
n = int(input())
mod = 10**9+7
num = 10**n%mod - 2*(9**n%mod)%mod + 8**n%mod
print(num if num>=0 else num+mod)
| def abc178c():
n = int(input())
print((pow(10, n) - pow(9, n) - pow(9, n) + pow(8, n)) % (pow(10, 9) + 7))
abc178c() | 1 | 3,171,796,551,572 | null | 78 | 78 |
n,*a=map(int,open(0).read().split())
mod=10**9+7
ans=0
for j in range(60):
cnt=0
for i in range(n):
cnt+=a[i]&1
a[i]=(a[i]>>1)
ans+=(cnt*(n-cnt)%mod)*pow(2,j,mod)
ans%=mod
print(ans) | array = []
while True:
n = input()
if n == "0 0":
break
array.append(n.split())
for i in range(len(array)):
for i2 in range(int(array[i][0])):
for i3 in range(int(array[i][1])):
if i3 == int(array[i][1])-1:
print("#")
else:
print("#",end="")
print("") | 0 | null | 61,595,685,562,880 | 263 | 49 |
x, y = [int(i) for i in input().split()]
if x < y:
a = x
x = y
y = a
def kouyakusu(x,y):
yakusu = x % y
if yakusu == 0:
print(y)
return y
else:
kouyakusu(y,yakusu)
max_kouyakusu = kouyakusu(x,y) | # coding: utf-8
def gcd(a, b):
while b:
a, b = b, a % b
return a
n, m = map(int, input().split())
print(int(gcd(n, m))) | 1 | 7,500,623,492 | null | 11 | 11 |
N, X, Y = map(int, input().split())
ans = [0] * (N + 1)
for i in range(1, N):
for j in range(i+1, N+1):
dis1 = j-i
dis2 = abs(X-i) + 1 + abs(Y - j)
dis3 = abs(Y-i) + 1 + abs(X - j)
d = min(dis1,dis2,dis3)
ans[d] += 1
for i in range(1, N):
print(ans[i]) | n,k=map(int,input().split())
a=list(map(int,input().split()))
l,r=10**9,0
while l-r>1:
t=(l+r)//2
if sum((i-1)//t for i in a)>k:
r=t
else:
l=t
print(l) | 0 | null | 25,364,930,617,312 | 187 | 99 |
n = int(input())
d = 'abcdefghijklm'
def conv(s):
s = list(map(lambda x: d[x], s))
return ''.join(s)
def dfs(s):
if len(s) == n:
print(conv(s))
else:
mx = max(s)+1
for i in range(mx+1):
dfs(s+[i])
dfs([0]) | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
from decimal import *
#再帰バージョン
N = INT()
def DFS(n):
if len(n) == N:
print(n)
else:
for i in range(len(set(n))+1):
m = n+ascii_lowercase[i]
DFS(m)
DFS("a")
| 1 | 52,398,992,362,268 | null | 198 | 198 |
N = int(raw_input())
num_list = map(int, raw_input().split())
c = 0
for i in range(0,N,1):
flag =0
minj =i
for j in range(i,N,1):
if num_list[j] < num_list[minj]:
minj = j
flag = 1
c += flag
num_list[i], num_list[minj] = num_list[minj], num_list[i]
print " ".join(map(str,num_list))
print c | def check_x(x: int) -> int:
return 1 if x == 0 else 0
if __name__=='__main__':
print(check_x(int(input()))) | 0 | null | 1,492,827,369,400 | 15 | 76 |
N = int(input())
l = []
for i in range(N):
l.append([int(x) for x in input().split()])
xlim = []
ylim = []
def cha(a):
return [a[0]-a[1],a[0]+a[1]]
for i in range(N):
ylim.append(cha(l[i])[1])
xlim.append(cha(l[i])[0])
xlim.sort()
ylim.sort()
print(max(xlim[-1]-xlim[0],ylim[-1]-ylim[0])) | N = int(input())
p = [list(map(int,input().split())) for _ in range(N)]
z = []
w = []
for i in range(N):
z.append(p[i][0] + p[i][1])
w.append(p[i][0] - p[i][1])
print(max(max(z)-min(z),max(w)-min(w))) | 1 | 3,477,646,859,050 | null | 80 | 80 |
def main():
A, B, C = map(int, input().split())
K = int(input())
while K > 0 and A >= B:
B *= 2
K -= 1
while K > 0 and B >= C:
C *= 2
K -= 1
if A < B < C:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main() | import itertools
A,B,C = list(map(int, input().split()))
K = int(input())
ans = False
for p in itertools.product(['a','b','c'], repeat=K):
A0,B0,C0 = A,B,C
for e in p:
if e == 'a':
A0 = 2*A0
elif e == 'b':
B0 = 2*B0
else:
C0 = 2*C0
if A0 < B0 < C0 :
ans = True
break
print('Yes' if ans else 'No')
| 1 | 6,863,354,262,664 | null | 101 | 101 |
def main():
n, x, y = map(int,input().split())
cnt = 0
ans=[0]*n
for i in range(1,n+1):
for j in range(i+1,n+1):
d = min(j-i,abs(x-i)+abs(y-j)+1)
ans[d] += 1
for i in range(1,n):
print(ans[i])
if __name__ == "__main__":
main() | import sys
import bisect
def input():
return sys.stdin.readline().rstrip()
def main():
N = int(input())
A = []
B = []
for i in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
pass
A.sort()
B.sort()
if N % 2 == 0:
n = N // 2
mini = (A[n]+A[n-1]) /2
maxi = (B[n]+B[n-1]) /2
print(int((maxi-mini)*2)+1)
else:
n = N//2
mini = A[n]
maxi = B[n]
print(maxi-mini+1)
if __name__ == "__main__":
main()
| 0 | null | 30,573,445,747,780 | 187 | 137 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
def cut(x):
cut_count = 0
for i in range(n):
cut_count += (a[i]-1)//x
return cut_count
l = 0
r = 10**9
while r-l > 1:
mid = (l+r)//2
if k >= cut(mid):
r = mid
else:
l = mid
print(r)
| import math
N, K = map(int,input().split())
logs = list(map(int,input().split()))
a = 0
b = max(logs)
b_memo = set()
count=0
flg =0
while b-a > 1:
c = (a+b)//2
times = []
for i in logs:
times.append(math.ceil(i/c)-1)
if sum(times) > K:
a = c
else:
b = c
print(b) | 1 | 6,450,834,560,700 | null | 99 | 99 |
def main():
H,W,M = map(int,input().split())
s = []
h_cnt = [0 for i in range(H)]
w_cnt = [0 for i in range(W)]
for i in range(M):
h,w = map(int,input().split())
s.append([h-1,w-1])
h_cnt[h-1] += 1
w_cnt[w-1] += 1
h_m,w_m = max(h_cnt), max(w_cnt)
h_mp,w_mp = [],[]
for i in range(H):
if h_cnt[i] == h_m:
h_mp.append(i)
for i in range(W):
if w_cnt[i] == w_m:
w_mp.append(i)
f = 0
for i in range(M):
if h_cnt[s[i][0]] == h_m and w_cnt[s[i][1]] == w_m:
f += 1
if len(w_mp)*len(h_mp)-f<1:
print(h_m+w_m-1)
else:
print(h_m+w_m)
if __name__ == "__main__":
main()
| N = int(input())
A_list = list(map(int, input().split()))
if A_list[0] > 1:
print(-1)
exit()
elif A_list[0] == 1:
if N == 0:
print(1)
else:
print(-1)
exit()
sumA = sum(A_list)
node = 1
count = 1
for i in range(len(A_list) - 1):
temp = min([node * 2, sumA])
count += temp
node = temp - A_list[i + 1]
if node < 0:
print(-1)
exit()
sumA -= A_list[i + 1]
print(count) | 0 | null | 11,732,827,091,688 | 89 | 141 |
a = input()
print("A" if a == a.upper() else "a") | alp =['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
a = str(input())
if a in alp:
print('A')
else:
print('a') | 1 | 11,351,002,433,200 | null | 119 | 119 |
a, b = map(int, input().split())
c = []
if a > b:
a, b = b, a
if b%a == 0:
print(a)
else:
while True:
for i in range(a):
x = i + 2
#print(a, x)
if a%x == 0:
if b%x == 0:
c.append(x)
a = a//x
b = b//x
#print(c)
break
elif b%(a//x) == 0:
c.append(a//x)
a = x
b = b//(a//x)
#print(c)
break
#if x%1000 == 0:
#print(x)
if x > a**0.5:
break
if x > a**0.5:
break
s = 1
for j in c:
s = s * j
print(s)
| a,b=map(int,input().split())
x=a%b
while x>0:
a=b
b=x
x=a%b
print(b)
| 1 | 7,700,479,318 | null | 11 | 11 |
cross_section = input()
visited = {0: -1}
height = 0
pools = []
for i, c in enumerate(cross_section):
if c == '\\':
height -= 1
elif c == '/':
height += 1
if height in visited:
width = i - visited[height]
sm = 0
while pools and pools[-1][0] > visited[height]:
_, volume = pools.pop()
sm += volume
pools.append((i, sm + width - 1))
visited[height] = i
print(sum(v for _, v in pools))
print(len(pools), *(v for _, v in pools)) | l = list(input())
h = [0]
for i in range(len(l)):
if l[i] == "\\":
h.append(h[i]-1)
elif l[i] == "/":
h.append(h[i]+1)
else:
h.append(h[i])
A = 0
k = 0
L = []
i = 0
if "".join(l[5:65]) + (" ") == "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ " and "".join(l[1:61]) + (" ") != "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ " :
print("1"+"\n"+ "1" + " " + "1")
else:
while i in range(len(l)):
if l[i] == "\\" and h[i] <= max(h[i+1:len(l)+2]):
s = 0
a = h[i]
s += 0.5
i += 1
while h[i] < a:
s += a - (h[i] + h[i+1])*0.5
i += 1
A += int(s)
k += 1
L.append(int(s))
else:
i += 1
print(A)
print(k,end="")
if len(L) >0:
print(" ",end="")
print(" ".join(map(str, L)))
else:
print("") | 1 | 59,179,593,828 | null | 21 | 21 |
# 1???????????? W ??¨?????? T ,T ??????????????? W ?????°???????????????????????°??????
import sys
# ??????W?????????
w = input()
# ??????T?????????
t = []
# ??????T?????????
while 1:
temp = input()
if temp == "END_OF_TEXT":
break
t += temp.strip(".")
t += " "
# ??????????????????
t = "".join(t).split()
# print(t)
# ??????T???????????¨????????????W????????????????????????
count = 0
for i in range(len(t)):
if t[i].lower() == w:
count += 1
print(count) | import re
W = input()
T = []
count = 0
while(1):
line = input()
if (line == "END_OF_TEXT"):
break
words = list(line.split())
for word in words:
T.append(word)
for word in T:
matchOB = re.fullmatch(W, word.lower())
if matchOB:
count += 1
print(count) | 1 | 1,805,410,129,722 | null | 65 | 65 |
X = input()
if X.isupper():
print("A")
else:
print("a") | n, k = map(int, input().split())
count = 0
for i in range(k, n + 2):
if i == k:
tot_min = 0
tot_max = 0
for j in range(i):
tot_min += j
tot_max += n - j
else:
tot_min += i - 1
tot_max += n - i + 1
count += tot_max - tot_min + 1
count %= 10 ** 9 + 7
print(count) | 0 | null | 22,208,474,830,476 | 119 | 170 |
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
if row <= 0:
return [[] for _ in range(col)]
elif col == 1:
return [I() for _ in range(row)]
else:
read_all = [LI() for _ in range(row)]
return map(list, zip(*read_all))
#################
N,K = LI()
A = LI()
ans = []
for i in range(N-K):
if A[i] < A[K+i]:
ans.append('Yes')
else:
ans.append('No')
for a in ans:
print(a) | from collections import deque
h, w = map(int, input().split())
chiz = [[] for _ in range(w)]
for _ in range(h):
tmp_list = input()
for i in range(w):
chiz[i].append(tmp_list[i])
def bfs(i,j):
ds = [[-1]*h for _ in range(w)]
dq = deque([(i,j)])
ds[i][j] = 0
res = -1
while dq:
i,j = dq.popleft()
for move in [(1,0),(-1,0),(0,-1),(0,1)]:
if i+move[0] >= 0 and i+move[0] < w and j+move[1] >= 0 and j+move[1] < h:
if chiz[i+move[0]][j+move[1]]=='.' and ds[i+move[0]][j+move[1]] == -1:
ds[i + move[0]][j + move[1]] = ds[i][j] + 1
res = max(res,ds[i + move[0]][j + move[1]])
dq.append((i + move[0],j + move[1]))
return res
res = -1
for j in range(h):
for i in range(w):
if chiz[i][j]=='.':
res = max(res, bfs(i,j))
print(res) | 0 | null | 50,959,875,457,972 | 102 | 241 |
i = 0
while(True):
i += 1
num = int(input())
if num == 0:
break
print("Case ",end = "")
print(i,end = ": ")
print(num)
| import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce
rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rf = lambda: map(float, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7
s = rr()
for i in range(1, 6):
if s == 'hi'*i:
print('Yes')
exit()
print('No')
| 0 | null | 26,763,100,785,368 | 42 | 199 |
N=int(input())
D=list(map(int,input().split()))
MOD=998244353
if D[0]!=0:
print(0)
exit()
b=[0]*N
for d in D:
b[d]+=1
if b[0]!=1:
print(0)
exit()
cnt=1
#print(b)
#print(b[1:])
for v1,v2 in zip(b,b[1:]):
#print(v1)
#print(v2)
cnt *= v1**v2 % MOD
print(cnt%MOD) | from collections import*
n,u,v=map(int,input().split())
e=[[]for _ in range(n+1)]
INF=10**18
d=[INF]*(n+1)
for _ in range(n-1):
a,b=map(int,input().split())
e[a]+=[b]
e[b]+=[a]
q=deque([(v,0)])
while q:
now,c=q.popleft()
d[now]=c
for to in e[now]:
if d[to]!=INF:continue
q.append((to,c+1))
q=[(u,0)]
ans=0
vis=[1]*(n+1)
while q:
now,c=q.pop()
vis[now]=0
f=1
for to in e[now]:
if vis[to]:
f=0
if d[to]>c+1:q+=[(to,c+1)]
if d[to]==c+1:ans=max(c+1,ans)
else:ans=max(c,ans)
if len(e[now])==1:ans=max(d[to],ans)
print(ans) | 0 | null | 135,898,720,211,892 | 284 | 259 |
N,K = map(int,input().split())
min = 0
max = 0
ans = 0
for i in range(K,N+2):
min = i*(i-1)//2
max = i*(2*N-i+1)//2
ans += max-min+1
ans %= (10**9+7)
print(int(ans))
| N, K = map(int, input().split())
mod = 10 ** 9 + 7
print(((N+1)*(N*N+2*N+6)//6+(K-1)*(2*K*K-(3*N+4)*K-6)//6) % mod) | 1 | 33,081,052,485,222 | null | 170 | 170 |
n=int(raw_input())
s=range(1,14)
h=range(1,14)
c=range(1,14)
d=range(1,14)
for i in range(n):
hd,r=raw_input().split()
if hd=='S':
s[int(r)-1]=0
elif hd=='H':
h[int(r)-1]=0
elif hd=='C':
c[int(r)-1]=0
elif hd=='D':
d[int(r)-1]=0
a='S '
for i in range(13):
if s[i]!=0:
print a +str(s[i])
a='H '
for i in range(13):
if h[i]!=0:
print a +str(h[i])
a='C '
for i in range(13):
if c[i]!=0:
print a +str(c[i])
a='D '
for i in range(13):
if d[i]!=0:
print a +str(d[i]) | s = input()
print(s[:3]) | 0 | null | 7,965,553,869,642 | 54 | 130 |
from collections import Counter
n = int(input())
s = list(input() for i in range(n))
c = Counter(s)
m = max(c.values())
s = sorted(list(set(s)))
for i in range(len(s)):
if c[s[i]] == m:
print(s[i]) | N=int(input())
S={}
for n in range(N):
s=input()
S[s]=S.get(s,0)+1
S=sorted(S.items(), key=lambda x:(-x[1],x[0]))
maxS=S[0][1]
for s, cnt in S:
if cnt!=maxS:
break
print(s) | 1 | 70,047,773,346,012 | null | 218 | 218 |
#dpでできないかな?
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,cos,radians,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n,a,b=MI()
l=b-a
if l%2==0:
ans=l//2
print(ans)
else:
edge=min(n-b,a-1)
#print(edge)
ans=edge
ans+=1
l-=1
ans+=l//2
print(ans) | n,a,b=map(int,input().split())
if (b-a)%2==0:
print((b-a)//2)
else:
c=min(b-1,n-a)
e=min(a-1,n-b)
d=(b-a-1)//2+e+1
print(min(c,d)) | 1 | 109,393,837,277,918 | null | 253 | 253 |
a,b,c,k=map(int,input().split())
if k<=a:
ans=k
elif k>a and k<=a+b:
ans=a
else:
ans=a-(k-(a+b))
print(ans) | A,B,C,K=map(int, input().split())
if A >= K:
ans = K
elif A+B >= K:
ans = A
else:
ans = A - (K-A-B)
print(ans)
| 1 | 21,792,062,134,228 | null | 148 | 148 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
count = 0
l, r, d= [int(x) for x in readline().rstrip().split()]
#print(l,r,d)
for i in range(l,r+1):
if i % d == 0:
count += 1
print(count)
| l,r,d=[int(x) for x in input().split()]
x=(r-l)//d
if l%d==0 or r%d==0:
x+=1
print(x) | 1 | 7,565,851,677,406 | null | 104 | 104 |
K,N=map(int,input().split())
Alist=list(map(int,input().split()))
Alist+=[Alist[0]+K]
diflist=[Alist[i+1]-Alist[i] for i in range(N)]
print(K-max(diflist)) | import math
K,N = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
for i in range(N):
a.append(a[i] + K)
minimum = math.inf
for i in range(N):
minimum = min(minimum,a[i+N-1]-a[i])
print(minimum)
| 1 | 43,512,387,276,336 | null | 186 | 186 |
M = 10**9 + 7
n,a,b = map(int, input().split())
def modinv(n):
return pow(n, M-2, M)
def comb(n, r):
num = denom = 1
for i in range(1,r+1):
num = (num*(n+1-i))%M
denom = (denom*i)%M
return num * modinv(denom) % M
print((pow(2, n, M) - comb(n, a) - comb(n, b) - 1) % M) | def power(x, y, p) :
res = 1 # Initialize result
# Update x if it is more
# than or equal to p
x = x % p
if (x == 0) :
return 0
while (y > 0) :
# If y is odd, multiply
# x with result
if ((y & 1) == 1) :
res = (res * x) % p
# y must be even now
y = y >> 1 # y = y/2
x = (x * x) % p
return res
def ncr(n, r, p):
# initialize numerator
# and denominator
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den, p - 2, p)) % p
n,a,b=map(int,input().split())
m=10**9+7;
ans=power(2,n,m)
ans-=ncr(n,a,m)
ans-=ncr(n,b,m)
print(ans%m-1)
| 1 | 66,065,956,300,828 | null | 214 | 214 |
#pdf見た
n = int(input())
xl = [list(map(int,input().split())) for i in range(n)]
sf = []
choice = -1e+9
for x,l in xl:
sf.append([x-l,x+l])
sf.sort(key=lambda x:x[1])
cnt = 0
for s,f in sf:
if choice <= s:
cnt += 1
choice = f
print(cnt) | import bisect
H=int(input())
A=[2**x for x in range(51)]
if H==1:
print(1)
elif H==2:
print(3)
else:
index=bisect.bisect_right(A,H)
print(sum(A[:index])) | 0 | null | 85,374,967,195,110 | 237 | 228 |
N, M = map(int, input().split())
if N % 2 == 1:
for m in range(1, M + 1):
print(m, N - m + 1)
count = 1
if N % 2 == 0:
for m in range(1, M + 1):
if m <= (N // 2 - 1) // 2:
start = m
end = N // 2 - m
print(start, end)
else:
start = N // 2 + count
end = N - count + 1
print(start, end)
count += 1
| temp = int(input())
if temp >= 30:
print("Yes")
else:
print("No") | 0 | null | 17,158,716,826,780 | 162 | 95 |
import collections
N = int(input())
a = list(map(int, input().split()))
l = [0]* N
for i in range(N-1):
#print(i, a[i]-1)
l[a[i]-1] += 1
#print(l)
for j in range(N):
print(l[j])
| import collections
N = int(input())
A = list(map(int,input().split()))
a = collections.Counter(A)
for i in range(1,len(A)+2):
print(a[i]) | 1 | 32,552,352,449,880 | null | 169 | 169 |
import sys
input = lambda: sys.stdin.readline().rstrip()
def solve():
A, B = map(int, input().split())
if 1 <= A and A <= 9 and 1 <= B and B <= 9:
print(A * B)
else:
print('-1')
if __name__ == '__main__':
solve()
| nums = [int(e) for e in input().split()]
a=nums[0]
b=nums[1]
c=nums[2]
d=nums[3]
max = a*c
if a * d > max:
max = a * d
if b * c > max:
max = b * c
if b * d > max:
max = b * d
print(max) | 0 | null | 80,307,215,089,464 | 286 | 77 |
import sys
input = sys.stdin.readline
def binary_search_int(ok, ng, test):
"""
:param ok: solve(x) = True を必ず満たす点
:param ng: solve(x) = False を必ず満たす点
"""
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if test(mid):
ok = mid
else:
ng = mid
return ok
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
F = list(map(int, input().split()))
F.sort(reverse=True)
def max2(x,y):
return x if x > y else y
def test(x):
temp = K
for a, f in zip(A, F):
temp -= max2((a - x//f), 0)
if temp < 0:
return False
return True
print(binary_search_int(A[-1]**2 + 100, -1,test))
| ri = [int(v) for v in input().split()]
A, B, C, D = ri
f = 1
while A > 0 and C > 0:
if f:
C -= B
else:
A -= D
f ^= 1
print("Yes" if A > C else "No")
| 0 | null | 97,404,522,882,888 | 290 | 164 |
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
ans = 0
for value in cnt.values():
ans +=int(value*(value-1)/2)
for k in A:
print(ans-cnt[k]+1)
| from itertools import *
N = int(input())
H = []
A = []
for i in range(N):
for j in range(int(input())):
x,y = map(int, input().split())
H+=[[i,x-1,y]]
for P in product([0,1],repeat=N):
for h in H:
if P[h[0]]==1 and P[h[1]]!=h[2]:
break
else:
A+=[sum(P)]
print(max(A)) | 0 | null | 85,034,823,369,772 | 192 | 262 |
N = int(input())
As = list(map(int, input().split()))
sum = 0
for i in range(N):
sum += As[i]
sum %= 10**9+7
ans = 0
for i in range(N):
sum -= As[i]
ans += As[i]*sum
ans %= 10**9+7
print(ans)
| # C - Sum of product of pairs
N = int(input())
A = list(int(a) for a in input().split())
MOD = 10**9 + 7
csA = [0] * (N+1)
for i in range(N):
csA[i+1] = csA[i] + A[i]
ans = 0
for i in range(N-1):
ans += (A[i] * (csA[N] - csA[i+1])) % MOD
print(ans%MOD) | 1 | 3,847,487,386,172 | null | 83 | 83 |
s, t = map(str, input().split())
print(str(t)+str(s)) | ls = list(map(str, input().split()))
print(ls[1]+ls[0]) | 1 | 103,448,353,028,030 | null | 248 | 248 |
i = 1
while True:
a = raw_input()
if a == '0':
break
print "Case %d: %s" % (i,a)
i = i + 1 | n = input()
multiplication_table_List = []
for i in range(1,10):
for j in range(1,10):
multiplication_table_List.append(str(i*j))
if n in multiplication_table_List:
print('Yes')
else:
print('No') | 0 | null | 80,328,255,062,208 | 42 | 287 |
N = int(input())
X = []
Y = []
for _ in range(N):
a = int(input())
tmp = []
for _ in range(a):
tmp.append(list(map(int, input().split())))
X.append(a)
Y.append(tmp)
ans = 0
for bit in range(2 ** N):
flag = True
for i in range(N):
if bit >> i & 1:
for x, y in Y[i]:
flag &= (bit >> (x - 1) & 1) == y
if flag:
ans = max(ans, bin(bit).count("1"))
print(ans)
| n=int(input())
A=[{} for _ in range(n)]
for i in range(n):
for _ in range(int(input())):
x,y=map(int,input().split())
A[i][x]=y
a=0
for i in range(2**n):
t=0
for j in range(n):
if i>>j&1:
if A[j] and any(i>>~-k&1!=A[j][k] for k in A[j]): break
else: t+=1
else: a=max(a,t)
print(a) | 1 | 121,995,685,564,620 | null | 262 | 262 |
N, P = map(int, input().split())
S = [int(i) for i in input()]
from collections import Counter
def solve(S,N,P):
if P==2 or P==5:
ans = 0
for i in range(N):
if S[i]%P==0:
ans += i+1
return ans
cum = [0]*(N+1)
mods = [0]*N
mods[0] = 1
for i in range(1,N):
mods[i] = mods[i-1]*10%P
for i in range(N):
cum[i+1] = (cum[i]+S[N-1-i]*mods[i])%P
c = Counter(cum)
ans = 0
for v in c.values():
ans += v*(v-1)//2
return ans
print(solve(S,N,P))
| n, p = map(int, input().split())
s = list(map(int, input()))
ans = 0
if p == 2 or p == 5:
for i, x in enumerate(s):
if (p == 2 and not x % 2) or (p == 5 and (x == 0 or x == 5)):
ans += i+1
print(ans)
exit()
s.reverse()
cum = [0] * (n+1)
for i in range(n):
cum[i+1] = (cum[i] + s[i] * pow(10, i, p)) % p
t = [0] * p
for x in cum: t[x] += 1
for x in t:
ans += x * (x-1) // 2
print(ans)
| 1 | 57,922,658,198,022 | null | 205 | 205 |
h, n = map(int, input().split())
a = [int(x) for x in input().split()]
print('Yes' if h<=sum(a) else 'No') | def main():
H, _ = map(int, input().split())
A = map(int, input().split())
cond = sum(A) >= H
print('Yes' if cond else 'No')
if __name__ == '__main__':
main()
| 1 | 77,603,124,688,948 | null | 226 | 226 |
import sys
readline = sys.stdin.readline
H1,M1,H2,M2,K = map(int,readline().split())
print(max(0,(H2 * 60 + M2) - (H1 * 60 + M1 + K))) | H1,M1,H2,M2,K = map(int,input().split())
M_all = (H2 *60 + M2) - (H1 *60 + M1) - K
if M_all <= 0:
print('0')
else:
print(M_all) | 1 | 18,184,067,877,482 | null | 139 | 139 |
N,M=map(int, input().split())
peaks=list(map(int, input().split()))
flag=[1]*N
a=0
b=0
for i in range(M):
a,b=map(int,input().split())
a-=1
b-=1
if peaks[a]<=peaks[b]:
flag[a]=0
if peaks[a]>=peaks[b]:
flag[b]=0
ans=0
for i in flag:
ans+=i
print(ans) | import sys
input = sys.stdin.readline
INF = 10**18
sys.setrecursionlimit(10**6)
import itertools as it
import collections as cl
from collections import deque
import math
from functools import reduce
from collections import defaultdict
MOD = 998244353
def li():
return [int(x) for x in input().split()]
N, K = li()
L, R = [], []
for _ in range(K):
l, r = li()
L.append(l)
R.append(r)
# dp[i]: i番目のマスにいく場合の数
dp = [0] * (N+1)
dp[1] = 1
# 区間 [left, right)の和はdpsum[right] - dpsum[left]
# 区間 [left, right]の和はdpsum[right+1] - dpsum[left]
# マス a~bは区間だと[a-1,b-1]に対応。よってマスliからriの和はdpsum[right] - dpsum[left - 1]
dpsum = [0] * (N+1)
dpsum[1] = 1
for i in range(2, N+1):
for j in range(K):
li = max(i - R[j], 1)
ri = i - L[j]
if ri >= 0:
dp[i] += dpsum[ri] - dpsum[li-1]
dp[i] %= MOD
dpsum[i] = dpsum[i-1] + dp[i]
dpsum[i] %= MOD
print(dp[N])
| 0 | null | 13,952,710,478,768 | 155 | 74 |
N = int(input())
if N % 2 == 0:
result = N//2 - 1
else:
result = N//2
print(result) | n = int(input())
lis = []
#print(n)
alf = ""
while n > 0:
n -= 1
mod = n % 26
lis.insert(0,mod)
n = n // 26
#print(n)
for i in lis:
alf += chr(ord("a") + i)
print(alf) | 0 | null | 82,464,998,691,752 | 283 | 121 |
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_e
# https://matsu7874.hatenablog.com/entry/2019/12/01/230357
n = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
ans = 1
# 先頭はr/g/b
count = [3 if i == 0 else 0 for i in range(n + 1)]
for a in A:
ans = ans * count[a] % MOD
if ans == 0:
break
count[a] -= 1
count[a + 1] += 1
print(ans) | n = int(input())
a = list(map(int, input().split()))
status = [0, 0, 0]
mod = 1000000007
ans = status.count(a[0])
status[0] += 1
for i in range(1, n):
ans *= status.count(a[i])
ans %= mod
for j in range(len(status)):
if status[j] == a[i]:
status[j] += 1
break
print(ans)
| 1 | 129,745,613,445,380 | null | 268 | 268 |
N = int(input())
S = [input() for i in range(N)]
# N = 5
# S = ['aa', 'a', 'aa', 'aaaa', 'aa']
C = dict([s,1] for s in S)
L = len(C)
print(L) | X,Y=map(int,input().split());print(max((4-X)*10**5,0)+max((4-Y)*10**5,0)+(400000 if (X,Y)==(1,1) else 0))
| 0 | null | 85,646,625,134,210 | 165 | 275 |
def input_li():
return list(map(int, input().split()))
def input_int():
return int(input())
H, W = input_li()
board = [input() for _ in range(H)]
# dp[x][y] ... マス(x, y)時点で実行した操作の最小回数
dp = [[10 ** 9] * W for _ in range(H)]
dp[0][0] = 1 if board[0][0] == '#' else 0
for h in range(H):
for w in range(W):
is_now_black = board[h][w] == '#'
if h == 0 and w != 0:
dp[h][w] = dp[h][w - 1] + (1 if is_now_black and board[h][w - 1] == '.' else 0)
elif h != 0 and w == 0:
dp[h][w] = dp[h - 1][w] + (1 if is_now_black and board[h - 1][w] == '.' else 0)
elif h != 0 and w != 0:
from_w = dp[h][w - 1] + (1 if is_now_black and board[h][w - 1] == '.' else 0)
from_h = dp[h - 1][w] + (1 if is_now_black and board[h - 1][w] == '.' else 0)
dp[h][w] = min(from_h, from_w)
print(dp[-1][-1])
| H, W = map(int, input().split())
L = [input() for _ in range(H)]
inf = 10**9
dp = [[inf] * W for _ in range(H)]
#[0][0]を埋める
if (L[0][0] == '.'):
dp[0][0] = 0
else:
dp[0][0] = 1
for i in range(H):
for j in range(W):
#[0][0]の時は無視
if (i == 0 and j == 0):
continue
#→の場合。一個前のマス。
a = dp[i][j - 1]
#↓の場合。一個前のマス。
b = dp[i - 1][j]
#.から#に移動するときだけ操作が(1回)必要
if (L[i][j - 1] == "." and L[i][j] == "#"):
a += 1
if (L[i - 1][j] == '.' and L[i][j] == '#'):
b += 1
# min(dp[i][j],a,b)でもいいが結局問題になるのはa,bの比較だけでは?
dp[i][j] = min(a, b)
print(dp[-1][-1]) | 1 | 49,319,986,491,100 | null | 194 | 194 |
n = int(input())
S = [int(s) for s in input().split()]
q = int(input())
T = [int(s) for s in input().split()]
print(sum([t in S for t in T])) | a_len = int(input())
a = {n for n in input().split(" ")}
b_len = int(input())
b = {n for n in input().split(" ")}
print(len(a & b)) | 1 | 65,946,802,900 | null | 22 | 22 |
S=input()
T=input()
Slen=len(S)
Tlen=len(T)
ans=5000
for i in range(0,Slen-Tlen+1):
tans=0
for j in range(0,Tlen):
if S[i+j]!=T[j]:
tans+=1
if tans<ans:
ans=tans
print(ans)
| l = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = list(int(input()) for _ in range(n))
for i in range(3) :
for j in range(3) :
for k in range(n) :
if l[i][j] == b[k] :
l[i][j] = 0
for i in range(3) :
if l[i][0] + l[i][1] + l[i][2] == 0 :
print('Yes')
exit()
if l[0][i] + l[1][i] + l[2][i] == 0 :
print('Yes')
exit()
if l[0][0] + l[1][1] + l[2][2] == 0 :
print('Yes')
exit()
if l[0][2] + l[1][1] + l[2][0] == 0 :
print('Yes')
exit()
print('No') | 0 | null | 31,683,467,686,400 | 82 | 207 |
# coding: utf-8
from collections import defaultdict
def main():
N = int(input())
dic = defaultdict(int)
max_p = 0
for i in range(N):
dic[input()] += 1
d = dict(dic)
l = []
for key, value in d.items():
l.append([key, value])
if max_p < value: max_p = value
l.sort(key=lambda x: (-x[1], x[0]), reverse=False)
for i, j in l:
if j == max_p:
print(i)
else:
break
if __name__ == "__main__":
main()
| if __name__ == '__main__':
n = int(input())
R = [int(input()) for i in range(n)]
minv = R[0]
maxv = R[1] - R[0]
for j in range(1, n):
if (maxv < R[j] - minv):
maxv = R[j] - minv
if (R[j] < minv):
minv = R[j]
print(maxv) | 0 | null | 34,998,192,831,878 | 218 | 13 |
import os
import sys
import numpy as np
def solve(N, U, V, AB):
G = [[0]*0 for _ in range(N+1)]
for idx_ab in range(len(AB)):
a, b = AB[idx_ab]
G[a].append(b)
G[b].append(a)
P1 = np.zeros(N+1, dtype=np.int64)
def dfs1(u):
st = [u]
while st:
v = st.pop()
p = P1[v]
for u in G[v]:
if p != u:
st.append(u)
P1[u] = v
dfs1(U)
path_u2v = [U]
v = V
while v != U:
v = P1[v]
path_u2v.append(v)
path_u2v.reverse()
l = len(path_u2v)
half = (l-2) // 2
c = path_u2v[half]
ng = path_u2v[half+1]
Depth = np.zeros(N+1, dtype=np.int64)
def dfs2(c):
st = [c]
P = np.zeros(N+1, dtype=np.int64)
while st:
v = st.pop()
p = P[v]
d = Depth[v]
for u in G[v]:
if p != u and u != ng:
st.append(u)
P[u] = v
Depth[u] = d + 1
dfs2(c)
c_ = path_u2v[l-1-half]
v = c_
while v != c:
Depth[v] = 0
v = P1[v]
d = l%2
ans = max(Depth) + half + d
return ans
# >>> numba compile >>>
numba_config = [
[solve, "i8(i8,i8,i8,i8[:,:])"],
]
if sys.argv[-1] == "ONLINE_JUDGE":
from numba import njit
from numba.pycc import CC
cc = CC("my_module")
for func, signature in numba_config:
vars()[func.__name__] = njit(signature)(func)
cc.export(func.__name__, signature)(func)
cc.compile()
exit()
elif os.name == "posix":
exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
else:
from numba import njit
for func, signature in numba_config:
vars()[func.__name__] = njit(signature, cache=True)(func)
print("compiled!", file=sys.stderr)
# <<< numba compile <<<
def main():
N, u, v = map(int, input().split())
if N==2:
print(0)
return
AB = np.array(sys.stdin.read().split(), dtype=np.int64).reshape(N-1, 2)
ans = solve(N, u, v, AB)
print(ans)
main()
| import sys
sys.setrecursionlimit(10**9)
f=lambda:map(int,sys.stdin.readline().split())
n,st,sa=f()
g=[set() for _ in range(n)]
for _ in range(n-1):
a,b=f()
g[a-1].add(b-1)
g[b-1].add(a-1)
def dfs(l,v,p=-1,d=0):
l[v]=d
for c in g[v]:
if c!=p: dfs(l,c,v,d+1)
lt=[0]*n
dfs(lt,st-1)
la=[0]*n
dfs(la,sa-1)
print(max(la[i] for i in range(n) if lt[i]<la[i])-1) | 1 | 117,700,504,498,778 | null | 259 | 259 |
from itertools import*
c=[f'{x} {y}'for x,y in product('SHCD',range(1,14))]
exec('c.remove(input());'*int(input()))
if c:print(*c,sep='\n')
| cards = {
'S':[r for r in range(1,13+1)],
'H':[r for r in range(1,13+1)],
'C':[r for r in range(1,13+1)],
'D':[r for r in range(1,13+1)]
}
n = int(input())
for nc in range(n):
(s,r) = input().split()
index = cards[s].index(int(r))
del cards[s][index]
for s in ['S','H','C','D']:
for r in cards[s]:
print(s,r) | 1 | 1,062,688,709,482 | null | 54 | 54 |
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
return list(map(int,readline().split()))
def readTuples():
return tuple(map(int,readline().split()))
def I():
return int(readline())
n,a,b = readInts()
ab = abs(b-a)
if ab%2 == 0:
print(ab//2)
else:
print(min(a-1, n-b) + 1 + (b-a-1)//2)
|
import numpy as np
class Combination :
def __init__ (self, N=10**6, mod=10**9+7) :
self.mod = mod
self.fact = [1, 1]
self.factinv = [1, 1]
self.inv = [0, 1]
for i in range(2, N+1) :
self.fact.append( (self.fact[-1] * i) % mod )
self.inv .append( (-self.inv[mod%i] * (mod//i) ) % mod )
self.factinv.append( (self.factinv[-1] * self.inv[-1]) % mod )
def nCr(self, n, r) :
if ( r < 0 ) or ( n < r ) : return 0
r = min(r, n-r)
return self.fact[n]*self.factinv[r]*self.factinv[n-r] % self.mod
def nPr(self, n, r) :
if ( r < 0 ) or ( n < r ) : return 0
return self.fact[n]*self.factinv[n-r] % self.mod
n, k = map(int, input().split())
mod = 10**9+7
comb = Combination(2*10**5+100)
ans = 0
for m in range(min(n+1,k+1)) :
ans = ans%mod + (comb.nCr(n,m) * comb.nCr(n-1, n-m-1))%mod
print(ans%mod)
| 0 | null | 88,092,562,481,028 | 253 | 215 |
import math
a,b,x = map(int,input().split())
S = a*a*b
if 2*x>=S:
tmp = 2 * (S - x) / (a**3)
else:
tmp = a * b * b / (2 * x)
print(math.degrees(math.atan(tmp)))
| import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')
N, A, B = map(int, input().split())
dis = B - A
if dis % 2 == 0:
ans = dis // 2
else:
ans = min(A - 1, N - B) + 1 + ((B - A) // 2)
print(ans)
| 0 | null | 136,578,204,827,078 | 289 | 253 |
N=int(input())
s,t=[],[]
for i in range(N):
S,T=input().split()
s.append(S)
t.append(int(T))
X=input()
xs=s.index(X)
print(sum(t[xs:])-t[xs]) | n=int(input())
st=[]
for i in range(n):
s,t=input().split()
st.append((s,t))
x=input()
flg=False
ans=0
for i in range(n):
if flg:
ans+=int(st[i][1])
if st[i][0]==x:
flg=True
print(ans) | 1 | 96,560,608,415,570 | null | 243 | 243 |
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect
N = int(input())
def solve():
cnt = 0
for i in range(1, N):
cnt += (N-1)//i
print(cnt)
return 0
if __name__ == "__main__":
solve()
| import math
n=int(input())
s=0
for i in range(n):
a=int(input())
b=math.ceil(a**0.5)
if a==2:
s+=1
elif a%2==0 or a < 2:
continue
else:
c=0
for j in range(3,b+1,2):
if a%j==0:
c+=1
break
if c==0:
s+=1
print(s) | 0 | null | 1,288,298,347,260 | 73 | 12 |
# -*- coding: utf-8 -*-
from collections import deque
queue = deque()
input_list = [int(i) for i in input().split()]
for i in range(input_list[0]):
proc = input().split()
queue.append([proc[0],int(proc[1])])
count = 0
while len(queue) != 0:
proc = queue.popleft()
if input_list[1] < proc[1]:
queue.append([proc[0],proc[1]-input_list[1]])
count += input_list[1]
else:
count += proc[1]
print(proc[0] + ' ' + str(count)) | A,B,C,D = list(map(int,input().split()))
Takahashi = C//B
if C%B != 0 :
Takahashi += 1
Aoki = A//D
if A%D != 0 :
Aoki += 1
# print(Takahashi,Aoki)
ans='No'
if Takahashi <= Aoki:
ans = 'Yes'
print(ans) | 0 | null | 14,877,835,190,332 | 19 | 164 |
N = int(input())
S, T = input().split()
assert len(S) == N
assert len(T) == N
print(''.join([s + t for s, t in zip(S, T)])) | import sys
a = sys.stdin.readlines()
for i in range(len(a)):
b = a[i].split()
m =int(b[0])
f =int(b[1])
r =int(b[2])
if m*f < 0 :
print "F"
elif m==-1 and f==-1 and r==-1:
break
else:
if m+f >= 80:
print "A"
elif 80 > m+f >=65:
print "B"
elif 65 > m+f >=50:
print "C"
elif 50 > m+f >=30 and r < 50:
print "D"
elif 50 > m+f >=30 and r >= 50:
print "C"
elif 30 > m+f:
print "F" | 0 | null | 56,954,303,754,588 | 255 | 57 |
def main():
a, b = map(int, input().split())
maxv = int((101 / 0.1) - 1)
for i in range(maxv+1):
if (i*8//100 == a) and (i*10//100 == b):
print(i)
exit()
print(-1)
if __name__ == '__main__':
main()
| #!/usr/bin/env python3
import sys
import decimal
def input():
return sys.stdin.readline()[:-1]
def main():
A, B = map(int, input().split())
for i in range(1, 10 ** 4):
a = int(decimal.Decimal(i * 0.08))
b = int(decimal.Decimal(i * 0.1))
if a == A and b == B:
print(i)
exit()
print(-1)
if __name__ == '__main__':
main()
| 1 | 56,442,338,126,088 | null | 203 | 203 |
import math
N, A, B = map(int, input().split())
K = math.floor(N // (A + B))
blue = A * K
L = N % (A + B)
if L > A:
blue += A
else:
blue += L
print(blue) | print('a' if input().islower() else 'A') | 0 | null | 33,593,101,823,204 | 202 | 119 |
n = int(input())
s = []
for i in range(n):
s.append(input())
ls1 = []
ls2 = []
for item in s:
stk1 = []
stk2 = []
for ch in item:
if ch == '(':
stk2.append(ch)
else:
if len(stk2) > 0:
stk2.pop()
else:
stk1.append(ch)
l1 = len(stk1)
l2 = len(stk2)
if l2 >= l1:
ls1.append((l1, l2))
else:
ls2.append((l1, l2))
ls1.sort()
cnt = 0
for item in ls1:
cnt -= item[0]
if cnt < 0:
print('No')
exit()
else:
cnt += item[1]
ls2.sort(key=lambda x: x[1])
ls2.reverse()
for item in ls2:
cnt -= item[0]
if cnt < 0:
print('No')
exit()
else:
cnt += item[1]
if cnt != 0:
print('No')
else:
print('Yes')
| n = int(input())
s = input().split()
s.reverse()
print(' '.join(map(str,s)))
| 0 | null | 12,383,666,588,358 | 152 | 53 |
# Vicfred
# https://atcoder.jp/contests/abc154/tasks/abc154_a
# simulation
s, t = input().split()
a, b = list(map(int, input().split()))
u = input()
balls = {}
balls[s] = a
balls[t] = b
balls[u] = balls[u] - 1
print(balls[s], balls[t])
| s, t = input().split()
a, b = map(int, input().split())
u = input()
print(a - (s == u), b - (t == u))
| 1 | 72,080,178,573,090 | null | 220 | 220 |
class Bit:
""" used for only int(>=0)
1-indexed (ignore 0-index)
"""
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
self.depth = n.bit_length()
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
def lower_bound(self, x):
""" 累積和がx以上になる最小のindexと、その直前までの累積和 """
sum_ = 0
pos = 0
for i in range(self.depth, -1, -1):
k = pos + (1 << i)
if k <= self.size and sum_ + self.tree[k] < x:
sum_ += self.tree[k]
pos += 1 << i
return pos + 1, sum_
def get_less_than_x_cnt(self, x):
""" 累積和がx未満 の個数 """
lb_pos, lb_sum = self.lower_bound(x)
return lb_pos-1
def get_less_than_and_x_cnt(self, x):
""" 累積和がx以下 の個数 """
lb_pos, lb_sum = self.lower_bound(x+1)
return lb_pos-1
def get_more_than_x_cnt(self, x):
""" 累積和がxより大きい 個数 """
return self.size - self.get_less_than_and_x_cnt(x)
def main():
n = int(input())
s = list(input())
q = int(input())
ql = []
for _ in range(q):
num,a,b = map(str, input().split())
ql.append((num,a,b))
alp_d = {chr(ord('a') + i): Bit(n) for i in range(26)}
for i, si in enumerate(s):
alp_d[si].add(i+1,1)
for query in ql:
a,b,c = query
if a == '1':
b = int(b)
before = s[b-1]
alp_d[before].add(b, -1)
alp_d[c].add(b,1)
s[b-1] = c
else:
l,r = int(b),int(c)
cnt = 0
for v in alp_d.values():
if v.sum(r)-v.sum(l-1) > 0:
cnt += 1
print(cnt)
if __name__ == "__main__":
main() | from decimal import Decimal
N = int(input())
M = int(N/Decimal(1.08)) + 1
if N == int(M*Decimal(1.08)) :
print( int(M))
else :
print(':(') | 0 | null | 93,806,895,001,284 | 210 | 265 |
k=int(input())
u='ACL'
print(u*k) | K = int(input())
c = ''
for i in range(1,K+1):
c += 'ACL'
print(c)
| 1 | 2,190,285,368,320 | null | 69 | 69 |
my_range = int(input())
data_in = list(map(int,input().split()))
n_of_odd = 0
for ind in range(my_range):
if (ind % 2) == 0:
rem = data_in[ind] % 2
n_of_odd = n_of_odd + rem
print(n_of_odd) | N = int(input())
A = list(map(int, input().split()))
count = 0
for a in A[0::2]:
if a % 2 == 1:
count = count + 1
print(count) | 1 | 7,758,717,044,550 | null | 105 | 105 |
import math
a,b,c,d = (int(x) for x in input().split())
if math.ceil (a/d) < math.ceil (c/b):
print ('No')
else:
print ('Yes') | week = ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN']
S = input()
print(6 - week.index(S)) if week.index(S) != 6 else print(7) | 0 | null | 81,210,272,038,218 | 164 | 270 |
N = int(input())
X = list(map(int, input().split()))
def cost(p):
res = 0
for x in X:
res += (x - p)**2
return res
m = sum(X) // N
print(min(cost(m), cost(m+1))) | n = int(input())
a = list(map(int, input().split()))
ans = 10**9
for i in range(0, 101):
temp = 0
for x in a:
temp += (x-i)**2
ans = min(ans, temp)
print(ans)
| 1 | 65,324,693,242,760 | null | 213 | 213 |
n = int(input())
str = input()
if (n%2 == 0) and (str[:(n//2)] == str[n//2:]):
print("Yes")
else:
print("No") | import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
T1, T2 = mapint()
A1, A2 = mapint()
B1, B2 = mapint()
if not (A1-B1)*(A2-B2)<0:
print(0)
else:
if A1<B1:
A1, B1 = B1, A1
A2, B2 = B2, A2
if A1*T1+A2*T2==B1*T1+B2*T2:
print('infinity')
exit(0)
rest = (A1-B1)*T1
come = (B2-A2)*T2
if come<rest:
print(0)
else:
ans = come//(come-rest)
last = 1 if come%(come-rest)==0 else 0
print(ans*2-1-last) | 0 | null | 138,970,531,191,690 | 279 | 269 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.