code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
N = int(input())
if N == 1:
print(0)
exit()
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
def p_num(m):
ret = 0
for j in range(1,10**12):
ret += j
if ret <= m < ret+(j+1):
ans = j
break
return ans
p = factorization(N)
cnt = 0
for k in range(len(p)):
cnt += p_num(p[k][1])
print(cnt)
|
N = int(input())
A = list(map(int, input().split()))
m=1000
s=0
if A[0]<A[1]:
s=int(1000/A[0])
m=m-s*A[0]
for i in range(1,N-1,1):
m=m+s*A[i]
s=0
if A[i+1]>A[i]:
s=int(m/A[i])
m=m-s*A[i]
m=m+max(A[N-1],A[N-2])*s
print(m)
| 0 | null | 12,187,698,002,818 | 136 | 103 |
N = int(input())
S = [input() for _ in range(N)]
d = {}
for s in S:
if s in d:
d[s] += 1
else:
d[s] = 1
maxcount = max([d[k] for k in d])
maxlist = list(filter(lambda x: d[x] == maxcount, d))
maxlist = sorted(maxlist)
for m in maxlist:
print(m)
|
def main():
n = int(input())
S, T = [], []
for _ in range(n):
s, t = input().split()
S.append(s)
T.append(int(t))
x = input()
print(sum(T[S.index(x) + 1:]))
if __name__ == '__main__':
main()
| 0 | null | 83,931,595,282,792 | 218 | 243 |
import sys
sys.setrecursionlimit(int(1e9))
class uft:
def __init__(self, N):
self.__N = N
self.__arr = [-1] * (N + 1)
def fp(self, x):
if self.__arr[x] < 0:
return x
else:
self.__arr[x] = self.fp(self.__arr[x])
return self.__arr[x]
def add(self, x, y):
px = self.fp(x)
py = self.fp(y)
if px > py:
px, py = py, px
if px == py:
return 1
self.__arr[px] += self.__arr[py]
self.__arr[py] = px
def groups(self):
ret = -1
for i in self.__arr:
if i < 0:
ret += 1
return ret
def show_arr(self):
print(self.__arr)
N, M = map(int, input().split())
UFT = uft(N)
for i in range(M):
A, B = map(int, input().split())
UFT.add(A,B)
print(UFT.groups() -1)
|
import math
from functools import reduce
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm(*numbers):
return reduce(lcm_base, numbers, 1)
N,M = map(int,input().split())
a = list(map(lambda a: int(a)//2, input().split()))
g = lcm(*a)
if any([g // item % 2 == 0 for item in a]):
print(0)
else:
ans = M//g
ans = max(math.ceil(ans/2),0)
print(ans)
| 0 | null | 51,983,597,191,108 | 70 | 247 |
deta_set_count = int(input())
for _ in range(deta_set_count):
k = list(map(int, input().split()))
k= sorted(k)
if k[0]**2 + k[1]**2 == k[2]**2:
print('YES')
else:
print('NO')
|
import sys
N = int(raw_input())
for line in sys.stdin:
a, b, c = sorted(map(int, line.split()))
if a ** 2 + b ** 2 == c ** 2:
print 'YES'
else:
print 'NO'
| 1 | 364,692,132 | null | 4 | 4 |
class Dice:
dice = {'N':2, 'E':4, 'S':5, 'W':3}
currTop = 1
def top(self):
return self.currTop
def rot(self, direction):
newTop = self.dice[direction]
currTop = self.currTop
self.currTop = newTop
if direction == 'N':
self.dice['N'] = 7 - currTop
self.dice['S'] = currTop
elif direction == 'S':
self.dice['N'] = currTop
self.dice['S'] = 7 - currTop
elif direction == 'E':
self.dice['E'] = 7 - currTop
self.dice['W'] = currTop
elif direction == 'W':
self.dice['E'] = currTop
self.dice['W'] = 7 - currTop
faces = list(map(int, input().split()))
cmd = input()
d = Dice()
for c in cmd:
d.rot(c)
print(faces[d.top()-1])
|
i=0
a=list(map(int,input().split()))
for x in range(a[0],a[1]+1):
if(a[2]%x==0):
i+=1
print(i)
| 0 | null | 404,997,037,020 | 33 | 44 |
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
N,M,L=map(int,input().split())
INF = 1 << 31
dist=np.array([[INF for _ in range(N)] for _ in range(N)])
for i in range(N):
dist[i][i]=0
for i in range(M):
a,b,c=map(int,input().split())
a-=1
b-=1
dist[a][b]=c
dist[b][a]=c
dist = floyd_warshall(dist)
for i in range(N):
for j in range(N):
if dist[i][j]<=L:
dist[i][j]=1
else:
dist[i][j]=INF
dist = floyd_warshall(dist)
dist[dist==INF]=0
#dist=dist.astype(int)
#print(dist)
Q=int(input())
ans=[0]*Q
for q in range(Q):
s,t=map(int,input().split())
s-=1
t-=1
ans[q]=int(dist[s][t]-1)
print(*ans,sep='\n')
|
from collections import Counter
S1 = input()
K = int(input())
S1C = Counter(S1)
if len(S1C) == 1:
print(len(S1) * K // 2)
exit()
start = S1[0]
end = S1[-1]
now = S1[0]
a1 = 0
flag = False
for s in S1[1:]:
if flag:
flag = False
now = s
continue
else:
if s == now:
a1 += 1
flag = True
now = s
S2 = S1 + S1
start = S2[0]
end = S2[-1]
now = S2[0]
a2 = 0
flag = False
for s in S2[1:]:
if flag:
flag = False
now = s
continue
else:
if s == now:
a2 += 1
flag = True
now = s
b = a2 - 2 * a1
print(a1 * K + b * (K-1))
| 0 | null | 174,580,392,771,402 | 295 | 296 |
while True:
a,op,b=raw_input().split()
if op == "?":break
if op == "+":print int(a) + int(b)
if op == "-":print int(a) - int(b)
if op == "*":print int(a) * int(b)
if op == "/":print int(a) / int(b)
|
while True:
a, op, b = map(str,input().split())
if op == '+':
print(int(a) + int(b))
elif op == '-':
print(int(a) - int(b))
elif op == '*':
print(int(a) * int(b))
elif op == '/':
print(int(a) // int(b))
elif op == '?':
break
| 1 | 687,183,335,958 | null | 47 | 47 |
sum = 0
num = [0] * (10 ** 5 + 1)
N = int(input())
A = [int(a) for a in input().split()]
for i in range(0, N):
sum += A[i]
num[A[i]] += 1
Q = int(input())
for i in range(0, Q):
B, C = (int(x) for x in input().split())
sum += (C - B) * num[B]
num[C] += num[B]
num[B] = 0
print(sum)
|
import numpy as np
from collections import defaultdict
N = int(input())
A = tuple(map(int, input().split()))
Q = int(input())
BC= [list(map(int,input().split())) for _ in range(Q)]
counter = defaultdict(int)
for x in A:
counter[x] += 1
total = sum(A)
for b, c in BC:
total += (c - b) * counter[b]
counter[c] += counter[b]
counter[b] = 0
print(total)
| 1 | 12,126,935,435,230 | null | 122 | 122 |
def main():
S = input()
if S.endswith('s'):
answer = S + 'es'
else:
answer = S + 's'
print(answer)
if __name__ == "__main__":
main()
|
import bisect
n = int(input())
ls = list(map(int,input().split()))
ls = sorted(ls)
ans = 0
for i in range(n):
for j in range(i+1,n):
k = bisect.bisect_left(ls,ls[i]+ls[j])
ans += k-j-1
print(ans)
| 0 | null | 86,890,516,925,170 | 71 | 294 |
import sys
N = int(input())
S = input()
if N%2!=0 :
print("No")
sys.exit(0)
else:
for i in range(int(N/2)):
if S[i]!=S[i+int(N/2)]:
print("No")
sys.exit(0)
print("Yes")
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N = int(readline())
S = readline().strip()
if N % 2 == 0 and S == S[: N // 2] * 2:
print('Yes')
else:
print('No')
return
if __name__ == '__main__':
main()
| 1 | 146,531,085,435,240 | null | 279 | 279 |
def resolve():
N, M = map(int, input().split())
ans = 0
if N == 1 and M == 1:
pass
else:
if N != 0:
ans += N*(N-1)/2
if M != 0:
ans += M*(M-1)/2
print(int(ans))
resolve()
|
# -*- coding: utf-8 -*-
# combinationを使う
import math
def comb(n, r):
return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))
n, m = map(int, input().split())
counter = 0
if n >= 2:
counter = counter + comb(n, 2)
if m >= 2:
counter = counter + comb(m, 2)
print(counter)
| 1 | 45,549,399,739,338 | null | 189 | 189 |
N = int(input())
D = list(map(int,input().split()))
cnt = 0
for i in range(N):
cnt += D[i]**2
tot = 0
for i in range(N):
tot += D[i]
tot = tot**2
tot -= cnt
print(tot//2)
|
N=int(input())
d=list(map(int,input().split()))
a=0
for i in range(len(d)):
for j in range(len(d)):
if i!=j and i>j:
a+=d[i]*d[j]
print(a)
| 1 | 168,902,868,300,540 | null | 292 | 292 |
n = int(input())
A = list()
for i in range(0, n):
A.append(int(input()))
G = [1] # G[0]????????¨?????????
cnt = 0
# G[i] = 3*Gi-1 + 1
for i in range(1, 100):
h = 4**i + 3*2**(i-1) + 1
if(h > n): # h???n?¶???????????????§?????????4n+3*2n-1+1
m = i
break
else:
G.append(h)
for g in reversed(G):
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
print(m)
print(" ".join(str(x) for x in reversed(G)))
print(cnt)
print("\n".join(str(x) for x in A))
|
import math
def insertionSort(A, n, g):
cnt = 0
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j + g] = A[j]
j -= g
cnt += 1
A[j + g] = v
return cnt
def shellSort(A, n):
cnt = 0
j = int(math.log(2 * n + 1, 3)) + 1
G = list(reversed([(3 ** i - 1)// 2 for i in range(1, j)]))
m = len(G)
for i in range(m):
cnt += insertionSort(A, n, G[i])
return A, cnt, G, m
n = int(input())
A = [int(input()) for i in range(n)]
ans, count, G, m = shellSort(A, n)
print(m)
print(' '.join(map(str,G)))
print(count)
[print(i) for i in A]
| 1 | 29,531,523,690 | null | 17 | 17 |
n = int(input())
A = list(map(int,input().split()))
xor_sum = 0
for i in range(n):
xor_sum = xor_sum^A[i]
ans = []
for i in range(n):
ans.append(xor_sum^A[i])
print(' '.join(map(str,ans)))
|
import sys
input=sys.stdin.readline #文字列入力はするな!!
n=int(input())
a=list(map(int,input().split()))
def f(x):
z=[0]*40
i=1
while x>0:
z[-i]=x%2
x=x//2
i+=1
return z
for i in range(n):
a[i]=f(a[i])
y=[0]*40
for i in range(40):
y[i]=sum(a[j][i] for j in range(n))%2
ans=[]
for i in range(n):
p=0
for j in range(40):
if y[-j-1]!=a[i][-j-1]:
p+=2**j
ans.append(p)
for i in range(n):
print(ans[i], end=" ")
| 1 | 12,510,881,776,312 | null | 123 | 123 |
# https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_c
from decimal import Decimal
import sys
# sys.setrecursionlimit(100000)
def input():
return sys.stdin.readline().strip()
def input_int():
return int(input())
def input_int_list():
return [int(i) for i in input().split()]
def main():
a, b, c = input_int_list()
sqrt_a = Decimal(a)**Decimal("0.5")
sqrt_b = Decimal(b)**Decimal("0.5")
sqrt_c = Decimal(c)**Decimal("0.5")
if sqrt_a + sqrt_b < sqrt_c:
print("Yes")
else:
print("No")
return
if __name__ == "__main__":
main()
|
#!/usr/bin/env python3
a, b, c = map(int, input().split())
if a+b>c:
print('No')
exit()
f1 = 4*a*b - 2*a*b + 2*c*a + 2*b*c
f2 = c**2 + b**2 + a**2
if f1 < f2:
print('Yes')
else:
print('No')
| 1 | 51,706,252,321,180 | null | 197 | 197 |
# 多次元リストの sort に使える
from operator import itemgetter
n = int(input())
x = [0] * n
l = [0] * n
for i in range(n):
x[i], l[i] = map(int, input().split())
st = sorted([(x[i] - l[i], x[i] + l[i]) for i in range(n)], key = itemgetter(1))
ans = 0
# 最後に選んだ仕事の終了時間
last = - 10 ** 10
for i in range(n):
if last <= st[i][0]:
ans += 1
last = st[i][1]
print(ans)
|
n=int(input())
lr=[]
for i in range(n):
x,l=map(int,input().split())
lr.append((x-l,x+l))
lr.sort(key=lambda x: x[1])
ans=0
l=-10**18
r=0
for i in range(n):
if i==0:
tl,tr=lr[i]
l=tl
r=tr
ans+=1
continue
tl,tr=lr[i]
if tl>=r:
ans+=1
r=tr
l=tl
print(ans)
| 1 | 90,050,158,503,420 | null | 237 | 237 |
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF = float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353
H, W = list(map(int, input().split()))
S = []
for i in range(H):
S.append(input())
def bfs(u):
stack = deque([u])
visited = set()
seen = set()
p = [[INF for j in range(W)] for i in range(H)]
p[u[0]][u[1]] = 0
for i in range(H):
for j in range(W):
if S[i][j] == "#":
p[i][j] = -1
while len(stack) > 0:
v = stack.popleft()
###
visited.add(v)
###
a = (v[0] + 1, v[1])
b = (v[0] , v[1] + 1)
c = (v[0] - 1, v[1])
d = (v[0] , v[1] - 1)
e = [a, b, c, d]
for ee in e:
if ee[0] >= 0 and ee[0] <= H-1 and ee[1] >= 0 and ee[1] <= W-1:
if S[ee[0]][ee[1]] == ".":
if ee not in visited:
p[ee[0]][ee[1]] = min(p[ee[0]][ee[1]], p[v[0]][v[1]] + 1)
if ee not in seen:
stack.append(ee)
seen.add(ee)
ans = 0
for i in range(H):
ans = max(ans, max(p[i]))
return ans
sol = 0
for i in range(H):
for j in range(W):
if S[i][j] == ".":
sol = max(sol, bfs((i,j)))
print(sol)
|
a,b=map(int,input().split())
if a-2*b>=0:
print(a-2*b)
else:
print("0")
| 0 | null | 130,479,906,821,822 | 241 | 291 |
s = str(input())
p = str(input())
if p[0] not in s:
print("No")
elif p in s:
print("Yes")
else:
for i in range(len(s)):
s = s[1:] + s[:1]
if p in s:
print("Yes")
break
else:
print("No")
|
s = input()
partition = s.replace('><','>|<').split('|')
ans=0
for sub in partition:
left = sub.count('<')
right = sub.count('>')
ans += sum(range(1, max(left, right) + 1))
ans += sum(range(1, min(left, right)))
print(ans)
| 0 | null | 79,167,367,326,738 | 64 | 285 |
import sys
input = sys.stdin.readline
def p_count(n):
return bin(n)[2:].count('1')
n = int(input())
x = input().rstrip()
x_dec = int(x,base = 2)
pop_cnt = x.count('1')
pop_cnt_0 = (pop_cnt + 1)
pop_cnt_1 = (pop_cnt - 1)
x_0 = pow(x_dec,1,pop_cnt_0)
x_1 = pow(x_dec,1,pop_cnt_1) if pop_cnt_1 > 0 else 0
x_bit = [0]*n
for i in range(n-1,-1,-1):
if x[i] == '0':
x_bit[i] = (x_0 + pow(2,n-1-i,pop_cnt_0))%pop_cnt_0
#x_bit[i] = (x_dec + pow(2,n-1-i))%pop_cnt_0
else:
if pop_cnt_1 > 0:
x_bit[i] = (x_1 - pow(2,n-1-i,pop_cnt_1))
x_bit[i] = x_bit[i] if x_bit[i] >= 0 else x_bit[i] + pop_cnt_1
else:
x_bit[i] = -1
anslist = []
for i in range(n):
if x_bit[i] == -1:
anslist.append(0)
continue
ans = 1
now = x_bit[i]
while True:
if now == 0:
break
now = now%p_count(now)
ans += 1
anslist.append(ans)
for ans in anslist:
print(ans)
|
import sys
sys.setrecursionlimit(10**8)
N = int(input())
X = input()
if X == '0':
for _ in range(N):
print(1)
exit()
mem = [None] * (200005)
mem[0] = 0
def f(n):
if mem[n] is not None: return mem[n]
c = bin(n).count('1')
r = 1 + f(n%c)
mem[n] = r
return r
for i in range(200005):
f(i)
cnt = X.count('1')
a,b = cnt+1, cnt-1
ans = [None] * N
x = int(X,2)
n = x % a
for i,c in reversed(list(enumerate(X))):
if c=='1': continue
ans[i] = mem[(n+pow(2,N-i-1,a))%a] + 1
if b:
n = x % b
for i,c in reversed(list(enumerate(X))):
if c=='0': continue
ans[i] = mem[(n-pow(2,N-i-1,b))%b] + 1
else:
for i in range(N):
if ans[i] is None:
ans[i] = 0
print(*ans, sep='\n')
| 1 | 8,178,337,320,124 | null | 107 | 107 |
S=input()
if S[-1]=='s':
Ans=S+'es'
else:
Ans=S+'s'
print(Ans)
|
n, m = map(int, input().split())
lis = sorted(list(map(int, input().split())), reverse=True)
limit = sum(lis) / (4 * m)
judge = 'Yes'
for i in range(m):
if lis[i] < limit:
judge = 'No'
break
print(judge)
| 0 | null | 20,671,263,334,930 | 71 | 179 |
from collections import deque
import sys
def main():
n, q = map(int,raw_input().split())
Q = deque([])
for i in xrange(n):
a = raw_input().split()
a[1] = int(a[1])
Q.append(a)
elaps = 0
while len(Q) > 0:
u = Q.popleft()
a = min(u[1], q)
u[1] -= a
elaps += a
if u[1] > 0:
Q.append(u)
else:
print u[0], elaps
return 0
main()
|
r = int(input())
import math
ans = 2 * math.pi * r
print(ans)
| 0 | null | 15,856,523,986,812 | 19 | 167 |
str = input()
for char in str:
if char.islower():
print(char.upper(), end='')
else:
print(char.lower(), end='')
print("");
|
inp = input()
print(inp.swapcase())
| 1 | 1,506,732,563,196 | null | 61 | 61 |
n=int(input())
lst=[]
for i in range(n):
a,b=map(int,input().split())
lst.append([a-b,a+b])
lst=sorted(lst,key=lambda x:x[1])
ans=0
end=-float("inf")
for i in lst:
if i[0]>=end:
ans+=1
end=i[1]
print(ans)
|
N = int(input())
R = []
for _ in range(N):
X, L = map(int, input().split())
R.append([X-L, X+L])
R = sorted(R, key=lambda x: x[1])
ans = 1
p = R[0][1]
for i in range(1, N):
if p <= R[i][0]:
ans += 1
p = R[i][1]
print(ans)
| 1 | 89,640,448,986,480 | null | 237 | 237 |
N = str(input())
answer = 'No'
for i in range(len(N)):
# print(N[i])
if N[i] == '7':
answer = 'Yes'
print(answer)
|
n = input()
a = False
for i in n:
if i == '7':
a = True
print('Yes' if a else 'No')
| 1 | 34,283,201,836,400 | null | 172 | 172 |
import sys
from collections import defaultdict
sys.setrecursionlimit(500000)
class Fraction:
def gcd(self, a ,b):
a,b = max(a,b),min(a,b)
while a%b!=0:
a,b = b,a%b
return b
def frac(self,a,b):
if a==0 and b==0:
return (0,0)
elif a==0:
return (0,1)
elif b==0:
return (1,0)
else:
d = self.gcd(abs(a),abs(b))
if a<0:
a = -a
b = -b
return (a//d,b//d)
def __init__(self, a, b):
self.value = self.frac(a,b)
def v(self):
return self.value
def __lt__(self, other):
assert self.value!=(0,0) and other.value!=(0,0), 'value (0,0) cannot be compared.'
a,b = self.value
c,d = other.value
return a*d < b*c
def __le__(self, other):
assert self.value!=(0,0) and other.value!=(0,0), 'value (0,0) cannot be compared.'
a,b = self.value
c,d = other.value
return a*d <= b*c
def __eq__(self, other):
a,b = self.value
c,d = other.value
return a==c and b==d
def __ne__(self, other):
a,b = self.value
c,d = other.value
return not (a==c and b==d)
def __gt__(self, other):
assert self.value!=(0,0) and other.value!=(0,0), 'value (0,0) cannot be compared.'
a,b = self.value
c,d = other.value
return a*d > b*c
def __ge__(self, other):
assert self.value!=(0,0) and other.value!=(0,0), 'value (0,0) cannot be compared.'
a,b = self.value
c,d = other.value
return a*d >= b*c
def __add__(self, other):
a,b = self.value
c,d = other.value
return Fraction(a*d + b*c, b*d)
def __sub__(self, other):
a,b = self.value
c,d = other.value
return Fraction(a*d - b*c, b*d)
def __mul__(self, other):
a,b = self.value
c,d = other.value
return Fraction(a*c, b*d)
def __truediv__(self, other):
a,b = self.value
c,d = other.value
return Fraction(a*d, b*c)
def __neg__(self):
a,b = self.value
return Fraction(-a,b)
def inv(self):
return Fraction(1,1) / self
def input():
return sys.stdin.readline()[:-1]
def main():
N = int(input())
vec = [list(map(int,input().split())) for i in range(N)]
arg = defaultdict(int)
zero = 0
for v in vec:
if v[0] == 0 and v[1] == 0:
zero += 1
else:
f = Fraction(v[0],v[1])
arg[f.v()] += 1
arg[(-f.inv()).v()] += 0
pair = []
fd = lambda : False
checked_list = defaultdict(fd)
for key in arg:
if not checked_list[key]:
inv = (-Fraction(*key).inv()).v()
pair.append([arg[key],arg[inv]])
checked_list[inv] = True
mod = 1000000007
ans = 1
for p1,p2 in pair:
ans *= pow(2,p1,mod) + pow(2,p2,mod) - 1
ans %= mod
ans += zero
ans %= mod
print((ans+mod-1)%mod)
if __name__ == '__main__':
main()
|
a ,b = map(int,input().split())
li = list(map(int,input().split()))
sum = 0
for i in li:
sum += i
if a > sum:
print(a - sum)
elif a == sum:
print(0)
else:
print(-1)
| 0 | null | 26,471,467,919,358 | 146 | 168 |
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))
#################
A,V = LI()
B,W = LI()
T = I()
if (V-W)*T >= abs(A-B):
print('YES')
else:
print('NO')
|
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if v <= w:
print('NO')
elif (abs(a-b) / (v-w)) <= t:
print('YES')
else:
print('NO')
| 1 | 15,142,410,929,608 | null | 131 | 131 |
s = input()
t = input()
t_2 = []
for i in range(len(t) - 1):
t_2.append(t[i])
line = "".join(t_2)
if line == s:
print("Yes")
else:
print("No")
|
S = input()
T = input()
N = len(S)
if len(T) == N+1:
Ts = T[:N]
if Ts == S:
print('Yes')
else:
print('No')
else:
print('No')
| 1 | 21,425,604,718,688 | null | 147 | 147 |
def mitsui2019d_lucky_pin():
import itertools
n = int(input())
s = input()
cnt = 0
for t in itertools.product(range(0, 10), repeat=2):
si = ''.join(map(str,t))
for i in range(n - 2):
if si[0] != s[i]: continue
for j in range(i + 1, n - 1):
if si[1] != s[j]: continue
ss = set(list(s[j+1:]))
cnt += len(ss)
break
break
print(cnt)
mitsui2019d_lucky_pin()
|
n=int(input())
s=input()
ans=0
for i in range(1000):
i='0'*(3-len(str(i)))+str(i)
if i[0] in s:
if i[1] in s[s.index(i[0])+1:]:
if i[2]in s[s.index(i[0])+s[s.index(i[0])+1:].index(i[1])+2:]:
ans+=1
print(ans)
| 1 | 128,360,731,714,600 | null | 267 | 267 |
H,N=map(int,input().split())
print('No' if sum(list(map(int,input().split()))) < H else 'Yes')
|
h,n=map(int,input().split())
a=list(map(int,input().split()))
sum=0
for i in a:
sum += i
if sum<h:
print("No")
else:
print("Yes")
| 1 | 78,062,036,719,770 | null | 226 | 226 |
from collections import defaultdict
N, P = map(int, input().split())
S = input()
if P == 2 or P == 5:
ans = 0
for i in range(N):
if int(S[i]) % P == 0:
ans += i + 1
print(ans)
else:
ctr = defaultdict(int)
ctr[0] = 1
cur = 0
for i in reversed(range(N)):
cur = (cur + int(S[i]) * pow(10, N - i - 1, P)) % P
ctr[cur] += 1
ans = 0
for v in ctr.values():
ans += v * (v - 1) // 2
print(ans)
|
def main():
n, p = map(int, input().split())
s = input()
mu = [None]*n
ans = 0
c = [0]*p
if 10%p == 0:
ss = map(int, s)
ss = list(ss)
for i in range(n):
if ss[i]%p == 0:
ans += i+1
print(ans)
return
sr = s[::-1]
ssr = map(int, sr)
tens = 1
v = 0
for i, si in enumerate(ssr):
v = (v + (si%p)*tens)%p
mu[i] = v
c[v] += 1
tens *= 10
tens %= p
c[0] += 1
for i in c:
if i:
ans += ((i-1)*i)//2
print(ans)
if __name__ == "__main__":
main()
| 1 | 57,936,838,391,872 | null | 205 | 205 |
a = list(set([i*j for i in range(1,10) for j in range(1, 10)]))
n = int(input())
print('Yes' if n in a else 'No')
|
N = int(input())
ac = 0
wa = 0
re = 0
tle = 0
for i in range(N):
s = input()
if s=="AC":
ac += 1
elif s=="WA":
wa += 1
elif s=="RE":
re += 1
elif s=="TLE":
tle += 1
print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle))
print("RE x "+str(re))
| 0 | null | 83,997,864,646,752 | 287 | 109 |
#ITP1_7_D
n,m,l=map(int,input().split())
a=[]
b=[]
for _ in range(n):
a.append(list(map(int,input().split())))
for _ in range(m):
b.append(list(map(int,input().split())))
c=[[0 for _ in range(l)] for _ in range(n)]
for i in range(n):
for j in range(l):
for k in range(m):
c[i][j]+=a[i][k]*b[k][j]
for i in range(n):
for j in range(l-1):
print(c[i][j],end=" ")
print(c[i][-1])
|
n_max, m_max, l_max = (int(x) for x in input().split())
a = []
b = []
c = []
for n in range(n_max):
a.append([int(x) for x in input().split()])
for m in range(m_max):
b.append([int(x) for x in input().split()])
for n in range(n_max):
c.append( [sum(a[n][m] * b[m][l] for m in range(m_max)) for l in range(l_max)])
for n in range(n_max):
print(" ".join(str(c[n][l]) for l in range(l_max)))
| 1 | 1,449,031,380,280 | null | 60 | 60 |
import math
A, B, N = map(int,input().split(' '))
def f(x):
return math.floor(A*x/B)-A*math.floor(x/B)
def main():
if N >= B:
print(f(B-1))
else:
print(f(N))
if __name__ == "__main__":
main()
|
n = int(input())
S = map(int,raw_input().split())
q = int(input())
T = map(int,raw_input().split())
count = 0
for v in T:
for i in range(n):
if S[i] == v:
count += 1
break
print count
| 0 | null | 14,217,138,951,172 | 161 | 22 |
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
import numpy as np
# import heapq
# from collections import deque
# N = int(input())
# S = input()
# n, *a = map(int, open(0))
N, K = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()
# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)
# def dfs(tree, s):
# for l in tree[s]:
# if depth[l[0]] == -1:
# depth[l[0]] = depth[s] + l[1]
# dfs(tree, l[0])
# dfs(tree, 1)
# def factorization(n):
# arr = []
# temp = n
# for i in range(2, int(-(-n**0.5//1))+1):
# if temp%i==0:
# cnt=0
# while temp%i==0:
# cnt+=1
# temp //= i
# arr.append([i, cnt])
# if temp!=1:
# arr.append([temp, 1])
# if arr==[]:
# arr.append([n, 1])
# return arr
A = [i for i in range(N + 1)]
A = np.array(A)
cum_A = np.cumsum(A)
cnt = 0
for i in range(K, N + 1):
cnt += (cum_A[N] - cum_A[N - i]) - cum_A[i - 1] + 1
print((cnt + 1) % (10**9 + 7))
|
N, K = map(int, input().split())
N += 1
ans = 0
p = 10 ** 9 + 7
for k in range(K, N + 1):
ans += (k * (N - k) + 1) % p
ans %= p
print(ans)
| 1 | 33,170,583,653,372 | null | 170 | 170 |
n = int(input())
s = input()
x = [int(i) for i in s]
pc = s.count('1')
def popcnt(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 f(x):
if x == 0:
return 0
return f(x % popcnt(x)) + 1
ans = [0]*n
for a in range(2):
npc = pc
if a == 0:
npc += 1
else:
npc -= 1
if npc <= 0:
continue
r0 = 0
for i in range(n):
r0 = (r0*2) % npc
r0 += x[i]
k = 1
for i in range(n-1, -1, -1):
if x[i] == a:
r = r0
if a == 0:
r = (r+k) % npc
else:
r = (r-k+npc) % npc
ans[i] = f(r) + 1
k = (k*2) % npc
for i in ans:
print(i)
|
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import fractions
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
#2で何回割れるかを数える関数
def t_per2(k):
return format(k,'b')[::-1].find('1')
def main():
n,m = map(int,ipt().split())
a = [int(i) for i in ipt().split()]
k2 = t_per2(a[0])
l = a[0]//2
for ai in a[1::]:
if not k2 == t_per2(ai):
print(0)
exit()
l = l*(ai//2)//(fractions.gcd(l,ai//2))
if l > m:
print(0)
exit()
print((m+l)//(2*l))
return
if __name__ == '__main__':
main()
| 0 | null | 54,767,976,391,028 | 107 | 247 |
l = int(input())
ll = float(l)
a=0
b=0
c=0
if(ll%3 == 0):
a=ll/3
b=ll/3
c=ll/3
else:
a=ll/3
b=a
c=ll-a-b
print(a*b*c)
|
# L = x + y + z
# S = x*y*z
#これをSが最大となるようにyとLの式で表すと
# S_max = 1/2 * (L - y) * y * 1/2 * (L - y) = 1/4 * (y**3 - 2*L*y**2 +L**2 * y)
L = int(input())
S_list = []
for y in range(L*10**3):
y_cal = y / 10**3
s = 1/4 * (y_cal**3 - 2*L*y_cal**2 +L**2 * y_cal)
S_list.append(s)
S_max = max(S_list)
print(S_max)
| 1 | 47,292,163,560,030 | null | 191 | 191 |
def North(dice):
w = dice[0]
dice[0] = dice[1]
dice[1] = dice[5]
dice[5] = dice[4]
dice[4] = w
return dice
def East(dice):
w = Dice[1]
dice[1] = dice[2]
dice[2] = dice[4]
dice[4] = dice[3]
dice[3] = w
return dice
def West(dice):
w = dice[0]
dice[0] = dice[2]
dice[2] = dice[5]
dice[5] = dice[3]
dice[3] = w
return dice
maxloop = 4
Ncnt = 0
Ecnt = 0
Wcnt = 0
Dice = input().split()
q = int(input())
CopyDice = Dice
for i1 in range(q):
Nloop = True
Eloop = True
Wloop = True
Ncnt = 0
Ecnt = 0
Wcnt = 0
I = input().split()
top = I[0]
front = I[1]
while Eloop:
while Nloop:
while Wloop:
if Dice[0] == top and Dice[1] == front:
print(Dice[2])
Nloop = False
Eloop = False
Wloop = False
break
Dice = West(Dice)
Wcnt += 1
if Wcnt == maxloop:
Wloop = False
Dice = North(Dice)
Wcnt = 0
Wloop = True
Ncnt += 1
if Ncnt == maxloop:
Nloop = False
Dice = East(Dice)
Ncnt = 0
Nloop = True
Ecnt += 1
if Ecnt == maxloop:
Eloop = False
Dice = CopyDice
|
n,m = map(int,input().split())
h = list(map(int,input().split()))
l = [list(map(int,input().split())) for i in range(m)]
a,b = [list(i) for i in zip(*l)]
z = [1] * n
for i in range(m):
x = a[i] - 1
y = b[i] - 1
if h[x] < h[y]:
z[x] = 0
elif h[x] > h[y]:
z[y] = 0
else:
z[x] = 0
z[y] = 0
print(n - z.count(0))
| 0 | null | 12,742,693,742,020 | 34 | 155 |
N = int(input())
A = list(map(int,input().split()))
mode = 0
money = 1000
kabu = 0
for i in range(N):
if i == 0:
if A[i+1] > A[i]:
kabu += 1000//A[i]
money -= kabu*A[i]
mode = 1
else:
continue
elif i == N-1:
money += kabu*A[i]
else:
if mode == 1:
if A[i] >= A[i-1]:
if A[i] > A[i+1]:
money += kabu*A[i]
kabu = 0
mode = 0
else:
continue
else:
if A[i] < A[i+1]:
kabu += money//A[i]
money -= kabu*A[i]
mode = 1
else:
continue
print(money)
|
import sys
def input():
return sys.stdin.readline()[:-1]
def main():
N = int(input())
A = list(map(int,input().split()))
zougen = [-1 if A[i] > A[i + 1] else 1 for i in range(N - 1)]
money = 1000
kabu = 0
for i in range(N-1):
if zougen[i] == 1:
kabu += money // A[i]
money = money % A[i]
else:
money += kabu * A[i]
kabu = 0
print(A[-1] * kabu + money)
if __name__ == "__main__":
main()
| 1 | 7,329,633,181,640 | null | 103 | 103 |
import sys
dataset = sys.stdin.readlines()
for s in range(ord('a'), ord('z') + 1):
count = 0
for data in dataset:
count += data.lower().count(chr(s))
print("{0} : {1}".format(chr(s), count))
|
import copy
import random
import sys
import time
from collections import deque
t1 = time.time()
readline = sys.stdin.buffer.readline
global NN
NN = 26
def evaluate(D, C, S, out, k):
score = 0
last = [0 for _ in range(NN)]
for d in range(len(out)):
last[out[d]] = d + 1
for i in range(NN):
score -= (d + 1 - last[i]) * C[i]
score += S[d][out[d]]
for d in range(len(out), min(D, len(out) + k)):
for i in range(NN):
score -= (d + 1 - last[i]) * C[i]
return score
def compute_score(D, C, S, out):
score = 0
last = [0 for _ in range(NN)]
for d in range(len(out)):
p = out[d]
last[p] = d + 1
last[out[d]] = d + 1
for i in range(NN):
score -= (d + 1 - last[i]) * C[i]
score += S[d][out[d]]
return score
def solve(D, C, S, k):
out = deque()
for _ in range(D):
max_score = -10 ** 8
best_i = 0
for i in range(NN):
out.append(i)
score = evaluate(D, C, S, out, k)
if max_score < score:
max_score = score
best_i = i
out.pop()
out.append(best_i)
return out
# 1箇所ランダムに変える
def random_change(D, C, S, out, score):
new_out = copy.deepcopy(out)
d = random.randrange(0, D)
new_out[d] = random.randrange(0, NN)
new_score = compute_score(D, C, S, new_out)
if new_score > score:
score = new_score
out = new_out
return out, score
# N箇所ランダムに変える
def random_changeN(D, C, S, out, score):
N = 2
new_out = copy.deepcopy(out)
for _ in range(N):
d = random.randrange(0, D)
new_out[d] = random.randrange(0, NN)
new_score = compute_score(D, C, S, new_out)
if new_score > score:
score = new_score
out = new_out
return out, score
# 2つswap
def random_swap2(D, C, S, out, score):
d1 = random.randrange(0, D - 1)
d2 = random.randrange(d1 + 1, min(d1 + 16, D))
new_out = copy.deepcopy(out)
new_out[d1], new_out[d2] = out[d2], out[d1]
new_score = compute_score(D, C, S, out)
if new_score > score:
score = new_score
out = new_out
return out, score
# 3つswap
def random_swap3(D, C, S, out, score):
d1 = random.randrange(0, D - 1)
d2 = random.randrange(d1 + 1, min(d1 + 8, D))
d3 = random.randrange(max(d1 - 8, 0), d1 + 1)
new_out = copy.deepcopy(out)
new_out[d1], new_out[d2], new_out[d3] = out[d2], out[d3], out[d1]
new_score = compute_score(D, C, S, out)
if new_score > score:
score = new_score
out = new_out
return out, score
def main():
D = int(readline())
C = list(map(int, readline().split()))
S = [list(map(int, readline().split())) for _ in range(D)]
# ランダムな初期値
# out = [random.randrange(0, NN) for _ in range(D)]
# 貪欲法で初期値を決める
# k = 18 # kを大きくして,局所解から遠いものを得る
k = 26 # kを大きくして,局所解から遠いものを得る
out = solve(D, C, S, k)
# 初期値を数カ所変える
# np = 0.2 # 変えすぎ?
# np = 0.1
np = 0.05
n = int(D * np)
queue = [random.randrange(0, D) for _ in range(n)]
for q in queue:
out[q] = random.randrange(0, NN)
score = compute_score(D, C, S, out)
for cnt in range(10 ** 10):
bl = [random.randint(0, 1) for _ in range(5)]
for b in bl:
if b:
out, score = random_change(D, C, S, out, score)
# out, score = random_changeN(D, C, S, out, score)
else:
# out, score = random_swap2(D, C, S, out, score)
out, score = random_swap3(D, C, S, out, score)
t2 = time.time()
if t2 - t1 > 1.85:
break
ans = [str(i + 1) for i in out]
print("\n".join(ans))
main()
| 0 | null | 5,615,520,393,294 | 63 | 113 |
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math
def readInt():
return int(input())
def readInts():
return list(map(int, input().split()))
def readChar():
return input()
def readChars():
return input().split()
n,k,s = readInts()
for i in range(k):
print(s, end=" ")
for i in range(n-k):
print(min(10**9-1,s+1),end=" ")
print()
|
n, k, s = map(int, input().split())
a = [s] * n
if s == 1:
s = 2
else:
s -=1
for i in range(k, n):
a[i] = s
print(a[0], end = "")
for i in a[1:]:
print("", i, end = "")
print()
| 1 | 91,289,564,977,220 | null | 238 | 238 |
def counter(s):
cnt = 0
flag = 0
for i in range(1, len(s)):
if flag == 1:
flag = 0
else:
if s[i] == s[i-1]:
cnt += 1
flag = 1
return cnt * k
s = str(input())
k = int(input())
if len(set(s)) == 1:
ans = len(s) * k // 2
else:
if k == 1 or s[0] != s[-1]:
ans = counter(s)
else:
l = 0
r = 0
for i in range(len(s)):
if s[i] == s[0]:
l += 1
else:
break
for j in range(len(s)-1, 0, -1):
if s[j] == s[0]:
r += 1
else:
break
ans = counter(s[l:-r])
ans += l // 2 + r // 2 + (l + r) // 2 * (k - 1)
print(ans)
|
from itertools import groupby
# RUN LENGTH ENCODING str -> tuple
def run_length_encode(S: str):
"""
'AAAABBBCCDAABBB' -> [('A', 4), ('B', 3), ('C', 2), ('D', 1), ('A', 2), ('B', 3)]
"""
grouped = groupby(S)
res = []
for k, v in grouped:
res.append((k, len(list(v))))
return res
S = input()
K = int(input())
if len(set(list(S))) == 1:
print((len(S) * K) // 2)
else:
rle = run_length_encode(S)
cnt = 0
for w, length in rle:
if length > 1:
cnt += length // 2
ans = cnt * K
if S[0] == S[-1]:
a = rle[0][1]
b = rle[-1][1]
ans -= (a // 2 + b // 2 - (a + b) // 2) * (K - 1)
print(ans)
| 1 | 175,844,666,744,240 | null | 296 | 296 |
N,X,T = map(int, input().split())
nf = float(N/X)
ni = int(N/X)
d = nf - ni
if d == 0:
ans = ni * T
else:
ans = (ni + 1) * T
print(ans)
|
S = input()
T = input()
l = len(S)
count = 0
for i in range(l):
if S[i] != T[i]:
count += 1
print(count)
| 0 | null | 7,365,895,188,630 | 86 | 116 |
from copy import deepcopy
n, m, q = map(int, input().split())
tuples = [tuple(map(int, input().split())) for i in range(q)]
As = [[1]*n]
def next(A, i):
if i == 0 and A[i] == m:
return
if A[i] == m:
next(A, i-1)
elif A[i] < m:
if (i < n - 1 and A[i] < A[i+1]) or (i == n-1):
A1 = deepcopy(A)
A1[i] += 1
As.append(A1)
next(A1, i)
if i > 0 and A[i] > A[i-1]:
A2 = deepcopy(A)
next(A2, i-1)
elif i == 0:
A1 = deepcopy(A)
next(A1, n-1)
next([1]*(n), n-1)
def check(A):
score = 0
for a, b, c, d in tuples:
if A[b-1] - A[a-1] == c:
score += d
return score
ans = 0
for A in As:
score = check(A)
ans = max(ans, score)
print (ans)
|
def main():
S = input()
if S[-1] == "s":
print(S+"es")
else:
print(S+"s")
if __name__ == "__main__":
main()
| 0 | null | 15,065,573,050,362 | 160 | 71 |
n, d, a = map(int, input().split())
D = True
pos = []
pos1 = []
for i in range(n):
x, h = map(int, input().split())
pos.append((x, h))
pos.sort(key=lambda x: x[0])
bombs = 0
damage = 0
y, z = 0, 0
while y < n:
x0 = pos[y][0]
try:
x1 = pos1[z][0]
except IndexError:
x1 = 1e16
if x0 <= x1:
health = pos[y][1]
health -= damage
number = max(0, (health-1) // a + 1)
bombs += number
damage += number*a
pos1.append((x0+2*d, number*a))
y+=1
else:
damage -= pos1[z][1]
z += 1
print(bombs)
|
N=int(input())
c=str(input())
num_R = c.count("R")
num_W = 0
ans = []
if num_R >= num_W:
ans.append(num_R)
else:
ans.append(num_W)
#print(ans)
for i in range(len(c)):
if c[i] == "R":
num_R -= 1
else:
num_W += 1
if num_R >= num_W:
ans.append(num_R)
else:
ans.append(num_W)
#print(ans)
print(min(ans))
| 0 | null | 44,025,945,844,640 | 230 | 98 |
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
L = [0]*26
v = 0
ans = [0]*D
import copy
for i in range(1, D+1):
max_score = -float('inf')
max_idx = 0
for j in range(26):
temp = v
temp += S[i-1][j]
L_ = copy.copy(L)
L_[j] = i
for k in range(26):
for l in range(i, min(i+14, D+1)):
temp -= C[k]*(i-L_[k])
if temp >= max_score:
max_score = temp
max_idx = j
v = max_score
L[max_idx] = i
ans[i-1] = max_idx+1
print(*ans, sep='\n')
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from time import time
from random import randint
from copy import deepcopy
start_time = time()
def calcScore(t, s, c):
scores = [0]*26
lasts = [0]*26
for i in range(1, len(t)):
scores[t[i]] += s[i][t[i]]
dif = i - lasts[t[i]]
scores[t[i]] -= c[t[i]] * dif * (dif-1) // 2
lasts[t[i]] = i
for i in range(26):
dif = len(t) - lasts[i]
scores[i] -= c[i] * dif * (dif-1) // 2
return scores
def greedy(c, s):
day_lim = len(s)
socres = [0]*26
t = [0]*day_lim
lasts = [0]*26
for i in range(1, day_lim):
pls = [v for v in socres]
mns = [v for v in socres]
for j in range(26):
pls[j] += s[i][j]
mns[j] -= c[j] * (i - lasts[j])
sum_mns = sum(mns)
pt = sum_mns - mns[0] + pls[0]
idx = 0
for j in range(1, 26):
tmp = sum_mns - mns[j] + pls[j]
if pt < tmp:
pt = tmp
idx = j
t[i] = idx
lasts[idx] = i
for j in range(26):
if j == idx:
socres[j] = pls[j]
else:
socres[j] = mns[j]
return socres, t
def subGreedy(c, s, t, day):
day_lim = len(s)
socres = [0]*26
t = [0]*day_lim
lasts = [0]*26
for i in range(1, day_lim):
if day <= i:
pls = [v for v in socres]
mns = [v for v in socres]
for j in range(26):
pls[j] += s[i][j]
mns[j] -= c[j] * (i - lasts[j])
sum_mns = sum(mns)
pt = sum_mns - mns[0] + pls[0]
idx = 0
for j in range(1, 26):
tmp = sum_mns - mns[j] + pls[j]
if pt < tmp:
pt = tmp
idx = j
t[i] = idx
lasts[idx] = i
for j in range(26):
if j == idx:
socres[j] = pls[j]
else:
socres[j] = mns[j]
else:
scores[t[i]] += s[i][t[i]]
lasts[t[i]] = i
for j in range(26):
dif = i - lasts[j]
scores[j] -= c[j] * dif
return socres, t
D = int(input())
c = list(map(int, input().split()))
s = [[0]*26 for _ in range(D+1)]
for i in range(1, D+1):
s[i] = list(map(int, input().split()))
scores, t = greedy(c, s)
sum_score = sum(scores)
while time() - start_time < 1.86:
typ = randint(1, 90)
if typ <= 70:
for _ in range(100):
tmp_t = deepcopy(t)
tmp_t[randint(1, D)] = randint(0, 25)
tmp_scores = calcScore(tmp_t, s, c)
sum_tmp_score = sum(tmp_scores)
if sum_score < sum_tmp_score:
sum_score = sum_tmp_score
t = deepcopy(tmp_t)
scores = deepcopy(tmp_scores)
elif typ <= 90:
for _ in range(30):
tmp_t = deepcopy(t)
dist = randint(1, 20)
p = randint(1, D-dist)
q = p + dist
tmp_t[p], tmp_t[q] = tmp_t[q], tmp_t[p]
tmp_scores = calcScore(tmp_t, s, c)
sum_tmp_score = sum(tmp_scores)
if sum_score < sum_tmp_score:
sum_score = sum_tmp_score
t = deepcopy(tmp_t)
scores = deepcopy(tmp_scores)
elif typ <= 100:
tmp_t = deepcopy(t)
day = randint(D//4*3, D)
tmp_scores, tmp_t = subGreedy(c, s, tmp_t, day)
sum_tmp_score = sum(tmp_scores)
if sum_score < sum_tmp_score:
sum_score = sum_tmp_score
t = tmp_t
scores = tmp_scores
for v in t[1:]:
print(v+1)
| 1 | 9,730,958,178,460 | null | 113 | 113 |
a, b = map(int, input().split())
print("%d %d" % (int(a * b), int(a + a + b + b)))
|
l = list(map(int, input().split(" ")))
print(l[0]*l[1], (l[0]+l[1])*2)
| 1 | 305,103,806,740 | null | 36 | 36 |
S=[]
T=[]
S_num=int(input())
S=input().split()
T_num=int(input())
T=input().split()
cnt=0
for i in range(T_num):
for j in range(S_num):
if(S[j]==T[i]):
cnt+=1
break
print(cnt)
|
n = int(input())
a = list(map(int, input().split()))
L = sum(a)
l = 0
i = 0
while l < L / 2:
l += a[i]
i += 1
print(min(abs(sum(a[:i - 1]) - sum(a[i - 1:])), abs(sum(a[:i]) - sum(a[i:]))))
| 0 | null | 70,996,628,064,452 | 22 | 276 |
def insertionSort(A,n,g,cnt):
for i in range(g,n):
v = A[i]
j = i-g
while (j>=0)*(A[j]>v):
A[j+g]=A[j]
j = j-g
cnt[0] += 1
A[j+g] = v
A =[]
N = int(input())
for i in range(N):
A.append(int(input()))
cnt = [0]
import math
m = math.floor(math.log(N,2))+1
G = [math.ceil(N/2)]
for i in range(1,m-1):
G.append(math.ceil(G[i-1]/2))
G.append(N-sum(G))
if G[len(G)-1] != 1:
G[len(G)-1] = 1
for k in range(m):
insertionSort(A,N,G[k],cnt)
print(m)
for i in range(m):
print(f"{G[i]}",end=" ")
print(f"\n{cnt[0]}")
for i in range(N):
print(f"{A[i]}")
|
def insert(A,n,g):
global cnt
for i in range(g,n):
v = a[i]
j = i-g
while(j>=0 and A[j]>v):
A[j+g] = A[j]
j = j-g
cnt+= 1
A[j+g] = v
def shell(A,n):
global cnt
cnt = 0
G = []
h = 1
while h <= n:
G.append(h)
h = 3*h+1
G.reverse()
m = len(G)
print(m)
print(" ".join(map(str,G)))
for i in G:
insert(A,n,i)
return cnt
n = int(input())
a = []
for i in range(n):
ai = int(input())
a.append(ai)
shell(a,n)
print(cnt)
for i in range(n):
print(a[i])
| 1 | 30,920,309,710 | null | 17 | 17 |
def Qb():
k = int(input())
s = input()
if len(s) <= k:
print(s)
else:
print(f'{s[:k]}...')
if __name__ == '__main__':
Qb()
|
input()
s = input()
count = 1
for i in range(len(s)-1):
if s[i]!=s[i+1]:
count+=1
print(count)
| 0 | null | 94,929,676,142,070 | 143 | 293 |
k, x = map(int, input().split())
if x <= k * 500: print('Yes')
else: print('No')
|
K, X = map(int, input().split())
print("Yes") if 500 * K >= X else print("No")
| 1 | 98,088,262,163,992 | null | 244 | 244 |
def main():
N = int(input()) # 文字列または整数(一変数)
print(N**2)
if __name__ == '__main__':
main()
|
r_input = input().split()
r = int(r_input[0])
print(r*r)
| 1 | 145,362,813,100,090 | null | 278 | 278 |
from itertools import permutations
from math import sqrt, pow, factorial
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
def calc(a,b):
[x1, y1] = a
[x2, y2] = b
return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))
sum = 0
for i in permutations(range(n)):
distance = 0
for j in range(1, n):
distance = calc(xy[i[j]], xy[i[j-1]])
sum += distance
print(sum/factorial(n))
|
import sys
for line in sys.stdin:
xy = sorted(map(int , line.split()))
if xy[0] == 0 and xy[1] == 0: break
print(*xy)
| 0 | null | 74,802,846,011,922 | 280 | 43 |
import math
A, B = map(int, input().split())
AA = A * 100 / 8
BB = B * 100 / 10
L = []
for i in range(10000):
if math.floor(i * 0.08) == A and math.floor(i * 0.1) == B:
L.append(i)
L = sorted(L)
if L == []:
print(-1)
exit()
print(L[0])
|
n = int(input())
ans = 0
for a in range(1,n):
if n%a == 0:
ans += n//a -1
else:
ans += n//a
print(ans)
| 0 | null | 29,455,379,808,672 | 203 | 73 |
from sys import stdin
freq = {}
for line in stdin:
string = line.lower()
for i in string:
if i.isalpha():
freq[i] = freq.get(i, 0) + 1
for char in range(ord('a'), ord('z')+1):
char = chr(char)
print('%s : %d' % (char, freq.get(char, 0)))
|
import sys
alphabet = ['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']
cnt = 26 * [0]
Input = ""
loop = True
#while loop:
# I = input()
# if not I:
# loop = False
# Input += I
for I in sys.stdin:
Input += I
for i1 in range(len(alphabet)):
for i2 in range(len(Input)):
if 'A' <= Input[i2] <= 'Z':
w = Input[i2].lower()
else:
w = Input[i2]
if alphabet[i1] == w:
cnt[i1] += 1
print(alphabet[i1] + " : " + str(cnt[i1]))
| 1 | 1,667,013,438,270 | null | 63 | 63 |
S = str(input())
for i in range(int(input())):
L = input().split()
o = L[0]
a = int(L[1])
b = int(L[2]) + 1
if len(L) == 4:
p = L[3]
else:
p = 0
if o == "print":
print(S[a:b])
elif o == "reverse":
S = S[:a]+S[a:b][::-1]+S[b:]
elif o == "replace":
S = S[:a]+p+S[b:]
|
def rev(val, v1, v2):
for i in range((v2-v1)//2 +1):
val[v1+i], val[v2-i] = val[v2-i], val[v1+i]
return val
def rep(val1, val2, v1, v2):
for i in range(v2-v1):
val1[v1+i] = val2[i]
return val1
st = input()
lst = [i for i in st]
q = int(input())
for i in range(q):
f = list(map(str, input().split()))
if f[0] == 'print':
s = ''.join(lst[int(f[1]):int(f[2])+1])
print(s)
elif f[0] == 'reverse':
lst = rev(lst, int(f[1]), int(f[2]))
elif f[0] == 'replace':
x = [i for i in f[3]]
lst = rep(lst, x, int(f[1]), int(f[2])+1)
| 1 | 2,094,158,270,110 | null | 68 | 68 |
def solve():
n, r = map(int, input().split())
return r + max(0, 100 * (10-n))
print(solve())
|
import numpy as np
import itertools
def check():
N,M,X = map(int, input().split())
A = np.array([[int(i) for i in input().split()] for _ in range(N)])
total = np.sum(A,axis=0)
flag = True if all((a>=X for a in total[1:])) else False
ans = total[0]
if flag:
for i in range(1,N+1):
for v in itertools.combinations([i for i in range(N)], i):
B = np.array([A[j] for j in v])
total2 = np.sum(B, axis=0)
sabun = total-total2
if all(a>=X for a in sabun[1:]):
ans = min(ans, sabun[0])
print(ans if flag else -1)
check()
| 0 | null | 42,880,946,580,834 | 211 | 149 |
x=int(input())
if x<100:
print(0)
exit()
if x>=2000:
print(1)
exit()
else:
t=x//100
a=x%100
if 0<=a<=t*5:
print(1)
else:
print(0)
|
from collections import deque
h, w = map(int, input().split())
s = []
for i in range(h):
s.append(list(input()))
def bfs(x, y):
if s[y][x] == '#':
return 0
queue = deque()
queue.appendleft([x, y])
visited = dict()
visited[(x, y)] = 0
while queue:
nx, ny = queue.pop()
cur = visited[(nx, ny)]
if nx - 1 >= 0 and (nx - 1, ny) not in visited:
if s[ny][nx - 1] == '.':
visited[(nx - 1, ny)] = cur + 1
queue.appendleft((nx - 1, ny))
if nx + 1 < w and (nx + 1, ny) not in visited:
if s[ny][nx + 1] == '.':
visited[(nx + 1, ny)] = cur + 1
queue.appendleft((nx + 1, ny))
if ny - 1 >= 0 and (nx, ny - 1) not in visited:
if s[ny - 1][nx] == '.':
visited[(nx, ny - 1)] = cur + 1
queue.appendleft((nx, ny - 1))
if ny + 1 < h and (nx, ny + 1) not in visited:
if s[ny + 1][nx] == '.':
visited[(nx, ny + 1)] = cur + 1
queue.appendleft((nx, ny + 1))
return max(visited.values())
result = 0
for i in range(h):
for j in range(w):
r = bfs(j, i)
result = max(result, r)
print(result)
| 0 | null | 111,149,595,575,272 | 266 | 241 |
N = int(input())
if N == 1:
print(0)
exit()
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
def p_num(m):
ret = 0
for j in range(1,10**12):
ret += j
if ret <= m < ret+(j+1):
ans = j
break
return ans
p = factorization(N)
cnt = 0
for k in range(len(p)):
cnt += p_num(p[k][1])
print(cnt)
|
# B - 81
# https://atcoder.jp/contests/abc144/tasks/abc144_b
n = int(input())
result = 'No'
for i in range(1, 10):
for j in range(1, 10):
if i * j == n:
result = 'Yes'
break
if result == 'Yes':
break
print(result)
| 0 | null | 88,102,184,148,450 | 136 | 287 |
W = input().rstrip().lower()
ans = 0
while True:
line = input().rstrip()
if line == 'END_OF_TEXT': break
line = line.lower().split(' ')
for word in line:
if word == W: ans += 1
print(ans)
|
# -*- coding: utf-8 -*-
n = input()
l = map(int, raw_input().split())
for i in range(n-1):
print l[n-i-1],
print l[0]
| 0 | null | 1,409,232,818,322 | 65 | 53 |
N,A,B=map(int,input().split())
D,M=divmod(N,A+B)
print((D*A)+min(M,A))
|
n=int(input())
lst={}
for i in range(n):
lst[input()]=1
print(len(lst))
| 0 | null | 42,939,770,458,160 | 202 | 165 |
import numpy as np
from numba import njit
@njit("i8[:](i8, i8[:], i8[:])", cache=True)
def cumsum(K, A, cA):
for i, a in enumerate(A):
cA[i] += cA[i - 1] + A[i]
if cA[i] > K:
break
cA = cA[cA != 0]
cA = np.append(0, cA)
return cA
@njit("i8(i8, i8[:], i8[:])", cache=True)
def solve(K, cA, cB):
ans = np.searchsorted(cA, K - cB, side="right") - 1
ans += np.arange(len(cB))
return ans.max()
N, M, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)
cA = np.zeros(N, dtype=np.int64)
cB = np.zeros(M, dtype=np.int64)
# np.cumsumだとoverflowする
cA = cumsum(K, A, cA)
cB = cumsum(K, B, cB)
ans = solve(K, cA, cB)
print(ans)
|
IDX_TABLE=\
{1:[4,2,3,5],
2:[1,4,6,3],
3:[1,2,6,5],
4:[1,5,6,2],
5:[4,1,3,6],
6:[3,2,4,5]}
nums = ["dummy"] + [int(x) for x in raw_input().split(" ")]
n = int(raw_input())
for i in range(n):
up, front = tuple([int(x) for x in raw_input().split(" ")])
up_idx = nums.index(up)
front_idx = nums.index(front)
ring_list = IDX_TABLE[up_idx]
ring_idx = ring_list.index(front_idx)
print nums[ring_list[(ring_idx+1) % 4]]
| 0 | null | 5,532,252,551,398 | 117 | 34 |
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0]*(N+1), [0]*(M+1)
for i in range(N):
a[i+1] = a[i] + A[i]
for i in range(M):
b[i+1] = b[i] + B[i]
ans, j = 0, M
for i in range(N + 1):
if a[i] > K:
break
while b[j] > K - a[i]:
j -= 1
ans = max(ans, i + j)
print(ans)
|
S = ["ABC","ARC"]
print(S[S.index(input())-1])
| 0 | null | 17,484,213,770,396 | 117 | 153 |
n = int(input())
s = list(input())
p = s[0]
ans = 1
for i in s[1:]:
if p!=i:
p = i
ans += 1
print(ans)
|
n = int(input())
s = str(input())
new_s = s[0]
for i in range(1,len(s)):
if s[i] == s[i-1]:
continue
else:
new_s += s[i]
print(len(new_s))
| 1 | 169,753,580,914,158 | null | 293 | 293 |
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
B = reduce(lambda x, y: x^y, A)
ans = []
for a in A:
ans.append(B^a)
print(*ans)
|
#abc167_e
n = int(input())
pos = []
neg = []
for _ in range(n):
s = input()
low_pos = 0
increase= 0
for v in s:
if v=="(":
increase += 1
else:
increase -= 1
low_pos = min(low_pos, increase)
if increase >= 0:
pos.append((low_pos, increase))
else:
#reverse left from right
low_pos, increase = low_pos - increase, -increase
neg.append((low_pos, increase))
pos.sort()
pos.reverse() #lowが高い順にする.
neg.sort()
neg.reverse() #lowが高い順にする.
now_pos = 0
for low_pos, increase in pos:
if now_pos + low_pos < 0:
print("No") #impossible
exit()
else:
now_pos += increase
right_pos = 0
for low_pos, increase in neg:
if right_pos + low_pos < 0:
print("No") #impossible
exit()
else:
right_pos += increase
if right_pos != now_pos:
print("No")
exit()
else:
print("Yes")
| 0 | null | 17,947,254,200,940 | 123 | 152 |
from math import sqrt
import itertools
N = int(input())
dis = [input().split() for i in range(N)]
lst = [x for x in range(N)]
p_lst = list(itertools.permutations(lst))
ans = 0
for i in p_lst:
for j in range(N-1):
ans += sqrt((int(dis[i[j]][0]) - int(dis[i[j+1]][0]))**2
+ (int(dis[i[j]][1]) - int(dis[i[j+1]][1]))**2)
print(ans/len(p_lst))
|
import itertools
N = int(input())
c = []
d = 0
for i in range(N):
x1, y1 = map(int, input().split())
c.append((x1,y1))
cp = list(itertools.permutations(c))
x = len(cp)
for i in range(x):
for j in range(N-1):
d += ((cp[i][j][0]-cp[i][j+1][0])**2 + (cp[i][j][1] - cp[i][j+1][1])**2)**0.5
print(d/x)
| 1 | 148,526,034,839,268 | null | 280 | 280 |
def prod(int_list):
p = 1
for i in int_list:
p *= i
return p
int_ary = [int(s) for s in input().split(" ")]
print(prod(int_ary), 2 * sum(int_ary))
|
N, M = map(int, input().split())
H = list(map(int, input().split()))
OK = [True] * N
for _ in range(M):
A, B = map(lambda x: int(x)-1, input().split())
if H[A] < H[B]:
OK[A] = False
elif H[A] > H[B]:
OK[B] = False
else:
OK[A] = False
OK[B] = False
ans = sum(OK)
print(ans)
| 0 | null | 12,767,703,207,520 | 36 | 155 |
S = input()
N = len(S)
one = S[:int((N-1) / 2)]
two = S[int((N+3) / 2)-1:]
if S == S[::-1]:
if one == one[::-1]:
if two == two[::-1]:
print('Yes')
exit()
print('No')
|
def m():
MOD = 998244353
N = int(input())
D = [0] + list(map(int, input().split()))
if D[1] != 0:
return 0
tree = {1:1}
for i in range(2, N + 1):
if D[i] == 0: return 0
tree[D[i] + 1] = tree[D[i] + 1] + 1 if tree.get(D[i] + 1, False) else 1
height = len(tree.keys())+1
cnt = 1
for i in range(2, height):
if not tree.get(i, 0):
return 0
cnt = cnt * pow(tree[i-1], tree[i]) % MOD
return cnt
print(m())
| 0 | null | 100,041,172,577,082 | 190 | 284 |
x, y = map(int, input().split())
prise = {3: 100000, 2: 200000, 1: 300000}
ans = 0
if x in (1, 2, 3):
ans += prise[x]
if y in (1, 2, 3):
ans += prise[y]
print(ans + 400000 if x == y == 1 else ans)
|
def main():
X, Y = map(int, input().split())
ans = 0;
if X == 1:
ans += 300000
elif X == 2:
ans += 200000
elif X == 3:
ans += 100000
if Y == 1:
ans += 300000
elif Y == 2:
ans += 200000
elif Y == 3:
ans += 100000
if X == 1 and Y == 1:
ans += 400000
print(ans)
if __name__ == '__main__':
main()
| 1 | 140,287,151,127,210 | null | 275 | 275 |
import sys
import bisect
import itertools
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n, m = list(map(int, readline().split()))
a = list(map(int, readline().split()))
a.sort()
cor_v = -1
inc_v = a[-1] * 2 + 1
while - cor_v + inc_v > 1:
bin_v = (cor_v + inc_v) // 2
cost = 0
#条件を満たすcostを全検索
p = n
for v in a:
p = bisect.bisect_left(a, bin_v - v, 0, p)
cost += n - p
if cost > m:
break
#costが制約を満たすか
if cost >= m:
cor_v = bin_v
else:
inc_v = bin_v
acm = [0] + list(itertools.accumulate(a))
c = 0
t = 0
for v in a:
p = bisect.bisect_left(a, cor_v - v)
c += n - p
t += acm[-1] - acm[p] + v * (n - p)
print(t - (c - m) * cor_v)
if __name__ == '__main__':
solve()
|
import math
N = int(input())
ans = math.floor(N / 2)
if N % 2 == 0:
print(ans - 1)
else:
print(ans)
| 0 | null | 131,141,612,914,102 | 252 | 283 |
S = input()
INC = '<'
DEC = '>'
icnt = 0
dcnt = 0
mode = DEC
ans = 0
for c in S:
if mode == DEC:
if c == DEC:
dcnt += 1
elif c == INC:
if icnt <= dcnt:
ans += (dcnt + 1) * dcnt // 2
else:
ans += icnt + dcnt * (dcnt - 1) // 2
icnt = 1
mode = INC
elif mode == INC:
if c == INC:
icnt += 1
elif c == DEC:
ans += icnt * (icnt - 1) // 2
dcnt = 1
mode = DEC
if mode == INC:
ans += (icnt + 1) * icnt // 2
elif mode == DEC:
if icnt <= dcnt:
ans += (dcnt + 1) * dcnt // 2
else:
ans += icnt + dcnt * (dcnt - 1) // 2
print(ans)
|
n,m = map(int, input().split())
c=0
if n>1 :
c+=n*(n-1) //2
if m>1 :
c+=m*(m-1) //2
print(c)
| 0 | null | 100,591,007,047,298 | 285 | 189 |
count = {}
for i in range(26):
count[(i)] = 0
while True:
try:
x = raw_input()
except:
break
for i in range(len(x)):
if(ord('a') <= ord(x[i]) and ord(x[i]) <= ord('z')):
count[(ord(x[i])-ord('a'))] += 1
elif(ord('A') <= ord(x[i]) and ord(x[i]) <= ord('Z')):
count[(ord(x[i])-ord('A'))] += 1
for i in range(26):
print '%s : %d' %(chr(i+ord('a')), count[(i)])
exit(0)
|
a, b = map(int, input().split())
mat = [map(int, input().split()) for i in range(a)]
vec = [int(input()) for i in range(b)]
for row in mat:
print(sum([x*y for x, y in zip(row, vec)]))
| 0 | null | 1,429,926,173,412 | 63 | 56 |
W,H,x,y,r=map(int,raw_input().split())
if r<=x<=W-r:
if r<=y<=H-r:
print "Yes"
else:
print "No"
else:
print "No"
|
W,H,x,y,r = map(int ,raw_input().split())
#print ' '.join(map(str,[W,H,x,y,r]))
if x < W and 0 < x and 0<y and y < H and r <= x and r <= (H - x) :
print "Yes"
else:
print "No"
| 1 | 453,984,887,200 | null | 41 | 41 |
a=int(input())
b=int(input())
c=[1,2,3]
c.remove(a)
c.remove(b)
if c==[1]:
print(1)
elif c==[2]:
print(2)
else:
print(3)
|
#!/usr/bin/env python3
print(6-eval(input()+"+"+input()))
| 1 | 110,834,927,601,258 | null | 254 | 254 |
import math
a, b , n = map(int, input().split())
ans1 = (a*(b-1))//b
ans2 = (a*n)//b
print(min(ans1, ans2))
|
a, b, n = map(int, input().split())
x = b-1 if n >= b else n
print(a*x//b)
| 1 | 28,238,048,613,000 | null | 161 | 161 |
#!/usr/bin/env python
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if v <= w:
print('NO')
exit()
if abs(b-a)/(v-w) > t:
print('NO')
exit()
print('YES')
|
from collections import deque
N,M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
G = {i:[] for i in range(N+1)}
for a,b in AB:
G[a].append(b)
G[b].append(a)
parent = [0]*(N+1)
parent[0]==-1
parent[1]==-1
q = deque()
q.append(1)
while len(q)>0:
room = q.popleft()
child = G[room]
for i in child:
if parent[i] == 0:
parent[i] = room
q.append(i)
if min(parent[2:])==0:
print('No')
else:
print('Yes')
for i in parent[2:]:
print(i)
| 0 | null | 17,663,027,995,678 | 131 | 145 |
x, y = map(int, input().split())
def shokin(z):
if z == 1:
return 300000
elif z == 2:
return 200000
elif z == 3:
return 100000
else:
return 0
v = 0
if x == 1 and y == 1:
v = 400000
print(shokin(x)+shokin(y)+v)
|
#https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_a
XY=input().split()
X=int(XY[0])
Y=int(XY[1])
award=0
if X==1 and Y==1:
award+=400000
for num in [X,Y]:
if num==3:
award+=100000
if num==2:
award+=200000
if num==1:
award+=300000
print(award)
| 1 | 141,048,797,382,568 | null | 275 | 275 |
n=int(input())
taro=0
hanako=0
for i in range(n):
t,h=map(str,input().split())
if t>h:
taro += 3
elif h>t:
hanako += 3
else:
taro += 1
hanako += 1
print(taro,hanako)
|
n = int(input())
t = 0
h = 0
for i in range(n):
tc, hc = input().split()
if tc > hc:
t += 3
elif tc < hc:
h += 3
elif tc == hc:
t += 1
h += 1
print(str(t)+' '+str(h))
| 1 | 1,989,519,117,960 | null | 67 | 67 |
N,S = map(int,input().split())
A = list(map(int,input().split()))
MOD = 998244353
dp = [0 for _ in range(S+1)]
#i個目までの和がjの数となるのは何通りあるかdp[i][j]
dp[0] = 1
#dp = [0 if i==0 else INF for i in range(S + 1)]
for i in range(N): #i個目まで見て。
p = [0 for _ in range(S+1)]
p,dp = dp,p
for j in range(S+1):
dp[j] = (dp[j]+p[j]*2)%MOD
if j >= A[i]:
#print(j,A[i],p[j-A[i]])
dp[j] += p[j-A[i]]
#print(dp)
ans = dp[S]%MOD
print(ans)
|
s=list(input())
s.reverse()
mod=2019
n=[0]*len(s)
n[0]=1
cnt=[0]*len(s)
cnt[0]=int(s[0])
ans=[0]*2019
answer=0
for i in range(1,len(s)):
n[i]+=(n[i-1]*10)%mod
for i in range(1,len(s)):
cnt[i]=(cnt[i-1]+int(s[i])*n[i])%mod
for i in cnt:
ans[i]+=1
for i in range(len(ans)):
answer+=(ans[i]*(ans[i]-1))//2
answer+=ans[0]
print(answer)
| 0 | null | 24,430,272,957,012 | 138 | 166 |
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
ans = "NO"
if abs(a-b) <= t * (v - w):
ans = "YES"
print(ans)
|
a,v = map(int, input().split())
b,w = map(int, input().split())
T = int(input())
if abs(b-a) <= (v-w)*T:
print('YES')
else:
print('NO')
| 1 | 15,047,655,991,940 | null | 131 | 131 |
while 1 :
a,op,b = raw_input().split()
if op == "?":
break
if op == "+":
print int(a) + int(b)
if op == "-":
print int(a) - int(b)
if op == "*":
print int(a) * int(b)
if op == "/":
print int(a) / int(b)
|
#coding:utf-8
def cal(a, b, op):
if op=="+":
return a + b
elif op == "-":
return a - b
elif op == "*":
return a * b
elif op == "/":
return a//b
else:
return -1
while True:
buff = input().split()
a = int(buff[0])
b = int(buff[2])
op = buff[1]
if op == "?":
break
print(cal(a, b, op))
| 1 | 690,015,819,298 | null | 47 | 47 |
N=int(input())
A=list(map(int,input().split()))
SUM=sum(A)
Q=int(input())
List=[0 for _ in range(10**5+1)]
for a in A:
List[a]+=1
for q in range(Q):
B,C=map(int,input().split())
SUM-=B*List[B]
SUM+=C*List[B]
List[C]+=List[B]
List[B]=0
print(SUM)
|
def main():
N = int(input())
A = [int(a) for a in input().split(" ")]
S = sum(A)
cA = [0] * 1000001
for i in range(len(A)):
cA[A[i]] += 1
Q = int(input())
for i in range(Q):
B, C = [int(x) for x in input().split(" ")]
diff = (C-B)*cA[B]
S += diff
cA[C] += cA[B]
cA[B] = 0
print(S)
main()
| 1 | 12,211,049,321,212 | null | 122 | 122 |
from functools import reduce
n, *s = open(0).read().split()
u = []
for t in s:
close_cnt = 0
tmp = 0
for c in t:
tmp += (1 if c == '(' else -1)
close_cnt = min(close_cnt, tmp)
u.append((close_cnt, tmp - close_cnt))
M = 10**6 + 1
acc = 0
for a, b in sorted(u, key=lambda z: (- M - z[0] if sum(z)>= 0 else M - z[1])):
if acc + a < 0:
print("No")
exit(0)
else:
acc += a + b
print(("No" if acc else "Yes"))
|
mod = 998244353
N,M,K = map(int,input().split())
ans = 0
def pow(x,n):
if n == 0:
return 1
if n % 2 == 0:
return pow((x ** 2)%mod, n // 2)%mod
else:
return x * pow((x ** 2)%mod, (n - 1) // 2)%mod
A = 1
for i in range(K+1):
p = N - i
x = M*pow(M-1,p-1)*A % mod
ans += x
A = A*(N-i-1)%mod
y = pow(i+1,mod-2)
A = A*y % mod
print(ans%mod)
| 0 | null | 23,367,685,783,070 | 152 | 151 |
a, b = map(int, input().split())
c = list(map(int, input().split()[:b]))
d = sum(c)
if d >= a:
print("Yes")
else:
print("No")
|
h, n = map(int, input().split())
print('No' if sum(list(map(int, input().split())))<h else 'Yes')
| 1 | 78,261,808,408,700 | null | 226 | 226 |
N = int(input())
a = []
for i in range(N):
a.append(int(input()))
mins = [a[0]]
for i in range(1, N):
mins.append(min(a[i], mins[i-1]))
mx = -10**12
for j in range(1, N):
mx = max(mx, a[j] - mins[j-1])
print(mx)
|
n = int(input())
i, j = int(input()), 0
nmin = i
a = -2 * 10 ** 9
for h in range(n - 1):
j = int(input())
a = max(a, j - nmin)
if j < nmin:
nmin = j
print(a)
| 1 | 13,099,503,398 | null | 13 | 13 |
import math
print(2**(int(math.log2(int(input())))+1)-1)
|
H = int(input())
cnt = 0
while(H>1):
H //= 2
cnt += 1
if H == 1:
print(2**(cnt+1)-1)
else:
print(2**cnt-1)
| 1 | 80,094,803,609,572 | null | 228 | 228 |
c = input()
ord_s = ord(c)
chr_s = chr(ord_s+1)
print(chr_s)
|
# https://atcoder.jp/contests/abc149/tasks/abc149_e
# すべての握手の組み合わせN**2を列挙しソートしM番目までを足し合わせればOK
# だけど制約からこれを行うことは困難
# すべてを列挙しなくともM番目の値を知ることは二分探索で可能(参考:億マス計算)
# Aの累積和を保持しておけば、M番目の値の探索中にMまでの値の合計もついでに計算できる
# 以下reverseでソート済みだと仮定
# XがM番目の数→X以上である数はM個以上(cntとする)→cntがM個以上の条件を満たすうちの最大となるXがM番目の値
# そのあと余分な分を引く処理とか必要
from bisect import bisect_right, bisect_left
import sys
read = sys.stdin.readline
def read_ints():
return list(map(int, read().split()))
class cumsum1d:
def __init__(self, ls: list):
'''
1次元リストを受け取る
'''
from itertools import accumulate
self.ls_accum = [0] + list(accumulate(ls))
def total(self, i, j):
# もとの配列lsにおける[i,j)の中合計
return self.ls_accum[j] - self.ls_accum[i]
N, M = read_ints()
A = read_ints()
A.sort() # bisectを使う都合上 reverseは抜き
A_reversed = list(reversed(A))
A_rev_acc = cumsum1d(A_reversed)
def is_ok(X):
# M番目の数はXである→X以上の個数>=M となるうちで最大のX(もっとも左の方のX)
# X以上の個数>=Mを返す
# X以下の個数はai+aj>=Xを満たす個数
cnt = 0
ans = 0
for a in A:
aa = X - a
idx_reverse = N - bisect_left(A, aa) # 大きい方からだと何番目か
# これはbisect_right(A_reversed,aa)に等しい
cnt += idx_reverse
ans += A_rev_acc.total(0, idx_reverse) + idx_reverse * a
return cnt >= M, ans, cnt
def meguru_bisect(ng, ok):
'''
define is_okと
初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
ng ok は とり得る最小の値-1 とり得る最大の値+1
最大最小が逆の場合はよしなにひっくり返す
'''
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
flg, ans, cnt = is_ok(mid)
if flg:
ok = mid
ans_true = ans # さいごにokとなる状態がans
cnt_true = cnt
else:
ng = mid
return ans_true, ok, cnt_true
ans_tmp, M_th_num, M_plus_alpha_th = \
meguru_bisect(2 * 10 ** 5 + 1, 0)
# print(ans_tmp, M_th_num, M_plus_alpha_th)
print(ans_tmp - (M_plus_alpha_th - M) * M_th_num)
| 0 | null | 100,392,101,156,850 | 239 | 252 |
n,m,l=map(int,raw_input().split())
matA=[map(int,raw_input().split()) for i in range(n)]
matB=[map(int,raw_input().split()) for j in range(m)]
for i in range(n):
for j in range(l):
print sum([matA[i][k]*matB[k][j] for k in range(m)]),
print
|
x = int(input())
nums = [True]*(10**6)
n = int(10**6**0.5)
for i in range(4, 10**6, 2): nums[i] = False
for i in range(3, n, 2):
if nums[i]:
for j in range(i+i, 10**6, i): nums[j] = False
while True:
if nums[x]:
print(x)
break
x += 1
| 0 | null | 53,182,591,831,710 | 60 | 250 |
import sys
from fractions import gcd
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
def lcm(x, y):
return x * y // gcd(x, y)
def main():
N, M, *A = map(int, read().split())
B = A[::]
while not any(b % 2 for b in B):
B = [b // 2 for b in B]
if not all(b % 2 for b in B):
print(0)
return
semi_lcm = 1
for a in A:
semi_lcm = lcm(semi_lcm, a // 2)
print((M // semi_lcm + 1) // 2)
return
if __name__ == '__main__':
main()
|
n, k = map(int, input().split())
A = list(map(lambda x: int(x) - 1, input().split()))
prev = 0
count = 0
used = {prev: count}
for _ in range(min(k, n)):
prev = A[prev]
count += 1
if prev in used:
for _ in range((k - used[prev]) % (count - used[prev])):
prev = A[prev]
break
used[prev] = count
print(prev + 1)
| 0 | null | 62,037,476,314,128 | 247 | 150 |
s = input()
q = int(input())
head = []
tail = []
flip = 0
for i in range(q):
query = input().split()
if query[0] == "1":
flip ^=1
else:
f = int(query[1]) - 1
c = query[2]
if (f ^ flip) == 0:
head.append(c)
else:
tail.append(c)
if flip:
head, tail = tail, head
s = s[::-1]
head = "".join(head)
tail = "".join(tail)
print(head[::-1] + s + tail)
|
#!/usr/bin/env python
# coding: utf-8
# In[14]:
from collections import deque
# In[21]:
S = deque(input())
Q = int(input())
rev_cnt = 0
for _ in range(Q):
q = input().split()
if len(q) == 1:
rev_cnt += 1
else:
if (rev_cnt+int(q[1]))%2 == 0:
S.append(q[2])
else:
S.appendleft(q[2])
if rev_cnt%2 == 0:
print("".join(S))
else:
print("".join(list(reversed(S))))
# In[ ]:
| 1 | 56,915,656,515,718 | null | 204 | 204 |
[n, k] = map(int, input().split(' '))
wi = list(map(int, [input() for i in range(n)]))
def isAllocatable(p):
kw, ki = 0, 1
for w in wi:
if w > p: return False
kw += w
if kw <= p: continue
ki += 1
if k < ki: return False
kw = w
return True
l = 0
r = sum(wi)
while l + 1 < r:
p = int((l + r) / 2)
if isAllocatable(p): r = p
else: l = p
print(r)
|
p_max = 100000 * 10000
nk = list(map(int, input().split()))
w = [int(input()) for i in range(nk[0])]
def search(pt):
m = 0
for j in range(nk[1]):
weight = 0
while weight + w[m] <= pt:
weight += w[m]
m += 1
if m == nk[0]:
return nk[0]
return m
def main():
st_p = p = 0
en_p = p_max
while en_p - st_p > 1:
p = int((en_p + st_p) / 2)
chk = search(p)
if chk >= nk[0]:
en_p = p
else:
st_p = p
return en_p
if __name__ == '__main__':
print(main())
| 1 | 89,033,339,056 | null | 24 | 24 |
from collections import deque
k = int(input())
ans=[]
# q = deque([[1],[2],[3],[4],[5],[6],[7],[8],[9]])
q = deque([1,2,3,4,5,6,7,8,9])
while q:
a = q.popleft()
ans.append(a)
if len(ans) > k:
break
tmp = int(str(a)[-1])
if tmp-1 >= 0:
q.append(10*a + tmp-1)
q.append(10*a + tmp)
if tmp+1 <= 9:
q.append(10*a + tmp+1)
print(ans[k-1])
|
from itertools import permutations
from bisect import bisect_left
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
perm = list(permutations(p))
perm.sort()
a = bisect_left(perm, p)
b = bisect_left(perm, q)
print(abs(a- b))
| 0 | null | 70,371,534,993,212 | 181 | 246 |
A, B = [s for s in input().split()]
A = int(A)
B = int(float(B) * 100 + .5)
C = A * B
ans = int(C // 100)
print(ans)
|
S, T = [input() for _ in range(2)]
count = 0
for i, j in zip(S, T):
count += i != j
print(count)
| 0 | null | 13,505,935,570,036 | 135 | 116 |
a = input()
if a == "RSR":
print(1)
else :
print(a.count("R"))
|
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
import itertools
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
s = S()
cnt = 0
max = 0
for i in s:
if i == "R":
cnt += 1
else:
if max < cnt:
max = cnt
cnt = 0
if max < cnt:
max = cnt
print(max)
| 1 | 4,812,750,123,928 | null | 90 | 90 |
N = int(input())
d_ls=[]
for vakawkawelkn in range(N):
D1,D2=map(int, input().split())
if D1==D2:
d_ls+=[1]
else:
d_ls+=[0]
flag=0
for i in range(N-2):
if d_ls[i]*d_ls[i+1]*d_ls[i+2]==1:
flag=1
if flag==0:
print("No")
else:
print("Yes")
# 2darray [[0] * 4 for i in range(3)]
# import itertools
|
s = input()
if s[-1] == "s":
s += "e"
print(s + "s")
| 0 | null | 2,435,130,680,990 | 72 | 71 |
# -*- coding: utf-8 -*-
S1 = 1
r = input()
R = int(r)
S2 = R ** 2
result = S2 / S1
print(int(result))
|
def main():
r = int(input())
print(r * r)
if __name__ == '__main__':
main()
| 1 | 144,778,569,847,466 | null | 278 | 278 |
a,b,n = map(int,input().split())
if n < b:
print(a*n//b)
else:
print(a*(b-1)//b)
|
import math
a,b,n = list(map(int,input().split()))
if b <= n:
x = b - 1
else:
x = n
ans = math.floor(a * x / b)
print(ans)
| 1 | 28,094,480,987,518 | null | 161 | 161 |
import math
n, d = map(int, input().split(" "))
ans = 0
for i in range(n):
x, y = map(int, input().split(" "))
double = x ** 2 + y ** 2
root = math.sqrt(double)
if root <= d:
ans += 1
print(ans)
|
import sys
import numpy as np
import numba
from numba import jit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@jit
def main(n, a):
ans = np.zeros(n)
for i, j in enumerate(a):
ans[j-1] = i+1
for i in ans:
print(int(i), end=' ')
n = int(readline())
a = np.array(readline().split(), np.int64)
main(n,a)
| 0 | null | 93,606,282,507,010 | 96 | 299 |
board, dp = [], []
bingo = False
for _ in range(3):
board.append(list(map(int, input().split())))
dp.append([0, 0, 0])
N = int(input())
for _ in range(N):
num = int(input())
for r in range(3):
for c in range(3):
if num == board[r][c]:
dp[r][c] = 1
for i in range(3):
if dp[i][0] == dp[i][1] == dp[i][2] == 1 or dp[0][i] == dp[1][i] == dp[2][i] == 1:
bingo = True
print("Yes")
break
if not bingo:
if dp[0][0] == dp[1][1] == dp[2][2] == 1 or dp[0][2] == dp[1][1] == dp[2][0] == 1:
print("Yes")
else:
print("No")
|
A1=input()
A2=input()
A3=input()
#N=int(N)
list1 = A1.split()
list1 = [int(i) for i in list1]
list2 = A2.split()
list2 = [int(i) for i in list2]
list3 = A3.split()
list3 = [int(i) for i in list3]
N = input()
N=int(N)
num=[]
for i in range(N):
num.append(int(input()))
T1 = all([(i in num ) for i in list1])
T2 = all([(i in num ) for i in list2])
T3 = all([(i in num ) for i in list3])
T4 = all([(list1[0] in num),(list2[0] in num),(list3[0] in num)])
T5 = all([(list1[1] in num),(list2[1] in num),(list3[1] in num)])
T6 = all([(list1[2] in num),(list2[2] in num),(list3[2] in num)])
T7 = all([(list1[0] in num),(list2[1] in num),(list3[2] in num)])
T8 = all([(list1[2] in num),(list2[1] in num),(list3[0] in num)])
if (any([T1,T2,T3,T4,T5,T6,T7,T8])) == True:
print("Yes")
else:
print("No")
| 1 | 60,114,048,669,768 | null | 207 | 207 |
N,K=map(int,input().split())
H=list(map(int,input().split()))
H.sort()
m=0
if K<N:
for i in range(N-K):
m+=H[i]
print(m)
|
# -*- Coding: utf-8 -*-
nums = int(input())
a = [int(input()) for i in range(nums)]
minv = a[0]
maxv = -2000000000
for i in range(1, nums):
maxv = max(maxv, a[i] - minv)
minv = min(minv, a[i])
print(maxv)
| 0 | null | 39,467,647,382,240 | 227 | 13 |
a = input()
b = a.split(' ')
c = int(b[0])
d = int(b[1])
e = str(c*d)
f = str(c*2 + d*2)
print(e+' '+f)
|
import sys
def main():
a, b = sys.stdin.readline().split(" ")
a, b = int(a), int(b)
print("{0} {1}".format(a*b, a*2 + b*2))
return
if __name__ == '__main__':
main()
| 1 | 309,049,715,228 | null | 36 | 36 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.