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 = input()
x = list(n)
length = len(x)
if x[length-1] == "3":
print("bon")
elif x[length-1] == "0" or x[length-1] == "1" or x[length-1] == "6" or x[length-1] =="8":
print("pon")
else:
print("hon") | n = int(input())
s_l = []
h_l = []
c_l = []
d_l = []
for i in range(1, 14):
s_l.append(i)
h_l.append(i)
c_l.append(i)
d_l.append(i)
for i in range(0, n):
mark, num = input().split()
if mark == "S":
s_l.remove(int(num))
if mark == "H":
h_l.remove(int(num))
if mark == "C":
c_l.remove(int(num))
if mark == "D":
d_l.remove(int(num))
for s in s_l:
print("S {}".format(s))
for h in h_l:
print("H {}".format(h))
for c in c_l:
print("C {}".format(c))
for d in d_l:
print("D {}".format(d)) | 0 | null | 10,250,730,395,558 | 142 | 54 |
import sys
uppers = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
lowers = 'abcdefghijklmnopqrstuvwxyz'
s = []
for line in sys.stdin:
s += line
for i in range(26):
print(lowers[i] + ' : ' + str(s.count(uppers[i]) + s.count(lowers[i]))) | #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
return list(map(int,readline().split()))
def readTuples():
return tuple(map(int,readline().split()))
def I():
return int(readline())
n = I()
def yaku(m):
ans = []
i = 1
while i*i <= m:
if m % i == 0:
j = m // i
ans.append(i)
i += 1
ans = sorted(ans)
return ans
a = yaku(n)
#print(a)
ans = float('inf')
for v in a:
ans = min(ans, (v-1)+(n//v)-1)
print(ans)
| 0 | null | 81,697,682,925,170 | 63 | 288 |
beforex_plus_y=[]
beforex_minus_y=[]
for i in range(int(input())):
xy=list(map(int,input().split()))
beforex_plus_y.append(xy[0]+xy[1])
beforex_minus_y.append(xy[0]-xy[1])
print(max(max(beforex_plus_y)-min(beforex_plus_y),max(beforex_minus_y)-min(beforex_minus_y))) | from collections import defaultdict
n, m = map(int, input().split())
ac_dict = defaultdict(int)
wa_dict = defaultdict(int)
ac_p, wa_p = set(), set()
for _ in range(m):
p, s = input().split()
p = int(p)
if s == 'AC':
ac_p.add(p)
ac_dict[p] = 1
elif ac_dict[p] != 1:
wa_p.add(p)
wa_dict[p] += 1
wa = 0
for pi in ac_p:
wa += wa_dict[pi]
print(sum(ac_dict.values()), wa)
| 0 | null | 48,118,252,801,318 | 80 | 240 |
s = input()
t = input()
if (s == t[:-1]) & (len(s) + 1 == len(t)):
print("Yes")
else:
print("No")
| N=int(input())
A=input().split()
S={}
for a in A:
if a in S.keys():
print('NO')
break
S[a]=1
else:
print('YES') | 0 | null | 47,459,798,229,458 | 147 | 222 |
import math
a, b, h, m = map(int, input().split())
ans = math.sqrt(a*a + b*b - 2*a*b*math.cos(math.pi*(h/6 + m/360 - m/30)))
print(ans)
| import math
a,b,h,m=map(int,input().split())
deg_a=6*m
deg_b=30*h+m/2
deg_c=abs((deg_a)-(deg_b))
rad=math.radians(deg_c)
c=a**2+b**2-2*a*b*math.cos(rad)
print(c**0.5)
| 1 | 20,089,698,856,766 | null | 144 | 144 |
import math
x1,y1,x2,y2=map(float,input().split())
print(round(math.sqrt((x1-x2)**2+(y1-y2)**2),7))
| import math
x1, y1, x2, y2 = map(float, raw_input().split())
print math.sqrt(pow(x2-x1,2) + pow(y2-y1,2))
| 1 | 156,405,331,982 | null | 29 | 29 |
while True:
a=input()
b=a.replace("/","//")
if "?" in b:
break
else:
print(eval(b)) | MOD = 998244353
N, M, K = map(int, input().split())
fac = [1] * N
for i in range(1, N):
fac[i] = (fac[i - 1] * i) % MOD
pow_mmm = [1] * N
for i in range(1, N):
pow_mmm[i] = (pow_mmm[i - 1] * (M - 1)) % MOD
ans = 0
for i in range(K + 1):
t = (M * pow_mmm[N - 1 - i]) % MOD
comb = (fac[N - 1] * pow(fac[N - 1 - i], MOD - 2, MOD) * pow(fac[i], MOD - 2, MOD)) % MOD
t = (t * comb) % MOD
ans = (ans + t) % MOD
print(ans) | 0 | null | 11,863,971,609,948 | 47 | 151 |
N, M, X = map(int, input().split())
book = [0] + [list(map(int, input().split())) for _ in range(N)]
ans = N * 10**5 + 1
for i in range(2**N):
read = [0] * (N+1)
rikai = [0] * (M+1)
cost = 0
for j in range(N):
read[j+1] = i%2
i //= 2
for j in range(1, N+1):
if read[j] == 1:
cost += book[j][0]
for k in range(1, M+1):
rikai[k] += book[j][k]
if min(rikai[1:]) >= X:
ans = min(ans, cost)
print(ans if ans != (N * 10**5 + 1) else -1)
| n, m, x = map(int, input().split())
books_info = []
price_info = []
for i in range(n):
c, *a = map(int, input().split())
books_info.append(a)
price_info.append(c)
pattern_list = []
for j in range(2 ** n):
tmp_list = []
for k in range(n):
if ((j >> k) & 1):
tmp_list.append(k)
else:
pass
pattern_list.append(tmp_list)
book_price = 10 ** 5 * 12 + 1
for pattern in pattern_list:
# 全ての参考書を買わない=len(pattern)が0の場合はスキップする
if len(pattern) == 0:
continue
is_ok = False
price = 0
for j in range(m):
m_sum = 0
price_sum = 0
for k in pattern:
m_sum += books_info[k][j]
price_sum += price_info[k]
if m_sum >= x:
is_ok = True
else:
is_ok = False
break
price = price_sum
if is_ok == True:
book_price = min(price, book_price)
else:
pass
print(book_price if book_price != 10 ** 5 * 12 + 1 else -1)
| 1 | 22,360,265,304,192 | null | 149 | 149 |
# your code goes here
#dice2
def np(dl,nu):
l=0
while dl[l]!=nu:
l+=1
return l
def si(n1,n2):
if n1==1:
if n2==2:
return 3
elif n2==3:
return 5
elif n2==4:
return 2
else:
return 4
elif n1==2:
if n2==1:
return 4
elif n2==3:
return 1
elif n2==4:
return 6
else:
return 3
elif n1==3:
if n2==2:
return 6
elif n2==5:
return 1
elif n2==1:
return 2
else:
return 5
elif n1==4:
if n2==1:
return 5
elif n2==2:
return 1
elif n2==5:
return 6
else:
return 2
elif n1==5:
if n2==1:
return 3
elif n2==3:
return 6
elif n2==4:
return 1
else:
return 4
elif n1==6:
if n2==3:
return 2
elif n2==2:
return 4
elif n2==5:
return 3
else:
return 5
D=[int(i) for i in input().split()]
q=int(input())
for i in range(q):
n=[int(i) for i in input().split()]
# print(n)
p=[]
for j in range(2):
p.append(np(D,n[j]))
# print(p)
print(D[si(p[0]+1,p[1]+1)-1]) | A,B=map(int,input().split())
c=-1
for i in range(1,10**5):
if int(i*0.08)==A and int(i*0.1)==B:
c=i
break
print(c) | 0 | null | 28,560,664,537,078 | 34 | 203 |
X = int(input())
year = 1
yokin = 100
while True:
yokin += yokin//100
if yokin >= X:
print(year)
break
year += 1 | x = int(input())
y = 0
z = 100
while z<x:
y+=1
z *= 101
z //= 100
print(y) | 1 | 26,925,181,422,140 | null | 159 | 159 |
a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=10**6
for i in range(m):
x,y,c=map(int,input().split())
ans=min(ans,a[x-1]+b[y-1]-c)
print(min(ans,min(a)+min(b))) | #C
K, N=map(int,input().split())
A=list(map(int,input().split()))
for i in range(N):
A.append(A[i]+K)
Right=[]
for i in range(N):
Right.append(A[N-1+i]-A[i])
print(min(Right)) | 0 | null | 48,584,289,819,650 | 200 | 186 |
a, b, c = map(int, input().split())
d = c - a - b
if d >= 0 and d * d > 4 * a * b:
print("Yes")
else:
print("No")
| r = int(input())
R = int(r*r)
print(R) | 0 | null | 98,642,034,672,642 | 197 | 278 |
n = int(input())
r = [int(input()) for i in range(n)]
start = r[0]
score = r[1] - r[0]
for i in range(1,n):
if r[i] - start > score: score = r[i] - start
if r[i] < start: start = r[i]
print(score) | ri = lambda S: [int(v) for v in S.split()]
N, M = ri(input())
c = 0
c += (M * (M-1)) / 2
c += (N * (N-1)) / 2
print(int(c)) | 0 | null | 22,775,229,625,440 | 13 | 189 |
def chebyshev_0(a, b):
return a - b
def chebyshev_1(a, b):
return a + b
N = int(input())
X = [0] * N
Y = [0] * N
for i in range(N):
X[i], Y[i] = map(int, input().split())
max_0 = - (10 ** 9) - 1
min_0 = 2 * (10 ** 9)
for x, y in zip(X, Y):
if chebyshev_0(x, y) > max_0:
max_0 = chebyshev_0(x, y)
if chebyshev_0(x, y) < min_0:
min_0 = chebyshev_0(x, y)
l0 = abs(max_0 - min_0)
max_1 = - (10 ** 9) - 1
min_1 = 2 * (10 ** 9)
for x, y in zip(X, Y):
if chebyshev_1(x, y) > max_1:
max_1 = chebyshev_1(x, y)
if chebyshev_1(x, y) < min_1:
min_1 = chebyshev_1(x, y)
l1 = abs(max_1 - min_1)
print(max([l0, l1]))
|
N=int(input())
A_list=sorted(list(map(int, input().split())), reverse=True)
ans=1
if 0 in A_list:
print(0)
exit()
else:
for a in A_list:
ans*=a
if ans>1e+18:
print(-1)
exit()
print(ans)
| 0 | null | 9,756,381,835,808 | 80 | 134 |
import itertools
n = int(input())
l = list(map(int, input().split()))
count = 0
ind_list = list(itertools.combinations(range(0,n), 3))
for ind in ind_list:
if (l[ind[0]]+l[ind[1]])>l[ind[2]] and (l[ind[1]]+l[ind[2]])>l[ind[0]] and (l[ind[2]]+l[ind[0]])>l[ind[1]]:
if l[ind[0]]!=l[ind[1]] and l[ind[0]]!=l[ind[2]] and l[ind[1]]!=l[ind[2]]:
count += 1
print(count) | import math
x1,y1,x2,y2=map(float,input().split())
x2=x2-x1
y2=y2-y1
x1,y1=0,0
dis=(x2**2+y2**2)
print(math.sqrt(dis)) | 0 | null | 2,598,018,146,658 | 91 | 29 |
x = input()
ans = 'A' if x in ('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') else 'a'
print(ans) | a = input()
n = ord(a)
if ord('A') <= n <= ord('Z'):
print('A')
else:
print('a')
| 1 | 11,310,906,293,986 | null | 119 | 119 |
K, N = map(int, input().split())
A = list(map(int, input().split()))
A2 = [K+a for a in A]
A3 = A + A2
dist = [0] * N
for i in range(N):
j = i + N - 1
dist[i] = A3[j] - A[i]
print(min(dist))
| K,N = map(int,input().split())
A = list(map(int,input().split()))
B = []
for i in range(N-1):
temp = A[i+1]-A[i]
B.append(temp)
B.append(K-A[-1]+A[0])
B.sort()
#print(B)
ans = K-B[-1]
print(ans)
| 1 | 43,137,061,945,568 | null | 186 | 186 |
diceface = { "TOP":0,"FRONT":1,"RIGHT":2,"LEFT":3,"BACK":4,"BOTTOM":5 }
dice = [ int( i ) for i in raw_input( ).split( " " ) ]
roll = raw_input( )
for i in range( len( roll ) ):
if "E" == roll[i]:
t = dice[ diceface["TOP"] ]
dice[ diceface["TOP"] ] = dice[ diceface["LEFT"] ]
dice[ diceface["LEFT"] ] = dice[ diceface["BOTTOM"] ]
dice[ diceface["BOTTOM"] ] = dice[ diceface["RIGHT"] ]
dice[ diceface["RIGHT"] ] = t
elif "N" == roll[i]:
t = dice[ diceface["TOP"] ]
dice[ diceface["TOP"] ] = dice[ diceface["FRONT"] ]
dice[ diceface["FRONT"] ] = dice[ diceface["BOTTOM"] ]
dice[ diceface["BOTTOM"] ] = dice[ diceface["BACK"] ]
dice[ diceface["BACK"] ] = t
elif "S" == roll[i]:
t = dice[ diceface["TOP"] ]
dice[ diceface["TOP"] ] = dice[ diceface["BACK"] ]
dice[ diceface["BACK"] ] = dice[ diceface["BOTTOM"] ]
dice[ diceface["BOTTOM"] ] = dice[ diceface["FRONT"] ]
dice[ diceface["FRONT"] ] = t
elif "W" == roll[i]:
t = dice[ diceface["TOP"] ]
dice[ diceface["TOP"] ] = dice[ diceface["RIGHT"] ]
dice[ diceface["RIGHT"] ] = dice[ diceface["BOTTOM"] ]
dice[ diceface["BOTTOM"] ] = dice[ diceface["LEFT"] ]
dice[ diceface["LEFT"] ] = t
print( dice[ diceface["TOP"] ] ) | class diceClass:
def __init__(self, valuelist):
self.valuelist = valuelist
self.t = valuelist[0]
self.b = valuelist[5]
self.n = valuelist[4]
self.s = valuelist[1]
self.e = valuelist[2]
self.w = valuelist[3]
def throw(self, direction):
# N,S,W,E
if direction == 'N':
self.t, self.s, self.b, self.n = self.s, self.b, self.n, self.t
elif direction == 'S':
self.t, self.s, self.b, self.n = self.n, self.t, self.s, self.b
elif direction == 'W':
self.t, self.e, self.b, self.w = self.e, self.b, self.w, self.t
elif direction == 'E':
self.t, self.e, self.b, self.w = self.w, self.t, self.e, self.b
arrinput = list(map(int, input().split()))
dirinput = input()
dice = diceClass(arrinput)
for s in dirinput:
dice.throw(s)
print(dice.t)
| 1 | 236,163,693,568 | null | 33 | 33 |
def main():
abcd = [int(_x) for _x in input().split()]
a = abcd[0]
b = abcd[1]
c = abcd[2]
d = abcd[3]
while True:
c = c - b
if c <= 0:
print("Yes")
return
a = a - d
if a <= 0:
print("No")
return
main()
| import math
a, b, c, d = map(int, input().split())
takahashi_attacks = math.ceil(c / b)
aoki_attacks = math.ceil(a / d)
if takahashi_attacks <= aoki_attacks:
print('Yes')
else:
print('No') | 1 | 29,755,853,751,940 | null | 164 | 164 |
N, K = map(int, input().split())
W = [0] * (N + 1)
W[1] = 1
R = []
for i in range(K):
l, r = map(int, input().split())
R.append((l, r))
MOD = 998244353
for i in range(1, N):
for l, r in R:
a = max(i - r, 0)
b = i - l
if b < 0:
continue
W[i + 1] += (W[b + 1] - W[a])
W[i + 1] %= MOD
W[i + 1] += W[i]
print(W[N] - W[N - 1])
| import numpy as np
N,K = list(map(int, input().split()))
LRs = [list(map(int, input().split())) for _ in range(K)]
dp = np.zeros(N+2, dtype = int)
dp[1] = 1
dp[2] = -1
atai = 0
for i in range(1, N+2):
atai += dp[i]
for LR in LRs:
if(i+LR[0] <= N):
dp[i+LR[0]] = (dp[i+LR[0]] + atai) % 998244353
if(i+LR[1] <= N):
dp[i+LR[1]+1] = (dp[i+LR[1]+1] -atai) % 998244353
# print(dp)
#復元
ruisekiwa = [0]
for hoge in dp:
ruisekiwa.append(ruisekiwa[-1]+hoge)
print(ruisekiwa[N+1] % 998244353) | 1 | 2,690,441,020,316 | null | 74 | 74 |
import sys
line = sys.stdin.readline()
output = []
for i in range( len( line )-1 ):
c = ord( line[i] )
if ord( 'a' ) <= c and c <= ord( 'z' ):
c = chr( c ).upper()
elif ord( 'A' ) <= c and c <= ord( 'Z' ):
c = chr( c ).lower()
else:
c = chr( c )
output.append( c )
print( "".join( output ) ) | i = map(str, raw_input())
def check(x):
if x.islower():
return x.upper()
return x.lower()
print ''.join(map(check, i)) | 1 | 1,484,206,417,978 | null | 61 | 61 |
a,b,c,d = map(float,input().split())
print(abs(complex(c-a,d-b))) | a, b, c, d = map(int, input().split())
if d < a:
print(d)
exit()
elif d < a + b:
print(a)
exit()
else:
print(a+(-1)*(d-a-b)) | 0 | null | 11,099,265,606,170 | 29 | 148 |
weatherS = input()
serial = 0
dayBefore = ''
for x in weatherS:
if dayBefore != 'R':
if x == 'R':
serial = 1
else:
if x == 'R':
serial += 1
dayBefore = x
print(serial) | #!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools as fts
import itertools as its
import math
import sys
INF = float('inf')
def solve(S: str):
return sum([S == "RRR", "RR" in S, "R" in S])
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
S = next(tokens) # type: str
print(f'{solve(S)}')
if __name__ == '__main__':
main()
| 1 | 4,876,373,062,702 | null | 90 | 90 |
import sys, math, itertools
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = 10**20
MOD = 998244353
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def factorialMod(n, p):
fact = [0] * (n+1)
fact[0] = fact[1] = 1
factinv = [0] * (n+1)
factinv[0] = factinv[1] = 1
inv = [0] * (n+1)
inv[1] = 1
for i in range(2, n + 1):
fact[i] = (fact[i-1] * i) % p
inv[i] = (-inv[p % i] * (p // i)) % p
factinv[i] = (factinv[i-1] * inv[i]) % p
return fact, factinv
def combMod(n, r, fact, factinv, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
def resolve():
N, M, K = LI()
ans = 0
fact, factinv = factorialMod(N, MOD)
for i in range(K + 1):
ans += combMod(N - 1, i, fact, factinv, MOD) * M * pow(M - 1, N - 1 - i, MOD)
ans %= MOD
print(ans)
if __name__ == '__main__':
resolve()
| array = [[10*[0] for _ in [0]*3] for _ in [0]*4]
n = int(input())
for _ in range(n):
a,b,c,d = map(int,input().split())
array[a-1][b-1][c-1] += d
for i in range(4):
for j in range(3): print('',*array[i][j])
if i<3: print('#'*20)
| 0 | null | 12,032,853,779,252 | 151 | 55 |
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
T = []
for i in range(N):
T.append(A[i]*F[i])
s = -1
l = 10**12
while(l-s > 1):
mid = (l-s)//2 + s
c = 0
for i in range(N):
if T[i] > mid:
if (T[i] - mid) % F[i] == 0:
c += (T[i] - mid) // F[i]
else:
c += (T[i] - mid) // F[i] + 1
if c > K:
s = mid
else:
l = mid
print(l) | import sys
input = sys.stdin.readline
def binary_search_int(ok, ng, test):
"""
:param ok: solve(x) = True を必ず満たす点
:param ng: solve(x) = False を必ず満たす点
"""
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if test(mid):
ok = mid
else:
ng = mid
return ok
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
F = list(map(int, input().split()))
F.sort(reverse=True)
def max2(x,y):
return x if x > y else y
def test(x):
temp = K
for a, f in zip(A, F):
temp -= max2((a - x//f), 0)
if temp < 0:
return False
return True
print(binary_search_int(A[-1]**2 + 100, -1,test))
| 1 | 164,552,292,239,788 | null | 290 | 290 |
s = input()
ans=0
s=s[::-1]
t=1
ketame=0
amari10=1
kosuu=[1]+[0]*2020
for i in s:
ketame=(ketame+(int(i)*amari10)%2019)%2019
amari10*=10
amari10%=2019
kosuu[ketame]+=1
for i in range(len(kosuu)):
if kosuu[i]>0:
ans+=kosuu[i]*(kosuu[i]-1)/2
print(int(ans)) | N,M=map(int,input().split())
sc=[]
for i in range(M):
sc.append(list(map(int,input().split())))
ans=-1
cnt=10**(N-1)
if cnt==1:cnt-=1
while True:
if len(str(cnt))>N:break
if len(str(cnt))!=N:continue
ret=True
for i in range(M):
if str(cnt)[sc[i][0]-1]!=str(sc[i][1]):
ret=False
break
if ret:
ans=cnt
break
cnt+=1
print(ans) | 0 | null | 45,659,734,709,252 | 166 | 208 |
n,x,d = map(int, input().split())
if n%x == 0:
print(n//x*d)
else:
print((n//x+1)*d) | N = int(input())
XY = []
points = []
for i in range(N):
points.append(i)
x, y = list(map(int, input().split()))
XY.append((x, y))
import math
import itertools
count = math.factorial(N)
line = 0
for pp in itertools.permutations(points, N):
i = 0
while i < N - 1:
i1, i2 = pp[i], pp[i + 1]
t = ((XY[i1][0] - XY[i2][0]) ** 2 + (XY[i1][1] - XY[i2][1]) ** 2) ** 0.5
line += t
i += 1
ans = line / count
print(ans)
| 0 | null | 76,044,553,712,252 | 86 | 280 |
while True:
( m, f, r) = [ int(i) for i in input().split()]
if ( m == f == r == -1): break
total = m + f
achieve = ''
if m == -1 or f == -1 or total < 30: achieve = 'F'
elif total < 50 and r < 50: achieve = 'D'
elif total < 65: achieve = 'C'
elif total < 80: achieve = 'B'
else: achieve = 'A'
print(achieve) | def main():
N = int(input())
A = list(map(int,input().split()))
buka_num = [0]*(N+1)
for i in range(N-1):
buka_num[A[i]] += 1
for i in range(1,N+1,1):
print(buka_num[i])
main()
| 0 | null | 16,765,419,892,992 | 57 | 169 |
import sys
def input():
return sys.stdin.readline().strip()
MOD = 10 ** 9 + 7
sys.setrecursionlimit(20000000)
class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10 ** 9 + 7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
if n < r:
return 0
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n + 1):
fac.append(fac[i - 1] * i % self.mod)
facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n + 1)
modinv[1] = 1
for i in range(2, n + 1):
modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod
return modinv
def main():
N, K = map(int, input().split())
answer = 0
if K >= N - 1:
cmb = Combination(2 * N + 1)
answer = cmb(N * 2 - 1, N - 1)
else:
cmb = Combination(N)
for i in range(K + 1):
answer += cmb(N, i) * cmb(N - 1, N - 1 - i)
print(answer % MOD)
if __name__ == "__main__":
main()
| # coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import combinations
def run():
n,k = map(int, input().split())
mod = 10 ** 9 + 7
ret = 0
inv = generate_inv(n, mod)
if k >= n-1:
k = n-1
left = 1
right = 1
ret = 1
for h in range(1, k+1):
right *= (n - h) * inv[h]
right %= mod
left *= (n - h + 1) * inv[h]
left %= mod
ret += right * left
ret %= mod
print(ret)
def generate_inv(n,mod):
"""
逆元行列
n >= 2
"""
ret = [0, 1]
for i in range(2,n+1):
next = -ret[mod%i] * (mod // i)
next %= mod
ret.append(next)
return ret
def comb_mod(n, a, mod):
"""
return: [n, a] % mod
Note: mod must be a prime number
"""
up = 1
down = 1
for i in range(a):
up *= n - i
up %= mod
down *= i + 1
down %= mod
down = pow_mod(down, mod - 2, mod)
return (up * down) % mod
def pow_mod(n, k, mod):
res = 1
while True:
if k // 2 >= 1:
if k % 2 == 1:
res = (res * n) % mod
n = (n ** 2) % mod
k = k // 2
else:
break
return (n * res) % mod
if __name__ == "__main__":
run() | 1 | 66,809,940,563,980 | null | 215 | 215 |
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
h, w, k = list(map(int, readline().split()))
s = [list(str(readline().rstrip().decode('utf-8'))) for _ in range(h)]
cnt = 0
ls = []
lsd = -1
for i in range(h):
if s[i].count("#") != 0:
lsd = i
is_f = True
cnt += 1
for j in range(w):
if s[i][j] == "#":
if is_f:
is_f = False
else:
cnt += 1
s[i][j] = cnt
while ls:
ti = ls.pop()
for j in range(w):
s[ti][j] = s[i][j]
else:
ls.append(i)
if i == h - 1:
while ls:
ti = ls.pop()
for j in range(w):
s[ti][j] = s[lsd][j]
for i in range(len(s)):
print(*s[i])
if __name__ == '__main__':
solve()
| h,w,k=map(int,input().split())
L=[0]*w
f=1
past=0
for i in range(h):
s=list(input())
for j in range(w):
if '#' not in s:
L.append(L[i*w+j])
else:
if s[j]=='.':
L.append(f)
else:
if past==1:
f += 1
else:
past=1
L.append(f)
if j==w-1:
f += 1
past=0
L=L[w:(h+1)*w]
zero=L.count(0)
z=zero//w
for i in range(w):
num=L[zero+i]
for j in range(z):
L[i+j*w]=num
for i in range(h):
ans=L[w*i:w*(i+1)]
ans=[str(x) for x in ans]
print(' '.join(ans)) | 1 | 143,817,005,252,320 | null | 277 | 277 |
ring = raw_input() * 2
word = raw_input()
if ring.find(word) != -1:
print("Yes")
else:
print("No") |
cnt = 0
def insertionSort(A, n, g):
global cnt####スコープ指定
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:##後半の条件が付いていてもiを回すのでソートされる
A[j+g] = A[j]
j = j - g
cnt+=1
A[j+g] = v
def shellSort(A, n):
tmp = 1
G=[]
while tmp<n:
G.append(tmp)
tmp*=3
tmp+=1###なぜ要るのか分からないが
G.reverse()
for i in range(len(G)):
insertionSort(A, n, G[i])
n = int(input())
G1=[]
tmp=1
while tmp<n:
G1.append(tmp)
tmp*=3
tmp += 1
G1.reverse()
A1 =[int(input()) for _ in range(n)]
m = len(G1)
shellSort(A1, n)
print(max(m,1))
if G1:
print(*G1)
else:
print(1)
print(cnt)
for a in A1:
print(a)
| 0 | null | 894,637,580,238 | 64 | 17 |
k= int(input())
s= input()
if len(s)>k:
r=s[:k]+"..."
print(r)
else:
print(s) | import math
r = float(input())
m = r ** 2 * math.pi
l = r * 2 * math.pi
print('{:.6f} {:.6f}'.format(m, l)) | 0 | null | 10,157,055,354,290 | 143 | 46 |
N,K = list(map(int,input().split()))
MOD = 10**9+7
arr = [pow(K//i, N, MOD) for i in range(1,K+1)]
for i in range(K//2,0,-1):
arr[i-1] -= sum(arr[2*i-1:K:i]) % MOD
arr[i-1] %= MOD
arr = [(i+1)*j%MOD for i,j in enumerate(arr)]
print(sum(arr)%MOD) |
import collections,sys
def s():
d = collections.deque()
input()
for e in sys.stdin:
if "i"==e[0]: d.appendleft(e[7:-1])
else:
if " "==e[6]:
m = e[7:0-1]
if m in d: d.remove(m)
elif "i"==e[7]: d.popleft()
else: d.pop()
print(*d)
s()
| 0 | null | 18,566,466,360,320 | 176 | 20 |
n, m = map(int, input().split())
L = list(map(int, input().split()))
a = 0
for i in range(len(L)):
a = a + L[i]
a = a / (4*m)
nL = sorted(L, reverse=True)
if a <= nL[m-1]:
print("Yes")
else:
print("No") | n,m = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort(reverse = True)
s = sum(a)
res = "Yes"
for i in range(m):
if a[i] * 4 * m < s:
res = "No"
print(res) | 1 | 38,891,241,537,758 | null | 179 | 179 |
n,m = list(map(int, input().split()))
graph = [set() for _ in range(n)]
for _ in range(m):
a,b = list(map(int, input().split()))
graph[a-1].add(b-1)
graph[b-1].add(a-1)
stack = []
group = [-1] * n
gid = 0
i = 0
for i in range(n):
if group[i] >= 0:
continue
group[i] = gid
stack.append(i)
while stack:
current = stack.pop()
for neighbor in graph[current]:
if group[neighbor] == -1:
group[neighbor] = gid
stack.append(neighbor)
gid += 1
print(gid-1) | n,m = list(map(int, input().split()))
parent = list(range(n))
def root(x):
if parent[x] == x: return x
rt = root(parent[x])
parent[x] = rt
return rt
def unite(x,y):
x = root(x)
y = root(y)
if x == y: return
parent[y] = x
for _ in range(m):
a,b = list(map(lambda x: int(x)-1, input().split()))
unite(a,b)
for i in range(n):
root(i)
cnt = len(set(parent)) - 1
print(cnt) | 1 | 2,315,277,804,000 | null | 70 | 70 |
while True :
x,op,y = input().split()
x=int(x)
y=int(y)
if op == '?' :
break
elif op == '+' :
print(x+y)
elif op == '-' :
print(x-y)
elif op == '*' :
print(x*y)
else :
print(x//y)
| def az10():
while True:
xs = raw_input().split()
a,op,b = int(xs[0]),xs[1],int(xs[2])
if op == "?" : break
if op == "+" : print (a + b)
if op == "-" : print (a - b)
if op == "*" : print (a * b)
if op == "/" : print (a / b)
az10() | 1 | 682,311,921,630 | null | 47 | 47 |
while 1:
try:
a, b = map(int,raw_input().split())
except EOFError:
break
ac, bc = a, b
while 1:
if a < b:
b = b - a
elif b < a:
a = a - b
elif a == b:
x = [a,ac*bc/a]
print "{:.10g} {:.10g}".format(*x)
break | a,b=map(int,input().split())
if a<b:
ans=str(a)*b
else:
ans=str(b)*a
print(ans) | 0 | null | 42,268,170,215,118 | 5 | 232 |
from collections import Counter
N,*A = map(int, open(0).read().split())
ac = Counter(A)
if len(ac) == N:
print('YES')
else:
print('NO') | def check(seq):
return len(seq) != len(set(seq))
def main():
N = int(input())
A = list(map(int, input().split()))
ans = check(A)
if ans:
print("NO")
else:
print("YES")
main() | 1 | 74,068,533,173,710 | null | 222 | 222 |
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, *D = map(int, read().split())
ans = 0
for i in range(N):
for j in range(i + 1, N):
ans += D[i] * D[j]
print(ans)
return
if __name__ == '__main__':
main()
| print('No') if int(input())%9 else print('Yes') | 0 | null | 86,393,208,219,648 | 292 | 87 |
N, K = list(map(int,input().split()))
def sum_(i, j):
return (a[i] + a[j]) * (j - i + 1) // 2
a = [i for i in range(N + 1)]
ans = 0
for i in range(K, N + 2):
min_ = sum_(0, i - 1)
max_ = sum_(N - i + 1, N)
ans += (max_ - min_ + 1)
ans %= 10 ** 9 + 7
print(ans) | import math
import sys
from functools import reduce
N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
A[i] = A[i] // 2
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
C = lcm_list(A)
B = [0 for _ in range(N)]
for i in range(N):
B[i] = C // A[i]
if B[i] % 2 == 0:
print(0)
sys.exit()
print( (M // C + 1) // 2) | 0 | null | 67,274,114,993,568 | 170 | 247 |
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
N = int(input())
if N % 2 == 0:
print(0.5)
else:
print(1.0-((N-1)//2.0)/N)
| N = int(input())
if N % 2 == 0:
print((N // 2) / N)
else:
print(-(-N // 2) / N)
| 1 | 177,242,932,645,312 | null | 297 | 297 |
n,m = map(int, input().split())
AC = [False]*n
WA = [0]*n
for i in range(m):
p,s = input().split()
p = int(p)-1
if AC[p] == False:
if s == 'WA':
WA[p] += 1
else:
AC[p] = True
wa = 0
for i in range(n):
if AC[i]:
wa += WA[i]
print(AC.count(True),wa)
| from math import ceil
from collections import deque
n,d,a = map(int,input().split())
m = [list(map(int,input().split())) for _ in range(n)]
m.sort()
l = [(x, ceil(h/a)) for x,h in m]
ans = 0
damage = 0
que = deque([])
for x,h in l:
while que and que[0][0] < x:
s,t = que.popleft()
damage -= t
need = max(0, h - damage)
ans += need
damage += need
if need:
que.append((x+2*d, need))
print(ans) | 0 | null | 87,761,767,733,248 | 240 | 230 |
N = int(input())
A = []
for i in range(N+1):
if i % 15 == 0:
pass
elif i % 3 == 0:
pass
elif i % 5 == 0:
pass
else:
A.append(i)
print(sum(A)) | #coding:utf-8
#1_10_B 2015.4.14
import math
a,b,C = list(map(int,input().split()))
rad = math.pi * C / 180
S = a * b * math.sin(rad) / 2
c = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(rad))
L = a + b + c
h = S * 2 / a
print('{:.10f}\n{:.10f}\n{:.10f}'.format(S,L,h)) | 0 | null | 17,688,052,349,152 | 173 | 30 |
def judge(k, N, A):
p = N - 1
t = 0
for i in A:
while p >= 0 and A[p] + i < k:
p -= 1
t += (p + 1)
return t
def main():
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
t = A[0] * 2
b = 0
X = None
while t - b > 1:
m = (t + b)//2
i = judge(m, N, A)
if i == M:
X = m
break
if i > M:
ip = judge(m + 1, N, A)
if ip == M:
X = m + 1
break
if ip < M:
X = m
break
b = m + 1
if i < M:
im = judge(m - 1, N, A)
if im >= M:
X = m - 1
break
t = m - 1
if X is None:
X = b
r = 0
p = N - 1
k = sum(A)
for i in A:
while p >= 0 and A[p] + i < X :
k -= A[p]
p -= 1
r += i * (p + 1) + k
return r - (judge(X, N, A) - M) * X
print(main())
| from bisect import bisect_left
import numpy
def main():
def isOK(score):
count = 0
for a in reversed(A):
border_score = score - a
index = bleft(A, border_score)
count += N - index
if count >= M:
return True
return False
N, M = map(int, input().split())
A = sorted(map(int, input().split()))
ans = 0
ng = A[-1] + A[-1] + 1
ok = A[0] + A[0]
bleft = bisect_left
while(abs(ok-ng) > 1):
#print(ok, ng)
mid = (ok+ng) // 2
f = isOK(mid)
if f:
ok = mid
else:
ng = mid
#print(f)
#print(ok, ng)
C = [0,] + A
C = numpy.cumsum(C[::-1])
#print(C)
min_score = float('inf')
count = 0
for a in reversed(A):
index = bleft(A, ok-a)
if index < N:
min_score = min(a+A[index], min_score)
ans += C[N-index-1] + (N-index) * a
count += N-index
ans -= min_score * (count-M)
print(ans)
if __name__ == '__main__':
main()
| 1 | 107,647,810,420,602 | null | 252 | 252 |
def func(N):
strN = str(N)
sum = 0
for s in strN:
sum += int(s)
return "Yes" if sum % 9 == 0 else "No"
if __name__ == "__main__":
N = str(input())
print(func(N)) | N, K, S = map(int,input().split())
L = [S]*K
for i in range(N-K):
if S < 10**9:
L.append(S+1)
else:
L.append(1)
print(' '.join(map(str, L))) | 0 | null | 47,573,307,122,062 | 87 | 238 |
A, B, C, D = map(int, input().split())
while True:
C -= B
if C <= 0: break
A -= D
if A <= 0: break
if C <= 0: print('Yes')
elif A <= 0: print('No') | import math
A,B,H,M = map(int,input().split())
x = abs((60*H+M)*0.5 - M*6)
theta = math.radians(x)
L = (A**2+B**2-2*A*B*math.cos(theta))**(1/2)
print(L) | 0 | null | 24,986,844,316,632 | 164 | 144 |
import math
R=int(input())
ensyu=2*math.pi*R
print(ensyu) | x, y = map(int, input().split())
while x != 0 or y != 0:
if x < y:
print(x, y)
else:
print(y, x)
x, y = map(int, input().split()) | 0 | null | 15,967,029,227,460 | 167 | 43 |
N = int(input())
S_list = []
for _ in range(N):
S_list.append(input().strip())
data = []
for s in S_list:
bottom = 0
height = 0
for c in s:
if c == ")":
height -= 1
if bottom > height:
bottom = height
else:
height += 1
if height == 0:
k1 = 1
k2 = 0
elif height > 0:
k1 = 0
k2 = -bottom
else:
k1 = 2
k2 = bottom - height
data.append((k1, k2, bottom, height, s))
data.sort()
def check():
height = 0
for k1, k2, b, h, s in data:
# print(height, b, h, s)
if height + b < 0:
return False
height += h
return height == 0
if check():
print("Yes")
else:
print("No")
| N = int(input())
s = []
for i in range(N):
s.append(input())
inc = []
dec = []
total = 0
for i in s:
cn = 0
mn = 0
for j in i:
if j=="(":
cn+=1
else:
cn-=1
mn = min(cn,mn)
total += cn
if cn>=0:
inc.append([mn,cn])
else:
dec.append([mn-cn,-cn])
inc.sort(reverse=True,key=lambda x:x[0])
dec.sort(reverse=True,key=lambda x:x[0])
def check(lis):
hi = 0
for i in lis:
if hi+i[0]<0:
return False
else:
hi+=i[1]
return True
if check(inc) and check(dec) and total==0:
print("Yes")
else:
print("No")
| 1 | 23,748,446,839,040 | null | 152 | 152 |
from collections import deque
K = int(input())
q = [1, 2, 3, 4, 5, 6, 7, 8, 9]
q = deque(q)
def next_n(n):
if n == 0:
return [0, 1]
elif n == 9:
return [8, 9]
else:
return [n-1, n, n+1]
for _ in range(K-1):
now = q.popleft()
for next_ in next_n(now%10):
q.append(now*10 + next_)
print(q[0]) | import sys
from collections import deque
input = sys.stdin.readline
n=int(input())
L=deque([i for i in range(1,10)])
if n<=9:
ans = L[n-1]
else:
cnt = 9
for i in range(1,n):
c=L.popleft()
if c%10!=0:
L.append(c*10+(c%10)-1)
cnt+=1
if cnt>=n:
break
L.append(c*10+(c%10))
cnt+=1
if cnt>=n:
break
if c%10!=9:
L.append(c*10+(c%10)+1)
cnt+=1
if cnt>=n:
break
ans = L[-1]
print(ans)
| 1 | 39,891,132,922,450 | null | 181 | 181 |
h1,m1,h2,m2,k=map(int,input().split())
x1 = h1 * 60 + m1
x2 = h2 * 60 + m2
print(x2 - x1 - k)
| h1,m1,h2,m2, k = [int(i) for i in input().split()]
time = abs(h2-h1)*60 + m2 -m1
print(time - k)
| 1 | 18,094,169,096,708 | null | 139 | 139 |
from random import *
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
X=[0]*26
XX=X[:]
Y=X[:]
YY=X[:]
P=[]
SC=0
N,M,L,O=0,0,0,0
for i in range(D):
for j in range(26):
X[j]+=C[j]
XX[j]+=X[j]
N,M=-1,-10**20
L,O=N,M
for j in range(26):
if Y==-1:
N,M=0,X[0]+S[i][0]
if M<X[j]+S[i][j]:
L,O=N,M
N,M=j,X[j]+S[i][j]
elif O<X[j]+S[i][j]:
L,O=j,X[j]+S[i][j]
XX[N]-=X[N]
X[N]=0
P.append([N,L])
SC+=X[N]
SC2=0
for i in range(10**5):
SC2=SC
d,q=randrange(0,D),randrange(0,26)
SC2-=S[d][P[d][0]]
SC2+=S[d][q]
for j in range(26):
Y[j]=0
YY[P[d][0]],YY[q]=0,0
for j in range(D):
if j==d:
Z=q
else:
Z=P[j][0]
Y[P[d][0]]+=C[P[d][0]]
Y[q]+=C[q]
Y[Z]=0
YY[P[d][0]]+=Y[P[d][0]]
YY[q]+=Y[q]
if SC2-sum(YY)>=SC-sum(XX) or randrange(0,1000)==0:
P[d][0]=q
XX=YY[:]
SC=SC2
for d in range(D):
for q in range(26):
SC2=SC
SC2-=S[d][P[d][0]]
SC2+=S[d][q]
for j in range(26):
Y[j]=0
YY[P[d][0]],YY[q]=0,0
for j in range(D):
if j==d:
Z=q
else:
Z=P[j][0]
Y[P[d][0]]+=C[P[d][0]]
Y[q]+=C[q]
Y[Z]=0
YY[P[d][0]]+=Y[P[d][0]]
YY[q]+=Y[q]
if SC2-sum(YY)>=SC-sum(XX):
P[d][0]=q
XX=YY[:]
SC=SC2
for i in range(D):
SC2=SC
d,q=i,P[i][1]
SC2-=S[d][P[d][0]]
SC2+=S[d][q]
for j in range(26):
Y[j]=0
YY[P[d][0]],YY[q]=0,0
for j in range(D):
if j==d:
Z=q
else:
Z=P[j][0]
Y[P[d][0]]+=C[P[d][0]]
Y[q]+=C[q]
Y[Z]=0
YY[P[d][0]]+=Y[P[d][0]]
YY[q]+=Y[q]
if SC2-sum(YY)>=SC-sum(XX):
P[d]=P[d][::-1]
XX=YY[:]
SC=SC2
for i in range(D):
print(P[i][0]+1) | r=input().split()
N=int(r[0])
K=int(r[1])
d=[int(s) for s in input().split()]
ans=0
for i in range(N):
if d[i]>=K:
ans+=1
print(ans) | 0 | null | 94,394,354,865,172 | 113 | 298 |
a=input()
b=a.split(" ")
c=list(map(int,b))
w=c[0]
h=c[1]
x=c[2]
y=c[3]
r=c[4]
if((x-r)<0 or (x+r)>w or (y-r)<0 or (y+r)>h):
str="No"
else :
str="Yes"
print(str) | def gcd(a,b):
if b==0:
return a
else:
return gcd(b,a%b)
mod=1000000007
n=input();
arr = list(map(int, raw_input().split()))
l=arr[0];
for i in arr:
x=gcd(l,i)
l=(l*i)/x
ans=0
#print l
for i in arr:
b=l/i
ans+=b
ans=(ans%mod +mod)%mod
print ans
| 0 | null | 44,176,442,986,202 | 41 | 235 |
import sys
from collections import defaultdict
input = sys.stdin.readline
mod = 998244353
def extgcd(a,b):
r = [1,0,a]
w = [0,1,b]
while w[2] != 1:
q = r[2]//w[2]
r2 = w
w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
r = r2
w = w2
return [w[0],w[1]]
def mod_inv(a,m):
x = extgcd(a,m)[0]
return ( m + x%m ) % m
def main():
n,s = map(int,input().split())
a = list(map(int, input().split()))
dp = [[0 for _ in range(s+1)] for _ in range(n+1)]
dp[0][0] = pow(2,n,mod)
MODINV2 = mod_inv(2,mod)
ans = 0
for i in range(n):
for j in range(s,-1,-1):
if j-a[i] < 0:
continue
dp[i+1][j] += dp[i][j-a[i]]*MODINV2
dp[i+1][j] %= mod
for j in range(s,-1,-1):
if j == s:
ans += dp[i+1][j]
ans %= mod
else:
dp[i+1][j] += dp[i][j]
dp[i+1][j] %= mod
print(ans)
if __name__ == "__main__":
main() | n, s = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
dp = [[0] * (s+1) for i in range(n+1)]
dp[0][0] = 1
for i in range(n):
a = A[i]
for j in range(s+1):
if j < s:
dp[i+1][j] = (dp[i+1][j] + 2*dp[i][j])%mod
if j+a<s+1:
dp[i+1][j+a] = (dp[i+1][j+a] + dp[i][j])%mod
ans = 0
for i in range(1, n+1):
ans = (ans + dp[i][s] * pow(2, n-i, mod)) % mod
print(ans)
| 1 | 17,594,643,401,294 | null | 138 | 138 |
def resolve():
a = int(input())
print(a + a ** 2 + a ** 3)
resolve() | N,M = (int(x) for x in input().split())
if N == M:
print('Yes')
else:
print('No') | 0 | null | 46,996,775,862,468 | 115 | 231 |
### -*- coding: utf-8 -*-
prev = input().split()[0]
next = input().split()[0]
if prev != next:
print("1")
else:
print("0") | import numpy as np
import sys
input = sys.stdin.readline
def main():
n, s = map(int, input().split())
A = np.array([int(i) for i in input().split()])
MOD = 998244353
dp = np.zeros(s + 1, dtype="int32")
dp[0] = 1
for i in range(n):
p = (dp * 2) % MOD
p %= MOD
p[A[i]:] += dp[:-A[i]]
dp = p % MOD
print(dp[s])
if __name__ == '__main__':
main() | 0 | null | 71,248,224,147,040 | 264 | 138 |
n, m = map(int,input().split())
nx = int(n * ( n - 1) / 2)
mx = int(m * (m -1) / 2)
print(nx + mx) | import math
r = float(raw_input())
print ('%.6f' % (r*r*math.pi)),
print ('%.6f' % (r*2*math.pi)) | 0 | null | 23,033,273,925,728 | 189 | 46 |
N=int(input())
res=[1000000000000]
for i in range(1,int(N**0.5)+1):
if(N%i==0):
res.append(i+N//i-2)
print(min(res)) | n,q=map(int,input().split())
Q=[]
sum=0
for i in range(n):
tmp=input().split()
tmp[1]=int(tmp[1])
Q.append(tmp[0])
Q.append(tmp[1])
loop=0
while loop==0:
for i in range(len(Q)//2):
tmp=[Q[0],Q[1]]
if tmp[1]>q:
sum+=q
Q.append(tmp[0])
Q.append(tmp[1]-q)
else:
sum+=tmp[1]
print(tmp[0],sum)
Q.pop(0)
Q.pop(0)
if len(Q)==0:
break
| 0 | null | 80,676,281,151,530 | 288 | 19 |
N, K = map(int, input().split())
n = N%K
m = K - n
print(min(abs(n), abs(m))) | n, k = [int(i) for i in input().split()]
ans = min((n % k), (k - n % k))
print(ans) | 1 | 39,267,735,067,440 | null | 180 | 180 |
sum = 0
for s in input():
sum += int(s)
print('Yes' if sum%9==0 else 'No') | n = [int(x) for x in input()]
s = sum(n)
if s % 9 == 0:
print('Yes')
else:
print('No') | 1 | 4,434,174,868,398 | null | 87 | 87 |
from collections import defaultdict
import math
def P(n, r):
return math.factorial(n)//math.factorial(n-r)
def C(n, r):
return P(n, r)//math.factorial(r)
S = input()[::-1]
N = len(S)
cnt = [0]*N
tmp = 0
d = defaultdict(int)
d[0] += 1
for i in range(N):
tmp += int(S[i])*pow(10,i,2019)
tmp %= 2019
d[tmp] += 1
ans = 0
for v in d.values():
if v >= 2:
ans += C(v,2)
print(ans) | # -*- coding: utf-8 -*-
while True:
score = list(map(int, input().split()))
if score[0] == -1 and score[1] == -1 and score[2] == -1:
break
elif -1 in (score[0], score[1]) or (score[0] + score[1]) < 30:
print('F')
elif (score[0] + score[1]) >= 80:
print('A')
elif 65 <= (score[0] + score[1]) < 80:
print('B')
elif 50 <= (score[0] + score[1]) < 65 or (30 <= (score[0] + score[1]) < 50 <= score[2]):
print('C')
elif 30 <= (score[0] + score[1]) < 50:
print('D')
| 0 | null | 16,049,162,962,020 | 166 | 57 |
def run(s):
'''
'''
print('{}{}'.format(s, 'es' if s[-1] == 's' else 's'))
if __name__ == '__main__':
s = input()
run(s) | string = input()
if string[len(string)-1] == "s":
print(string+'es')
else:
print(string+'s')
| 1 | 2,420,332,498,412 | null | 71 | 71 |
A, B, K = map(int, input().split())
i = 0
if A <= K:
K = K - A
A = 0
if A > K:
A = A - K
K = 0
if B <= K and A == 0:
K = K - B
B = 0
if B >= K and A == 0:
B = B - K
K = 0
print(A)
print(B) | import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
A, B, K = map(int, readline().split())
if A >= K:
A -= K
else:
K -= A
A = 0
B = max(0, B - K)
print(A, B)
if __name__ == '__main__':
main()
| 1 | 104,007,716,885,580 | null | 249 | 249 |
n, k, s = map(int, input().split())
A = [0] * n
if s == 10 ** 9:
for i in range(k):
A[i] = 10 ** 9
for i in range(k, n):
A[i] = 1
else:
for i in range(k):
A[i] = s
for i in range(k, n):
A[i] = s + 1
print(*A) | def resolve():
A, B, H, M = list(map(int, input().split()))
ath = ((H*60+M)/(12*60))*360
bth = M/60*360
diff = abs(ath - bth) if abs(ath - bth) < 180 else 360-abs(ath - bth)
import math
print(math.sqrt((A**2)+(B**2)-2*A*B*math.cos(2*math.pi*diff/360)))
if '__main__' == __name__:
resolve() | 0 | null | 55,707,360,897,284 | 238 | 144 |
n = int(input())
a = list(map(int,input().split()))
t=0
for i in a:
t = t ^ i
ans = []
for i in a:
ans.append(t ^ i)
print(" ".join(str(i) for i in ans)) | N = int(input())
def sum(n):
return (n + 1) * n // 2
print(sum(N) - sum(N // 3) * 3 - sum(N // 5) * 5 + sum(N // 15) * 15)
| 0 | null | 23,547,941,111,832 | 123 | 173 |
ary = list(filter(lambda x: int(x) % 3 != 0 and int(x) % 5 != 0, list(range(int(input()) + 1))))
print(sum(ary)) | from collections import defaultdict
facts = defaultdict(int)
mod=10**9+7
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
n=int(input())
a=[int(i) for i in input().split()]
for i in range(n):
for b,p in factorization(a[i]):
if facts[b]<p:
facts[b]=p
ans=0
f=1
for k,v in facts.items():
f*=pow(k,v,mod)
f%=mod
for i in range(n):
ans+=f*pow(a[i],mod-2,mod)
ans%=mod
print(ans) | 0 | null | 61,397,396,628,740 | 173 | 235 |
from math import pi
r = float(input())
print('{:.5f} {:.5f}'.format(r*r*pi,r*2*pi)) | r=input();p=3.141592653589;print "%.9f"%(p*r*r),r*2*p | 1 | 632,514,423,420 | null | 46 | 46 |
n=int(input())
lipp = []
lipm = []
limm = []
allcnt = 0
for _ in range(n):
s = input()
cnt = 0
mi = 0
for x in s:
cnt += 1 if x == '(' else -1
mi = min(mi,cnt)
if cnt >= 0:
lipm.append([mi,cnt])
else:
limm.append([mi - cnt, -cnt])
allcnt += cnt
if allcnt != 0:
print('No')
exit()
lipm.sort(reverse = True)
limm.sort(reverse = True)
def solve(l):
now = 0
for mi, cnt in l:
if mi + now < 0:
print('No')
exit()
now += cnt
solve(lipm)
solve(limm)
print("Yes") | from itertools import accumulate,chain
n,*s=open(0).read().split()
t=[2*i.count("(")-len(i) for i in s]
st=[[min(accumulate(s_,lambda a,b: a+(1 if b=="(" else -1),initial=0)),t_] for s_,t_ in zip(s,t)]
now=0
for c,d in chain(sorted([x for x in st if x[1]>=0])[::-1],sorted([x for x in st if x[1]<0],key=lambda z:z[1]-z[0])[::-1]):
if now+c<0:
print("No");break
now+=d
else:
print("No" if now else "Yes") | 1 | 23,746,857,410,004 | null | 152 | 152 |
n = int(input())
l = list(map(int, input().split()))
ans=0
for i in range(n):
for j in range(i+1,n):
for k in range(j+1,n):
li = [l[i], l[j], l[k]]
m = max(li)
if 2*m < sum(li) and len(set(li)) == 3:
ans += 1
print(ans) | from itertools import combinations as comb
N = int(input())
L = list(map(int,input().split()))
count = 0
for a, b, c in comb(L, 3):
if a != b and b != c and c != a and a + b > c and b + c > a and c + a > b:
count += 1
print(count) | 1 | 5,042,406,572,480 | null | 91 | 91 |
H = int(input())
i=0
count=0
while(H>0):
H=H//2
count += 2**i
i+=1
print(count) | def resolve():
H = int(input())
ans = 1
while H > 0:
ans *= 2
H //= 2
print(ans - 1)
resolve()
| 1 | 80,143,933,228,760 | null | 228 | 228 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import combinations_with_replacement
def main():
n, m, q = map(int, input().split())
qs = []
for _ in range(q):
abcd = tuple(map(int, input().split()))
qs.append(abcd)
A = tuple(combinations_with_replacement(range(1, m+1), n))
r = 0
for Ae in A:
t0 = 0
for qe in qs:
if Ae[qe[1]-1] - Ae[qe[0]-1] == qe[2]:
t0 += qe[3]
r = max(r, t0)
print(r)
if __name__ == '__main__':
main()
| import itertools
n,m,q=map(int,input().split())
a=[]
b=[]
c=[]
d=[]
for i in range(q):
a1,b1,c1,d1=map(int,input().split())
a.append(a1)
b.append(b1)
c.append(c1)
d.append(d1)
l=list(range(1,m+1))
ans=0
for A in list(itertools.combinations_with_replacement(l, n)):
sum=0
for i in range(q):
if A[b[i]-1]-A[a[i]-1]==c[i]:
sum+=d[i]
ans=max(ans,sum)
print(ans)
| 1 | 27,699,893,203,740 | null | 160 | 160 |
while 1:
H, W = map(int, raw_input().split())
if H == W == 0:
break
for i in range(H):
if i % 2 == 0:
if W % 2 == 0:
print "#." * (W/2)
else:
print "#." * (W/2) + "#"
else:
if W % 2 == 0:
print ".#" * (W/2)
else:
print ".#" * (W/2) + "."
print "" | N = int(input())
S = list(input())
L = [chr(ord("A")+i) for i in range(26)]
X = ""
for i in S:
a = L.index(i) + N
if a >= 26:
a = a - 26
X += L[a]
else:
X += L[a]
print(X)
| 0 | null | 67,989,950,994,330 | 51 | 271 |
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
def S():
return input().rstrip()
def I():
return int(input())
def MI():
return map(int, input().split())
n, k = MI()
p = list(MI())
c = list(MI())
p.insert(0, 0)
c.insert(0, 0)
ans = -float("INF")
for i in range(1, n + 1):
next = p[i]
score = 0
MAX = -float("INF")
for j in range(1, k + 1):
score += c[next]
MAX = max(MAX, score)
if next == i:
loop_score = score
loop_size = j
if loop_score > 0:
q, r = divmod(k, loop_size)
# 周れるだけ周る-1+余りの回数で最大となるマス動く
score1 = loop_score * (q - 1) + MAX
# 周れるだけ周る+余りの回数で最大となるマス動くとき
score2 = loop_score * q
MAX = score2
next = p[i]
for _ in range(1, r + 1):
score2 += c[next]
MAX = max(MAX, score2)
next = p[next]
score = max(score1, MAX)
break
else:
# 一周未満
score = MAX
break
else:
next = p[next]
else:
score = MAX
ans = max(ans, score)
print(int(ans))
| def yumiri(L, n):
for i in range(len(L)):
if L[i] > n:
return i - 1
def parunyasu(a, b, p, q, T):
reans = ans
rd1, rq1, d1, nd1, nq1, q1, newans = naobou(a, q, reans)
rd2, rq2, d2, nd2, nq2, q2, newans = naobou(b, p, newans)
Flag = False
if reans <= newans:
Flag = True
else:
k = pow(2.71, (newans - reans) / T)
if random.random() < k:
Flag = True
if Flag:
t[d1 - 1] = q1
t[d2 - 1] = q2
return newans
else:
ayaneru(rd2, rq2, d2, nd2, nq2)
ayaneru(rd1, rq1, d1, nd1, nq1)
return reans
def ayaneru(rd, rq, d, nd, nq):
ZL[rd].insert(rq, d)
del ZL[nd][nq + 1]
def gaochan(d, q, T):
reans = ans
rd1, rq1, d1, nd1, nq1, q1, newans = naobou(d, q, ans)
Flag = False
if reans <= newans:
Flag = True
else:
k = pow(2.71, (newans - reans) / T)
if random.random() < k:
Flag = True
if Flag:
t[d1 - 1] = q1
return newans
else:
ayaneru(rd1, rq1, d1, nd1, nq1)
return reans
def naobou(d, q, ans):
newans = ans
rd = t[d - 1] - 1
rq = yumiri(ZL[rd], d)
newans += SUMD[ZL[rd][rq] - ZL[rd][rq - 1] - 1] * c[rd]
newans += SUMD[ZL[rd][rq + 1] - ZL[rd][rq] - 1] * c[rd]
newans -= SUMD[ZL[rd][rq + 1] - ZL[rd][rq - 1] - 1] * c[rd]
del ZL[rd][rq]
nd = q - 1
nq = yumiri(ZL[nd], d)
newans += SUMD[ZL[nd][nq + 1] - ZL[nd][nq] - 1] * c[nd]
newans -= SUMD[d - ZL[nd][nq] - 1] * c[nd]
newans -= SUMD[ZL[nd][nq + 1] - d - 1] * c[nd]
ZL[nd].insert(nq + 1, d)
newans -= s[d - 1][rd]
newans += s[d - 1][nd]
return rd, rq, d, nd, nq, q, newans
def rieshon():
ans = 0
for i in range(D):
ans += s[i][t[i] - 1]
for j in range(26):
if t[i] - 1 == j:
L[j] = 0
ZL[j].append(i + 1)
else:
L[j] += 1
ans -= L[j] * c[j]
for i in range(26):
ZL[i].append(D + 1)
return ans
import time
import random
startTime = time.time()
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
L = [0] * 26
ZL = [[0] for _ in range(26)]
SUMD = [0] * (D + 1)
for i in range(1, D + 1):
SUMD[i] = SUMD[i - 1] + i
RD = [0] * 26
t = [0] * D
for i in range(D):
RD[0] += 1
ma = s[i][0] + RD[0] * c[0]
man = 0
for j in range(1, 26):
RD[j] += 1
k = s[i][j] + RD[j] * c[j]
if k > ma:
ma = k
man = j
t[i] = man + 1
RD[man] = 0
ans = rieshon()
cnt = 0
T0 = 2000
T1 = 60
tt = 0
T = T0
TL = 1.8
while tt < 1:
n = random.randrange(3)
if n == 1:
d = random.randrange(D) + 1
q = random.randrange(26) + 1
if t[d - 1] == q: continue
ans = gaochan(d, q, T)
else:
l = random.randrange(min(D - 1, 13)) + 1
d = random.randrange(D - l) + 1
p = t[d - 1]
q = t[d + l - 1]
if p == q: continue
ans = parunyasu(d, d + l, p, q, T)
cnt += 1
if cnt >= 100:
tt = (time.time() - startTime) / TL
T = pow(T0, 1 - tt) * pow(T1, tt)
cnt = 0
for i in range(D):
print(t[i])
| 0 | null | 7,464,781,716,358 | 93 | 113 |
a, b = map(int, raw_input().split())
print "%d %d %.6f"%(a/b, a%b, a*1.0/b) | a, b = map(int, input().split())
print("{:d} {:d} {:f}".format(a//b, a%b, a/b)) | 1 | 596,535,653,418 | null | 45 | 45 |
x1, y1, x2, y2 = map(float, input().split())
x = abs(x2 - x1)
y = abs(y2 - y1)
dis = (x ** 2 + y ** 2) ** (1 / 2)
dis = round(dis, 8)
print("{}" .format(dis))
| P = [1 for _ in range(10**6)]
P[0]=0
P[1]=0
for i in range(2,10**3):
for j in range(i*i,10**6,i):
P[j] = 0
Q = []
for i in range(10**6):
if P[i]==1:
Q.append(i)
N = int(input())
C = {}
for q in Q:
if N%q==0:
cnt = 0
while N%q==0:
N = N//q
cnt += 1
C[q] = cnt
if N>1:
C[N] = 1
cnt = 0
for q in C:
n = C[q]
k = 1
while n>=(k*(k+1))//2:
k += 1
cnt += k-1
print(cnt) | 0 | null | 8,472,542,064,100 | 29 | 136 |
import numpy as np
last=[0]*26
D=int(input())
c=list(map(int, (input().split(' '))))
s=[]
a=[0]*D
sat=0
for i in range(D):
s.append(list(map(int, (input().split(' ')))))
for i in range(D):
a[i]=int(input())
last[a[i]-1] = i+1
sat += s[i][a[i]-1] - np.dot(c, list(map(lambda x: i+1-x, last)))
print(sat) |
import copy
import sys
# 再帰上限を引き上げる
sys.setrecursionlimit(10**6)
def dfs(graph, v, d):
seen[v] = True # 訪問済みかどうか
dist[v] = d # 距離を記録
# 頂点vから行ける頂点を全探索
for i in graph[v]:
if seen[i]:
continue
dfs(graph, i, d+1)
# ここから本文
N, u, v = map(int, input().split())
u -= 1
v -= 1
# グラフ構造を作る
graph = [[] for i in range(N)]
for i in range(N - 1):
A, B = map(int, input().split())
A -= 1
B -= 1
graph[A].append(B)
graph[B].append(A)
# 青木くんからの各頂点の距離
seen = [False for i in range(N)]
dist = [0 for i in range(N)]
dfs(graph, v, 0)
aoki_dist = copy.deepcopy(dist)
# 高橋くんからの各頂点の距離
seen = [False for i in range(N)]
dist = [0 for i in range(N)]
dfs(graph, u, 0)
takahashi_dist = copy.deepcopy(dist)
ans = 0
for i in range(N):
if aoki_dist[i] > takahashi_dist[i]:
if aoki_dist[i] - 1 > ans:
ans = aoki_dist[i] - 1
print(ans) | 0 | null | 63,418,987,706,202 | 114 | 259 |
x,n=map(int,input().split())
*p,=map(int,input().split())
q=[0]*(102)
for pp in p:
q[pp]=1
diff=1000
ans=-1
for i in range(0,102):
if q[i]:
continue
cdiff=abs(i-x)
if cdiff<diff:
diff=cdiff
ans=i
print(ans) | X, N = map(int, input().split())
P = list(map(int, input().split()))
st = set(P)
ans = 111
for i in range(111):
if i in st:
continue
if abs(ans - X) > abs(i - X):
ans = i
print(ans)
| 1 | 14,094,547,796,768 | null | 128 | 128 |
while True:
num = int(input())
if num == 0:
break
box = []
while num != 0:
box.append(num%10)
num = num//10
print(sum(box))
| n, k = map(int, input().split())
w = [int(input()) for _ in range(n)]
# k台以内のトラックで運べる荷物の個数
# P: ひとつのトラックに積載できる最大量
def check(P):
i = 0
for j in range(k):
s = 0
while s + w[i] <= P:
s += w[i]
i += 1
if i == n:
return n
return i
# 二部探索
left = 0
right = 100000 * 10000
while right - left > 1:
mid = (left + right) // 2
v = check(mid)
if v >= n:
right = mid
else:
left = mid
print(right)
| 0 | null | 855,354,354,120 | 62 | 24 |
n,k=map(int,input().split())
p_list=list(map(int,input().split()))
p_list=sorted(p_list)
new_p_list=[]
for i in range(k):
new_p_list.append(p_list[i])
print(sum(new_p_list)) | import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
n, k = inm()
a = sorted(inl())
print(sum(a[:k])) | 1 | 11,549,804,011,900 | null | 120 | 120 |
C = input()
alp = "abcdefghijklmnopqrstuvwxyz"
print(alp[alp.index(C)+1])
| def main():
import sys
def input(): return sys.stdin.readline().rstrip()
k = int(input())
s = input()
n = len(s)
mod = 10**9+7
p25 = [0]*(k+1)
p26 = [0]*(k+1)
c = [0]*(k+1)
p25[0], p26[0] = 1, 1
c[0]= 1
for i in range(1, k+1):
p25[i] = p25[i-1]*25
p25[i] %= mod
p26[i] = p26[i-1]*26
p26[i] %= mod
c[i] = (n+i-1)*c[i-1]
c[i] *= pow(i, mod-2, mod)
c[i] %= mod
p25.reverse()
c.reverse()
ans = 0
for i in range(k+1):
tmp = p25[i]*p26[i]*c[i]
tmp %= mod
ans += tmp
ans %= mod
print(ans)
if __name__ == '__main__':
main() | 0 | null | 52,497,346,655,190 | 239 | 124 |
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
"""
def exhaustive_search(m, i):
if i == n:
return 0
if m < 0:
return 0
if m == A[i]:
return 1
return max(exhaustive_search(m, i + 1), exhaustive_search(m - A[i], i + 1))
"""
def dp_search(m):
dp = [[1] + [0] * m for _ in range(n + 1)] # dp[i][j] i番目まででjを作れるか
for i in range(1, n+1):
for j in range(1, m+1):
if j >= A[i-1]:
dp[i][j] = max(dp[i-1][j], dp[i-1][j - A[i-1]])
else:
dp[i][j] = dp[i-1][j]
return dp[n][m]
for mi in m:
if dp_search(mi):
print("yes")
else:
print("no")
| n,m = map(int, input().split())
#a = list(map(int, input().split()))
class UnionFind:
def __init__(self,n):
self.par=[i for i in range(n)]
self.siz=[1]*n
def root(self,x):
while self.par[x]!=x:
self.par[x]=self.par[self.par[x]]
x=self.par[x]
return x
def unite(self,x,y):
x=self.root(x)
y=self.root(y)
if x==y:
return False
if self.siz[x]<self.siz[y]:
x,y=y,x
self.siz[x]+=self.siz[y]
self.par[y]=x
return True
def is_same(self,x,y):
return self.root(x)==self.root(y)
def size(self,x):
return self.siz[self.root(x)]
uni = UnionFind(n)
for i in range(m):
a,b = map(int, input().split())
uni.unite(a-1, b-1)
cnt = [0]*(n)
for i in range(n):
cnt[uni.root(i)] = 1
print(sum(cnt)-1) | 0 | null | 1,200,196,172,170 | 25 | 70 |
n = int(input())
x = str(input())
one = x.count("1")
X = int(x, 2)
if one==1:
for i in range(n):
if x[i]=="1":
print(0)
elif i==n-1:
print(2)
else:
print(1)
elif one>1:
Xp = X % (one+1)
Xm = X % (one-1)
def f(x):
if x==0:
return 0
return 1+f(x%bin(x).count("1"))
for i in range(n):
if x[i]=="0":
c = pow(2, n-i-1, one+1)
print(f((Xp+c)%(one+1))+1)
else:
c = pow(2, n-i-1, one-1)
print(f((Xm-c)%(one-1))+1)
else:
for i in range(n):
print(1) | def solve(n,m):
if not n:return 1
n%=m
return-~solve(n,bin(n).count('1'))
n=int(input())
s=input()
a=int(s,2)
*x,=map(int,s)
h=sum(x)
try:a,b=a%(h-1),a%(h+1)
except:b=a%(h+1)
for i in range(n):
if x[i]:
if not h-1:
print(0)
continue
x[i]=0
t=(a-pow(2,~i+n,h-1))%(h-1)
else:
x[i]=1
t=(b+pow(2,~i+n,h+1))%(h+1)
r=solve(t,bin(t).count('1'))
x[i]^=1
print(r) | 1 | 8,299,233,979,542 | null | 107 | 107 |
from random import choice
from random import random
from time import time
class Optimizer:
def __init__(self, C, S):
self.C = C
self.S = S
X = []
L = [-1] * 26
for i in range(365):
max_diff = -10**10
best_j = 0
for j in range(26):
memo = L[j]
L[j] = i
diff = self.S[i][j] - \
sum([self.C[jj] * (i - L[jj]) for jj in range(26)])
if diff > max_diff:
max_diff = diff
best_j = j
L[j] = memo
L[best_j] = i
X.append(best_j)
self.X = X
def calc_score(self):
score = 0
L = [-1 for j in range(26)]
A = [0 for j in range(26)]
for i in range(365):
score += self.S[i][self.X[i]]
A[self.X[i]] += (i - L[self.X[i]]) * \
(i - L[self.X[i]] - 1) // 2
L[self.X[i]] = i
for j in range(26):
A[j] += (365 - L[j]) * (365 - L[j] - 1) // 2
score -= self.C[j] * A[j]
return score
def optimize(self, temp, threp, interval, start_time, lim=1.8):
max_score = self.calc_score()
while True:
t = (time() - start_time) / 2
if random() < threp:
i = choice(range(365))
j = choice(range(26))
memo = self.X[i]
self.X[i] = j
else:
a = choice(range(interval))
i0 = choice(range(365 - a))
i1 = i0 + a
self.X[i0], self.X[i1] = self.X[i1], self.X[i0]
new_score = self.calc_score()
if new_score > max_score:
max_score = new_score
elif random() < pow(2.7, (new_score - max_score) / pow(2000, 1 - t)):
max_score = new_score
else:
try:
self.X[i0], self.X[i1] = self.X[i1], self.X[i0]
except BaseException:
self.X[i] = memo
if time() - start_time > lim:
break
return max(max_score + 10**6, 0)
if __name__ == "__main__":
d = int(input())
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]
opt = Optimizer(C, S)
opt.optimize(400, 0.8, 10, time(), lim=1.8)
for x in opt.X:
print(x + 1)
| 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 | 21,140,124,864,638 | 113 | 169 |
def Main(K):
l = (1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51)
return l[K-1]
def main():
K = int(input())
print(Main(K))
if __name__ == '__main__':
main() | n = int(input())
a = [int(i) for i in input().split()]
b = []
sum_a = sum(a)
cum = 0
for i in a:
cum += i
b.append(abs(sum_a - cum * 2))
print(min(b)) | 0 | null | 96,204,688,983,260 | 195 | 276 |
st = str(input())
q = int(input())
com = []
for i in range(q):
com.append(input().split())
for k in com:
if k[0] == "print":
print(st[int(k[1]):int(k[2])+1])
elif k[0] == "reverse":
s = list(st[int(k[1]):int(k[2])+1])
s.reverse()
ss = "".join(s)
st = st[:int(k[1])] + ss + st[int(k[2])+1:]
else:
st = st[:int(k[1])] + k[3] + st[int(k[2])+1:]
| import sys
line = sys.stdin.readline().strip()
n = int(sys.stdin.readline())
for i in range(n):
v = sys.stdin.readline().split()
op = v[0]
a = int(v[1])
b = int(v[2])
if op == "print":
print(line[a: b + 1])
elif op == "reverse":
line = line[:a] + line[a: b + 1][::-1] + line[b + 1:]
elif op == "replace":
p = v[3]
line = line[:a] + p + line[b + 1:] | 1 | 2,076,285,455,552 | null | 68 | 68 |
N = int(input())
ll = [] #リストのリスト
for i in range(N):
l = [None]*N
a = int(input())
for j in range(a):
x, y = map(int, input().split())
l[x-1] = y
ll.append(l)
ans = 0
for i in range(1, 2**N): #bit全探索
b = 1
hon = [0]*N #正直者なら1,
for j in range(N):
if i>>j&1:
hon[j] = 1
for k in range(N): # llとhonの比較 # 全正直者について
if hon[k]==1: #正直者のつじつまを合わせる
for h in range(len(ll[k])): #正直者の全ての証言について
if ll[k][h]==None:
continue
if hon[h]!=ll[k][h]:
b = 0
if b:
p = hon.count(1)
ans = max(p, ans)
print(ans) | '''
Created on 2020/09/10
@author: harurun
'''
def main():
import sys
pin=sys.stdin.readline
pout=sys.stdout.write
perr=sys.stderr.write
N,M=map(int,pin().split())
if N==3:
ans=[1,0,0]
for _ in [0]*M:
s,c=map(int,pin().split())
if s==1 and c==0:
print(-1)
return
if s!=1 and ans[s-1]!=0 and ans[s-1]!=c:
print(-1)
return
ans[s-1]=c
a=""
for i in ans:
a+=str(i)
print(a)
return
elif N==2:
ans=[1,0]
for _ in [0]*M:
s,c=map(int,pin().split())
if s==1 and c==0:
print(-1)
return
if s!=1 and ans[s-1]!=0 and ans[s-1]!=c:
print(-1)
return
ans[s-1]=c
a=""
for i in ans:
a+=str(i)
print(a)
return
else:
if M==0:
print(0)
return
s,c=map(int,pin().split())
ans=c
for j in range(M-1):
s,c=map(int,pin().split())
if c!=ans:
print(-1)
return
print(ans)
return
main() | 0 | null | 91,177,105,578,650 | 262 | 208 |
# local search is all you need
# 「日付 d とコンテストタイプ q をランダムに選び、d 日目に開催するコンテストをタイプ q に変更する」を実装する
from time import time
t0 = time()
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate
def exit(*argv, **kwarg):
print(*argv, **kwarg)
sys.exit()
def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと
def a_int(): return int(read())
def ints(): return list(map(int, read().split()))
def read_col(H):
'''H is number of rows
A列、B列が与えられるようなとき
ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合'''
ret = []
for _ in range(H):
ret.append(list(map(int, read().split())))
return tuple(map(list, zip(*ret)))
def read_tuple(H):
'''H is number of rows'''
ret = []
for _ in range(H):
ret.append(tuple(map(int, read().split())))
return ret
MOD = 10**9 + 7
INF = 2**31 # 2147483648 > 10**9
# default import
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right # , insort_left, insort_right
from functools import reduce
from random import randint
def score(D, C, S, T):
last = [-1] * 26
# scores = [0]
score = 0
for d in range(D):
# scores.append(scores[-1] + S[d][T[d]])
score += S[d][T[d]]
last[T[d]] = d
for i in range(26):
# scores[-1] -= C[i] * (d - last[i])
score -= C[i] * (d - last[i]) # この場で一番罰則が大きいやつを使うとか?
return score
D = a_int()
C = ints()
S = read_tuple(D)
def maximizer(newT, bestT, bestscore):
tmpscore = score(D, C, S, newT)
if tmpscore > bestscore:
return newT, tmpscore
else:
return bestT, bestscore
def ret_init_T():
'''greedyで作ったTを初期値とする。
return
----------
T, score ... 初期のTとそのTで得られるscore
'''
def _make_T(n_days):
# editorialよりd日目の改善は、改善せずにd+n_days経過したときの関数にしたほうが
# 最終的なスコアと相関があるんじゃない?
T = []
last = [-1] * 26
for d in range(D):
ma = -INF
for i in range(26):
tmp = S[d][i]
for j in range(n_days):
tmp += C[i] * (d + j - last[i])
if tmp > ma:
t = i
ma = tmp
last[t] = d # Tを選んだあとで決める
T.append(t)
return T
T = _make_T(0)
sco = score(D, C, S, T)
for i in range(1, 20):
T, sco = maximizer(_make_T(i), T, sco)
return T, sco
bestT, bestscore = ret_init_T()
def add_noise(T):
'''日付dとコンテストqをランダムに選びd日目に開催するコンテストのタイプをqに変更する'''
ret = T.copy()
d = randint(0, D - 1)
q = randint(0, 25)
ret[d] = q
return ret
t1 = time()
bestT, bestscore = maximizer(add_noise(bestT), bestT, bestscore)
dt = time() - t1
times = (1.95 - (time() - t0)) // dt
for _ in range(int(times)):
bestT, bestscore = maximizer(add_noise(bestT), bestT, bestscore)
# while time() - t0 < 1.92:
# # while time() - t0 < 5:
# bestT, bestscore = maximizer(add_noise(bestT), bestT, bestscore)
# print(bestscore)
# print(bestscore)
# print(t0, t1, dt, times, time() - t0)
# print(score(D, C, S, T))
print(*mina(*bestT, sub=-1), sep='\n')
| def main():
D = int(input())
C = [0] * 26
C = list(map(int,input().split()))
S = [ list(map(int,input().split(" "))) for i in range(D)]
last = [0] * 26
for i in range(D):
max = -9999999999999
max_t = 0
for t in range(26):
score = 0
for j in range(26):
if j == t:
#last[j] = 0
score += S[i][j]
else:
#last[j] += 1
score -= (last[j]+10)*C[j]
if score > max:
max = score
max_t = t
for j in range(26):
if j == max_t:
last[j] = 0
else:
last[j] += 1
print(max_t + 1)
if __name__ == '__main__':
main() | 1 | 9,654,477,956,592 | null | 113 | 113 |
H, N = map(int, input().split())
l = []
for i in range(N):
l.append(list(map(int, input().split())))
dp = [0] * 20000
for i in range(1, 20001):
dp[i] = min(dp[i-a]+b for a, b in l)
if i == H:
break
print(dp[H]) | H, N = [int(_) for _ in input().split()]
A = []
ma = None
for i in range(N):
a, b = [int(_) for _ in input().split()]
A.append((a, b, a / b))
A.sort(key=lambda x: -x[2])
ans = 0
# ans = (H // A[0][0]) * A[0][1]
h = H # % A[0][0]
if h > 0:
memo = [10 ** 9 + 7] * (h + 1)
memo[h] = 0
for j in range(h, 0, -1):
for i in range(N):
a, b, c = A[i]
x = j - a
if x < 0:
x = 0
memo[x] = min(memo[x], memo[j] + b)
ans += memo[0]
print(ans)
| 1 | 80,844,979,197,292 | null | 229 | 229 |
import sys
import itertools
from math import gcd
n = int(sys.stdin.read())
print(sum(gcd(gcd(abc[0], abc[1]), abc[2]) for abc in itertools.product(range(1, n + 1), repeat=3)))
| def gcd(x,y):
while y>0:
x,y = y,x%y
return x
K = int(input())
cnt = 0
for a in range(1,K+1):
for b in range(1,K+1):
for c in range(1,K+1):
x = a
x = gcd(x,b)
x = gcd(x,c)
cnt += x
print(cnt) | 1 | 35,815,229,932,300 | null | 174 | 174 |
A, B, M = map(int, input().split())
price_A = list(map(int, input().split()))
price_B = list(map(int, input().split()))
min_A = min(price_A)
min_B = min(price_B)
ans = min_A + min_B
for i in range(M):
x, y, c = map(int, input().split())
ans = min(price_A[x-1]+price_B[y-1]-c,ans)
print(ans)
| A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 999999
for i in range(M):
x, y, c = map(int, input().split())
if x <= A and y <= B:
d = a[x - 1] + b[y - 1] - c
if d < ans:
ans = d
if (min(a) + min(b)) < ans:
ans = min(a) + min(b)
print(ans) | 1 | 54,138,142,539,570 | null | 200 | 200 |
X = int(input())
Food = [100,101,102,103,104,105]
dp = [False] * (X+1)
dp[0] = True
for i in range(X+1):
for f in Food:
if i - f >= 0:
#print(i,i-f)
dp[i] = dp[i - f] | dp[i]
print('1' if dp[X] else '0')
| import sys
input=lambda: sys.stdin.readline().rstrip()
n,m,k=map(int,input().split())
mod=998244353
n_max=2*(10**5+1)
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
F[i+1]=(F[i]*(i+1))%mod
FI[n_max-1]=pow(F[n_max-1],mod-2,mod)
for i in reversed(range(n_max-1)):
FI[i]=(FI[i+1]*(i+1))%mod
def comb(x,y):
return (F[x]*FI[x-y]*FI[y])%mod
P=[1]
for i in range(n):
P.append((P[-1]*(m-1))%mod)
ans=0
for i in range(k+1):
ans+=m*P[n-1-i]*comb(n-1,i)
if ans>mod:
ans%=mod
print(ans) | 0 | null | 74,980,492,003,872 | 266 | 151 |
input = input()
W,H,x,y,r = map(int ,input.split())
if x - r < 0 or x + r > W or y - r < 0 or y + r > H:
print("No")
if x - r >= 0 and x + r <= W and y - r >= 0 and y + r <= H:
print("Yes")
| W,H,x,y,r = map(int, input().split())
if(x+r <= W and y+r <= H):
if(x-r >= 0 and y-r >= 0) :
print("Yes")
else :
print("No")
else :
print("No")
| 1 | 452,082,305,022 | null | 41 | 41 |
N, M = map(int, input().split(' '))
result = 0
if N > 1:
result += N * (N - 1) / 2
if M > 1:
result += M * (M - 1) / 2
print(int(result)) | moji=""
while True:
try:
t = input()
moji += t.lower()
except :
break
moji2 = [chr(i) for i in range(97,97+26)]
for j in moji2:
print(j+" : "+str(moji.count(j)))
| 0 | null | 23,729,970,227,868 | 189 | 63 |
n = int(input())
s = input()
if len(s) > n:
print(s[:n] + '...')
else:
print(s) | def resolve():
K = int(input())
S = input()
if K < len(S):
print(S[:K] + "...")
else:
print(S)
resolve() | 1 | 19,625,479,666,276 | null | 143 | 143 |
INF = 10000000000
def merge(A,left,mid,right):
count = 0
L = A[left:mid] + [INF]
R = A[mid:right] + [INF]
i,j = 0,0
for k in range(left, right):
count += 1
if L[i] <= R[j]:
A[k]=L[i]
i += 1
else:
A[k]=R[j]
j += 1
return count
def merge_sort(A,left,right):
if left+1 < right:
mid = (left+right)//2
count_l = merge_sort(A,left,mid)
count_r = merge_sort(A,mid,right)
return merge(A,left,mid,right) + count_l + count_r
return 0
n = int(input())
A = [int(i) for i in input().split()]
count = merge_sort(A, 0, n)
for i in range(n):
if i:
print(" ", end = "")
print(A[i], end = "")
print()
print(count)
| X=int(input())
n = 0
big = 0
small=0
#print(10**9)
while True:
if (n**5 - (n-1)**5) > 10**9 :
break
big=n
n += 1
n=0
while True:
if (n**5 - (n-1)**5) > 10**9 :
break
small=n
n -= 1
a = list(range(0, big, 1))+list(range(-1, small-1, -1))
b = list(range(0, big-1, 1))+list(range(-1, small-2, -1))
stopFlag = False
for ia in a:
if stopFlag :
break
for ib in b:
if (ia**5) - (ib**5) == X:
print(ia, ib)
stopFlag = True
break
| 0 | null | 12,856,031,688,920 | 26 | 156 |
from functools import reduce
print("Yes" if reduce(lambda a, b: (a+b)%9, map(int, input()), 0) == 0 else "No")
| def MI(): return map(int, input().split())
D,T,S=MI()
if D<=T*S:
print('Yes')
else:
print('No') | 0 | null | 4,005,453,186,552 | 87 | 81 |
import itertools
import bisect
N = int(input())
LS = list(map(int,input().split()))
LS.sort()
ans = 0
for a,b in itertools.combinations(LS,2):
a,b = min(a,b),max(a,b)
lo = b - a
up = a + b
cnt = bisect.bisect_left(LS,up) - bisect.bisect_right(LS,lo) - 1
if lo < a:
cnt -= 1
if cnt <= 0:
continue
ans += cnt
print(ans // 3)
| N = int(input())
l = list(map(int,input().split()))
def is_ok(n, su):
return l[n] > su
def binary_search(left, right, su):
while (abs(right - left) > 1):
mid = (left + right) // 2
if is_ok(mid, su): right = mid
else: left = mid
return right
l = sorted(l)
ans = 0
for i in range(2, N):
for j in range(1, i):
left = j
right = -1
ret = binary_search(right, left, l[i] - l[j])
if ret != right: ans += j - ret
print(ans) | 1 | 171,030,972,573,578 | null | 294 | 294 |
C = input()
word = 'abcdefghijklmnopqrstuvwxyz'
i = word.find(C)
print(word[i+1]) | N=int(input())
num_list=list(map(int,input().split(" ")))
MAX=500000
L=[None]*((MAX)//2+2)
R=[None]*((MAX)//2+2)
def merge(A,left,mid,right):
cnt=0
n1=mid-left
n2=right-mid
for i in range(n1):
L[i]=A[i+left]
for i in range(n2):
R[i]=A[i+mid]
L[n1]=(10**9+1)
R[n2]=(10**9+1)
j,k=0,0
for i in range(left,right):
cnt+=1
if L[j]<=R[k]:
A[i]=L[j]
j+=1
else:
A[i]=R[k]
k+=1
return cnt
def mergesort(A,left,right):
if left+1<right:
mid=(left+right)//2
cntL=mergesort(A,left,mid)
cntR=mergesort(A,mid,right)
return merge(A,left,mid,right)+cntL+cntR
return 0
cnt=mergesort(num_list,0,N)
print(*num_list)
print(cnt)
| 0 | null | 45,949,311,586,272 | 239 | 26 |
S = input().split("S")
S_len = [len(S_each) for S_each in S]
print(max(S_len)) | s = input()
if s == "SSS":
print("0")
elif s == "RRS" or s == "SRR":
print("2")
elif s == "RRR":
print("3")
else:
print("1")
| 1 | 4,885,928,905,312 | null | 90 | 90 |
s=input().strip()
print('ARC' if s=='ABC' else 'ABC') | n = int(input())
ans = 0
for b in range(1, n+1):
y = n // b
ans += y*(y+1)*b/2
print(int(ans)) | 0 | null | 17,673,787,562,838 | 153 | 118 |
from itertools import permutations as p
N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
j = 0
for i in p(range(1, N + 1)):
j += 1
if i == P: a = j
if i == Q: b = j
if a - b >= 0: print(a - b)
else: print(b - a) | N, M = map(int, input().split())
A = list(map(int, input().split()))
cnt = 0
sumA = sum(A)
for a in A:
if a >= sumA / 4 / M:
cnt += 1
if cnt >= M:
print('Yes')
else:
print('No')
| 0 | null | 69,613,879,330,292 | 246 | 179 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.