code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
S = input()
N = len(S)
cnt = 0
for i in range(N//2):
if S[i] != S[-1-i]:
cnt += 1
print(cnt) | MOD = int(1e9+7)
N, K = map(int, input().split())
count = [0] * (K+1)
ans = 0
for now in range(K, 0, -1):
count[now] = pow(K // now, N, MOD)
for j in range(2*now ,K+1, now):
count[now] -= count[j]
if count[now] < 0:
count[now] += MOD
ans += now * count[now]
print(ans % MOD) | 0 | null | 78,511,165,253,630 | 261 | 176 |
#coding:UTF-8
while True:
n = map(int,raw_input().split())
if (n[0] or n[1]) == 0:
break
n.sort()
print n[0],n[1] | n = int(raw_input())
A = map(int, raw_input().split())
d = {}
def soleve(i, m, n):
if m == 0:
return True
if i >= n:
return False
if d.has_key((i, m)):
return d[(i, m)]
res = soleve(i + 1, m, n) or soleve(i + 1, m - A[i], n)
d[(i, m)] = res
return res
q = int(raw_input())
M = map(int, raw_input().split())
for m in M:
if soleve(0, m, n):
print 'yes'
else:
print 'no' | 0 | null | 321,105,853,180 | 43 | 25 |
n = int(input())
s = input()
x = n // 2
print(["Yes", "No"][n % 2 != 0 or s[:x] != s[x:]]) | # coding: utf-8
# Your code here!
X,K,D=map(int,input().split())
move=min(abs(X)//D,K)
ans=abs(X)-move*D
if move==K:
print(ans)
else:
if (K-move)%2==0:
print(ans)
else:
print(abs(ans-D)) | 0 | null | 76,200,259,814,742 | 279 | 92 |
n = int(input())
c = 0
for i in range(1,n):
if (i%2==1):
c+=1
print("{0:.10f}".format(1-(c/n)))
| N = int(input())
if N == 1:
print(1)
elif N%2 == 0:
print(0.5)
else:
print((N+1)/2/N) | 1 | 177,331,962,712,252 | null | 297 | 297 |
def check():
N = int(input())
plus,minus = [],[]
for i in range(N):
S = input()
now = 0
mini = 0
for s in S:
if s=='(':
now += 1
else:
now -= 1
mini = min(mini,now)
if now>=0:
plus.append([mini,now])
else:
minus.append([now-mini,now])
plus.sort(reverse=True)
minus.sort(reverse=True)
now = 0
for a,b in plus:
if now + a <0:
return 'No'
now += b
for a,b in minus:
if now + b-a <0:
return 'No'
now += b
if now > 0:
return 'No'
return 'Yes'
print(check()) | n, m = map(int, input().split())
if m%2 == 1:
for i in range(int((m-1)/2)):
print(str(i+1) + ' ' + str(m-i))
for i in range(int((m+1)/2)):
print(str(m+i+1) + ' ' + str(2*m-i+1))
else:
for i in range(int(m/2)):
print(str(i+1) + ' ' + str(m-i+1))
for i in range(int(m/2)):
print(str(i+m+2) + ' ' + str(2*m-i+1)) | 0 | null | 26,221,334,339,156 | 152 | 162 |
from collections import Counter
s=input()
n=len(s)
M=[0]
mod=2019
for i in range(n):
m=(M[-1]+int(s[n-1-i])%mod*pow(10,i,mod))%mod
M.append(m)
MC=Counter(M)
r=0
for v in MC.values():
if v>1:
r+=v*(v-1)//2
print(r) | N = str(input())
n,mods = 0,[1]+[0]*2018
d = 1
for i in reversed(N):
n = (n+int(i)*d)%2019
mods[n] += 1
d = (d*10)%2019
print(sum([i*(i-1)//2 for i in mods])) | 1 | 30,825,096,907,180 | null | 166 | 166 |
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce, lru_cache
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def MAP1() : return map(lambda x:int(x)-1,input().split())
def LIST() : return list(MAP())
def LIST1() : return list(MAP1())
n = INT()
k = INT()
@lru_cache(None)
def F(n, k):
# n以下で0でないものがちょうどk個ある数字の個数
if n < 10:
if k == 0:
return 1
if k == 1:
return n
return 0
q, r = divmod(n, 10)
ret = 0
if k >= 1:
ret += F(q, k-1) * r
ret += F(q-1, k-1) * (9-r)
ret += F(q, k)
return ret
print(F(n, k)) | import sys
import math
sys.setrecursionlimit(1000000)
N = int(input())
K = int(input())
from functools import lru_cache
@lru_cache(maxsize=10000)
def f(n,k):
# print('n:{},k:{}'.format(n,k))
if k == 0:
return 1
if k== 1 and n < 10:
return n
keta = len(str(n))
if keta < k:
return 0
h = n // (10 ** (keta-1))
b = n % (10 ** (keta-1))
ret = 0
for i in range(h+1):
if i==0:
ret += f(10 ** (keta-1) - 1, k)
elif 1 <= i < h:
ret += f(10 ** (keta-1) - 1, k-1)
else:
ret += f(b,k-1)
return ret
print(f(N,K)) | 1 | 76,320,905,021,710 | null | 224 | 224 |
n, m=map(int, input().split())
x = list(map(int, input().split()))
y = sorted(x, reverse=True)
if y[m-1] >= sum(x)/(4*m):
print('Yes')
else:
print('No') | def get_dice(pips):
return [[0, pips[4], 0, 0],
[pips[3], pips[0], pips[2], pips[5]],
[0, pips[1], 0, 0]]
def move_e(dice):
dice[1] = dice[1][3:] + dice[1][:3]
return dice
def move_n(dice):
return [[0, dice[1][1], 0, 0],
[dice[1][0], dice[2][1], dice[1][2], dice[0][1]],
[0, dice[1][3], 0, 0]]
def move_s(dice):
return [[0, dice[1][3], 0, 0],
[dice[1][0], dice[0][1], dice[1][2], dice[2][1]],
[0, dice[1][1], 0, 0]]
def move_w(dice):
dice[1] = dice[1][1:] + dice[1][:1]
return dice
func = {'E':move_e,'N':move_n,'S':move_s,'W':move_w}
dice = get_dice(list(map(int, input().split())))
for c in input():
dice = func[c](dice)
print(dice[1][1]) | 0 | null | 19,365,919,863,992 | 179 | 33 |
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_sums, b_sums = [0], [0]
for i in range(n):
a_sums.append(a_sums[i] + a[i])
for i in range(m):
b_sums.append(b_sums[i] + b[i])
ans = 0
j = m
for i in range(n + 1):
if a_sums[i] > k:
break
while a_sums[i] + b_sums[j] > k:
j -= 1
ans = max(ans, i + j)
print(ans) | n,m,k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
from itertools import accumulate
import bisect
cumsum_a = list(accumulate(a))
cumsum_b = list(accumulate(b))
ans = 0
for i in range(1, n+1):
if cumsum_a[i-1] > k:
break
cnt_b = bisect.bisect(cumsum_b, k - cumsum_a[i-1])
ans = max(ans, i + cnt_b)
for i in range(1, m+1):
if cumsum_b[i-1] > k:
break
cnt_a = bisect.bisect(cumsum_a, k - cumsum_b[i-1])
ans = max(ans, i + cnt_a)
print(ans) | 1 | 10,666,467,809,050 | null | 117 | 117 |
def resolve():
N = int(input())
X = input()
if N == 1:
if X.count("1"):
print(0)
else:
print(1)
return True
base_1_count = X.count("1")
if base_1_count == 0:
for _ in range(N):
print(1)
return True
X_int = int(X, 2)
X_int_p = X_int%(base_1_count + 1)
# RE 対策
if base_1_count == 1:
for i in range(N):
if X[i] == "1":
print(0)
else:
if i == N - 1:
Xi = X_int_p + 1
else:
Xi = X_int_p
count = 1
while Xi != 0:
Xi %= bin(Xi).count("1")
count += 1
print(count)
return True
X_int_m = X_int%(base_1_count - 1)
for i in range(N):
# 初期値計算を高速にやる
if X[i] == "1":
temp_1_count = base_1_count-1
pow_2 = pow(2, N-i-1, base_1_count-1)
if X_int_m <= pow_2:
Xi = X_int_m - pow_2 + base_1_count-1
else:
Xi = X_int_m - pow_2
else:
temp_1_count = base_1_count+1
Xi = X_int_p + pow(2, N-i-1, base_1_count+1)
while Xi >= base_1_count+1:
Xi %= base_1_count+1
# print("1_c={0}".format(temp_1_count))
if temp_1_count == Xi:
print(1)
continue
count = 1
while Xi != 0:
num_of_1 = bin(Xi).count("1")
Xi %= num_of_1
count += 1
print(count)
if __name__ == "__main__":
resolve() | import itertools
N = int(input())
H = []
for n in range(N):
A = int(input())
tmp = []
for a in range(A):
tmp.append(list(map(int, input().split())))
H.append(tmp)
ans = 0
for pro in itertools.product([0, 1], repeat=N):
flag = 0
for p in range(len(pro)):
if pro[p] != 0:
for h in H[p]:
if pro[h[0]-1] != h[1]:
flag = 1
break
if flag == 1:
break
if p == len(pro) - 1:
ans = max(ans, sum(pro))
print(ans)
| 0 | null | 64,672,474,239,438 | 107 | 262 |
n = int(input())
a = list(map(int,input().split()))
ans = 1
if 0 in a:
print(0)
else:
for i in range(n):
ans *= a[i]
if ans > 10 ** 18:
print(-1)
break
else:
print(ans) | n=int(input())
L=list(map(int,input().split()))
if L.count(0)!=0:
print(0)
else:
L_1=sorted(L)
x=1
for i in range(n):
x*=L_1[i]
if x>10**18:
x=-1
break
print(x) | 1 | 16,179,492,221,118 | null | 134 | 134 |
_ = input()
S = input()
newS = S.replace("ABC", "")
print((len(S) - len(newS)) // 3) | h,w = list(map(int, input().split()))
board = []
dp = []
INF=10**18
for _ in range(h):
board.append(input())
dp.append([INF]*w)
dxy=[(0,1), (0,-1), (1,0), (-1,0)]
dp[0][0]=1 if board[0][0] == '#' else 0
for y in range(h):
for x in range(w):
dp_list=[dp[y][x]]
if x>0:
dp_left = dp[y][x-1]
if board[y][x-1] != board[y][x] and board[y][x] == '#':
dp_left += 1
dp_list.append(dp_left)
if y>0:
dp_up=dp[y-1][x]
if board[y-1][x] != board[y][x] and board[y][x] == '#':
dp_up += 1
dp_list.append(dp_up)
dp[y][x]=min(dp_list)
print(dp[h-1][w-1]) | 0 | null | 74,405,406,148,762 | 245 | 194 |
# https://atcoder.jp/contests/abc145/tasks/abc145_d
X, Y = list(map(int, input().split()))
MOD = int(1e9 + 7)
def combination(n, r, mod=MOD):
def modinv(a, mod=MOD):
return pow(a, mod-2, mod)
# nCr with MOD
r = min(r, n - r)
res = 1
for i in range(r):
res = res * (n - i) * modinv(i+1, mod) % mod
return res
# 1回の移動で3増えるので,X+Yは3の倍数 (0, 0) start
if (X + Y) % 3 != 0:
ans = 0
print(0)
else:
# X+Yは3の倍数
# (+1, +2)をn回,(+2, +1)をm回実行
# n + 2m = X
# 2n + m = Y
# 3 m = 2 X - Y
# m = (2 X - Y) // 3
# n = X - 2 * m
m = (2 * X - Y) // 3
n = X - 2 * m
if m < 0 or n < 0:
print(0)
else:
print(combination(m + n, m, MOD))
| n = input()
digit1 = int(n[-1])
ans = ''
if digit1 in {2, 4, 5, 7, 9}:
ans = 'hon'
elif digit1 in {0, 1, 6, 8}:
ans = 'pon'
elif digit1 in {3}:
ans = 'bon'
print(ans)
| 0 | null | 84,368,921,764,090 | 281 | 142 |
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 10**9 + 7
N = 10**6 # N は必要分だけ用意する
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N+1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
x,y=map(int,input().split())
if ((x+y)%3!=0):
print(0)
else:
xx=(2*x-y)//3
yy=(2*y-x)//3
if (xx<0 or yy<0):
print(0)
else:
ans=cmb(xx+yy,xx,p)
print(ans) | N=int(input())
xp=yp=0
xn=yn=10**9
zs=[0]*N
ws=[0]*N
for i in range(N):
xi,yi=map(int,input().split())
zs[i]=xi+yi
ws[i]=xi-yi
zs.sort()
ws.sort()
ans=max(zs[-1]-zs[0],ws[-1]-ws[0])
print(ans) | 0 | null | 76,967,214,474,878 | 281 | 80 |
n=int(input())
a=input().split(' ')
b=[int(i) for i in a]
s=0
for k in range(2,n):
for j in range(1,k):
for i in range(j):
if (b[i]!=b[j] and b[j]!=b[k] and b[k]!=b[i]):
m=max(b[i],b[j],b[k])
if 2*m<b[i]+b[j]+b[k]:
s+=1
print(s) | n=int(raw_input())
ans=''
for i in range(3,n+1):
if i%3==0 or '3' in str(i):
ans+=(' '+str(i))
print ans | 0 | null | 3,034,406,461,600 | 91 | 52 |
import math
import sys
import collections
import bisect
readline = sys.stdin.readline
def main():
[h, w, n] = [int(readline().rstrip()) for _ in range(3)]
print(math.ceil(n/max(h, w)))
if __name__ == '__main__':
main()
| # import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
h=int(input())
w=int(input())
n=int(input())
v=max(h,w)
cnt=0
while n>0:
n-=v
cnt+=1
print(cnt)
resolve() | 1 | 88,994,747,440,608 | null | 236 | 236 |
n=list(map(int,input()))
if n[-1] in [2,4,5,7,9]:
print('hon')
elif n[-1] in [0,1,6,8]:
print('pon')
else:
print('bon') | n,m=map(int,input().split())
l=[]
for i in range(m):
order=list(map(int,input().split()))
l.append(order)
if n==1:
for i in range(10):
if all(str(i)[l[j][0]-1]==str(l[j][1]) for j in range(m)):
print(i)
exit()
elif n==2:
for i in range(10,10**2):
if all(str(i)[l[j][0]-1]==str(l[j][1]) for j in range(m)):
print(i)
exit()
else:
for i in range(10**2,10**3):
if all(str(i)[l[j][0]-1]==str(l[j][1]) for j in range(m)):
print(i)
exit()
print(-1) | 0 | null | 40,067,925,274,950 | 142 | 208 |
# 問題:https://atcoder.jp/contests/abc143/tasks/abc143_b
n = int(input())
d = list(map(int, input().strip().split()))
res = 0
for i in range(1, n):
for j in range(i):
res += d[i] * d[j]
print(res)
| kx=input().rstrip().split(" ")
k=int(kx[0])
x=int(kx[1])
if 500*k>=x:
print("Yes")
else:
print("No") | 0 | null | 133,024,092,467,140 | 292 | 244 |
S,W = map(int,input().split())
print(("safe","unsafe")[W >= S]) | a, b = map(int, input().split())
if a > b:
print('safe')
else:
print('unsafe') | 1 | 29,401,449,223,652 | null | 163 | 163 |
x = input().split(' ')
a = int(x[0])
b = int(x[1])
if a == b:
print('a == b')
elif a < b:
print('a < b')
else:
print('a > b') | from math import sin, cos, radians, sqrt
a, b, C = map(float, input().split())
rad = radians(C)
h = b * sin(rad)
print(a * h / 2)
print(a + b + sqrt(a ** 2 + b ** 2 - 2 * a * b * cos(rad)))
print(h)
| 0 | null | 263,584,968,178 | 38 | 30 |
def main():
N, M = map(int, input().split())
A = list(map(int, input().split()))
threshold = sum(A) / (4 * M)
if sorted(A, reverse=True)[M-1] >= threshold:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| n, m = map(int, input().split())
a = list(map(int, input().split()))
a_sort = sorted(a, reverse=True)
a_sum = sum(a)
if a_sort[m - 1] < a_sum / (4 * m):
print('No')
else:
print('Yes') | 1 | 38,804,516,703,030 | null | 179 | 179 |
N = int(input())
print(N//2 if N%2 else N//2-1) | mod = pow(10, 9) + 7
def powmod(x, y):
res = 1
for i in range(y):
res = res * x % mod
return res
n = int(input())
ans = powmod(10, n) - powmod(9, n) - powmod(9, n) + powmod(8, n)
ans %= mod
ans = (ans + mod) % mod
print(ans)
| 0 | null | 77,863,205,285,162 | 283 | 78 |
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
s=input()
len_s=len(s)
T=[0]*(len_s+1)
T[-1],T[-2]=0,int(s[-1])
mod=2019
for i in range(len_s-2,-1,-1):
T[i]=(T[i+1]+int(s[i])*pow(10,len_s-i-1,mod))%mod
tc=list(Counter(T).values())
ans=0
for tcc in tc:
ans+=tcc*(tcc-1)//2
print(ans)
if __name__=='__main__':
main() | a,b=map(int,input().split())
c,b=map(int,input().split())
if a!=c:
print(1)
else:
print(0) | 0 | null | 77,379,727,187,630 | 166 | 264 |
class Dice(object):
def __init__(self, n):
self.n = n
def move(self, to):
if to == 'N':
self.n[0], self.n[1], self.n[4], self.n[5] = self.n[1], self.n[5], self.n[0], self.n[4]
elif to == 'E':
self.n[0], self.n[2], self.n[3], self.n[5] = self.n[3], self.n[0], self.n[5], self.n[2]
elif to == 'S':
self.n[0], self.n[1], self.n[4], self.n[5] = self.n[4], self.n[0], self.n[5], self.n[1]
elif to == 'W':
self.n[0], self.n[2], self.n[3], self.n[5] = self.n[2], self.n[5], self.n[0], self.n[3]
def top(self):
return self.n[0]
dice = Dice([int(i) for i in input().split()])
move = input()
for m in move:
dice.move(m)
print(dice.top())
| import sys
def sieve(N):
is_prime = [True] * (N + 1)
prime_list = []
is_prime[0] = is_prime[1] = False
prime_list.append(2)
for i in range(3, N + 1, 2):
if is_prime[i]:
prime_list.append(i)
for j in range(i * i, N, i):
is_prime[j] = False
return prime_list
primes = sieve(10001)
primes_set = set(primes)
def is_prime(num):
if num in primes_set:
return True
elif num <= 10000:
return False
else:
for prime in primes:
if num % prime == 0:
return False
return True
if __name__ == '__main__':
N = sys.stdin.readline()
N = int(N)
ans = 0
for i in range(N):
num = sys.stdin.readline()
num = int(num)
if is_prime(num): ans += 1
sys.stdout.write(str(ans) + '\n') | 0 | null | 126,235,179,838 | 33 | 12 |
A, B, C, D = map(int, input().split())
while A > 0 and C > 0:
A -= D
C -= B
if C <= 0:
print('Yes')
else:
print('No') | N=int(input())
DP=[-1]*10000
DP[0]=1
DP[1]=0
DP[2]=0
mod=10**9+7
for i in range(3,N+1):
DP[i]=(DP[i-3]+DP[i-1])%mod
print(DP[N])
| 0 | null | 16,550,684,412,360 | 164 | 79 |
from collections import defaultdict
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = defaultdict(int)
sa = [0] * (n + 1)
d[0] = 1
if k == 1:
print(0)
exit()
for i in range(n):
sa[i + 1] = sa[i] + a[i]
sa[i + 1] %= k
ans = 0
for i in range(1, n + 1):
v = sa[i] - i
v %= k
ans += d[v]
d[v] += 1
if 0 <= i - k + 1:
vv = sa[i - k + 1] - (i - k + 1)
vv %= k
d[vv] -= 1
print(ans)
| #!/usr/bin/env python3
from itertools import accumulate
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = [0] + list(accumulate(a))
def f(x):
return (x + n * k) % k
ans = 0
dic = {}
for i in range(n + 1):
if i >= k:
prev = f(s[i - k] - (i - k))
dic[prev] -= 1
cur = f(s[i] - i)
if cur in dic:
ans += dic[cur]
dic[cur] += 1
else:
dic[cur] = 1
print(ans)
| 1 | 137,751,547,290,374 | null | 273 | 273 |
def main():
N = int(input())
A = [ int(a) for a in input().split()]
A_ = set(A)
if len(A)==len(A_):
print("YES")
else:
print("NO")
if __name__ == "__main__":
main() | N = input()
A = list(int(x) for x in input().split())
if len(set(A)) == len(A):
print('YES')
else:
print('NO')
| 1 | 74,162,138,744,892 | null | 222 | 222 |
n,q = map(int,input().split())
queue = []
for i in range(n):
name,time = input().split()
queue.append((name, int(time)))
t = 0
while queue:
name,time = queue.pop(0)
t += min(q, time)
if time > q:
queue.append((name, time-q))
else:
print(name,t)
| time = 0
n, q = map(int, input().split())
qname = list(range(n))
qtime = list(range(n))
ename = []
etime = []
for i in range(n):
inp = input().split()
qname[i], qtime[i] = inp[0], int(inp[1])
while len(qtime) > 0:
if qtime[0] <= q:
time += qtime.pop(0)
ename.append(qname.pop(0))
etime.append(time)
else:
time += q
qname.append(qname.pop(0))
qtime.append(qtime.pop(0)-q)
for (a, b) in zip(ename, etime):
print(a, b) | 1 | 45,406,579,582 | null | 19 | 19 |
import sys
def lower(word):
Word = ''
str = list(word)
for i in range(len(str)):
if str[i].isupper(): Word += str[i].lower()
else: Word += str[i]
return Word
a = []
for line in sys.stdin:
a.extend(list(line))
count = [0] * 26
for i in range(len(a)):
a[i] = lower(a[i])
if 97 <= ord(a[i]) and ord(a[i]) < 123:
count[ord(a[i]) - 97] += 1
for i in range(26):
print(chr(i + 97) + ' : ' + str(count[i]))
| N = input()
money = 100000
for i in range(N):
money = int(money *1.05)
if money % 1000 != 0:
money = (money // 1000 + 1) * 1000
print money | 0 | null | 820,090,910,628 | 63 | 6 |
m,n,o=map(int,raw_input().split())
print'Yes'if m<n<o else'No' | N,K=map(int,input().split())
A=[]
people=list(range(1,N+1,1))
for idx in range(K):
d=int(input())
X=list((map(int,input().split())))
for i in range(len(X)):
A.append(X[i])
ans =[i for i in people if not i in A]
print(len(ans)) | 0 | null | 12,469,828,236,220 | 39 | 154 |
import sys
import collections
import itertools
def resolve(in_):
one = ord(b'1')
two = ord(b'2')
# print(f'{one=} {two=}')
S = in_.readline().strip()
q = collections.deque(S)
# print(f'{S=} {q=}')
reverse_flag = False
Q = int(in_.readline())
for query in itertools.islice(in_, Q):
T = query[0]
if T == one:
reverse_flag ^= True
# q.reverse()
elif T == two:
F = query[2]
C = query[4]
if (F == one) ^ reverse_flag:
q.appendleft(C)
else:
q.append(C)
else:
if reverse_flag:
q.reverse()
reverse_flag = 0
return bytes(q)
def main():
answer = resolve(sys.stdin.buffer)
print(answer.decode('ascii'))
if __name__ == '__main__':
main()
| import numpy as np
N, M = map(int, input().split())
A = []
A = map(int, input().split())
dif = N - sum(A)
if dif >= 0:
print(dif)
else:
print('-1') | 0 | null | 44,559,887,678,560 | 204 | 168 |
lakes = [] # [(左岸位置, 断面積)]
lefts = [] # lefts[i]: まだ対になっていない上から i 番目の左岸位置
for i, c in enumerate(input()):
if c == '\\':
lefts.append(i)
elif c == '/':
if lefts:
left = lefts.pop()
area = i - left
while lakes:
sub_left, sub_area = lakes[-1]
if left < sub_left:
area += sub_area
lakes.pop()
else:
break
lakes.append((left, area))
L = [lake[1] for lake in lakes]
print(sum(L))
print(len(L), *L)
| # -*- coding: utf-8 -*-
modelmap = list(input())
S1 = []
S2 = []
A = 0
for i, l in enumerate(modelmap):
if l == "\\":
S1.append(i)
elif l == "/" and len(S1) > 0:
ip = S1.pop()
A += i - ip
L = i - ip
while len(S2) > 0 and S2[-1][0] > ip:
L += S2.pop()[1]
S2.append([ip, L])
print(A)
text2 = "{}".format(len(S2))
for s in S2:
text2 += " " + str(s[1])
print(text2) | 1 | 58,410,662,610 | null | 21 | 21 |
import math
lrd=input().split()
l=int(lrd[0])
r=int(lrd[1])
d=int(lrd[2])
a=math.ceil(l/d)
b=math.floor(r/d)
print(b-a+1)
| L,R,d=map(int,input().split())
R_=R//d
L_=(L-1)//d
print(R_-L_) | 1 | 7,595,867,400,320 | null | 104 | 104 |
A=[]
fp =0
bp =0
n=int(raw_input())
while n:
s = raw_input()
if s[0] == 'i':
A.append(int(s[7:]))
fp += 1
elif s[6] == ' ':
try:
i = A[::-1].index(int(s[7:]))
if i!=-1:
del A[-i-1]
fp -=1
except:
pass
elif s[6] == 'F':
A.pop()
fp -=1
elif s[6] == 'L':
bp +=1
n -=1
for e in A[bp:fp+1][::-1]:
print int(e), | n=int(input())
z_max,z_min=-10**10,10**10
w_max,w_min=-10**10,10**10
for i in range(n):
a,b=map(int,input().split())
z=a+b
w=a-b
z_max=max(z_max,z)
z_min=min(z_min,z)
w_max=max(w_max,w)
w_min=min(w_min,w)
print(max(z_max-z_min,w_max-w_min)) | 0 | null | 1,742,263,998,368 | 20 | 80 |
import sys
# 最大公約数(greatest common divisor)を求める関数
def gcd(a, b):
while b:
a, b = b, a % b
return a
# 最小公倍数(least common multiple)を求める関数
# //は切り捨て除算
def lcm(a, b):
return a * b // gcd(a, b)
lines = sys.stdin.readlines()
for line in lines:
a = list(map(int, line.split(" ")))
print(gcd(a[0], a[1]), lcm(a[0], a[1]))
| import bisect
import sys
sys.setrecursionlimit(10**9)
def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))
INF=10**20
def main():
N=ii()
L=list(mi())
ans = 0
L.sort()
for ai in range(N):
for bi in range(ai+1,N):
a,b = L[ai],L[bi]
left = bisect.bisect_left(L,abs(a-b)+1)
right = bisect.bisect_right(L,a+b-1)
count = right - left
if left <= ai <= right:
count -= 1
if left <= bi <= right:
count -= 1
ans += count
# if count > 0:
# print(a,b,count)
print(ans//3)
if __name__ == "__main__":
main() | 0 | null | 85,579,948,560,070 | 5 | 294 |
from collections import deque
n, u, v = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(n-1):
a, b = map(int, input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
d_1 = deque()
d_1.append(u-1)
dist_1 = [-1] * n
dist_1[u-1] = 0
while d_1:
node = d_1.popleft()
for next_node in edge[node]:
if dist_1[next_node] < 0:
dist_1[next_node] = dist_1[node] + 1
d_1.append(next_node)
d_2 = deque()
d_2.append(v-1)
dist_2 = [-1] * n
dist_2[v-1] = 0
while d_2:
node = d_2.popleft()
for next_node in edge[node]:
if dist_2[next_node] < 0:
dist_2[next_node] = dist_2[node] + 1
d_2.append(next_node)
res = 0
for i in range(n):
if dist_1[i] < dist_2[i]:
res = max(res, dist_2[i]-1)
print(res) | from itertools import permutations
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
P=sorted(list(permutations(range(1,n+1),n)))
print(abs(P.index(p)-P.index(q))) | 0 | null | 108,684,046,192,470 | 259 | 246 |
n, x, t = map(int, input().split())
i = 0
while True:
i += 1
if i*x >= n :
break
print(i*t) | a, b, c = map(int, input().split())
if a % b == 0:
print(a//b * c)
else:
print((a//b + 1) * c) | 1 | 4,290,974,467,010 | null | 86 | 86 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a[:k])
mx = s
for i in range(k, n):
s += a[i] - a[i - k]
mx = max(mx, s)
print((mx + k) / 2) | N, M = map(int, input().split())
A = list(map(int, input().split()))
assert len(A) == M
# M個の宿題, それぞれAi日かかる
yasumi = N - sum(A)
if yasumi >= 0:
print(yasumi)
else:
print(-1) | 0 | null | 53,753,772,159,880 | 223 | 168 |
import sys
readline = sys.stdin.readline
N,X,M = map(int,readline().split())
MAXD = 55
# nex[t][v] = v (mod M)から2 ** tステップ進んだ先の値
# まずnex[0][v] は、v (mod M)から1ステップ進んだ先の値を入れておく
# sums[t][v] = v (mod M)から2 ** tステップ進んだ総和
# まずsums[0][v]は、各項がvそのものになる(1ステップだから)
nex = [[-1] * M for i in range(MAXD + 1)]
sums = [[0] * M for i in range(MAXD + 1)]
# まず、1ステップ進んだ先の値を入れる
for r in range(M):
nex[0][r] = r * r % M
sums[0][r] = r
for p in range(MAXD):
for r in range(M):
nex[p + 1][r] = nex[p][nex[p][r]]
sums[p + 1][r] = sums[p][r] + sums[p][nex[p][r]]
# 最初は、1ステップ(今いる場所)の場合の総和が入っている。次の進み先の総和と足すことで、
# 今いる場所と次の場所の総和となり、2つ進んだ場合の総和が求められる
# これで2つ進んだ場合の総和を求めるリストになるため、
# ここで同じことをやることで、「2つ分の総和とその次の2つ分の総和」->「4つ分の総和」となる
res = 0
cur = X
for p in range(MAXD, -1, -1):
if N & (1 << p):
res += sums[p][cur]
cur = nex[p][cur]
print(res) | import math
a, b, C = map(float, input().split())
h = b * math.sin(math.radians(C))
S = a * h / 2
a1 = b * math.cos(math.radians(C))
cc = math.sqrt(h * h + (a - a1) * (a - a1))
print("{a:5f}".format(a=S))
print("{a:5f}".format(a=a + b + cc))
print("{a:5f}".format(a=h))
| 0 | null | 1,469,333,713,280 | 75 | 30 |
i = list(map(int, input().split()))
a = i[0]
b = i[1]
c = i[2]
answer = 0
for j in range(a, b + 1) :
if c % j == 0 :
answer += 1
print(answer) | def counter(a, b, c):
count = 0
for n in range(a, b+1):
if c % n == 0:
count += 1
print(count)
a, b, c = list(map(int, input().split()))
counter(a, b, c) | 1 | 561,896,275,880 | null | 44 | 44 |
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
ret = 0
for i in range(k):
last = 'x'
for c in t[i::k]:
if last != c:
ret += p if c == 'r' else r if c == 's' else s
last = c
else:
last = 'x'
print(ret)
| N, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
s = 0
for i in h:
if i >= k:
s += 1
print(s) | 0 | null | 142,601,384,674,112 | 251 | 298 |
n=int(input())
for i in range(n):
p=list(map(int,input().split(" ")))
p.sort()
if pow(p[0],2) + pow(p[1],2) == pow(p[2],2):
print('YES')
else:
print('NO')
| print "\n".join(s for s in map(lambda x:x[0]+x[1]==x[2] and 'YES' or 'NO', [sorted(int(x)**2 for x in raw_input().split(' ')) for i in range(int(raw_input()))])) | 1 | 254,962,652 | null | 4 | 4 |
from fractions import gcd
n,m = map(int,input().split())
a = list(map(lambda x: int(x)//2,input().split()))
def lcm(x,y):
return x*y//gcd(x,y)
def f(x):
cnt = 0
while x%2 == 0:
x //= 2
cnt += 1
return cnt
r = set([f(i) for i in a])
if len(r) != 1:
print(0)
exit()
T = 1
for i in range(n):
T = lcm(T,a[i])
ans=-(-(m//T)//2)
c=T
print(ans) | def d_semi_common_multiple():
from fractions import gcd
from functools import reduce
N, M = [int(i) for i in input().split()]
A = [int(i) // 2 for i in input().split()] # 先に2で割っておく
def count_divide_2(n):
"""n に含まれる因数 2 の指数"""
return (n & -n).bit_length()
def lcm(a, b):
return a * b // gcd(a, b)
# A の全要素について,2で割れる回数は等しいか?
tmp = count_divide_2(A[0])
for a in A:
if count_divide_2(a) != tmp:
return 0
t = reduce(lambda x, y: lcm(x, y), A)
return (M // t) - (M // (2 * t))
print(d_semi_common_multiple()) | 1 | 101,931,903,153,704 | null | 247 | 247 |
if __name__ == "__main__":
n = int(raw_input())
v = map( int, raw_input().split())
min = 1000000
max = -1000000
s = 0
i = 0
while i < n:
if min > v[i]:
min = v[i]
if max < v[i]:
max = v[i]
s += v[i]
i += 1
print "{0} {1} {2}".format( min, max, s) | n, k = map(int, input().split())
p = list(map(int, input().split()))
sortPrice = sorted(p)
# print(sortPrice)
price = []
for i in range(0, k):
price.append(sortPrice[i])
print(sum(price)) | 0 | null | 6,184,865,110,620 | 48 | 120 |
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque
x = int(stdin.readline().rstrip())
for i in range(-150,150):
for j in range(-150,150):
if i**5-j**5 == x: print(i,j); sys.exit()
| def main():
x = int(input())
a_lst = []
b_lst = []
for i in range(400):
a_lst.append(-200 + i)
for i in range(400):
b_lst.append(-200 + i)
flag = False
for i in range(len(a_lst)):
for j in range(len(b_lst)):
a = a_lst[i]
b = b_lst[j]
if a ** 5 - b ** 5 == x:
print(a, b)
flag = True
break
if flag:
break
if __name__ == '__main__':
main() | 1 | 25,598,111,608,982 | null | 156 | 156 |
import math
x, y, X, Y = [float(i) for i in input().split()]
print(math.sqrt((x-X)**2 + abs(y-Y)**2)) | import math
x1, y1, x2, y2 = list(map(float, input().split(' ')))
print("{0:.4f}".format(math.sqrt((x1 - x2)**2 + (y1 - y2)**2)))
| 1 | 152,890,176,392 | null | 29 | 29 |
print((int(input()) + 1) // 2) | n = int(input())
ans = n // 2
if n % 2 != 0: ans += 1
print(ans) | 1 | 59,165,012,523,290 | null | 206 | 206 |
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
a=LI()
ALL=0
for i in range(N):
ALL=ALL^a[i]
ans=[0]*N
for i in range(N):
ans[i]=ALL^a[i]
print(' '.join(map(str, ans)))
main()
| import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.argsort(A)
for a in A:
print(a+1, end=" ") | 0 | null | 96,610,094,253,760 | 123 | 299 |
import math
a,b,c=map(float,input().split())
h=b*math.sin(c/180.0*math.pi)
ad=a-b*math.cos(c/180.0*math.pi)
d=(h*h+ad*ad)**0.5
l = a + b + d
s = a * h / 2.0
print('{0:.6f}'.format(s))
print('{0:.6f}'.format(l))
print('{0:.6f}'.format(h)) | import math
e=map(float,raw_input().split())
a=e[0]
b=e[1]
C=math.radians(e[2])
c=(a**2+b**2-2*a*b*math.cos(C))**0.5
h=b*math.sin(C)
S=h*a*0.5
L=a+b+c
print S
print L
print h
| 1 | 173,994,824,220 | null | 30 | 30 |
n,m=map(int,input().split())
if n%2==1:
x=[f"{i+1} {n-i}" for i in range(m)]
print(" ".join(x))
else:
x=[f"{i+1} {n-i}" if i<m/2 else f"{i+1} {n-i-1}" for i in range(m)]
print(" ".join(x))
| N, D, A = map(int, input().split())
X = [0] * N
for i in range(N):
x, h = map(int, input().split())
X[i] = (x, h)
X = sorted(X)
from collections import deque
q = deque()
ans = 0
total = 0
for i in range(N):
x, h = X[i]
while (len(q) > 0 and q[0][0] < x):
total -= q[0][1]
q.popleft()
h -= total
if h > 0:
num = (h + A - 1) // A
ans += num
damage = num * A
total += damage
q.append((x + 2 * D, damage))
print(ans) | 0 | null | 55,601,296,232,648 | 162 | 230 |
from math import sqrt
N = input()
sum = 0
for _ in xrange(N):
n = input()
for i in xrange(2,int(sqrt(n))+1):
if n%i == 0:
break
else:
sum += 1
print sum | import math
def isPrime(n):
for i in range(2, int(math.sqrt(n))+1):
if n % i == 0:
return False
return True
N = int(input())
nums = [int(input()) for i in range(N)]
print(sum([isPrime(n) for n in nums])) | 1 | 9,804,299,108 | null | 12 | 12 |
import math
r = float(raw_input())
print str("{:.10f}".format(r*r*math.pi)) + ' ' + str("{:.10f}".format(2*r*math.pi)) | a, b = input().split()
print(b, end = "")
print(a) | 0 | null | 52,030,771,978,140 | 46 | 248 |
N,K= list(map(int, input().split()))
Ps = list(map(int, input().split()))
ruisekiwa = [0]
for P in Ps:
ruisekiwa.append(P + ruisekiwa[-1])
#print(ruisekiwa)
ans = 0
for i in range(N-K+1):
ans = max(ans, (ruisekiwa[i+K] - ruisekiwa[i] + K) / 2)
# print(ans)
print(ans) |
def main():
s, t = input().split(' ')
print(t, end='')
print(s)
if __name__ == '__main__':
main()
| 0 | null | 89,221,865,573,060 | 223 | 248 |
def main():
n, x, t = map(int, input().split())
if (n % x) == 0:
ans = (n // x) * t
else:
ans = (n // x + 1) * t
print(ans)
if __name__ == "__main__":
main()
| n, x, t = list(map(int, input().split()))
tmp = int(n / x)
tmp2 = n % x
if tmp2 > 0:
tmp += 1
print(tmp * t) | 1 | 4,230,363,821,830 | null | 86 | 86 |
s = input()
l, r = 0, len(s)-1
c = 0
while l < r:
if s[l] != s[r]:
c += 1
l += 1
r -= 1
print(c)
| def main():
d, t, s = (int(i) for i in input().split())
if t*s >= d:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| 0 | null | 61,547,042,039,588 | 261 | 81 |
n = int(input())
ans = 0
for i in range(1,n+1):
if (i % 3 == 0) or (i % 5 == 0):
pass
else:
ans += i
print(ans) | import math
N = int(input())
num = list(map(int, input().split()))
#N = 10**6
#num = list(range(1, N+1))
MAXX = 10**6 + 1
MAXZ = int(math.sqrt(MAXX)+2)
furui = [[] for _ in range(MAXX)]
furui[1].append(1)
count = [0]*MAXX
for i in range(2, MAXX):
if len(furui[i]) == 0:
for k in range(i, MAXX, i):
furui[k].append(i)
setwise = True
pairwise = True
for i in range(N):
if not setwise and not pairwise: break
for fu in furui[num[i]]:
count[fu] += 1
if fu > 1 and count[fu] >= N:
setwise = False
pairwise = False
break
elif fu > 1 and count[fu] > 1:
pairwise = False
if pairwise:
print('pairwise coprime')
elif setwise:
print('setwise coprime')
else:
print('not coprime')
| 0 | null | 19,574,585,013,496 | 173 | 85 |
n = int(input())
L = list(map(int,input().split(' ')))
L.sort()
ans = 0
for i in range(n-2):
for j in range(i+1,n-1):
for k in range(j+1,n):
if L[i]==L[j]:
continue
if L[j]==L[k]:
continue
if L[i]+L[j] <= L[k]:
continue
ans+=1
print(ans)
| n=int(input())
Ns=list(map(int, input().split() ) )
ans=0
for i in range(n):
for j in range(i,n):
for k in range(j,n):
a , b , c = sorted([Ns[i] , Ns[j] , Ns[k]])
if a+b>c and a!=b and b!=c:
ans+=1
print(ans)
| 1 | 5,022,720,662,530 | null | 91 | 91 |
n=map(str,raw_input().split())
a=[]
ai=0
for i in n:
if i=="+" :
a.append(a[ai-1]+a[ai-2])
a.pop(ai-1);a.pop(ai-2)
ai-=1
elif i=="-":
a.append(a[ai-2]-a[ai-1])
a.pop(ai-1);a.pop(ai-2)
ai-=1
elif i=="*":
a.append(a[ai-1]*a[ai-2])
a.pop(ai-1);a.pop(ai-2)
ai-=1
else:
a.append(int(i))
ai+=1
print(a[0]) |
def main():
l = input().split(' ')
while len(l) > 1:
idx = 0
while l[idx] not in ["+", "-", "*"]:
idx += 1
res = str(eval(str(l[idx-2] + l[idx] + l[idx-1])))
l[idx-2] = res
l.pop(idx-1)
l.pop(idx-1)
print(l[0])
main()
| 1 | 36,434,282,694 | null | 18 | 18 |
def main():
n = int(input())
# n, k = map(int, input().split())
# h = list(map(int, input().split()))
s = input()
ans = ""
for i in s:
ans += chr((ord(i) - ord("A") + n)% 26 + ord("A"))
print(ans)
if __name__ == '__main__':
main()
| n = int(input())
mydict = {}
answer_list = []
for i in range(n) :
query, wd = input().split()
if query == "insert" :
mydict[wd] = 1
else :
if wd in mydict.keys() : answer_list.append("yes")
else : answer_list.append("no")
for i in answer_list :
print(i)
| 0 | null | 67,404,215,277,398 | 271 | 23 |
import numpy
a,b,x=map(int,input().split())
V=a*a*b
if x<=V/2:
y=2*x/b/a
theta=numpy.arctan(b/y)
print(theta*360/2/numpy.pi)
else:
x=V-x
y=2*x/a/a
theta=numpy.arctan(y/a)
print(theta*360/2/numpy.pi)
| from math import atan, degrees
a, b, x = map(int, input().split())
if a*a*b <= 2*x:
theta = degrees(atan(2*b/a-2*x/(a*a*a)))
else:
theta = degrees(atan(a*b*b/(2*x)))
print(theta) | 1 | 162,742,620,237,414 | null | 289 | 289 |
# This code is generated by [Atcoder_base64](https://github.com/kyomukyomupurin/AtCoder_base64)
import base64
import subprocess
import zlib
exe_bin = "c$~#qeQaCR6~DIQ#Ay@9ZBv@IKs}bC7RYN%K1fz&#EzXlgA+<Vy3)11IJVO~aO~*$8It}1VWFs|O&6vK@y9lG+Wy!kZK6^&P2HrWO9x|OTA9Swt=rTgJ{+K;6{G4l8t>fq?tOmm`n|z4q}?b!@BH35=bn4+_jyl7V*O5s1F_;lUqpmktkw8liqCG=MF8tUweWijx*1giUuBTv>2-&hdh~iUy)LK5^Ymt9rVayjBl}XUGgE~8x*qX$s$N5<>is5qlGf{UoAsPj?<mzfO63_vRF6^CzAE}ZLUEpkk(pLey8A69NuKww)_9)U={*Q~)#%d~AEiUIKD)RqP=6U^{jeh~jdix~NGDs;QYJs$GTqhL(%CNLvclb}Pd+NUYj9MRC;iPrMcy}3jJ!WJaPhMDN4JLZ?=%j@!lw)3U8nv^Wb0A6-@u~N0h-iJ)c8VOU+(!DX0oC@1^;U;@SR}rHVb^zMqY4O<G0x0-?6cC)dt^!*hn*%`)us{Y~**^;F3+fwP1e@YC^p}P0L3+_F<&q53kYiCf4E5-#I0jxbsfZ$DIh{LzCGI&M9$O!5HD_$N)~J<kTT4r=;YOfxdJ$lNyPSrBm8F>o@xbhb1`|8Is^}SZPa085L8yq-+k4#dE3lXhu@PfyiSV9_Yx;WD@vsNtpm2l2SG@rkV(JVw}w>aw<NFrA#g*E71g?fy6{y#)=%5lw33si3|bO26m(bla7wykyacT?!>$AA8x~GD?j=)KZcd|L^iLGh$L7rAP$K~abn_8JRX-o87HRWIIg6oC51BMQYN034nw0cQKXTZj6;)m#iF4;e7Df9Kiw^KXwQ51;x?gO=r(eQ%p{lkUj=I+nF21gi=678RvhrO&Y_K$R`_p}q<S**_ERjsNvb7!<Bqbt1C`f>!js#bWTlm<yt4gk9#X?Bm1pY%TkjTEX>^*y7wA4R%i*(B-s3alj6dI?(P~s)H%Pf)z&!^1k^!$Z;6($z%79-n;HwSzbpu{!z}Y+@+e5tpXY+*MUITuT+NnY1HItO@8E}^Yf6;(f8StMNaO1wWXuyr@{;v#pjR6<u-uH;d+#l8Wk$7ZLahA@DbLTuusMPT+K&7q6;kRK+FFX-`f~YKCDnZ%$6~dDyET32T!-OYYvb?DBGT}*6mS0r)M+i@vuzXVG#|TecUtUo8eZY?|Fu#I(f}?>_aAb5CJoG2UV^v$X5qAsW=BB`6aS}Add8N5dobNg10pDMCpQzPZ7@JQvHx~DUz_D<1-I2v7l7WkX%P|o4sjp)5El+~Rd%lJ(uvrE!&n-E+_czx)(Gx3Nixoa7-Ugbn!rNlu<>Cg-NMm=n*_VHP?w5|a8?O9s&yYrm^Bt|w*!R{oY?(zGe+%$uoa%GWjcPwCdQ>NSuEO&f5-70x5?EVR{9vV23M`7pV$DrSv8_&RS-u_u@Bi|F;Qru&;K8NhPeEp3Txi(xwAN4aJ#Ub9LU$Dx;gxu-=RvS5&adC6l8$rg+jE{}8QzXB1TIGluN@Q%Z-{emUfDeon|D9rAXe%>)Qo)tq)O|rx&7$xY8(LC2!=+*dG{J(u=~1LcuUy`L*v(OZD`aVC|xT1b6|;#3X^|-bgPd1&P~j0Ujcpb?21b)ToKO}?-d;{iLb3FO<?djYOszNw6izca}~w|%I^^8dhP`UFbV$DL9-tLuK1f9rBYFZCcNZ+1>_t=UG0Ytm&Voh5b*=c;~=5&!7l~(L<@fijs_tXTTeLErnWo}bU0YJ5rwYb{+2oy&fahp-}x8<eB`p?4_sva#0vj}@ewY35G*zRS%fhocK;>+E(tj6vLIeE^w)<=bZ)7$Nn1w;v*@8z4xTr=cJ|VF_+6;#IM7CD&}pE}Kwkyg4*f&+-Xzfdz$?&_yMTWasN&GhNu)Rq4<X02&#}3##<Sq4@ey1-8-w1RhIwu+5A{)bANVmv1iZd}Z_|AZs~`8wqI);(yrZr8Hl|O`mU}_YxW1Bh5dU@q?k0mg<n^6!hP+MluCUjCyejD3_KZ8|ZJnzQdv`mRS9x0j33~k?0g@rFC%76;6|gQ6KcMXbF?zq(chIZVLhAe(sR!DVLYn=r68k4y5wCx~D&*aE+%0-rpQ#qTU2`=9-d@?;6;x{p8ER4Ysw(hr0_@lx4*!pZ?UVYxNO|M^#z@!E2eua#>7vf|pfKIMHd3DL%j~+w_VZ1YvVEA{t5_d@v{K3v`T`9a+iSMb&4}$Wi}XF)OOI3k*dE$M>3U=?Y_B^?_b1jjY$IUfmhD*^DBW9Q#=EM`e*0<tY|m%)--^s~|0-$ib5Ll7@)u}BOO$7RU7`GG`u-o3H}1`!Wzp}GT)Bxh;C4zoDeb3p52fQC^gk7L?%LJY_XYp9(Xo6+$@}jSI)v7iw!F#(o(Oaat?k=2^wZdMLA1LpCLuYyj#%O@q*&rr`nWXXZhbtO@oIhCn(-RFKh3yD9|vZ<Rv&L>e3d>f&G>44ewy(*^I=uT>(P`Y?nSefc!NIQ&A1Qkw#3)yc>^=P7M--j*Xiqr8E@3r4Ku#pa@@MmP5L}H<1njzR(SayYQ{HKU}U;ip{pexCwE*Y#Eq@10>y7vb(+x3TEDJON{5Y|UTWt`tr-tdymgfsAEo##hd)Z|o#yI2tUg!9^V`(UB4_7^s(fX?*!lmeD!&%JS;xPzmj9FbTRBcHt9B~;_nP{<uEPHshlcZhZgLPimE)mRy;p8PKCa(0PLju{94Ggv`HJ#5XVbgiCQp*L$@6>;5&81`a?_4^j@Wl@(APm$zGY+ol9S+-^YO<v^0HH_m*rL2neDud{ApFbay@yU`pL)bx{aMtr*)nu?bPDW$Jwd&OB0%1YsP1s8qU{y#A#jc4`_SO)A5|5_!*~lp6d5hzL&<6E$eSPt@BYI+tj<+Wo`cs8$9f?wu3@=R~9Q-d|zBj3yG;Igm=Xr2nAyp=kjAXs%36SGAP!Cv6PiEl7bSll2h{I<3a+Jb75GS#0iq~${~!CS$rs+9gC-NQpw6W9M4aqM0Rp2ol;Us;hxU!E^8r@K9X=;mg6%xl~LpwG%m*{Q#hHQoSXp_1BZz#CQ*$0hk^qU92pFgR2|+mIEo`81;y|X!r_Mog9Fh%cxO^hngKOsrN`lc{{G>}2p$QBViB;KO2(Bq!qErRd|U?SbE)JfC+&KBjfpLDri{L$=`aXOE{iAPnWQOkXk|dlyYcGg6kYi((Ha@(W6}96lZYnggzj?gkoTIzj)fPG<#O!VItR&XtNFx4F0c00e@?}gWyyfjv#ypF%Na^Ol$EJp+w`tQD%V^Y5^^(>N_-5cB5QPlJxLibIfaBwR!IrLP_#vfAEMl$OkNnvOX*~bltd~w5zkE^Avu!)dm2?_?agB;IVWW^CI-VhIhBqRLHab6R!Ef)Lh>ja%EAMTB=}WhCCFKIhzqF+I^8Cca+%XqwV9%6uxF?tJ}D*OK~;zDMFPzENtm2g3(tR7$UToNiEO>J`;NwngX2Gsw7V74=f6|=IeGqA9pLoY`JK_`PtYg#{%dfzV*2cy&*(Oav*S5`EFMJK-IM9F`v9X8w87*U?=a}Id*U8s{x-$#4U8V=0>;PhAkyxROrPB^7-jcR=0EqjP(3HE81&gagwcml*?%XhY(F_qRvGNE`wFA%e$2;@wf||VAEG?F*D%WN=S2S|3;h$w_>HcdpJ0^T<5}VRzrg92KLluGij((o^y{2HyH7F7$BQ$MzRBscb0MR@;O>_`Gpl~@GwQSRAfwzhqN4rZN9Os<&bN&6*EC-L6sK?Zz1U9w=bS#f7cwex1D=oPD@gn9!SXxh@5dU?$BU2u>+s)T&}a9G*?Q~xc>TX2E%thTN&h}i0ot%?PLKKZ0@B*g=ckS~X#Dgi)c-E0ub-!V=6ZO2R<2Nt>Feios@Thozg|xNBU(S7kYW1UIovAGXq6}JrTQ0W;K)AHf-2{Kt-*I=X`&Nf;$HIW=NcRRr)a`*g~NIMe*+LGoE`"
open("./kyomu", 'wb').write(zlib.decompress(base64.b85decode(exe_bin)))
subprocess.run(["chmod +x ./kyomu"], shell=True)
subprocess.run(["./kyomu"], shell=True) |
S = list(input())
K = int(input())
N = len(S)
# print(S)
# dp[i][j][k]
dp = [[[0] * 2 for _ in range(K+2)] for _ in range(N+1)]
dp[0][0][0] = 1
# 上の桁から調べていく
for i in range(1, N + 1):
for j in range(K + 1):
for k in range(2):
for num in range(10):
if num == 0:
inc = 0
else:
inc = 1
# N未満が確定していれば0-9の全ての遷移が可能なので加える
if k == 1:
dp[i][j+inc][k] += dp[i - 1][j][k]
else:
if num < int(S[i-1]):
# k = 1が確定
dp[i][j + inc][1] += dp[i - 1][j][k]
elif num == int(S[i-1]):
# k = 0のまま
dp[i][j + inc][0] += dp[i - 1][j][k]
# print(dp)
print(dp[N][K][0] + dp[N][K][1]) | 0 | null | 39,173,621,662,164 | 72 | 224 |
def main():
n = int(input())
ans = 0
x = n // 2
for i in range(1, n + 1):
m = n // i
ans += i * ((m + 1) * m) // 2
print(ans)
if __name__ == "__main__":
main()
| N,K = map(int,input().split())
i = 0
while True:
if N >= K ** i:
i += 1
else:
break
print(i) | 0 | null | 37,593,514,771,010 | 118 | 212 |
def main():
A,B,C = map(int,input().split())
K = int(input())
num = 0
while (B <= A):
num += 1
if num <= K:
B *= 2
else:
return ("No")
while (C <= B):
num += 1
if num <= K:
C *= 2
else:
return ('No')
return('Yes')
print(main())
| N = int(input())
print(len({ input() for i in range(N) })) | 0 | null | 18,466,473,306,710 | 101 | 165 |
#cやり直し
import numpy
n = int(input())
a = list(map(int, input().split()))
ans = 0
mod = 10**9 +7
before = a[-1]
for i in range(n-1,0,-1):
ans += (a[i-1]*before)%mod
before += a[i-1]
print(ans%mod) | MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
S = sum(A) % MOD
ans = 0
for x in A:
S -= x
S %= MOD
ans += S * x
ans %= MOD
ans %= MOD
print(ans) | 1 | 3,870,285,292,792 | null | 83 | 83 |
from itertools import groupby
s = input()
k = int(input())
r = len(s) * k // 2
a = [len(tuple(g)) & 1 for _, g in groupby(s)]
if len(a) > 1:
r -= sum(a) * k // 2
if s[0] == s[-1] and a[0] & a[-1]:
r += k - 1
print(r)
| from itertools import permutations
import math
N = int(input())
l = [list(map(int, input().split())) for i in range(N)]
waru = 1
for i in range(N):
waru*= i+1
a = [i+1 for i in range(N)]
c = 0
su = 0
for i in permutations(a,N):
li = list(i)
for j in range(len(li)-1):
start = l[li[j]-1]
g = l[li[j+1]-1]
su += math.sqrt((start[0]-g[0]) ** 2 + (start[1]-g[1]) ** 2)
print(su/waru) | 0 | null | 162,278,505,632,692 | 296 | 280 |
from math import sqrt
while 1:
n = int(input())
if n == 0:
break
a = list(map(int, input().split()))
av = sum(a)/len(a)
Sum = sum((x-av)**2 for x in a)
print(f'{sqrt(Sum/n):.8f}')
|
from math import sqrt
while True:
input_data =[] # ????´??????????
alpha = 0 # ??????
num = int(input())
if num == 0:
break
input_data = [float(i) for i in input().split()]
m = sum(input_data) / float(num)
for i in range(num):
alpha += (input_data[i] - m)**2
print(sqrt(alpha/num)) | 1 | 195,374,170,982 | null | 31 | 31 |
def solve():
a, b = input().split()
if a > b:
print(b*int(a))
else:
print(a*int(b))
if __name__ == '__main__':
solve()
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, 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
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
T1, T2 = MAP()
A1, A2 = MAP()
B1, B2 = MAP()
if T1*A1+T2*A2 == T1*B1+T2*B2:
print("infinity")
exit()
if (A1 < B1 and A2 < B2) or (B1 < A1 and B2 < A2):
print(0)
exit()
if A1 > B1:
A1, B1 = B1, A1
A2, B2 = B2, A2
if A1*T1+A2*T2 < B1*T1+B2*T2:
print(0)
exit()
F = A1*T1-B1*T1
L = A2*T2-B2*T2
S, T = divmod(-F, F+L)
if T == 0:
print(2*S)
else:
print(2*S+1)
| 0 | null | 107,842,049,982,492 | 232 | 269 |
H, W = [int(x) for x in input().split()]
if H == 1 or W == 1:
print(1)
else:
print((H * W + 1) // 2)
| N = int(input())
A = list(map(int, input().split()))
if N == 0 and A[0] == 1:
print(1)
exit()
if A[0] != 0:
print(-1)
exit()
sum_leaf = sum(A)
ans = 1
before_top = 1
for i in range(1, len(A)):
if A[i] <= before_top*2:
ans += min(sum_leaf, before_top*2)
before_top = min(sum_leaf, before_top*2) - A[i]
sum_leaf -= A[i]
else:
print(-1)
exit()
print(ans) | 0 | null | 35,021,552,981,348 | 196 | 141 |
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
n, m, k = map(int, input().split())
friends = UnionFind(n)
direct_friends = [0] * n
enemies = [[] for _ in range(n)]
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
direct_friends[a] += 1
direct_friends[b] += 1
friends.union(a, b)
for i in range(k):
c, d = map(int, input().split())
c -= 1
d -= 1
enemies[c].append(d)
enemies[d].append(c)
ans = []
for i in range(n):
num = friends.size(i) - 1 - direct_friends[i]
for enm in enemies[i]:
if friends.same(i, enm):
num -= 1
ans.append(num)
print(*ans)
| n,m,k=map(int,input().split())
par=[i for i in range(n)]
size=[1 for i in range(n)]
def find(x):
if par[x]==x:
return x
else:
par[x]=find(par[x])
return par[x]
def union(a,b):
x=find(a)
y=find(b)
if x!=y:
if size[x]<size[y]:
par[x]=par[y]
size[y]+=size[x]
else:
par[y]=par[x]
size[x]+=size[y]
else:
return
graph=[[] for i in range(n)]
for i in range(m):
a,b=map(int,input().split())
union(a-1,b-1)
graph[a-1].append(b-1)
graph[b-1].append(a-1)
for i in range(k):
a,b=map(int,input().split())
if find(a-1)==find(b-1):
graph[a-1].append(b-1)
graph[b-1].append(a-1)
ans=[]
for i in range(n):
cnt=size[find(i)]
xxx=list(set(graph[i]))
cnt-=len(xxx)
cnt-=1
ans+=[str(cnt)]
print(' '.join(ans)) | 1 | 61,552,650,029,472 | null | 209 | 209 |
n,k=map(int,input().split())
l=list(map(int,input().split()))
maxi=0
suml=sum(l[:k])
maxl=sum(l[:k])
for i in range(n-k):
if suml-l[i]+l[k+i]>maxl:
maxl=suml-l[i]+l[k+i]
maxi=i+1
suml=suml-l[i]+l[k+i]
sumsum=0
for j in range(maxi,maxi+k):
sumsum+=(l[j]+1)/2
print(sumsum) | def main():
n, x, y = map(int, input().split())
ans = [0] * n
for i in range(1,n):
for j in range(i+1, n+1):
r1 = j-i
r2 = abs(x-i) + 1 + abs(j-y)
r3 = abs(y-i) + 1 + abs(j-x)
ans[min(r1,r2,r3)] += 1
for i in range(1,n):
print(ans[i])
if __name__ == "__main__":
main() | 0 | null | 59,492,809,604,648 | 223 | 187 |
N = int(input())
A = sorted(list(map(int,input().split())),reverse=True)
if N%2==0:
cnt = A[0]
for i in range(1,N//2):
cnt += 2*A[i]
print(cnt)
else:
cnt = A[0]
for i in range(1,N//2):
cnt += 2*A[i]
cnt += A[N//2]
print(cnt) | x, y = map(int, input().split())
for i in range(1, x+1):
if (4*i + 2*(x - i) == y) or (2*i + 4*(x - i) == y):
print("Yes")
exit()
print("No") | 0 | null | 11,483,219,613,712 | 111 | 127 |
n = int(raw_input())
x = map(int,raw_input().split())
i = n-1
while i != -1:
print "%d" %x[i] ,
i = i-1 | n = int(raw_input())
num = map(int, raw_input().split())
num.reverse()
print " ".join(map(str, num))
| 1 | 990,603,477,568 | null | 53 | 53 |
print("Yes" if len(set(map(int,input().split())))==1 else "No") | x = input().split()
for i in range(5):
if x[i] == '0':
print(i+1) | 0 | null | 48,698,695,372,320 | 231 | 126 |
s = raw_input().rstrip().split(" ")
a = int(s[0])
b = int(s[1])
c = int(s[2])
if a<b and b<c:print "Yes"
else:print "No" | data = input().split()
print(int(data[0])*int(data[1])) | 0 | null | 8,039,216,957,332 | 39 | 133 |
def max2(x,y):
return x if x > y else y
N = int(input())
D = []
for i, a in enumerate(map(int, input().split())):
D.append((a<<11) + i)
D.sort(reverse=True)
dp = [0]*(N+1)
for i, d in enumerate(D,start=1):
x, a = d%(1<<11),d>>11
for j in reversed(range(0, i+1)):
dp[j] = max2((dp[j-1]+a*(x-(j-1)))*(j-1>=0), (dp[j]+a*(N-(i-j)-x))*(j<=i-1))
print(max(dp)) | N=int(input());A=sorted((int(x),i)for i,x in enumerate(input().split()));t=[0]*N**2
for w in range(N):
a,j=A[w]
for l in range(N-w):
r=l+w;p=a*abs(j-l);t[l*N+r]=max(p+t[(l+1)*N+r],a*abs(j-r)+t[l*N+r-1])if w else p
print(t[N-1]) | 1 | 33,651,406,501,878 | null | 171 | 171 |
def read_a(n, m):
A = []
for _ in range(0, n):
A.append([int(x) for x in input().split()])
return A
def read_b(m):
B = []
for _ in range(0, m):
B.append(int(input()))
return B
def multiply(A, B):
C = []
for a in A:
C.append(sum(map(lambda x, y:x*y, a, B)))
return C
def main():
n, m = [int(x) for x in input().split()]
A = read_a(n, m)
B = read_b(m)
C = multiply(A, B)
print("\n".join([str(x) for x in C]))
if __name__ == '__main__':
main()
| n,m = map(int,input().split())
A = []
B = []
for i in range(n):
tmp = list(map(int,input().split()))
A.append(tmp)
tmp=[]
for i in range(m):
num = int(input())
B.append(num)
for i in range(n):
c = 0
for j in range(m):
c += A[i][j]*B[j]
print(c)
| 1 | 1,159,809,367,772 | null | 56 | 56 |
import sys
input = lambda: sys.stdin.readline().rstrip()
class SegTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.ide_ele = ide_ele
self.segfunc = segfunc
self.num = 2**(n - 1).bit_length()
self.seg = [self.ide_ele] * 2 * self.num
for i in range(n):
self.seg[i + self.num - 1] = init_val[i]
for i in range(self.num - 2, -1, -1):
self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])
def update(self, k, x):
k += self.num - 1
self.seg[k] = x
while k:
k = (k - 1) // 2
self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
def query(self, p, q):
if q <= p:
return self.ide_ele
p += self.num - 1
q += self.num - 2
res = self.ide_ele
while q - p > 1:
if p & 1 == 0:
res = self.segfunc(res, self.seg[p])
if q & 1 == 1:
res = self.segfunc(res, self.seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = self.segfunc(res, self.seg[p])
else:
res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
return res
def solve():
N = int(input())
S = list(input())
Q = int(input())
seg = [[0 for _ in range(N)] for _ in range(26)]
for i in range(N):
al = ord(S[i]) - ord('a')
seg[al][i] = 1
segtree = []
segfunc = lambda a, b: a | b
for i in range(26):
segtree.append(SegTree(seg[i], segfunc, 0))
ans = []
for i in range(Q):
a, b, c = input().split()
a = int(a)
if a == 1:
b = int(b) - 1
ps = S[b]
S[b] = c
segtree[ord(ps) - ord('a')].update(b, 0)
segtree[ord(c) - ord('a')].update(b, 1)
elif a == 2:
b, c = int(b) - 1, int(c)
count = 0
for i in range(26):
count += segtree[i].query(b, c)
ans.append(count)
print('\n'.join(map(str, ans)))
if __name__ == '__main__':
solve()
| import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
N = int(input())
S = list(input())
Q = int(input())
q_list = [list(input().split()) for _ in range(Q)]
bit_tree = [[0] * (N+1) for _ in range(26)]
def BIT_add(i, tree):
while i <= N:
tree[i] += 1
i += i&(-i)
def BIT_sub(i, tree):
while i <= N:
tree[i] -= 1
i += i&(-i)
def BIT_sum(i, tree):
s = 0
while i:
s += tree[i]
i -= i&(-i)
return s
for i in range(N):
x = ord(S[i]) - ord('a')
BIT_add(i + 1, bit_tree[x])
for q in range(Q):
line = q_list[q]
if line[0] == '1':
i, c = line[1:]
i = int(i) - 1
old_c = ord(S[i]) - ord('a')
new_c = ord(c) - ord('a')
BIT_sub(i + 1, bit_tree[old_c])
BIT_add(i + 1, bit_tree[new_c])
S[i] = c
else:
l, r = map(int, line[1:])
now = 0
for i in range(26):
cnt = BIT_sum(r, bit_tree[i]) - BIT_sum(l - 1, bit_tree[i])
if cnt > 0:
now += 1
print(now) | 1 | 62,437,686,216,400 | null | 210 | 210 |
n,k,s=map(int,input().split())
ans=[s]*k
if n-k>0:
ans1=[]
if s==10**9:
ans1=[1]*(n-k)
else:
ans1=[s+1]*(n-k)
ans[len(ans):len(ans)]=ans1
print(' '.join(map(str,ans))) | def modelAnswer(N:int,K:int,S:int) -> None:
ans = "{} ".format(S)*K
if(S == 10**9):
ans += "1 "*(N-K)
else:
ans += "{} ".format(S+1)*(N-K)
print(ans)
def main():
N,K,S = map(int,input().split())
modelAnswer(N,K,S)
if __name__ == '__main__':
main() | 1 | 91,247,537,379,820 | null | 238 | 238 |
class DoublyLinkedList:
def __init__(self):
self.nil = self.make_node(None)
self.nil['next'] = self.nil
self.nil['prev'] = self.nil
def make_node(self, k):
return {'key':k, 'next':None,'prev':None}
def insert(self, key):
x = self.make_node(key)
x['next'] = self.nil['next']
self.nil['next']['prev'] = x
self.nil['next'] = x
x['prev'] = self.nil
def listSearch(self,key):
cur = self.nil['next']
while cur['key'] != None and cur['key'] != key:
cur = cur['next']
return cur
def delete(self, k):
self.delete_node(self.listSearch(k))
def delete_node(self,x):
if x['key'] == None: return
x['prev']['next'] = x['next']
x['next']['prev'] = x['prev']
def deleteFirst(self):
self.delete_node(self.nil['next'])
def deleteLast(self):
self.delete_node(self.nil['prev'])
def printList(self):
x = self.nil['next']
while True:
if x['key'] == None:
break
else:
print x['key'],
x = x['next']
print
def main():
N = int(raw_input())
commands = []
for i in xrange(N):
commands.append(raw_input())
d = DoublyLinkedList()
for c in commands:
a = c[0]
if a == 'i':
d.insert(int(c[7:]))
else:
if c[6] == 'F':
d.deleteFirst()
elif c[6] == 'L':
d.deleteLast()
else:
d.delete(int(c[7:]))
d.printList()
return 0
main() | N1=int(input())
array1=input().split()
N2=int(input())
array2=input().split()
c=0
for n2 in range(N2):
if array2[n2] in array1:
c+=1
print(c)
| 0 | null | 57,043,186,254 | 20 | 22 |
def main():
S = input()
if "7" in S:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| import sys
N = int(input())
strN = str(N)
if not ( 100 <= N <= 999 ): sys.exit()
print('Yes') if '7' in strN else print('No') | 1 | 34,241,328,475,898 | null | 172 | 172 |
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy
def main():
a,b,c = map(int, input().split())
k = int(input())
flag = False
if a < b < c:
print("Yes")
sys.exit()
for i in range(k):
if a < b < c:
c *= 2
if a >= b:
if b >= c:
c *= 2
else:
b *= 2
else:
if b >= c:
c *= 2
else:
b *= 2
if a < b < c:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| A,B,C=map(int,input().split())
K = int(input())
flag = False
cnt = 0
while(A>=B):
if cnt > K :
break
B = 2*B
cnt += 1
while(B>=C):
if cnt >= K:
break
C = 2*C
cnt += 1
#print(A,B,C)
if A < B and B < C:
flag = True
if flag:
print("Yes")
else:
print("No") | 1 | 6,898,920,943,740 | null | 101 | 101 |
k = int(input())
a, b = list(map(int, input().split()))
p = 0
while p <= 1000:
if a <= p <= b:
print("OK")
exit()
p += k
print("NG")
| class DP:
def __init__(self, value, variety, coins):
self.value = value
self.variety = variety
self.coins = coins
self.DP = [[0 for _ in range(value + 1)] for _ in range(variety)]
self.DPinit()
def monitor(self):
for (i, row) in enumerate(self.DP):
print(coins[i], row)
def DPinit(self):
for row in self.DP:
row[1] = 1
self.DP[0] = [i for i in range(self.value + 1)]
def DPcomp(self):
for m in range(self.variety):
if m == 0:
continue
for n in range(self.value + 1):
self.DP[m][n] = self.numberOfCoin(m, n)
def numberOfCoin(self, m, n):
if n >= self.coins[m]:
return min(self.DP[m - 1][n], self.DP[m][n - self.coins[m]] + 1)
else:
return self.DP[m - 1][n]
def answer(self):
self.DPcomp()
return self.DP[self.variety - 1][self.value]
if __name__ == "__main__":
status = list(map(int,input().split()))
coins = list(map(int,input().split()))
dp = DP(status[0],status[1],coins)
print(dp.answer()) | 0 | null | 13,290,475,794,010 | 158 | 28 |
D = int(input())
C = [int(x) for x in input().split()]
S = [[int(i) for i in input().split()] for D in range(D)]
T = [0]*D
for i in range(D):
T[i] = int(input())
score = [0]*26
last = [-1]*26
for i in range(D):
score[T[i]-1] += S[i][T[i]-1]
last[T[i]-1] = i
for j in range(26):
score[j] -= C[j]*(i-last[j])
print(sum(score))
| N = 26
D = int(input())
c_list = list(map(int, input().split()))
s_table = []
for _ in range(D):
s_table.append(list(map(int, input().split())))
data = []
for _ in range(D):
data.append(int(input()) - 1)
def calc(data):
last = [-1] * N
satisfaction = 0
for i in range(D):
j = data[i]
satisfaction += s_table[i][j]
last[j] = i
for k in range(N):
satisfaction -= c_list[k] * (i - last[k])
print(satisfaction)
return satisfaction
calc(data)
| 1 | 9,854,650,068,932 | null | 114 | 114 |
import sys
import math
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def main():
N, X, Y = NMI()
counts = [0] * N
for i in range(1, N):
for j in range(i+1, N+1):
dist = min(abs(j-i), abs(i-X) + 1 + abs(Y-j))
counts[dist] += 1
for d in counts[1:]:
print(d)
if __name__ == "__main__":
main() | n,x,y = map(int, input().split())
g = [0]*(n)
for i in range(1,n+1):
for j in range(1,i):
e = abs(y-i)+1+abs(x-j)
f = i-j
g[min(e,f)]+=1
for i in g[1:]:
print(i) | 1 | 44,312,189,799,722 | null | 187 | 187 |
S = input()
S = str.swapcase(S)
print(S)
| string = input()
for s in string:
if s.isupper():
print(s.lower(), end='')
else:
print(s.upper(), end='')
print('') | 1 | 1,501,686,652,292 | null | 61 | 61 |
n=int(input())
arr = [[False for i in range(13)] for j in range(4)]
for count in range(n):
code = input().split()
if (code[0]=="S"):
arr[0][int(code[1])-1]=True
elif (code[0]=="H"):
arr[1][int(code[1])-1]=True
elif(code[0]=="C"):
arr[2][int(code[1])-1]=True
else:
arr[3][int(code[1])-1]=True
for i in range(4):
if(i==0):
img="S"
elif(i==1):
img="H"
elif(i==2):
img="C"
else:
img="D"
for j in range(13):
if(arr[i][j]==False):
print(img+" "+str(j+1)) | x,y=map(int,input().split())
if (x*2) <= y <= (x*4) and y%2 ==0:
print('Yes')
else:
print('No')
| 0 | null | 7,434,454,563,910 | 54 | 127 |
[r,c] = map(int,raw_input().split())
D = [[0 for i in range(c+1)] for j in range(r+1)]
for y in range(r):
v = map(int,raw_input().split())
for x in range(c):
D[y][x] = v[x]
D[y][c] = D[y][c] + v[x]
D[r][x] = D[r][x] + v[x]
D[r][c] = D[r][c] + v[x]
for y in range(r+1):
s = ''
for x in range(c+1):
if x == 0:
s = str(D[y][x])
else: s = s + ' ' + str(D[y][x])
print s | n, k = map(int, input().split())
p = [0] + list(map(int, input().split()))
c = [0] + list(map(int, input().split()))
ans = - 10 ** 18
for i in range(1, n+1):
base = i
nxt = p[i]
cnt = 0
score = 0
while True:
cnt += 1
if cnt > k:
break
score += c[nxt]
ans = max(ans, score)
#print("i = ", i, "ans = ", ans, "score = ", score)
if nxt == base:
break
nxt = p[nxt]
if cnt >= k:
continue
extra = k - cnt
score_tmp = score
nxt = p[nxt]
nxt_tmp = nxt
for j in range(min(extra, cnt)):
score += c[nxt]
ans = max(ans, score)
#print("ans = ", ans, "score = ", score, "nxt = ", nxt, "c[nxt] = ", c[nxt])
nxt = p[nxt]
#print("score = ", score, "ans = ", ans)
score = score_tmp
nxt = nxt_tmp
a = extra // cnt
if extra % cnt == 0:
a -= 1
score += score * max(a, 0)
ans = max(ans, score)
for j in range(extra - a * cnt):
score += c[nxt]
ans = max(ans, score)
#print("ans = ", ans, "score = ", score, "nxt = ", nxt, "c[nxt] = ", c[nxt])
nxt = p[nxt]
print(ans) | 0 | null | 3,352,322,140,244 | 59 | 93 |
gcd=list(map(int,input().split()))
if gcd[0]<gcd[1]:
gcd[0],gcd[1]=gcd[1],gcd[0]
while gcd[1]>0:
r=gcd[0]%gcd[1]
gcd[0]=gcd[1]
gcd[1]=r
print(gcd[0])
| #coding:UTF-8
def GCD(x,y):
d=0
if x < y:
d=y
y=x
x=d
if y==0:
print(x)
else:
GCD(y,x%y)
if __name__=="__main__":
a=input()
x=int(a.split(" ")[0])
y=int(a.split(" ")[1])
GCD(x,y) | 1 | 8,246,234,240 | null | 11 | 11 |
import sys
N,K = map(int,input().split())
array_hight = list(map(int,input().split()))
if not ( 1 <= N <= 10**5 and 1 <= K <= 500 ): sys.exit()
count = 0
for I in array_hight:
if not ( 1 <= I <= 500): sys.exit()
if I >= K:
count += 1
print(count) | #!/usr/bin/python
# -*- coding: utf-8 -*-
import math
result = 100000
num = int(raw_input())
for i in range(num):
result *= 1.05
result /= 1000
result = math.ceil(result)
result *= 1000
print int(result) | 0 | null | 89,693,362,212,090 | 298 | 6 |
N = int(input())
divisor = [N]
ans = 0
#Nの約数の列挙
for i in range(2,N+1,1):
if i*i < N:
if N % i == 0:
divisor.append(i)
divisor.append(N//i)
elif i*i == N:
divisor.append(i)
else:
break
#N-1の約数の列挙
yakusuuu = [N-1]
for i in range(2,N,1):
if i*i < (N-1):
if (N - 1)% i == 0:
yakusuuu.append(i)
yakusuuu.append((N-1)//i)
elif i*i == (N-1):
yakusuuu.append(i)
else:
break
for i in yakusuuu:
if N % i == 1:
ans += 1
#print(divisor)
#print(yakusuuu)
M = N
for K in divisor:
#print(K)
while M % K == 0:
M = M//K
if M == 1:
ans += 1
else:
M = M % K
if M == 1:
ans += 1
M = N
print(ans) | n = int(input());div=[];ans=[]
for i in range(1,int(n**0.5)+2):
if n%i == 0:
div.append(i);div.append(n//i)
for i in div:
if i == 1:
continue
tmp = n
while tmp % i == 0:
tmp //= i
if tmp % i ==1:
ans.append(i)
n -= 1
for i in range(1,int(n**0.5)+2):
if n%i == 0:
ans.append(i);ans.append(n//i)
print(len(set(ans))-1) | 1 | 41,340,683,529,960 | null | 183 | 183 |
S, T = map(str, input().split())
print('{}{}'.format(T, S)) | s,t = map(str,input().split())
print(t+s) | 1 | 103,436,004,569,870 | null | 248 | 248 |
s = input().strip()
print(s[0:3]) | x,y = map(int, input().split())
ans = 'false'
for i in range(0,x+1):
if y == 2*i + 4*(x-i):
ans = 'true'
break
if ans == 'true':
print('Yes')
else:
print('No') | 0 | null | 14,275,711,488,500 | 130 | 127 |
I=input
r=range
a=[[[0 for i in r(10)]for j in r(3)]for k in r(4)]
for i in r(int(I())):b,f,r,v=map(int,I().split());a[b-1][f-1][r-1]+=v
f=0
for i in a:
if f:print('#'*20)
else:f=1
for j in i:print('',*j) | n = input()
ls = list(n)
wa = 0
for i in range(len(ls)):
wa += int(ls[i])
print('Yes') if wa % 9 == 0 else print('No') | 0 | null | 2,774,880,364,060 | 55 | 87 |
N = int(input())
S = str(input())
alpha = ['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']
answer = ''
for i in range(len(S)):
num = alpha.index(S[i])+N
if num > 25:
num -= 26
answer += alpha[num]
print(answer) | def main():
N = int(input())
S = str(input())
ans = ''
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']
for i in range(len(S)):
c = alphabet.index(S[i]) + N
if c > 25:
c = c - 26
ans = ans + alphabet[c]
print(ans)
main() | 1 | 134,907,918,499,332 | null | 271 | 271 |
import itertools
n = int(input())
a = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))
able = [0] * (max(n * max(a) + 1, 2001))
for item in itertools.product([0, 1], repeat=n):
total = sum([i * j for i, j in zip(a, item)])
able[total] = 1
for m in M:
print('yes' if able[m] else 'no')
| n = int(raw_input())
A = map(int, raw_input().strip().split(' '))
q = int(raw_input())
M = map(int, raw_input().strip().split(' '))
def ans(i, m):
if m == 0:
return 1
if i >= n or m > sum(A):
return 0
res = ans(i + 1, m) or ans(i + 1, m - A[i])
return res
for j in range(0, q):
if ans(0, M[j]):
print "yes"
else:
print"no" | 1 | 99,195,060,800 | null | 25 | 25 |
X, Y = list(map(int, input().split()))
print(X*Y) | N = int(input())
ls = list(map(int,input().split()))
cnt = [0] * (N+1)
for i in range(N-1):
cnt[ls[i]] += 1
for i in range(1,N+1):
print(cnt[i]) | 0 | null | 24,117,405,662,522 | 133 | 169 |
S, T = map(str, input().split())
A, B = map(int, input().split())
U = input()
if U == S:
A -= 1
else:
B -= 1
print(str(A) + ' ' + str(B)) | print(' '.join((lambda x:[str((x[2]-1)) if x[4] == x[0] else str(x[2]),str((x[3]-1)) if x[4] == x[1] else str(x[3])])(input().split()+list(map(int,input().split()))+[input()]))) | 1 | 72,309,418,259,636 | null | 220 | 220 |
n=int(input())
l0=[[] for _ in range(n)]
l1=[[] for _ in range(n)]
for i in range(n):
a=int(input())
for j in range(a):
x,y=map(int,input().split())
if y==0:
l0[i].append(x)
else:
l1[i].append(x)
ans=0
for i in range(2**n):
s0=set()
s1=set()
num=0
num1=[]
num0=[]
for j in range(n):
if (i>>j) & 1:
num1.append(j+1)
for k in range(len(l0[j])):
s0.add(l0[j][k])
for k in range(len(l1[j])):
s1.add(l1[j][k])
else:
num0.append(j+1)
for j in range(len(s1)):
if s1.pop() in num0:
num=1
break
if num==0:
for j in range(len(s0)):
if s0.pop() in num1:
num=1
break
if num==0:
ans=max(ans,len(num1))
print(ans)
| import math
def fact(n):
ans = 1
for i in range(2, n+1):
ans*= i
return ans
def comb(n, c):
return fact(n)//(fact(n-c)*c)
s,w = map(int, input().split())
if(s >w):
print('safe')
else:
print('unsafe')
| 0 | null | 75,063,461,150,832 | 262 | 163 |
def main():
N,K=map(int,input().split())
res=0
MOD=10**9+7
for i in range(K,N+2):
MAX=(N+(N-i+1))*i//2
MIN=(i-1)*i//2
res+=MAX-MIN+1
res%=MOD
print(res%MOD)
if __name__=="__main__":
main() | N, K = map(int, input().split())
MOD = 10 ** 9 + 7
ans = 1
for i in range(K, N + 1):
ans += i * (2 * N - i + 1) // 2 % MOD - i * (i - 1) // 2 % MOD + 1
ans %= MOD
print(ans) | 1 | 33,197,876,098,530 | null | 170 | 170 |
n,m=map(int,input().split())
s=list(map(int,list(input())))
ans=[]
i=n
while i>0:
j=max(0,m-i)
while s[i-(m-j)]!=0:
j+=1
if j==m:
print(-1)
exit(0)
ans.append(m-j)
i-=(m-j)
ans.reverse()
print(' '.join(map(str,ans)))
| N, M = map(int, input().split())
S = input()
index = N
count = 0
history = []
while index > 0:
start = max(0, index - M)
for i, c in enumerate(S[start:index], start=start):
if c == '0':
history.append(index - i)
index = i
count += 1
break
else:
print(-1)
exit()
print(*history[::-1]) | 1 | 139,243,635,784,630 | null | 274 | 274 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.