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
|
---|---|---|---|---|---|---|
k = int(input())
ok = False
for i in range(1, k+1):
if i == 1:
a = 7 % k
else:
anext = (a * 10 + 7) % k
a = anext
if a == 0:
print(i)
ok = True
break
if not ok:
print(-1)
| ope = list(input().split())
stack = []
for o in ope:
if o == '+':
b, a = stack.pop(), stack.pop()
stack.append(a + b)
elif o == '-':
b, a = stack.pop(), stack.pop()
stack.append(a - b)
elif o == '*':
b, a = stack.pop(), stack.pop()
stack.append(a * b)
else:
stack.append(int(o))
print(stack[0])
| 0 | null | 3,045,440,314,278 | 97 | 18 |
L = []
n,x = map(int, input().split())
while not(n == 0 and x == 0):
L.append([n, x])
n, x = map(int, input().split())
for i in L:
ans = 0
for j in range(1, i[0] - 1):
if j > i[1] - 3:
break
else:
for k in range(j + 1, i[0]):
m = i[1] - (j + k)
if m <= k:
break
elif m <= i[0]:
ans += 1
else:
continue
print(ans) | while True:
N,X = map(int,input().split())
if N==0 and X==0:
break
ans = 0
for a in range(1,N+1):
for b in range(a+1,N+1):
if b >= N+1:
break
c = X-(a+b)
if c > b and c <=N:
ans +=1
print("{:d}".format(ans))
| 1 | 1,295,573,746,490 | null | 58 | 58 |
n = int(input())
l = list(map(int,input().split()))
from itertools import accumulate
cum=list(accumulate(l))
tot=sum(l)
ans=2020202020*100000
for i in cum:
ans=min(ans, abs(tot-i*2))
print(ans)
| """
何回足されるかで考えればよい。
真っ二つに切っていく。
各項は必ずM未満。
M項以内に必ずループが現れる。
"""
N,X,M = map(int,input().split())
memo1 = set()
memo2 = []
ans = 0
a = X
flag = True
rest = N
while rest > 0:
if a in memo1 and flag:
flag = False
for i in range(len(memo2)):
if memo2[i] == a:
loopStart = i
setSum = 0
for i in range(loopStart,len(memo2)):
setSum += memo2[i]**2 % M
loopStep = len(memo2)-loopStart
loopCount = rest // loopStep
ans += loopCount*setSum
rest -= loopCount*loopStep
else:
memo1.add(a)
memo2.append(a)
ans += a
a = a**2%M
rest -= 1
print(ans) | 0 | null | 72,551,000,662,990 | 276 | 75 |
values = input()
W, H, x, y, r = [int(x) for x in values.split()]
flag = True
if x - r < 0 or x + r > W:
flag = False
if y - r < 0 or y + r > H:
flag = False
if flag:
print('Yes')
else:
print('No') | x = input().split(" ")
if int(x[2]) - int(x[4]) >= 0 and int(x[3]) - int(x[4]) >= 0 and int(x[2]) + int(x[4]) <= int(x[0]) and int(x[3]) + int(x[4]) <= int(x[1]) :
print("Yes")
else:
print("No")
| 1 | 450,319,942,528 | null | 41 | 41 |
H, W, K = map(int, input().split())
m = []
for h in range(H):
m.append(list(map(int, list(input()))))
ans = float('inf')
for hb in range(2**(H-1)):
hl = []
for i in range(H-1):
if hb & (1 << i) > 0:
hl.append(i+1)
t = len(hl)
hl = [0]+hl+[H]
w, pw = 0, 0
wl = [0]*len(hl)
while w < W:
ok = True
for i in range(len(hl)-1):
sh, eh = hl[i], hl[i+1]
for h in range(sh, eh):
wl[i] += m[h][w]
if wl[i] > K:
ok = False
break
if not ok:
break
if not ok:
if pw == w:
t = float('inf')
break
pw, w = w, w
t += 1
wl = [0]*len(hl)
else:
w += 1
ans = min(t, ans)
print(ans)
| #!/usr/bin/env python3
import sys
def input():
return sys.stdin.readline()[:-1]
def main():
H = int(input())
ans = 0
n = 1
for i in range(10**12):
if H == 1:
ans += n
print(ans)
exit()
ans += n
n *= 2
H = int(H/2)
if __name__ == '__main__':
main()
| 0 | null | 64,440,963,803,370 | 193 | 228 |
i = 1
a = input()
while a != 0:
print "Case %d: %d" % (i, a)
i = i + 1
a = input() | i=1
while True:
n=int(input())
if n!=0:
print("Case %d: %d"%(i,n))
i=i+1
else:
break | 1 | 478,900,087,072 | null | 42 | 42 |
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) | n = int(input())
R = [int(input()) for i in range(n)]
minv = float('inf')
maxv = -float('inf')
for r in R:
maxv = max(maxv, r-minv)
minv = min(minv, r)
print(maxv) | 0 | null | 74,305,791,813,960 | 280 | 13 |
def gcd(a, b):
if b == 0:
return a
return gcd(b, a%b)
while True:
try:
a, b = map(int, raw_input().strip().split(' '))
print "%d %d" % (gcd(a, b), a*b/gcd(a, b))
except EOFError:
break | #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
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
#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
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
n = I()
A = readInts()
ans = float('inf')
for i in range(1,101):
diff = 0
for j in range(n):
diff += pow(A[j]-i,2)
ans = min(ans,diff)
print(ans)
| 0 | null | 32,434,670,817,010 | 5 | 213 |
N = int(input())
L = list(map(int, input().split()))
le = len(L)
score = 0
for i in range(le):
for j in range(i+1,le):
for k in range(j+1,le):
if (L[i] + L[j] > L[k] and
L[i] + L[k] > L[j] and
L[k] + L[j] > L[i] ):
if (L[i] != L[j] and
L[i] != L[k] and
L[k] != L[j]):
score += 1
print(score) | def POW(x, n, mod): #xのn乗をmodで割った際の余りの高速計算
ans = 1
while n > 0:
if n % 2 == 1:
ans *= x%mod
x = (x*x)%mod
n >>= 1 #ビットシフト
return ans
if __name__ == '__main__':
N, K = map(int, input().split())
lst = [0] * (K+1)
mod = 10 ** 9 + 7
ans = 0
for i in range(K):
k = K - i
n = K // k
v = POW(n,N,mod)
m = 2
while(m * k <= K):
v -= lst[m*k]
if v < 0:
v += mod
m += 1
lst[k] = v
v = (k * v)%mod
ans = (ans+v)%mod
print(int(ans)) | 0 | null | 20,932,740,261,296 | 91 | 176 |
a,b,c =raw_input().split()
a,b,c = map(int,(a,b,c))
ls = list((a,b,c))
ls.sort()
string_ans=''
for k in ls:
string=''
string = str(k)+" "
string_ans = string_ans + string
print string_ans.strip() | num = input().split()
print(' '.join(map(str, sorted(num)))) | 1 | 421,093,363,240 | null | 40 | 40 |
N=int(input())
A=[int(i) for i in input().split()]
S=set(A)
ans=1
for i in A:
ans*=i
if ans>10**18:
ans=-1
break
if 0 in S:
ans=0
print(ans)
| cnt = 0
s = input().lower()
while 1:
line = input()
if line == "END_OF_TEXT":
break
for w in line.lower().split():
if w == s:
cnt+=1
print(cnt) | 0 | null | 8,955,636,459,454 | 134 | 65 |
# -*- coding: utf-8 -*-
n = input()
x = y = 0
for _ in xrange(n):
a, b = raw_input().split()
if a==b:
x += 1
y += 1
elif a>b:
x += 3
else:
y += 3
print x, y | n,k,s = map(int,input().split())
rem = s+1
if rem > 10**9:
rem = 1
li = []
for i in range(n):
if i < k:
li.append(s)
else:
li.append(rem)
print(*li)
| 0 | null | 46,377,871,367,968 | 67 | 238 |
n, h = map(int, input().split())
hn = map(int, input().split())
cnt = 0
for i in hn:
if i >= h:
cnt += 1
print(cnt) | N, K = map(int, input().split())
H = list(map(int, input().split()))
print(len(list(filter(lambda x: x >= K, H)))) | 1 | 179,650,232,728,330 | null | 298 | 298 |
list = [int(a) for a in input().split()]
list.sort()
print(*list) | n = int(input())
ls = list(map(int,input().split()))
ls.sort(reverse=True)
p = len(ls)
if len(ls)%2 == 1:
p += 1
p //= 2
q = 0
for i in range(1,p+1):
if i == 1:
q += ls[0]
else:
if i == p:
if len(ls)%2 == 1:
q += ls[p-1]
else:
q += 2*ls[p-1]
else:
q += 2*ls[i-1]
print(q) | 0 | null | 4,853,118,019,680 | 40 | 111 |
from collections import defaultdict
import sys
def input():return sys.stdin.readline().strip()
def main():
N, P = map(int, input().split())
S = input()
ans = 0
if P in [2, 5]:
for i, c in enumerate(S[::-1]):
if int(c) % P == 0:
ans += N-i
else:
d = defaultdict(int)
d[0] = 1
num = 0
ten = 1
for c in S[::-1]:
num += int(c) * ten
num %= P
d[num] += 1
ten *= 10
ten %= P
ans = sum([d[i]*(d[i]-1)//2 for i in range(P)])
print(ans)
if __name__ == "__main__":
main() | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import Counter
N, P = map(int, readline().split())
S = list(map(int, read().rstrip().decode()))
def solve_2(S):
ind = (i for i, x in enumerate(S, 1) if x % 2 == 0)
return sum(ind)
def solve_5(S):
ind = (i for i, x in enumerate(S, 1) if x % 5 == 0)
return sum(ind)
def solve(S,P):
if P == 2:
return solve_2(S)
if P == 5:
return solve_5(S)
S = S[::-1]
T = [0] * len(S)
T[0] = S[0] % P
power = 1
for i in range(1, len(S)):
power *= 10
power %= P
T[i] = T[i-1] + power * S[i]
T[i] %= P
counter = Counter(T)
return sum(x * (x - 1) // 2 for x in counter.values()) + counter[0]
print(solve(S,P))
| 1 | 58,299,727,057,328 | null | 205 | 205 |
N = int(input())
L = list(map(int,input().split()))
cnt = 0
for n in range(N):
if (n + 1) % 2 == 1 and L[n] % 2 == 1:
cnt += 1
print(cnt) | N=int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(0, N, 2):
ans += A[i] % 2 != 0
print(ans)
| 1 | 7,765,936,842,230 | null | 105 | 105 |
import math
x1, y1, x2, y2 = map(float, input().split())
dx = x1 - x2
dy = y1 - y2
d = math.hypot(dx, dy)
print(d) | import math
x1,y1,x2,y2=map(float,input().split())
a = ((x1-x2)**2)+((y1-y2)**2)
a = math.sqrt(a)
print('{:.8f}'.format(a))
| 1 | 158,801,541,248 | null | 29 | 29 |
def calc():
# 入力
a = int(input())
# 計算処理
result = 0
for i in range(1,4):
result += a ** i
# 出力
print(result)
calc() | n,k=(int(x) for x in input().split())
h=list(int(x) for x in input().split())
c=0
for i in h:
if i>=k:
c+=1
print(c) | 0 | null | 94,489,053,764,280 | 115 | 298 |
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
@njit((i8,i8,i8[:],i8[:]), cache=True)
def main(H,N,A,B):
INF = 1<<30
dp = np.full(H+1,INF,np.int64)
dp[0] = 0
for i in range(N):
for h in range(A[i],H):
dp[h] = min(dp[h],dp[h-A[i]]+B[i])
dp[H] = min(dp[H],min(dp[H-A[i]:H]+B[i]))
ans = dp[-1]
return ans
H, N = map(int, input().split())
A = np.zeros(N,np.int64)
B = np.zeros(N,np.int64)
for i in range(N):
A[i],B[i] = map(int, input().split())
print(main(H,N,A,B)) | h,n = map(int,input().split())
a = [0]*n
b = [0]*n
for i in range(n): a[i],b[i] = map(int,input().split())
dp = [10**9]*(h+1)
dp[0] = 0
for i in range(h):
for j in range(n):
dp[min(i+a[j],h)] = min(dp[min(i+a[j],h)],dp[i]+b[j])
print(dp[h]) | 1 | 80,717,811,637,090 | null | 229 | 229 |
from math import ceil
A, B, C, D = map(int, input().split())
time_A, time_C = ceil(A/D), ceil(C/B)
print('Yes') if time_A >= time_C else print('No') | A, B, C, D = map(int, input().split())
print('No' if -A // D > -C // B else 'Yes') | 1 | 29,692,250,480,670 | null | 164 | 164 |
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")
| import math
while True:
try:
x, y = map(int, input().split())
print(str(math.gcd(x,y)) + " " + str((x * y) // math.gcd(x, y)))
except EOFError:
break
| 0 | null | 228,664,735,838 | 41 | 5 |
s = input()
t = input()
ans = 0
for cs, ct in zip(s, t):
if cs != ct:
ans += 1
print(ans) | n,k,*l=map(int,open(0).read().split())
for _ in range(min(k,41)):
s=[0]*-~n
for i in range(n):
s[max(i-l[i],0)]+=1
s[min(i+l[i]+1,n)]-=1
for i in range(n): s[i+1]+=s[i]
l=s
print(*l[:n]) | 0 | null | 13,063,028,754,000 | 116 | 132 |
d = int(input())
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]
X = [int(input()) - 1 for i in range(d)]
L = [-1 for j in range(26)]
score = 0
for i in range(d):
L[X[i]] = i
score += S[i][X[i]]
score -= sum([C[j] * (i - L[j]) for j in range(26)])
print(score)
| def str_reverse(s, a, b):
s_new = s[0:a]
s_rev = s[a:b+1]
s_rev_len = len(s_rev)
for i in range(s_rev_len):
j = s_rev_len - i - 1
s_new += s_rev[j]
s_new += s[b+1:]
return s_new
def str_replace(s, a, b, new):
s_new = s[0:a]
s_new += new
s_new += s[b+1:]
return s_new
s = input()
n = int(input())
for q in range(n):
line = input()
if line.find('print') == 0:
cmd, a, b = line.split()
a = int(a)
b = int(b)
print(s[a:b+1])
elif line.find('reverse') == 0:
cmd, a, b = line.split()
a = int(a)
b = int(b)
s = str_reverse(s, a, b)
elif line.find('replace') == 0:
cmd, a, b, p = line.split()
a = int(a)
b = int(b)
s = str_replace(s, a, b, p) | 0 | null | 6,083,541,727,520 | 114 | 68 |
K = int(input())
k = K - 1
numbers = {
0: 1
}
while k > 0:
k -= 1
for i in range(len(numbers)):
n = numbers[i]
if n == 9:
continue
if abs(numbers.get(i - 1, n) - (n + 1)) <= 1 and abs(numbers.get(i + 1, n) - (n + 1)) <= 1:
numbers[i] += 1
j = i - 1
while j >= 0:
numbers[j] = max(numbers[j + 1] - 1, 0)
j -= 1
break
else:
for key in numbers.keys():
numbers[key] = 0
numbers[len(numbers)] = 1
print(''.join([str(numbers[i]) for i in range(len(numbers))])[::-1])
| from collections import deque
k = int(input())
a = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in range(k-1):
b = a.popleft()
if b%10 != 0: a.append(b*10+b%10-1)
a.append(b*10+b%10)
if b%10 != 9: a.append(b*10+b%10+1)
print(a[0]) | 1 | 39,889,002,831,206 | null | 181 | 181 |
import sys
def input(): return sys.stdin.readline().strip()
def MAP(): return map(int, input().split())
n, a, b = MAP()
print(abs(a - b) // 2 if not (a - b) % 2 else abs(a - b) // 2 + min(min(a, b) - 1, n - max(a, b)) + 1) | n=int(input())
print(1-n) | 0 | null | 55,927,729,888,612 | 253 | 76 |
# -*- coding: utf-8 -*-
while True:
deck = str(raw_input())
if deck == '-':
break
m = int(raw_input())
for i in range(m):
h = int(raw_input())
deck = deck[h:] + deck[0:h]
print deck | #?±±???(?????????)?????\???
deck = input()
#????????????(-)????±±????????\?????????????????§??????
while deck != "-":
#?????°?????\???
times = int(input())
#????????????????????????
shuffle = list(deck)
#?????????????????????????´?
deck_length = len(deck)
#times????????°???????????£?????????
for i in range(times):
#????????§?????????????????\????????????????????§?????£?????????
val = int(input())
shuffle = shuffle[val:] + shuffle[:val]
#???????????????
print("".join(shuffle))
#?¬?????±±????????\???
deck = input() | 1 | 1,882,696,866,262 | null | 66 | 66 |
# coding: utf-8
# Your code here!
s=input()
ans=ord(s)+1
print(chr(ans))
| import sys
import math
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]
def main():
H, W, K = NMI()
choco = [SI() for _ in range(H)]
ans = 100000
for case in range(2**(H-1)):
groups = [[0]]
for i in range(H-1):
if (case >> i) & 1:
groups[-1].append(i+1)
else:
groups.append([i+1])
white = [0] * len(groups)
is_badcase = False
cut = len(groups) - 1
for w in range(W):
diff = [0] * len(groups)
for gi, group in enumerate(groups):
for h in group:
if choco[h][w] == "1":
white[gi] += 1
diff[gi] += 1
if max(white) <= K:
is_cont = True
continue
if max(diff) > K:
is_badcase = True
break
cut += 1
white = diff[:]
continue
if not is_badcase:
ans = min(ans, cut)
print(ans)
if __name__ == "__main__":
main() | 0 | null | 70,296,492,876,600 | 239 | 193 |
from collections import deque
s = input()
q = int(input())
r = False
S = deque(s)
for _ in range(q):
d = list(input().split())
if len(d)==1:
r = ~r
else:
if (d[1]=='1' and ~r) or (d[1]=='2' and r):
S.appendleft(d[2])
else:
S.append(d[2])
s = ''.join(S)
if r:
s = s[::-1]
print(s) | import sys
# sys.setrecursionlimit(100000)
from collections import deque
def input():
return sys.stdin.readline().strip()
def input_int():
return int(input())
def input_int_list():
return [int(i) for i in input().split()]
def main():
s = deque(list(input()))
q = input_int()
inverse = False
for _ in range(q):
data = input().split()
if len(data) == 1:
inverse = not inverse
else:
if (data[1] == "1" and not inverse) or (data[1] == "2" and inverse):
s.appendleft(data[2])
else:
s.append(data[2])
if inverse:
print("".join(reversed(s)))
else:
print("".join(s))
return
if __name__ == "__main__":
main()
| 1 | 57,412,619,521,660 | null | 204 | 204 |
import sys
char_list = []
for line in sys.stdin:
char_list.append([j for j in line.lower()])
char_dict = {i:0 for i in "abcdefghijklmnopqrstuvwxyz"}
for i in range(len(char_list)):
for j in char_list[i]:
if j in char_dict:
char_dict[j] += 1
for i in char_dict:
print(i+" : {0}".format(char_dict[i]))
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??§???????°?????????????
"""
import sys
lower = "abcdefghijklmnopqrstuvwxyz"
upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
inp = sys.stdin.read() # EOF?????§????????????
inp = inp.translate(str.maketrans(upper,lower))
for i in lower:
print("{0} : {1}".format(i,inp.count(i))) | 1 | 1,663,915,087,890 | null | 63 | 63 |
print(0) if int(input())==1 else print(1) | X = int(input())
flag = False
for i in range(-120, 120):
for j in range(-120, 120):
if i ** 5 - j ** 5 == X:
print(i, j)
flag = True
break
if flag:
break | 0 | null | 14,183,480,893,668 | 76 | 156 |
def main():
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for ia in range(N-2):
a = L[ia]
ic = ia + 2
for ib in range(ia+1, N-1):
b = L[ib]
while ic < N and L[ic] < a+b:
ic += 1
ans += ic - (ib + 1)
print(ans)
main() | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n,m = inpl()
h = inpl()
g = [[] for _ in range(n)]
for _ in range(m):
a,b = inpl()
a,b = a-1,b-1
g[a].append(b)
g[b].append(a)
res = 0
for i in range(n):
for j in g[i]:
if h[j] >= h[i]:
break
else:
res += 1
print(res) | 0 | null | 98,359,295,350,868 | 294 | 155 |
digitsStr = input()
honlist = ["2","4","5","7","9"]
ponList = ["0","1","6","8"]
if digitsStr[-1] == '3':
print('bon')
elif digitsStr[-1] in honlist:
print('hon')
elif digitsStr[-1] in ponList:
print('pon') | n=input()
hon="24579"
pon="0168"
x=n[len(n)-1]
if x in hon:
print("hon")
elif x in pon:
print("pon")
else:
print("bon")
| 1 | 19,347,640,581,960 | null | 142 | 142 |
class BIT:
from operator import add, sub, mul, floordiv
X_unit = 0
X_f = add
X_f_rev = sub
def __init__(self, seq):
N = len(seq)
self.N = N
self.X = seq[:]
for i in range(self.N):
j = i + ((i+1) & -(i+1))
if j < self.N:
self.X[j] = self.X_f(self.X[i], self.X[j])
def set_val(self, i, x):
while(i < self.N):
self.X[i] = self.X_f(self.X[i], x)
i += (i+1) & -(i+1)
def cum_val(self, i):
res = self.X_unit
while(i > -1):
res = self.X_f(res, self.X[i])
i -= (i+1) & -(i+1)
return res
#区間[L, R)
def fold(self, L, R):
return self.X_f_rev(self.cum_val(R-1), self.cum_val(L-1))
def bisect_left(self, w):
if w > self.cum_val(self.N - 1):
return self.N
elif self.N == 2:
return 1
n = 2**((self.N - 1).bit_length() - 1)
res = 0
while(n):
if res + n - 1 > self.N - 1:
n //= 2
continue
if w <= self.X[res + n - 1]:
n //= 2
else:
w -= self.X[res + n - 1]
res += n
n //= 2
return res
def bisect_right(self, w):
if w >= self.cum_val(self.N - 1):
return self.N
elif self.N == 2:
return 1
n = 2**((self.N - 1).bit_length() - 1)
res = 0
while(n):
if res + n - 1 > self.N - 1:
n //= 2
continue
if w < self.X[res + n - 1]:
n //= 2
else:
w -= self.X[res + n - 1]
res += n
n //= 2
return res
def lower_bound(self, w):
ans = self.bisect_right(self.cum_val(w))
if ans == self.N:
return -1
else:
return ans
def upper_bound(self, w):
ans = self.bisect_left(self.cum_val(w-1))
return ans
N = int(input())
S = list(input())
L = [BIT([0]*N) for _ in range(26)]
for i in range(N):
L[ord(S[i])-97].set_val(i, 1)
Q = int(input())
for _ in range(Q):
q, a, b = input().split()
if q == "1":
a = int(a)
L[ord(S[a-1])-97].set_val(a-1, -1)
L[ord(b)-97].set_val(a-1, 1)
S[a-1] = b
else:
a, b = int(a), int(b)
ans = 0
for i in range(26):
if L[i].fold(a-1, b) >= 1:
ans += 1
print(ans) | S=input()
t=len(S)
print("YNeos"[sum(1for i in range(t) if S[i]!=S[~i] )!=0 or S[(t+2)//2:]!=S[:(t-1)//2]::2]) | 0 | null | 54,534,752,292,358 | 210 | 190 |
def main():
from decimal import Decimal
N, M = (Decimal(i) for i in input().split())
print(int(N * M))
if __name__ == '__main__':
main()
| # -*- coding: utf-8 -*-
# combinationを使う
import math
def comb(n, r):
return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))
n, m = map(int, input().split())
counter = 0
if n >= 2:
counter = counter + comb(n, 2)
if m >= 2:
counter = counter + comb(m, 2)
print(counter) | 0 | null | 31,087,654,307,260 | 135 | 189 |
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(K):
B = [0] * (N + 1)
for i in range(N):
l = max(0,i-A[i])
r = min(N,i+A[i]+1)
B[l] += 1
B[r] -= 1
for i in range(N):
B[i+1] += B[i]
B.pop(-1)
if A == B:
break
A = B
print(*A)
if __name__ == "__main__":
main() | import math
from itertools import accumulate
n, k = map(int, input().split())
As = list(map(int, input().split()))
for i in range(min(41, k)):
_As = [0]*(n+1)
for j in range(n):
l = max(0, j - As[j])
r = min(n - 1, j + As[j])
_As[l] += 1
_As[r+1] -= 1
As = list(accumulate(_As))[:-1]
print(' '.join([str(A) for A in As])) | 1 | 15,430,991,095,520 | null | 132 | 132 |
n = int(input())
d = [list(map(int, input().split())) for _i in range(n)]
c = 0
for i, j in d:
if i==j:
c += 1
if c == 3:
print('Yes')
import sys
sys.exit()
else:
c = 0
print('No') | from sys import stdin,stdout
st=lambda:list(stdin.readline().strip())
li=lambda:list(map(int,stdin.readline().split()))
mp=lambda:map(int,stdin.readline().split())
inp=lambda:int(stdin.readline())
pr=lambda n: stdout.write(str(n)+"\n")
mod=1000000007
INF=float('inf')
for _ in range(1):
n=inp()
f=0
ans=0
for i in range(n):
a,b=mp()
if a==b:
ans+=1
else:
ans=0
if ans==3:
f=1
break
if f:
pr('Yes')
else:
pr('No')
| 1 | 2,491,120,569,700 | null | 72 | 72 |
import math
a,b,H,M=map(int,input().split())
h=30*H+(0.5)*M
m=6*M
c=abs(h-m)
x=math.sqrt(a**2+b**2-(2*a*b*(math.cos(math.radians(c)))))
print(x) | h=[]
for i in range(10):
h.append((int)(input()))
h.sort()
h.reverse()
for i in range(3):
print(h[i])
| 0 | null | 9,959,211,358,488 | 144 | 2 |
_ = int(input())
hoge = [int(x) for x in input().split()]
_ = int(input())
def exSearch(i, m):
if m == 0:
return True
if i >= len(hoge) or m > sum(hoge):
return False
res = exSearch(i+1, m) or exSearch(i+1, m-hoge[i])
return res
if __name__ == '__main__':
for val in (int(x) for x in input().split()):
if exSearch(0, val):
print ('yes')
else:
print ('no')
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
????????????
?????? n ?????°??? A ??¨??´??° m ???????????????A ???????´?????????????????????????????´?????¶????????????????
m ???????????????????????????????????????????????°????????????????????????????????????
AA ??????????´???????????????????????????¨?????§????????????
??°??? A ??????????????????????????§???????????¨?????? q ?????? mi ????????????????????§???
???????????????????????? "yes" ????????? "no" ??¨???????????????????????????
n ??? 20 ; q ??? 200 ; 1 ??? A???????´? ??? 2000 ; 1 ??? Mi ??? 2000
"""
def main():
""" ????????? """
n = int(input())
A = sorted(map(int,input().split()))
q = int(input())
M = list(map(int,input().split()))
g = 0
tA = []
l = 2 ** n
for i in range(1,l):
c = 0
bi = "{0:0{width}b}".format(i,width=n)
bi = bi[::-1]
for j in range(n):
if bi[j] == "1":
c += A[j]
tA.append(c)
# tA.sort()
for mi in M:
if mi in tA:
print("yes")
else:
print("no")
if __name__ == '__main__':
main() | 1 | 99,970,138,470 | null | 25 | 25 |
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"] ] ) | a, b, c, d, e, f = map(int, input().split())
S = list(input())
i = 0
number1 = a
number2 = b
number3 = c
number4 = d
number5 = e
number6 = f
while i < len(S) :
if S[i] == "N" :
number1 = b
number2 = f
number3 = c
number4 = d
number5 = a
number6 = e
elif S[i] == "S" :
number1 = e
number2 = a
number3 = c
number4 = d
number5 = f
number6 = b
elif S[i] == "E" :
number1 = d
number2 = b
number3 = a
number4 = f
number5 = e
number6 = c
elif S[i] == "W" :
number1 = c
number2 = b
number3 = f
number4 = a
number5 = e
number6 = d
a = number1
b = number2
c = number3
d = number4
e = number5
f = number6
i = i + 1
print(number1)
| 1 | 238,712,096,558 | null | 33 | 33 |
H, W = map(int, input().split())
S = [0]*(H+2)
S[0] = ''.join(['#']*(W+2))
S[-1] = ''.join(['#']*(W+2))
for i in range(1,H+1):
S[i] = '#'+input()+'#'
maxd = 0
import queue
dy = [1,0,-1,0]
dx = [0,1,0,-1]
for h in range(1,H+1):
for w in range(1,W+1):
if S[h][w]=='.':
visited = [[False]*(W+2) for _ in range(H+2)]
q = queue.Queue()
visited[h][w] = True
q.put([h,w,0])
while not q.empty():
a,b,c = q.get()
#print(a,b,c)
for i in range(4):
y,x = a+dy[i], b+dx[i]
if S[y][x]=='.' and visited[y][x]==False:
q.put([y,x,c+1])
visited[y][x]=True
maxd = max(maxd,c)
print(maxd)
| sortingThreeNum = list(map(int, input().split()))
sortingThreeNum.sort()
print(sortingThreeNum[0], sortingThreeNum[1], sortingThreeNum[2])
| 0 | null | 47,278,208,072,700 | 241 | 40 |
d = int(input())
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]
X = []
L = [-1 for j in range(26)]
for i in range(d):
max_diff = -10**10
best_j = 0
for j in range(26):
memo = L[j]
L[j] = i
diff = S[i][j] - sum([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)
for x in X:
print(x + 1)
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from time import time
from random import randint
from copy import deepcopy
start_time = time()
def calcScore(t, s, c):
scores = [0]*26
lasts = [0]*26
for i in range(1, len(t)):
scores[t[i]] += s[i][t[i]]
dif = i - lasts[t[i]]
scores[t[i]] -= c[t[i]] * dif * (dif-1) // 2
lasts[t[i]] = i
for i in range(26):
dif = len(t) - lasts[i]
scores[i] -= c[i] * dif * (dif-1) // 2
return scores
def greedy(c, s):
day_lim = len(s)
socres = [0]*26
t = [0]*day_lim
lasts = [0]*26
for i in range(1, day_lim):
pls = [v for v in socres]
mns = [v for v in socres]
for j in range(26):
pls[j] += s[i][j]
mns[j] -= c[j] * (i - lasts[j])
sum_mns = sum(mns)
pt = sum_mns - mns[0] + pls[0]
idx = 0
for j in range(1, 26):
tmp = sum_mns - mns[j] + pls[j]
if pt < tmp:
pt = tmp
idx = j
t[i] = idx
lasts[idx] = i
for j in range(26):
if j == idx:
socres[j] = pls[j]
else:
socres[j] = mns[j]
return socres, t
def subGreedy(c, s, t, day):
day_lim = len(s)
socres = [0]*26
t = [0]*day_lim
lasts = [0]*26
for i in range(1, day_lim):
if day <= i:
pls = [v for v in socres]
mns = [v for v in socres]
for j in range(26):
pls[j] += s[i][j]
mns[j] -= c[j] * (i - lasts[j])
sum_mns = sum(mns)
pt = sum_mns - mns[0] + pls[0]
idx = 0
for j in range(1, 26):
tmp = sum_mns - mns[j] + pls[j]
if pt < tmp:
pt = tmp
idx = j
t[i] = idx
lasts[idx] = i
for j in range(26):
if j == idx:
socres[j] = pls[j]
else:
socres[j] = mns[j]
else:
scores[t[i]] += s[i][t[i]]
lasts[t[i]] = i
for j in range(26):
dif = i - lasts[j]
scores[j] -= c[j] * dif
return socres, t
D = int(input())
c = list(map(int, input().split()))
s = [[0]*26 for _ in range(D+1)]
for i in range(1, D+1):
s[i] = list(map(int, input().split()))
scores, t = greedy(c, s)
sum_score = sum(scores)
while time() - start_time < 1.86:
typ = randint(1, 90)
if typ <= 70:
for _ in range(100):
tmp_t = deepcopy(t)
tmp_t[randint(1, D)] = randint(0, 25)
tmp_scores = calcScore(tmp_t, s, c)
sum_tmp_score = sum(tmp_scores)
if sum_score < sum_tmp_score:
sum_score = sum_tmp_score
t = deepcopy(tmp_t)
scores = deepcopy(tmp_scores)
elif typ <= 90:
for _ in range(30):
tmp_t = deepcopy(t)
dist = randint(1, 20)
p = randint(1, D-dist)
q = p + dist
tmp_t[p], tmp_t[q] = tmp_t[q], tmp_t[p]
tmp_scores = calcScore(tmp_t, s, c)
sum_tmp_score = sum(tmp_scores)
if sum_score < sum_tmp_score:
sum_score = sum_tmp_score
t = deepcopy(tmp_t)
scores = deepcopy(tmp_scores)
elif typ <= 100:
tmp_t = deepcopy(t)
day = randint(D//4*3, D)
tmp_scores, tmp_t = subGreedy(c, s, tmp_t, day)
sum_tmp_score = sum(tmp_scores)
if sum_score < sum_tmp_score:
sum_score = sum_tmp_score
t = tmp_t
scores = tmp_scores
for v in t[1:]:
print(v+1)
| 1 | 9,754,214,585,908 | null | 113 | 113 |
from collections import defaultdict
n = int(input())
d = list(map(int,input().split()))
dic = defaultdict(int)
ans = 1
mod = 998244353
for i in range(n):
dic[d[i]] += 1
if dic[0] == 1 and d[0] == 0:
for i in range(n):
if not (dic[i] == 0 and dic[i+1] == 0):
ans *= dic[i]**dic[i+1] % mod
ans %= mod
print(ans)
else:
print(0)
| a = int(input(""))
print(int(a*a)) | 0 | null | 150,526,430,497,850 | 284 | 278 |
from sys import stdin
while True:
arr = [int(n) for n in stdin.readline().rstrip().split()]
if arr[0] == arr[1] == 0:
break
arr.sort()
print(arr[0], arr[1])
| while True:
x,y = map(int, input().split())
if not x and not y:
break
else:
if x > y:
print(y,x)
else:
print(x,y) | 1 | 535,051,409,578 | null | 43 | 43 |
n = int(input())
p = []
for i in range(n):
x,y = map(int,input().split())
p.append([x,y])
q = []
r = []
for i in range(n):
q.append(p[i][0]+p[i][1])
r.append(p[i][0]-p[i][1])
q.sort()
r.sort()
ans = max(abs(q[-1]-q[0]),abs(r[-1]-r[0]))
print(ans) | """AtCoder Beginner Contest 178.
E
"""
import sys
def input() -> str: # noqa: A001
"""Input."""
return sys.stdin.readline()[:-1]
def calc(p1: list, p2: list) -> int:
"""Calc Manhattan Distance."""
return abs(p2[1] - p1[1]) + abs(p2[0] - p1[0])
def main():
"""Run."""
n = int(input())
patterns = {
'lt': (1, 1),
'rt': (-1, 1),
'lb': (-1, -1),
'rb': (1, -1),
}
points: dict = {k: None for k in patterns.keys()}
for _ in range(n):
p = list(map(int, input().split(' ')))
for k, (x, y) in patterns.items():
max_p = points[k]
if max_p:
max_p_pos = (max_p[0] * x) + (max_p[1] * y)
p_pos = (p[0] * x) + (p[1] * y)
if max_p_pos < p_pos:
points[k] = p
else:
points[k] = p
ans = 0
for i, p1 in enumerate(points.values()):
for p2 in list(points.values())[i + 1:]:
ans = max(ans, calc(p1, p2))
print(ans)
main()
| 1 | 3,372,022,199,788 | null | 80 | 80 |
N = int(input())
l = []
for i in range(N+1):
if i % 5 == 0 or i % 3 == 0:
l.append(0)
else:
l.append(i)
print(sum(l)) | n = int(input())
sum = (1 + n) * n // 2
sho_3 = n // 3
sho_5 = n // 5
sho_15 = n // 15
s_3 = (sho_3 * 3 + 3) * sho_3 // 2
s_5 = (sho_5 * 5 + 5) * sho_5 // 2
s_15 = (sho_15 * 15 + 15) * sho_15 // 2
print(sum - s_3 - s_5 + s_15)
| 1 | 34,982,172,284,540 | null | 173 | 173 |
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
A, B, N = I()
print(math.floor(A*min(B-1,N)/B))
| import sys,math
def solve():
a = float(input())
print(a**2*math.pi ,a*2*math.pi)
solve()
| 0 | null | 14,468,296,804,388 | 161 | 46 |
r, c = map(int, input().split())
row_lists = []
column = []
for i in range(r):
rows = list(map(int, input().split()))
row_sum = sum(rows)
rows.append(row_sum)
row_lists.append(rows)
for j in range(c+1):
tmp_list = []
for i in range(r):
tmp = row_lists[i][j]
tmp_list.append(tmp)
sum_tmp_list = sum(tmp_list)
column.append(sum_tmp_list)
# output
for i in range(r):
print(' '.join(map(str, row_lists[i])))
print(" ".join(map(str, column)))
| r, c = map(int, input().split())
data = [list(map(int, input().split())) for i in range(r)]
for i in range(r):
data[i].append(sum(data[i]))
data.append([sum(data[j][i] for j in range(r)) for i in range(c + 1)])
for i in range(r + 1):
for j in range(c + 1):
print(data[i][j], end='')
if j != c:
print(' ', end='')
print('') | 1 | 1,375,066,793,280 | null | 59 | 59 |
N=int(input())
ans=[]
for i in range(1,99):
if N>26**i:
N-=26**i
else:
N-=1
for l in range(i):
key=(chr(ord("a")+(N%26)))
N=int(N/26)
ans.append(key)
break
ans.reverse()
for i in range(len(ans)):
print(ans[i],end="") | N = int(input())
t = ""
while N > 0:
t += chr((N-1)%26 + 97)
N = (N-1)//26
print(t[::-1]) | 1 | 11,914,605,811,328 | null | 121 | 121 |
# DP法でトライ
N = int(input())
A = list(map(int, input().split()))
# i 日目に、株の売却が終了した時点の所持金の最大値
dp = [0]*N
dp[0] = 1000
for i in range(1,N):
for j in range(0,i):
dp[i] = max(dp[i], dp[i-1],(dp[j]//A[j])*A[i]+dp[j]%A[j])
print(dp[-1]) | import sys
input = sys.stdin.readline
def main():
N = int(input())
A = list(map(int, input().split()))
tmp = 1000
for i in range(N-1):
if A[i] < A[i+1]:
s = tmp//A[i]
tmp %= A[i]
tmp += s * A[i+1]
print(tmp)
if __name__ == '__main__':
main() | 1 | 7,347,318,190,540 | null | 103 | 103 |
terms = '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'.split(', ')
print(terms[int(input()) - 1]) | import sys
input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]
IN=lambda : map(int, input().split())
mod=1000000007
#+++++
def main():
ll=[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]
a = int(input())
print(ll[a-1])
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
def input_clipboard():
import clipboard
input_text=clipboard.get()
input_l=input_text.splitlines()
for l in input_l:
yield l
if __name__ == "__main__":
if sys.platform =='ios':
if input_method==input_methods[0]:
ic=input_clipboard()
input = lambda : ic.__next__()
elif input_method==input_methods[1]:
sys.stdin=open('inputFile.txt')
else:
pass
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret) | 1 | 49,894,235,139,142 | null | 195 | 195 |
s = input()
if s[-1] == 's':
s += 'es'
else:
s += 's'
print(s)
| count = int(input())
point = {'taro': 0, 'hanako': 0}
for i in range(count):
(taro, hanako) = [s for s in input().split()]
if (taro > hanako) - (taro < hanako) == 0:
point['taro'] += 1
point['hanako'] += 1
elif (taro > hanako) - (taro < hanako) > 0:
point['taro'] += 3
else:
point['hanako'] += 3
print(point['taro'], point['hanako']) | 0 | null | 2,228,103,999,250 | 71 | 67 |
n,m = input().split()
n = int(n)
m = int(m)
print(int(n*(n-1)/2+m*(m-1)/2)) | a,b = map(int,input().split())
k = str(a)
l = str(b)
X = k*b
Y = l*a
if (X < Y):
print(X)
else:
print(Y) | 0 | null | 65,108,613,583,292 | 189 | 232 |
def main():
x, y, a, b, c = list(map(int, input().split()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
P = sorted(P, reverse = True)[:x]
Q = sorted(Q, reverse = True)[:y]
ans = sorted(P + Q + R, reverse = True)
print(sum(ans[:x + y]))
if __name__ == '__main__':
main()
| X = int(input())
if X == 2:
print(2)
exit()
count = 0
if X % 2 == 0:
X += 1
while True:
now = X + count
k = 3
while k*k <= now:
if now % k == 0:
count += 2
break
else:
k += 2
continue
if k*k > now:
break
print(now) | 0 | null | 75,101,270,919,740 | 188 | 250 |
a = input().split()
b = []
for i in range(len(a)):
if a[i] == "+":
b[-2] = b[-2] + b[-1]
b.pop()
elif a[i] == "-":
b[-2] = b[-2] - b[-1]
b.pop()
elif a[i] == "*":
b[-2] = b[-2] * b[-1]
b.pop()
else:
b.append(int(a[i]))
print(b[-1])
| c = input()
cl =[chr(ord("a")+i) for i in range(26)]
print(cl[cl.index(c)+1]) | 0 | null | 46,398,895,852,658 | 18 | 239 |
N = input()
flag = 0
for n in N:
if int(n) == 7:
flag = 1
break
if flag==0:
print("No")
else:
print("Yes") | #E - Logs
import math
# 入力
N,K = map(int,input().split())
A = list(map(int,input().split()))
Amax = int(max(A))
high = Amax
Cancut = Amax
low = 0
while ( (high - low) > 0.01 ) :
Cut = 0
X = (high + low) / 2.0
for i in range(N):
Cut = Cut + math.ceil(A[i]/X) - 1
if Cut <= K:
high = X
Cancut = X
else:
low = X
# 出力
if (math.floor(high) != math.floor(low)):
Cancut = math.floor( 100 * Cancut) /100.0
print(math.ceil(Cancut)) | 0 | null | 20,513,943,632,038 | 172 | 99 |
A = int(input())
B = int(input())
print(*(set([1,2,3])-set([A,B]))) | a=int(input())
b=int(input())
ans=6-a-b
print(ans) | 1 | 110,639,691,921,252 | null | 254 | 254 |
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
firstDis = abs(A - B)
steps = (V - W)*T
print("YES" if firstDis <= steps else "NO")
| import sys
a,v = map(int, sys.stdin.readline().rstrip("\n").split())
b,w = map(int, sys.stdin.readline().rstrip("\n").split())
t = int(sys.stdin.readline().rstrip("\n"))
between = abs(b - a)
speed = v-w
if between <= speed*t:
print('YES')
else:
print('NO') | 1 | 15,202,489,188,828 | null | 131 | 131 |
s = input()
s = s[::-1]
n = len(s)
m = [0] * 2019
m[0] = 1
a = 0
d = 1
for i in range(n):
a = (a + int(s[i]) * d) % 2019
d = (d * 10) % 2019
m[a] += 1
print(sum([int(x * (x - 1) / 2) for x in m if x > 1]))
| s=input()
dic={}
cur=0
power=0
for i in range(0,len(s)+1):
s_int=len(s)-i-1
if cur in dic:
dic[cur]+=1
else:
dic[cur]=1
try:
num=int(s[s_int])
cur+=num*pow(10,power,2019)
cur%=2019
power+=1
except IndexError:
break
res=0
for i in range(len(dic)):
t=dic.popitem()
cc=t[1]
res+=cc*(cc-1)//2
print(res)
| 1 | 30,843,567,255,324 | null | 166 | 166 |
N = int(input())
L = list(map(int, input().split())) #リストで複数行作るには?
count = 0
for i in range(2, N):
for j in range(1, i):
for k in range(0, j):
if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
continue
elif L[k] < L[i] + L[j] and L[i] < L[j] + L[k] and L[j] < L[i] + L[k]:
count += 1
print(count) | import sys
sys.setrecursionlimit(300000)
from itertools import combinations
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')
N = I()
L = LMI()
ans = 0
for a, b, c in combinations(L, 3):
if a == b or b == c or c == a:
continue
if a + b > c and b + c > a and c + a > b:
ans += 1
print(ans)
| 1 | 5,060,967,777,820 | null | 91 | 91 |
n=int(raw_input())
p=[0,0]
for i in range(n):
c=[0 for i in range(100)]
c=map(list,raw_input().split())
m=0
while 1:
try:
if c[0]==c[1]:
p[0]+=1
p[1]+=1
break
elif c[0][m]<c[1][m]:
p[1]+=3
break
elif c[1][m]<c[0][m]:
p[0]+=3
break
m+=1
except IndexError:
if len(c[0])<len(c[1]):
p[1]+=3
break
if len(c[1])<len(c[0]):
p[0]+=3
break
print p[0], p[1] | N = int(input())
A = list(map(int, input().split()))
ans = 1
P = 10**18
for i in range(N):
ans *= A[i]
if ans > P:
ans = -1
break
ans = 0 if any([a==0 for a in A]) else ans
print(ans) | 0 | null | 9,154,194,617,942 | 67 | 134 |
s = list(input())
q = int(input())
l1 = []
l2 = []
rev = False
for i in range(q):
inp = input()
if inp[0] == "1":
if rev:
rev = False
else:
rev = True
elif inp[2] == "1":
a = inp[4]
if rev:
l2.append(a)
else:
l1.append(a)
else:
a = inp[4]
if rev:
l1.append(a)
else:
l2.append(a)
l1.reverse()
ans = l1 + s + l2
if rev:
ans.reverse()
print("".join(ans)) | N=int(input())
x="No"
for i in range(1,10):
if N%i==0 and N/i<10:
x="Yes"
break
print(x) | 0 | null | 108,328,010,432,700 | 204 | 287 |
# 19-String-Finding_a_Word.py
# ?????????????´¢
# ??????????????? W ??¨?????? T ????????????????????????T ??????????????? W ?????°???????????????????????°?????????????????????????????????
# ?????? T ????????????????????????????????????????????§????????????????????????????????? Ti ??¨????????????
# ???????????? Ti ?????????????????? W ??¨??????????????????????????°??????????????????
# ???????????§????????¨?°???????????????\???????????????
# Constraints
# W????????????????????????10????¶????????????????
# T??????????????????????????????????????????1000????¶????????????????
# Input
# ?????????????????? W ????????????????????????
# ?¶???????????????°????????????????????£??????????????????????????????
# END_OF_TEXT ??¨??????????????????????????????????????????????????????
# Output
# ?????? W ?????°???????????????????????????
# Sample Input
# computer
# Nurtures computer scientists and highly-skilled computer engineers
# who will create and exploit "knowledge" for the new era.
# Provides an outstanding computer environment.
# END_OF_TEXT
# Sample Output
# 3
# Note
import re
count=0
w = input().lower()
while 1:
string = input()
if string=="END_OF_TEXT":
break;
string=string.lower().split()
for i in string:
count += w==i
print(count) | n = 0
T=""
s= input().lower()
while True:
t=input()
T += t + " "
if T.count("END_OF_TEXT")>0:
break
TL = T.split(" ")
for i in TL:
i = i.replace('"','')
i= i.replace(".","")
if i.lower() == str(s):
n += 1
else:
pass
print (n) | 1 | 1,836,108,231,740 | null | 65 | 65 |
def i1():
return int(input())
def i2():
return [int(i) for i in input().split()]
mod=10**9+7
def bp(a,n):
r=1
while(n):
if n%2:
r=r*a%mod
a=a*a%mod
n>>=1
return r
[n,k]=i2()
if n<=k:
x=1
for i in range(n-1):
x*=2*n-1-i
x%=mod
y=1
for i in range(n-1):
y*=i+1
y%=mod
print((x*bp(y,10**9+5))%mod)
else:
x=1
y=1
t=1
for i in range(k):
t*=i+1
t%=mod
y*=n-1-i
y%=mod
y*=n-i
y%=mod
c=bp(t,10**9+5)
x+=y*c*c
x%=mod
print(x) | n,k=map(int,input().split())
P=10**9+7
class FactInv:
def __init__(self,N,P):
fact=[];ifact=[];fact=[1]*(N+1);ifact=[0]*(N+1)
for i in range(1,N):
fact[i+1]=(fact[i]*(i+1))%P
ifact[-1]=pow(fact[-1],P-2,P)
for i in range(N,0,-1):
ifact[i-1]=(ifact[i]*i)%P
self.fact=fact;self.ifact=ifact;self.P=P
def comb(self,n,k):
return (self.fact[n]*self.ifact[k]*self.ifact[n-k])%self.P
C=FactInv(2*n+10,P)
ans=0
for i in range(0,min(k+1,n)):
ans+=(C.comb(n,i)*C.comb(n-1,n-i-1))%P
ans%=P
print(ans) | 1 | 67,271,758,420,080 | null | 215 | 215 |
from math import gcd
A,B = [int(i) for i in input().split()]
print(A*B//gcd(A,B))
| H, W, K = map(int, input().split())
c = []
for _ in range(H):
c.append(input())
#こういうinputをすると,c_ij = c[i][j] (C[i]という文字列のj文字目)という構造になってくれて,とても嬉しい。
#print(c)
ans = 0
#bit全探索
for rows in range(1 << H):
#bit演算子。1 << H は二進数で1000...という風に,1の後ろに0がH個並ぶ。
#例えば rows = 110010 のときには,(2 ** 5ケタ目の1は無視して)(0-indexで)1行目と4行目を赤で塗る状態を指す。
for cols in range(1 << W):
black_count = 0
for i in range(H):
if (rows >> i) % 2 == 1:continue #i行目が赤で塗られていたならば,何もせずiを一歩進める。
for j in range(W):
if (cols >> j) % 2 ==1:continue #j列目が赤で塗られていたならば,何もせずjを一歩進める。
if c[i][j] == "#":
black_count += 1
if black_count == K:
ans += 1
print(ans) | 0 | null | 61,438,032,096,100 | 256 | 110 |
l = map(int, raw_input().split())
a, b, c = sorted(l)
print a, b, c | tmp = map(int, raw_input().split())
tmp.sort()
for i in tmp:
print i,
| 1 | 416,846,515,162 | null | 40 | 40 |
cnt = 0
coefficients = [1]
n = 1
_list = []
length = int(input())
for i in range(length):
try:
_list.append(int(input()))
except EOFError:
continue
for i in range(1,length):
if i < n:
continue
coefficients.append(i)
n = i*2.25 + 1
for c in coefficients[::-1]:
for i in range(length):
val = _list[i]
j = i - c
while j >= 0 and _list[j] > val:
_list[j + c] = _list[j]
j -= c
cnt += 1
_list[j+c] = val
print(len(coefficients))
print(*coefficients[::-1])
print(cnt)
print(*_list, sep='\n') | import math
n = int(input())
a = list(map(int,input().split()))
MAX = 1000005
is_prime = [1]*MAX
D = [None]*MAX
is_prime[0],is_prime[1] = 0,0
for i in range(2,MAX):
if is_prime[i]:
D[i] = i
for j in range(i*2,MAX,i):
is_prime[j] = 0
D[j] = i
counts = [0]*MAX
pair = True
for a_i in a:
if a_i == 1:
continue
pf = {}
while True:
p = D[a_i]
if counts[p]>0:
pair = False
pf[p] = pf.get(p,0)+1
if p == a_i:
break
else:
a_i //= p
for p in pf.keys():
counts[p] += 1
if pair:
print('pairwise coprime')
else:
g = a_i
for a_i in a:
g = math.gcd(a_i,g)
if g == 1:
print('setwise coprime')
else:
print('not coprime') | 0 | null | 2,078,483,552,162 | 17 | 85 |
x = int(input())
n = x//100
if x%100 <= 5*n:
print(1)
else:
print(0) | x = int(input())
q, r = divmod(x, 100)
if 0 <= r <= 5*q:
print(1)
else:
print(0)
| 1 | 127,415,354,012,220 | null | 266 | 266 |
while True:
a, b, c = input().split()
a = int(a)
c = int(c)
if b == "+":
print(a + c)
elif b == "-":
print(a - c)
elif b == '*':
print(a * c)
elif b == '/':
print(a // c)
else:
break
| N = int(input())
def solve(x1, y1, x2, y2, n):
if n == 0:
return print(x1, y1)
else:
solve(x1, y1, (2 * x1 + x2) / 3, (2 * y1 + y2) / 3, n - 1)
solve((2 * x1 + x2) / 3, (2 * y1 + y2) / 3, (x1 + x2) / 2 + (y1 - y2) * (3 ** (1 / 2)) / 6, (y1 + y2) / 2 + (x2 - x1) * (3 ** (1 / 2)) / 6, n - 1)
solve((x1 + x2) / 2 + (y1 - y2) * (3 ** (1 / 2)) / 6, (y1 + y2) / 2 + (x2 - x1) * (3 ** (1 / 2)) / 6, (x1 + 2 * x2) / 3, (y1 + 2 * y2) / 3, n - 1)
solve((x1 + 2 * x2) / 3, (y1 + 2 * y2) / 3, x2, y2, n - 1)
solve(0, 0, 100, 0, N)
print(100, 0)
| 0 | null | 396,894,522,880 | 47 | 27 |
N = int(input())
A = list(map(int,input().split()))
# for i in range(N):
# A[i] = int(i)
cMoney = 1000
stock = 0
A.append(0)
for i in range(N):
stock = 0
if A[i] < A[i+1]:
stock = cMoney // A[i]
cMoney -= stock * A[i]
cMoney += A[i+1] * stock
print(cMoney)
# for i in range(N):
# stock = 0
# if A[i] < A[i+1]:
# stock = cMoney // A[i]
# cMoney += (A[i+1] - A[i]) * stock
# print(cMoney) | from sys import stdin
inp = lambda : stdin.readline().strip()
n= int(inp())
prices = [int(x) for x in inp().split()]
money= 1000
buy = -1
if prices[0] <=money:
buy = prices[0]
for i in range(1, len(prices)):
if prices[i] > prices[i - 1]:
if buy != -1:
money = money%buy + (money//buy)*prices[i]
buy = prices[i]
else:
if prices[i] < buy and prices[i] < money:
buy = prices[i]
print(money) | 1 | 7,328,096,993,140 | null | 103 | 103 |
text = input()
q = int(input())
for _ in range(q):
ops = input().split()
if len(ops) == 3:
op, a, b = ops
else:
op, a, b, p = ops
a = int(a)
b = int(b)
if op == 'print':
print(text[a:b+1])
elif op == 'reverse':
text = text[:a] + ''.join(reversed(text[a:b+1])) + text[b + 1:]
else:
text = text[:a] + p + text[b + 1:] | def my_print(s, a, b):
print(s[a:b+1])
def my_reverse(s, a, b):
return s[:a] + s[a:b+1][::-1] + s[b+1:]
def my_replace(s, a, b, p):
return s[:a] + p + s[b+1:]
if __name__ == '__main__':
s = input()
q = int(input())
for i in range(q):
code = input().split()
op, a, b = code[0], int(code[1]), int(code[2])
if op == 'print':
my_print(s, a, b)
elif op == 'reverse':
s = my_reverse(s, a, b)
elif op == 'replace':
s = my_replace(s, a, b, code[3]) | 1 | 2,100,662,265,340 | null | 68 | 68 |
N = int(input())
A = N / 2
A = int(A)
B = (N + 1) / 2
B = int(B)
if N % 2 == 0:
print(A)
else:
print(B)
| import sys
A, B, C, D = map(int, input().split())
while A > 0 or B > 0:
C = C - B
if C <= 0:
print("Yes")
sys.exit()
A = A - D
if A <= 0:
print("No")
sys.exit() | 0 | null | 44,569,594,787,952 | 206 | 164 |
from collections import deque
k = int(input())
# 23から232(A),233(B),234(C)が作れる
# 20からは200(B),201(C)しか作れない
# 29からは298(A),299(B)しか作れない
queue = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in range(k):
x = queue.popleft()
#print(x)
# (A)の場合
if x % 10 != 0:
queue.append(10 * x + (x % 10) - 1)
# (B)の場合
queue.append(10 * x + x % 10)
# (C)の場合
if x % 10 != 9:
queue.append(10 * x + x % 10 + 1)
print(x)
| n=int(input());s=input();print('No'if s[:n//2]!=s[n//2:] else'Yes') | 0 | null | 93,387,803,154,692 | 181 | 279 |
import sys
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]
def main():
a = II()
print(a + pow(a,2) + pow(a,3))
if __name__ == "__main__":
main() | W = input()
count = 0
#T = input().lower()
#print(T)
#while T != 'END_OF_TEXT':
while True:
T = input()
if T == 'END_OF_TEXT':
break
for i in T.lower().split():
if W == i:
count += 1
#T = input().lower()
#print(i)
print(count) | 0 | null | 6,077,714,505,130 | 115 | 65 |
import math
import sys
if __name__ == '__main__':
for line in sys.stdin:
a,b = map(int,line.split())
print(math.gcd(a,b),(a*b) // math.gcd(a,b))
| a,b,k = map(int, input().split())
if k > a and k >= a+b:
print( 0 , 0 )
elif k < a :
print(a-k , b)
elif k == a:
print(0 , b)
elif k>a and k < a+b:
print(0 , b-(k-a))
| 0 | null | 51,974,679,137,888 | 5 | 249 |
n = int(input())
res = [i for i in range(3, n+1) if (i % 3 == 0) or ("3" in str(i))]
print(" ",end="")
print(*res)
| a,b,n = map(int,input().split())
if n < b:
print(a*n//b)
else:
print(a*(b-1)//b) | 0 | null | 14,511,746,138,408 | 52 | 161 |
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n, k = LI()
A = [0] + LI()
for i in range(1, n + 1):
A[i] = (A[i] + A[i - 1] - 1) % k
ans = 0
D = defaultdict(int)
for j in range(n, -1, -1):
ans += D[A[j]]
D[A[j]] += 1
if j + k - 1 < n + 1:
D[A[j + k - 1]] -= 1
if k == 1:
print(0)
else:
print(ans)
| import sys
input = sys.stdin.readline
n = int(input())
info = [0] * n
for i in range(n):
x, l = map(int, input().split())
info[i] = [x+l, x, l]
info.sort()
ans = 1
right = info[0][1] + info[0][2]
for i in range(1, n):
if right <= info[i][1] - info[i][2]:
ans += 1
right = info[i][1] + info[i][2]
print(ans) | 0 | null | 113,329,416,125,130 | 273 | 237 |
#coding: utf-8
string = str(input())
X = 0
li = []
for a in range(len(string)):
if string[a] == " ":
li.append(string[X:a])
X = a+1
li.append(string[X:])
for aa in range(len(li)):
li[aa] = int(li[aa])
h1 = li[0]
m1 = li[1]
h2 = li[2]
m2 = li[3]
k = li[4]
Time = (h2 * 60 + m2) - (h1 * 60 + m1) - k
print(int(Time)) | a,b,c=list(map(int,input().split()))
print(str(c)+" "+str(a)+" "+str(b)) | 0 | null | 28,117,856,749,388 | 139 | 178 |
while True:
(H, W) = [int(x) for x in input().split()]
if H == W == 0:
break
for row in range(H):
if row % 2 == 0:
for w in range(W):
if w % 2 == 0:
print("#", end="")
else:
print(".", end="")
else:
print()
else:
for w in range(W):
if w % 2 == 0:
print(".",end="")
else:
print("#",end="")
print()
print() | n = int(input())
d = list(map(int, input().split()))
s = 0
for i in range(n):
for j in range(n):
if i != j:
s += d[i]*d[j]
s //= 2
print(s)
| 0 | null | 84,491,754,078,808 | 51 | 292 |
# coding: utf-8
N,K=map(int,input().split())
A=list(map(int,input().split()))
MOD=10**9+7
ans=1
if K==N:
for i in range(N):
ans*=A[i]
if ans>0:
ans=ans%MOD
elif max(A)<=0 and K%2==1:
A.sort(reverse=True)
for i in range(K):
ans*=A[i]
if ans>0:
ans=ans%MOD
else:
Ap=[]
Am=[]
for i in range(N):
if A[i]>0:
Ap.append(A[i])
else:
Am.append(A[i])
Ap.sort(reverse=True)
Am.sort()
if K%2==1 and Ap:
ans*=Ap.pop(0)
P=[]
for i in range(len(Ap)//2):
P.append(Ap[i*2]*Ap[i*2+1])
for i in range(len(Am)//2):
P.append(Am[i*2]*Am[i*2+1])
P.sort(reverse=True)
for i in range(K//2):
ans*=P[i]
ans=ans%MOD
print(ans%MOD) | N = int(input())
S = int(N**(1/2))
for i in range(S,0,-1):
if N%i == 0:
A = N//i
B = i
break
print(A+B-2) | 0 | null | 85,241,261,307,648 | 112 | 288 |
n, m = map(int, input().split())
number = [0] * n
cou = [0] * n
#logging.debug(number)#
for i in range(m):
s, c = map(int, input().split())
s -= 1
if cou[s] > 0 and c != number[s]:
print(-1)
exit()
else:
cou[s] += 1
number[s] = c
#logging.debug("number = {}, cou = {}".format(number, cou))
if n > 1 and number[0] == 0 and cou[0] >= 1:
print(-1)
exit()
elif n > 1 and number[0] == 0:
number[0] = 1
number = map(str, number)
print(''.join(number)) | N, M = map(int, input().split())
d = {}
flag = True
for i in range(M):
s, c = map(int, input().split())
if s in d.keys() and d[s] != c:
flag = False
d[s] = c
if M == 0:
if N > 1: d[1] = 1
else: d[1] = 0
elif 1 not in d.keys():
d[1] = 1
elif N > 1 and d[1] == 0:
flag = False
if M != 0 and max(d.keys()) > N:
flag = False
if flag:
res = 0
for s, c in d.items():
res += c * 10 ** (N - s)
print(res)
else:
print("-1") | 1 | 60,920,973,576,512 | null | 208 | 208 |
n = int(input())
a = [int(i) for i in input().split(" ")]
t = a[0]
for i in a[1:]:
t = t ^ i
ans = [t^i for i in a]
print(" ".join(map(str, ans))) | import math
a, b, h, m = map(int, input().split())
ang = h * 30 - m * 5.5
ans = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(ang)))
print(ans)
| 0 | null | 16,382,058,368,090 | 123 | 144 |
M = 1046527
POW = [pow(4, i) for i in range(13)]
def insert(dic, string):
# i = 0
# while dic[(hash1(string) + i*hash2(string)) % M]:
# i += 1
# dic[(hash1(string) + i*hash2(string)) % M] = string
dic[get_key(string)] = string
def find(dic, string):
# i = 0
# while dic[(hash1(string) + i*hash2(string)) % M] and dic[(hash1(string) + i*hash2(string)) % M] != string:
# i += 1
# return True if dic[(hash1(string) + i*hash2(string)) % M] == string else False
# print(dic[get_key(string)], string)
return True if dic[get_key(string)] == string else False
def get_num(char):
if char == "A":
return 1
elif char == "C":
return 2
elif char == "G":
return 3
else:
return 4
def get_key(string):
num = 0
for i in range(len(string)):
num += POW[i] * get_num(string[i])
return num
def main():
n = int(input())
dic = [None] * POW[12]
# print(dic)
for i in range(n):
order, string = input().split()
if order == "insert":
insert(dic, string)
else:
if find(dic, string):
print('yes')
else:
print('no')
if __name__ == "__main__":
main()
| N = int(input())
a = list(map(int, input().split()))
x = 0
for r in a:
x ^= r
print(' '.join([str(x^r) for r in a])) | 0 | null | 6,273,359,147,026 | 23 | 123 |
# 21 import sympyが最速だが、Atcoderには無い
import math
x = int(input())
#エラトステネスの篩
n = [i for i in range(2,int(math.sqrt(x))+1)]
for i in n:
for j in n:
if j % i == 0 and j/i !=1:
n.remove(j)
while x > 0:
for i in n:
if x % i == 0:
break
else:
print(x)
break
x+=1 | x = int(input())
while True:
flag =0
for i in range(2,x//2):
if x%i==0:
flag =1
break
if flag ==0:
print(x)
exit()
x = x+1 | 1 | 105,511,052,114,780 | null | 250 | 250 |
d=int(input())
c=list(map(int,input().split()))
num=[]
for i in range(d):
num.append(list(map(int,input().split())))
ans=0
num2=[0]*26
for i in range(1,d+1):
t=int(input())
num2[t-1]=i
ans+=num[i-1][t-1]
for j in range(26):
ans-=((i-num2[j])*c[j])
print(ans)
| D = int(input())
C = list(map(int, input().split()))
S = list(list(map(int, input().split())) for i in range(D))
T = list(int(input()) for i in range(D))
manzoku = 0
yasumi= [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
#1日目
for day in range(D):
yasumi = list(map(lambda x: x + 1, yasumi))
yasumi[T[day] - 1] = 0
manzoku += S[day][T[day] - 1]
for i in range(26):
manzoku -= C[i] * yasumi[i]
print(manzoku) | 1 | 9,966,480,290,250 | null | 114 | 114 |
class COM:
def __init__(self, n: int, mod: int):
self.n = n
self.mod = mod
self.fact = [1, 1]
self.factinv = [1, 1]
self.inv = [0, 1]
for i in range(2, n + 1):
self.fact.append((self.fact[-1] * i) % mod)
self.inv.append((-self.inv[mod % i] * (mod // i)) % mod)
self.factinv.append((self.factinv[-1] * self.inv[-1]) % mod)
def get_cmb(self, n: int, k: int):
if (k < 0) or (n < k):
return 0
k = min(k, n - k)
return self.fact[n] * self.factinv[k] % self.mod * self.factinv[n - k] % self.mod
def solve():
n, k = map(int, input().split())
MOD = 10 ** 9 + 7
com = COM(n, MOD)
ans = 0
for i in range(min(n, k + 1)):
ans += com.get_cmb(n, i) * com.get_cmb(n - 1, i)
ans %= MOD
print(ans)
if __name__ == '__main__':
solve()
| N,M = map(int,input().split())
if N > M:
ans = str(M)*N
else:
ans = str(N)*M
print(ans) | 0 | null | 75,290,000,238,388 | 215 | 232 |
n=int(input())
l=[list(input().split()) for _ in range(n)]
x=input()
ans=0
for i in range(n):
s,t=l[i]
t=int(t)
ans+=t
if s==x:
c=ans
print(ans-c)
| K = int(input())
from collections import deque
q = deque(list(range(1, 10)))
ans = 0
num = 0
for i in range(K):
num = q.popleft()
ans = num
if num % 10 != 0:
q.append(num * 10 + (num % 10 - 1))
q.append(num * 10 + num % 10)
if num % 10 != 9:
q.append(num * 10 + (num % 10 + 1))
print(ans) | 0 | null | 68,479,871,769,582 | 243 | 181 |
str = input()
for q in range(int(input())):
com, *num = input().strip().split()
a, b = int(num[0]), int(num[1])
if com == 'print':
print(str[a:b+1])
elif com == 'replace':
str = str[:a] + num[2] + str[b+1:]
else: # com == 'reverse'
str = str[:a] + str[a:b+1][::-1] + str[b+1:] | temp = input()
n = int(input())
for _ in range(n):
order,a,b,*value = input().split()
a = int(a)
b = int(b)
if order == "print":
print(temp[a:b+1])
elif order == "reverse":
rev = temp[a:b+1]
temp = temp[:a] + rev[::-1] + temp[b+1:]
else:#replace
temp = temp[:a] + value[0] + temp[b+1:]
| 1 | 2,069,538,930,492 | null | 68 | 68 |
r, c = map(int, input().split())
output = []
for _ in range(r):
l = list(map(int, input().split()))
s = sum(l)
l.append(s)
output.append(l)
final = []
for i in range(c):
t = 0
for j in range(r):
t += output[j][i]
final.append(t)
s = sum(final)
final.append(s)
output.append(final)
for i in output:
print(*i)
| r, c = [int(s) for s in input().split()]
rows = [[0 for i in range(c + 1)] for j in range(r + 1)]
for rc in range(r):
in_row = [int(s) for s in input().split()]
for cc, val in enumerate(in_row):
rows[rc][cc] = val
rows[rc][-1] += val
rows[-1][cc] += val
rows[-1][-1] += val
for row in rows:
print(' '.join([str(i) for i in row])) | 1 | 1,356,232,183,788 | null | 59 | 59 |
#coding:utf-8
#?????¬???????????????
def draw_topbottom(n):
a = ""
for i in range(n):
a += "#"
print a
def draw_middle(n):
a = "#"
for i in range(n-2):
a += "."
a += "#"
print a
while 1:
HW = raw_input().split()
H = int(HW[0])
W = int(HW[1])
if H == 0 and W == 0:
break
draw_topbottom(W)
for i in range(H-2):
draw_middle(W)
draw_topbottom(W)
print "" | a,b = map(int, input().split())
ans = 0
for i in range(10000):
x = int(i*0.08)
y = int(i*0.10)
if x == a and y == b:
ans = i
break
if ans == 0:
print(-1)
exit()
print(ans)
| 0 | null | 28,624,465,341,332 | 50 | 203 |
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
n, m = l()
g = [[] for i in range(n)]
for i in range(m):
a, b = l()
g[a-1].append(b-1)
g[b-1].append(a-1)
q = deque([0])
d = [-1] * n
d[0] = 0
while q:
v = q.popleft()
for w in g[v]:
if d[w] != -1:
continue
d[w] = v
q.append(w)
if -1 in d:
print("No")
else:
print("Yes")
for di in d[1:]:
print(di+1)
| from collections import deque
n,m=map(int,input().split())
node=[[] for _ in range(n)]
for i in range(m):
a,b=map(int,input().split())
node[b-1].append(a-1)
node[a-1].append(b-1)
distance=[-1]*n
distance[0]=0
d=deque()
d.append(0)
while d:
v=d.popleft()
for i in node[v]:
if distance[i]!=-1:
continue
distance[i]=v+1
d.append(i)
print('Yes')
for i in range(1,n):
print(distance[i]) | 1 | 20,359,044,812,630 | null | 145 | 145 |
X = int(input())
q, r = divmod(X, 500)
H = q * 1000 + ((r // 5) * 5)
print(H) | X = int(input())
ans = X // 500 * 1000
ans += X % 500 // 5 * 5
print(ans) | 1 | 42,808,262,359,140 | null | 185 | 185 |
a,b = map(int, input().split())
d = a/b
r = a%b
print('%d %d %f' % (d,r,d))
| n = input()
for i in xrange(n):
tmp = map(int, raw_input().split())
if tmp[0]**2 + tmp[1]**2 == tmp[2]**2 or tmp[1]**2 + tmp[2]**2 == tmp[0]**2 or tmp[2]**2 + tmp[0]**2 == tmp[1]**2:
print "YES"
else:
print "NO" | 0 | null | 296,202,924,420 | 45 | 4 |
s = int(input())
a = [None, 0, 0] + [1] * (s - 2)
for i in range(3, s - 2):
a[i + 3] += a[i]
a[i + 1] += a[i]
print(a[s] % (10**9 + 7))
| N=int(input())
s=list()
t=list()
st=[]
for i in range(N):
st.append(input().split())
X=input()
ans=0
count=False
for j in range(N):
if count:
ans+=int(st[j][1])
if st[j][0]==X:
count=True
print(ans) | 0 | null | 50,273,318,609,392 | 79 | 243 |
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) | while True:
y,x = [int(i) for i in input().split()]
if y==x==0:
break
print('#'*x)
for i in range(y-2):
print('#'+'.'*(x-2)+'#')
if y > 1:
print('#'*x)
print() | 0 | null | 7,390,341,404,908 | 128 | 50 |
ri = lambda S: [int(v) for v in S.split()]
def rii(): return ri(input())
a, b = rii()
print(min(str(a) * b, str(b) * a)) | a, b = map(int, input().split(' '))
if a > b:
print(str(b) * a)
else:
print(str(a) * b) | 1 | 84,248,449,082,018 | null | 232 | 232 |
if __name__ == "__main__":
S = input()
list_s = [s for s in S]
ans = 0
if list_s[0] == 'S' and list_s[1] == 'S' and list_s[2] == 'S':
ans = 0
elif list_s[0] == 'S' and list_s[1] == 'S' and list_s[2] == 'R':
ans = 1
elif list_s[0] == 'S' and list_s[1] == 'R' and list_s[2] == 'R':
ans = 2
elif list_s[0] == 'R' and list_s[1] == 'R' and list_s[2] == 'R':
ans = 3
elif list_s[0] == 'R' and list_s[1] == 'S' and list_s[2] == 'R':
ans = 1
elif list_s[0] == 'R' and list_s[1] == 'R' and list_s[2] == 'S':
ans = 2
elif list_s[0] == 'R' and list_s[1] == 'S' and list_s[2] == 'S':
ans = 1
elif list_s[0] == 'S' and list_s[1] == 'R' and list_s[2] == 'S':
ans = 1
print(ans)
| S=input()
count=[0]
s=0
for i in range(3):
if S[i]=='R':
if i==2 or S[i+1]=='S':
s=s+1
count.append(s)
s=0
else:
s=s+1
print(max(count)) | 1 | 4,909,828,305,140 | null | 90 | 90 |
a = list(input())
b = list(input())
ans = 0
for p, q in zip(a, b):
if p != q:
ans += 1
print(ans)
| def solve():
a = list(input())
b = list(input())
ans = 0
for i in range(len(a)):
if a[i]!=b[i]:
ans+=1
print(ans)
solve() | 1 | 10,529,700,773,812 | null | 116 | 116 |
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
result = -float('inf')
for i in range(N):
p = P[i] - 1
c = C[p]
k = K - 1
t = c
while p != i and k != 0:
p = P[p] - 1
c += C[p]
t = max(t, c)
k -= 1
if k == 0 or c <= 0:
result = max(result, t)
continue
l = K - k
c = c * (K // l - 1)
k = K - (K // l - 1) * l
t = c
while k != 0:
p = P[p] - 1
c += C[p]
t = max(t, c)
k -= 1
result = max(result, t)
print(result)
| import sys
input = sys.stdin.readline
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
js = [None for _ in range(n)] # 周期とスコア増分
for s in range(n):
if js[s]:
continue
m = s
tmp = 0
memo = [[] for _ in range(n)]
i = 0
while True:
m = p[m] - 1
tmp += c[m]
memo[m].append((i, tmp))
if len(memo[m]) > 1:
js[m] = (memo[m][1][0] - memo[m][0][0], memo[m][1][1] - memo[m][0][1])
if len(memo[m]) > 2:
break
i += 1
ans = -100000000000
for s in range(n):
m = s
tmp = 0
visited = [0] * n
for i in range(k):
m = p[m] - 1
if visited[m]:
break
visited[m] = 1
tmp += c[m]
if js[m] and js[m][1] > 0:
ans = max(ans, tmp + js[m][1] * ((k - i - 1) // js[m][0]))
else:
ans = max(ans, tmp)
print(ans)
| 1 | 5,394,633,332,160 | null | 93 | 93 |
a, b, c = map(int, input().split())
print('Yes' if (a==b and a!=c) or (a==c and a!=b) or (b==c and b!=a) else 'No') | from sys import stdin, setrecursionlimit
def gcd(x, y):
if x % y == 0:
return y
return gcd(y, x % y)
def main():
input = stdin.buffer.readline
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [a[i] // 2 for i in range(n)]
a = list(set(a))
n = len(a)
lcm = 1
for i in range(n):
lcm = lcm * a[i] // gcd(lcm, a[i])
for i in range(n):
if (lcm // a[i] % 2) == 0:
print(0)
exit()
ans = m // lcm
print(ans - ans // 2)
if __name__ == "__main__":
setrecursionlimit(10000)
main()
| 0 | null | 84,936,869,655,978 | 216 | 247 |
# 動的計画法で求める
s = int(input())
mod = 10 ** 9 + 7
A = [0, 0, 0, 1, 1, 1, 2, 3]
for i in range(8, 2000 + 1):
ans = (sum(A[:i - 3 + 1]) + 1) % mod #Aの先頭からi-3+1までを取得
A.append(ans)#配列に結果を加える
print(A[s]) | N,M=map(int,input().split())
A=input()
List_A=A.split()
day=0
for i in range(0,M):
day=day+int(List_A[i])
if N>=day:
print(N-day)
else:
print(-1) | 0 | null | 17,737,140,086,912 | 79 | 168 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.