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
|
---|---|---|---|---|---|---|
# -*- coding: utf-8 -*-
from collections import deque
queue = deque()
input_list = [int(i) for i in input().split()]
for i in range(input_list[0]):
proc = input().split()
queue.append([proc[0],int(proc[1])])
count = 0
while len(queue) != 0:
proc = queue.popleft()
if input_list[1] < proc[1]:
queue.append([proc[0],proc[1]-input_list[1]])
count += input_list[1]
else:
count += proc[1]
print(proc[0] + ' ' + str(count))
|
n, q = [int(i) for i in input().split()]
process = []
for i in range(n):
name, time = input().split()
process.append([name, int(time)])
count = 0
while True:
if len(process) == 0: break
if process[0][1] <= q:
count += process[0][1]
print(process[0][0], count)
process[0][1] = process[0][1] - q
process.pop(0)
else:
count += q
process[0][1] = process[0][1] - q
process.append(process.pop(0))
| 1 | 44,744,232,890 | null | 19 | 19 |
#Macで実行する時
import sys
import os
if sys.platform=="darwin":
base = os.path.dirname(os.path.abspath(__file__))
name = os.path.normpath(os.path.join(base, '../atcoder/input.txt'))
#print(name)
sys.stdin = open(name)
a = str(input())
print(chr(ord(a)+1))
|
ch = ord(input().rstrip())
print(chr(ch + 1))
| 1 | 92,246,879,106,650 | null | 239 | 239 |
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]))
|
from itertools import groupby
S=input()
K=int(input())
count=0
group=[len(list(value)) for key,value in groupby(S)]
for value in group:
count+=value//2
count*=K
if S[0]==S[-1] and group[0]%2!=0 and group[-1]%2!=0:
if len(S)==group[0]:
count+=K//2
else:
count+=K-1
print(count)
| 0 | null | 95,338,174,924,200 | 132 | 296 |
print('bust' if sum(list(map(int,input().split()))) > 21 else 'win')
|
#!python3.8
# -*- coding: utf-8 -*-
# abc179/abc179_a
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
def main():
S = i2s()
if S[-1] != 's':
print(S + 's')
else:
print(S + 'es')
return
main()
| 0 | null | 60,897,799,474,160 | 260 | 71 |
cards = [
"{0} {1}".format(s, r)
for s in ('S', 'H', 'C', 'D')
for r in range(1, 13 + 1)
]
count = int(input())
for n in range(count):
card = input()
cards.remove(card)
for n in cards:
print(n)
|
n,k,c=map(int,input().split())
s=input()
l=[0]*n
pre=n+c+1
cnt=k
for i in range(n-1,-1,-1):
if s[i]=="o" and -(i)+pre>c and cnt>0:
pre=i
l[i]=cnt
cnt-=1
pre=-c-5
cnt=0
for i in range(n):
if s[i]=="o" and i-pre>c and cnt<k:
pre=i;cnt+=1
if l[i]==cnt:print(i+1)
| 0 | null | 20,821,449,179,560 | 54 | 182 |
n = int(input())
d = {}
for i in range(n):
s = input()
if s in d:
d[s] += 1
else:
d[s] = 1
mx = max(d.values())
ans = ['']
for k, v in d.items():
if v == mx:
ans.append(k)
ans.sort()
print(*ans, sep='\n')
|
import collections
N = int(input())
S = [input() for i in range(N)]
S = sorted(S)
C = collections.Counter(S)
M = C.most_common()
V = C.values()
MAX = max(V)
for i in range(len(M)):
if M[i][1] == MAX:
print(M[i][0])
| 1 | 69,761,687,924,834 | null | 218 | 218 |
X, Y, Z = list(map(int, input().split()))
print("{} {} {}".format(Z, X, Y))
|
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import itertools
import math
import sys
INF = float('inf')
def solve(X: int, Y: int, Z: int):
return f"{Z} {X} {Y}"
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
X = int(next(tokens)) # type: int
Y = int(next(tokens)) # type: int
Z = int(next(tokens)) # type: int
print(f'{solve(X, Y, Z)}')
if __name__ == '__main__':
main()
| 1 | 38,089,891,249,130 | null | 178 | 178 |
n = int(input())
A = list(map(int, input().split()))
T = [0]*n
for a in A:
T[a-1] += 1
for t in T:
print(t)
|
# B - Golden Coins
# X
X = int(input())
kiri_happy = X // 500
inaho_happy = (X - (500 * kiri_happy)) // 5
answer = (kiri_happy * 1000) + (inaho_happy * 5)
print(answer)
| 0 | null | 37,422,912,706,328 | 169 | 185 |
print(*sorted(input().split()))
|
n, m, l = map(int, raw_input().split(" "))
a = [map(int, raw_input().split(" ")) for j in range(n)]
b = [map(int, raw_input().split(" ")) for i in range(m)]
c = [[0 for k in range(l)] for j in range(n)]
for j in range(n):
for k in range(l):
for i in range(m):
c[j][k] += a[j][i] * b[i][k]
for j in range(n):
print " ".join(map(str, (c[j])))
| 0 | null | 922,386,667,770 | 40 | 60 |
x = int(input())
if x < 30:
print("No")
elif x >= 30:
print("Yes")
|
d = int(input())
if d >= 30:
print("Yes")
else:
print("No")
| 1 | 5,718,715,688,828 | null | 95 | 95 |
from collections import deque
from bisect import bisect_left
n = int(input())
l = sorted(map(int, input().split()))
ld = deque(l)
cnt = 0
for a in range(n - 2):
l_a = ld.popleft()
for b in range(a + 1, n - 1):
cnt += bisect_left(l, l_a + l[b]) - b - 1
print(cnt)
|
import math
A, B, N = map(int,input().split(' '))
def f(x):
return math.floor(A*x/B)-A*math.floor(x/B)
def main():
if N >= B:
print(f(B-1))
else:
print(f(N))
if __name__ == "__main__":
main()
| 0 | null | 100,083,415,091,012 | 294 | 161 |
N = int(input())
memo1 = []
memo2 = []
memo3 = []
memo4 = []
for i in range(N):
S = input()
sum_n = sum([1 if s=='(' else -1 for s in S])
if sum_n >= 0:
sum_n = 0
min_n = 1
for s in S:
if s == ')':
sum_n -= 1
min_n = min(min_n, sum_n)
else:
sum_n += 1
if min_n >= 0:
memo1.append([min_n, sum_n])
else:
memo2.append([min_n, sum_n])
else:
sum_n = 0
min_n = 1
for s in S[::-1]:
if s == '(':
sum_n -= 1
min_n = min(min_n, sum_n)
else:
sum_n += 1
if min_n >= 0:
memo4.append([min_n, sum_n])
else:
memo3.append([min_n, sum_n])
left = 0
for min_n, sum_n in memo1:
left += sum_n
memo2.sort(reverse=True)
for min_n, sum_n in memo2:
if left + min_n < 0:
print('No')
quit()
else:
left += sum_n
right = 0
for min_n, sum_n in memo4:
right += sum_n
memo3.sort(reverse=True)
for min_n, sum_n in memo3:
if right + min_n < 0:
print('No')
quit()
else:
right += sum_n
if left == right:
print('Yes')
else:
print('No')
|
N = int(input())
pl = []
mi = []
for i in range(N):
_m = 0
_t = 0
s = input()
for c in s:
if c == ")":
_t -= 1
_m = min(_m, _t)
else:
_t += 1
if _t > 0:
pl.append([-_m, -_t]) # sortの調整のために負にしている
else:
mi.append([- _t + _m, _m, _t])
pl = sorted(pl)
mi = sorted(mi)
#import IPython;IPython.embed()
if len(pl) == 0:
if mi[0][0] == 0:
print("Yes")
else:
print("No")
exit()
if len(mi) == 0:
print("No")
exit()
tot = 0
for m, nt in pl:
if tot - m < 0: # これはひくではないのでは?
print("No")
exit()
else:
tot -= nt
for d, m, nt in mi:
if tot + m <0:
print("No")
exit()
else:
tot += nt
if tot != 0:
print("No")
else:
print("Yes")
# どういう時できるか
# で並べ方
# tot, minの情報が必要
# totが+のものはminとtotを気をつける必要がある
# minがsum以上であればどんどん足していけばいい.
# なのでminが大きい順にsortし,totの大きい順にsort
# その次はtotがminusの中ではminが小さい順に加える
# 合計が0になる時Yes,それ意外No.
| 1 | 23,782,772,287,450 | null | 152 | 152 |
#nは問題数 mは提出した回数
n,m = map(int,input().split())
submit = []
check = [0] * n
for x in range(m):
a,b = input().split()
a = int(a)
x = [a,b]
submit.append(x)
o = 0
x = 0
for y in submit:
if check[y[0]-1] == 0:
if y[1] == "AC":
o += 1
check[y[0]-1] = 1
elif y[1] == "WA":
x += 1
for z in submit:
if check[z[0]-1] == 0:
if z[1] == "WA":
x -= 1
print(o,x)
|
n,m=map(int,input().split())
ac_cnt = set()
wa_cnt = 0
penalty = [0]*n
for i in range(m):
p,s = input().split()
num = int(p) - 1
if num not in ac_cnt:
if s == "AC":
ac_cnt.add(num)
wa_cnt += penalty[num]
else:
penalty[num] += 1
print(len(set(ac_cnt)),wa_cnt)
| 1 | 93,051,921,685,480 | null | 240 | 240 |
from sys import stdin
import math
inp = lambda : stdin.readline().strip()
n = int(inp())
a = [int(x) for x in inp().split()]
ans = 0
for i in range(1, n):
if a[i] < a[i-1]:
ans += a[i-1] - a[i]
a[i] += a[i-1] - a[i]
print(ans)
|
import sys
N = int(raw_input())
for line in sys.stdin:
a, b, c = sorted(map(int, line.split()))
if a ** 2 + b ** 2 == c ** 2:
print 'YES'
else:
print 'NO'
| 0 | null | 2,255,494,471,748 | 88 | 4 |
n, m, k = map(int, input().split())
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n-r)
return fact[n] *factinv[r]* factinv[n-r] %p
p = 998244353
N = 2 * 10**5 + 2
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
y = [0,m]
for i in range(n):
y.append((y[-1]*(m-1))%p)
r = 0
for i in range(k+1):
r = (r + y[n-i]*cmb(n-1, i, p))%p
print(r)
|
from itertools import permutations
def same(l1, l2, n):
for i in range(n):
if l1[i] != l2[i]:
return False
return True
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
P = [p-1 for p in P]
Q = [q-1 for q in Q]
for i,pattern in enumerate(permutations(range(N))):
if same(P, pattern, N):
i_p = i
if same(Q, pattern, N):
i_q = i
print(abs(i_p - i_q))
| 0 | null | 62,221,266,747,082 | 151 | 246 |
import math
import sys
import os
from operator import mul
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))
if os.getenv("LOCAL"):
inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
sys.stdin = open(inputFile, "r")
INF = float("inf")
_,k = LI()
a = LI()
a = list(map(lambda x:x-1,a))
# 訪れる順序、indexは移動回数
route = [0]
# 訪れた番号、高速検索用にhash tableを使う
visited = set([0])
next = a[0]
while True:
if next in visited:
loopStart = route.index(next)
break
else:
route.append(next)
visited.add(next)
next = a[next]
# print(route)
# print(loopStart)
beforeLoop = route[:loopStart]
# print(beforeLoop)
loop = route[loopStart:]
# print(loop)
# loop前
if k < loopStart:
ans = beforeLoop[k]
# loop後
else:
numOfLoops,mod = divmod((k-(loopStart)),len(loop))
# print(numOfLoops,mod)
ans = loop[mod]
ans += 1
print(ans)
|
N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [-1 for i in range(N+1)]
B[1] = 0
n = 1
m = 0
while 1:
n = A[n]
m += 1
if m == K:
print(n)
break
if B[n] == -1:
B[n] = m
else:
a = (K - m) % (m - B[n])
for i in range(a):
n = A[n]
print(n)
break
| 1 | 22,817,866,581,888 | null | 150 | 150 |
print((int(input())-1)>>1)
|
import math
n = int(input())
print(math.floor(n / 2) - (1-n%2))
| 1 | 153,304,004,408,036 | null | 283 | 283 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys
INF = float('inf')
def solve(N: int, P: "List[int]"):
ans = 0
l = INF
for pi in P:
l = min(l, pi)
if pi <= l:
ans += 1
return ans
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
P = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
print(f'{solve(N, P)}')
if __name__ == '__main__':
main()
|
def main():
n = int(input())
p = [int(i) for i in input().split()]
Min = [10**9]
ans = 0
for i in range(n):
Min.append(min(Min[-1],p[i]))
for i in range(n):
if Min[i]>p[i]:
ans += 1
print(ans)
main()
| 1 | 85,592,336,612,508 | null | 233 | 233 |
x = input().split()
a,b = int(x[0]),int(x[1])
print("%d %d" %(a*b,2*a+2*b))
|
l = list(map(int, input().split(" ")))
print(l[0]*l[1], (l[0]+l[1])*2)
| 1 | 308,813,107,412 | null | 36 | 36 |
import collections
import sys
import math
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def LIST() : return list(MAP())
def NIJIGEN(H): return [list(input()) for i in range(H)]
K=int(input())
if K%2==0 or K%5==0:
print(-1)
ans=7%K
for i in range(K):
if ans==0:
print(i+1)
exit()
ans=((ans*10)+7)%K
|
k = int(input())
mod = 7 % k
counter = 1
memo = 1
mod_map = set()
mod_map.add(mod)
while mod != 0:
mod = ((mod * 10) % k + 7) % k
if mod not in mod_map:
mod_map.add(mod)
else:
counter = -1
break
counter += 1
if mod == 0:
break
print(counter)
| 1 | 6,143,467,496,232 | null | 97 | 97 |
n,m = map(int,input().split())
hi = [0] + list(map(int,input().split()))
judge = [0]+[1]*(n)
for _ in range(m):
a,b = map(int, input().split())
if hi[a] >= hi[b]:
judge[b] = 0
if hi[a] <= hi[b]:
judge[a] = 0
print(sum(judge))
|
import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp
INF = inf
MOD = 1000000007
n, m = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()]for j in range(m)] # nは行数
tmp = [True for i in range(n + 1)]
res = 0
for i in range(m):
a, b = A[i]
if H[a - 1] <= H[b - 1]:
tmp[a] = False
if H[a - 1] >= H[b - 1]:
tmp[b] = False
for i in range(1, n + 1):
if tmp[i]:
res += 1
print(res)
| 1 | 25,084,632,709,280 | null | 155 | 155 |
def main():
A, B, C = map(int, input().split())
K = int(input())
while B <= A:
B *= 2
K -= 1
while C <= B:
C *= 2
K -= 1
if K >= 0:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
|
a,b,c = list(map(int,input().split()))
k = int(input())
cnt = 0
while not a < b:
b*=2
cnt+=1
while not b < c:
c*=2
cnt+=1
#print('cnt:',cnt,'k:',k)
print('Yes' if cnt <=k else 'No')
| 1 | 6,855,178,487,620 | null | 101 | 101 |
n,m,x=map(int,input().split())
c=[list(map(int,input().split())) for _ in range(n)]
import itertools
sum_min=10**7
for i in itertools.product([0,1],repeat=n):
level=[0]*m
for j in range(m):
level[j]=sum(i[k]*c[k][j+1] for k in range(n))
for l in range(m):
if level[l]<x:
break
else:
sum_min=min(sum_min,sum(i[k]*c[k][0] for k in range(n)))
print(sum_min if sum_min!=10**7 else -1)
|
N, M, X = [int(i) for i in input().split()]
CA = []
for i in range(N):
CA.append([int(j) for j in input().split()])
#print(CA)
mcost = 10**10
for i in range(2**N):
learn = [0]*M
cost = 0
bn = str(bin(i))[2:].zfill(N)
#print(bn)
for j,b in enumerate(bn):
if b == "1":
cost += CA[j][0]
for m in range(M):
learn[m] += CA[j][m+1]
learn.sort()
#print(learn)
if learn[0] >= X:
mcost = min(mcost, cost)
if mcost == 10**10:
mcost = -1
print(mcost)
| 1 | 22,288,378,423,092 | null | 149 | 149 |
n = int(input())
lis = list(map(int, input().split()))
cnt = 0
a = 1
for i in range(n):
if lis[i] == a:
cnt += 1
a += 1
if cnt == 0:
print(-1)
else:
print(n-cnt)
|
#!/usr/bin python3
# -*- coding: utf-8 -*-
r, c, k = map(int, input().split())
itm = [[0]*(c) for _ in range(r)]
for i in range(k):
ri, ci, vi = map(int, input().split())
itm[ri-1][ci-1] = vi
dp0 = [[0]*4 for c_ in range(3005)]
dp1 = [[0]*4 for c_ in range(3005)]
for i in range(r):
for j in range(c):
nowv = itm[i][j]
dp0[j][3] = max(dp0[j][3], dp0[j][2] + nowv)
dp0[j][2] = max(dp0[j][2], dp0[j][1] + nowv)
dp0[j][1] = max(dp0[j][1], dp0[j][0] + nowv)
dp0[j+1][0] = max(dp0[j+1][0], dp0[j][0])
dp0[j+1][1] = max(dp0[j+1][1], dp0[j][1])
dp0[j+1][2] = max(dp0[j+1][2], dp0[j][2])
dp0[j+1][3] = max(dp0[j+1][3], dp0[j][3])
dp1[j][0] = max(dp1[j][0], max(dp0[j]))
dp0 = dp1.copy()
print(max(dp1[c-1]))
| 0 | null | 59,810,505,773,440 | 257 | 94 |
N=int(input())
ans =0
for i in range(1,N):ans += (N-1)//i
print(ans)
|
M = 10 ** 6
d = [0] * (M+1)
for a in range(1, M+1):
for b in range(a, M+1):
n = a * b
if n > M:
break
d[n] += 2 - (a==b)
N = int(input())
ans = 0
for c in range(1, N):
ans += d[N - c]
print(ans)
| 1 | 2,585,077,741,500 | null | 73 | 73 |
n, m = map(int, input().split())
a = list (map(int, input().split()))
b = sum(a)
if n >= b:
print( n - b )
if n < b:
print( -1 )
|
N, M = map(int, input().split())
A = list(map(int, input().split()))
print(max(-1, N-sum(A)))
| 1 | 31,983,686,255,040 | null | 168 | 168 |
N, K = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
def nibu(x, arr):
if x <= arr[0]:
return len(arr)
if arr[-1] < x:
return 0
l = 0
h = len(arr) - 1
while h - l >1:
m = (l + h) // 2
if x <= arr[m]:
h = m
else:
l = m
return len(arr) - h
print(nibu(K, h))
|
from collections import deque
import copy
H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]
def bfs(x,y):
check = copy.deepcopy(S)
que = deque()
que.append((x,y))
check[y][x] = 0
while que.__len__() != 0:
x,y = que.popleft()
tmp = check[y][x]
for dx,dy in (1,0),(-1,0),(0,1),(0,-1):
sx = x + dx
sy = y + dy
if -1 < sx < W and -1 < sy < H:
if check[sy][sx] == '.':
check[sy][sx] = tmp + 1
que.append((sx,sy))
return tmp
ans = 0
for x in range(W):
for y in range(H):
if S[y][x] == '.':
ans = max(bfs(x,y),ans)
print(ans)
| 0 | null | 136,858,952,877,570 | 298 | 241 |
s=input()
t=input()
for i in range(len(s)):
if s[i]!=t[i]:
print("No")
exit()
if len(t)==len(s)+1:
print("Yes")
|
S = input()
T = input()
print('Yes' if T.startswith(S) else 'No')
| 1 | 21,418,423,355,872 | null | 147 | 147 |
n, r = map(int,input().split())
ans = r + max(10-n,0)*100
print(ans)
|
n, r = [int(_) for _ in input().split()]
print(r if n >= 10 else r + 100 * (10 - n))
| 1 | 63,610,651,944,764 | null | 211 | 211 |
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = [int(x) for x in input().split()]
from itertools import accumulate
a_csum = list(accumulate(a))
ans = 10**10
for i in range(n - 1):
ans = min(ans, abs(a_csum[i] - (a_csum[-1] - a_csum[i])))
print(ans)
|
n=input()
s=''
for i in range(1,int(n)+1):
s += (' '+str(i)) if i%3==0 or '3' in str(i) else ''
print(s)
| 0 | null | 71,668,330,192,836 | 276 | 52 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
R,C,K = map(int,readline().split())
board = [[0]*C for _ in range(R)]
for _ in range(K):
r,c,v = map(int,readline().split())
board[r-1][c-1] = v
dp0 = [[0]*C for _ in range(R)]
dp1 = [[0]*C for _ in range(R)]
dp2 = [[0]*C for _ in range(R)]
dp3 = [[0]*C for _ in range(R)]
for i in range(R):
for j in range(C):
if dp1[i][j] < dp0[i][j]+board[i][j]:
dp1[i][j] = dp0[i][j]+board[i][j]
if j>0:
if dp0[i][j] < dp0[i][j-1]:
dp0[i][j] = dp0[i][j-1]
if dp1[i][j] < dp1[i][j-1]:
dp1[i][j] = dp1[i][j-1]
if dp2[i][j] < dp2[i][j-1]:
dp2[i][j] = dp2[i][j-1]
if dp3[i][j] < dp3[i][j-1]:
dp3[i][j] = dp3[i][j-1]
if dp1[i][j] < dp0[i][j-1]+board[i][j]:
dp1[i][j] = dp0[i][j-1]+board[i][j]
if dp2[i][j] < dp1[i][j-1]+board[i][j]:
dp2[i][j] = dp1[i][j-1]+board[i][j]
if dp3[i][j] < dp2[i][j-1]+board[i][j]:
dp3[i][j] = dp2[i][j-1]+board[i][j]
if i>0:
if dp0[i][j] < dp0[i-1][j]:
dp0[i][j] = dp0[i-1][j]
if dp0[i][j] < dp1[i-1][j]:
dp0[i][j] = dp1[i-1][j]
if dp0[i][j] < dp2[i-1][j]:
dp0[i][j] = dp2[i-1][j]
if dp0[i][j] < dp3[i-1][j]:
dp0[i][j] = dp3[i-1][j]
if dp1[i][j] < dp0[i-1][j]+board[i][j]:
dp1[i][j] = dp0[i-1][j]+board[i][j]
if dp1[i][j] < dp1[i-1][j]+board[i][j]:
dp1[i][j] = dp1[i-1][j]+board[i][j]
if dp1[i][j] < dp2[i-1][j]+board[i][j]:
dp1[i][j] = dp2[i-1][j]+board[i][j]
if dp1[i][j] < dp3[i-1][j]+board[i][j]:
dp1[i][j] = dp3[i-1][j]+board[i][j]
print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]))
|
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
b = 0
tb = 0
for i in range(M):
if tb + B[i] > K:
break
tb += B[i]
b = i+1
ans = [0, b]
m = b
a = 0
ta = 0
for i in range(N):
if ta + A[i] > K:
break
a = i+1
ta += A[i]
while True:
if ta + tb > K:
if b == 0:break
b -= 1
tb -= B[b]
else:
if a + b > m:
m = a + b
ans = [a, b]
break
print(ans[0]+ans[1])
| 0 | null | 8,098,763,053,500 | 94 | 117 |
from collections import deque
N, M = [int(x) for x in input().split()]
conn = [[] for _ in range(N + 1)]
for i in range(M):
A, B = [int(x) for x in input().split()]
conn[A].append(B)
conn[B].append(A)
q = deque([1])
signpost = [0] * (N + 1)
while q:
v = q.popleft()
for w in conn[v]:
if signpost[w] == 0:
signpost[w] = v
q.append(w)
print('Yes')
for i in range(2, N + 1):
print(signpost[i])
|
import sys
import os
import math
import bisect
import itertools
import collections
import heapq
import queue
import array
# 時々使う
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque
# 再帰の制限設定
sys.setrecursionlimit(10000000)
def ii(): return int(sys.stdin.buffer.readline().rstrip())
def il(): return list(map(int, sys.stdin.buffer.readline().split()))
def fl(): return list(map(float, sys.stdin.buffer.readline().split()))
def iln(n): return [int(sys.stdin.buffer.readline().rstrip())
for _ in range(n)]
def iss(): return sys.stdin.buffer.readline().decode().rstrip()
def sl(): return list(map(str, sys.stdin.buffer.readline().decode().split()))
def isn(n): return [sys.stdin.buffer.readline().decode().rstrip()
for _ in range(n)]
def lcm(x, y): return (x * y) // math.gcd(x, y)
# MOD = 10 ** 9 + 7
MOD = 998244353
INF = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N, K = il()
D = [il() for _ in range(K)]
dp = [0] * (N)
dp[0] = 1
acc = 0
for i in range(1, N):
for l, r in D:
if i - l >= 0:
acc += dp[i-l]
acc %= MOD
if i - r - 1 >= 0:
acc -= dp[i-r-1]
acc %= MOD
dp[i] = acc
print(dp[-1])
if __name__ == '__main__':
main()
| 0 | null | 11,675,875,008,952 | 145 | 74 |
while True:
n,x=map(int,input().split())
a=0
if n==0 and x==0:break
for i in range(1,n+1):
for j in range(1,i):
for k in range(1,j):
if i+j+k==x:a+=1
print(a)
|
class Dice(object):
def __init__(self, line):
self.top = 1
self.bottom = 6
self.south = 2
self.east = 3
self.west = 4
self.north = 5
self.convert = [int(s) for s in line.split()]
def move(self, direction):
if 'N' == direction:
self.top, self.north, self.bottom, self.south = self.south, self.top, self.north, self.bottom
elif 'S' == direction:
self.top, self.north, self.bottom, self.south = self.north, self.bottom, self.south, self.top
elif 'W' == direction:
self.top, self.east, self.bottom, self.west = self.east, self.bottom, self.west, self.top
elif 'E' == direction:
self.top, self.east, self.bottom, self.west = self.west, self.top, self.east, self.bottom
def search(self, line):
top, south = [int(s) for s in line.split()]
for direction in 'NNNNWNNNN':
self.move(direction)
if self.convert[self.south - 1] == south:
break
for direction in 'WWWW':
self.move(direction)
if self.convert[self.top - 1] == top:
break
return self.result()
def result(self):
return self.convert[self.east - 1]
dice = Dice(input())
for i in range(int(input())):
print(dice.search(input()))
| 0 | null | 762,302,735,392 | 58 | 34 |
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()
|
k = int(input())
s = input()
mod = 10**9 + 7
ans = 0
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):
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
comb = Combination(2*10**6+10)
for i in range(k+1):
ans += pow(25, k-i, mod) * pow(26, i, mod) * comb(len(s)+k-i-1, len(s)-1)
ans %= mod
print(ans)
| 0 | null | 31,415,963,206,210 | 195 | 124 |
A,B,C=map(int,input().split())
K=int(input())
D=[]
for i in range(K):
for j in range(K-i):
if A*(2**i)<B*(2**j) and B*(2**j)<C*(2**(K-i-j)):
D.append('Yes')
else:
D.append('No')
if ('Yes' in D)==True:
print('Yes')
else:
print('No')
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
S,T = readline().decode().rstrip().split()
ans = ''
for i in range(N):
ans += S[i] + T[i]
print(ans)
| 0 | null | 59,336,605,950,788 | 101 | 255 |
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 8 20:45:37 2020
@author: liang
"""
def gcc(a,b):
if b == 0:
return a
return gcc(b, a%b)
A, B = map(int, input().split())
if A < B:
A ,B = B, A
print(A*B//gcc(A,B))
|
n, k = map(int, input().split())
ps = []
MOD = 998244353
s = set()
for _ in range(k):
l,r = map(int, input().split())
ps.append([l,r])
dp = [0] * (n+1)
dp[0] = 1
acc = [0,1]
for i in range(1,n):
for l, r in ps:
dp[i] += acc[max(0,i-l+1)] - acc[max(0,i-r)]
acc.append((acc[i] + dp[i])%MOD)
print(dp[n-1]%MOD)
| 0 | null | 58,119,322,327,404 | 256 | 74 |
#B
A, B, C, D=map(int, input().split())
A_survive=0
C_survive=0
while A>0:
A-=D
A_survive+=1
while C>0:
C-=B
C_survive+=1
if A_survive >= C_survive:
print('Yes')
else:
print('No')
|
from itertools import permutations
n = int(input())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
perm = list(permutations(sorted(p), n)) #; print(perm)
a = perm.index(tuple(p))
b = perm.index(tuple(q))
print(abs(a-b))
| 0 | null | 64,895,090,931,108 | 164 | 246 |
from sys import stdin
n, k, s = map(int, stdin.readline().rstrip().split())
flag = 0
for i in range(n):
if flag < k:
print(s)
flag += 1
else:
if s == 10 ^ 9:
print(s-1)
else:
if s == 1:
print(2)
else:
print(s-1)
|
n = int(input())
s = input()
res = 0
tem = s.find('WR')
if tem == -1:
print(res)
else:
i, j = 0, len(s)-1
while i<j:
while i < j and s[i] != 'W': i+=1
while i < j and s[j] != 'R':j -= 1
if s[i] == 'W' and s[j] == 'R':
res += 1
i += 1
j -= 1
print(res)
| 0 | null | 48,765,401,054,172 | 238 | 98 |
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): 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)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
n,m,x = I()
book = [l() for i in range(n)]
money = []
for i in range(2**n):
ccc = 0
bag = [0]*(m+1)
for j in range(n):
for k in range(m+1):
if ((i>>j)&1):
bag[k] += book[j][k]
for p in range(1,m+1):
if bag[p] >= x:
ccc += 1
if ccc == m:
money.append(bag[0])
if len(money) == 0:
print(-1)
else:
print(min(money))
|
x = int(input())
x500 = x // 500
y = x - x500*500
y5 = y // 5
z = y - y5*5
print(x500*1000+y5*5)
| 0 | null | 32,468,447,415,588 | 149 | 185 |
a, b = map(int, input().split())
c = list(map(int, input().split()))
if a >= sum(c):
print(a - sum(c))
else:
print('-1')
|
from collections import deque
import sys
def input():
return sys.stdin.readline().strip()
q = deque(input())
Q = int(input())
flipped = False
for _ in range(Q):
q_t, *q_b = input().split()
if q_t == "1":
flipped = not flipped
else:
F, C = q_b
if (F == "2" and not flipped) or (F == "1" and flipped):
q.append(C)
else:
q.appendleft(C)
q = list(q)
if flipped:
print("".join(q[::-1]))
else:
print("".join(q))
| 0 | null | 44,793,823,048,702 | 168 | 204 |
def solve():
# tmp_max = P[0]
tmp_min = P[0]
cnt = 1
for i in range(0,N):
if P[i] < tmp_min:
tmp_min = P[i]
cnt += 1
print(cnt)
if __name__ == "__main__":
N = int(input())
P = list(map(int, input().split()))
solve()
|
import sys
input = sys.stdin.readline
n, s, c = int(input()), list(map(int, input().split())), 0
m = s[0]
for i in range(n):
if s[i] <= m: m = s[i]; c += 1
print(c)
| 1 | 85,416,192,148,938 | null | 233 | 233 |
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 6 12:21:24 2020
@author: liang
"""
import math
pi = 3.141592653589793238
h, m, H, M = map(int,input().split())
print(math.sqrt(h**2+m**2-2*h*m*math.cos(2*pi*(30*H-5.5*M)/360)))
|
R,G,B=map(int,input().split())
K=int(input())
M=0
while R>=G or G>=B:
if R>=G:
G*=2
M+=1
if G>=B:
B*=2
M+=1
if M<=K:
print('Yes')
else:
print('No')
| 0 | null | 13,517,906,384,192 | 144 | 101 |
# -*- coding: utf-8 -*-
#https://mathtrain.jp/tyohukuc
n, m, k = map(int,input().split())
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 998244353
N = n+1 # N は必要分だけ用意する
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
ans = 0
beki = [1,m-1]
for i in range(2,N+1):
beki.append(((beki[-1]*(m-1)) % p))
for x in range(k+1):
ans += m * beki[n-x-1] %p * cmb(n-1,x,p) %p
ans = ans % p
print(ans)
|
#import numpy as np
import math
#from decimal import *
#from numba import njit
#@njit
def main():
(N, M, K) = map(int, input().split())
MOD = 998244353
fact = [1]*(N+1)
factinv = [1]*(N+1)
for i in range(1,N+1):
fact[i] = fact[i-1]*i % MOD
factinv[i] = pow(fact[i], MOD-2, MOD)
def comb(n, k):
return fact[n] * factinv[k] * factinv[n-k] % MOD
ans = 0
for k in range(K+1):
ans += (comb(N-1,k)*M*pow(M-1, N-k-1, MOD))%MOD
print(ans%MOD)
main()
| 1 | 23,267,800,063,326 | null | 151 | 151 |
#ABC167
A,B,C,K=map(int,input().split())
#----------以上入力----------
if A > K:
print(K)
elif A+B >= K:
print(A)
else:
print(A-(K-A-B))
|
K,X=map(int,input().split())
print("YNeos"[500*K<X::2])
| 0 | null | 59,902,039,153,092 | 148 | 244 |
# coding: utf-8
n, m = map(int, input().split())
matrixA = []
vectorB = []
for i in range(n):
matrixA.append(list(map(int, input().split())))
for i in range(m):
vectorB.append(int(input()))
for i in range(n):
num = 0
for j in range(m):
num += matrixA[i][j] * vectorB[j]
print(num)
|
class Dice(object):
def __init__(self, nums):
self.top, self.front, self.right, self.left, self.back, self.bottom = nums
def roll(self, directions):
if directions == 'E':
self.top, self.right, self.left, self.bottom = self.left, self.top, self.bottom, self.right
return
if directions == 'N':
self.top, self.front, self.back, self.bottom = self.front, self.bottom, self.top, self.back
return
if directions == 'S':
self.top, self.front, self.back, self.bottom = self.back, self.top, self.bottom, self.front
return
if directions == 'W':
self.top, self.right, self.left, self.bottom = self.right, self.bottom, self.top, self.left
return
self.roll(directions[0])
self.roll(directions[1:])
if __name__ == '__main__':
nums = [int(i) for i in input().split()]
d = Dice(nums)
q = int(input())
for i in range(q):
top, front = [int(x) for x in input().split()]
if(top == d.front):
d.roll('N')
elif(top == d.right):
d.roll('W')
elif(top == d.left):
d.roll('E')
elif(top == d.back):
d.roll('S')
elif(top == d.bottom):
d.roll('NN')
if(front == d.right):
d.roll('WSE')
elif(front == d.left):
d.roll('ESW')
elif(front == d.back):
d.roll('SENWSE')
print(d.right)
| 0 | null | 701,929,096,980 | 56 | 34 |
N = int(input())
A = []
for n in range(1,10):
for m in range(1,10):
A.append(n*m)
if N in A:
print("Yes")
else:
print("No")
|
N = int(input())
ans = False
for i in range(1,10):
if N % i == 0 and N / i <= 9:
ans = True
if ans:
print("Yes")
else:
print("No")
| 1 | 160,082,102,773,168 | null | 287 | 287 |
n=int(input())
a=list(map(int,input().split()))
l=[0,0,0]
mod=10**9+7
ans=1
for i in a:
ans*=l.count(i)
ans%=mod
for j in range(3):
if l[j]==i:
l[j]+=1
break
print(ans)
|
n=int(input())
a=list(map(int,input().split()))
if a[0]!=0:
print(0)
exit()
r=1
b=0
g=0
pos=3
for i in range(1,n):
pre=0
de=0
if a[i]==r:
pre += 1
r += 1
de=1
if a[i]==b:
pre += 1
if de==0:
b += 1
de=1
if a[i]==g:
pre += 1
if de==0:
g += 1
pos *= pre
print(pos%(10**9+7))
| 1 | 130,415,344,314,500 | null | 268 | 268 |
N,K=map(int,input().split())
A=list(map(int,input().split()))
B=[1]
C=["#"]*N
roop=False
for i in range(K):
if C[B[i]-1]=="#":
C[B[i]-1]="$"
else:
roop=True
break
B.append(A[B[i]-1])
if roop==True:
f=B.index(B[i])
T=i-f
if T==0:
print(B[f])
else:
r=(K-f)%T
print(B[f+r])
else:
print(B[K])
|
def main():
k, n = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
d =[min(a)+k-max(a)]
for i in range(n-1):
d.append(a[i+1]-a[i])
print(k-max(d))
if __name__ == "__main__":
main()
| 0 | null | 32,983,924,359,584 | 150 | 186 |
s = input()
p = input()
s += s[:len(p)-1]
if s.find(p) >= 0:
print('Yes')
else:
print('No')
|
n = int(input())
x = list(map(int,input().split()))
ans = 1000000000000
for i in range(1,101):
b = 0
for num in x:
b += (num - i)**2
ans = min(b,ans)
print(ans)
| 0 | null | 33,389,053,747,192 | 64 | 213 |
# -*- coding: utf-8 -*-
ABC = input()
ABC = ABC.replace(" ", "")
if ABC.count(ABC[0]) == 2 or ABC.count(ABC[1]) == 2 or ABC.count(ABC[2]) == 2:
print("Yes")
else:
print("No")
|
###2分探索
import sys
N,K = map(int,input().split())
A = list(map(int,input().split()))
p = 0###無理(そこまで小さくできない)
q = max(A)###可能
if K == 0:
print(q)
sys.exit(0)
while q-p > 1:
r = (p+q)//2
count = 0
for i in range(N):
if A[i]/r == A[i]//r:
count += A[i]//r - 1
else:
count += A[i]//r
if count > K:
p = r
else:
q = r
#print(p,q)
print(q)
| 0 | null | 37,291,126,349,150 | 216 | 99 |
def solve():
N, K, C = map(int, input().split())
workable = [i for i, s in enumerate(input()) if s=="o"]
if len(workable) == K:
return workable
latest = set()
prev = workable[-1]+C+1
for x in reversed(workable):
if prev - x > C:
latest.add(x)
prev = x
if len(latest) > K:
return []
must = []
prev = -C-1
for x in workable:
if x - prev > C:
if x in latest:
must.append(x)
prev = x
return must
for i in solve():
print(i+1)
|
def greedy_sche(read_dir=1):
res = []
i = 1 if read_dir == 1 else n
cnt = 1
while cnt <= k:
if s[i - 1]:
res.append(i)
cnt += 1
i += read_dir * (c + 1)
else:
i += read_dir
return res
n, k, c = map(int, input().split())
s = [c == 'o' for c in input()]
[print(f) for f, b in zip(greedy_sche(1), greedy_sche(-1)[::-1]) if f == b]
| 1 | 40,409,553,283,492 | null | 182 | 182 |
n, k = map(int, input().split())
d = [[], []]
for _ in range(k):
l, r = map(int, input().split())
d[0].append(l-1)
d[1].append(r-1)
dp = [0]*n
dp[0] = 1
a = [0]*(n+1)
a[1] = dp[0]
for i in range(1, n):
for j in range(k):
r = i - d[0][j]
l = i - d[1][j]
if l < 1:
l = 1
if r < 0:
continue
dp[i] += a[r] - a[l-1]
dp[i] %= 998244353
a[i+1] = (a[i] + dp[i]) % 998244353
print(dp[-1])
|
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions import gcd
#input=sys.stdin.readline
import bisect
s=input()
t=input()
n=len(s)
ans=0
for i in range(n):
if s[i]!=t[i]:
ans+=1
print(ans)
| 0 | null | 6,534,044,195,820 | 74 | 116 |
N = int(input())
S,T = input().split()
L = []
for n in range(N):
L.append(S[n])
L.append(T[n])
print(*L,sep="")
|
n=int(input())
s,t=input().split()
l=[]
for i in range(2*n):
if i%2==0:
l.append(s[i//2])
else:
l.append(t[(i-1)//2])
l=''.join(l)
print(l)
| 1 | 112,065,345,346,720 | null | 255 | 255 |
a = input()
if 'a' <= a <= 'z':
print("a")
else:
print("A")
|
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)
| 1 | 11,270,970,977,488 | null | 119 | 119 |
import collections
N=int(input())
D=list(map(int,input().split()))
mod=998244353
if D[0]!=0:
print(0);exit()
D=collections.Counter(D)
if D[0]!=1:
print(0);exit()
ans=1
for i in range(1,len(D)):
ans*=pow(D[i-1],D[i],mod)
ans%=mod
print(ans)
|
n=int(input())
d=list(map(int,input().split()))
mx=max(d)
l=[0]*(10**5)
mx=0
for i in range(n):
if (i==0 and d[i]!=0) or (i!=0 and d[i]==0):
print(0)
exit()
l[d[i]]+=1
mx=max(mx,d[i])
t=1
ans=1
for i in range(1,mx+1):
ans *= t**l[i]
t=l[i]
print(ans%998244353)
| 1 | 154,999,529,965,310 | null | 284 | 284 |
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
import random
J=998244353
########################################################
n,k=INPUT()
A=[]
for i in range(k):
x,y=INPUT()
A.append([x,y])
A.sort()
s,e=-1,-1
S=[]
for i in range(len(A)):
if i==0:
S.append([A[i][0],A[i][1]])
else:
if A[i][0]>S[-1][1]:
S.append([A[i][0],A[i][1]])
else:
S[-1][1]=A[i][1]
cum=[0]*(n+1)
dp=[0]*(n+1)
dp[1]=1
cum[1]=1
for i in range(2,n+1):
for ele in S:
x=ele[0]
y=ele[1]
dp[i]=(dp[i]+cum[max(i-x,0)]-cum[max(0,i-y-1)])%J
cum[i]=(cum[i-1]+dp[i])%J
print(dp[n])
|
n, k = map(int, input().split())
# n, k = (2*10**5, 10)
ranges = []
for i in range(k):
l, r = map(int, input().split())
# f = (2 * 10 ** 5) // k
# l, r = (f * i, f*(i+1))
ranges.append((l, r))
mod = 998244353
counts = [0]*(n+1)
sum_dp = [0]*(n+2)
counts[0] = 1
sum_dp[1] = 1
for i in range(1, n+1):
for r in ranges:
left = max(0, i - r[1])
right = max(0, i - r[0] + 1)
counts[i] += (sum_dp[right] - sum_dp[left])
counts[i] = counts[i] % mod
sum_dp[i+1] = sum_dp[i] + counts[i]
print(counts[n-1] % mod)
| 1 | 2,700,705,162,610 | null | 74 | 74 |
n,m,l = map(int,input().split())
a = [list(map(int,input().split(" "))) for i in range(n)]
b = [list(map(int,input().split(" "))) for j in range(m)]
for i in range(n):
for j in range(l):
c = 0
for k in range(m):
c += a[i][k]*b[k][j]
print(c,end="")
if j != l-1:
print("",end=" ")
print()
|
n=int(input())
s=["AC","WA","TLE","RE"]
c=[0]*4
for _ in range(n):
c[s.index(input())]+=1
for s1,c1 in zip(s,c):
print(f'{s1} x {c1}')
| 0 | null | 5,079,775,162,272 | 60 | 109 |
import math
import itertools
def distance(p1, p2):
return math.sqrt((p1[0]-p2[0])**2 + (p1[1] - p2[1])**2)
n = int(input())
adj = {}
for i in range(1, n+1):
x, y = map(int, input().split())
adj[i] = (x, y)
dd = {}
ans = 0
for i in range(1, n):
for j in range(i+1, n+1):
dist = distance(adj[i], adj[j])
ans += dist
print(format((2 * ans) / n, '.10f'))
|
#!/usr/bin/env python3
import math
def solver(visited, coord, depth = 0):
dists = []
if len(visited) == depth:
for i in range(1, len(visited)):
x1, y1 = coord[visited[i - 1]][0], coord[visited[i - 1]][1]
x2, y2 = coord[visited[i]][0], coord[visited[i]][1]
dists.append(math.sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)))
return sum(dists)
for i in range(0, len(visited)):
if visited[i] != -1: continue
visited[i] = depth
dists.append(solver(visited, coord, depth + 1))
visited[i] = -1;
return sum(dists)
def main():
n = int(input())
coord = []
for i in range(0, n):
coord.append([int(c) for c in input().split()])
print(solver([-1 for i in range(0, n)], coord) / math.factorial(n))
if __name__ == "__main__":
main()
| 1 | 148,689,939,848,528 | null | 280 | 280 |
def main():
n,p = map(int,input().split())
s = input()
if p == 2:
ans = 0
for i in range(n):
if int(s[i])%2 == 0:
ans += i+1
print(ans)
return
if p == 5:
ans = 0
for i in range(n):
if int(s[i])%5 == 0:
ans += i+1
print(ans)
return
dp = [0 for _ in range(p)]
dp[0] += 1
x = 0
for i in range(n):
x = (x+int(s[n-1-i])*pow(10,i,p))%p
dp[x] += 1
ans = 0
for i in range(p):
ans += (dp[i]*(dp[i]-1))//2
print(ans)
if __name__ == "__main__":
main()
|
a, b = map(int, input().split())
al = []
b_lis = []
for _ in range(a):
g = list(map(int, input().split()))
g.append(sum(g))
al.append(g)
for i in range(b+1):
p = 0
for j in range(a):
p += al[j][i]
b_lis.append(p)
al.append((b_lis))
for i in al:
print(' '.join([str(v) for v in i]))
| 0 | null | 29,601,745,178,218 | 205 | 59 |
print(int(input()[:2] != input()[:2]))
|
# coding: utf-8
M1, D1 = (int(x) for x in input().split())
M2, D2 = (int(x) for x in input().split())
if M1 == M2: print(0)
else: print(1)
| 1 | 123,850,534,334,462 | null | 264 | 264 |
n=int(input())
a=list(map(int,input().split()))
num=[i for i in range(1,n+1)]
order=dict(zip(num,a))
order2=sorted(order.items(),key=lambda x:x[1])
ans=[]
for i in range(n):
ans.append(order2[i][0])
print(' '.join([str(n) for n in ans]))
|
N = int(input())
st = []
for _ in range(N):
s,t = map(str,input().split())
st.append((s,int(t)))
X = input()
ans = 0
flag = False
for s,t in st:
if flag:
ans += t
if s == X:
flag = True
print(ans)
| 0 | null | 138,341,003,283,042 | 299 | 243 |
def arg(operator):
try:
return elements.index(operator)
except:
return 100000000000000
elements = [elem if elem in ['+', '-', '*']
else int(elem) for elem in input().split()]
while len(elements) != 1:
if arg('+') or arg('-') or arg('*'):
i = arg('+')
i = min(i, arg('-'))
i = min(i, arg('*'))
if elements[i] == '+': r = elements[i-2] + elements[i-1]
elif elements[i] == '-': r = elements[i-2] - elements[i-1]
elif elements[i] == '*': r = elements[i-2] * elements[i-1]
# i, i-1, i-2 -> one element
elements = elements[:i-2] + [r] + elements[i+1:]
else:
break
print(elements[0])
|
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np # cumsum
# from bisect import bisect_left, bisect_right
def solve():
N, M = MI()
A = LI()
ans = N - sum(A)
print(-1 if ans < 0 else ans)
if __name__ == '__main__':
solve()
| 0 | null | 15,932,866,141,478 | 18 | 168 |
def gcd2(x,y):
if y == 0: return x
return gcd2(y,x % y)
def lcm2(x,y):
return x // gcd2(x,y) * y
a,b = map(int,input().split())
print(lcm2(a,b))
|
import math
A,B = map(int,input().split())
#print(math.gcd(A,B))
C = A*B //(math.gcd(A,B))
print(C)
| 1 | 113,038,470,741,152 | null | 256 | 256 |
n=int(input())
l=[['a1']]+[[] for _ in range(9)]
for i in range(9):
for b in l[i]:
t=b[-1]
for p in range(int(t)):
l[i+1].append(b[:-1]+chr(97+p)+t)
l[i+1].append(b[:-1]+chr(97+int(t))+str(int(t)+1))
for i in l[n-1]:
if len(i)==12:
print(i[:-2])
else:
print(i[:-1])
|
nS = int(input())
S = list(map(int,input().split()))
nQ = int(input())
Q = list(map(int,input().split()))
cnt = 0
for i in range(nQ):
copy_S = S.copy()
copy_S.append(Q[i])
j = 0
while copy_S[j] != Q[i]:
j += 1
if j < len(copy_S)-1 : cnt += 1
print(cnt)
| 0 | null | 26,144,139,813,262 | 198 | 22 |
h1,m1,h2,m2,k = map(int,input().split())
okiteiru = (h2*60+m2)-(h1*60+m1)
print(okiteiru - k)
|
import math
import re
import copy
h1,m1,h2,m2,k = map(int,input().split())
w1 = h1*60 + m1
w2 = h2 * 60 + m2
w3 = (w2-w1+24*60)%(24*60)
w3 = w3 - k
print(w3)
| 1 | 18,078,475,567,268 | null | 139 | 139 |
H,W=map(int,input().split())
s=[input()for _ in range(H)]
a=[[0]*W for _ in range(H)]
for i in range(H):
for j in range(W):
if i==j==0:a[0][0]=0
elif i==0:a[0][j]=a[0][j-1]if s[0][j]==s[0][j-1]else a[0][j-1]+1
elif j==0:a[i][0]=a[i-1][0]if s[i][0]==s[i-1][0]else a[i-1][0]+1
else:a[i][j]=min(a[i][j-1]if s[i][j]==s[i][j-1]else a[i][j-1]+1,a[i-1][j]if s[i][j]==s[i-1][j]else a[i-1][j]+1)
print((a[H-1][W-1]+1)//2 if s[0][0]=='.'else a[H-1][W-1]//2+1)
|
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N =I()
_P= LI()
#AB = [LI() for _ in range(N)]
#A,B = zip(*AB)
P = np.array(_P)
#C = np.zeros(N + 1)
def main():
# count = 1
# # if (len(P)==1):
# # return count
# min_array =[P[0]]
# for i in range(1,N):
# if (P[i]<=min_array[i-1]):
# count += 1
# if P[i-1]>P[i]:
# min_array.append(P[i])
# else:
# min_array.append(P[i-1])
# return count
# print(min_array)
Q = np.minimum.accumulate(P)
count = np.count_nonzero(P <= Q)
return count
print(main())
# if ans:
# print('Yes')
# else:
# print('No')
| 0 | null | 67,156,798,244,470 | 194 | 233 |
a = list(reversed(sorted([int(raw_input()) for _ in range(10)])))
print a[0]
print a[1]
print a[2]
|
import sys
a = list(map(int,sys.stdin.readlines()))
for i in range(10):
for j in range(i+1,10):
if a[i] < a[j]:
a[i],a[j] = a[j],a[i]
for i in range(3):
print(a[i])
| 1 | 11,211,642 | null | 2 | 2 |
a = int(input())
a-=1
cnt = 0
for i in range(1,a):
if i < a:
a -= 1
cnt += 1
else :
break
print (cnt)
|
n = int(input())
s = str(input())
if n % 2 == 1:
print("No")
exit()
if s[:n // 2] == s[n // 2:]:
print("Yes")
exit()
print("No")
| 0 | null | 150,008,320,278,560 | 283 | 279 |
print("bust") if sum(list(map(int,input().split()))) > 21 else print("win")
|
N = int(input())
A = list(map(int, input().split()))
D = {}
for i in range(N):
i+=1
D.update([(A[i-1], i)])
ans = []
for i in range(1, N+1):
ans.append(D[i])
str_ans = list(map(str, ans))
print(' '.join(str_ans))
| 0 | null | 149,877,666,973,738 | 260 | 299 |
m1,_ = input().split()
m2,_ = input().split()
ans = 0
if m1 != m2:
ans = 1
print(ans)
|
M1,D1=list(map(int, input().split()))
M2,D2=list(map(int, input().split()))
if (M1==M2-1 or M1-M2==11) and D2==1:
print(1)
else:
print(0)
| 1 | 124,245,383,652,740 | null | 264 | 264 |
n, m = (int(x) for x in input().split())
n1, m1 = (int(a) for a in input().split())
if n==n1:
print('0')
else:
print('1')
|
n = int(input())
a = list(map(int, input().split()))
ans = []
ans.append(min(a))
ans.append(max(a))
ans.append(sum(a))
print(" ".join(map(str, ans)))
| 0 | null | 62,470,986,115,662 | 264 | 48 |
n = int(input())
a = list(map(int, input().split()))
number_buka = [0]*n
for i in a:
number_buka[i-1] += 1
for j in number_buka:
print(j)
|
n, *aa = open(0).read().split()
def bubble(aa):
aa = list(map(list, aa))
n = len(aa)
for i in range(n):
for j in range(n-1, i, -1):
if aa[j-1][1] > aa[j][1]:
aa[j-1], aa[j] = aa[j], aa[j-1]
aa = list(map(lambda x: ''.join(x), aa))
return aa
def selection(aa):
aa = list(map(list, aa))
n = len(aa)
for i in range(n):
mini = i
for j in range(i, n):
if aa[j][1] < aa[mini][1]:
mini = j
aa[mini], aa[i] = aa[i], aa[mini]
aa = list(map(lambda x: ''.join(x), aa))
return aa
bres = bubble(aa)
sres = selection(aa)
print(*bres)
print('Stable')
print(*sres)
if bres == sres:
print('Stable')
else:
print('Not stable')
| 0 | null | 16,399,183,479,770 | 169 | 16 |
# coding=utf-8
from __future__ import division
from math import sqrt
def main():
n = input()
while n:
scores = map(int, raw_input().split())
m = sum(scores) / n
print sqrt(sum([(x - m) ** 2 for x in scores]) / n)
n = input()
if __name__ == '__main__':
main()
|
import sys
input = sys.stdin.buffer.readline
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
ans = "No"
for i in range(N-2):
ok = (AB[i][0] == AB[i][1] and AB[i+1][0] == AB[i+1][1] and AB[i+2][0] == AB[i+2][1])
if ok:
ans = "Yes"
print(ans)
| 0 | null | 1,333,962,673,582 | 31 | 72 |
#142-A
N = int(input())
D = []
for i in range(1,N+1):
D.append(i)
#print(D)
cnt = 0
for j in D:
if j % 2 != 0:
cnt += 1
#print(cnt)
print(cnt / len(D))
|
(h,n),*t=[[*map(int,t.split())]for t in open(0)]
d=[0]*9**8
for i in range(h):d[i+1]=min(b+d[i-a+1]for a,b in t)
print(d[h])
| 0 | null | 129,444,927,452,100 | 297 | 229 |
x = int(input())
ans = 0
a = int(x / 500)
ans = ans + a * 1000
x = x % 500
b = int(x / 5)
ans = ans + b * 5
print(ans)
|
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [list(input())[:-1] for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
H,W,K = map(int,input().split())
P = [list(input())[:-1] for _ in range(H)]
num= 1
cur = 1
flag = [0]*H
ans = [[0]*W for _ in range(H)]
for i in range(H):
count = 0
li = [0]*W
for j in range(W):
if P[i][j] == "#":
count += 1
if count == 0:
flag[i] = 1
else:
judge = 0
d = 0
for j in range(W):
if P[i][j] == "." or d == 1:
ans[i][j] = num
else:
ans[i][j] = num
judge += 1
if judge == count:
d = 1
else:
num += 1
num += 1
for i in range(H):
if flag[i] == 0:
index = i
break
for i in range(index):
flag[i] = 0
for j in range(W):
ans[i][j] = ans[index][j]
for i in range(H):
if flag[i] == 1:
for j in range(W):
ans[i][j] = ans[i-1][j]
for i in range(H):
print(*ans[i])
| 0 | null | 93,221,697,453,500 | 185 | 277 |
import heapq
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
L = []
ans = 0
heapq.heappush(L, -A[0])
for i in range(1, N):
max = heapq.heappop(L)
max *= -1
ans += max
heapq.heappush(L, -A[i])
heapq.heappush(L, -A[i])
print(ans)
|
import sys; input = sys.stdin.readline
# n, m , k = map(int, input().split())
# matrix = [list(input().strip()) for _ in range(n)]
n = int(input())
lis = sorted(map(int, input().split()), reverse=True)
ans = lis[0]
i = 1
c = 1
while c<n-1:
if c < n-1: ans += lis[i]; c+=1
if c < n-1: ans += lis[i]; c+=1
i+=1
print(ans)
| 1 | 9,141,191,792,542 | null | 111 | 111 |
from math import gcd
from itertools import product
from functools import reduce
l1 = [i for i in range(1, int(input()) + 1)]
print(sum(reduce(gcd, l) for l in product(l1, repeat=3)))
|
import math
k = int(input())
sum_gcd = 0
for a in range(1,k+1):
for b in range(1,k+1):
for c in range(1,k+1):
sum_gcd += math.gcd(math.gcd(a,b) , c)
print(sum_gcd)
| 1 | 35,532,821,641,894 | null | 174 | 174 |
a = input()
t = list(a)
if t[len(t)-1] == "?":
t[len(t)-1] = "D"
if t[0] == "?":
if t[1] == "D" or t[1] == "?":
t[0] = "P"
else:
t[0] = "D"
for i in range(1, len(t)-1):
if t[i] == "?" and t[i-1] == "P":
t[i] = "D"
elif t[i] == "?" and t[i+1] == "D":
t[i] = "P"
elif t[i] == "?" and t[i+1] == "?":
t[i] = "P"
elif t[i] == "?":
t[i] = "D"
answer = "".join(t)
print(answer)
|
pd = list(input())
for i in range(len(pd)):
if '?' in pd[i]:
pd[i] = 'D'
print(pd[i], end = '')
| 1 | 18,462,715,370,070 | null | 140 | 140 |
def warshall_floid(d):
for k in range(1,n+1):
for i in range(1,n+1):
for j in range(1,n+1):
d[i][j] = min(d[i][j],d[i][k]+d[k][j])
return d
n,m,l = map(int,input().split())
d = [[10**13]*(n+1) for i in range(n+1)]
for i in range(m):
a,b,c = map(int,input().split())
d[a][b] = c
d[b][a] = c
for i in range(1,n+1):
d[i][i] = 0
d = warshall_floid(d)
for i in range(1,n+1):
for j in range(1,n+1):
if d[i][j] <= l:
d[i][j] = 1
else:
d[i][j] = 10**13
d = warshall_floid(d)
q = int(input())
for i in range(q):
s,t = map(int,input().split())
if d[s][t] >= 10**13:
print(-1)
else:
print(d[s][t]-1)
|
n, m, l = map(int, input().split())
x = [[] for _ in range(n)]
dp = [[n*10**9 for _ in range(n)] for _ in range(n)]
for _ in range(m):
a, b, c = map(int, input().split())
if c <= l:
x[a-1].append(b-1)
x[b-1].append(a-1)
dp[a-1][b-1] = c
dp[b-1][a-1] = c
q = int(input())
st = []
for _ in range(q):
st.append(list(map(int, input().split())))
dp[0][0] = 0
for i in range(1,n):
dp[i][i] = 0
for j in range(i):
for a in x[i]:
dp[i][j] = min(dp[i][j],dp[i][a]+dp[a][j])
dp[j][i] = dp[i][j]
for j in range(i):
for k in range(i):
dp[j][k] = min(dp[j][k],dp[j][i]+dp[i][k])
dp2 = [[n for _ in range(n)] for _ in range(n)]
for i in range(n):
for j in range(n):
if dp[i][j] <= l:
dp2[i][j] = 1
for i in range(1,n):
for j in range(i):
for k in range(i):
dp2[i][j] = min(dp2[i][j],dp2[i][k]+dp2[k][j])
dp2[j][i] = dp2[i][j]
for j in range(i):
for k in range(i):
dp2[j][k] = min(dp2[j][k],dp2[j][i]+dp2[i][k])
for u in st:
ans = dp2[u[0]-1][u[1]-1]
if ans >= n:
print(-1)
else:
print(ans-1)
| 1 | 173,677,410,723,012 | null | 295 | 295 |
n = int(input())
m = 10**13
for x in range(1,1000001):
y = n / x
if y % 1 == 0:
v = x + y -2
m = min(m, v)
print(int(m))
|
N=int(input())
ans=float("inf")
i=1
while i**2<=N:
if N%i==0:
temp=(i-1)+(N//i -1)
ans=min(ans, temp)
i+=1
print(ans)
| 1 | 161,792,445,936,202 | null | 288 | 288 |
radius = int(input())
print(44/7*radius)
|
def gcd_e(x, y):
if y == 0:
return x
else:
return gcd_e(y,x%y)
def lcm(x, y):
return (x * y) // gcd_e(x, y)
n,m=list(map(int,input().split()))
A=list(map(int,input().split()))
a,b=A[0],0
for i in range(1,n):
b = A[i]
a = lcm(a,b)
for i in set(A):
if (a // i) % 2 == 0:
print('0')
exit()
if a // 2 > m:
print('0')
else:
print((m-a//2)//a+1)
| 0 | null | 66,847,925,993,212 | 167 | 247 |
N, K, C = map(int, input().split())
S = [1 if a == "o" else 0 for a in input()]
c = 0
X = [0] * N
Y = [0] * N
i = 0
while i < N:
if S[i]:
c += 1
X[i] = 1
i += C + 1
else:
i += 1
if c > K:
exit()
i = N - 1
while i >= 0:
if S[i]:
Y[i] = 1
i -= C + 1
else:
i -= 1
for i in range(N):
if X[i] and Y[i]:
print(i + 1)
|
x=int(input())
n=x//500
m=x%500
k=m//5
print(1000*n+5*k)
| 0 | null | 41,992,015,347,722 | 182 | 185 |
n=int(input())
a,c,i=[],0,1
while i <= n:
if c==0:
x=i
if x%3==0:
print(' '+str(i), end='')
i+=1
continue
c=0
if x%10==3:
print(' '+str(i), end='')
i+=1
continue
x//=10
if x == 0:
i+=1
continue
else:
c=1
print()
|
ls = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a']
print(ls[ls.index(input())+1])
| 0 | null | 46,644,570,262,638 | 52 | 239 |
from collections import defaultdict
N, u, v = map(int, input().split())
d = defaultdict(list)
for _ in range(N-1):
A, B = map(int, input().split())
d[A].append(B)
d[B].append(A)
def get_dist(s):
dist = [-1]*(N+1)
dist[s] = 0
q = [s]
while q:
a = q.pop()
for b in d[a]:
if dist[b]!=-1:
continue
dist[b] = dist[a] + 1
q.append(b)
return dist
du, dv = get_dist(u), get_dist(v)
ds = [(i,j[0], j[1]) for i,j in enumerate(zip(du, dv)) if j[0]<j[1]]
ds.sort(key=lambda x:-x[2])
a, b, c = ds[0]
print(c-1)
|
from collections import deque
def bfs(s):
que = deque([(s, 0)])
dist = [None]*n
while que:
cur, cst = que.popleft()
if dist[cur] != None:
continue
dist[cur] = cst
for nxt in es[cur]:
que.append((nxt, cst+1))
return dist
n,u,v = map(int,input().split())
es = [[] for _ in range(n)]
for _ in range(n-1):
a,b = map(int,input().split())
es[a-1].append(b-1)
es[b-1].append(a-1)
dist_u = bfs(u-1)
dist_v = bfs(v-1)
ans = 0
for i in range(n):
if dist_v[i]-dist_u[i] >= 1:
ans = max(ans, dist_v[i])
print(max(0, ans-1))
| 1 | 117,306,498,078,980 | null | 259 | 259 |
r=input();p=3.14159265358979;print "%.9f"%(p*r*r),r*2*p
|
import math
r = float(raw_input())
print ('%.6f' % (r*r*math.pi)),
print ('%.6f' % (r*2*math.pi))
| 1 | 640,318,284,100 | null | 46 | 46 |
N=int(input())
A=list(map(int, input().split()))
B=[0]*N
C=''
for i in range(N):
B[A[i]-1]=i+1
for i in range(N):
C+=str(B[i])+' '
print(C[0:-1])
|
n = int(input())
A = list(map(int, input().split()))
L = [0]*n
for i in range(n):
L[A[i]-1] = i+1
print(*L)
| 1 | 180,651,374,852,712 | null | 299 | 299 |
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
count_a = Counter(A)
ans_list = [0] * (N+1)
for k, v in count_a.items():
ans_list[k] = int(v * (v-1) / 2)
all_sum = sum(ans_list)
for i in range(N):
print(all_sum - count_a[A[i]] + 1)
|
N = int(input())
A = list(map(int,input().split()))
ls = [0] * (N + 1)
for a in A:
ls[a] += 1
C = 0
for i in set(A):
n = ls[i]
C += n * (n - 1) //2
for a in A:
n = ls[a]
print(C - (n - 1))
| 1 | 47,716,093,475,688 | null | 192 | 192 |
while 1:
a, op, b = map(str, raw_input().split())
a = int(a)
b = int(b)
if op == '?':
break
elif op == '+':
print (a + b)
elif op == '-':
print (a - b)
elif op == '*':
print (a * b)
elif op == '/':
print (a / b)
|
while True:
a, op, b = map(str, raw_input().split())
a = int(a)
b = int(b)
if op == '+':
print a + b
elif op == '-':
print a - b
elif op == '*':
print a * b
elif op == '/':
if b != 0:
print a / b
elif op == '?':
break
else:
break
| 1 | 685,136,906,002 | null | 47 | 47 |
a = int(input())
n = 1
while True:
if a*n % 360 == 0:
break
else:
n += 1
print(n)
|
import itertools
import math
#print(3 & (1 << 0))
def main():
N = int(input())
items = [i+1 for i in range(N)]
locations=[]
for i in range(N):
locations.append(list(map(int, input().split())))
paths =list(itertools.permutations(items))
sum = 0
for path in paths: # path = [1,2,3,4,5]
for i in range(len(path)-1):
from_idx = path[i] -1
to_idx = path[i+1] -1
xdiff= locations[from_idx][0] - locations[to_idx][0]
ydiff= locations[from_idx][1] - locations[to_idx][1]
sum = sum + math.sqrt(xdiff**2 + ydiff**2)
print( sum / len(paths))
main()
| 0 | null | 80,696,772,453,892 | 125 | 280 |
#!/usr/bin/pypy
# coding: utf-8
N,M,L=map(int, raw_input().split())
RG=[[ 0 if i==j else float('inf') for i in range(N)] for j in range(N)]
for i in xrange(M):
f,t,c = map(int, raw_input().split())
if c <= L:
RG[f-1][t-1] = c
RG[t-1][f-1] = c
for k in xrange(N):
for i in xrange(N):
for j in xrange(i, N):
t = RG[i][k] + RG[k][j]
if RG[i][j] > t:
RG[i][j] = t
RG[j][i] = t
FG=[[float('inf') for i in range(N)] for j in range(N)]
for i in xrange(N):
for j in xrange(i, N):
if RG[i][j] <= L:
FG[i][j] = 1
FG[j][i] = 1
for k in xrange(N):
for i in xrange(N):
for j in xrange(i, N):
t = FG[i][k] + FG[k][j]
if FG[i][j] > t:
FG[i][j] = t
FG[j][i] = t
Q=int(raw_input())
for i in xrange(Q):
s, t = map(int, raw_input().split())
v = FG[s-1][t-1]
if v == float('inf'):
print (str(-1))
else:
print (str(int(v-1)))
|
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
SA = [0]
SB = [0]
tmp_A, tmp_B = 0 ,0
for i in range(N):
tmp_A += A[i]
if tmp_A <= K:
SA.append(tmp_A)
else:
break
for i in range(M):
tmp_B += B[i]
if tmp_B <= K:
SB.append(tmp_B)
else:
break
ans = 0
cursol_B = len(SB) - 1
for i in range(len(SA)):
while SA[i] + SB[cursol_B] > K:
cursol_B -= 1
ans = max(ans, i + cursol_B)
print(ans)
| 0 | null | 91,808,632,870,372 | 295 | 117 |
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)
|
import itertools
n, m, q = map(int, input().split())
a, b, c, d = [0] * q, [0] * q, [0] * q, [0] * q
for i in range(q):
a[i], b[i], c[i], d[i] = map(int, input().split())
aa = [i for i in range(1, m+1)]
maxv = -1
for i in itertools.combinations_with_replacement(aa, n):
cnt = 0
for j in range(q):
if i[b[j]-1] - i[a[j]-1] == c[j]:
cnt += d[j]
maxv = max(maxv, cnt)
print(maxv)
| 1 | 27,793,438,668,960 | null | 160 | 160 |
#self.r[x] means root of "x" if "x" isn't root, else number of elements
class UnionFind():
def __init__(self, n):
self.r = [-1 for i in range(n)]
#use in add-method
def root(self, x):
if self.r[x] < 0: #"x" is root
return x
self.r[x] = self.root(self.r[x])
return self.r[x]
#add new path
def add(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return False
self.r[x] += self.r[y]
self.r[y] = x
return True
n, m = map(int, input().split())
UF = UnionFind(n)
for i in range(m):
a, b = map(lambda x: int(x)-1, input().split())
UF.add(a, b)
ans = 0
for i in UF.r:
if i < 0:
ans += 1
print(ans-1)
|
from math import sqrt
import itertools
N = int(input())
dis = [input().split() for i in range(N)]
lst = [x for x in range(N)]
p_lst = list(itertools.permutations(lst))
ans = 0
for i in p_lst:
for j in range(N-1):
ans += sqrt((int(dis[i[j]][0]) - int(dis[i[j+1]][0]))**2
+ (int(dis[i[j]][1]) - int(dis[i[j+1]][1]))**2)
print(ans/len(p_lst))
| 0 | null | 75,160,518,051,708 | 70 | 280 |
x = input()
if x == "ABC":
print("ARC")
else:
print("ABC")
|
n, a, b = map(int, input().split())
print((b-a)//2 + min(a-1,n-b) + 1 if (b-a)%2 else (b-a)//2)
| 0 | null | 66,709,068,286,080 | 153 | 253 |
S = input()
ans = 0
tmp = 0
for i in range(len(S)):
if S[i] == "R":
tmp += 1
ans = max(ans, tmp)
else:
tmp = 0
print(ans)
|
s=input().split('S')
print(len(max(s)))
| 1 | 4,909,342,945,992 | null | 90 | 90 |
while True:
L = map(int,raw_input().split())
H = (L[0])
W = (L[1])
if H == 0 and W == 0:break
if W % 2 == 1:
for x in range(0,H):
if x % 2 == 0:
print "{}#".format("#."* (W / 2))
else:
print "{}.".format(".#"* (W / 2))
else:
for x in range(0,H):
if x % 2 == 0:
print "#." * (W / 2)
else:
print ".#" * (W / 2)
print ""
|
while True:
[H,W]=[int(x) for x in input().split()]
if [H,W]==[0,0]:
break
unit="#."
for i in range(0,H):
print(unit*(W//2)+unit[0]*(W%2))
unit=unit[1]+unit[0]
print("")
| 1 | 861,290,319,692 | null | 51 | 51 |
N = int(input())
XL = [list(map(int, input().split())) for x in range(N)]
XL = sorted(XL, key=lambda x: x[0]+x[1])
cnt = 0
prev_right = -10**9+10
for x, l in XL:
left = x - l
right = x + l
if left >= prev_right:
cnt += 1
prev_right = right
print(cnt)
|
N = int(input())
rob = []
for i in range(N):
X, L = map(int, input().split())
rob.append([X-L, X+L])
rob.sort(key=lambda x: x[1])
ans = N
for i in range(N-1):
if rob[i+1][0] < rob[i][1]:
rob[i+1][1] = rob[i][1]
ans -= 1
print(ans)
| 1 | 90,061,311,051,738 | null | 237 | 237 |
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')
|
N = int(input())
M = 0
ans = 'No'
for _ in range(N):
d1, d2 = map(int, input().split())
if d1 == d2:
M += 1
if M >= 3:
ans = 'Yes'
else:
M = 0
print(ans)
| 1 | 2,468,754,645,092 | null | 72 | 72 |
x, y = map(int, input().split())
prize = 0
if x <= 3:
prize += (300000 - (x - 1) * 100000)
if y <= 3:
prize += (300000 - (y - 1) * 100000)
if (x == 1) & (y == 1):
prize += 400000
print(prize)
|
X=list(map(int, input().split()))
t=0
for i in range(len(X)):
if X[i]==1:
t+=300000
elif X[i]==2:
t+=200000
elif X[i]==3:
t+=100000
if X[0]==X[1] and X[0]==1:
t+=400000
print(t)
| 1 | 141,156,274,066,204 | null | 275 | 275 |
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
#------------------------------------------#
BIG_NUM = 2000000000
HUGE_NUM = 9999999999999999
MOD = 1000000007
EPS = 0.000000001
def MIN(A,B):
if A <= B:
return A
else:
return B
def MAX(A,B):
if A >= B:
return A
else:
return B
#------------------------------------------#
class Point:
def __init__(self,arg_x,arg_y):
self.x = arg_x
self.y = arg_y
def roll(div1,div2):
tmp_start = Point(div2.x-div1.x,div2.y-div1.y)
tmp_end = Point(tmp_start.x*math.cos(math.pi/3) -tmp_start.y*math.sin(math.pi/3),
tmp_start.x*math.sin(math.pi/3) + tmp_start.y*math.cos(math.pi/3))
ret = Point(tmp_end.x + div1.x,tmp_end.y + div1.y)
return ret;
def outPut(point):
print("%.8f %.8f"%(point.x,point.y))
def calc(left,right,count):
div1 = Point((2*left.x + right.x)/3,(2*left.y + right.y)/3)
div2 = Point((2*right.x + left.x)/3,(2*right.y + left.y)/3)
peek = roll(div1,div2)
if count > 1:
calc(left,div1,count-1)
calc(div1,peek,count-1)
calc(peek,div2,count-1)
calc(div2,right,count-1)
else:
outPut(left);
outPut(div1);
outPut(peek);
outPut(div2);
N = int(input())
left = Point(0,0)
right = Point(100,0)
if N == 0:
outPut(left)
outPut(right)
else:
calc(left,right,N)
outPut(right)
|
import math
def koch(d, p1, p2):
if d == 0:
return
v = [p2[0] - p1[0], p2[1] - p1[1]]
s = [p1[0] + v[0] / 3, p1[1] + v[1] / 3]
t = [p1[0] + 2 * v[0] / 3, p1[1] + 2 * v[1] / 3]
u = [p1[0] + v[0] / 2 - v[1] * math.sqrt(3) / 6, p1[1] + v[1] / 2 + v[0] * math.sqrt(3) / 6]
koch(d - 1, p1, s)
print(" ".join(map(str, s)))
koch(d - 1, s, u)
print(" ".join(map(str, u)))
koch(d - 1, u, t)
print(" ".join(map(str, t)))
koch(d - 1, t, p2)
n = int(input())
print("0 0")
koch(n, [0, 0], [100, 0])
print("100 0")
| 1 | 132,909,963,812 | null | 27 | 27 |
#155_A
a, b, c = map(int, input().split())
if a==b and a!=c and b!=c:
print('Yes')
elif a==c and a!=b and c!=b:
print('Yes')
elif b==c and b!=a and c!=a:
print('Yes')
else:
print('No')
|
n = int(input())
s = []
for i in range(n):
s.append(input())
ls = []
rs = []
tot = 0
for si in s:
b = 0
h = 0
for c in si:
if c == '(':
h += 1
else:
h -= 1
b = min(h,b)
if h > 0:
ls.append((b,h))
else:
rs.append((b-h,-h))
tot += h
ls.sort(reverse = True)
rs.sort(reverse = True)
def check(x):
t = 0
for bx,hx in x:
if t+bx < 0:
return False
t += hx
return True
if check(ls) and check(rs) and tot == 0:
print('Yes')
else:
print('No')
| 0 | null | 45,731,239,842,520 | 216 | 152 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.