code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
d, q = list(map(int, input().split())), int(input())
dd = {v: k for k, v in enumerate(d)}
dms = ((1, 2, 4, 3), (0, 3, 5, 2), (0, 1, 5, 4), (0, 4, 5, 1), (0, 2, 5, 3), (1, 3, 4, 2))
while q:
t, f = map(int, input().split())
dm = dms[dd[t]]
print(d[dm[(dm.index(dd[f]) + 1) % 4]])
q -= 1 | if __name__ == '__main__':
N = int(input())
l = input().split()
num = [int(i) for i in l]
print(min(num), max(num), sum(num)) | 0 | null | 491,062,947,178 | 34 | 48 |
import math
lst = []
while True:
try:
a, b = map(int, input().split())
lst.append(int(math.log10(a+b))+1)
except EOFError:
for i in lst:
print(i)
break | 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) | 0 | null | 2,403,487,305,660 | 3 | 90 |
D = int(input())
c = [int(i) for i in input().split()]
s = []
for i in range(D):
tmp = [int(j) for j in input().split()]
s.append(tmp)
t = []
for i in range(D):
t.append(int(input()))
sat = 0
lst = [0 for i in range(26)]
for i in range(D):
sat += s[i][t[i]-1]
lst[t[i]-1] = i + 1
for j in range(26):
sat -= c[j] * ((i + 1) - lst[j])
print(sat) | 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)) | 0 | null | 61,374,242,008,640 | 114 | 256 |
N = int(input())
a = N//2
b = N%2
if b==0:
a -=1
print(a) | N = int(input())
if (N - 1) % 2 == 0:
a = (N-1) / 2
print(int(a))
else:
b = N / 2 - 1
print(int(b)) | 1 | 153,011,719,910,408 | null | 283 | 283 |
def solve():
num_lines = int(raw_input())
s = set()
for i in xrange(num_lines):
command, target = raw_input().split(" ")
if command[0] == "i":# insert
s.add(target)
continue
if target in s:
print "yes"
else:
print "no"
if __name__ == "__main__":
solve() | # Aizu Problem ALDS_1_4_C: Dictionary
import sys, math, os
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input.txt", "rt")
D = set()
N = int(input())
for _ in range(N):
cmd, string = input().split()
if cmd == "insert":
D.add(string)
elif cmd == "find":
print("yes" if string in D else "no") | 1 | 74,806,751,360 | null | 23 | 23 |
n,m = map(int, input().split())
AC = [False]*n
WA = [0]*n
for i in range(m):
p,s = input().split()
p = int(p)-1
if AC[p] == False:
if s == 'WA':
WA[p] += 1
else:
AC[p] = True
wa = 0
for i in range(n):
if AC[i]:
wa += WA[i]
print(AC.count(True),wa)
| n, m = map(int, input().split())
listAC = [0] * n
listWAAC = [0] * n
listWA = [0] * n
for i in range(m):
p, s = map(str, input().split())
p = int(p) - 1
if listAC[p] == 1:
continue
if s == 'AC':
listAC[p] += 1
listWAAC[p] += listWA[p]
continue
listWA[p] += 1
print(sum(listAC), sum(listWAAC))
| 1 | 93,682,168,224,880 | null | 240 | 240 |
n, m = map(int, input().split())
nl = [i for i in range(1000)]
if m == 0:
for i in range(1000):
st = str(i)
if len(st) != n:
nl[i] = 1000
print(min(nl) if min(nl) < 1000 else -1)
exit()
for h in range(m):
s, c = map(int, input().split())
for i in range(1000):
st = str(i)
if len(st) != n or st[s - 1] != str(c):
nl[i] = 1000
print(min(nl) if min(nl) < 1000 else -1) | n = int(input())
table = [0] * (n + 1)
for i in range(1, n+1):
for j in range(i, n+1, i):
table[j] += 1
ans = 0
for i in range(n+1):
ans += table[i] * i
print(ans)
| 0 | null | 35,753,254,049,448 | 208 | 118 |
from collections import deque
import sys
sys.setrecursionlimit(10**7)
N,u,v=map(int, input().split())
D=[[] for i in range(N)]
for i in range(N-1):
a,b=map(int, input().split())
a-=1
b-=1
D[a].append(b)
D[b].append(a)
Taka=[0]*(N+1)
Aoki=[0]*(N+1)
def f(n,p,A):
for i in D[n]:
if i!=p:
A[i]=A[n]+1
f(i,n,A)
f(u-1,-1,Taka)
f(v-1,-1,Aoki)
ans=0
for i in range(N):
if Taka[i]<Aoki[i]:
ans=max(ans,Aoki[i]-1)
print(ans) | from collections import defaultdict, deque
N, u, v = map(int, input().split())
u -= 1
v -= 1
dic = defaultdict(list)
for i in range(N-1):
a, b = map(int, input().split())
dic[a-1] += [b-1]
dic[b-1] += [a-1]
dist1 = [float('inf')]*N
dist2 = [float('inf')]*N
q1 = deque([u])
q2 = deque([v])
dist1[u] = 0
dist2[v] = 0
while q1:
e = q1.popleft()
for p in dic[e]:
if dist1[p]>dist1[e]+1:
dist1[p] = dist1[e]+1
q1 += [p]
while q2:
e = q2.popleft()
for p in dic[e]:
if dist2[p]>dist2[e]+1:
dist2[p] = dist2[e]+1
q2 += [p]
ans = -1
j = 0
for i in range(N):
if ans<dist2[i]-1 and dist1[i]<dist2[i]:
ans = dist2[i]-1
if u==v:
ans = 0
print(ans) | 1 | 117,854,899,306,816 | null | 259 | 259 |
n = int(input())
dp = [0]*(n+1)
for i in range(n+1):
if i == 0:
dp[i] = 1
elif i == 1:
dp[i] = 1
else:
dp[i] = dp[i-1] + dp[i-2]
print(dp[n])
| import itertools
n,m,q = map(int, input().split())
list_ = [list(map(int, input().split())) for _ in range(q)]
num=1
seed = [[i] for i in range(1,m+1)]
while num!=n:
num+=1
tmp_list = []
while seed:
tmp = seed.pop()
for i in range(tmp[-1],m+1):
tmp_list.append(tmp+[i])
seed = tmp_list.copy()
max_score = 0
visited = set()
for arr in seed:
score = 0
for arr_2 in list_:
if arr[arr_2[1]-1] - arr[arr_2[0]-1] == arr_2[2]:
score+=arr_2[3]
max_score = max(max_score, score)
print(max_score) | 0 | null | 13,838,966,526,748 | 7 | 160 |
S = str(input())
T = str(input())
s, t = len(S), len(T)
diff = [0 for i in range(s-t+1)]
for i in range(s-t+1):
target = S[i:i+t]
for j in range(t):
if target[j] != T[j]:
diff[i] += 1
j = 0
print(min(diff)) | import sys
import math
from functools import reduce
N = str(input())
A = list(map(int, input().split()))
M = 10 ** 6
sieve = [0] * (M+1)
for a in A:
sieve[a] += 1
def gcd(*numbers):
return reduce(math.gcd, numbers)
d = 0
for i in range(2, M+1):
tmp = 0
for j in range(i,M+1,i):
tmp += sieve[j]
if tmp > 1:
d = 1
break
if d == 0:
print('pairwise coprime')
exit()
if gcd(*A) == 1:
print('setwise coprime')
exit()
print('not coprime')
| 0 | null | 3,936,880,273,930 | 82 | 85 |
import sys
N = int(input())
A = [int(x) for x in input().split()]
L = [0] * N + [A[N]] # 下限
U = [0] * N + [A[N]] # 上限
for i in range(N - 1, -1, -1):
L[i] = (L[i + 1] + 1) // 2 + A[i]
U[i] = U[i + 1] + A[i]
if 1 < L[0]:
print(-1)
sys.exit()
U[0] = 1
for i in range(1, N + 1):
U[i] = min(2 * (U[i - 1] - A[i - 1]), U[i]) # 深さiの頂点数
print(sum(U)) | S = input()
wait_day = 0
if S == "SUN":
wait_day = 7
elif S == "MON":
wait_day = 6
elif S == "TUE":
wait_day = 5
elif S == "WED":
wait_day = 4
elif S == "THU":
wait_day = 3
elif S == "FRI":
wait_day = 2
elif S == "SAT":
wait_day = 1
print(wait_day) | 0 | null | 75,659,511,992,208 | 141 | 270 |
numbers = [int(x) for x in input().split(" ")]
a, b = numbers[0], numbers[1]
print("{} {} {:.5f}".format((a//b), (a%b), (a/b))) | def BubbleSort(A,N):
flag = 1
count = 0
while flag:
flag = 0
for i in range(N-1,0,-1):
if A[i] < A[i-1]:
tmp = A[i]
A[i] = A[i- 1]
A[i-1] = tmp
flag = 1
count = count +1
print(' '.join(map(str,A)))
print(count)
N = int(input())
A = input()
A = list(map(int,A.split()))
BubbleSort(A,N)
| 0 | null | 301,168,811,140 | 45 | 14 |
n=int(input())
if(n>=30):
print("Yes")
else:
print('No')
| # -*- coding: utf-8 -*-
n, m, l = list(map(int, input().split()))
a = []
b = []
for i in range(n):
a.append(list(map(int, input().split())))
for i in range(m):
b.append(list(map(int, input().split())))
for i in range(n):
for j in range(l):
mat_sum = 0
for k in range(m):
mat_sum += a[i][k] * b[k][j]
if j == l - 1:
print('{0}'.format(mat_sum), end='')
else:
print('{0} '.format(mat_sum), end='')
print()
| 0 | null | 3,593,995,324,540 | 95 | 60 |
n = int(input())
boss = list(map(int, input().split()))
subordinate = {}
for b in boss:
subordinate[b] = subordinate.get(b, 0) + 1
for i in range(1, n+1):
print(subordinate.get(i, 0))
| def BubbleSort(C, N):
for i in xrange(0, N):
for j in reversed(xrange(i+1, N)):
if C[j][1] < C[j-1][1]:
C[j], C[j-1] = C[j-1], C[j]
def SelectionSort(C, N):
for i in xrange(N):
minj = i
for j in xrange(i, N):
if C[j][1] < C[minj][1]:
minj = j
C[i], C[minj] = C[minj], C[i]
def isStable(C, N):
flag = 0
for i in xrange(1, 14):
Ct = [C[j] for j in xrange(N) if C[j][1] == str(i)]
if len(Ct) > 1:
for k in xrange( len(Ct)-1 ):
if Ct[k][2] > Ct[k+1][2]:
flag = 1
if flag == 0: print "Stable"
else: print "Not stable"
# MAIN
N = input()
C = []
Ct = map(str, raw_input().split())
for i in xrange(N):
C.append([Ct[i][0], Ct[i][1::], i])
Ct = list(C)
BubbleSort(Ct, N)
print " ".join([Ct[i][0]+Ct[i][1] for i in xrange(N)])
isStable(Ct, N)
Ct = list(C)
SelectionSort(Ct, N)
print " ".join([Ct[i][0]+Ct[i][1] for i in xrange(N)])
isStable(Ct, N) | 0 | null | 16,300,703,748,096 | 169 | 16 |
# coding: utf-8
n = int(input().rstrip())
count = 0
for i in range(1,n//2+1):
m = n - i
if i != m:
count += 1
print(count) | a, b, m = map(int, input().split())
arr_a = list(map(int, input().split()))
arr_b = list(map(int, input().split()))
cost = []
for i in range(m):
x, y, c = map(int, input().split())
cost.append(arr_a[x - 1] + arr_b[y - 1] - c)
cost.append(min(arr_a) + min(arr_b))
ans = min(cost)
print(ans) | 0 | null | 103,378,906,454,250 | 283 | 200 |
s=[0]*26
try:
while True:
n=str(input())
n=n.lower()
#print(n)
for i in range(len(n)):
if 97<=ord(n[i])<=122:
s[ord(n[i])-97]+=1
except EOFError:pass
for j in range(26):
print(chr(j+97),':',s[j])
| import sys
import string
def main():
tmp = ''
try:
while True:
tmp += input()
except EOFError:
pass
tmp = list(filter(lambda x: x in string.ascii_lowercase, tmp.lower()))
for c in string.ascii_lowercase:
print('{} : {}'.format(c, tmp.count(c)))
return 0
if __name__ == '__main__':
sys.exit(main())
| 1 | 1,689,695,712,530 | null | 63 | 63 |
S = input()
if S == 'AAA':
print('No')
elif S == 'BBB':
print('No')
else:
print('Yes') | s = input()
hitachi = ""
for i in range(5):
hitachi += "hi"
if s==hitachi:
print("Yes")
exit(0)
print("No")
| 0 | null | 53,901,352,182,818 | 201 | 199 |
N,R=map(int,input().split())
if N<10:
print(int(R+(100*(10-N))))
else:
print(R) | import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7
N, K = rl()
H = rl()
ans = 0
for h in H:
if h >= K:
ans += 1
print(ans) | 0 | null | 121,397,414,745,420 | 211 | 298 |
N = input()
Y = int(N)
a = Y%10
if a==3:
print("bon")
elif a==0:
print("pon")
elif a==1:
print("pon")
elif a==6:
print("pon")
elif a==8:
print("pon")
elif a==2:
print("hon")
elif a==4:
print("hon")
elif a==5:
print("hon")
elif a==7:
print("hon")
else:
print("hon")
| N = input()[-1]
if N == "3":
print("bon")
elif N in {"2", "4", "5", "7", "9"}:
print("hon")
else:
print("pon")
| 1 | 19,173,952,451,768 | null | 142 | 142 |
dice_init = input().split()
dicry = {'search':"152304",'hittop':'024135', 'hitfront':'310542'}
num = int(input())
def dicing(x):
global dice
dice = [dice[int(c)] for c in dicry[x]]
for _ in range(num):
dice = dice_init
top, front = map(int, input().split())
while True:
if int(dice[0]) == top and int(dice[1]) == front:
break
elif int(dice[0]) == top:
dicing('hittop')
elif int(dice[1]) == front:
dicing('hitfront')
else:
dicing('search')
print(dice[2])
| n, m = map(int, input().split())
err = False
ans = list('*' * n)
for _ in range(m):
si, ci = map(int, input().split())
if ans[si - 1] == '*' or ans[si - 1] == str(ci):
ans[si - 1] = str(ci)
else:
err = True
if ans[0] == '0' and n != 1:
err = True
if ans[0] == '*':
if n == 1:
ans[0] = '0'
else:
ans[0] = '1'
if err:
print(-1)
else:
print(''.join(ai if ai != '*' else '0' for ai in ans))
| 0 | null | 30,670,534,567,520 | 34 | 208 |
#!/usr/bin/env python3
import sys
from itertools import chain
def solve(A: int, B: int):
answer = 6 - A - B
return answer
def main():
tokens = chain(*(line.split() for line in sys.stdin))
A = int(next(tokens)) # type: int
B = int(next(tokens)) # type: int
answer = solve(A, B)
print(answer)
if __name__ == "__main__":
main()
| import bisect
N = int(input())
L = list(map(int, input().split()))
count = 0
L.sort()
for i in range(N-2):
for j in range(i+1,N-1):
k = bisect.bisect_left(L,L[i]+L[j])
count += k-j-1
print(count) | 0 | null | 140,807,347,914,116 | 254 | 294 |
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_9_D
def reverse(s, a, b):
s1 = s[0:a]
s2 = s[a:b+1]
s2 = s2[::-1]
s3 = s[b+1:len(string)]
return s1 + s2 + s3
def replace(s, a, b, p):
s1 = s[0:a]
s2 = p
s3 = s[b+1:len(string)]
return s1 + s2 + s3
string = input()
q = int(input())
for _ in range(q):
c = input().split()
if c[0] == "print":
print(string[int(c[1]):int(c[2])+1])
if c[0] == "reverse":
string = reverse(string, int(c[1]), int(c[2]))
if c[0] == "replace":
string = replace(string, int(c[1]), int(c[2]), c[3]) | N = int(input())
A = list(map(int, input().split()))
flag = True
swap = 0
while flag:
flag = False
for j in range(N - 1, 0, -1):
if A[j] < A[j - 1]:
A[j], A[j - 1] = A[j - 1], A[j]
swap += 1
flag = True
print(" ".join(list(map(str, A))))
print(swap) | 0 | null | 1,047,213,394,820 | 68 | 14 |
def resolve():
a, b, m = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
ans = min(a_list) + min(b_list)
for _ in range(m):
x, y, c = map(int, input().split())
ans = min(ans, a_list[x-1]+b_list[y-1]-c)
print(ans)
resolve() | A, B, M = map(int, input().split())
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
m = []
for n in range(M):
m.append([int(s) for s in input().split()])
minValue = min(a) + min(b)
for i in range(M):
discountPrice = a[m[i][0] - 1] + b[m[i][1] - 1] - m[i][2]
if discountPrice < minValue:
minValue = discountPrice
print(minValue)
| 1 | 54,089,723,995,050 | null | 200 | 200 |
s = input()
w = {'SUN': 7, 'MON': 6, 'TUE': 5, 'WED': 4, 'THU': 3, 'FRI': 2, 'SAT': 1}
print(w[s])
| ans = input()
if ans == "SUN": print(7)
if ans == "MON": print(6)
if ans == "TUE": print(5)
if ans == "WED": print(4)
if ans == "THU": print(3)
if ans == "FRI": print(2)
if ans == "SAT": print(1)
| 1 | 133,083,049,839,480 | null | 270 | 270 |
import sys
n = int(input())
ans = n*100/108
for i in [int(ans), int(ans)+1]:
if int(i*1.08) == n:
print(i)
sys.exit()
print(":(")
| def main(N, rate=1.08):
X = int(-(-N // 1.08))
return X if int(X * rate) == N else -1
if __name__ == "__main__":
N = int(input())
ans = main(N)
print(ans if ans > 0 else ':(')
| 1 | 126,023,135,101,162 | null | 265 | 265 |
n=int(raw_input())
if n:
l=[int(x) for x in raw_input().split()]
print min(l),max(l),sum(l)
else:
print "0 0 0" | from itertools import tee
print(
' '.join(
map(str,
map(lambda f, ns: f(ns),
(min, max, sum),
(lambda m: tee(m, 3))(
map(int,
(lambda _, line: line.split())(
input(), input()))))))) | 1 | 729,519,333,020 | null | 48 | 48 |
from collections import deque
H, W = map(int, input().split())
S_raw = [list(input()) for _ in range(H)]
m = 0
def calc(h,w):
S = [list(S_raw[i][j] for j in range(W)) for i in range(H)]
S[h][w]=0
queue = deque([(h,w)])
while queue:
q = queue.popleft()
for x in ((q[0]-1, q[1]),(q[0]+1, q[1]), (q[0], q[1]-1), (q[0], q[1]+1)):
if 0<=x[0]<=H-1 and 0<=x[1]<=W-1:
if S[x[0]][x[1]]==".":
S[x[0]][x[1]] = S[q[0]][q[1]]+1
queue.append(x)
return max(S[h][w] for w in range(W) for h in range(H) \
if str(S[h][w]).isdigit())
for h in range(H):
for w in range(W):
if S_raw[h][w]==".":
m = max(m, calc(h,w))
print(m) | h,w = map(int,input().split())
f = []
for i in range(h):
s = list(map(lambda x:0 if x== "." else 1,list(input())))
f.append(s)
from collections import deque
def dfs_field(field,st,go):
"""
:param field: #が1,.が0になったfield
st: [i,j]
go: [i,j]
:return: 色々今は回数returnしている。
"""
h = len(field)
w = len(field[0])
around = [[-1,0],[1,0],[0,1],[0,-1]]
que = deque()
visited = set()
visited.add(str(st[0])+","+str(st[1]))
que.append([st[0],st[1],0])
max_cos = 0
while True:
if len(que) == 0:
return max_cos
top = que.popleft()
nowi = top[0]
nowj = top[1]
cost = top[2]
for a in around:
ni = nowi+a[0]
nj = nowj+a[1]
if ni < 0 or ni > h-1 or nj < 0 or nj > w-1:
continue
if field[ni][nj] == 1:
continue
if ni == go[0] and nj == go[1]:
return cost+1
else:
key = str(ni)+","+str(nj)
if key not in visited:
que.append([ni,nj,cost+1])
visited.add(key)
if cost+1 > max_cos:
max_cos = cost+1
# print(que)
ans = 0
for i in range(h):
for j in range(w):
if f[i][j] == 0:
ct = dfs_field(f,[i,j],[-2,-2])
if ans < ct:
ans = ct
print(ans)
| 1 | 94,565,893,982,982 | null | 241 | 241 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
def solve():
N, X, M = map(int, input().split())
if N == 1:
print(X)
return
A = X
steps = [0] * M
sms = [0] * M
steps[A] = 1
sms[A] = A
sm = A
ans = A
rest = 0
for i in range(2, N+1):
A = (A*A) % M
sm += A
ans += A
if steps[A] != 0:
P = i - steps[A]
v = sm - sms[A]
rest = N - i
ans += v * (rest//P)
rest %= P
break
steps[A] = i
sms[A] = sm
for i in range(rest):
A = (A*A) % M
ans += A
print(ans)
solve()
| # -*- coding: utf-8 -*-
"""
Created on Sat Sep 19 22:03:19 2020
@author: liang
"""
N, X, M = map(int,input().split())
mod_set = {X}
mod_lis = [X]
A = [0]*(10**6+1)
A[0] = X
flag = False
#for i in range(1,N):
i = 1
for i in range(1,min(10**6,N)):
tmp = A[i-1]**2%M
if tmp in mod_set:
flag = True
break
A[i] = tmp
mod_set.add(tmp)
mod_lis.append(tmp)
if flag:
j = mod_lis.index(tmp)
else:
j = i
T = i - j
ans = 0
if T != 0:
#print("A")
ans += sum(mod_lis[:j])
T_sum = sum(mod_lis[j:])
"""
【切り捨て演算は必ず()をつけて先に計算】
"""
ans += T_sum * ((N-j)//T)
#print((N-j)//T, T_sum)
T_lis = mod_lis[j:i]
ans += sum(T_lis[:(N-j)%T])
else:
#print("B")
ans = sum(mod_lis)
# print(mod_lis)
#print(T_lis)
#print((N-j)%T)
#print(T_lis[:10])
print(ans)
#print(T_sum)
#print(sum(T_lis)) | 1 | 2,800,976,058,568 | null | 75 | 75 |
def solve():
n = int(input())
print((n+1)//2)
solve() | s = input()
hi = ['hi', 'hihi', 'hihihi', 'hihihihi', 'hihihihihi']
print('Yes') if s in hi else print('No') | 0 | null | 55,793,050,298,806 | 206 | 199 |
import math
X = int(input())
g = math.gcd(360, X)
l = X*360//g
print(l // X)
| X = int(input())
P = 360
ans = 1
x = X
while x%P != 0:
ans += 1
x += X
print(ans)
| 1 | 13,205,760,962,130 | null | 125 | 125 |
import sys
input = sys.stdin.readline
from collections import *
def bfs(s):
q = deque([s])
dist = [-1]*N
dist[s] = 0
leaf = set()
while q:
v = q.popleft()
flag = True
for nv in G[v]:
if dist[nv]==-1:
dist[nv] = dist[v]+1
q.append(nv)
flag = False
if flag:
leaf.add(v)
return dist, leaf
N, u, v = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
A, B = map(int, input().split())
G[A-1].append(B-1)
G[B-1].append(A-1)
d1, _ = bfs(u-1)
d2, leaf = bfs(v-1)
ans = 0
for i in range(N):
if i not in leaf and d1[i]<=d2[i]:
ans = max(ans, d2[i])
print(ans) | from collections import deque
N,u,v = map(int,input().split())
u -= 1
v -= 1
adj = [ [] for _ in range(N) ]
for _ in range(N-1):
a,b = map(int,input().split())
a -= 1
b -= 1
adj[a].append(b)
adj[b].append(a)
def bfs(v):
visited = [False] * N
q = deque([v])
span = [-1] * N
s = 0
while q:
l = len(q)
newq = deque([])
for _ in range(l):
node = q.popleft()
visited[node] = True
span[node] = s
for nei in adj[node]:
if not visited[nei]:
newq.append(nei)
q = newq
s += 1
return span
t = bfs(u)
a = bfs(v)
ans = 0
for i in range(N):
if t[i] <= a[i]:
ans = max(ans, a[i]-1)
print(ans) | 1 | 117,183,925,056,320 | null | 259 | 259 |
import sys
input = sys.stdin.readline
import bisect
# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
n = int(input())
s = input()
R, G, B = [], [], []
for i in range(n):
index = i+1
if s[i] == "R":
R.append(index)
elif s[i] == "G":
G.append(index)
elif s[i] == "B":
B.append(index)
all_count = len(R)*len(G)*len(B)
count = 0
# j - i != k - j
# k = 2j - i
for i in range(n):
for j in range(i+1, n):
if s[i] == s[j]:
continue
k = 2*j - i
if k >= n:
continue
if s[k] == s[i] or s[k] == s[j]:
continue
count += 1
print(all_count - count)
def bi(num, a, b, x):
print((a * num) + (b * len(str(b))))
if (a * num) + (b * len(str(b))) <= x:
return False
return True
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| from math import *
K=int(input())
ans=0
for a in range(1,K+1):
for b in range(1,K+1):
for c in range(1,K+1):
ans+=gcd(gcd(a,b),c)
print(ans) | 0 | null | 35,788,886,732,768 | 175 | 174 |
a, b, c = map(int, input().split())
k = int(input())
while a >= b and k > 0:
b = b*2
k = k-1
while b >= c and k > 0:
c = c*2
k = k-1
if a < b < c:
print('Yes')
else:
print('No') | a, b, c = map(int, input().split())
k = int(input())
cnt = 0
while not (a < b < c):
cnt += 1
if a >= b:
b *= 2
elif b >= c:
c *= 2
if cnt > k:
print("No")
exit(0)
print("Yes") | 1 | 6,903,966,543,068 | null | 101 | 101 |
print('Yes' if 'AAA'<input()<'BBB' else 'No') | # Station and Bus
S = input()
ans = ['No', 'Yes'][int('A' in S) + int('B' in S) - 1]
print(ans)
| 1 | 54,975,229,017,748 | null | 201 | 201 |
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)
# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
return [ int(s) for s in input().split(" ")]
# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
return [ int(input()) for _ in range(n)]
# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
return map(int, open(0).read().split())
def log(*args):
print("DEBUG:", *args, file=sys.stderr)
n = int(input())
A = get_nums_l()
# スキップできる回数
p = 1 if n%2==0 else 2
# log(p)
# dp[i][j][k] i==1なら次取れる スキップ回数をj回残してk個目まで見たときの最大和
dp = [ [ [0]*(n+1) for _ in range(p+1) ] for _ in range(2) ]
dp[0][0][0] = -999999999999999999
dp[0][1][0] = -999999999999999999
dp[1][0][0] = -999999999999999999
if p == 2:
dp[0][2][0] = -999999999999999999
dp[1][1][0] = -999999999999999999
# log(dp)
for k in range(n):
dp[0][0][k+1] = dp[1][0][k] + A[k]
dp[0][1][k+1] = dp[1][1][k] + A[k]
dp[1][0][k+1] = max(dp[1][1][k], dp[0][0][k])
dp[1][1][k+1] = dp[0][1][k]
if p == 2:
dp[0][2][k+1] = dp[1][2][k] + A[k]
dp[1][2][k+1] = dp[0][2][k]
#dp[1][0][k+1] = max(dp[1][0][k+1], dp[1][1][k])
dp[1][1][k+1] = max(dp[1][1][k+1], dp[1][2][k])
# for a in dp:
# for b in a:
# log(b)
ans = [dp[0][0][n], dp[0][1][n], dp[1][0][n], dp[1][1][n]]
if p == 2:
# ans.append(dp[0][2][n])
ans.append(dp[1][2][n])
print(max(ans))
| def main():
N = int(input())
A = list(map(int, input().split()))
a0, a1, a2, b0, b1, b2 = 0, 0, 0, 0, 0, 0
for i, a in enumerate(A):
a0, a1, a2, b0, b1, b2 = (
b0,
max(b1, a0),
max(b2, a1),
a0 + a,
a1 + a if i >= 1 else a1,
a2 + a if i >= 2 else a2)
if N & 1:
return max(b2, a1)
else:
return max(b1, a0)
print(main())
| 1 | 37,297,255,227,894 | null | 177 | 177 |
s = input()
k = int(input())
def seqcnt(s):
cnt=1
ans=0
bk=''
for c in s+' ':
if bk==c:
cnt+=1
else:
ans+=(cnt)//2
cnt=1
bk=c
return ans
cnt=seqcnt(s)
cnt2=seqcnt(s*2)
if len(set(list(s)))==1:
print(len(s)*k//2)
else:
print(cnt+(cnt2-cnt)*(k-1)) | def main():
S = list(input())
K = int(input())
cnt = 0
if K == 1:
T = S
for i in range(len(T)-1):
if T[i] == T[i+1]:
T[i+1] = '.'
ans = T.count('.')
print(ans)
return
if len(S) == 1:
ans = max(0, (K - (K%2==1))//2)
print(ans)
return
if len(set(S)) == 1:
tmp = len(S)*K
tmp = tmp - (tmp%2 == 1)
ans = tmp//2
print(ans)
return
T3 = S + S + S
for i in range(len(T3)-1):
if T3[i] == T3[i+1]:
T3[i+1] = '.'
T2aster = T3[len(S):(2*len(S))].count('.')
T3aster = T3.count('.')
ans = T3aster + T2aster * (K-3)
print(ans)
if __name__ == "__main__":
main()
| 1 | 175,146,021,902,370 | null | 296 | 296 |
# -*- 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()
| a = input().split()
if -1000 > int(a[0]):
print('')
elif 1000 < int(a[0]):
print('')
elif -1000 > int(a[1]):
print('')
elif 1000 < int(a[1]):
print('')
elif int(a[0]) < int(a[1]):
print('a < b')
elif int(a[0]) > int(a[1]):
print('a > b')
elif int(a[0]) == int(a[1]):
print('a == b')
| 0 | null | 6,191,535,993,162 | 121 | 38 |
import sys
import math
from collections import defaultdict
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
if row <= 0:
return [[] for _ in range(col)]
elif col == 1:
return [I() for _ in range(row)]
else:
read_all = [LI() for _ in range(row)]
return map(list, zip(*read_all))
#################
T1,T2 = LI()
A1,A2 = LI()
B1,B2 = LI()
if A1 > B1 and A2 > B2:
print(0)
exit()
if A1 < B1 and A2 < B2:
print(0)
exit()
if A1 > B1:
t = (A1-B1)*T1 / (B2-A2)
delta = (A1-B1)*T1+(A2-B2)*T2
if t == T2:
print('infinity')
exit()
elif t > T2:
print(0)
exit()
else:
if delta > 0:
print(math.floor((T2-t)*(B2-A2)/delta) + 1)
exit()
else:
x = (A1-B1)*T1 / (-delta)
if int(x) == x:
print(2*int(x))
else:
print(2*math.floor(x)+1)
else:
t = (B1-A1)*T1 / (A2-B2)
delta = (B1-A1)*T1+(B2-A2)*T2
if t == T2:
print('infinity')
exit()
elif t > T2:
print(0)
exit()
else:
if delta > 0:
print(math.floor((T2-t)*(A2-B2)/delta) + 1)
exit()
else:
x = (B1-A1)*T1 / (-delta)
if int(x) == x:
print(2*int(x))
else:
print(2*math.floor(x)+1) | import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
def main():
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
P = t1 * (b1 - a1)
Q = t2 * (b2 - a2)
if P + Q == 0:
print("infinity")
return
if P * (P + Q) > 0:
print(0)
return
P = abs(P)
Q = abs(Q)
T = P % (Q - P)
S = P // (Q - P)
if T == 0:
ans = 2 * S
else:
ans = 2 * S + 1
print(ans)
main()
| 1 | 131,013,774,937,772 | null | 269 | 269 |
n = input()
money = 100000
for i in range(n):
money = int(money * 1.05)
if money != money / 1000 * 1000:
money = money / 1000 * 1000 + 1000
print money | from sys import exit
N, K = [int(x) for x in input().split()]
H = list([int(x) for x in input().split()])
if len(H) <= K:
print(0)
exit()
H.sort(reverse=True)
H = H[K:]
print(sum(H))
| 0 | null | 39,353,097,587,508 | 6 | 227 |
import sys
input = lambda: sys.stdin.readline().rstrip()
class SegTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.ide_ele = ide_ele
self.segfunc = segfunc
self.num = 2**(n - 1).bit_length()
self.seg = [self.ide_ele] * 2 * self.num
for i in range(n):
self.seg[i + self.num - 1] = init_val[i]
for i in range(self.num - 2, -1, -1):
self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])
def update(self, k, x):
k += self.num - 1
self.seg[k] = x
while k:
k = (k - 1) // 2
self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
def query(self, p, q):
if q <= p:
return self.ide_ele
p += self.num - 1
q += self.num - 2
res = self.ide_ele
while q - p > 1:
if p & 1 == 0:
res = self.segfunc(res, self.seg[p])
if q & 1 == 1:
res = self.segfunc(res, self.seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = self.segfunc(res, self.seg[p])
else:
res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
return res
def solve():
N = int(input())
S = list(input())
Q = int(input())
seg = [1 << (ord(s) - ord('a')) for s in S]
segtree = []
segfunc = lambda a, b: a | b
segtree = SegTree(seg, segfunc, 0)
ans = []
for i in range(Q):
a, b, c = input().split()
a = int(a)
if a == 1:
b = int(b) - 1
al = ord(c) - ord('a')
segtree.update(b, 1 << al)
elif a == 2:
b, c = int(b) - 1, int(c)
res = segtree.query(b, c)
res = sum(list(map(int, bin(res)[2:])))
ans.append(res)
print('\n'.join(map(str, ans)))
if __name__ == '__main__':
solve()
| t=int(input())
n=input()
print(n.count('ABC')) | 0 | null | 80,692,274,962,588 | 210 | 245 |
w = input()
t = []
while True:
temp = input()
if temp == 'END_OF_TEXT':
break
else:
t += [s.strip(',.') for s in temp.lower().split(' ')]
print(t.count(w)) | # AOJ ITP1_9_A
# ※大文字と小文字を区別しないので注意!!!!
# 全部大文字にしちゃえ。
def main():
W = input().upper() # 大文字にする
line = ""
count = 0
while True:
line = input().split(" ")
if line[0] == "END_OF_TEXT": break
for i in range(len(line)):
word = line[i].upper()
if W == word: count += 1
print(count)
if __name__ == "__main__":
main()
# Accepted.
| 1 | 1,804,040,561,888 | null | 65 | 65 |
n = int(input())
x_i = [float(i) for i in input().split()]
y_i = [float(i) for i in input().split()]
abs_sub = []
D1,D2,D3=0.0,0.0,0.0
for i in range(len(x_i)):
#p==1
D1 += ((x_i[i]-y_i[i])**2)**(1/2)
#p==2
D2 +=(x_i[i]-y_i[i])**2
#p==3
D3 +=(((x_i[i]-y_i[i])**2)**(1/2))**3
#p==inf
abs_sub.append(((x_i[i]-y_i[i])**2)**(1/2))
D2 = D2**(1/2)
D3 = D3**(1/3)
D_inf=abs_sub[0]
for i in range(len(abs_sub)):
if D_inf < abs_sub[i]:
D_inf = abs_sub[i]
print("{:.6f}\n{:.6f}\n{:.6f}\n{:.6f}".format(D1,D2,D3,D_inf))
| N=int(input())
if N&0b1:
ans=N//2+1
else:
ans=N//2
print(ans) | 0 | null | 29,828,223,265,162 | 32 | 206 |
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7
def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def f(N):
res = 0
while N != 0:
b = format(N, "b").count("1")
N %= b
res += 1
return res
def main():
N = int(input())
X = input().strip()
K = X.count("1")
A = [(1, 1)]
for i in range(N):
a, b = A[-1]
A.append(((a * 2) % (K - 1) if K != 1 else 0, (b * 2) % (K + 1)))
B = [0, 0]
for i, b in enumerate(X[::-1]):
if b == "0":
continue
if K != 1:
B[0] += A[i][0]
B[0] %= K - 1
B[1] += A[i][1]
B[1] %= K + 1
res = [0] * N
for i, b in enumerate(X[::-1]):
if b == "0":
res[i] = (B[1] + A[i][1]) % (K + 1)
else:
if K == 1:
res[i] = 0
continue
res[i] = (B[0] - A[i][0]) % (K - 1)
res[i] = f(res[i]) + 1
for r in res[::-1]:
print(r)
if __name__ == "__main__":
main()
| def LI():
return list(map(int, input().split()))
X = int(input())
ans = X//500*1000
X = X % 500
ans += X//5*5
print(ans)
| 0 | null | 25,291,652,827,044 | 107 | 185 |
MOD = int(1e9+7)
def main():
S = int(input())
dp = [[0] * (S+1) for _ in range(S//3+2)]
for i in range(3, S+1):
dp[1][i] = 1
for i in range(2, S//3+2):
sm = sum(dp[i-1]) % MOD
sm = (sm - sum(dp[i-1][S-2:S+1])) % MOD
for j in range(3*i, S+1)[::-1]:
dp[i][j] = sm
sm = (sm - dp[i-1][j-3]) % MOD
ans = 0
for i in range(S//3+2):
ans = (ans + dp[i][S]) % MOD
print(ans)
if __name__ == "__main__":
main()
| a, b = map(str, input().split())
print(int(a)*int(b) if len(a)==len(b)==1 else "-1") | 0 | null | 80,796,441,922,652 | 79 | 286 |
def main():
a,b,c=map(int,input().split())
if a<b<c:
print('Yes')
else:
print('No')
if __name__=='__main__':
main()
| n = int(input())
ret = 0
b = 1
while n > 0:
ret += b
n //= 2
b *= 2
print(ret)
| 0 | null | 40,074,703,255,244 | 39 | 228 |
n,m,q=map(int, input().split())
s=[list(map(int, input().split())) for i in range(q)]
import itertools
A = [i for i in range(1,m+1)]
k = list(itertools.combinations_with_replacement(A, n))
ma = 0
for i in k:
su = 0
for n in s:
if i[n[1]-1] - i[n[0]-1] == n[2]:
su += n[3]
ma = max(ma,su)
print(ma) | str = input()
q = int(input())
for x in range(q):
en = input().split()
if en[0] == "print":
print(str[int(en[1]):int(en[2])+1])
elif en[0] == "reverse":
str = str[:int(en[1])] + str[int(en[1]):int(en[2])+1][::-1] + str[int(en[2])+1:]
else:
str = str[:int(en[1])] + en[3] + str[int(en[2])+1:]
| 0 | null | 14,744,573,861,380 | 160 | 68 |
N = int(input())
v = 0
for c in str(N):
v += int(c)
if v % 9 == 0:
print('Yes')
else:
print('No') | N = int(input())
n = str(N)
a = list(n)
count = 0
for i in range(len(a)):
count = count + int(a[i])
if count % 9 == 0:
print("Yes")
else:
print("No") | 1 | 4,439,816,413,810 | null | 87 | 87 |
def resolve():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(K, N):
if A[i-K] < A[i]:
print("Yes")
else:
print("No")
if '__main__' == __name__:
resolve() | N = int(input())
A = {}
for i in range(N):
s = input()
if s in A:
A[s] += 1
else:
A[s] = 1
s_max = max(A.values())
for j in sorted(k for k in A if A[k] == s_max):
print(j) | 0 | null | 38,307,276,062,438 | 102 | 218 |
a,b = map(int,input().split())
l=[]
if a>=b:
for i in range(a):
l.append(b)
else:
for i in range(b):
l.append(a)
print(''.join(map(str,l))) | import sys
input = sys.stdin.readline
a,b=map(int,input().split())
if a>b:
print(str(b)*a)
else:
print(str(a)*b)
| 1 | 84,179,980,297,530 | null | 232 | 232 |
N=int(input())
if N%2==1:
N+=1
print(int(N/2)) | N = int(input())
print(N//2 if N/2 == N//2 else N//2 + 1) | 1 | 59,199,603,923,798 | null | 206 | 206 |
def resolve():
N, M, Q = list(map(int, input().split()))
Q = [list(map(int, input().split())) for _ in range(Q)]
import itertools
maxpoint = 0
for seq in itertools.combinations_with_replacement(range(1, M+1), N):
point = 0
for a, b, c, d in Q:
if seq[b-1] - seq[a-1] == c:
point += d
maxpoint = max(maxpoint, point)
print(maxpoint)
if '__main__' == __name__:
resolve() | def substring(s, t):
min = 10000 # 変更数の最小
startIdx = 0 # arraySのstartインデックス
arrayIdx = 0 # arraySのインデックス
arrayS = []
arrayT = []
for item in s:
arrayS.append(item)
# Sの文字列-Tの文字列+1回ループ
loopCnt = len(s) - len(t) + 1
for i in range(0, loopCnt):
count = 0 # 変更数
arrayIdx = startIdx
for item in t:
if not item == arrayS[arrayIdx]:
count += 1
arrayIdx += 1
if count < min:
min = count
startIdx += 1
print(min)
s = input()
t = input()
substring(s, t) | 0 | null | 15,533,621,939,872 | 160 | 82 |
A, B, K = map(int, input().split())
a = A - K
if a >= 0:
print(a, B)
elif a < 0:
b = B + a
print(0, max(b,0))
| A, B, K = map(int, input().split())
if K <= A:
print("{} {}".format(A - K, B))
else:
K -= A
print("{} {}".format(0, max(B - K, 0)))
| 1 | 103,857,044,645,112 | null | 249 | 249 |
import sys
def display(inp):
s = len(inp)
for i in range(s):
if i!=len(inp)-1:
print("%d" % inp[i], end=" ")
else:
print("%d" % inp[i], end="")
print("")
line = sys.stdin.readline()
size = int(line)
line = sys.stdin.readline()
inp = []
for i in line.split(" "):
inp.append(int(i))
display(inp)
for i in range(1,size):
if inp[i]!=size:
check = inp.pop(i)
for j in range(i):
if check<inp[j]:
inp.insert(j,check)
break
if j==i-1:
inp.insert(j+1,check)
break
display(inp) | x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(1000):
if x-i not in p:
print(x-i)
exit()
elif x+i not in p:
print(x+i)
exit() | 0 | null | 7,082,593,416,982 | 10 | 128 |
N = int(input())
sum_ = 0
for i in range(1, N + 1):
n = int(N / i)
sum_ += (n / 2) * (2 * i + (n - 1) * i)
print(int(sum_))
| s=input()
q=int(input())
flag=0
t=['' for _ in range(2)]
cnt=0
for _ in range(q):
a=list(input().split())
if a[0]=='1':
flag=1-flag
cnt+=1
else:
if a[1]=='1':t[flag]+=a[2]
else:t[1-flag]+=a[2]
ans=t[0][::-1]+s+t[1]
if cnt%2:ans=ans[::-1]
print(ans) | 0 | null | 34,250,408,143,516 | 118 | 204 |
line = input()
words = line.split()
nums = list(map(int, words))
a = nums[0]
b = nums[1]
d = a // b
r = a % b
f = a / b
f = round(f,5)
print ("{0} {1} {2}".format(d,r,f)) | import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**5)
def geta(fn=lambda s: s.decode()):
return map(fn, readline().split())
def gete(fn=lambda s: s.decode()):
return fn(readline().rstrip())
def main():
a, b, c = geta(int)
print("win" if sum([a, b, c]) <= 21 else "bust")
if __name__ == "__main__":
main() | 0 | null | 59,499,993,717,460 | 45 | 260 |
from itertools import combinations
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i, j in combinations(xy, 2):
ans += ((i[0] - j[0]) ** 2 + (i[1] - j[1]) ** 2) ** 0.5
print(ans * 2 / n) | import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
a, b = map(int, readline().split())
print(str(min(a, b)) * max(a, b))
if __name__ == '__main__':
main()
| 0 | null | 116,166,095,971,530 | 280 | 232 |
a, b = [int(n) for n in input().split()]
d = a // b
r = a % b
f = a / b
if b == 100000009:
print(d, r, '0.000000019999998200000162')
else:
print(d, r, f) | a, b = map(int, input().split())
print('{0} {1} {2:f}'.format(a // b, a % b, a / b)) | 1 | 595,355,789,760 | null | 45 | 45 |
import sys
input=sys.stdin.readline
import math
from collections import defaultdict,deque
from itertools import permutations
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()
"""========main code==============="""
t,k=ml()
n=ll()
ans=0
lol=0
for i in range(t):
if(i>=k):
lol+=((n[i]*(n[i]+1))//2)/n[i]
lol-=((n[i-k]*(n[i-k]+1))//2)/n[i-k]
else:
lol+=((n[i]*(n[i]+1))//2)/n[i]
ans=max(ans,lol)
print(ans) | import math
n = int(input())
values = list(map(int, input().split(' ')))
values.sort(reverse=True)
sum = 0
for i in range(1, n):
sum += values[math.floor(i/2)]
print(sum) | 0 | null | 42,168,174,456,772 | 223 | 111 |
from sys import stdin
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())
def main():
N = i_input()
Z = []
W = []
for i in range(1, N + 1):
x, y = i_map()
Z.append(x + y)
W.append(x - y)
Z.sort()
W.sort()
ans = max([Z[-1] - Z[0], W[-1] - W[0]])
print(ans)
if __name__ == "__main__":
main()
| r, c = map(int, input().split())
data = [list(map(int, input().split())) for i in range(r)]
for i in range(r):
data[i].append(sum(data[i]))
data.append([sum(data[j][i] for j in range(r)) for i in range(c + 1)])
for i in range(r + 1):
for j in range(c + 1):
print(data[i][j], end='')
if j != c:
print(' ', end='')
print('') | 0 | null | 2,403,887,221,120 | 80 | 59 |
class Info:
def __init__(self,arg_start,arg_end,arg_S):
self.start = arg_start
self.end = arg_end
self.S = arg_S
POOL = []
LOC = []
cnt = 0
sum_S = 0
line = input()
for c in line:
if c == "\\":
LOC.append(cnt)
elif c == "/":
if len(LOC) == 0:
continue
tmp_start = LOC.pop()
tmp_end = cnt
tmp_S = tmp_end - tmp_start
sum_S += tmp_S
while len(POOL) > 0:
if POOL[-1].start > tmp_start and POOL[-1].end < tmp_end:
tmp_S += POOL[-1].S
POOL.pop()
else:
break
POOL.append(Info(tmp_start,tmp_end,tmp_S))
else:
pass
cnt += 1
lst = [len(POOL)]
for i in range(len(POOL)):
lst.append(POOL[i].S)
print(sum_S)
print(*lst)
| n, k = map(int, input().split())
a = sorted(map(int, input().split()))
f = sorted(map(int, input().split()))[::-1]
# 成績 Σ{i=1~n}a[i]*f[i]
# a[i]小さいの、f[i]でかいの組み合わせるとよい(交換しても悪化しない)
def c(x):
need = 0
for i in range(n):
if a[i] * f[i] > x:
# f[i]を何回減らしてx以下にできるか
diff = a[i] * f[i] - x
need += 0 - - diff // f[i]
return need <= k
l = 0
r = 1 << 60
while r != l:
mid = (l + r) >> 1
if c(mid):
r = mid
else:
l = mid + 1
print(l)
| 0 | null | 82,337,336,728,038 | 21 | 290 |
from collections import deque
n,limit = map(int,input().split())
total_time = 0
queue = deque()
for _ in range(n):
p,t = input().split()
queue.append([p,int(t)])
while len(queue) > 0:
head = queue.popleft()
if head[1] <= limit:
total_time += head[1]
print('{} {}'.format(head[0],total_time))
else:
head[1] -= limit
total_time += limit
queue.append(head)
| import time as ti
class MyQueue(object):
"""
My Queue class
Attributes:
queue: queue
head
tail
"""
def __init__(self):
"""Constructor
"""
self.length = 50010
self.queue = [0] * self.length
# counter = 0
# while counter < self.length:
# self.queue.append(Process())
# counter += 1
self.head = 0
self.tail = 0
# def enqueue(self, name, time):
def enqueue(self, process):
"""enqueue method
Args:
name: enqueued process name
time: enqueued process time
Returns:
None
"""
self.queue[self.tail] = process
# self.queue[self.tail].name = name
# self.queue[self.tail].time = time
self.tail = (self.tail + 1) % self.length
def dequeue(self):
"""dequeue method
Returns:
None
"""
# self.queue[self.head].name = ""
# self.queue[self.head].time = 0
self.queue[self.head] = 0
self.head = (self.head + 1) % self.length
def is_empty(self):
"""check queue is empty or not
Returns:
Bool
"""
if self.head == self.tail:
return True
else:
return False
def is_full(self):
"""chech whether queue is full or not"""
if self.tail - self.head >= len(self.queue):
return True
else:
return False
class Process(object):
"""process class
"""
def __init__(self, name="", time=0):
"""constructor
Args:
name: name
time: time
"""
self.name = name
self.time = time
def forward_time(self, time):
"""time forward method
Args:
time: forward time interval
Returns:
remain time
"""
self.time -= time
return self.time
def time_forward(my_queue, interval, current_time,):
"""
Args:
my_queue: queue
interval: time step interval
current_time: current time
"""
value = my_queue.queue[my_queue.head].forward_time(interval)
if value <= 0:
current_time += (interval + value)
print my_queue.queue[my_queue.head].name, current_time
my_queue.dequeue()
elif value > 0:
current_time += interval
name, time = my_queue.queue[my_queue.head].name, \
my_queue.queue[my_queue.head].time
my_queue.enqueue(my_queue.queue[my_queue.head])
my_queue.dequeue()
return current_time
my_queue = MyQueue()
n, q = [int(x) for x in raw_input().split()]
counter = 0
while counter < n:
name, time = raw_input().split()
my_queue.enqueue(Process(name, int(time)))
counter += 1
# end_time_list = []
current_time = 0
while not my_queue.is_empty():
current_time = time_forward(my_queue, q, current_time) | 1 | 42,672,754,180 | null | 19 | 19 |
import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
S = sys.stdin.buffer.readline().decode().rstrip()
N = len(S)
# ピッタリ払う
dp0 = [INF] * (N + 1)
# 1 多く払う
dp1 = [INF] * (N + 1)
dp0[0] = 0
dp1[0] = 1
for i, c in enumerate(S):
dp0[i + 1] = min(dp0[i] + int(c), dp1[i] + 10 - int(c))
dp1[i + 1] = min(dp0[i] + int(c) + 1, dp1[i] + 10 - int(c) - 1)
# print(dp0)
# print(dp1)
print(dp0[-1])
| N = int(input())
print('ACL' * N) | 0 | null | 36,363,784,398,916 | 219 | 69 |
N, M = map(int, input().split())
s = [0] * M
c = [0] * M
for i in range(M):
s[i], c[i] = map(int, input().split())
ran = []
for i in range(10 ** (N - 1), 10 ** N):
ran.append(i)
if N == 1:
ran.append(0)
ran.sort()
minimum = 10 ** N
for r in ran:
st = str(r)
ok = True
for j in range(M):
if st[s[j] - 1] != str(c[j]):
ok = False
if ok == True:
minimum = min(minimum, r)
break
if minimum == 10 ** N:
print(-1)
else:
print(minimum)
| n = int(input())
for cnt in range(n):
t = list(map(int, input().split()))
t.sort()
if t[2]**2 == t[1]**2 + t[0]**2:
print('YES')
else:
print('NO') | 0 | null | 30,517,783,535,840 | 208 | 4 |
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
L = [0]*26
v = 0
ans = [0]*D
import copy
for i in range(1, D+1):
max_score = -float('inf')
max_idx = 0
for j in range(26):
temp = v
temp += S[i-1][j]
L_ = copy.copy(L)
L_[j] = i
for k in range(26):
for l in range(i, min(i+14, D+1)):
temp -= C[k]*(i-L_[k])
if temp >= max_score:
max_score = temp
max_idx = j
v = max_score
L[max_idx] = i
ans[i-1] = max_idx+1
print(*ans, sep='\n')
| S = input()
T = input()
Nmax = len(T)
for i in range(len(S)-len(T)+1):
diff = 0
for j in range(len(T)):
if(S[i+j] != T[j]):
diff += 1
Nmax = min(diff, Nmax)
print(Nmax) | 0 | null | 6,681,798,788,002 | 113 | 82 |
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
U = max(A)+1
L = 0
def can(x, K):
ct = 0
for i in range(N):
ct += (A[i]-1)//x
if ct <= K:
return True
else:
return False
while U-L > 1:
x = (U+L+1)//2
if can(x, K):
U = x
else:
L = x
print(U)
| import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil
def main():
n, k = map(int, input().split())
a = tuple(map(int, input().split()))
def kaisu(long):
return(sum([ceil(ae/long) - 1 for ae in a]))
def bs_meguru(key):
def isOK(index, key):
if kaisu(index) <= key:
return True
else:
return False
ng = 0
ok = max(a)
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if isOK(mid, key):
ok = mid
else:
ng = mid
return ok
print(bs_meguru(k))
if __name__ == '__main__':
main()
| 1 | 6,458,011,407,022 | null | 99 | 99 |
x,n=map(int,input().split())
if n==0:
print(x)
exit()
p=[int(y) for y in input().split()]
a=0
for i in range(101):
if x-a not in p:
print(x-a)
break
elif x+a not in p:
print(x+a)
break
a+=1 | a=100000
for _ in range(int(input())):
a=((a*1.05)//1000+1)*1000 if (a*1.05)%1000 else a*1.05
print(int(a)) | 0 | null | 6,988,218,753,800 | 128 | 6 |
N = int(input())
divs = set()
n = 1
while n*n <= N:
if N%n==0:
divs.add(n)
divs.add(N//n)
n += 1
divs2 = set()
n = 1
while n*n <= (N-1):
if (N-1)%n==0:
divs2.add(n)
divs2.add((N-1)//n)
n += 1
ans = len(divs2) - 1
for d in divs:
if d==1: continue
n = N
while n >= 1:
if n==1:
ans += 1
break
if n%d == 0:
n //= d
else:
if n%d == 1:
ans += 1
break
print(ans) | import math
def prime(x):
p = {}
last = math.floor(x ** 0.5)
if x % 2 == 0:
cnt = 1
x //= 2
while x & 1 == 0:
x //= 2
cnt += 1
p[2] = cnt
for i in range(3, last + 1, 2):
if x % i == 0:
x //= i
cnt = 1
while x % i == 0:
cnt += 1
x //= i
p[i] = cnt
if x != 1:
p[x] = 1
return p
N = int(input())
P = prime(N - 1)
if N == 2:
print(1)
exit()
ans = 1
for i in P.keys():
ans *= P[i] + 1
ans -= 1
P = prime(N)
D = [1]
for i in P.keys():
L = len(D)
n = i
for j in range(P[i]):
for k in range(L):
D.append(D[k] * n)
n *= i
for i in D:
if i == 1: continue
t = N
while (t / i == t // i):
t //= i
t -= 1
if t / i == t // i:
ans += 1
print(ans)
| 1 | 41,351,973,022,372 | null | 183 | 183 |
a, b = input().split()
str = ''
if int(a)<=int(b):
for _ in range(int(b)):
str += a
else:
for _ in range(int(a)):
str += b
print(str) | a, b = map(int, input().split())
if a > b:
print(str(b) * a)
elif a < b:
print(str(a) * b)
else:
print(str(a) * a) | 1 | 84,484,745,700,420 | null | 232 | 232 |
input_n = input()
n = str(input_n)
listN = list(n)
#listN = n.split(' ')
if listN[len(listN) - 1] == "s":
listN.append("e")
listN.append("s")
else:
listN.append("s")
for i in range(len(listN)):
print(listN[i], end = "")
| def solve():
string = list(input())
ans = 0
if string[-1]=="s":
ans = "".join(string)+"es"
print(ans)
return
else:
print("".join(string)+"s")
return
solve() | 1 | 2,384,501,931,660 | null | 71 | 71 |
n = int(input())
d = dict(zip([i for i in range(1, n + 1)], [0] * n))
l = map(int, input().split())
for i in l:
d[i] += 1
for i in d.values():
print(i) | N = int(input())
A = [int(x) for x in input().split()]
cnt = [0 for x in range(N)]
for i in range(len(A)) :
cnt[A[i]-1] += 1
for i in range(N) :
print(cnt[i]) | 1 | 32,388,563,765,800 | null | 169 | 169 |
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def LIST() : return list(MAP())
def dfs(s,d,i):
for j in range(i+1):
s[d] = chr(ord('a')+j)
if d < len(s) - 1:
dfs(s, d+1, max(j+1, i))
else:
a.add("".join(s))
n = INT()
s = ['a']*n
a = set()
dfs(s, 0, 0)
b = sorted(list(a))
for x in b:
print(x) | from collections import deque
s=deque(input())
q=int(input())
qq=[list(input().split()) for i in range(q)]
rl=1
fleft=deque()
fright=deque()
for i in qq:
if i[0]=='1':
rl*=-1
else:
if i[1]=='1':
if rl==1:
fleft.appendleft(i[2])
else:
fright.append(i[2])
else:
if rl==1:
fright.append(i[2])
else:
fleft.appendleft(i[2])
fleft.reverse()
s.extendleft(fleft)
s.extend(fright)
if rl==-1:
s.reverse()
print(''.join(s)) | 0 | null | 55,003,755,257,480 | 198 | 204 |
def main():
N = int(input())
A = []
B = []
for _ in range(N):
a, b = (int(i) for i in input().split())
A.append(a)
B.append(b)
A.sort()
B.sort()
ans = -1
if N % 2 == 1:
ans = B[N//2] - A[N//2] + 1
else:
a = (A[N//2] + A[N//2 - 1])/2
b = (B[N//2] + B[N//2 - 1])/2
ans = b - a + 1
ans += ans - 1
print(int(ans))
if __name__ == '__main__':
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N,*ab = map(int, read().split())
A, B = [], []
for a, b in zip(*[iter(ab)]*2):
A.append(a)
B.append(b)
A.sort()
B.sort()
if N % 2 == 0:
a1, a2 = A[N // 2 - 1], A[N // 2]
b1, b2 = B[N // 2 - 1], B[N // 2]
ans = b1 + b2 - (a1 + a2) + 1
else:
a = A[N // 2]
b = B[N // 2]
ans = b - a + 1
print(ans)
if __name__ == "__main__":
main()
| 1 | 17,251,717,550,468 | null | 137 | 137 |
n=int(input())
a=list(map(int,input().split()))
MOD= 10**9 + 7
toki = [0]*(n+1)
shigi=0
toki[0] = sum(a)-a[0]
for i in range(1, n-1):
toki[i] = toki[i-1]-a[i]
for i in range(n-1):
shigi += (a[i] * toki[i])
print(shigi%MOD) | N = int(input())
A = [int(i) for i in input().split()]
S = []
e = 0
for i in A:
e += i
S.append(e)
ans = 0
for i in range(N-1):
ans += A[i]%(10**9+7)*((S[N-1] - S[i])%(10**9+7))
print(ans%(10**9+7)) | 1 | 3,818,465,201,588 | null | 83 | 83 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??????????????????
?????????????????????????????´?????????????????????
????????§?????????????????????(S, H, C, D)??¨???????????°???(1, 2, ..., 9)??????
?§??????????????¨? 36 ????????????????????¨????????????
????????°??????????????? 8 ???"H8"??????????????? 1 ???"D1"??¨??¨????????????
????????????????????????????????????????????¢?????´??????????????¨?????????
??????????????? N ????????????????????????????????°???????????????
???????????´?????????????????°????????????????????????????????????
??¢?????´??????????????????????????\????????????????????????????????????????????¨????????????
??°??????????´???? 0 ??????????????§?¨???°?????????????????????
1 BubbleSort(C, N)
2 for i = 0 to N-1
3 for j = N-1 downto i+1
4 if C[j].value < C[j-1].value
5 C[j] ??¨ C[j-1] ?????????
6
7 SelectionSort(C, N)
8 for i = 0 to N-1
9 minj = i
10 for j = i to N-1
11 if C[j].value < C[minj].value
12 minj = j
13 C[i] ??¨ C[minj] ?????????
??????????????¢?????´?????????????????????????????????????????\??????????????????????????????????????£??????????????±????????????????????????
"""
import math
def swap(A, x, y):
""" ??????A???x????????¨y?????????????´??????\???????????? """
t = A[x]
A[x] = A[y]
A[y] = t
def value(c):
""" ??????????????°?????¨???????????? """
return int(c[1:])
def suits(A):
""" ????????????????????????????????¨???????????????????????? """
s = ""
for c in A:
s = s + c[0]
return s
def bSort(A, N):
""" ?????????????????? """
for i in range(0, N-1):
for j in range(N-1, i, -1):
if value(A[j]) < value(A[j-1]):
swap(A,j,j-1)
def sSort(A, N):
""" ?????????????????? """
for i in range(0, N-1):
minj = i
for j in range(i,N):
if value(A[j]) < value(A[minj]):
minj = j
if minj != i:
swap(A,i,minj)
# ?????????
N = int(input().strip())
A = input().strip().split()
bA = A[:]
bSort(bA,N)
b1 = suits(bA)
print(" ".join(map(str,bA)))
print("Stable")
sA = A[:]
sSort(sA,N)
s1 = suits(sA)
print(" ".join(map(str,sA)))
if s1 == b1:
print("Stable")
else:
print("Not stable") | n, card = int(input()), input().split()
card1, card2 = card[:], card[:]
for i in range(n-1):
for j in range(n-1, i, -1):
if int(card1[j][1]) < int(card1[j-1][1]):
card1[j], card1[j-1] = card1[j-1], card1[j]
print(" ".join(card1))
print("Stable")
for i in range(n-1):
for j in range(i+1, n):
if j == i+1:
idx = j
elif int(card2[idx][1]) > int(card2[j][1]):
idx = j
if int(card2[i][1]) > int(card2[idx][1]):
card2[i], card2[idx] = card2[idx], card2[i]
print(" ".join(card2))
if card1 == card2:
print("Stable")
else:
print("Not stable")
| 1 | 25,345,707,380 | null | 16 | 16 |
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_C
# Stable Sort
# Result:
# Modifications
# - modify inner loop start value of bubble_sort
# This was the cause of the previous wrong answer.
# - improve performance of is_stable function
import sys
ary_len = int(sys.stdin.readline())
ary_str = sys.stdin.readline().rstrip().split(' ')
ary = map(lambda s: (int(s[1]), s), ary_str)
# a is an array of tupples whose format is like (4, 'C4').
def bubble_sort(a):
a_len = len(a)
for i in range(0, a_len):
for j in reversed(range(i + 1, a_len)):
if a[j][0] < a[j - 1][0]:
v = a[j]
a[j] = a[j - 1]
a[j - 1] = v
# a is an array of tupples whose format is like (4, 'C4').
def selection_sort(a):
a_len = len(a)
for i in range(0, a_len):
minj = i;
for j in range(i, a_len):
if a[j][0] < a[minj][0]:
minj = j
if minj != i:
v = a[i]
a[i] = a[minj]
a[minj] = v
def print_ary(a):
vals = map(lambda s: s[1], a)
print ' '.join(vals)
def is_stable(before, after):
length = len(before)
for i in range(0, length):
for j in range(i + 1, length):
if before[i][0] == before[j][0]:
v1 = before[i][1]
v2 = before[j][1]
for k in range(0, length):
if after[k][1] == v1:
v1_idx_after = k
break
for k in range(0, length):
if after[k][1] == v2:
v2_idx_after = k
break
if v1_idx_after > v2_idx_after:
return False
return True
def run_sort(ary, sort_fn):
ary1 = list(ary)
sort_fn(ary1)
print_ary(ary1)
if is_stable(ary, ary1):
print 'Stable'
else:
print 'Not stable'
### main
run_sort(ary, bubble_sort)
run_sort(ary, selection_sort) | """
n=int(input())
s=[int(x) for x in input().split()]
q=int(input())
t=[int(x) for x in input().split()]
#print(s)
c=0
for i in t:
if i in s:
c+=1
print(c)
"""
"""
n=int(input())
s=[int(x) for x in input().split()]
q=int(input())
t=[int(x) for x in input().split()]
#binary search
a=0
for i in range(q):
L=0
R=n-1#探索する方の配列(s)はソート済みでないといけない
while L<=R:
M=(L+R)//2
if s[M]<t[i]:
L=M+1
elif s[M]>t[i]:
R=M-1
else:
a+=1
break
print(a)
"""
#Dictionary
#dict型オブジェクトに対しinを使うとキーの存在確認になる
n=int(input())
d={}
for i in range(n):
command,words=input().split()
if command=='find':
if words in d:
print('yes')
else:
print('no')
else:
d[words]=0
| 0 | null | 51,876,501,140 | 16 | 23 |
# coding: utf-8
# Here your code !
for i in range(9):
for j in range(9):
print('%sx%s=%s' % ((i+1), (j+1), (i+1)*(j+1))) | import sys
for i in range(1,10):
for j in range(1,10):
print("{0}x{1}={2}".format(i,j,i*j)) | 1 | 1,497,540 | null | 1 | 1 |
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
t1 = t2 = t3 = ti = 0.0
for a, b in zip(x, y):
d1 = abs(a - b)
ti = max(ti, d1)
t1 += d1
t2 += d1**2
t3 += d1**3
print(t1)
print(math.sqrt(t2))
print(t3 ** (1.0/3))
print(ti) | import math
n = int(input())
xv = [int(xi) for xi in input().split()]
yv = [int(yi) for yi in input().split()]
print(sum([abs(xi-yi) for (xi, yi) in zip(xv, yv)]))
print(math.sqrt(sum([pow(abs(xi-yi), 2) for (xi, yi) in zip(xv, yv)])))
print(math.pow(sum([pow(abs(xi-yi), 3) for (xi, yi) in zip(xv, yv)]), 1/3))
print(max([abs(xi-yi) for (xi, yi) in zip(xv, yv)])) | 1 | 213,992,478,062 | null | 32 | 32 |
def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(K, N):
if A[i - K] < A[i]:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main() | N = int(input())
S, T = (x for x in input().split())
ans = ''
for i in range(N):
ans += (S[i] + T[i])
print(ans) | 0 | null | 59,390,493,003,676 | 102 | 255 |
import sys
from math import *
readline = sys.stdin.readline
def isPrime(x):
if x == 2 or x == 3:
return True
elif x % 2 == 0 or x % 3 == 0:
return False
s = ceil(sqrt(x))
for i in range(5, s + 1, 2):
if x % i == 0:
return False
return True
print(sum(isPrime(int(readline())) for _ in range(int(input()))))
| n = input()
m = len(n)
x = 0
for i in range(m):
x += int(n[i])
print("Yes" if x % 9 == 0 else "No") | 0 | null | 2,185,582,996,870 | 12 | 87 |
n = int(input())
f = 100000
if n == 0:
print(int(f))
else:
for i in range(n):
f *= 1.05
#print(f)
#F = f - f%1000 + 1000
if f%1000 != 0:
f = (f//1000)*1000 + 1000
#print(i,f)
print(int(f))
| a=100000
n=int(input())
for i in range(n):
a=a*1.05
if a%1000 !=0:
a=a-(a%1000)+1000
print(int(a))
| 1 | 1,265,529,408 | null | 6 | 6 |
li=["SUN","MON","TUE","WED","THU","FRI","SAT"]
day=input()
for i in range(7):
if(li[i]==day):
print(7-i) | s = input()
t = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
print(7-int(t.index(s))) | 1 | 133,215,467,142,384 | null | 270 | 270 |
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
a=LI()
ALL=0
for i in range(N):
ALL=ALL^a[i]
ans=[0]*N
for i in range(N):
ans[i]=ALL^a[i]
print(' '.join(map(str, ans)))
main()
| import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N = int(input())
As = list(mapint())
ALL = 0
for a in As:
ALL ^= a
ans = [ALL^a for a in As]
print(*ans) | 1 | 12,514,360,278,148 | null | 123 | 123 |
import math
N=int(input())
M =int(math.sqrt(N))
for i in range(M):
if N%(M-i)==0:
K=N//(M-i)
L=M-i
break
print(L+K-2)
| x, y = map(int, input().split())
for i in range(1, x+1):
if (4*i + 2*(x - i) == y) or (2*i + 4*(x - i) == y):
print("Yes")
exit()
print("No") | 0 | null | 87,630,739,672,112 | 288 | 127 |
import numpy as np
h,w,m=map(int, input().split())
hw=[tuple(map(int,input().split())) for i in range(m)]
H=np.zeros(h)
W=np.zeros(w)
for i in range(m):
hi,wi=hw[i]
H[hi-1]+=1
W[wi-1]+=1
mh=max(H)
mw=max(W)
hmax=[i for i, x in enumerate(H) if x == mh]
wmax=[i for i, x in enumerate(W) if x == mw]
f=0
for i in range(m):
hi,wi=hw[i]
if H[hi-1]==mh and W[wi-1]==mw:
f+=1
if len(hmax)*len(wmax)-f<1:
print(int(mh+mw-1))
else:
print(int(mh+mw)) | import sys
input = sys.stdin.readline
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = tuple(map(int, input().split()))
def can_eat(t):
F_time = sorted([t // f for f in F])
training = 0
for i in range(N):
training += max(0, A[i] - F_time[i])
return training <= K
# bisect
l, r = -1, 10 ** 12
while r - l > 1:
m = (r + l) // 2
if can_eat(m):
r = m
else:
l = m
print(r)
| 0 | null | 85,129,520,694,910 | 89 | 290 |
MOD = 998244353
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]
def main():
N, S = ZZ()
A = ZZ()
dp = [[0] * (S+1) for _ in range(N + 1)]
dp[0][0] = 1
for i in range(N):
for j in range(S+1):
dp[i+1][j] += 2*dp[i][j]
if A[i] <= j <= S: dp[i+1][j] += dp[i][j-A[i]]
dp[i+1][j] %= MOD
print(dp[N][S])
return
if __name__ == '__main__':
main()
|
def solve(N,S,A):
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1
mod = 998244353
for i, a in enumerate(A, 1):
for s in range(S+1):
if s-a >= 0:
dp[i][s] = (dp[i-1][s] * 2 + dp[i-1][s-a]) % mod
else:
dp[i][s] = dp[i-1][s] * 2 % mod
print(dp[N][S])
N, S = map(int, input().split())
A = list(map(int, input().split()))
solve(N,S,A)
| 1 | 17,672,822,775,892 | null | 138 | 138 |
def check(a, b, c):
a2 = a ** 2
b2 = b ** 2
c2 = c ** 2
if (a2 + b2) == c2:
return True
else:
return False
n = int(input())
for c in range(n):
line = input()
datas = map(int, line.split())
li = list(datas)
a = li[0]
b = li[1]
c = li[2]
if check(a, b, c) or check(b, c, a) or check(c, a, b):
print("YES")
else:
print("NO") | #coding:utf-8
buff = [int(x) for x in input().split()]
a = buff[0]
b = buff[1]
c = buff[2]
print(len([x for x in [x+a for x in range(b - a + 1)] if c%x==0])) | 0 | null | 271,745,644,622 | 4 | 44 |
#!/usr/bin/env python3
def solve(A: "List[int]"):
return ["win", "bust"][sum(A) >= 22]
def main():
A = list(map(int, input().split()))
answer = solve(A)
print(answer)
if __name__ == "__main__":
main()
| import sys
[print(len(str(sum(map(int, line.split()))))) for line in sys.stdin] | 0 | null | 59,405,812,843,356 | 260 | 3 |
input()
s = input()
count = 1
for i in range(len(s)-1):
if s[i]!=s[i+1]:
count+=1
print(count) | #デフォルト
import itertools
from collections import defaultdict
import collections
import math
import sys
sys.setrecursionlimit(200000)
mod = 1000000007
t = list(input())
for i in range(len(t)):
if (t[i] == "?"):
print("D",end="")
else:
print(t[i],end="") | 0 | null | 94,408,622,478,940 | 293 | 140 |
X,K,D = map(int, input().split())
X = abs(X)
if X//D > K:
print(X-(D*K))
exit()
if (K-X//D)%2:
print(D-X%D)
else:
print(X%D) | x,k,d = map(int, input().split())
x = abs(x)
if x - d*k >= 0:
print(abs(x-d*k))
else:
a = x // d
if k % 2 == 0:
if a % 2 == 0:
print(abs(x - d*a))
else:
print(abs(x - d * (a+1)))
else:
if a % 2 == 0:
print(abs(x - d * (a + 1)))
else:
print(abs(x - d * a))
| 1 | 5,199,350,777,500 | null | 92 | 92 |
def resolve():
N, K = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
print(sum(p[:K]))
if __name__ == "__main__":
resolve() | def ex_euclid(a, b):
x0, x1 = 1, 0
y0, y1 = 0, 1
z0, z1 = a, b
while z1 != 0:
q = z0 // z1
z0, z1 = z1, z0 % z1
x0, x1 = x1, x0 - q * x1
y0, y1 = y1, y0 - q * y1
return z0, x0, y0
def mod_inv(a, n):
g, x, _ = ex_euclid(a, n)
if g != 1:
print("modular inverse does not exist")
else:
return x % n
def mod_factorial(x, modulo):
ans = 1
for i in range(1, x+1):
ans *= i
ans %= modulo
return ans
X, Y = map(int, input().split())
M = 10 ** 9 + 7
a, b = (2*X-Y)/3, (2*Y-X)/3
if a < 0 or b < 0:
print(0)
elif a == 0 and b == 0:
print(0)
elif a%1 != 0 or b%1!= 0:
print(0)
else:
a, b = int(a), int(b)
answer = 1
answer *= mod_factorial(a+b, M)
answer *= mod_inv(mod_factorial(a, M), M)
answer %= M
answer *= mod_inv(mod_factorial(b, M), M)
answer %= M
print(answer) | 0 | null | 80,469,214,934,108 | 120 | 281 |
def gcd(x, y):
if y == 0:
return x
else:
return gcd(y, x % y)
x, y = [int(n) for n in input().split()]
print(gcd(x, y)) | from collections import defaultdict
h, w, m = map(int, input().split())
rowsum = [0] * h
rowmax = 0
colsum = [0] * w
colmax = 0
targets = defaultdict(int)
for _ in range(m):
hi, wi = map(int, input().split())
hi -= 1
wi -= 1
rowsum[hi] += 1
rowmax = max(rowmax, rowsum[hi])
colsum[wi] += 1
colmax = max(colmax, colsum[wi])
targets[(hi, wi)] = 1
rowindices = []
for i, v in enumerate(rowsum):
if v == rowmax:
rowindices.append(i)
colindices = []
for i, v in enumerate(colsum):
if v == colmax:
colindices.append(i)
ans = rowmax + colmax - 1
for ri in rowindices:
for ci in colindices:
if targets[(ri, ci)]:
continue
print(rowmax + colmax)
exit()
print(ans) | 0 | null | 2,401,834,144,710 | 11 | 89 |
n = int(open(0).readline())
ans = 0
for i in range(1,n+1):
count = n//i
end = count*i
ans += count * (i+end)//2
print(ans) | import numpy as np
n = int(input())
cnt = 0
for k in range(1,n+1):
d = n//k
if d == 1:
cnt += (k+n)*(n-k+1)//2
break
cnt += k*d*(d+1)//2
print(cnt) | 1 | 11,133,757,216,622 | null | 118 | 118 |
while True:
x, y = list(map(int, input().split(" ")))
if (x, y) == (0, 0):
break
elif (x < y):
print(x, y)
else:
print(y, x) | n = int(input())
A = list(map(int, input().split()))
from collections import defaultdict
dic = defaultdict(int)
ans = 0
for i in range(n):
if i - A[i] in dic:
ans += dic[i-A[i]]
dic[i+A[i]] += 1
print(ans)
| 0 | null | 13,216,005,567,712 | 43 | 157 |
n = int(input())
a = list(map(int, input().split()))
pm = sum(a)
e = 1
te = 1
for i in a:
pm -= i
e = min((e-i)*2, pm)
if e < 0:
break
te += e
if e < 0:
print(-1)
else:
print(te) | n = int(input())
L = list(map(int,input().split()))
ans = 0
for i in range(n-2):
for j in range(i+1,n-1):
for k in range(j+1,n):
if L[i]!=L[j] and L[i]!=L[k] and L[j]!=L[k] and abs(L[j]-L[k])<L[i]<L[j]+L[k]:
ans += 1
print(ans) | 0 | null | 11,929,036,429,750 | 141 | 91 |
from sys import stdin
def main():
input = stdin.readline
n, k, c = map(int, input().split())
s = input()
l, r = [], []
cur = 0
count = 0
while cur <= n:
if s[cur] == "o":
count += 1
l.append((count, cur+1))
cur += c
cur += 1
cur = n
count = k
while cur >= 0:
if s[cur] == "o":
r.append((count, cur+1))
count -= 1
cur -= c
cur -= 1
ans = (i[1] for i in set(l) & set(r))
for i in sorted(ans):
print(i)
if __name__ == '__main__':
main() | import math
from itertools import permutations
def calc_distance(a, b):
dx = a[0] - b[0]
dy = a[1] - b[1]
d = math.sqrt(dx * dx + dy * dy)
return d
N = int(input())
city = [0] * N
for i in range(N):
city[i] = list(map(int, input().split()))
mtx = [0 for i in range(N)] * N
mtx = [[calc_distance(a, b) for a in city] for b in city]
all_distance = 0
paths = permutations([i for i in range(N)])
cnt = 0
for pt in paths:
distance = 0
for idx in range(1, len(pt)):
distance += mtx[pt[idx]][pt[idx-1]]
all_distance += distance
cnt += 1
all_distance /= cnt
print(all_distance)
| 0 | null | 94,485,705,924,288 | 182 | 280 |
# Transformation
string = input()
commandAmount = int(input())
for i in range(commandAmount):
command = input().rstrip().split()
start = int(command[1])
end = int(command[2])
if command[0] == 'print':
print(string[start : end + 1]) # ここはコメントアウトしないこと
elif command[0] == 'reverse':
replacedString = list(string)
# print(replacedString)
for i in range(start, end + 1):
replacedString[i] = list(string)[start + end - i]
# print(replacedString)
string = ''.join(replacedString)
elif command[0] == 'replace':
string = list(string)
replace = list(command[3])
for i in range(start, end + 1):
string[i] = replace[i - start]
string = ''.join(string)
| n=int(input())
a=list(map(int,input().split()))
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
d=[0 for i in range(pow(10,5)+1)]
s=sum(a)
for i in range(n):
d[a[i]]+=1
for i in range(q):
s+=(bc[i][1]-bc[i][0])*d[bc[i][0]]
print(s)
d[bc[i][1]]+=d[bc[i][0]]
d[bc[i][0]]=0
| 0 | null | 7,096,418,380,160 | 68 | 122 |
from math import pi
def main():
S = int(input())
print(2 * pi * S)
if __name__ == "__main__":
main()
| import math
R = int(input())
print(2.0 * math.pi * R) | 1 | 31,494,688,889,130 | null | 167 | 167 |
N = int(input())
print(N//2 if N%2 else N//2-1) | N = int(input())
if N % 2 == 0:
ans = N // 2
ans -= 1
else:
ans = (N - 1) // 2
print(ans) | 1 | 152,936,235,962,770 | null | 283 | 283 |
#!/usr/bin/env python3
import sys
from itertools import chain
# form bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter
# import numpy as np
def solve(N: int):
az = "abcdefghijklmnopqrstuvwxyz"
N -= 1
answer = ""
while True:
answer = az[N % 26] + answer
N = N // 26
if N == 0:
break
N = N - 1
return answer
def main():
tokens = chain(*(line.split() for line in sys.stdin))
# N = map(int, line.split())
N = int(next(tokens)) # type: int
answer = solve(N)
print(answer)
if __name__ == "__main__":
main()
| n = int(input())
ans = ""
for i in range(11):
n2 = (n-1)%26
ans = chr(97+n2)+ans
n = int((n-1)/26)
#print(n)
if n == 0:
break
print(ans)
| 1 | 11,889,987,848,232 | null | 121 | 121 |
N = int(input())
As = sorted(list(map(int, input().split())))
sieve = [True] * 1000001
prev = 0
for i in range(N):
if As[i] == prev:
sieve[As[i]] = False
continue
else:
prev = As[i]
try:
for j in range(2, 1000000 // prev + 1):
sieve[prev * j] = False
except:
continue
count = 0
As = list(set(As))
for i in range(len(As)):
if sieve[As[i]] is True:
count += 1
print(count) | n = int(input())
A = list(map(int, input().split()))
MAX_N = max(A)+ 1
cnt = [0] * MAX_N
for a in A:
for i in range(a, MAX_N, a):
if cnt[i] <= 2:
cnt[i] += 1
ans = 0
for a in A:
if cnt[a] == 1:
ans += 1
print(ans)
| 1 | 14,373,667,316,228 | null | 129 | 129 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.