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
|
---|---|---|---|---|---|---|
n=int(input())
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
ans=0
l=len(factorization(n))
s=factorization(n)
for i in range(l):
for j in range(1,1000):
if s[i][1]>=j:
ans+=1
s[i][1]-=j
else:
break
if n==1:
print(0)
else:
print(ans)
| n = int(input())
A = list(map(int, input().split()))
A.sort()
l = [False]*(A[n-1] + 1)
fix = []
for i in A:
if l[i]:
fix.append(i)
l[i] = True
for i in range(A[n-1]+1):
if l[i]:
for j in range(i*2, A[n-1]+1, i):
l[j] = False
for i in fix:
l[i] = False
ans = [i for i in range(A[n-1] + 1) if l[i]]
print(len(ans))
| 0 | null | 15,535,240,335,900 | 136 | 129 |
x = input()
str.swapcase(x)
print(str.swapcase(x))
| H = int(input())
W = int(input())
N = int(input())
HW =H*W
ans =H+W
for h in range(0,H+1):
for w in range(0,W+1):
cntB = HW - (H-h)*(W-w)
if cntB>=N:
ans = min(ans, h+w)
print(ans) | 0 | null | 45,124,922,974,592 | 61 | 236 |
N = int(input())
a = list(map(int, input().split()))
x = 0
for r in a:
x ^= r
print(' '.join([str(x^r) for r in a])) | import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
N = int(readline())
a = list(map(int,readline().split()))
s = 0
for ai in a:
s = s^ai
ans = []
for ai in a:
ans.append(s^ai)
print(' '.join(map(str,ans)))
| 1 | 12,480,354,157,798 | null | 123 | 123 |
n = int(input())
a = list(map(int,input().split()))
ans = 1
for i in a :
ans *= i
if ans > 10**18 :
ans = -1
break
if 0 in a :
ans = 0
print(ans) | n = int(input())
a = list(map(int, input().split()))
m = 1
if 0 in a:
print(0)
else:
for i in range(n):
m = m * a[i]
if m > 10 ** 18:
print(-1)
break
elif i == n - 1:
print(m) | 1 | 16,031,223,326,370 | null | 134 | 134 |
i=0
a=list(map(int,input().split()))
for x in range(a[0],a[1]+1):
if(a[2]%x==0):
i+=1
print(i) | import math
import sys
import os
from operator import mul
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))
if os.getenv("LOCAL"):
inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
sys.stdin = open(inputFile, "r")
INF = float("inf")
N = I()
S = [_S() for _ in range(N)]
ans = 0
s = set()
for i in range(N):
s.add(S[i])
ans = len(s)
print(ans) | 0 | null | 15,394,534,483,552 | 44 | 165 |
def main():
N, R = map(int, input().split())
if N >= 10:
print(R)
else:
print(R+(100*(10-N)))
if __name__ == '__main__':
main() | import sys
import fractions
readline = sys.stdin.buffer.readline
def main():
gcd = fractions.gcd
def lcm(a, b):
return a * b // gcd(a, b)
N, M = map(int, readline().split())
A = list(set(map(int, readline().split())))
B = A[::]
while not any(b % 2 for b in B):
B = [b // 2 for b in B]
if not all(b % 2 for b in B):
print(0)
return
semi_lcm = 1
for a in A:
semi_lcm = lcm(semi_lcm, a // 2)
if semi_lcm > M:
print(0)
return
print((M // semi_lcm + 1) // 2)
return
if __name__ == '__main__':
main()
| 0 | null | 82,714,449,789,270 | 211 | 247 |
import math
n=int(input())
a=[]
for i in range(2):
s = list(map(int, input().split()))
a.append(s)
d1=0
for i in range(n):
d1+=abs(a[0][i-1]-a[1][i-1])
print(format(d1, '.6f'))
d2_1=0
for i in range(n):
d2_1+=(abs(a[0][i-1]-a[1][i-1]))**2
d2=math.sqrt(d2_1)
print(format(d2, '.6f'))
d3_1=0
for i in range(n):
d3_1+=(abs(a[0][i-1]-a[1][i-1]))**3
d3=(d3_1)**(1/3)
print(format(d3, '.6f'))
dn=0
for i in range(n):
dn=max(abs(a[0][i-1]-a[1][i-1]),dn)
print(format(dn, '.6f'))
| # -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1
def main():
N=int(input())
A=list(map(int,input().split()))
B=[(A[i],i) for i in range(N)]
B.sort(key=lambda t: -t[0])
dp=[[0]*(N+1) for _ in range(N+1)]
ans=0
for i in range(N):
for x in range(i+1):
y=i-x
dp[x+1][y]=max(dp[x+1][y],dp[x][y]+B[i][0]*abs(B[i][1]-x))
dp[x][y+1]=max(dp[x][y+1],dp[x][y]+B[i][0]*abs(N-1-y-B[i][1]))
ans=max(ans,dp[x+1][y],dp[x][y+1])
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 17,059,235,223,616 | 32 | 171 |
n = int(input())
m=list(map(int,input().split()))
A=[0]*n
for i in range(n-1):
A[m[i]-1]+=1
print(*A, sep = "\n")
| n = int(input())
n1 = n//2
s = input()
s1 = s[n1:]
s2 = s[:n1]
if n % 2 != 0:
print('No')
else:
if s1 == s2:
print('Yes')
else:
print('No') | 0 | null | 89,835,741,568,600 | 169 | 279 |
N = int(input())
l = input().split()
p = []
for i in range(N):
p.append((int(l[i]),i))
p.sort()
s = N
ans = 0
for i in range(N):
(a,b) = p[i]
if b < s:
ans += 1
s = b
print(ans) | n = int(input())
p = list(map(int,input().split()))
maxp = 999999
cnt=0
for x in p:
if maxp >= x:
cnt += 1
maxp = x
print(cnt)
| 1 | 85,650,825,145,496 | null | 233 | 233 |
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = list(input())
POINT = {"r":P,"s":R,"p":S}
GET = [False] * N
ANS = 0
for i in range(N):
t = T[i]
if i <= K-1:
ANS += POINT[t]
GET[i] = True
else:
if not GET[i-K] or t != T[i-K]:
ANS += POINT[t]
GET[i] = True
print(ANS)
| n, k = list(map(int, input().split(' ')))
r, s, p = list(map(int, input().split(' ')))
d = dict(r=p,
s=r,
p=s)
ttt = input()
ans = 0
prevs = []
for i in range(n):
if i < k or ttt[i] != prevs[i-k]:
ans += d[ttt[i]]
prevs.append(ttt[i])
else:
prevs.append('hoge')
print(ans)
| 1 | 106,769,244,943,220 | null | 251 | 251 |
A, B, K = map(int, input().split())
if A >= K:
a = A - K
b = B
else:
if K <= A + B:
a = 0
b = B - (K - A)
else:
a = 0
b = 0
print(a, b)
| while True:
H,W = list(map(int, input().split()))
if (H == 0 and W == 0):
break
else:
for n in range(H):
s = ""
for m in range(W):
s += "#"
print(s)
print("") | 0 | null | 52,351,361,091,000 | 249 | 49 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??´?????????
"""
suits = {"S": 0, "H": 1, "C": 2, "D": 3}
nsuits = ["S", "H", "C", "D"]
cards = [[0 for i in range(13)] for j in range(4)]
n = int(input())
for i in range(n):
inp = input().split(" ")
s = inp[0]
c = int(inp[1]) - 1
cards[suits[s]][c] = 1
for i in range(4):
for j in range(13):
if cards[i][j] == 0:
print("{0} {1}".format(nsuits[i], j+1)) | from collections import defaultdict
h, w, m = map(int, input().split())
targets = []
targets_count_w = defaultdict(int)
targets_count_h = defaultdict(int)
for _ in range(m):
y, x = map(int, input().split())
y -= 1
x -= 1
targets_count_w[x] += 1
targets_count_h[y] += 1
targets.append((y, x))
max_w = max(targets_count_w.values())
max_h = max(targets_count_h.values())
y_idx = defaultdict(bool)
x_idx = defaultdict(bool)
max_count_x = 0
max_count_y = 0
for i in range(w):
if targets_count_w[i] == max_w:
x_idx[i] = True
max_count_x += 1
for i in range(h):
if targets_count_h[i] == max_h:
y_idx[i] = True
max_count_y += 1
ans = max_w + max_h
kumi = max_count_x*max_count_y
for ty, tx in targets:
if y_idx[ty] and x_idx[tx]:
kumi -= 1
if kumi == 0:
break
if kumi == 0:
print(ans-1)
else:
print(ans)
| 0 | null | 2,882,655,088,850 | 54 | 89 |
n=int(raw_input())
print (n-1)/2 | N = int(input())
ans = set()
for i in range(1, N + 1):
j = N - i
if i == j or i == 0 or j == 0:
continue
ans.add((min(i, j), max(i, j)))
print(len(ans)) | 1 | 153,125,299,201,400 | null | 283 | 283 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import combinations_with_replacement
def main():
n, m, q = map(int, input().split())
qs = []
for _ in range(q):
abcd = tuple(map(int, input().split()))
qs.append(abcd)
A = tuple(combinations_with_replacement(range(1, m+1), n))
r = 0
for Ae in A:
t0 = 0
for qe in qs:
if Ae[qe[1]-1] - Ae[qe[0]-1] == qe[2]:
t0 += qe[3]
r = max(r, t0)
print(r)
if __name__ == '__main__':
main()
| N,M,Q=map(int,input().split())
Query=[list(map(int,input().split())) for i in range(Q)]
import itertools
ans=0
for x in itertools.combinations_with_replacement(range(1, M+1), N):
l=0
for i in range(Q):
a,b,c,d=map(int,Query[i])
if x[b-1]-x[a-1]==c:
l+=d
ans=max(ans,l)
print(ans) | 1 | 27,680,851,132,142 | null | 160 | 160 |
#!/usr/bin/env python3
h, w = list(map(int, input().split()))
ss = [list(str(input())) for _ in range(h)]
dp = [[100*100 for _ in range(w)] for i in range(h)] # dp[h][w]
if ss[0][0] == "#":
dp[0][0] = 1
else:
dp[0][0] = 0
# print(dp)
for h_tmp in range(0, h):
for w_tmp in range(0, w):
if w_tmp > 0:
# print(dp[h_tmp][w_tmp-1])
if ss[h_tmp][w_tmp-1] == "." and ss[h_tmp][w_tmp] == "#":
dp[h_tmp][w_tmp] = min(dp[h_tmp][w_tmp], dp[h_tmp][w_tmp-1]+1)
else:
dp[h_tmp][w_tmp] = min(dp[h_tmp][w_tmp], dp[h_tmp][w_tmp-1])
if h_tmp > 0:
# print(dp[h_tmp][w_tmp-1])
if ss[h_tmp-1][w_tmp] == "." and ss[h_tmp][w_tmp] == "#":
dp[h_tmp][w_tmp] = min(dp[h_tmp][w_tmp], dp[h_tmp-1][w_tmp]+1)
else:
dp[h_tmp][w_tmp] = min(dp[h_tmp][w_tmp], dp[h_tmp-1][w_tmp])
# print(dp)
print(dp[-1][-1])
| import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]
#本当に貪欲法か? DP法では??
#本当に貪欲法か? DP法では??
#本当に貪欲法か? DP法では??
h,w=mii()
mat=[list(ss()) for _ in range(h)]
chk=[[0]*w for _ in range(h)]
for i in range(h):
for j in range(w):
if i==0:
if j==0:
if mat[i][j]=="#":
chk[i][j]+=1
else:
if mat[i][j]!=mat[i][j-1] and mat[i][j]=="#":
chk[i][j]=chk[i][j-1]+1
else:
chk[i][j]=chk[i][j-1]
else:
if j==0:
if mat[i][j]!=mat[i-1][j] and mat[i][j]=="#":
chk[i][j]=chk[i-1][j]+1
else:
chk[i][j]=chk[i-1][j]
else:
if mat[i][j]==mat[i-1][j] and mat[i][j]==mat[i][j-1]:
chk[i][j]=min(chk[i-1][j],chk[i][j-1])
elif mat[i][j]!=mat[i-1][j] and mat[i][j]==mat[i][j-1] and mat[i][j]=="#":
chk[i][j]=min(chk[i-1][j]+1,chk[i][j-1])
elif mat[i][j]!=mat[i][j-1] and mat[i][j]==mat[i-1][j] and mat[i][j]=="#":
chk[i][j]=min(chk[i-1][j],1+chk[i][j-1])
elif mat[i][j]=="#":
chk[i][j]=min(chk[i-1][j]+1,1+chk[i][j-1])
else:
chk[i][j]=min(chk[i-1][j],chk[i][j-1])
print(chk[-1][-1])
#print(chk) | 1 | 49,350,485,808,778 | null | 194 | 194 |
in1=input().split()
in2=input().split()
if int(in1[0])==int(in2[0]):
print(0)
else:
print(1) | m, d = input().split(' ')
M, D = input().split(' ')
if D == '1':
print(1)
else:
print(0) | 1 | 124,773,122,478,130 | null | 264 | 264 |
a, b, c, k = map(int, input().split())
if k - a <= 0:
print(k)
elif k - a > 0 and k - a - b <= 0:
print(a)
else:
s = k - a - b
print(a - s)
| A, B, C, K = map(int, input().split())
if K <= A:
print(1 * K)
elif A < K <= A + B:
print(1 * A)
elif A + B < K:
print(1 * A - 1 * (K - A - B)) | 1 | 21,932,567,524,010 | null | 148 | 148 |
s=list(input())
length=len(s)
if(s[length-1]=='s'):
s.append('es')
else:
s.append('s')
s = ''.join(s)
print(s)
| def gcd(a, b):
if (a % b) == 0:
return b
return gcd(b, a%b)
def lcd(a, b):
return a * b // gcd(a, b)
while True:
try:
nums = list(map(int, input().split()))
print(gcd(nums[0], nums[1]), lcd(nums[0], nums[1]))
except EOFError:
break | 0 | null | 1,184,963,032,612 | 71 | 5 |
n=int(input())
a=[int(i) for i in input().split()]
flag=0
for i in range(0,len(a)):
if(a[i]%2==0 and (a[i]%3==0 or a[i]%5==0)):
pass
elif(a[i]%2==0 and (a[i]%3!=0 or a[i]%5!=0)):
flag=1
break
if(flag==1):
print('DENIED')
else:
print('APPROVED') | class dice:
def __init__(self,label):
self.top, self.front, self.right, self.left, self.rear, self.bottom \
= label
def roll(self,op):
if op=='N': self.top, self.front, self.bottom, self.rear = \
self.front, self.bottom, self.rear , self.top
elif op=='E': self.top, self.left , self.bottom, self.right = \
self.left , self.bottom, self.right, self.top
elif op=='W': self.top, self.right, self.bottom, self.left = \
self.right, self.bottom, self.left , self.top
elif op=='S': self.top, self.rear , self.bottom, self.front = \
self.rear , self.bottom, self.front, self.top
def print_top(self): print(self.top)
def print_right(self): print(self.right)
def get_label(self):
return [self.top, self.front, self.right, self.left, self.rear, self.bottom]
label = list(map(int,input().split()))
d = dice(label)
q = int(input())
for _ in range(q):
top_front = [int(x) for x in input().split()]
for op in 'EEESSSWWWNNNWWWSSWWSESWS':
if d.get_label()[:2] == top_front:
d.print_right()
break
d.roll(op) | 0 | null | 34,577,619,083,070 | 217 | 34 |
def main():
n = int(input())
numbers = list(map(int, input().split()))
ans1 = min(numbers)
ans2 = max(numbers)
ans3 = sum(numbers)
print(ans1, ans2, ans3)
if __name__=="__main__":
main() | T=input()
tmp=T.replace('?','D')
print(tmp) | 0 | null | 9,504,491,281,280 | 48 | 140 |
a, b, c, d = map(int,input().split())
while True:
c = c - b
a = a - d
if c <= 0:
print('Yes')
break
elif a <= 0:
print('No')
break
else:
pass | #! /usr/bin/env python3
import sys
sys.setrecursionlimit(10**9)
YES = "Yes" # type: str
NO = "No" # type: str
INF=10**20
def solve(A: int, B: int, C: int, D: int):
while True:
C-=B
if C <= 0:
print(YES)
break
A-=D
if A <= 0:
print(NO)
break
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
A = int(next(tokens)) # type: int
B = int(next(tokens)) # type: int
C = int(next(tokens)) # type: int
D = int(next(tokens)) # type: int
solve(A, B, C, D)
if __name__ == "__main__":
main()
| 1 | 29,725,438,938,090 | null | 164 | 164 |
t=int(input())
print("{}:{}:{}".format(t//60**2,t%60**2//60,t%60**2%60)) | clr = list(map(int, input().split()))
k = int(input())
for i in range(k):
if clr[2] <= clr[1] :
clr[2] *= 2
elif clr[1] <= clr[0]:
clr[1] *= 2
else:
break
if clr[2] > clr[1] > clr[0] :
print("Yes")
else:
print("No") | 0 | null | 3,601,403,623,850 | 37 | 101 |
def main() :
n = int(input())
nums = [int(i) for i in input().split()]
flag = True
count = 0
index = 0
while flag :
flag = False
for i in reversed(range(index+1, n)) :
if nums[i-1] > nums[i] :
nums[i-1], nums[i] = nums[i], nums[i-1]
count += 1
flag = True
index += 1
nums_str = [str(i) for i in nums]
print(" ".join(nums_str))
print(count)
if __name__ == '__main__' :
main() | # -*- coding:utf-8 -*-
n = int(input())
data = input()
data = data.split()
for i in range(len(data)):
data[i] = int(data[i])
sum = 0
for i in range(n):
sum += data[i]
print(min(data), max(data), sum, sep = ' ') | 0 | null | 382,770,040,548 | 14 | 48 |
from collections import namedtuple
Line = namedtuple('Line', ['lowest', 'end'])
def main():
N = int(input())
up_lines = []
down_lines = []
for i in range(N):
s = input()
now = 0
lowest = 0
for c in s:
if c == "(":
now += 1
else:
now -= 1
lowest = min(lowest, now)
if now > 0:
up_lines.append(Line(lowest, now))
else:
down_lines.append(Line(lowest-now, -now))
up_lines.sort(key=lambda line: -line.lowest)
down_lines.sort(key=lambda line: -line.lowest)
left = 0
for line in up_lines:
if left + line.lowest < 0:
print("No")
return
left += line.end
if left < 0:
print("No")
break
right = 0
for line in down_lines:
if right + line.lowest < 0:
print("No")
return
right += line.end
if right < 0:
print("No")
break
if left == right:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| n = int(input());
dict = {}
for i in range(n):
s = input();
if not s in dict:
dict[s] = 1
sum = 0
for i in dict:
sum += 1
print(sum)
| 0 | null | 26,932,096,007,442 | 152 | 165 |
def main():
L, R, d = map(int, input().split(' '))
X = 0
if L % d == 0:
X = int(L / d) - 1
else:
X = int(L / d)
print(int(R / d) - X)
main() | N = int(input())
print(sum([i for i in range(1, N+1) if i%3 if i%5])) | 0 | null | 21,224,225,407,840 | 104 | 173 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
count = 0
l, r, d= [int(x) for x in readline().rstrip().split()]
#print(l,r,d)
for i in range(l,r+1):
if i % d == 0:
count += 1
print(count)
| # coding: utf-8
from collections import deque
n, quantum = [int(i) for i in input().split()]
dq = deque()
for i in range(n):
p, time = [str(i) for i in input().split()]
dq.append([p, int(time)])
time = 0
while(len(dq) != 0):
#引き算処理
#処理が終了しない場合
if dq[0][1] > quantum:
dq[0][1] -= quantum
dq.rotate(-1)
time += quantum
#処理が終了する場合
else:
time += dq[0][1]
print("{} {}".format(dq[0][0], time))
dq.popleft() | 0 | null | 3,802,822,606,908 | 104 | 19 |
N = int(input())
A = list(map(int,input().split()))
number_list = [0]*1000010
for a in A:
number_list[a] += 1
flag1 = True
flag2 = True
for i in range(2,1000001):
count = 0
for j in range(1,1000001):
if i*j > 1000000:
break
tmp = i*j
count += number_list[tmp]
if count > 1:
flag1 = False
if count == N:
flag2 = False
if flag2 == False and flag1 == False:
print("not coprime")
elif flag2 == True and flag1 == False:
print("setwise coprime")
else:
print("pairwise coprime") | S = int(input())
s = S%60
m = (S-s)/60%60
h = S/3600%24
answer = str(int(h))+":"+str(int(m))+":"+str(s)
print(answer)
| 0 | null | 2,206,839,067,410 | 85 | 37 |
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mat = lambda x, y, v: [[v]*y for _ in range(x)]
ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)]
mod = 1000000007
sys.setrecursionlimit(1000000)
N = ri()
C = rs()
l, r = 0, N-1
ans = 0
while l < r:
while C[l] == 'R' and l < N-1:
l += 1
while C[r] == 'W' and r > 0:
r -= 1
if l >= r: break
l += 1
r -= 1
ans += 1
print(ans) | n = int(input())
s = input()
num_r = s.count("R")
count = 0
for i in range(num_r):
if s[i] != "R":
count += 1
print(count) | 1 | 6,314,260,930,560 | null | 98 | 98 |
s=input()
if 'SU' in s:
print('7')
if 'MO' in s:
print('6')
if 'TU' in s:
print('5')
if 'WE' in s:
print('4')
if 'TH' in s:
print('3')
if 'FR' in s:
print('2')
if 'SA' in s:
print('1')
| def main():
S = input()
if S == "SUN":
print(7)
exit(0)
elif S == "MON":
print(6)
exit(0)
elif S == "TUE":
print(5)
exit(0)
elif S == "WED":
print(4)
exit(0)
elif S == "THU":
print(3)
exit(0)
elif S == "FRI":
print(2)
exit(0)
else:
print(1)
exit(0)
if __name__ == "__main__":
main()
| 1 | 133,186,019,953,890 | null | 270 | 270 |
string=input()
print(string[:3]) | def resolve():
n = int(input())
a = list(map(int, input().split()))
all_xor = 0
for ai in a:
all_xor ^= ai
ans = []
for ai in a:
ans.append(str(all_xor ^ ai))
print(' '.join(ans))
resolve() | 0 | null | 13,736,539,245,220 | 130 | 123 |
n,m=map(int,raw_input().split())
c=map(int,raw_input().split())
dp=[[0]+[float('inf')]*n]+[[0]+[float('inf')]*n for i in xrange(m)]
for i in xrange(m):
for j in xrange(n+1):
if c[i]>j:
dp[i+1][j]=dp[i][j]
else:
dp[i+1][j]=min(dp[i][j],dp[i+1][j-c[i]]+1)
print(dp[m][n]) | x = input().split()
a = int(x[0])
b = int(x[1])
c = int(x[2])
count = 0
# a =< b
for i in range(a,b+1):
if c % i == 0:
count += 1
print(count)
| 0 | null | 350,177,090,872 | 28 | 44 |
n = int(input())
#nを素因数分解したリストを返す
def prime_decomposition(n):
i = 2
table = []
while i * i <= n:
while n % i == 0:
n /= i
table.append(i)
i += 1
if n > 1:
table.append(n)
return table
a = prime_decomposition(n)
list_num=[]
for i,n in enumerate(a):
if i ==0:
list_num.append(n)
if n in list_num:
continue
elif n not in list_num:
list_num.append(n)
count = 0
for i in list_num:
num = a.count(i)
handan = True
j = 1
counter = 0
while handan == True:
num -=j
if num<0:
handan =False
elif num>=0:
counter+=1
j+=1
count +=counter
print(count) | from collections import Counter
n = int(input())
ans = 0
dp = []
cl = []
n1 = n
if n == 1:
ans = 0
else:
for i in range(2, int(n**0.5)+1):
if n%i == 0:
cl.append(i)
while n%i == 0:
n = n/i
dp.append(i)
if n == 1:
break
if n != 1:
ans = 1
c = Counter(dp)
for i in cl:
cnt = 1
while c[i] >= cnt:
c[i] -= cnt
ans += 1
cnt += 1
print(ans)
| 1 | 17,005,713,951,732 | null | 136 | 136 |
import sys
sys.setrecursionlimit(10 ** 7)
N = input()
# DP
INF = pow(10, 8)
L = len(N)
dp = [[INF] * 2 for _ in range(L+2)]
dp[0][0] = 0
# reverse
N = N[::-1] + '0'
for i in range(L+1):
for j in range(2):
# 繰り下がりも加味
n = int(N[i])
n += j
# 更新後のdp
ni = i + 1
# 10通りから探索
for a in range(10):
nj = 0
b = a - n
# 繰り下がりあり
if b < 0:
b += 10
nj = 1
dp[ni][nj] = min(dp[i][j] + a + b, dp[ni][nj])
ans = min(dp[L+1][0], dp[L+1][1])
print(ans)
| # E - Payment
S = input()
N = len(S)
# 先頭からi桁目までの金額のやり取りに必要な紙幣の枚数
dp = [0]
dp_plus1 = [1]
for i in range(N):
x = int(S[i])
dp.append(min(dp[i] + x, dp_plus1[i] + (10 - x)))
dp_plus1.append(min(dp[i] + (x + 1), dp_plus1[i] + (10 - (x + 1))))
print(dp[-1]) | 1 | 71,238,846,295,680 | null | 219 | 219 |
import sys
input = sys.stdin.readline
from collections import Counter
def rle(list):
dict = {}
for i in list:
if i in dict.keys():
dict[i] += 1
else:
dict[i] = 1
return dict
n = int(input())
a = list(map(int, input().split()))
minus = Counter([i-a[i] for i in range(n)])
plus = Counter([i+a[i] for i in range(n)])
cnt = 0
for i in minus:
if i in plus:
cnt += minus[i] * plus[i]
print(cnt)
| import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return input().split()
def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')
from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
def solve():
n = II()
A = LI()
memo = {}
ans = 0
for i in range(n):
mae = (i+1) + A[i]
ima = (i+1) - A[i]
ans += memo.get(ima, 0)
memo[mae] = memo.get(mae, 0) + 1
# print(memo)
print(ans)
if __name__ == '__main__':
solve()
| 1 | 26,005,851,253,870 | null | 157 | 157 |
n = input()
s = list(map(int, input().split()))
print(min(s), max(s), sum(s)) | n = input()
if n == 0:
print(1)
elif n == 1:
print(1)
else:
fib = [0 for i in range(n + 1)]
fib[0] = 1
fib[1] = 1
for i in range(2, n + 1):
fib[i] = fib[i - 1] + fib[i - 2]
print(fib[n]) | 0 | null | 368,584,495,930 | 48 | 7 |
import sys
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
sc = [(s - 1, c) for s, c in sc]
ans = ["x"] * n
for s, c in sc:
if n > 1 and s == 0 and c == 0:
print(-1)
sys.exit()
elif ans[s] != "x" and ans[s] != c:
print(-1)
sys.exit()
else:
ans[s] = c
if n > 1 and ans[0] == "x":
ans[0] = 1
for i in range(n):
if ans[i] == "x":
ans[i] = 0
ans = [str(x) for x in ans]
print("".join(ans)) | N, M = map(int, raw_input().split())
matrix = [map(int, raw_input().split()) for n in range(N)]
array = [input() for m in range(M)]
for n in range(N):
c = 0
for m in range(M):
c += matrix[n][m] * array[m]
print c | 0 | null | 30,912,017,500,312 | 208 | 56 |
A, B = map(int, input().split())
R = A * B
print(R)
|
n = int(input())
s = input()
count = 1
for h in range(len(s)-1):
if s[h] != s[h+1]:
count += 1
print(count)
| 0 | null | 93,347,500,954,792 | 133 | 293 |
import numpy as np
from numpy.fft import rfft, irfft
import sys
input=sys.stdin.readline
N, M = map(int, input().split())
fft_len = 1<<18
MAX = 2*10**5
A = np.zeros(fft_len)
for a in [int(x) for x in input().split()]:
A[a] += 1
F = rfft(A, fft_len)
f = np.rint(irfft(F*F))
n, ans = 0, 0
for i, c in enumerate(f[:MAX+1][::-1]):
if M < n+c:
ans += (M-n)*(MAX-i)
break
ans += c*(MAX-i)
n += c
print(int(ans))
| import sys
import bisect
import itertools
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n, m = list(map(int, readline().split()))
a = list(map(int, readline().split()))
a.sort()
cor_v = -1
inc_v = a[-1] * 2 + 1
while - cor_v + inc_v > 1:
bin_v = (cor_v + inc_v) // 2
cost = 0
#条件を満たすcostを全検索
p = n
for v in a:
p = bisect.bisect_left(a, bin_v - v, 0, p)
cost += n - p
if cost > m:
break
#costが制約を満たすか
if cost >= m:
cor_v = bin_v
else:
inc_v = bin_v
acm = [0] + list(itertools.accumulate(a))
c = 0
t = 0
for v in a:
p = bisect.bisect_left(a, cor_v - v)
c += n - p
t += acm[-1] - acm[p] + v * (n - p)
print(t - (c - m) * cor_v)
if __name__ == '__main__':
solve()
| 1 | 108,449,574,423,200 | null | 252 | 252 |
n = list(map(int,input()))[::-1]
n.append(0)
for i in range(len(n)):
if n[i] >= 6 or (n[i] == 5 and n[i+1] >= 5):
n[i] = 10 - n[i]
n[i+1] += 1
print(sum(n))
| import sys
from functools import reduce
from operator import xor
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
s = reduce(xor, a)
print(' '.join([str(xor(s, i)) for i in a]))
| 0 | null | 41,866,177,260,868 | 219 | 123 |
sen = input()
n = int(input())
for i in range(n):
cmd = input().split()
sta = int(cmd[1])
end = int(cmd[2])
if cmd[0] == 'replace':
sen = sen[0:sta] + cmd[3] + sen[end+1:]
elif cmd[0] == 'reverse':
rev = sen[sta:end+1]
rev = rev[::-1]
# print(rev)
sen = sen[0:sta] + rev +sen[end+1:]
elif cmd[0] == 'print':
print(sen[sta:end+1])
# print('sen : '+sen) | x = int(input())
idx = 0
tmp = 0
while 1:
tmp += x
idx += 1
if tmp % 360 == 0:
break
print(idx)
| 0 | null | 7,635,122,424,160 | 68 | 125 |
a = 1
b = 1
op = ''
i = 0
while op!='?':
a,op,b = [i for i in input().split()]
a = int(a)
b = int(b)
if op!='?':
if op=='+':
print(a+b)
elif op=='-':
print(a-b)
elif op=='*':
print(a*b)
elif op=='/':
print(a//b) | a = []
while True:
b = raw_input().split()
if b[1] == '?':
break
c = [int(b[0]), b[1], int(b[2])]
a.append(c)
for list in a:
x, op, y = list
if op == '+':
print x + y
elif op == '-':
print x - y
elif op == '*':
print x * y
else:
print x / y | 1 | 674,344,669,920 | null | 47 | 47 |
import math
N = int(input())
a = list(map(int,input().split()))
m = max(a)
c = [0] * (m+1)
for i in a:
c[i] += 1
pairwise = True
for i in range(2, m+1, 1):
cnt = 0
for j in range(i, m+1, i):
cnt += c[j]
if cnt > 1:
pairwise = False
break
if pairwise:
print("pairwise coprime")
exit()
g = 0
for i in range(N):
g = math.gcd(g, a[i])
if g == 1:
print("setwise coprime")
exit()
print("not coprime") | n = int(input())
input_line = input().split()
member = [int(input_line[i]) for i in range(n)]
stands = 0
for i in range(1,n):
stand = member[i-1] - member[i]
if stand > 0:
stands += stand
member[i] += stand
print(stands) | 0 | null | 4,332,489,446,698 | 85 | 88 |
n = int(input())
number = list(map(int,input().split()))
count = 0
for i in range(1,n + 1):
for j in range(1,i):
if number[i - j] < number[i - j - 1]:
number[i - j],number[i - j - 1] = number[i - j - 1],number[i - j]
count += 1
number = list(map(str,number))
print(" ".join(number))
print(count) | n = int(input())
li = list(map(int, input().split()))
cnt = 0
flag = True
while flag:
flag = False
for i in range(n-1,0,-1):
if li[i] < li[i-1]:
li[i], li[i-1] = li[i-1], li[i]
flag = True
cnt +=1
print(*li)
print(cnt) | 1 | 16,793,810,940 | null | 14 | 14 |
a,b=map(int, input().split())
c=list(map(int, input().split()))
l =[]
ans = 0
def abc(n):
return (n+1)/2
cb = list(map(abc,c))
s = sum(cb[:b])
l.append(s)
for i in range(b,a):
s = s - cb[i-b] + cb[i]
l.append(s)
L = sorted(l)
print(L[-1]) | n, k = map(int, input().split())
p = list(map(int, input().split()))
s = sum(p[:k])
ret = s
for i in range(k, n):
s += p[i] - p[i - k]
ret = max(ret, s)
print((ret + k) / 2.0)
| 1 | 74,908,587,362,852 | null | 223 | 223 |
# 168_b
K = int(input())
S = input()
# str.islower()
# >文字列中の大小文字の区別のある文字全てが小文字で、
# >かつ大小文字の区別のある文字が 1 文字以上あるなら True を、そうでなければ False を返します。
if (1 <= K and K <= 100) and S.islower() and (1 <= len(S) and len(S) <= 100):
if len(S)<=K:
print(S)
elif len(S)>K:
print("{}...".format(S[0:K]))
| t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if a[0]*t[0]+a[1]*t[1]==b[0]*t[0]+b[1]*t[1]:
print('infinity')
elif a[0]*t[0]+a[1]*t[1]>b[0]*t[0]+b[1]*t[1]:
if a[0]*t[0]>b[0]*t[0]:
print(0)
elif a[0]*t[0]==b[0]*t[0]:
print(1)
else:
n=t[0]*(b[0]-a[0])
m=t[0]*(a[0]-b[0])+t[1]*(a[1]-b[1])
q=n//m
if n%m==0:
print(2*q)
else:
print(2*q+1)
else:
if a[0]*t[0]<b[0]*t[0]:
print(0)
elif a[0]*t[0]==b[0]*t[0]:
print(1)
else:
n=-t[0]*(b[0]-a[0])
m=-t[0]*(a[0]-b[0])-t[1]*(a[1]-b[1])
q=n//m
if n%m==0:
print(2*q)
else:
print(2*q+1) | 0 | null | 75,744,684,578,080 | 143 | 269 |
x, n = map(int, input().split())
p = list(map(int, input().split()))
i = 0
while True:
if x-i not in p:
print(x-i)
break
if x+i not in p:
print(x+i)
break
i += 1 | def main():
K = int(input())
ans = False
if K % 2 == 0:
print(-1)
exit()
cnt = 7 % K
for i in range(1, K+1):
if cnt == 0:
ans = True
print(i)
exit()
cnt = (10 * cnt + 7) % K
if ans == False:
print(-1)
exit()
main() | 0 | null | 10,008,076,010,180 | 128 | 97 |
inp = input()
if inp[0] == inp[1] and inp[1] == inp[2]:
print("No")
else:
print("Yes") | S = str(input())
if S != 'AAA' and S != 'BBB':
print('Yes')
else:
print('No') | 1 | 55,027,175,389,602 | null | 201 | 201 |
def main():
from collections import deque
N, M, K = map(int, input().split())
f = [set() for _ in range(N + 1)]
b = [set() for _ in range(N + 1)]
for _ in range(M):
i, j = map(int, input().split())
f[i].add(j)
f[j].add(i)
for _ in range(K):
i, j = map(int, input().split())
b[i].add(j)
b[j].add(i)
visited = [False] * (N + 1)
ans = [0] * (N + 1)
for i in range(1, N+1):
if visited[i]:
continue
visited[i] = True
link = {i}
todo = deque([i])
while len(todo) != 0:
c = todo.pop()
for p in f[c]:
if not(visited[p]):
link.add(p)
todo.append(p)
visited[p] = True
for j in link:
ans[j] = len(link) - len(link & f[j]) - len(link & b[j]) - 1
print(*ans[1:])
if __name__ == '__main__':
main() | #import numpy as np
#import math
#from decimal import *
#from numba import njit
#@njit
def main():
S,W = map(int, input().split())
if S <= W:
print('unsafe')
else:
print('safe')
main()
| 0 | null | 45,556,508,117,152 | 209 | 163 |
import math
import sys
import os
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))
if os.getenv("LOCAL"):
inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
sys.stdin = open(inputFile, "r")
INF = float("inf")
MOD = 998244353
# もらうDP(forcus on destination), 区間の和を足しこむ=累積和
N,K = LI()
LRs = [LI() for _ in range(K)]
dp = [0]*(N+1)
cum = [0]*(N+1)
dp[1] = 1
cum[1] = 1
for i in range(2, N+1):
for j in range(K):
l, r = LRs[j]
start = max(0,i-r-1)
end = max(0,i-l)
dp[i] += cum[end] - cum[start]
dp[i] %= MOD
# 累積和を更新
cum[i] = (cum[i-1] + dp[i]) % MOD
ans = dp[N]
print(ans) | N, K = map(int, input().split())
P = int(1e9+7)
cnt = [0]*(K+1)
ans = 0
for i in range(K, 0, -1):
c = pow(K//i, N, P) - sum(cnt[::i])
cnt[i] = c
ans = (ans+i*c)%P
print(ans%P)
| 0 | null | 19,761,298,432,330 | 74 | 176 |
# -*- coding: utf-8 -*-
def main():
A, B, C, K = map(int, input().split())
ans = 0
if K <= A:
ans = K
else:
if K <= A + B:
ans = A
else:
ans = A + (-1 * (K - A - B))
print(ans)
if __name__ == "__main__":
main() | a,b,c,k=map(int,input().split())
if a>=k:
print(k)
elif (k>a) and (a+b>=k):
print(a)
elif (a+b<k):
print(a-(k-(a+b)))
| 1 | 21,874,790,880,410 | null | 148 | 148 |
S,W = map(int, input().split())
print("suanfsea f e"[S<=W::2]) | (n,k),p,c=[[*map(int,t.split())]for t in open(0)]
a=-9e9
for i in range(n):
s=f=m=0;x,*l=i,
while~f:x=p[x]-1;s+=c[x];l+=s,;m+=1;f-=x==i
for j in range(min(m,k)):a=max(a,l[j]+(~j+k)//m*s*(s>0))
print(a) | 0 | null | 17,239,428,763,200 | 163 | 93 |
def answer(s: str) -> str:
return 'x' * len(s)
def main():
s = input()
print(answer(s))
if __name__ == '__main__':
main() | s = len(input())
print("x" * s)
| 1 | 72,753,403,239,452 | null | 221 | 221 |
while 1:
x, y = map(int, raw_input().split())
if x == y == 0:
break
else:
if x < y:
print "%d %d" % (x, y)
else:
print "%d %d" % (y, x) | while 1:
a,b=map(int,input().split())
if a+b==0:
break
elif a>b:
print(b,a)
continue
print(a,b) | 1 | 533,092,339,358 | null | 43 | 43 |
while True:
try:
print len(list(str(sum(map(int,raw_input().split())))))
except:
break | A = int(input())
B = int(input())
C = [A, B]
for i in [1, 2, 3]:
if i not in C:
print(i)
| 0 | null | 55,406,593,269,600 | 3 | 254 |
A = input().split(" ")
B = input().split(" ")
if A[0] == B[0]:
print("0")
else:
print("1")
| n,k = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
slist = ['']*k
for i in range(n):
slist[i%k] += T[i]
ans = 0
for s in slist:
dp = [[0,0,0]for i in range(len(s))]
#dp[i][j] = 直前にjを出したときの得点の最大値
'''
0..r
1..s
2..p
'''
dp[0][1] = S if s[0] == 'p' else 0
dp[0][0] = R if s[0] == 's' else 0
dp[0][2] = P if s[0] == 'r' else 0
for i in range(1,len(s)):
if s[i] == 'r':
dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + P
dp[i][1] = max(dp[i-1][0],dp[i-1][2])
dp[i][0] = max(dp[i-1][1],dp[i-1][2])
elif s[i] == 's':
dp[i][0] = max(dp[i-1][2],dp[i-1][1]) + R
dp[i][1] = max(dp[i-1][0],dp[i-1][2])
dp[i][2] = max(dp[i-1][1],dp[i-1][0])
else:
dp[i][1] = max(dp[i-1][2],dp[i-1][0]) + S
dp[i][0] = max(dp[i-1][1],dp[i-1][2])
dp[i][2] = max(dp[i-1][1],dp[i-1][0])
ans += max(dp[len(s)-1][0],dp[len(s)-1][1],dp[len(s)-1][2])
#print(slist)
print(ans)
| 0 | null | 116,030,466,170,112 | 264 | 251 |
A,B,C,K = map(int,input().split())
score = 0
if A<K:
K -= A
score += A
else:
score += K
print(score)
exit()
if B<K:
K -= B
else:
print(score)
exit()
score -= min(K,C)
print(score) | tmp = input().split(" ")
A = int(tmp[0])
B = int(tmp[1])
if A <= 9 and B <= 9:
print(A * B)
else:
print("-1") | 0 | null | 89,793,289,761,152 | 148 | 286 |
n, m, k = map(int, input().split())
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return ''.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf = UnionFind(n)
from collections import defaultdict
direct_f = defaultdict(int)
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
direct_f[a] += 1
direct_f[b] += 1
uf.union(a, b)
ans = [uf.size(i) - direct_f[i] - 1 for i in range(n)]
for i in range(k):
c, d = map(int, input().split())
c -= 1
d -= 1
if uf.same(c,d):
ans[c] -= 1
ans[d] -= 1
print(*ans) | N,M,K=map(int,input().split())
par=[0]*(N+1)
num=[0]*(N+1)
group = [1]*(N+1)
for i in range(1,N+1): par[i]=i
def root(x):
if par[x]==x: return x
return root(par[x])
def union(x,y):
rx = root(x)
ry = root(y)
if rx==ry: return
par[max(rx,ry)] = min(rx,ry)
group[min(rx,ry)] += group[max(rx,ry)]
def same(x,y):
return root(x)==root(y)
for _ in range(M):
a,b=map(int,input().split())
union(a,b)
num[a]+=1
num[b]+=1
for _ in range(K):
c,d=map(int,input().split())
if same(c,d):
num[c]+=1
num[d]+=1
for i in range(1,N+1):
print(group[root(i)]-num[i]-1,end=" ") | 1 | 61,767,603,883,028 | null | 209 | 209 |
A,B,C=map(int,input().split())
K=int(input())
ans="No"
for _ in range(K+1):
if A>=B:
B*=2
elif B>=C:
C*=2
else:
ans="Yes"
print(ans)
| # import sys
# input = sys.stdin.readline
import collections
def main():
n = int(input())
s = input()
a_list = []
for i in range(n):
if s[i] == "W":
a_list.append(0)
else:
a_list.append(1)
r_count = sum(a_list)
print(r_count - sum(a_list[0:r_count]))
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| 0 | null | 6,590,842,251,282 | 101 | 98 |
A, B=(input().split())
A=int(A)
C=int(B[0])*100+int(B[2])*10+int(B[3])
print(int(A*C//100))
| a=int(input())
b=0
c=int(a**(1/2))
for i in range(-1000,1000):
for j in range(-1000,1000):
if((i**5)-(j**5)==a):
b=1
break
if(b==1):
break
print(i,j) | 0 | null | 20,896,645,528,168 | 135 | 156 |
X = int(input())
for a in range(121):
for b in range(121):
if a ** 5 - b ** 5 == X:
print(a, b)
break
elif a ** 5 + b ** 5 == X:
print(a, -b)
break
else:
continue
break
| taro_score = 0
hanako_socore = 0
game_times = int(input())
for _ in range(game_times):
cards = input().split()
if cards[0] > cards[1]:
taro_score += 3
elif cards[0] == cards[1]:
taro_score += 1
hanako_socore += 1
else:
hanako_socore += 3
print(taro_score, hanako_socore)
| 0 | null | 13,749,125,941,522 | 156 | 67 |
r, c = map(int, input().split())
table = []
for _ in range(r):
table.append(list(map(int, input().split())))
for row in range(r):
print(' '.join(map(str, table[row])), sum(table[row]), sep=' ')
# print(' '.join(map(str, [sum(table[:][col]) for col in range(c)])), sum(table), sep=' ')
col_sum = [sum([table[row][col] for row in range(r)]) for col in range(c)]
print(' '.join(map(str, col_sum)), sum(col_sum), sep=' ')
| # AOJ ITP1_7_C
def numinput():
a = input().split()
for i in range(len(a)):
a[i] = int(a[i])
return a
def main():
a = numinput()
r = a[0]; c = a[1]
M = []
for i in range(r):
M.append(numinput()) # あ、そうか。。
sum = 0
for j in range(c): sum += M[i][j]
M[i].append(sum)
list = []
for j in range(c + 1):
sum = 0
for i in range(r): sum += M[i][j]
list.append(sum)
M.append(list)
for i in range(r + 1):
_str_ = ""
for j in range(c):
_str_ += str(M[i][j]) + " "
_str_ += str(M[i][c])
print(_str_)
if __name__ == "__main__":
main()
| 1 | 1,384,441,319,264 | null | 59 | 59 |
N, K = map(int, input().split())
x = 10
y = 10 + N
ans = 0
a = x
b = y
for i in range(1, N + 2):
if i >= K:
ans += b - a + 1
a += (x + i)
b += (y - i)
print(ans % (10 ** 9 + 7))
| def main():
n, k = list(map(int, input().split()))
mod = 1000000007
N = list(range(n + 1))
mn = [0] * (n + 1)
mx = [0] * (n + 1)
mx[0] = n
for i in range(1, n + 1):
mn[i] = mn[i - 1] + N[i]
mx[i] = mx[i - 1] + N[n - i]
ans = 0
for a, b in zip(mn[k - 1:], mx[k - 1:]):
ans += b - a + 1
ans %= mod
print(ans)
if __name__ == '__main__':
main()
| 1 | 32,989,535,417,552 | null | 170 | 170 |
# ==================================================-
# 二分探索
# functionを満たす,search_listの最大の要素を出力
# 【注意点】searchリストの初めの方はfunctionを満たし、後ろに行くにつれて満たさなくなるべき
import math
import sys
sys.setrecursionlimit(10 ** 9)
def binary_research(start, end,function):
if start == end:
return start
middle = math.ceil((start + end) / 2)
if function(middle, k, a_sum, b_sum):
start = middle
else:
end = middle - 1
return binary_research(start, end, function)
# ==================================================-
n, m, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a_sum = [0]
b_sum = [0]
for book in a:
a_sum.append(a_sum[-1] + book)
for book in b:
b_sum.append(b_sum[-1] + book)
def can_read(num, k, a_sum, b_sum):
min_read_time = 1000000000000
for i in range(max(0, num - m), min(num+1,n+1)):
a_num = i
b_num = num - i
min_read_time = min(min_read_time, a_sum[a_num] + b_sum[b_num])
if min_read_time <= k:
return True
return False
start = 0
end = n + m
print(binary_research(start, end, can_read)) | n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0 for i in range(n+1)]
b = [0 for j in range(m+1)]
for i in range(n):
a[i+1] = a[i]+A[i]
for j in range(m):
b[j+1] = b[j]+B[j]
j = m
res = 0
for i in range(n+1):
if a[i] > k:
break
while k - a[i] < b[j]:
j -= 1
res = max(res, i+j)
print(res) | 1 | 10,843,264,759,840 | null | 117 | 117 |
a = list(map(int,input().split(' ')))
if a[0] < a[1] and a[1] < a[2]:
print('Yes')
else:
print('No')
| n=map(int,raw_input().split())
if n[0]<n[1]<n[2]:
print "Yes"
else:
print "No" | 1 | 388,948,012,940 | null | 39 | 39 |
str = input()
s_ans = 'Yes'
if len(str)%2 == 1:
s_ans ='No'
else:
for i in range(0,len(str),2):
moji = str[i:i+2]
if str[i:i+2] != 'hi':
s_ans = 'No'
break
print(s_ans) | w=input()
a=0
while True:
t=input().split()
l=[]
for T in t:
l.append(T.lower())
a+=l.count(w)
if t[0]=="END_OF_TEXT":
break
print(a)
| 0 | null | 27,342,337,189,070 | 199 | 65 |
N = int(input())
alphabet = list("abcdefghijklmnopqrstuvwxyz")
res = ""
while (N > 0):
N -= 1
num = int(N % 26)
res += alphabet[num]
N /= 26
N = N // 1
print(res[::-1]) | N = int(input())
a = [0]
i = 0
L = 26
while True:
if a[i] < N <= a[i] + L**(i + 1):
break
a.append(a[i] + L**(i + 1))
i += 1
N -= a[i] + 1
for j in range(i, -1, -1):
if j > 0:
print(chr(N // L**(j) + ord('a')), end="")
else:
print(chr(N + ord('a')), end="")
N = N % L**(j)
| 1 | 11,917,571,425,892 | null | 121 | 121 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
N = int(readline())
A = list(map(int, readline().split()))
S = set(A)
if len(S) == N:
print("YES")
else:
print("NO")
if __name__ == '__main__':
main()
| n=int(input())
a= list(map(int, input().split()))
kt=1
a.sort()
for i in range (0,n-1):
if a[i]==a[i+1]:
kt=0
break
if kt==1:
print("YES")
else:
print("NO") | 1 | 73,865,405,723,072 | null | 222 | 222 |
INPUT = list(input().split())
a = int(INPUT[0])
b = int(INPUT[1])
if a == b:
print("Yes")
else:
print("No") | def fib(n):
F = {0:1, 1:1}
def fibonacci(n):
ans = F.get(n,-1)
if ans > 0: return ans
F[n] = fibonacci(n-1) + fibonacci(n-2)
return F[n]
return fibonacci(n)
if __name__=='__main__':
print(fib(int(input()))) | 0 | null | 41,884,263,389,770 | 231 | 7 |
n,k=map(int,input().split())
l =[]
cnt =0
for i in range(k):
d = int(input())
a = list(map(int,input().split()))
for j in a:
l.append(j)
for i in range(1,n+1):
if i not in l:
cnt+=1
print(cnt) | inps = input().split()
if len(inps) >= 2:
a = int(inps[0])
b = int(inps[1])
if a > b:
print("a > b")
elif a < b:
print("a < b")
else:
print("a == b")
else:
print("Input illegal.") | 0 | null | 12,543,202,487,790 | 154 | 38 |
m, t, s = input().split()
if float(m) / float(s) <= float(t):
print('Yes')
else:
print('No') | d,t,s = input().split()
d,t,s=int(d),int(t),int(s)
if t>=(d/s):
print("Yes")
else:
print("No")
| 1 | 3,567,875,485,952 | null | 81 | 81 |
def main():
X, Y = map(int, input().split())
ans = 0;
if X == 1:
ans += 300000
elif X == 2:
ans += 200000
elif X == 3:
ans += 100000
if Y == 1:
ans += 300000
elif Y == 2:
ans += 200000
elif Y == 3:
ans += 100000
if X == 1 and Y == 1:
ans += 400000
print(ans)
if __name__ == '__main__':
main() | def resolve():
X, Y = input().split()
ans = 0
if X == "3":
ans += 100000
elif X == "2":
ans += 200000
elif X == "1":
ans += 300000
else:
ans += 0
if Y == "3":
ans += 100000
elif Y == "2":
ans += 200000
elif Y == "1":
ans += 300000
else:
ans += 0
if X == "1" and Y == "1":
ans += 400000
else:
ans += 0
print(ans)
resolve() | 1 | 140,726,431,159,912 | null | 275 | 275 |
import sys
sys.setrecursionlimit(303)
def doit(n, k, m):
if len(n) == 0 or k < 0:
return k == 0
if (n, k) not in m:
d = int(n[0])
m[(n, k)] = sum(doit(n[1:] if i == d else '9' * (len(n) - 1), k - 1 if i > 0 else k, m) for i in range(d + 1))
return m[(n, k)]
print(doit(input(), int(input()), {}))
| import sys
from functools import lru_cache
N = int(sys.stdin.readline().rstrip())
K = int(sys.stdin.readline().rstrip())
@lru_cache(None)
def F(N, K):
"""(0以上)N以下で、0でないものがちょうどK個"""
assert N >= 0 # Nが非負であることを保証する
if N < 10: # N が一桁
if K == 0: # 使える 0 以外の数がない場合
return 1 #
if K == 1:
return N # 1,2,...,N までのどれか
return 0 # それ以上 K が余っていたら作れない
q, r = divmod(N, 10) # N = 10*q + r と置く
ret = 0
if K >= 1:
# 1の位(r)が nonzero
ret += F(q, K - 1) * r #
ret += F(q - 1, K - 1) * (9 - r)
# 1の位(r)が zero
ret += F(q, K)
return ret
print(F(N, K))
| 1 | 76,249,488,015,730 | null | 224 | 224 |
def main():
S = input()
if "RRR" in S:
print(3)
elif "RR" in S:
print(2)
elif "R" in S:
print(1)
else:
print(0)
if __name__ == '__main__':
main()
| # -*- coding: utf-8 -*-
S = input()
if 'RRR' in S:
print("3")
elif 'RR' in S:
print("2")
elif 'R' in S:
print("1")
else:
print("0") | 1 | 4,852,744,145,000 | null | 90 | 90 |
n = list(map(int, input().split()))
n.sort()
print('{} {} {}'.format(n[0], n[1], n[2])) | nums = list(map(int, input().split()))
nums.sort()
print(nums[0], nums[1], nums[2]) | 1 | 404,110,992,672 | null | 40 | 40 |
N,S=map(int,input().split())
A=list(map(int,input().split()))
mod=998244353
DP=[0]*(S+1)
DP[0]=pow(2,N,mod)
INV=pow(2,mod-2,mod)
for a in A:
for i in range(S-a,-1,-1):
DP[i+a]=(DP[i]*INV+DP[i+a])%mod
print(DP[S]) | mod = 998244353
n, s = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0]*(3001) 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] % mod
if j-A[i] >= 0:
dp[i+1][j] = (dp[i+1][j]+dp[i][j-A[i]]) % mod
print(dp[n][s])
| 1 | 17,597,243,804,100 | null | 138 | 138 |
def main():
N = int(input())
A = [[i for i in input().split()] for j in range(N)]
X = input()
ans = 0
flag = False
for a, b in A:
if a == X:
flag = True
continue
if flag:
ans += int(b)
print(ans)
if __name__ == '__main__':
main()
| n=int(input())
s=[""]*n
t=[0]*n
for i in range(n):
s[i],t[i]=input().split()
t[i]=int(t[i])
x=input()
c=0
for i in range(n):
if s[i]==x:
c=i
break
ans=0
for i in range(c+1,n):
ans+=t[i]
print(ans) | 1 | 96,859,935,374,498 | null | 243 | 243 |
def atc_154b(S: str) -> str:
return "x" * len(S)
S_input = input()
print(atc_154b(S_input))
| s=input()
lis=list(s)
n=len(lis)
X=["x" for i in range(n)]
print("".join(X)) | 1 | 72,766,348,763,008 | null | 221 | 221 |
import sys
input = sys.stdin.readline
# C - Subarray Sum
n, k, s = map(int, input().split())
ans = ''
str_s = str(s)
if s < pow(10, 9):
str_another = str(s + 1)
else:
str_another = '1'
for i in range(n):
if i < k:
ans += str_s + ' '
else:
ans += str_another + ' '
print(ans[:len(ans)-1]) | L,R,d=map(int,input().split());print(R//d-(L-1)//d) | 0 | null | 49,084,445,550,232 | 238 | 104 |
n, x, m = map(int, input().split())
X = [-1] * m
P = []
sum_p = 0
while X[x] == -1: # preset
X[x] = len(P) # pre length
P.append(sum_p) # pre sum_p
sum_p += x # now sum_p
x = x*x % m
P.append(sum_p) # full sum_p
p_len = len(P) - 1
cyc_times, nxt_len = divmod(n - X[x], p_len - X[x])
cyc = (sum_p - P[X[x]]) * cyc_times
remain = P[X[x] + nxt_len]
print(cyc + remain)
| def f(x, m):
return x * x % m
def main():
N, X, M = map(int, input().split())
pre = set()
pre.add(X)
cnt = 1
while cnt < N:
X = f(X, M)
if X in pre: break
cnt += 1
pre.add(X)
if cnt == N:
return sum(pre)
ans = sum(pre)
N -= cnt
loop = set()
loop.add(X)
while cnt < N:
X = f(X, M)
if X in loop: break
loop.add(X)
left = N % len(loop)
ans += sum(loop) * (N // len(loop))
for i in range(left):
ans += X
X = f(X, M)
return ans
print(main())
| 1 | 2,809,278,221,190 | null | 75 | 75 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools as ite
import math
import random
import sys
import codecs
from collections import defaultdict
sys.setrecursionlimit(1000000)
INF = 10 ** 18
MOD = 10 ** 9 + 7
n, m = map(int, input().split())
c = list(map(int, input().split()))
DP = [0] + [n] * n
for i in range(m):
for j in range(c[i], n + 1):
DP[j] = min(DP[j], DP[j - c[i]] + 1)
print(DP[n])
| import bisect
n=int(input())
s=list(input())
#アルファベットの各文字に対してからのリストを持つ辞書
alpha={chr(i):[] for i in range(97,123)}
#alpha[c]で各文字ごとに出現場所をソートして保管
for i,c in enumerate(s):
bisect.insort(alpha[c],i+1)
for i in range(int(input())):
p,q,r=input().split()
if p=='1':
q=int(q)
b=s[q-1]
if b!=r:
alpha[b].pop(bisect.bisect_left(alpha[b],q))
bisect.insort(alpha[r],q)
s[q-1]=r
else:
count=0
for l in alpha.values():
pos=bisect.bisect_left(l,int(q))
if pos<len(l) and l[pos]<=int(r):
count+=1
print(count)
| 0 | null | 31,498,316,560,228 | 28 | 210 |
while True:
s = input().rstrip().split(' ')
a = int(s[0])
b = int(s[2])
op = s[1]
if op == "?":
break
elif op == "+":
print(str(a + b))
elif op == "-":
print(str(a - b))
elif op == "*":
print(str(a * b))
elif op == "/":
print(str(int(a / b))) | n = int(input())
a = list(map(int, input().split()))
try:
idx = a.index(0)
print(0)
except ValueError:
ans = a[0]
for i in range(1, len(a)):
ans *= a[i]
if ans > 10**18:
print('-1')
exit()
print(ans) | 0 | null | 8,508,718,689,984 | 47 | 134 |
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
G = [0]*3
ans = 1
for i in range(N):
x = 0
cnt = 0
for j, g in enumerate(G):
if g == A[i]:
x = j if cnt == 0 else x
cnt += 1
G[x] += 1
ans *= cnt
ans = ans % mod
print(ans) | n = input()
A=[int(j) for j in input().split()]
nums = [0,0,0]
ans = 1
for a in A:
ans = (ans*nums.count(a))%(10**9 +7)
for i in range(len(nums)):
if nums[i] == a:
nums[i] = a+1
break
print(ans) | 1 | 130,181,968,536,320 | null | 268 | 268 |
n, m, q = map(int, input().split())
a_list = []
b_list = []
c_list = []
d_list = []
for _ in range(q):
a, b, c, d = map(int, input().split())
a_list.append(a)
b_list.append(b)
c_list.append(c)
d_list.append(d)
import itertools
ans = 0
h_list = [i+1 for i in range(m)]
for A in itertools.combinations_with_replacement(h_list, n):
# print(A)
max_d = 0
for a, b, c, d in zip(a_list, b_list, c_list, d_list):
if A[b-1]-A[a-1] == c:
max_d += d
ans = max(ans, max_d)
print(ans) | from collections import defaultdict
import sys
input = sys.stdin.readline
# エラトステネスの篩
#############################################################
def get_sieve_of_eratosthenes(n):
if not isinstance(n, int):
raise TypeError('n is int type.')
if n < 2:
raise ValueError('n is more than 2')
prime = [2]
limit = int(n**0.5)
data = [i + 1 for i in range(2, n, 2)]
while True:
p = data[0]
if limit <= p:
return prime + data
prime.append(p)
data = [e for e in data if e % p != 0]
#############################################################
# 素因数分解、リストで返す
#############################################################
def prime_factorize(n, prime_list):
a = []
for p in prime_list:
if p * p > n:
break
while True:
if n % p == 0:
a.append(p)
n //= p
else:
break
if n != 1:
a.append(n)
a.sort()
return a
#############################################################
N = int(input())
A = list(map(int, input().split()))
data = set(get_sieve_of_eratosthenes(10**6))
primes = defaultdict(int)
for i in range(N):
p = prime_factorize(A[i], data)
p_set = set(p)
for pi in p_set:
primes[pi] += 1
# print(primes)
if len(primes) == 0:
print("pairwise coprime")
exit()
max_cnt = max(primes.values())
min_cnt = min(primes.values())
if max_cnt == 1:
print("pairwise coprime")
elif max_cnt != N:
print("setwise coprime")
else:
print("not coprime")
| 0 | null | 15,971,988,698,278 | 160 | 85 |
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
N = I()
d = LI()
ans = 0
for i in range(N-1):
for j in range(i+1,N):
ans += d[i]*d[j]
print(ans) | A,B=map(int,input().split())
print(A*B if 1<=A<=9 and 0<B<10 else -1) | 0 | null | 163,229,977,145,370 | 292 | 286 |
N = int(input())
A = list(map(int,input().split()))
def insertionSort(A,N):
for i in range(1,N):
v = A[i]
j = i -1
while j >= 0 and A[j] > v:
A[j+1] = A[j]
j -= 1
A[j+1] = v
outputNum(A)
def outputNum(A):
tmp = map(str,A)
text = " ".join(tmp)
print(text)
outputNum(A)
insertionSort(A,N)
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
from decimal import *
#再帰バージョン
N = INT()
def DFS(n):
if len(n) == N:
print(n)
else:
for i in range(len(set(n))+1):
m = n+ascii_lowercase[i]
DFS(m)
DFS("a")
| 0 | null | 26,290,626,063,968 | 10 | 198 |
from decimal import *
x,y,z = map(int,input().split())
a=Decimal(x)
b=Decimal(y)
c=Decimal(z)
if Decimal((c-a-b)**Decimal(2)) > Decimal(Decimal(4)*a*b) and c-a-b > 0:
print('Yes')
else:
print('No') | #!/usr/bin/env python
from sys import stdin, stderr
def main():
a, b, c = map(int, stdin.readline().split())
print('Yes' if c-a-b >= 0 and 4*a*b < (c-a-b)**2 else 'No')
return 0
if __name__ == '__main__': main()
| 1 | 51,541,475,630,050 | null | 197 | 197 |
n, k = map(int, input().split())
aa = list(map(int, input().split()))
ff = list(map(int, input().split()))
a = sorted(aa, reverse=True)
f = sorted(ff)
def C(x):
ret = 0
for i in range(n):
ret += max(0, a[i] - x // f[i])
return ret
lb = -1
ub = 10 ** 12 + 1
while (ub - lb) > 1:
mid = (ub + lb) // 2
if C(mid) > k:
lb = mid
else:
ub = mid
print(ub)
| l1=input().split()
l2=list(map(int,input().split()))
l2[l1.index(input())]-=1
print(" ".join(str(x) for x in l2)) | 0 | null | 118,399,276,670,820 | 290 | 220 |
from itertools import accumulate
N, K = map(int, input().split())
P = list(map(int, input().split()))
P = [((x+1) * x / 2) / x for x in P]
A = list(accumulate(P))
ans = A[K-1]
for i in range(K, N):
ans = max(ans, A[i] - A[i-K])
print(ans)
| l = [x+' '+y for x in['S','H','C','D']for y in[str(i+1)for i in range(13)]]
for n in range(int(input())):
l.remove(input())
for i in l:
print(i) | 0 | null | 37,818,434,415,278 | 223 | 54 |
n, m = map(int, input().split())
a = list(map(int, input().split()))
s = int(sum(a))
if n > s:
print(n-s)
elif n == s:
print(0)
else:
print(-1)
| N, M = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
print(max(N - sum(A), -1))
| 1 | 32,048,074,202,990 | null | 168 | 168 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N = int(input())
XY = []
for _ in range(N):
A = int(input())
xy = [list(mapint()) for _ in range(A)]
XY.append(xy)
ans = 0
for i in range(1<<N):
honest = [-1]*N
cnt = 0
ok = True
for j in range(N):
if (i>>j)&1:
honest[j]=1
else:
honest[j]=0
for j in range(N):
if (i>>j)&1:
cnt += 1
for x, y in XY[j]:
if honest[x-1]!=y:
ok = False
break
if ok:
ans = max(ans, cnt)
print(ans)
| from itertools import product
n = int(input())
info = {}
for p in range(n):
a = int(input())
L = []
for _ in range(a):
x,y = list(map(int, input().split()))
x,y = x-1, y
L.append((x,y))
info[p] = L
ans = 0
for bit_pattern in product(range(2), repeat=n):
for p,bit in enumerate(bit_pattern):
if bit:
if not all([bit_pattern[x] == y for x,y in info[p]]):
break
else:
ans = max(ans, sum(bit_pattern))
print(ans) | 1 | 121,082,224,653,188 | null | 262 | 262 |
from math import cos, radians, sin, sqrt
def g(a, b, c):
c_rad = radians(c)
yield a * b * sin(c_rad) / 2
yield a + b + sqrt(a ** 2 + b ** 2 - 2 * a * b * cos(c_rad))
yield b * sin(c_rad)
a, b, c = list(map(int, input().split()))
for i in g(a, b, c):
print("{:.8f}".format(i)) | import math
a, b, C = map(int,input().split());
c = math.radians(C)
print((1/2)*a*b*math.sin(c));
print(a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(c)));
print(b*math.sin(c));
| 1 | 174,231,812,612 | null | 30 | 30 |
a, b = list(map(int, input().split()))
print("{0} {1} {2}".format(a//b, a%b, format(a / b, '.5f'))) | a, b = map(int, input().split())
print("{:d} {:d} {:f}".format(a//b, a%b, a/b)) | 1 | 601,972,584,616 | null | 45 | 45 |
n = int(input())
s = input()
ans = ''
for i in s:
next_number = ord(i)+n
if next_number > 90:
next_number -= 26
ans += chr(next_number)
else:
ans += chr(next_number)
print(ans) | N = int(input())
S = list(input())
M = len(S)
A = [""]*M
for i in range(M):
ref = 65 + (ord(S[i]) + N - 65) % 26
A[i] = chr(ref)
ans = "".join(A)
print(ans) | 1 | 134,615,430,856,220 | null | 271 | 271 |
n = int(input())
s, t = map(str, input().split())
sl = list(s)
tl = list(t)
a = []
for i in range(n):
a.append(s[i])
a.append(t[i])
print(''.join(a)) | import collections
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
H, W, *S = open(0).read().split()
H, W = [int(_) for _ in [H, W]]
A = []
B = []
C = []
for i in range(H * W):
x, y = divmod(i, W)
if S[x][y] == '.':
for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
nx, ny = x + dx, y + dy
if not (0 <= nx < H and 0 <= ny < W):
continue
if S[nx][ny] == '.':
A += [i]
B += [nx * W + ny]
C += [1]
F = floyd_warshall(csr_matrix((C, (A, B)), shape=(H*W, H*W)))
print(int(np.max(F[F!=np.inf])))
| 0 | null | 102,835,608,033,950 | 255 | 241 |
import sys
import random
test = False
def solve(c_list, days, now):
r = sum(c_list[i]*(now-days[i]) for i in range(26))
return r
if test == True:
seed = 94
random.seed(seed)
d = 365
c = [random.randrange(0, 101) for _ in range(26)]
s = [[random.randrange(0, 20001) for _ in range(26)] for _ in range(d)]
c_ = ' '.join(map(str, c))
s_ = '\n'.join([' '.join(map(str, i)) for i in s])
with open('./input.txt', 'w') as f:
f.write('\n'.join([str(d), c_, s_]))
else:
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _i in range(d)]
last_days = [-1 for _i in range(26)]
result = []
score = 0
for today in range(d):
checker = [c[j]*(today-last_days[j]) for j in range(26)]
y = sum(checker)
finder = [s[today][j]-(y-checker[j]) for j in range(26)]
x = finder.index(max(finder))
last_days[x] = today
result.append(x+1)
score += s[today][x] - solve(c, last_days, today)
#print(score)
if test == True:
with open('./output.txt', 'w') as f:
f.write('\n'.join(map(str, result)))
else:
for i in result:
print(i) | n,m = map(int, input().split())
A = list(map(int, input().split()))
rank = sum(A) / (4*m)
cnt =0
for a in A:
cnt += rank <= a
if cnt >= m:
print('Yes')
else:
print('No') | 0 | null | 24,281,487,329,824 | 113 | 179 |
import sys
sys.setrecursionlimit(10**6)
x = int(input())
if x >= 30:
print('Yes')
else:
print('No') | n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
dict = {'s': r, 'p': s, 'r': p}
cnt, ans = set(), 0
for i, ti in enumerate(t):
if (i - k in cnt) and ti == t[i - k]:
continue
ans += dict[ti]
cnt.add(i)
print(ans)
| 0 | null | 56,529,337,220,110 | 95 | 251 |
def solve():
S,T = input().split()
A,B = [int(i) for i in input().split()]
U = input()
if U == S:
print(A-1, B)
else:
print(A, B-1)
if __name__ == "__main__":
solve() | s, t = map(str, input().split())
a, b = map(int, input().split())
u = input()
st = {}
st[s] = a
st[t] = b
st[u] -= 1
print('{} {}'.format(st[s], st[t])) | 1 | 71,923,024,571,760 | null | 220 | 220 |
def main():
""""ここに今までのコード"""
H = int(input())
Count, atk = 1,1
while H > atk * 2 - 1:
atk = atk * 2
Count = Count * 2 + 1
print(Count)
if __name__ == '__main__':
main() | n=int(input())
cnt=0
ans=0
while(n>=1):
ans+=2**cnt
n//=2
cnt+=1
print(ans) | 1 | 80,573,168,694,330 | null | 228 | 228 |
N = int(input())
S = input()
if N % 2 or S[:N//2] != S[N//2:]:
print("No")
else:
print("Yes") | print('bust' if sum(list(map(int,input().split()))) > 21 else 'win') | 0 | null | 133,340,146,375,030 | 279 | 260 |
import itertools
a, b, c = map(int, input().split(" "))
k = int(input())
f = False
for conb in list(itertools.combinations_with_replacement([0, 1, 2], k)):
a_i = conb.count(0)
b_i = conb.count(1)
c_i = conb.count(2)
if (a * (2 ** a_i) < b * (2 **b_i)) and (b * (2 ** b_i) < c * (2 ** c_i)):
f = True
if f:
print("Yes")
else:
print("No") | a,b,c=map(int,input().split())
k=int(input())
cnt=0
while a>=b:
b*=2
cnt+=1
while b>=c:
c*=2
cnt+=1
print("Yes" if cnt<=k else "No") | 1 | 6,824,528,393,980 | null | 101 | 101 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.