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
|
---|---|---|---|---|---|---|
def main():
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().rstrip()
n = int(input())
nd = defaultdict(int)
for i in range(1, n+1):
tmp = str(i)
h, t = int(tmp[0]), int(tmp[-1])
nd[(h, t)] += 1
ans = 0
for i in range(1, 10):
for j in range(1, 10):
ans += nd[(i, j)]*nd[(j, i)]
print(ans)
if __name__ == '__main__':
main() | import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
mod = 998244353
n, k = LI()
l = [0 for _ in range(k)]
r = [0 for _ in range(k)]
for i in range(k):
l[i], r[i] = LI()
dp = [0 for _ in range(n+1)]
dpsum = [0 for _ in range(n+1)]
dp[1], dpsum[1] = 1, 1
for i in range(2,n+1):
for el, er in zip(l, r):
dp[i] += dpsum[max(i-el, 0)] - dpsum[max(i-er-1, 0)]
dp[i] %= mod
dpsum[i] = (dpsum[i-1] + dp[i])%mod
print(dp[n])
main()
| 0 | null | 44,680,413,854,240 | 234 | 74 |
N = int(input())
cnt = [[0 for i in range(10)] for j in range(10)]
for i in range(1, N+1):
i_str = str(i)
cnt[int(i_str[0])][int(i_str[-1])] += 1
ans = 0
for i in range(10):
for j in range(10):
ans += cnt[i][j] * cnt[j][i]
print(ans) | n = int(input())
def count_ab(start, end):
l = len(str(n))
if start == 0:
return 0
if l == 1:
if start == end:
if n >= start:
return 1
else:
return 0
else:
return 0
else:
if start == end:
cnt = 1
else:
cnt = 0
if int(str(n)[0]) > start:
for i in range(1, l):
cnt += 10 ** i // 10
if int(str(n)[0]) == start:
for i in range(1, l - 1):
cnt += 10 ** i //10
cnt += int(str(n)[1:]) // 10
if int(str(n)[-1]) >= end:
cnt += 1
if int(str(n)[0]) < start:
for i in range(1, l - 1):
cnt += 10 ** i //10
return cnt
ans = 0
for i in range(10):
for j in range(10):
A = count_ab(i, j)
B = count_ab(j, i)
ans += A * B
print(ans) | 1 | 86,173,342,953,370 | null | 234 | 234 |
#!/usr/bin/env python3
def main():
N = int(input())
print(-(-N // 2))
main()
| #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 # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
import math
print(math.ceil(I()/2))
| 1 | 58,995,882,839,488 | null | 206 | 206 |
#depth first
N=int(input())
V=[]
a=[0]
for i in range(N):
V.append([int(i) for i in input().split()])
w=V[i][2:]
w.sort()
V[i]=V[i][:2]+w
a.append(0)
V=sorted(V,key=lambda x:x[0])
c=1
t=1
i=0
r=[1]
a[1]=1
p=[[1,t]]
q=[]
while t<N*2:
j=2
while t<N*2 and j-2<V[i][1] and V[i][1]>0 and a[V[i][j]]==1:
j+=1
t+=1
if j-2<V[i][1]:
a[V[i][j]]=1
c+=1
r.append(V[i][j])
p.append([V[i][j],t])
i=V[i][j]-1
else:
q.append(p[-1]+[t])
r.pop(-1)
p.pop(-1)
if len(r)>0:
i=r[-1]-1
else:
j=1
while j<N and a[j]==1:
j+=1
if j<N:
t+=1
i=j-1
r.append(j)
p.append([j,t])
q=sorted(q,key=lambda x:x[0])
for i in range(N):
for j in range(3):
q[i][j]=str(q[i][j])
print(" ".join(q[i])) | N = int(input())
DG = {}
node_ls = []
is_visited = {}
#有効グラフをdictで管理することにする
for _ in range(N):
tmp = input().split()
node_id = tmp[0]
node_ls.append(node_id)
is_visited[node_id] = False
adj_num = int(tmp[1])#各頂点の次元が入っている
if adj_num != 0:
DG[node_id] = tmp[2:]
else:
DG[node_id] = []
d = {}#最初に発見したときの時刻を記録
f = {}#隣接リストを調べ終えたときの完了時刻を記録
t = 1
def dfs(node):
global t
#終了条件
if is_visited[node]:
return
is_visited[node] = True
d[node] = t
t += 1
for no in DG[node]:
dfs(no)
f[node] = t
t += 1
for node in node_ls:
dfs(node)
#print(d,f)
for node in node_ls:
print(node, d[node], f[node])
| 1 | 2,928,966,232 | null | 8 | 8 |
while True:
[h, w] = map(int, (input().split()))
if h==0 and w==0:
break
else:
print("#"*w+"\n"+("#"+"."*(w-2)+"#\n")*(h-2)+"#"*w+"\n") | while 1:
h,w=map(int,raw_input().split())
if h==w==0:break
print '#'*w
for i in range(h-2):
if w>=2:
print '#'+'.'*(w-2)+'#'
else :
print '#'
print '#'*w
print'' | 1 | 837,694,072,500 | null | 50 | 50 |
from collections import Counter
N, P = map(int, input().split())
S = list(input())
cnt = 0
if P in [2, 5]:
for i, s in enumerate(S):
if int(s) % P == 0:
cnt += (i + 1)
else:
num = 0
mods = Counter()
for i, s in enumerate(reversed(S)):
num += int(s) * pow(10, i, P)
num %= P
mods[num] += 1
mods[0] += 1
for i, s in enumerate(S):
mods[num] -= 1
cnt += mods[num]
num -= int(s) * pow(10, N - 1 - i, P)
num %= P
print(cnt)
| N, P = map(int, input().split())
S = input()
if 10 % P == 0:
ans = 0
for r in range(N):
if int(S[r]) % P == 0:
ans += r + 1
print(ans)
exit()
d = [0] * (N + 1)
ten = 1
for i in range(N - 1, -1, -1):
a = int(S[i]) * ten % P
d[i] = (d[i + 1] + a) % P
ten *= 10
ten %= P
cnt = [0] * P
ans = 0
for i in range(N, -1, -1):
ans += cnt[d[i]]
cnt[d[i]] += 1
print(ans) | 1 | 58,237,240,570,530 | null | 205 | 205 |
k=int(input())
l=[0]*k
x=7%k
s=-1
for c in range(k):
if x==0:
s=c+1
break
if l[x]==1:
break
l[x]=1
x=(10*x+7)%k
print(s) | a = int(input())
b = input().split()
c = []
for i in range(a * 2):
if i % 2 == 0:
c.append(b[0][i // 2])
else:
c.append(b[1][(i - 1) // 2])
for f in c:
print(f,end="") | 0 | null | 59,297,927,596,000 | 97 | 255 |
l=['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']
c=input('')
for a in range(25):
if l[a]==c:
print(l[a+1]) | a = input()
print(chr(((ord(a)-ord("a")+1)%26)+ord("a"))) | 1 | 92,162,427,848,190 | null | 239 | 239 |
import math
def main():
r = int(input())
print(math.pi *r *2)
if __name__ == "__main__":
main() | #
# author sidratul Muntaher
# date: Aug 19 2020
#
n = int(input())
from math import pi
print(pi* (n*2))
| 1 | 31,342,478,957,532 | null | 167 | 167 |
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1 # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7
def debug(*x):
print(*x, file=sys.stderr)
def solve(A, B, C, K):
while A >= B:
K -= 1
B *= 2
while B >= C:
K -= 1
C *= 2
if K >= 0:
return "Yes"
return "No"
def main():
# parse input
A, B, C = map(int, input().split())
K = int(input())
print(solve(A, B, C, K))
# tests
T1 = """
7 2 5
3
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
Yes
"""
T2 = """
7 4 2
3
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
No
"""
def _test():
import doctest
doctest.testmod()
g = globals()
for k in sorted(g):
if k.startswith("TEST_"):
doctest.run_docstring_examples(g[k], g)
def as_input(s):
"use in test, use given string as input file"
import io
f = io.StringIO(s.strip())
g = globals()
g["input"] = lambda: bytes(f.readline(), "ascii")
g["read"] = lambda: bytes(f.read(), "ascii")
input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
if sys.argv[-1] == "-t":
print("testing")
_test()
sys.exit()
main()
|
import sys
def check(x_list, f, r, v):
x_list[f][r] += v
def peo(x_list):
for i in range(3):
for j in range(10):
sys.stdout.write(" %d" %(x_list[i][j]))
print ("")
A_bill = [[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,0,0,0,0]]
B_bill = [[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,0,0,0,0]]
C_bill = [[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,0,0,0,0]]
D_bill = [[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,0,0,0,0]]
n = input()
for i in range(n):
x = raw_input()
b, f, r, v = x.split()
b = int(b)
f = int(f)
r = int(r)
v = int(v)
if b == 1:
check(A_bill, f-1,r-1,v)
elif b == 2:
check(B_bill, f-1,r-1,v)
elif b == 3:
check(C_bill, f-1,r-1,v)
elif b == 4:
check(D_bill, f-1,r-1,v)
peo(A_bill)
print("####################")
peo(B_bill)
print("####################")
peo(C_bill)
print("####################")
peo(D_bill) | 0 | null | 3,992,357,105,830 | 101 | 55 |
import sys
A, B = [int(x) for x in input().split()]
ans_A = 0
ans_B = 0
for i in range(1500):
ans_A = (i*8//100)
ans_B = (i//10)
if(ans_A==A)and(ans_B==B):
print(i)
sys.exit()
print(-1) | n, x, m = map(int, input().split())
v = list(range(m))
p = [-1 for _ in range(m)]
a = x
p[a - 1] = 0
s = [x]
l, r = n, n
for i in range(n):
a = a ** 2 % m
if p[a - 1] >= 0:
l, r = p[a - 1], i + 1
break
else:
s.append(a)
p[a - 1] = i + 1
ans = sum(s[:l])
if l != r:
b = (n - 1 - i) // (r - l) + 1
c = (n - 1 - i) % (r - l)
ans += b * sum(s[l:r]) + sum(s[l:l + c])
print(ans)
| 0 | null | 29,483,136,798,180 | 203 | 75 |
a, b, m = map(int, input().split())
a_s = list(map(int, input().split()))
b_s = list(map(int, input().split()))
m_s =[]
for _ in range(m):
m_s.append(list(map(int, input().split())))
mini = min(a_s) + min(b_s)
for am, bm, sale in m_s:
mini = min(mini, a_s[am-1]+b_s[bm-1]-sale)
print(mini) | a,b,m = map(int,input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
x = []
y = []
c = []
for i in range(m):
xs,ys,cs = map(int,input().split())
x.append(xs)
y.append(ys)
c.append(cs)
ans1 = 10**10
for j in range(m):
if ans1 >= a[x[j]-1] + b[y[j]-1] - c[j]:
ans1 = a[x[j]-1] + b[y[j]-1] - c[j]
ans2 = min(a)+min(b)
print(min(ans1,ans2)) | 1 | 53,922,004,574,918 | null | 200 | 200 |
def find_prime(x):
while True:
if x == 2:
return x
else:
for i in range(2, x+1):
if x % i == 0:
if i == x:
return x
else:
break
else:
continue
x += 1
def main():
x = int(input())
x = find_prime(x)
print(x)
if __name__ == "__main__":
main()
| def prime_num(n):
f = 3
while f * f <= n:
if n % f == 0:
return 1
f += 2
return 0
x = int(input())
if x == 2:
print(x)
exit()
prime = (x//2)*2 + 1
while 1 == 1:
if prime_num(prime) == 0:
print(prime)
exit()
prime += 2 | 1 | 105,460,412,022,350 | null | 250 | 250 |
def main():
a, b = map(int, input().split())
maxv = int((101 / 0.1) - 1)
for i in range(maxv+1):
if (i*8//100 == a) and (i*10//100 == b):
print(i)
exit()
print(-1)
if __name__ == '__main__':
main()
|
A, B = map(int, input().split())
lb_a = int(-(-A // 0.08))
ub_a = int(-(-(A + 1) // 0.08) - 1)
lb_b = int(-(-B // 0.1))
ub_b = int(-(-(B + 1) // 0.1) - 1)
if ub_b < lb_a or ub_a < lb_b:
print(-1)
else:
print(max(lb_a, lb_b))
| 1 | 56,208,421,979,400 | null | 203 | 203 |
while 1:
S = raw_input()
if (S == '-'):
break
N = input()
for i in range(N):
h = input()
S = S[h : len(S)] + S[0 : h]
print S
| # author: Taichicchi
# created: 15.09.2020 21:22:26
import sys
X, K, D = map(int, input().split())
X = abs(X)
if X >= K * D:
print(X - (K * D))
else:
k = K - X // D
x = X - D * (X // D)
if k % 2:
print(abs(x - D))
else:
print(x)
| 0 | null | 3,556,539,886,340 | 66 | 92 |
#C
K, N=map(int,input().split())
A=list(map(int,input().split()))
for i in range(N):
A.append(A[i]+K)
Right=[]
for i in range(N):
Right.append(A[N-1+i]-A[i])
print(min(Right)) | score = list(map(int,input().split()))
kenl = list(map(int,input().split()))
syoki = 0
syoki = kenl[0]+(score[0]-kenl[score[1]-1])
length = [0]*score[1]
length[0] = syoki
for i in range(score[1]-1):
length[i+1] = kenl[i+1]-kenl[i]
length.sort()
answer = length[score[1]-1]
print(score[0]-answer) | 1 | 43,549,940,927,162 | null | 186 | 186 |
M=998244353
n,m,k=map(int,input().split())
a,c=0,1
for i in range(k+1):
a+=c*m*pow(m-1,n+~i,M)
c=c*(n+~i)*pow(i+1,-1,M)%M
print(a%M) | N, M, K = map(int, input().split())
mod = 998244353
inv = [0,1]
for i in range(2, N):
inv.append((-inv[mod%i]*(mod//i))%mod)
if N == 1:
print(M)
exit()
m = [1]
s = 1
for _ in range(N-1):
s = s*(M-1)%mod
m.append(s)
ncombi = [1]
c = 1
for k in range(K):
c = c*(N-1-k)*inv[k+1]
c %= mod
ncombi.append(c)
ans = 0
for k in range(K+1):
ans = ans + m[-k -1]*ncombi[k]
ans %= mod
ans = ans*M%mod
print(ans) | 1 | 23,232,276,477,410 | null | 151 | 151 |
while 1:
e=map(int,raw_input().split())
m=e[0]
f=e[1]
r=e[2]
if m==f==r==-1:
break
elif m==-1 or f==-1 or m+f<30:
print "F"
elif m+f<50 and r<50:
print "D"
elif m+f<65:
print "C"
elif m+f<80:
print "B"
else:
print "A" | while True:
score = [int(i) for i in input().split()]
if score == [-1, -1, -1]:
break
sum = score[0] + score[1]
if sum < 30 or score[0] == -1 or score[1] == -1:
print('F')
elif sum < 50 and score[2] < 50:
print('D')
elif sum < 65 or (sum < 65 and score[2] >= 50):
print('C')
elif sum < 80:
print('B')
elif sum >= 80:
print('A')
| 1 | 1,205,418,289,052 | null | 57 | 57 |
a,b,c,d = map(int, input().split())
if a*b <= 0 and c*d <= 0:
print(max([a*c, b*d]))
elif a*b <= 0 and c >= 0:
print(b*d)
elif a*b <=0 and d <=0:
print(a*c)
elif a>=0 and c*d<=0:
print(b*d)
elif a>=0 and c>=0:
print(b*d)
elif a>=0 and d<=0:
print(a*d)
elif b<=0 and c*d<=0:
print(a*c)
elif b<=0 and c>=0:
print(b*c)
elif b<=0 and d<=0:
print(a*c) | def main():
N = int(input())
A = {input() for i in range(N)}
print(len(A))
if __name__ == '__main__':
main()
| 0 | null | 16,674,649,937,230 | 77 | 165 |
sa, sb = input().split()
a = int(sa)
bi,bf = map(int,sb.split("."))
b = bi * 100 + bf
print((a*b)//100) | nq = str(input()).split()
n = int(nq[0])
q = int(nq[1])
p = [str(input()).split() for i in range(n)]
p = [(str(i[0]), int(i[1])) for i in p]
ans = []
time = 0
while len(p) != 0:
t = p.pop(0)
if t[1] > q:
#p = [(s[0], s[1], s[2]+q) for s in p]
time += q
p.append((t[0], t[1]-q))
elif t[1] <= q:
#p = [(s[0], s[1], s[2]+t[1]) for s in p]
ans.append((t[0], t[1]+time))
time += t[1]
for t in ans:
print('{0} {1}'.format(t[0], t[1])) | 0 | null | 8,235,753,256,974 | 135 | 19 |
N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
dp = [0] * (S+1)
dp[0] = 1
for a in A:
for j in range(S, -1, -1):
if j-a >= 0:
dp[j] = dp[j]*2 + dp[j-a]
else:
dp[j] = dp[j]*2
print(dp[S]%mod) | H, W, K = map(int, input().split())
table = []
ans = 0
for _ in range(H):
li = input()
table.append(li)
for i in range(2**H):
for j in range(2**W):
counter = 0
for k in range(H):
for l in range(W):
if (i>>k)&1 and (j>>l)&1 and table[k][l] == "#":
counter += 1
if counter == K:
ans += 1
print(ans)
| 0 | null | 13,321,273,912,480 | 138 | 110 |
N=int(input())
S=list(input() for _ in range(N))
from collections import Counter
cnt=Counter(S)
max_cnt=cnt.most_common()[0][1]
ans=[]
for k, v in cnt.items():
if v!=max_cnt:
continue
ans.append(k)
print(*sorted(ans), sep="\n") | #!/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')
YES = "Yes" # type: str
NO = "No" # type: str
def solve(N: int, M: int, A: "List[int]"):
t = sum(A)/4/M
return [YES, NO][len([a for a in A if a >= t]) < M]
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
M = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
print(f'{solve(N, M, A)}')
if __name__ == '__main__':
main()
| 0 | null | 54,395,152,491,610 | 218 | 179 |
import math
r=float(input())
print('%f %f' %(math.pi*r*r, 2*math.pi*r)) | import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
s = input().rstrip()
n = len(s)
t = s[0:(n-1)//2]
q = s[(n+2)//2:n]
if s == s[::-1] and t == t[::-1] and q == q[::-1]:
print("Yes")
else:
print("No")
| 0 | null | 23,403,650,743,158 | 46 | 190 |
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [int(input()) for i in range(m)]
for i, ai in enumerate(a):
cnt = 0
for j, bj in enumerate(b):
cnt += ai[j] * bj
print(cnt)
| from collections import deque
N, D, A = map(int, input().split())
mons = []
for _ in range(N):
X, H = map(int, input().split())
mons.append((X, (H + A - 1) // A))
mons.sort()
ans = 0
q = deque([])
tot = 0
for x, h in mons:
while q:
x0, h0 = next(iter(q))
if x - 2 * D <= x0:
break
tot -= h0
q.popleft()
h = max(0, h - tot)
ans += h
tot += h
q.append((x, h))
print(ans)
| 0 | null | 41,454,862,809,308 | 56 | 230 |
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
from numba import njit
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,K = LI()
p = LI()
p.sort()
p1 = np.array(p)
print(p1[:K].sum())
| import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
n, k = inm()
a = sorted(inl())
print(sum(a[:k])) | 1 | 11,540,189,563,520 | null | 120 | 120 |
from collections import Counter
N = int(input())
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
a = prime_factorize(N)
num = list(Counter(a).values())
ans = 0
for i in num:
j = 1
while i - j >= 0:
ans += 1
i -= j
j += 1
print(ans) | import math
def factorization(n):
arr = []
temp = n
for i in range(2, int(math.ceil(n**0.5))):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i,cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
n = int(input())
if n == 1:
print(0)
exit(0)
fact_1i = factorization(n)
res = 0
for _, num in fact_1i:
temp_num = 1
while temp_num <= num:
res += 1
num -= temp_num
temp_num += 1
print(res) | 1 | 16,891,021,237,532 | null | 136 | 136 |
N = int(input())
from functools import reduce
import math
sum=0
for i in range(1,N+1):
for j in range(1,N+1):
a = math.gcd(i,j)
for k in range(1,N+1):
sum+=math.gcd(a,k)
print(sum) | #!/usr/bin/env python3
from functools import reduce
from itertools import combinations
from math import gcd
K = int(input())
sum = K * (K + 1) // 2
for i in combinations(range(1, K + 1), 2):
sum += 6 * reduce(gcd, i)
for i in combinations(range(1, K + 1), 3):
sum += 6 * reduce(gcd, i)
print(sum)
| 1 | 35,490,147,050,332 | null | 174 | 174 |
N=int(input())
S=input()
ans=""
for i in range(len(S)):
ans+=chr(ord("A")+(ord(S[i])-ord("A")+N)%26)
print(ans) | N = int(input())
S = input()
char = ''
for i in range(len(S)):
char += chr((ord(S[i]) + N - 65) % 26 + 65)
print(char)
| 1 | 134,555,586,308,480 | null | 271 | 271 |
MOD = 10**9 + 7
K = int(input())
S = len(input())
FCT = [1]
for i in range(1, K+S+1):
FCT.append((FCT[-1] * i)%MOD)
def pmu(n, r, mod=MOD):
return (FCT[n] * pow(FCT[n-r], mod-2, mod)) % mod
def cmb(n, r, mod=MOD):
return (pmu(n, r) * pow(FCT[r], mod-2, mod)) % mod
def solve():
ans = 1
for i in range(S+1, K+S+1):
ans = (ans*26) % MOD
add = pow(25, i-S, MOD)
add = (add * cmb(i-1, i-S)) % MOD
ans = (ans + add) % MOD
return ans
if __name__ == "__main__":
print(solve())
| x = list(map(int, input().split()))
print(x[2], x[0], x[1])
| 0 | null | 25,335,586,164,980 | 124 | 178 |
import sys
def resolve(in_):
N, X, T = map(int, next(in_).split())
minute = 0
tako = 0
while tako < N:
tako += X
minute += T
return minute
def main():
answer = resolve(sys.stdin)
print(answer)
if __name__ == '__main__':
main()
| N, X, T = map(int,input().split())
add = 0
if N % X > 0:
add = 1
ans = int(N//X + add)*T
print(ans) | 1 | 4,269,034,050,292 | null | 86 | 86 |
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
p = 0
def is_ok(arg,l):
return ls[arg] < l
def meguru_bisect(ng, ok):
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
l = ls[i] + ls[j]
if is_ok(mid,l):
ok = mid
else:
ng = mid
return ok
for i in range(n-2):
for j in range(i+1,n-1):
ng = n
ok = j
m = meguru_bisect(ng, ok)
p += m-j
print(p)
| import bisect
def main():
n = int(input())
l = sorted(list(int(i) for i in input().split()))
cnt = 0
for i in range(n - 2):
a = l[i]
for j in range(i + 1, n-1):
b = l[j]
cnt += bisect.bisect_left(l, a+b)-(j+1)
print(cnt)
if __name__ == "__main__":
main()
| 1 | 171,737,373,187,240 | null | 294 | 294 |
from collections import deque
import numpy as np
H,W = map(int,input().split())
Maze=[list(input()) for i in range(H)]
ans=0
for hi in range(0,H):
for wi in range(0,W):
if Maze[hi][wi]=="#":
continue
maze1=[[0]*W for _ in range(H)]
stack=deque([[hi,wi]])
while stack:
h,w=stack.popleft()
for i,j in [[1,0],[-1,0],[0,1],[0,-1]]:
new_h,new_w=h+i,w+j
if new_h <0 or new_w <0 or new_h >=H or new_w >=W:
continue
elif Maze[new_h][new_w]!="#" and maze1[new_h][new_w]==0:
maze1[new_h][new_w]=maze1[h][w]+1
stack.append([new_h,new_w])
maze1[hi][wi]=0
ans=max(ans,np.max(maze1))
print(ans) | from collections import deque
h, w = map(int, input().split())
meiro = [list(input()) for i in range(h)]
# meiro[y][x]
def bfs(a, b): # a縦b横
mx_dist = 0
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
dist = [[-1] * w for i in range(h)]
dist[a][b] = 0
que = deque([])
que.append((a, b))
while que:
y, x = que.popleft()
D = dist[y][x]
for i in range(4):
X = x + dx[i]
Y = y + dy[i]
if 0 <= Y and Y <= h - 1 and X <= w - 1 and 0 <= X:
if meiro[Y][X] == ".":
if dist[Y][X] == -1:
dist[Y][X] = D + 1
que.append((Y, X))
mx_dist = max(mx_dist, D + 1)
return mx_dist
saidai = 0
for i in range(h):
for j in range(w):
if meiro[i][j] == ".":
saidai = max(saidai, bfs(i, j))
print(saidai)
| 1 | 95,068,627,730,908 | null | 241 | 241 |
from math import ceil
from bisect import bisect_right
n, d, a = map(int, input().split())
l = []
l2 = []
l3 = []
l4 = [0 for i in range(n+1)]
l5 = [0 for i in range(n+1)]
ans = 0
for i in range(n):
x, h = map(int, input().split())
l.append([x, h])
l2.append(x + 2 * d)
l3.append(x)
l.sort(key=lambda x: x[0])
l2.sort()
l3.sort()
for i in range(n):
cnt = ceil((l[i][1] - l4[i] * a) / a)
if cnt > 0:
ans += cnt
ind = bisect_right(l3, l2[i])
l5[ind] += cnt
l4[i] += cnt
l4[i+1] = l4[i] - l5[i+1]
print(ans) | def main():
N=int(input())
print(sum([(N-1)//a for a in range(1,N)]))
if __name__=="__main__":
main() | 0 | null | 42,483,502,310,428 | 230 | 73 |
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
k = inp()
runrun = [["1","2","3","4","5","6","7","8","9"]]
runrun_int = []
for j in range(2,11):
tmp = []
for i in range(len(runrun[j - 2])):
if runrun[j-2][i][j-2] == "0":
tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2])))
tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2]) + 1))
elif runrun[j-2][i][j-2] in ["1","2","3","4","5","6","7","8"]:
tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2]) - 1))
tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2])))
tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2]) + 1))
elif runrun[j-2][i][j-2] == "9":
tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2]) - 1))
tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2])))
runrun.append(tmp)
ans = []
for i in range(len(runrun)):
for j in range(len(runrun[i])):
ans.append(int(runrun[i][j]))
ans.sort()
print(ans[k - 1]) | a = int(input(""))
print(int(a*a)) | 0 | null | 92,940,176,340,900 | 181 | 278 |
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
count = 0
stack = set()
visited = []
visited_set = set()
endf = False
current = 0
while True:
i = A[current]-1
visited_set.add(current)
visited.append(current)
if not i in visited_set:
current = i
count += 1
else:
leng = len(visited_set)
roop_len = leng - visited.index(i)
header_len = leng - roop_len
break
if count >= K:
endf = True
print(i+1)
break
if not endf:
roop_ind = (K - header_len + 1) % roop_len
if roop_ind == 0:
print(visited[-1]+1)
else:
print(visited[header_len + roop_ind-1]+1) | from copy import deepcopy
def main():
n, k = map(int, input().split())
a = [int(x)-1 for x in input().split()]
visited = set()
i = 0
cnt = 0
# 途中で前に行ったところに行ったら終わり
# kが小さくてcnt == kになってもおわり
while True:
if i in visited:
break
visited.add(i)
cnt += 1
i = a[i]
if cnt == k:
print(i+1)
exit()
k -= cnt
period = list()
period.append(i)
i = a[i]
# 何回で同じ場所に戻るか
while True:
if i == period[0]:
break
period.append(i)
i = a[i]
# 余り
mod = k % len(period)
ans = period[mod]
print(ans+1)
if __name__ == '__main__':
main() | 1 | 22,700,902,334,768 | null | 150 | 150 |
n = int(input())
a = 0
w = 0
t = 0
r = 0
for i in range(n):
s = input()
if s == 'AC':
a+=1
elif s =='WA':
w +=1
elif s =='TLE':
t +=1
else:
r+=1
print('AC x '+str(a))
print('WA x '+str(w))
print('TLE x '+str(t))
print('RE x '+str(r)) | n = int(input())
s = [input() for i in range(n)]
z = ['AC','WA','TLE','RE']
for j in z:
print(j+' x '+str(s.count(j)))
| 1 | 8,733,585,471,940 | null | 109 | 109 |
from math import sqrt
while True:
n = int(input())
if n == 0:
break
scores = list(map(int,input().split()))
m = sum(scores)/len(scores)
print(sqrt(sum((sc -m)**2 for sc in scores)/len(scores))) | X = int(input())
print((X//500)*1000+(X%500)//5*5) | 0 | null | 21,432,642,863,308 | 31 | 185 |
import sys
for line in sys.stdin:
xy = sorted(map(int , line.split()))
if xy[0] == 0 and xy[1] == 0: break
print(*xy) | n = int(input())
a = list(map(int,input().split()))
lst = [0]*(max(a)+1)
for i in a:
lst[i] += 1
num_lst = [0]*(max(a)+1)
for i in range(1,max(a)+1):
if not lst[i] in [0,1]:
num_lst[i] = lst[i]*(lst[i]-1)//2
ans = sum(num_lst)
for i in a:
if lst[i] in [0,1]:
print(ans)
else:
print(ans-num_lst[i]+((lst[i]-1)*(lst[i]-2)//2)) | 0 | null | 24,239,184,117,422 | 43 | 192 |
import sys
input = lambda: sys.stdin.readline().rstrip()
S = input()
print("ABC" if S == "ARC" else "ARC") | s = input()
if s[1] == 'B':
s1 = s.replace('B', 'R')
else:
s1 = s.replace('R', 'B')
print(s1) | 1 | 24,224,724,913,118 | null | 153 | 153 |
n = int(input())
for i in range(1,n+1):
x = i
if x % 3 == 0:
print('', i, end='')
else:
while True:
if x % 10 == 3:
print('', i, end='')
break
x //= 10
if x == 0:
break
print() | nums = tuple(map(int, input().split()))
s = set(nums)
if len(s) == 2:
print('Yes')
else:
print("No")
| 0 | null | 34,684,904,297,690 | 52 | 216 |
def main():
N, K = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))
C = list(map(int, input().split()))
loop = [0] * N
loopsum = [0] * N
for i in range(N):
if loop[i] > 0:
continue
cnt = 0
cur = i
visited = set()
score = 0
while cur not in visited:
visited.add(cur)
cnt += 1
cur = P[cur]
score += C[cur]
for v in visited:
loop[v] = cnt
loopsum[v] = score
ans = max(C)
for i in range(N):
if loopsum[i] >= 0 and loop[i] <= K:
score = loopsum[i] * (K // loop[i] - 1)
limit = K % loop[i] + loop[i]
else:
score = 0
limit = min(loop[i], K)
cur = i
for _ in range(limit):
cur = P[cur]
score += C[cur]
ans = max(ans, score)
print(ans)
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, k = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))
C = list(map(int, input().split()))
def dfs(i):
if 0 <= visited[i]:
return
visited[i] = idx
cycle.append(i)
global csum
csum += C[i]
dfs(P[i])
visited = [-1]*n
idx = 0
cycles = []
for i in range(n):
if 0 <= visited[i]:
continue
cycle = []
csum = 0
dfs(i)
cycles.append((cycle, csum))
idx += 1
INF = 10**18
ans = -INF
for i in range(n):
cycle, csum = cycles[visited[i]]
cmem = len(cycle)
if 0 < csum:
a, b = divmod(k, cmem)
scoreA = csum*(a-1)
b += cmem
score = 0
scoreB = 0
for _ in range(b):
i = P[i]
score += C[i]
if scoreB < score:
scoreB = score
X = scoreA+scoreB
else:
b = min(k, cmem)
score = 0
INF = 10**18
X = -INF
for _ in range(b):
i = P[i]
score += C[i]
if X < score:
X = score
if ans < X:
ans = X
print(ans)
| 1 | 5,354,551,281,732 | null | 93 | 93 |
n = int(input())
for i in range(0, n):
a, b, c = sorted(map(int, input().strip("\n").split(" ")))
# a,b,c = sorted(input().strip("\n").split(" "))
#print(a, b, c)
if c*c - (a*a + b*b) == 0:
print("YES")
else:
print("NO") | count=int(raw_input())
for i in range(0,count):
a,b,c=map(int,raw_input().split())
if pow(a,2)+pow(b,2)==pow(c,2):
print 'YES'
elif pow(a,2)+pow(c,2)==pow(b,2):
print 'YES'
elif pow(b,2)+pow(c,2)==pow(a,2):
print 'YES'
else:
print 'NO' | 1 | 275,312,950 | null | 4 | 4 |
'''
ITP-1_8-D
????????°
???????????????????????°??¶???????????? ss ???????????????????????????????¨????????????£?¶????????????????????????????????????§???
????????? pp ??????????????????????????????????????°????????????????????????????????????
???Input
????????????????????? ss ????????????????????????
????????????????????? pp ????????????????????????
???Output
pp ??????????????´?????? Yes ??¨?????????????????´?????? No ??¨????????????????????????????????????
'''
# inputData
x = str(input())
y = str(input())
xString = []
for i in x:
xString.append(i)
yString = []
for i in y:
yString.append(i)
n = len(yString)
flag = 0
for i in range(len(xString)):
if xString[i:i+n] == yString:
flag = 1
break
if i+n > len(xString):
if xString[i:]+xString[0:(i+n)%len(xString)] == yString:
flag = 1
break
# outputCheck
if flag == 0:
print('No')
elif flag == 1:
print('Yes') | s=input()
p=input()
b=s
s+=s
ans=0
same_count=0
for i in range(len(b)):
for j in range(len(p)):
if s[i+j]==p[j]:
same_count+=1
if same_count==len(p):
ans=1
same_count=0
if ans==1:
print("Yes")
else:
print("No")
| 1 | 1,746,623,596,214 | null | 64 | 64 |
import sys
def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()
INF = float('inf')
n = I()
# 区間スケジューリング問題 : いくつかの区間の中から重ならないように最大で何個選べるか
# ソート + 貪欲法 で解ける
arm_pos = []
for _ in range(n):
x, l = LI()
arm_pos.append([x - l, x + l])
arm_pos = sorted(arm_pos, key=lambda x: x[1]) # アームの終点の位置でソート
ans = n
for i in range(n - 1):
if arm_pos[i][1] > arm_pos[i + 1][0]: # i のアームの終点が i + 1 のアームの始点 と重なっていた場合
arm_pos[i + 1] = arm_pos[i] # i + 1 のアームを取り除く
ans -= 1
print(ans)
| import math
pi=math.pi
r=float(input())
menseki=r*r*pi
ensyu=2*r*pi
print(str(menseki)+" "+str(ensyu))
| 0 | null | 45,412,685,093,348 | 237 | 46 |
a, b, k = map(int,input().split())
if a <= k:
k -= a
a = 0
if b <= k:
b =0
else:
b -= k
else:
a -= k
print(a, b)
| def solve():
INF = float('inf')
def WarshallFloyd(adjList):
numV = len(adjList)
D = [[INF]*numV for _ in range(numV)]
for u, adj in enumerate(adjList):
for v, wt in adj:
D[u][v] = wt
D[u][u] = 0
for k in range(numV):
Dk = D[k]
for i in range(numV):
Di = D[i]
Dik = Di[k]
for j in range(numV):
D2 = Dik + Dk[j]
if D2 < Di[j]:
D[i][j] = D2
return D
N, M, L = map(int, input().split())
adjL = [[] for _ in range(N)]
for _ in range(M):
A, B, C = map(int, input().split())
A, B = A-1, B-1
adjL[A].append((B, C))
adjL[B].append((A, C))
D = WarshallFloyd(adjL)
adjL2 = [[] for _ in range(N)]
for i in range(N):
for j in range(i+1, N):
if D[i][j] <= L:
adjL2[i].append((j, 1))
adjL2[j].append((i, 1))
D = WarshallFloyd(adjL2)
Q = int(input())
anss = []
for _ in range(Q):
s, t = map(int, input().split())
s, t = s-1, t-1
if D[s][t] == INF:
anss.append(-1)
else:
anss.append(D[s][t]-1)
print('\n'.join(map(str, anss)))
solve()
| 0 | null | 138,843,851,165,630 | 249 | 295 |
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from collections import Counter
def resolve():
n = int(input())
sieve = list(range(n + 1))
primes = []
for i in range(2, n + 1):
if sieve[i] == i:
primes.append(i)
for p in primes:
if p * i > n or sieve[i] < p:
break
sieve[p * i] = p
ans = 0
for i in range(1, n):
C = Counter()
while i > 1:
C[sieve[i]] += 1
i //= sieve[i]
score = 1
for val in C.values():
score *= val + 1
ans += score
print(ans)
resolve() | n = int(input())
l = []
for i in range(3, n + 1):
if i % 3 == 0 or "3" in str(i):
l.append(i)
print("",*l) | 0 | null | 1,766,943,031,008 | 73 | 52 |
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n = I()
a = LI()
ans = 1
cnt = [0] * (n+1)
for i in range(n):
if a[i] == 0:
ans *= 3 - cnt[0]
ans %= mod
else:
ans *= cnt[a[i]-1] - cnt[a[i]]
ans %= mod
cnt[a[i]] += 1
print(ans) | def judge(m, f, r):
p = m + f
if (m == -1 or f == -1 or p < 30):
a = 'F'
elif (p >= 80):
a = 'A'
elif (p >= 65 and p < 80):
a = 'B'
elif (p >= 50 and p < 65 or r >= 50):
a = 'C'
elif (p >= 30 and p < 50):
a = 'D'
return a
while True:
m, f, r = map(int, input().split())
if (m == -1 and f == -1 and r == -1):
break
print(judge(m, f, r)) | 0 | null | 65,726,553,996,598 | 268 | 57 |
def abc172c_tsundoku():
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [0] * (n + 1)
B = [0] * (m + 1)
for i in range(1, n + 1):
A[i] = A[i - 1] + a[i - 1]
if A[i] > k:
n = i - 1
break
for i in range(1, m + 1):
B[i] = B[i - 1] + b[i - 1]
if B[i] > k:
m = i - 1
break
ans = 0
for i in range(0, n + 1):
j = max(ans - i, 0)
if j > m or A[i] + B[j] > k: continue
while j <= m:
if A[i] + B[j] > k:
j -= 1
break
j += 1
j = min(m,j)
ans = max(i + j, ans)
print(ans)
abc172c_tsundoku() | import numpy as np
n,m,k = map(int,input().split())
a_ls = list(map(int, input().split()))
b_ls = list(map(int, input().split()))
a_csum = np.cumsum(a_ls)
b_csum = np.cumsum(b_ls)
def isOK(index, key, l):
if l[index] > key:
return True
else:
return False
def binary_search(l, key):
'''
keyより大きい値を持つ最小のインデックスを返す
'''
left = -1
right = len(l)
while (right - left) > 1:
mid = left + (right - left) // 2
# 直感的に記憶
# 「含まれている」んだったら「含むを許容(等号付き)する右側」はmidまで動かして問題ない
# 新しいrightの位置がkeyの位置だとしても、「含む」は許容されてる
# 「含まれていない」んだったら「含まない(<)左の壁」をそこまで動かしてもkeyを通り過ぎることはない
if isOK(mid, key, l):
right = mid
else:
left = mid
# whileを抜ける時、rightとleftは一個差で、かつkeyがrightの位置にある
return right
ans = 0
for i in range(n):
rest = k - a_csum[i]
if rest < 0:
break
ind = binary_search(b_csum, rest)
canread_b = max(0,ind)
canread = i+1 + canread_b
ans = max(canread, ans)
rest = k
ind = binary_search(b_csum, rest)
canread_b = max(0,ind)
ans = max(canread_b, ans)
print(ans)
| 1 | 10,763,845,746,402 | null | 117 | 117 |
N,A,B = (int(x) for x in input().split())
if (B - A) % 2 == 0:
print((B-A)//2)
else:
if B - A == 1:
if A == 1 or B == N:
print('1')
else:
print('2')
else:
if A <= N-B:
print((A+B-1)//2)
else:
print((2*N-A-B+1)//2) | n,a,b = map(int,input().split())
if (a-b)%2 == 0:
print(abs(a-b)//2)
else:
if abs(a-1) <= abs(n-b):
# b -= abs(a-1)
if (a-b)%2 == 1:
b -= 1
print(abs(a-1)+abs(a-b)//2+1)
else:
print(abs(a-1)+abs(a-b)//2)
else:
# a += abs(n-b)
if (a-b)%2 == 1:
# b += 1
a += 1
print(abs(n-b)+abs(a-b)//2+1)
else:
print(abs(n-b)+abs(a-b)//2)
| 1 | 109,601,443,946,240 | null | 253 | 253 |
import math
H, W, K = map(int, input().split())
S = [list(map(lambda x: int(x=='1'), input())) for _ in range(H)]
def cal_min_vert_div(hs):
cnt = 0
n_h_div = len(hs)
n_white = [0]*n_h_div
for i in range(W):
for j in range(n_h_div):
n_white[j] += hs[j][i]
if n_white[j] > K:
n_white = [hs[k][i] for k in range(n_h_div)]
cnt += 1
if max(n_white)>K:
return math.inf
break
return cnt
ans = math.inf
for mask in range(2**(H-1)):
hs = []
tmp = S[0]
for i in range(H-1):
if mask>>i & 1:
hs.append(tmp)
tmp = S[i+1]
else:
tmp = [tmp[w]+S[i+1][w] for w in range(W)]
hs.append(tmp)
tmp = cal_min_vert_div(hs)+sum(map(int, bin(mask)[2:]))
ans = min(ans, tmp)
print(ans)
| if __name__ == "__main__":
n = int(input())
ops = []
words = []
for _ in range(n):
op, word = input().split()
ops.append(op)
words.append(word)
db = set()
for op, word in zip(ops, words):
if op=='insert':
db.add(word)
else:
if word in db:
print("yes")
else:
print("no")
| 0 | null | 24,354,738,253,340 | 193 | 23 |
n=int(input())
an=0
for j in range(1,n):
an+=int((n-1)/j)
print(an) | def main():
n = int(input())
t = (n+1) // 2
if n == 1:
print(1)
elif n % 2 == 0:
print(0.5)
else:
print(t*1.0 / n)
main() | 0 | null | 89,609,155,031,878 | 73 | 297 |
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])) | r, c = map(int, input().split())
tbl = [[] for _ in range(r)]
cSum = [0 for _ in range(c+1)]
for i in range(r):
tblS = input()
tbl[i] = list(map(int, tblS.split()))
print(tblS, end = '')
print(' ', sum(tbl[i]), sep = '')
for j in range(c):
cSum[j] += tbl[i][j]
cSum[c] += sum(tbl[i])
print(' '.join(map(str, cSum)))
| 1 | 1,377,914,323,200 | null | 59 | 59 |
n=int(input())
s=list(input())
r=[]
g=[]
b=[]
for i in range(n):
if s[i]=='R':
r.append(i)
elif s[i]=='G':
g.append(i)
else:
b.append(i)
import bisect
def binary_search(a, x):
# 数列aのなかにxと等しいものがあるか返す
i = bisect.bisect_left(a, x)
if i != len(a) and a[i] == x:
return True
else:
return False
ans=0
for i in range(len(r)):
for j in range(len(g)):
p=0
if r[i]<g[j]:
if binary_search(b,g[j]-r[i]+g[j]):
p+=1
if binary_search(b,r[i]+(g[j]-r[i])/2):
p+=1
if binary_search(b,r[i]-(g[j]-r[i])):
p+=1
else:
if binary_search(b,r[i]-g[j]+r[i]):
p+=1
if binary_search(b,g[j]+(r[i]-g[j])/2):
p+=1
if binary_search(b,g[j]-(r[i]-g[j])):
p+=1
ans+=len(b)-p
print(ans)
| def inN():
return int(input())
def inL():
return list(map(int,input().split()))
def inNL(n):
return [list(map(int,input().split())) for i in range(n)]
n = inN()
s = input()
r = s.count('R')
b = s.count('B')
g = s.count('G')
cnt = 0
for i in range(n):
for j in range(i+1,n):
k = 2*j - i
if k < n:
if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
cnt += 1
print(r*g*b - cnt) | 1 | 36,356,004,675,594 | null | 175 | 175 |
A = input()
B = input()
se = set(["1","2","3"])
a = se-set([A,B])
print(a.pop()) | a = int(input())
b = int(input())
if a == 2 and b == 3 or b == 2 and a == 3:
print('1')
elif a == 1 and b == 2 or b == 1 and a == 2:
print('3')
else:
print('2')
| 1 | 110,469,220,513,470 | null | 254 | 254 |
a = input().lower()
cnt = 0
while 1:
c = input()
if c == 'END_OF_TEXT':
break
cnt += c.lower().split().count(a)
print(cnt)
| n = int(input())
# 動的計画法
def fibonacci(n):
F = [0]*(n+1)
F[0] = 1
F[1] = 1
for i in range(2, n+1):
F[i] = F[i-2] + F[i-1]
return F
f = fibonacci(n)
print(f[n])
| 0 | null | 907,331,814,728 | 65 | 7 |
N = int(input())
d_list = list(map(int,input().split()))
ans = 0
for i in range(N-1):
for j in range(i+1,N):
ans += d_list[i] * d_list[j]
print(ans)
| #!/usr/bin/env python
def main():
N = int(input())
D = list(map(int, input().split()))
ans = 0
for i in range(N-1):
d1 = D[i]
for d2 in D[i+1:]:
ans += d1 * d2
print(ans)
if __name__ == '__main__':
main()
| 1 | 168,164,737,878,452 | null | 292 | 292 |
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, As):
ans = 0
i = 1
for A in As:
if A == i:
i += 1
else:
ans += 1
ans = -1 if ans == N else ans
print(ans)
if __name__ == '__main__':
# S = input()
N = int(input())
# N, M = map(int, input().split())
As = [int(i) for i in input().split()]
# Bs = [int(i) for i in input().split()]
solve(N, As)
| # -*- coding: UTF-8 -*-
# Stack
top = 0
S = {}
def push(x):
global top
global S
top += 1
S[top] = x
def pop():
global top
global S
top -= 1
return S[top + 1]
input_list = list(input().split()) #計算対象(スペース区切り→配列に展開)
for target in input_list:
if target == '+':
a = pop()
b = pop()
c = b+a
push(c)
elif target == '-':
a = pop()
b = pop()
c = b-a
push(c)
elif target == '*':
a = pop()
b = pop()
c = b*a
push(c)
else:
push(int(target))
print(pop())
| 0 | null | 57,114,476,253,600 | 257 | 18 |
S=input()
T=input()
yes=True
l=len(S)
for i in range(0,l):
if S[i]!=T[i]:
yes=False
break
if yes:
print("Yes")
else:
print("No")
| t = input()
if(len(t) == 1):
if (t[0] == '?'): t = "D"
if(t[0] == '?'):
if (t[1] == 'D'): t = "".join(['P' , t[1:]])
elif(t[1] == '?'): t = "".join(['PD', t[2:]])
else: t = "".join(['D' , t[1:]])
if(t[-1] == '?'):
t = "".join([t[:-1], 'D'])
for i in range(len(t)-1):
if(t[i] == '?'):
if(t[i-1] == 'P'): t = "".join([t[:i], 'D' , t[i+1:]])
elif(t[i+1] == 'D'): t = "".join([t[:i], 'P' , t[i+1:]])
elif(t[i+1] == 'P'): t = "".join([t[:i], 'D' , t[i+1:]])
elif(t[i+1] == '?'): t = "".join([t[:i], 'PD', t[i+2:]])
print(t) | 0 | null | 19,952,626,473,638 | 147 | 140 |
while True:
a, b, c = map(int, raw_input().split())
if (a == -1) and (b == -1) and (c == -1):
break
if (a == -1) or (b == -1):
print "F"
elif (a + b) >= 80:
print "A"
elif (a + b) >= 65:
print "B"
elif (a + b) >= 50:
print "C"
elif (a + b) < 30:
print "F"
elif c >= 50:
print "C"
else:
print "D" | def code():
l = []
while True:
m,f,r = map(int,input().split())
if m == f == r == -1:
break
else:
l.append([m,f,r])
for i in l:
s = ''
x = i[0]+i[1]
if i[0] == -1 or i[1] == -1:
s = 'F'
elif x >= 80:
s = 'A'
elif x >= 65:
s = 'B'
elif x >= 50:
s = 'C'
elif x >= 30:
s = 'D'
if i[2] >= 50:
s = 'C'
else:
s = 'F'
print(s)
code() | 1 | 1,238,068,279,420 | null | 57 | 57 |
#!/usr/bin/env python3
import collections as cl
import sys
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def main():
bingo_num = []
for i in range(3):
N = LI()
bingo_num.append(N)
N = II()
for i in range(N):
b = II()
for row_i in range(3):
for col_j in range(3):
if bingo_num[row_i][col_j] == b:
bingo_num[row_i][col_j] = 0
for i in range(3):
if sum(bingo_num[i]) == 0:
print("Yes")
exit()
for j in range(3):
if bingo_num[0][j] + bingo_num[1][j] + bingo_num[2][j] == 0:
print("Yes")
exit()
sum_naname = 0
sum_naname_2 = 0
for i in range(3):
sum_naname += bingo_num[i][i]
sum_naname_2 += bingo_num[i][2 - i]
if sum_naname == 0 or sum_naname_2 == 0:
print("Yes")
exit()
print("No")
main()
| import copy
D = int(input())
c = list(map(int, input().split()))
s = []
for _ in range(D):
s.append(list(map(int, input().split())))
t = []
for _ in range(D):
t.append(int(input()))
u = [] # last(d,i)
x = [0] * 26
u.append(x)
for i in range(D):
v = copy.deepcopy(u)
y = v[-1]
y[t[i]-1] = i+1
u.append(y)
del u[0]
ans = 0
for i in range(D):
ans += s[i][t[i]-1]
for j in range(26):
ans -= c[j] * ((i+1) - u[i][j])
print(ans)
| 0 | null | 34,773,916,395,878 | 207 | 114 |
def LinearSearch1(S, n, t):
for i in range(n):
if S[i] == t:
return i
break
else:
return -1
"""
def LinearSearch2(S, n, t):
S.append(t)
i = 0
while S[i] != t:
i += 1
S.pop()
if i == n:
return -1
else:
return i
"""
n = int(input())
S = [int(s) for s in input().split()]
q = int(input())
T = {int(t) for t in input().split()}
ans = sum(LinearSearch1(S, n, t) >= 0 for t in T)
print(ans) | while True:
a, b = map(int, input().split(" "))
if a == b == 0:
break
if a > b:
a, b = b, a
print("%d %d" % (a,b))
| 0 | null | 284,264,445,252 | 22 | 43 |
apple = list(map(int, input().split()))
x = apple[0]
y = apple[1] #to eat
a = apple[2]
b = apple[3] #i have
c = apple[4]
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
XredApl = []
for i in range(x):
XredApl.append(p[i])
YgrnApl = []
for i in range(y):
YgrnApl.append(q[i])
fnlst = XredApl + YgrnApl + r
fnlst.sort(reverse=True)
s = 0
for i in range(x+y):
s += fnlst[i]
print(s)
| x = int(input())
for i in range(1,x+1):
if 100*i <= x and x <= 105*i:
print(1)
break
else:
print(0) | 0 | null | 86,193,170,988,624 | 188 | 266 |
N=int(input())
ans=0
for a in range(1,N):
ans+=int((N-1)//a)
print(ans)
| x = int(input())
if x >= 30:
ans = 'Yes'
else:
ans = 'No'
print(ans) | 0 | null | 4,130,680,274,462 | 73 | 95 |
def main():
n, m = map(int, input().split())
# nは偶数、mは奇数
# n+mから2つ選ぶ選び方は
# n:m = 0:2 和は 偶数、選び方はmC2
# n:m = 1:1 和は 奇数 (今回はこれは含めない)
# n:m = 2:0 和は 偶数、選び方はnC2
cnt = 0
if m >= 2:
cnt += m * (m -1) // 2
if n >=2:
cnt += n * (n -1) // 2
print(cnt)
if __name__ == '__main__':
main() | n,m = map(int,input().split())
ans = 0
for i in range(n-1):
ans = ans + i+1
for b in range(m-1):
ans = ans + b+1
print(ans) | 1 | 45,272,772,613,120 | null | 189 | 189 |
weatherS = input()
p = weatherS[0] == 'R'
q = weatherS[1] == 'R'
r = weatherS[2] == 'R'
if p and q and r:
serial = 3
elif (p and q) or (q and r):
serial = 2
elif p or q or r:
serial = 1
else:
serial = 0
print(serial) | S = input()
sum = 0
for i in range(3):
if S[i]=="R":
sum += 1
if sum == 2 and S[1] == "S":
sum = 1
print(sum)
| 1 | 4,810,593,152,480 | null | 90 | 90 |
from bisect import bisect_left as lower_bound
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def show(*inp, end='\n'):
if show_flg:
print(*inp, end=end)
YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True
def main():
N = I()
XL = []
ans = 0
for i in range(N):
x, l = MI()
XL.append((x + l, x - l))
# print(XL)
XL.sort()
cur = -10**19
r = 0
for i in range(N):
if XL[i][1] >= cur:
r += 1
cur = XL[i][0]
# print(i, cur)
print(r)
if __name__ == '__main__':
main()
| from functools import lru_cache
MOD = 998244353
def solve_baka(n, m, k):
print('params:', n, m, k)
ans = 0
for i in range(m**n):
s = ''
for j in range(n):
s = str(i % m) + s
i = i // m
cnt = 0
for j in range(n-1):
if s[j] == s[j+1]:
cnt += 1
if cnt <= k:
ans += 1
print(s, cnt <= k)
print('ans:', ans)
return ans
@lru_cache(maxsize=None)
def modpow(n, m):
ret = 1
while m > 0:
if m & 1:
ret = ret * n % MOD
n = n * n % MOD
m >>= 1
return ret
def solve(n, m, k):
factorial = [1]
for i in range(1, max(n+1, m+1)):
factorial.append(i*factorial[i-1] % MOD)
permutation = [1]
for i in list(range(1, n))[::-1]:
permutation.append(i * permutation[-1] % MOD)
ans = 0
for i in range(0, k+1):
val = m * permutation[i] % MOD
val = val * modpow(factorial[i], MOD-2) % MOD
val = val * modpow(m-1, n-1-i) % MOD
ans = (ans + val) % MOD
return ans
def main():
# for n in range(3, 7):
# for m in range(1, 5):
# for k in range(0, n):
# assert solve_baka(n, m, k) == solve(n, m, k)
n, m, k = map(int, input().split())
print(solve(n, m, k))
if __name__ == '__main__':
main()
| 0 | null | 56,555,423,104,670 | 237 | 151 |
N, K = map(int, input().split())
H = list(map(int, input().split()))
print(len(list(filter(lambda x: x >= K, H)))) | # import itertools
# import math
# import sys
import numpy as np
# N = int(input())
# S = input()
# n, *a = map(int, open(0))
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# S = input()
# d = sorted(d.items(), key=lambda x:x[0]) # keyでsort
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement([i for i in range(1, M + 1)], N))
# print(a[0][0])
# print(conditions[0])
A = np.array(A)
B = np.array(B)
cum_A = np.cumsum(A)
cum_A = np.insert(cum_A, 0, 0)
cum_B = np.cumsum(B)
cum_B = np.insert(cum_B, 0, 0)
j = M
max_num = 0
for i in range(N + 1):
while(True):
# j -= 1
if j < 0:
break
minute = cum_A[i] + cum_B[j]
if minute <= K:
if i + j > max_num:
max_num = i + j
break
j -= 1
print(max_num) | 0 | null | 95,291,184,688,228 | 298 | 117 |
S = str(input())
Q = int(input())
flip = 0
front,back = '',''
for i in range(Q):
j = input()
if len(j) == 1:
flip += 1
continue
else:
if j[2] == '1' and flip % 2 == 0:
front = j[4] + front
continue
elif j[2] == '2' and flip % 2 == 0:
back = back + j[4]
continue
elif j[2] == '1' and flip % 2 ==1:
back= back + j[4]
continue
elif j[2] == '2' and flip % 2 ==1:
front = j[4] + front
continue
S = front + S + back
if flip % 2 == 1:
S = S[::-1]
print(S) | from collections import deque
s=input()
q=int(input())
n=0
que=deque(s)
for i in range(q):
l=input()
if l[0]=='1':
n+=1
else:
if (l[2]=='1' and n%2==0) or (l[2]=='2' and n%2==1):
que.appendleft(l[4])
else:
que.append(l[4])
ans=''.join(que)
if n%2==0:
print(ans)
else:
print(ans[::-1])
| 1 | 57,280,113,813,312 | null | 204 | 204 |
string = input()
numbers = string.split(' ')
numbers.sort()
print(numbers[0], numbers[1], numbers[2])
| def show_list(a):
for x in a:
print x,
print
def stable_check(sorted_values,sorted_suits,default_values,default_suits,n):
for i in xrange(1,10):
check_ss = []
check_ds = []
if i in sorted_values:
for x in xrange(n):
if i == sorted_values[x]:
check_ss.append(sorted_suits[x])
if i == default_values[x]:
check_ds.append(default_suits[x])
for x in xrange(len(check_ss)):
if check_ss[x]!=check_ds[x]:
return "Not stable"
return "Stable"
def bubble_sort(values,suits,n):
flag = True
while flag:
flag = False
for j in reversed(xrange(1,n)):
if values[j] < values[j-1]:
tmp = values[j]
values[j] = values[j-1]
values[j-1] = tmp
tmp = suits[j]
suits[j] = suits[j-1]
suits[j-1] = tmp
flag = True
show_list(marge_suits_values(values,suits,n))
def selection_sort(values,suits,n):
for i in xrange(n):
minj = i
for j in xrange(i,n):
if values[j]<values[minj]:
minj = j
if minj!=i:
tmp = values[i]
values[i]=values[minj]
values[minj]=tmp
tmp = suits[i]
suits[i]=suits[minj]
suits[minj]=tmp
show_list(marge_suits_values(values,suits,n))
def marge_suits_values(values,suits,n):
ans = []
for x in xrange(n):
ans.append(suits[x]+str(values[x]))
return ans
def main():
n = input()
a = raw_input().split()
suits1 = []
values1 =[]
for x in xrange(n):
suits1.append(a[x][0])
values1.append(int(a[x][1]))
suits2 = list(suits1)
values2 = list(values1)
bubble_sort(values1,suits1,n)
print stable_check(values1,suits1,values2,suits2,n)
values1 = list(values2)
suits1 = list(suits2)
selection_sort(values2,suits2,n)
print stable_check(values2,suits2,values1,suits1,n)
if __name__ == '__main__':
main() | 0 | null | 217,536,957,892 | 40 | 16 |
days_summer_vacation, amount_homework = map(int, input().split())
a = map(int, input().split())
schedule_hw = list(a)
need_days_hw = 0
for i in schedule_hw:
need_days_hw += i
if days_summer_vacation > need_days_hw:
print(days_summer_vacation - need_days_hw)
elif days_summer_vacation == need_days_hw:
print(0)
else:
print(-1) | x = int(input())
p = list(map(int, input().split()))
if len(set(p)) == len(p):
print("YES")
else:
print("NO") | 0 | null | 53,001,125,971,520 | 168 | 222 |
print("aA"[input().isupper()]) | if input().islower() == True:
print("a")
else:
print("A") | 1 | 11,338,828,260,188 | null | 119 | 119 |
S = int(input())
m = (10**9)+7
lists=[1]+[0]*(S)
for i in range(S):
for j in range(3,S+1):
try:
lists[i+j]+=lists[i]
except IndexError:
break
print ((lists[S])%m) | s = int(input())
n = [1,0,0]
if s < 3:
print(n[s])
else:
for i in range(s-2):
n.append(n[-1]+n[-3])
print((n[-1])%1000000007) | 1 | 3,292,637,749,720 | null | 79 | 79 |
def Li():
return list(map(int, input().split()))
N = int(input())
A = Li()
ans = 1
if 0 in A:
ans = 0
else:
for i in A:
ans *= i
if ans > pow(10, 18):
ans = -1
break
print(ans)
| n = int(input())
lst = list(map(int,input().split()))
lst = sorted(lst)
ans = 1
for i in range (n):
ans = ans*lst[i]
if (ans > 10**18):
ans = -1
break
print(ans)
| 1 | 16,257,098,913,230 | null | 134 | 134 |
import sys
def main():
orders = sys.stdin.readlines()[1:]
dna_set = set()
for order in orders:
command, dna = order.split(" ")
if command == "insert":
dna_set.add(dna)
elif command == "find":
if dna in dna_set:
print("yes")
else:
print("no")
if __name__ == "__main__":
main() | dict = {}
def insert(word):
global dict
dict[word] = 0
def find(word):
global dict
if word in dict:
print('yes')
else:
print('no')
def main():
N = int(input())
order = [list(input().split()) for _ in range(N)]
for i in range(N):
if order[i][0] == 'insert':
insert(order[i][1])
elif order[i][0] == 'find':
find(order[i][1])
main()
| 1 | 74,661,382,860 | null | 23 | 23 |
N = int(input())
ans = ''
while N:
N -= 1
N, mod = divmod(N, 26)
ans += chr(ord('a') + mod)
print(ans[::-1]) | # -*- coding: utf-8 -*-
def num2alpha(num):
if num <= 26:
return chr(64+num)
elif num % 26 == 0:
return num2alpha(num//26-1)+chr(90)
else:
return num2alpha(num // 26) + chr(64 + num % 26)
def base_10_to_n(X, n):
if (int(X/n)):
return base_10_to_n(int(X/n), n)+str(X % n)
return str(X % n)
def main():
n = int(input())
alpha = num2alpha(n)
print(alpha.lower())
if __name__ == "__main__":
main()
| 1 | 12,001,577,210,392 | null | 121 | 121 |
def main():
n = int(input())
ans = n * (n + 1) - 1 # 1とk 自信
i = 2
while i * i <= n:
num = n // i
min_i = i * i
max_i = i * num
ans += (num - i + 1) * (min_i + max_i) # 自分自身
ans -= min_i
i += 1
print(ans)
if __name__ == "__main__":
main() | #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
n=int(input())
ans=0
for i in range(1,n+1):
num=n//i
ans+=(num*(i+num*i))//2
print(ans) | 1 | 11,089,618,609,888 | null | 118 | 118 |
from functools import reduce
n,a,b=map(int,input().split())
mod=10**9+7
def nCk(n,k):
c=reduce(lambda x,y: x*y%mod, range(n,n-k,-1))
m=reduce(lambda x,y: x*y%mod, range(1,k+1))
return c*pow(m,mod-2,mod)%mod
all=pow(2,n,mod)
nCa=nCk(n,a)
nCb=nCk(n,b)
print((all-nCa-nCb-1)%mod) | def comb(n, k, mod):
m = 1
for i in range(n, n - k, -1):
m = m * i % mod
n = 1
for i in range(1, k + 1):
n = n * i % mod
return (m * pow(n, mod - 2, mod) % mod)
def main():
mod = 1000000007
n, a, b = map(int, input().split())
ans = pow(2, n, mod) - 1 - comb(n, a, mod) - comb(n, b, mod)
ans = ans % mod
print(ans)
if __name__ == '__main__':
main()
| 1 | 66,050,377,808,730 | null | 214 | 214 |
a, b = map(int, input().split())
for price in range(0,1010) :
if int(price*0.08) == a and int(price*0.10) == b :
print(price)
break
else :
print("-1")
| n = int(input())
cards = {
'S': [],
'H': [],
'C': [],
'D': []
}
for _ in range(n):
color, rank = input().split()
cards[color].append(rank)
for color in ['S', 'H', 'C', 'D']:
for rank in [x for x in range(1, 14) if str(x) not in cards[color]]:
print(color, rank) | 0 | null | 28,825,880,716,880 | 203 | 54 |
a, b, c = map(int, input().split())
d, e, f = map(int, input().split())
g, h, i = map(int, input().split())
n = int(input())
for j in range(n):
x = int(input())
if a == x:
a = 0
elif b == x:
b == 0
elif c == x:
c = 0
elif d == x:
d = 0
elif e == x:
e = 0
elif f == x:
f = 0
elif g == x:
g = 0
elif h == x:
h = 0
elif i == x:
i = 0
y =[[a, b, c], [d, e, f], [g, h, i], [a, d, g], [b, e, h], [c, f, i], [a, e, i], [c, e, g]]
print("Yes" if [0, 0, 0] in y else "No") | print('Yes'if len(set(list(map(int,input().split()))))==1else'No') | 0 | null | 71,621,786,584,910 | 207 | 231 |
n=int(input())
a=[0]+[int(x) for x in input().split()]
ans=[0]*(n+1)
for i in range(len(a)):
ans[a[i]]=i
ans.pop(0)
print(*ans) | sute = map(int,raw_input().split())
num = map(int,raw_input().split())
for i in range(len(num) - 1):
print "%d" % num[len(num) - i - 1],
print num[0] | 0 | null | 90,932,937,698,628 | 299 | 53 |
A = int(input())
B = int(input())
answer = [1,2,3]
answer = set(answer)
wrong = set([A, B])
temp = answer - wrong
print(temp.pop()) | A = int(input())
B = int(input())
for x in range(1, 4):
if x not in [A, B]:
print(x)
break
| 1 | 110,717,289,458,112 | null | 254 | 254 |
c = 0
def merge(A, l, m, r):
global c
L = A[l:m]
L.append(1e10)
R = A[m:r]
R.append(1e10)
i, j = 0, 0
for k in range(l, r):
c += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
def sort(A, l, r):
if r-l > 1:
m = (l+r)//2
sort(A, l, m)
sort(A, m, r)
merge(A, l, m, r)
N = int(input())
A = list(map(int, input().split()))
sort(A, 0, N)
print(" ".join(map(str, A)))
print(c)
| #ciが R のとき赤、W のとき白です。
#入力
#N
#c1...cN
N = int(input())
C = input()
Rednum = C.count('R')
#print(Rednum)
#Rの数 - 左にある赤の数が答
NewC = C[:Rednum]
#print(NewC)
Whinum = NewC.count('R')
print(Rednum - Whinum)
| 0 | null | 3,213,586,062,040 | 26 | 98 |
# C - Subarray Sum
def main():
N, K, S = map(int, input().split())
res = [str(S)] * K + ["1" if S == 10 ** 9 else str(S + 1)] * (N - K)
print(" ".join(res))
if __name__ == "__main__":
main()
| N,K,S=map(int,input().split())
ans=[S]*K
if S==10**9:
ans.extend([S-1]*(N-K))
else:
ans.extend([S+1]*(N-K))
print(*ans) | 1 | 91,381,469,679,500 | null | 238 | 238 |
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline # 文字列読み込む時はこっち
import numpy as np
from functools import partial
array = partial(np.array, dtype=np.int64)
zeros = partial(np.zeros, dtype=np.int64)
full = partial(np.full, dtype=np.int64)
ra = range
enu = enumerate
def exit(*argv, **kwarg):
print(*argv, **kwarg)
sys.exit()
def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと
def a_int(): return int(readline())
def ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64)
def read_matrix(H, W):
'''return np.ndarray shape=(H,W) matrix'''
lines = []
for _ in range(H):
lines.append(read())
lines = ' '.join(lines) # byte同士の結合ができないのでreadlineでなくreadで
return np.fromstring(lines, sep=' ', dtype=np.int64).reshape(H, W)
def read_col(H):
'''H is number of rows
A列、B列が与えられるようなとき
ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合'''
ret = []
for _ in range(H):
ret.append(list(map(int, readline().split())))
return tuple(map(list, zip(*ret)))
def read_tuple(H):
'''H is number of rows'''
ret = []
for _ in range(H):
ret.append(tuple(map(int, readline().split())))
return ret
MOD = 10**9 + 7
INF = 2**31 # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right # , insort_left, insort_right
from functools import reduce
from math import gcd
def lcm(a, b):
# 最小公倍数
g = gcd(a, b)
return a // g * b
# from numba import njit
# @njit('(i8,i8,i8[:])',cache=True)
N = a_int()
XY = read_matrix(N, 2)
X = XY[:, 0]
Y = XY[:, 1]
f0 = X - Y
f1 = X + Y
print(max(f0.max() - f0.min(), f1.max() - f1.min()))
| N = int(input())
print(int(N / 2 + 0.5) /N) | 0 | null | 90,331,798,939,140 | 80 | 297 |
N = input()
N = list(map(int,N))
print( 'Yes' if 7 in N else 'No') | N = input()
flag = False
for i in range(len(N)):
if N[i] =="7":
flag =True
if flag:
print ("Yes")
else :
print ("No") | 1 | 34,549,125,108,082 | null | 172 | 172 |
from itertools import product
H, W, K = map(int, input().split())
grid = ""
for _ in range(H):
grid += input()
ans = 10000
for Hcut in product((0, 1), repeat = H-1):
Gr_num = sum(Hcut) + 1
old = [0]*Gr_num
cnt = 0
for i in range(W):
#縦一列のchocoを見る
choco = grid[i::W]
new = [0]*Gr_num
gr = 0
for j in range(H):
new[gr] += int(choco[j])
if j < H-1:
if Hcut[j] == 1:
gr += 1
#そもそも一列でオーバーしてたら詰み。
if max(new) > K:
cnt += 10000
break
#新しい一列を追加しても大丈夫か確認
check = [old[gr] + new[gr] for gr in range(Gr_num)]
if max(check) > K:
old = new[:]
cnt += 1
else:
old = check[:]
ans = min(ans, cnt+sum(Hcut))
print(ans) | s=input()
t=input()
i=len(s)-1
counter=0
while i>=0:
if s[i]!=t[i]:
counter+=1
i=i-1
print(counter) | 0 | null | 29,462,511,805,220 | 193 | 116 |
while True:
H,W=[int(i) for i in input().split(" ")]
if H==W==0:
break
for h in range(H):
s="#" if h%2==0 else "."
for w in range(W-1):
s+="#" if s[-1]=="." else "."
print(s)
print() | while True:
a, b = map(int, input().split())
if a == 0 and b == 0:
break
for n in range(a):
mark1 = "#"
mark2 = "."
outLen = ""
if n % 2 == 0 :
mark1 = "."
mark2 = "#"
for m in range(b):
if m % 2 != 0:
outLen = outLen + mark1
else:
outLen = outLen + mark2
print(outLen)
print("")
| 1 | 889,618,074,618 | null | 51 | 51 |
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)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
N,K = I()
h = l()
for i in range(N):
if h[i] >= K:
count += 1
print(count)
| n, k = map(int, input().split())
l = list(map(int, input().split()))
cnt = 0;
for i in l:
if i >= k:
cnt += 1;
print(cnt) | 1 | 178,755,952,138,962 | null | 298 | 298 |
n, k = map(int, input().split())
p = list(map(int, input().split()))
p = [_p-1 for _p in p]
c = list(map(int, input().split()))
ans = -float('inf')
visited = [False] * n
ss = []
for i in range(n):
if visited[i]: continue
cur = i
s = []
while not visited[cur]:
visited[cur] = True
s.append(c[cur])
cur = p[cur]
ss.append(s)
for s in ss:
m = len(s)
cumsum = [0] * (m*2+1)
for i in range(2*m):
cumsum[i+1] = cumsum[i] + s[i%m]
amari = [-float('inf')] * m
for i in range(m):
for j in range(m):
amari[j] = max(amari[j], cumsum[i+j] - cumsum[i])
for r in range(0, m):
if r > k: continue
q = (k-r)//m
if r==0 and q==0:
continue
if cumsum[m] > 0:
ans = max(ans, amari[r] + cumsum[m]*q)
elif r > 0:
ans = max(ans, amari[r])
print(ans)
| # -*- coding: utf-8 -*-
import sys
from itertools import accumulate
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K = map(int, readline().split())
P = [0] + list(map(int,readline().split()))
C = [0] + list(map(int,readline().split()))
ans = -10 ** 10
for i in range(1,N+1):
l = 1
j = P[i]
s = C[j]
ans = max(ans, s) #iを始まりとして
while j != i: # 1周期もしないときの最大値
j = P[j]
s += C[j]
l += 1
if K >= l:
ans = max(ans, s)
c = 1
j = P[j]
t = C[j]
ans = max(ans, t + ((K - c) // l) * s) # 1回と周期分
while j != i:
j = P[j]
t += C[j]
c += 1
if K >= c:
ans = max(ans, t + ((K - c) // l) * s) # c回と周期分
print(ans) | 1 | 5,379,972,237,670 | null | 93 | 93 |
from itertools import combinations
n=int(input())
a=list(map(int,input().split()))
q=int(input())
m=list(map(int,input().split()))
s=set()
for i in range(1,n+1):
for j in combinations(a,i):
s.add(sum(j))
for i in m:
if i in s:
print("yes")
else:
print("no")
| def main():
input()
array_a = list(map(int, input().split()))
input()
array_q = map(int, input().split())
def can_construct_q (q, i, sum_sofar):
if sum_sofar == q or sum_sofar + array_a[i] == q:
return True
elif sum_sofar > q or i >= len (array_a) - 1:
return False
if can_construct_q(q, i + 1, sum_sofar + array_a[i]):
return True
if can_construct_q(q, i + 1, sum_sofar):
return True
sum_array_a = sum(array_a)
for q in array_q:
#print(q)
if sum_array_a < q:
print('no')
elif can_construct_q(q, 0, 0):
print('yes')
else:
print('no')
return
main()
| 1 | 102,053,914,820 | null | 25 | 25 |
n,m=map(int,input().split())
ans=["#"]*n
for _ in range(m):
s,c=map(int,input().split())
# 同じ桁に複数の指示が飛んできたら狩猟
if not ans[s-1] in["#",c]:
print(-1)
exit()
ans[s-1]=c
# nが一桁の時の対応
if len(ans)==1:
print(0 if ans[0]=="#" else ans[0])
exit()
#頭の数字について
if ans[0]==0:
print(-1)
exit()
if ans[0]=="#":
ans[0]=1
for num in ans:
print(num if num!="#" else 0,end="")
| n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
for i in range(10 ** (n - 1) - (n == 1), 10 ** n):
is_ok = True
for s, c in sc:
s -= 1
if int(str(i)[s]) != c:
is_ok = False
if is_ok:
print(i)
exit()
print(-1) | 1 | 60,705,407,700,730 | null | 208 | 208 |
n = int(input())
for _ in range(n):
edges = sorted([int(i) for i in input().split()])
if edges[0] ** 2 + edges[1] ** 2 == edges[2] ** 2:
print("YES")
else:
print("NO")
| count=int(raw_input())
for i in range(0,count):
a,b,c=map(int,raw_input().split())
if pow(a,2)+pow(b,2)==pow(c,2):
print 'YES'
elif pow(a,2)+pow(c,2)==pow(b,2):
print 'YES'
elif pow(b,2)+pow(c,2)==pow(a,2):
print 'YES'
else:
print 'NO' | 1 | 314,230,532 | null | 4 | 4 |
#16D8101023J 久保田凌弥 kubotarouxxx python3
x,y=map(int, input().split())
if x>y:
while 1:
if (x%y)==0:
print(y)
break
a=x%y
x=y
y=a
else:
while 1:
if (y%x)==0:
print(x)
break
a=y%x
y=x
x=a
| import sys
import math
def gcd(x, y):
if y == 0:
return x
return gcd(y, x%y)
x, y = map(int, raw_input().split())
print gcd(min(x, y), max(x, y)) | 1 | 7,721,416,352 | null | 11 | 11 |
import sys
input = sys.stdin.readline
class SegmentTree:
def __init__(self,l):
nb = bin(len(l))[2:]
b = sum([int(d) for d in nb])
if b == 1:
self.end_leaves = pow(2,len(nb)-1)
else:
self.end_leaves = pow(2,len(nb))
self.tree = [set() for _ in range(self.end_leaves*2)]
for i in range(len(l)):
self.tree[self.end_leaves+i].add(l[i])
def union(self,a):
if a >= self.end_leaves // 2:
self.tree[a] = self.tree[a*2] | self.tree[a*2+1]
return self.tree[a]
else:
self.tree[a] = self.union(a*2) | self.union(a*2+1)
return self.tree[a]
def update(self,a,s):
x = a + self.end_leaves
if s not in self.tree[x]:
self.tree[x] = set(s)
while x > 1:
x //= 2
self.tree[x] = self.tree[x*2] | self.tree[x*2+1]
def query(self,l,r):
x = l + self.end_leaves
y = r + self.end_leaves
tl = set()
tr = set()
while y - x > 1:
if x % 2 == 1:
tl = tl | self.tree[x]
x += 1
if y % 2 == 0:
tr = self.tree[y] | tr
y -= 1
x >>= 1
y >>= 1
if y - x == 0:
print(len(tl|tr|self.tree[x]))
else:
print(len(tl|tr|self.tree[x]|self.tree[y]))
N = int(input())
S = list(input())
st = SegmentTree(S)
st.union(1)
Q = int(input())
for i in range(Q):
q = input().split()
if q[0] == '1':
st.update(int(q[1])-1,q[2])
else:
st.query(int(q[1])-1,int(q[2])-1) | n = int(input())
from collections import deque
graph = [deque([]) for _ in range(n+1)]
for _ in range(n):
u, k, *v = [int(x) for x in input().split()]
v.sort()
for i in v:
graph[u].append(i)
arrive = [-1 for i in range(n+1)]
finish = [-1 for i in range(n+1)]
times = 0
def dfs(v):
global times
times += 1
arrive[v] = times
stack = [v]
while stack:
v = stack[-1]
if graph[v]:
w = graph[v].popleft()
if arrive[w] == -1:
times += 1
arrive[w] = times
stack.append(w)
else:
times += 1
finish[v] = times
stack.pop()
return
for i in range(n):
if arrive[i+1] == -1:
dfs(i+1)
for j in range(n):
tmp = [j+1, arrive[j+1], finish[j+1]]
print(*tmp)
| 0 | null | 31,409,362,838,204 | 210 | 8 |
#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))
| # 解説を参考に作成
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
def inverse(a, p):
"""逆元"""
a_, p_ = a, p
x, y = 1, 0
while p_:
t = a_ // p_
a_ -= t * p_
a_, p_ = p_, a_
x -= t * y
x, y = y, x
x %= p
return x
# from decorator import stop_watch
#
#
# @stop_watch
def solve(n, k):
mod = 10 ** 9 + 7
ans = 0
p_mod = [1, 1]
for i in range(2, n + 1):
p_mod.append((p_mod[-1] * i) % mod)
for i in range(min(n, k + 1)):
if i == 0:
ans += 1
elif i == 1:
ans += n * (n - 1)
else:
nCi = p_mod[n] * inverse(p_mod[n - i], mod) % mod * inverse(p_mod[i], mod) % mod
nmHi = (p_mod[n - 1] * inverse(p_mod[n - i - 1], mod) % mod) * inverse(p_mod[i], mod) % mod
# ans += cmb2(n, i, mod) * cmb2(n - 1, i, mod)
ans += nCi * nmHi % mod
ans %= mod
print(ans)
if __name__ == '__main__':
# S = input()
# N = int(input())
n, k = map(int, input().split())
# Ai = [int(i) for i in input().split()]
# Bi = [int(i) for i in input().split()]
# ABi = [[int(i) for i in input().split()] for _ in range(N)]
solve(n, k)
# # test
# from random import randint
# from func import random_str
# solve()
| 0 | null | 79,603,535,641,642 | 239 | 215 |
import math
def koch(d, a, b):
if d== 0:
return
s=[0,0]
t=[0,0]
u=[0,0]
s[0] = (2.0*a[0]+1.0*b[0])/3.0
s[1] = (2.0*a[1]+1.0*b[1])/3.0
t[0] = (1.0*a[0]+2.0*b[0])/3.0
t[1] = (1.0*a[1]+2.0*b[1])/3.0
u[0] = (t[0] - s[0])*math.cos(math.radians(60))-(t[1] - s[1])*math.sin(math.radians(60)) + s[0]
u[1] = (t[0] - s[0])*math.sin(math.radians(60))+(t[1] - s[1])*math.cos(math.radians(60)) + s[1]
koch(d-1,a,s)
print("{:.8f}".format(s[0]), "{:.8f}".format(s[1]))
koch(d-1,s,u)
print("{:.8f}".format(u[0]), "{:.8f}".format(u[1]))
koch(d-1,u,t)
print("{:.8f}".format(t[0]), "{:.8f}".format(t[1]))
koch(d-1, t, b)
n = int(input())
p1=[0,0]
p2=[100,0]
print("{:.8f}".format(p1[0]), "{:.8f}".format(p1[1]))
koch(n, p1, p2)
print("{:.8f}".format(p2[0]), "{:.8f}".format(p2[1]))
| n=int(input())
start=[[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for i in range(n):
b,f,r,v=[int(i) for i in input().split()]
start[b-1][f-1][r-1]+=v
for i in range(4):
for j in range(3):
for k in range(10):
print(" ",end="")
print(start[i][j][k],end="")
print()
if i<=2:
for m in range(20):
print("#",end="")
print()
| 0 | null | 602,346,421,820 | 27 | 55 |
a=input().strip()
if(a==a.lower()):
print("a",end="")
else:
print("A",end="") | alpha = str(input())
if alpha in "abcdefghijklmnopqrstuvwxyz":
print("a")
else:
print("A") | 1 | 11,409,347,382,432 | null | 119 | 119 |
if __name__ == '__main__':
n,m = map(int,input().split())
a = n // m
b = n % m
if b == 0:
print(a)
else:
if a == 0:
print("1")
else:
print(a+1)
| import math
H, A = list(map(int, input().split()))
if H % A == 0:
print(H // A)
else:
print(math.ceil(H / A))
| 1 | 76,729,855,662,838 | null | 225 | 225 |
import math
a,b,C=list(map(int,input().split()))
C_radian=math.radians(C)
S=a*b*math.sin(C_radian)/2
L=a+b+(a**2+b**2-2*a*b*math.cos(C_radian))**0.5
h=b*math.sin(C_radian)
print(S)
print(L)
print(h) | n = int(input())
ans = 0
for a in range(1,n):
if n%a == 0:
ans += n//a -1
else:
ans += n//a
print(ans)
| 0 | null | 1,402,298,872,370 | 30 | 73 |
n, k = map(int, input().split())
p = list(map(int,input().split()))
P = sorted(p)
price = 0
for i in range(k):
price += P[i]
print(price)
| S = int(input())
N = list(map(int, input().split(' ')))
N.sort()
sum = 0
for i in range(S):
sum += N[i]
print(N[0], N[-1], sum) | 0 | null | 6,171,725,906,662 | 120 | 48 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.