problem_id
stringlengths 6
6
| buggy_code
stringlengths 8
526k
| fixed_code
stringlengths 12
526k
| labels
listlengths 0
15
⌀ | buggy_submission_id
int64 1
1.54M
| fixed_submission_id
int64 2
1.54M
| user_id
stringlengths 10
10
| language
stringclasses 8
values |
|---|---|---|---|---|---|---|---|
p02820
|
n,k = (int(i) for i in input().split())
r,s,p = (int(i) for i in input().split())
t = input()
ans = 0
x = []
for i in range(n):
if i<k:
if t[i] == "r":
x.append(0)
ans += p
elif t[i] == "s":
x.append("r")
ans += r
elif t[i] == "p":
x.append("s")
ans += s
else:
if t[i] == "r":
if x[i-k] != "p":
x.append("p")
ans += p
else:
x.append(-1)
elif t[i] == "s":
if x[i-k] != "r":
x.append("r")
ans += r
else:
x.append(-1)
elif t[i] == "p":
if x[i-k] != "s":
x.append("s")
ans += s
else:
x.append(-1)
print(ans)
|
n,k = (int(i) for i in input().split())
r,s,p = (int(i) for i in input().split())
t = input()
ans = 0
x = []
for i in range(n):
if i<k:
if t[i] == "r":
x.append("p")
ans += p
elif t[i] == "s":
x.append("r")
ans += r
elif t[i] == "p":
x.append("s")
ans += s
else:
if t[i] == "r":
if x[i-k] != "p":
x.append("p")
ans += p
else:
x.append(-1)
elif t[i] == "s":
if x[i-k] != "r":
x.append("r")
ans += r
else:
x.append(-1)
elif t[i] == "p":
if x[i-k] != "s":
x.append("s")
ans += s
else:
x.append(-1)
print(ans)
|
[
"call.arguments.change"
] | 625,494
| 625,495
|
u620755070
|
python
|
p02820
|
*t,s=open(0).read().split()
n,k,r,s,p=map(int,t)
d={'r':p,'s':r,'p':s}
b=['']*n*2
a=0
for i,c in enumerate(s[:n]):
if c!=b[i-k]:
b[i]=c
a+=d[c]
print(a)
|
*n,t=open(0).read().split()
n,k,r,s,p=map(int,n)
d={'r':p,'s':r,'p':s}
b=['']*n*2
a=0
for i,c in enumerate(t[:n]):
if c!=b[i-k]:
b[i]=c
a+=d[c]
print(a)
|
[
"assignment.variable.change",
"identifier.change",
"assignment.value.change",
"call.arguments.change"
] | 625,507
| 625,508
|
u729133443
|
python
|
p02820
|
n,k = map(int,input().split())
r,s,p = map(int,input().split())
S = input()
ans = 0
hand = ""
dic = {"r":"p","p":"s","s":"r"}
for i in range(n):
if i < k:
if S[i] == "r":
ans += p
hand += "p"
elif S[i] == "p":
ans += s
hand += "s"
else:
ans += r
hand += "r"
else:
if dic[S[i]] == hand[i-k]:
hand += S[i]
continue
else:
if S[i] == "r":
ans += p
hand += "p"
elif S[i] == "p":
ans += s
hand += "s"
else:
ans += r
hand += "r"
print(ans)
|
n,k = map(int,input().split())
r,s,p = map(int,input().split())
S = input()
ans = 0
hand = ""
dic = {"r":"p","p":"s","s":"r"}
for i in range(n):
if i < k:
if S[i] == "r":
ans += p
hand += "p"
elif S[i] == "p":
ans += s
hand += "s"
else:
ans += r
hand += "r"
else:
if dic[S[i]] == hand[i-k]:
hand += "q"
continue
else:
if S[i] == "r":
ans += p
hand += "p"
elif S[i] == "p":
ans += s
hand += "s"
else:
ans += r
hand += "r"
print(ans)
|
[] | 625,518
| 625,519
|
u350836088
|
python
|
p02820
|
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=str(input())
c=int(0)
def get(x,c):
if x=="r":
c+=P
elif x=="s":
c+=R
else:
c+=S
return c
n=len(T)
for i in range(n):
if i<=K-1:
c=get(T[i],c)
else:
if T[i-K]!=T[i]:
c=get(T[i],c)
if T[i-K]!="o" and T[i-K]==T[i]:
T=T[:i-K]+"o"+T[i-K+1:]
print(c)
|
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=str(input())
c=int(0)
def get(x,c):
if x=="r":
c+=P
elif x=="s":
c+=R
else:
c+=S
return c
n=len(T)
for i in range(n):
if i<=K-1:
c=get(T[i],c)
else:
if T[i-K]!=T[i]:
c=get(T[i],c)
if T[i-K]!="o" and T[i-K]==T[i]:
T=T[:i]+"o"+T[i+1:]
print(c)
|
[
"expression.operation.binary.remove"
] | 625,522
| 625,523
|
u692311686
|
python
|
p02820
|
def A():
temp = input().split()
print(''.join(temp[::-1]))
def B():
temp = [int(n) for n in input().split()]
A = temp[0]
B = temp[1]
K = temp[2]
to_minus = min(A, K)
A -= to_minus
K -= to_minus
if K > 0:
B -= min(B, K)
print (A, B)
import math
def C():
X = int(input())
if X <= 2:
print(2)
return
def isPrime(n):
if n <= 3:
return True
if(n % 2 == 0 or n % 3 == 0):
return False
for i in range(5,int(math.sqrt(n) + 1), 6):
if(n%i == 0 or n%(i + 2) == 0):
return False
return True
while True:
if isPrime(X):
print(X)
return
X += 1
def D():
temp = [int(n) for n in input().split()]
N = temp[0]
K = temp[1]
temp = [int(n) for n in input().split()]
point_dict = {'r': temp[0], 's': temp[1], 'p': temp[2]}
T = input()
winning_rule = {'r': 'p', 's': 'r', 'p': 's'}
ans = 0
last_choice = ['' for i in range(K)]
for i, c in enumerate(T):
if i<K or last_choice[i%K] != winning_rule[c]:
last_choice[i%K] = winning_rule[c]
ans += point_dict[winning_rule[c]]
else:
last_choice[i%K] = c
print(ans)
D()
|
def A():
temp = input().split()
print(''.join(temp[::-1]))
def B():
temp = [int(n) for n in input().split()]
A = temp[0]
B = temp[1]
K = temp[2]
to_minus = min(A, K)
A -= to_minus
K -= to_minus
if K > 0:
B -= min(B, K)
print (A, B)
import math
def C():
X = int(input())
if X <= 2:
print(2)
return
def isPrime(n):
if n <= 3:
return True
if(n % 2 == 0 or n % 3 == 0):
return False
for i in range(5,int(math.sqrt(n) + 1), 6):
if(n%i == 0 or n%(i + 2) == 0):
return False
return True
while True:
if isPrime(X):
print(X)
return
X += 1
def D():
temp = [int(n) for n in input().split()]
N = temp[0]
K = temp[1]
temp = [int(n) for n in input().split()]
point_dict = {'r': temp[0], 's': temp[1], 'p': temp[2]}
T = input()
winning_rule = {'r': 'p', 's': 'r', 'p': 's'}
ans = 0
last_choice = ['' for i in range(K)]
for i, c in enumerate(T):
if i<K or last_choice[i%K] != winning_rule[c]:
last_choice[i%K] = winning_rule[c]
ans += point_dict[winning_rule[c]]
else:
last_choice[i%K] = None
print(ans)
D()
|
[
"assignment.value.change"
] | 625,528
| 625,529
|
u151285327
|
python
|
p02820
|
def f(x):
if x == "r":
return "p"
elif x == "s":
return "r"
else:
return "s"
def g(x):
if x == "r":
return r
elif x == "s":
return s
else:
return p
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = str(input())
ssssppr
m = n
a = 0
ss = [' '] * m
if m <= k:
for i in range(m):
a += g(f(t[i]))
print(a)
else:
for i in range(k):
a += g(f(t[i]))
ss[i] = f(t[i])
for i in range(k,m):
if t[i-k] != t[i]:
a += g(f(t[i]))
ss[i] = f(t[i])
elif (t[i-k] == t[i]) and (ss[i-k] != f(t[i])):
a += g(f(t[i]))
ss[i] = f(t[i])
print(a)
|
def f(x):
if x == "r":
return "p"
elif x == "s":
return "r"
else:
return "s"
def g(x):
if x == "r":
return r
elif x == "s":
return s
else:
return p
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = str(input())
m = n
a = 0
ss = [' '] * m
if m <= k:
for i in range(m):
a += g(f(t[i]))
print(a)
else:
for i in range(k):
a += g(f(t[i]))
ss[i] = f(t[i])
for i in range(k,m):
if t[i-k] != t[i]:
a += g(f(t[i]))
ss[i] = f(t[i])
elif (t[i-k] == t[i]) and (ss[i-k] != f(t[i])):
a += g(f(t[i]))
ss[i] = f(t[i])
print(a)
|
[] | 625,538
| 625,539
|
u865119809
|
python
|
p02820
|
def f(x):
if x == "r":
return "p"
elif x == "s":
return "r"
else:
return "s"
def g(x):
if x == "r":
return r
elif x == "s":
return s
else:
return p
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = str(input())
ssssppr
m = n
a = 0
ss = [' '] ** m
if m <= k:
for i in range(m):
a += g(f(t[i]))
print(a)
else:
for i in range(k):
a += g(f(t[i]))
ss[i] = f(t[i])
for i in range(k,m):
if t[i-k] != t[i]:
a += g(f(t[i]))
ss[i] = f(t[i])
elif (t[i-k] == t[i]) and (ss[i-k] != f(t[i])):
a += g(f(t[i]))
ss[i] = f(t[i])
print(a)
|
def f(x):
if x == "r":
return "p"
elif x == "s":
return "r"
else:
return "s"
def g(x):
if x == "r":
return r
elif x == "s":
return s
else:
return p
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = str(input())
m = n
a = 0
ss = [' '] * m
if m <= k:
for i in range(m):
a += g(f(t[i]))
print(a)
else:
for i in range(k):
a += g(f(t[i]))
ss[i] = f(t[i])
for i in range(k,m):
if t[i-k] != t[i]:
a += g(f(t[i]))
ss[i] = f(t[i])
elif (t[i-k] == t[i]) and (ss[i-k] != f(t[i])):
a += g(f(t[i]))
ss[i] = f(t[i])
print(a)
|
[
"assignment.value.change",
"expression.operation.binary.change"
] | 625,540
| 625,539
|
u865119809
|
python
|
p02820
|
def f(x):
if x == "r":
return "p"
elif x == "s":
return "r"
else:
return "s"
def g(x):
if x == "r":
return r
elif x == "s":
return s
else:
return p
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = str(input())
ssssppr
m = n
a = 0
ss = [' '] ** m
if m <= k:
for i in range(m):
a += g(f(t[i]))
print(a)
else:
for i in range(k):
a += g(f(t[i]))
ss[i] = f(t[i])
for i in range(k,m):
if t[i-k] != t[i]:
a += g(f(t[i]))
ss[i] = f(t[i])
elif (t[i-k] == t[i]) and (ss[i-k] != f(t[i])):
a += g(f(t[i]))
ss[i] = f(t[i])
print(a)
|
def f(x):
if x == "r":
return "p"
elif x == "s":
return "r"
else:
return "s"
def g(x):
if x == "r":
return r
elif x == "s":
return s
else:
return p
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = str(input())
m = n
a = 0
ss = [' '] * m
if m <= k:
for i in range(m):
a += g(f(t[i]))
print(a)
else:
for i in range(k):
a += g(f(t[i]))
ss[i] = f(t[i])
for i in range(k,m):
if t[i-k] != t[i]:
a += g(f(t[i]))
ss[i] = f(t[i])
elif (t[i-k] == t[i]) and (ss[i-k] != f(t[i])):
a += g(f(t[i]))
ss[i] = f(t[i])
print(a)
|
[
"assignment.value.change",
"expression.operation.binary.change"
] | 625,541
| 625,539
|
u865119809
|
python
|
p02820
|
import sys
bbn=1000000007
#+++++
def main():
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
dd={'s':r, 'p':s, 'r':p}
point = lambda c : dd[c]
max_p=sum([point(c) for c in t])
same_k={'s':0, 'p':0, 'r':0}
tn=t
for i in range(k,n):
if tn[i]==tn[i-k] and tn[i]!='_':
same_k[tn[i]] += 1
tn[i] = '_'
down=0
for cc in ['r','s','p']:
down+=same_k[cc]*point(cc)
print(max_p-down)
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
if __name__ == "__main__":
if sys.platform =='ios':
sys.stdin=open('inputFile.txt')
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
|
import sys
bbn=1000000007
#+++++
def main():
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
dd={'s':r, 'p':s, 'r':p}
point = lambda c : dd[c]
max_p=sum([point(c) for c in t])
same_k={'s':0, 'p':0, 'r':0}
tn=list(t)
for i in range(k,n):
if tn[i]==tn[i-k] and tn[i]!='_':
same_k[tn[i]] += 1
tn[i] = '_'
down=0
#print(tn)
for cc in ['r','s','p']:
down+=same_k[cc]*point(cc)
print(max_p-down)
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
if __name__ == "__main__":
if sys.platform =='ios':
sys.stdin=open('inputFile.txt')
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
|
[
"call.add",
"call.arguments.change"
] | 625,568
| 625,569
|
u505830998
|
python
|
p02820
|
N,K = list(map(int, input().split()))
R,S,P = list(map(int, input().split()))
T = list(map(str, input()))
res = 0
def change(hand):
if hand == 'r':
return 'p'
if hand == 's':
return 'r'
if hand == 'p':
return 's'
memo = []
for (i,t) in enumerate(T):
if i >= K:
if memo[i-K] == change(t):
memo.append(t)
continue
if t == 'r':
res = res+P
memo.append(change(t))
if t == 's':
res = res+R
memo.append(change(t))
if t == 'p':
res = res+S
memo.append(change(t))
print(res)
|
N,K = list(map(int, input().split()))
R,S,P = list(map(int, input().split()))
T = list(map(str, input()))
res = 0
def change(hand):
if hand == 'r':
return 'p'
if hand == 's':
return 'r'
if hand == 'p':
return 's'
memo = []
for (i,t) in enumerate(T):
if i > K-1:
if memo[i-K] == change(t):
memo.append(' ')
continue
if t == 'r':
res = res+P
memo.append(change(t))
if t == 's':
res = res+R
memo.append(change(t))
if t == 'p':
res = res+S
memo.append(change(t))
print(res)
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one",
"call.arguments.change"
] | 625,576
| 625,577
|
u545221414
|
python
|
p02820
|
N,K = list(map(int, input().split()))
R,S,P = list(map(int, input().split()))
T = list(map(str, input()))
res = 0
def change(hand):
if hand == 'r':
return 'p'
if hand == 's':
return 'r'
if hand == 'p':
return 's'
memo = []
for (i,t) in enumerate(T):
if i > K:
if memo[i-K] == change(t):
memo.append(t)
continue
if t == 'r':
res = res+P
memo.append(change(t))
if t == 's':
res = res+R
memo.append(change(t))
if t == 'p':
res = res+S
memo.append(change(t))
print(res)
|
N,K = list(map(int, input().split()))
R,S,P = list(map(int, input().split()))
T = list(map(str, input()))
res = 0
def change(hand):
if hand == 'r':
return 'p'
if hand == 's':
return 'r'
if hand == 'p':
return 's'
memo = []
for (i,t) in enumerate(T):
if i > K-1:
if memo[i-K] == change(t):
memo.append(' ')
continue
if t == 'r':
res = res+P
memo.append(change(t))
if t == 's':
res = res+R
memo.append(change(t))
if t == 'p':
res = res+S
memo.append(change(t))
print(res)
|
[
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one",
"call.arguments.change"
] | 625,578
| 625,577
|
u545221414
|
python
|
p02820
|
N,K = list(map(int, input().split()))
R,S,P = list(map(int, input().split()))
T = list(map(str, input()))
res = 0
def change(hand):
if hand == 'r':
return 'p'
if hand == 's':
return 'r'
if hand == 'p':
return 's'
memo = []
for (i,t) in enumerate(T):
if i > K-1:
if memo[i-K] == change(t):
memo.append(t)
continue
if t == 'r':
res = res+P
memo.append(change(t))
if t == 's':
res = res+R
memo.append(change(t))
if t == 'p':
res = res+S
memo.append(change(t))
print(res)
|
N,K = list(map(int, input().split()))
R,S,P = list(map(int, input().split()))
T = list(map(str, input()))
res = 0
def change(hand):
if hand == 'r':
return 'p'
if hand == 's':
return 'r'
if hand == 'p':
return 's'
memo = []
for (i,t) in enumerate(T):
if i > K-1:
if memo[i-K] == change(t):
memo.append(' ')
continue
if t == 'r':
res = res+P
memo.append(change(t))
if t == 's':
res = res+R
memo.append(change(t))
if t == 'p':
res = res+S
memo.append(change(t))
print(res)
|
[
"call.arguments.change"
] | 625,579
| 625,577
|
u545221414
|
python
|
p02820
|
N,K = list(map(int, input().split()))
R,S,P = list(map(int, input().split()))
T = list(map(str, input()))
res = 0
def change(hand):
if hand == 'r':
return 'p'
if hand == 's':
return 'r'
if hand == 'p':
return 's'
memo = []
for (i,t) in enumerate(T):
if i > K-1:
if memo[i-K] == change(t):
memo.append(t)
continue
if t == 'r':
res = res+P
memo.append(change(t))
if t == 's':
res = res+R
memo.append(change(t))
if t == 'p':
res = res+S
memo.append(change(t))
print(res)
|
N,K = list(map(int, input().split()))
R,S,P = list(map(int, input().split()))
T = list(map(str, input()))
res = 0
def change(hand):
if hand == 'r':
return 'p'
if hand == 's':
return 'r'
if hand == 'p':
return 's'
memo = []
for (i,t) in enumerate(T):
if i > K-1:
if memo[i-K] == change(t):
memo.append(' ')
continue
if t == 'r':
res = res+P
memo.append(change(t))
if t == 's':
res = res+R
memo.append(change(t))
if t == 'p':
res = res+S
memo.append(change(t))
print(res)
|
[
"call.arguments.change"
] | 625,580
| 625,577
|
u545221414
|
python
|
p02820
|
N,K = list(map(int, input().split()))
R,S,P = list(map(int, input().split()))
T = list(map(str, input()))
res = 0
def change(hand):
if hand == 'r':
return 'p'
if hand == 's':
return 'r'
if hand == 'p':
return 's'
memo = []
for (i,t) in enumerate(T):
if i > K-1:
if memo[i-K] == change(t):
memo.append(t)
continue
if t == 'r':
res = res+P
memo.append(change(t))
if t == 's':
res = res+R
memo.append(change(t))
if t == 'p':
res = res+S
memo.append(change(t))
print(res)
|
N,K = list(map(int, input().split()))
R,S,P = list(map(int, input().split()))
T = list(map(str, input()))
res = 0
def change(hand):
if hand == 'r':
return 'p'
if hand == 's':
return 'r'
if hand == 'p':
return 's'
memo = []
for (i,t) in enumerate(T):
if i > K-1:
if memo[i-K] == change(t):
memo.append(' ')
continue
if t == 'r':
res = res+P
memo.append(change(t))
if t == 's':
res = res+R
memo.append(change(t))
if t == 'p':
res = res+S
memo.append(change(t))
print(res)
|
[
"call.arguments.change"
] | 625,581
| 625,577
|
u545221414
|
python
|
p02820
|
n,k = map(int, input().split())
r,s,p = map(int, input().split())
S = input()
ans = 0
for i in range(k):
Ssep = S[i::k]
flg = False
for j in range(len(Ssep)):
if j >= 1 and Ssep[j] == Ssep[j-1] and not flg:
flg = True
continue
if Ssep[j] == "r":
ans += p
if Ssep[j] == "s":
ans += r
if Ssep[j] == "p":
ans += s
flg = False
print(Ssep,ans)
print(ans)
|
n,k = map(int, input().split())
r,s,p = map(int, input().split())
S = input()
ans = 0
for i in range(k):
Ssep = S[i::k]
flg = False
for j in range(len(Ssep)):
if j >= 1 and Ssep[j] == Ssep[j-1] and not flg:
flg = True
continue
if Ssep[j] == "r":
ans += p
if Ssep[j] == "s":
ans += r
if Ssep[j] == "p":
ans += s
flg = False
print(ans)
|
[
"call.remove"
] | 625,586
| 625,587
|
u905582793
|
python
|
p02820
|
N, K = map(int, input().split(" "))
R, S, P = map(int, input().split(" "))
T = input()
score_by_hand = {"r": P, "s": R, "p": S}
result = 0
score = 0
for k in range(K):
column = T[k::K]
print(column)
before = None
for hand in column:
if hand == before:
before = None
else:
score += score_by_hand[hand]
before = hand
print(score)
|
N, K = map(int, input().split(" "))
R, S, P = map(int, input().split(" "))
T = input()
score_by_hand = {"r": P, "s": R, "p": S}
result = 0
score = 0
for k in range(K):
column = T[k::K]
before = None
for hand in column:
if hand == before:
before = None
else:
score += score_by_hand[hand]
before = hand
print(score)
|
[
"call.remove"
] | 625,593
| 625,594
|
u721569287
|
python
|
p02820
|
n,k = map(int, input().split())
r, s, p = map(int, input().split())
scores = {"r":p,"s":r,"p":s}
T = input()
import numpy as np
subT = [""] * k
for i in range(n):
ind = i % k
subT[ind] += T[i]
ans = 0
for S in subT:
cnt = 0
prev = "0"
for i, s in enumerate(S):
if i == 0:
ans += scores[s]
elif prev == s:
cnt += 1
if cnt == 2:
ans += scores[s]
cnt = 0
else:
ans += scores[s]
prev = s
print(ans)
|
n,k = map(int, input().split())
r, s, p = map(int, input().split())
scores = {"r":p,"s":r,"p":s}
T = input()
import numpy as np
subT = [""] * k
for i in range(n):
ind = i % k
subT[ind] += T[i]
ans = 0
for S in subT:
cnt = 0
prev = "0"
for i, s in enumerate(S):
if i == 0:
ans += scores[s]
elif prev == s:
cnt += 1
if cnt == 2:
ans += scores[s]
cnt = 0
else:
ans += scores[s]
cnt = 0
prev = s
print(ans)
|
[
"assignment.add"
] | 625,597
| 625,598
|
u545368057
|
python
|
p02820
|
from collections import deque
n,k = map(int, input().split())
r,s,p = map(int, input().split())
t = deque(list(s for s in input()))
best_hand = {'r': 'p', 's': 'r', 'p': 's'}
ban = []
cand = ''
while t:
cpu = t.popleft()
if len(ban) < k:
add_hand = best_hand[cpu]
else:
ban_hand = ban.pop(0)
if best_hand[cpu] == ban_hand:
add_hand = 'e'
else:
add_hand = best_hand[cpu]
ban.append(add_hand)
cand += add_hand
print(p*cand.count('p') + s*cand.count('s') + r*cand.count('r'))
print(cand)
|
from collections import deque
n,k = map(int, input().split())
r,s,p = map(int, input().split())
t = deque(list(s for s in input()))
best_hand = {'r': 'p', 's': 'r', 'p': 's'}
ban = []
cand = ''
while t:
cpu = t.popleft()
if len(ban) < k:
add_hand = best_hand[cpu]
else:
ban_hand = ban.pop(0)
if best_hand[cpu] == ban_hand:
add_hand = 'e'
else:
add_hand = best_hand[cpu]
ban.append(add_hand)
cand += add_hand
print(p*cand.count('p') + s*cand.count('s') + r*cand.count('r'))
|
[
"call.remove"
] | 625,599
| 625,600
|
u089376182
|
python
|
p02820
|
from collections import deque
n,k = map(int, input().split())
r,s,p = map(int, input().split())
t = deque(list(s for s in input()))
best_hand = {'r': 'p', 's': 'r', 'p': 's'}
ban = []
cand = ''
while t:
cpu = t.popleft()
if len(ban) < 2:
add_hand = best_hand[cpu]
else:
ban_hand = ban.pop(0)
if best_hand[cpu] == ban_hand:
add_hand = 'e'
else:
add_hand = best_hand[cpu]
ban.append(add_hand)
cand += add_hand
print(p*cand.count('p') + s*cand.count('s') + r*cand.count('r'))
|
from collections import deque
n,k = map(int, input().split())
r,s,p = map(int, input().split())
t = deque(list(s for s in input()))
best_hand = {'r': 'p', 's': 'r', 'p': 's'}
ban = []
cand = ''
while t:
cpu = t.popleft()
if len(ban) < k:
add_hand = best_hand[cpu]
else:
ban_hand = ban.pop(0)
if best_hand[cpu] == ban_hand:
add_hand = 'e'
else:
add_hand = best_hand[cpu]
ban.append(add_hand)
cand += add_hand
print(p*cand.count('p') + s*cand.count('s') + r*cand.count('r'))
|
[
"identifier.replace.add",
"literal.replace.remove",
"control_flow.branch.if.condition.change"
] | 625,601
| 625,600
|
u089376182
|
python
|
p02820
|
num = input().split(' ')
point = input().split(' ')
point_int = [int(point[i]) for i in range(3)]
data = input()
count = 1
result = 0
judge = [0 for i in range(int(num[0]))]
for i in range(int(num[0])):
if(data[i] == 'r'):
if(i - int(num[1]) >= 0):
if(data[i - int(num[1])] == 'r'):
if(judge[i - int(num[1])] == 0):
result += point_int[2]
judge[i] = 1
else:
pass
else:
result += point_int[2]
judge[i] = 1
else:
result += point_int[2]
judge[i] = 1
elif(data[i] == 's'):
if(i - int(num[1]) >= 0):
if(data[i - int(num[1])] == 's'):
if(judge[i - int(num[1])] == 0):
result += point_int[0]
judge[i] = 1
else:
pass
else:
result += point_int[0]
judge[i] = 1
else:
result += point_int[0]
judge[i] = 1
else:
if(i - int(num[1]) >= 0):
if(data[i - int(num[1])] == 'p'):
if(judge[i - int(num[1])] == 0):
result += point_int[1]
judge[i] = 1
else:
pass
else:
result += point_int[1]
judge[i] = 1
else:
result += point_int[1]
judge[i] = 1
print(result)
print(result)
|
num = input().split(' ')
point = input().split(' ')
point_int = [int(point[i]) for i in range(3)]
data = input()
count = 1
result = 0
judge = [0 for i in range(int(num[0]))]
for i in range(int(num[0])):
if(data[i] == 'r'):
if(i - int(num[1]) >= 0):
if(data[i - int(num[1])] == 'r'):
if(judge[i - int(num[1])] == 0):
result += point_int[2]
judge[i] = 1
else:
pass
else:
result += point_int[2]
judge[i] = 1
else:
result += point_int[2]
judge[i] = 1
elif(data[i] == 's'):
if(i - int(num[1]) >= 0):
if(data[i - int(num[1])] == 's'):
if(judge[i - int(num[1])] == 0):
result += point_int[0]
judge[i] = 1
else:
pass
else:
result += point_int[0]
judge[i] = 1
else:
result += point_int[0]
judge[i] = 1
else:
if(i - int(num[1]) >= 0):
if(data[i - int(num[1])] == 'p'):
if(judge[i - int(num[1])] == 0):
result += point_int[1]
judge[i] = 1
else:
pass
else:
result += point_int[1]
judge[i] = 1
else:
result += point_int[1]
judge[i] = 1
print(result)
|
[
"call.remove"
] | 625,608
| 625,609
|
u378234362
|
python
|
p02820
|
line1 = input().split(' ')
line2 = input().split(' ')
N = int(line1[0])
K = int(line1[1])
R = int(line2[0])
S = int(line2[1])
P = int(line2[2])
T = input()
score = 0
mem = list(range(K))
for i in range(N):
index = i % K
if (mem[index] != T[i:i+1]):
if (T[i:i+1] == 'r'):
score = score + R
elif (T[i:i+1] == 's'):
score = score + S
elif (T[i:i+1] == 'p'):
score = score + P
mem[index] = T[i:i+1]
else:
mem[index] = 0
print(score)
|
line1 = input().split(' ')
line2 = input().split(' ')
N = int(line1[0])
K = int(line1[1])
R = int(line2[0])
S = int(line2[1])
P = int(line2[2])
T = input()
score = 0
mem = list(range(K))
for i in range(N):
index = i % K
if (mem[index] != T[i:i+1]):
if (T[i:i+1] == 'r'):
score = score + P
elif (T[i:i+1] == 's'):
score = score + R
elif (T[i:i+1] == 'p'):
score = score + S
mem[index] = T[i:i+1]
else:
mem[index] = 0
print(score)
|
[
"assignment.value.change",
"identifier.change",
"expression.operation.binary.change"
] | 625,610
| 625,611
|
u250639998
|
python
|
p02820
|
# K回前と現在の問いが同じだったら0点
str1 = input().split(" ")
str2 = input().split(" ")
t = list(input())
n = int(str1[0])
k = int(str1[1])
r = int(str2[0])
s = int(str2[1])
p = int(str2[2])
result = 0
hoge = 0
for i in range(0,n):
if i < k:
continue
j = i-k
if t[i] == t[j]:
t[i] = "_"
print(t)
pres = p * t.count("r")
rres = r * t.count("s")
sres = s * t.count("p")
print(pres + rres + sres)
|
# K回前と現在の問いが同じだったら0点
str1 = input().split(" ")
str2 = input().split(" ")
t = list(input())
n = int(str1[0])
k = int(str1[1])
r = int(str2[0])
s = int(str2[1])
p = int(str2[2])
result = 0
hoge = 0
for i in range(0,n):
if i < k:
continue
j = i-k
if t[i] == t[j]:
t[i] = "_"
pres = p * t.count("r")
rres = r * t.count("s")
sres = s * t.count("p")
print(pres + rres + sres)
|
[
"call.remove"
] | 625,624
| 625,625
|
u990148524
|
python
|
p02820
|
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
ans = 0
d = {'p': S, 's': R, 'r': P}
flag = [0] * K
for n in range(N):
q = n % K
ans += d.get(T[n])
if n >= K and T[n] == T[n - K] and n < N - K:
flag[q] += 1
elif (flag[q] != 0 and T[n] != T[n - K]) or n >= N - K:
if n >= N - K and T[n] == T[n - K]:
flag[q] += 1
ans -= d.get(T[n - K]) * ((flag[q] + 1) // 2)
flag[q] = 0
print(ans)
|
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
ans = 0
d = {'p': S, 's': R, 'r': P}
flag = [0] * K
for n in range(N):
q = n % K
ans += d.get(T[n])
if n >= K:
if T[n] == T[n - K] and n < N - K:
flag[q] += 1
elif (flag[q] != 0 and T[n] != T[n - K]) or n >= N - K:
if n >= N - K and T[n] == T[n - K]:
flag[q] += 1
ans -= d.get(T[n - K]) * ((flag[q] + 1) // 2)
flag[q] = 0
print(ans)
|
[
"control_flow.branch.if.condition.change"
] | 625,628
| 625,629
|
u908763441
|
python
|
p02820
|
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
t1 = t.replace("r","P")
t2 = t1.replace("s","R")
t3 = t2.replace("p","S")
# print(t3)
T = list(t3)
# print(T)
minus = 0
ls = ["R","S","P"]
for i in range(k,n):
if i < n-k:
tmp = T[i]
before = T[i-k]
after = T[i+k]
if tmp == before:
ls.remove(tmp)
if tmp == after:
T[i] = ls[0]
else:
ls.remove(after)
T[i] = ls[0]
ls.append(after)
ls.append(tmp)
# if tmp == "R":
# minus += r
# elif tmp == "S":
# minus += s
# else:
# minus += p
if T[i] == "R":
minus += r
elif T[i] == "S":
minus += s
elif T[i] == "P":
minus += p
else:
pass
elif i >= n-k:
tmp = T[i]
before = T[i-k]
# after = T[i+k]
if tmp == before:
ls.remove(tmp)
# if tmp == after:
# T[i] = ls[0]
# else:
# ls.remove(after)
# T[i] = ls[0]
# ls.append(after)
tmp = ls[0]
ls.append(tmp)
# if tmp == "R":
# minus += r
# elif tmp == "S":
# minus += s
# else:
# minus += p
if T[i] == "R":
minus += r
elif T[i] == "S":
minus += s
elif T[i] == "P":
minus += p
else:
pass
# print(T)
p1 = r * T.count("R")
# print(p1)
p2 = s * T.count("S")
# print(p2)
p3 = p * T.count("P")
# print(p3)
# print(minus)
print(p1+p2+p3-minus)
|
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
t1 = t.replace("r","P")
t2 = t1.replace("s","R")
t3 = t2.replace("p","S")
# print(t3)
T = list(t3)
# print(T)
minus = 0
ls = ["R","S","P"]
for i in range(k,n):
if i < n-k:
tmp = T[i]
before = T[i-k]
after = T[i+k]
if tmp == before:
ls.remove(tmp)
if tmp == after:
T[i] = ls[0]
else:
ls.remove(after)
T[i] = ls[0]
ls.append(after)
ls.append(tmp)
if T[i] == "R":
minus += r
elif T[i] == "S":
minus += s
elif T[i] == "P":
minus += p
else:
pass
elif i >= n-k:
tmp = T[i]
before = T[i-k]
# after = T[i+k]
if tmp == before:
ls.remove(tmp)
T[i] = ls[0]
ls.append(tmp)
if T[i] == "R":
minus += r
elif T[i] == "S":
minus += s
elif T[i] == "P":
minus += p
else:
pass
# print(T)
p1 = r * T.count("R")
# print(p1)
p2 = s * T.count("S")
# print(p2)
p3 = p * T.count("P")
# print(p3)
# print(minus)
print(p1+p2+p3-minus)
|
[
"assignment.variable.change"
] | 625,637
| 625,638
|
u255673886
|
python
|
p02820
|
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
score = np.array([0, R, S, P], dtype=int)
M = (1 + (N-1)//K)
addi = M * K - N
t = np.array([{'n':0, 's':1, 'p':2, 'r':3}[i] for i in T+'n'*addi], dtype=int)
t = t.reshape(M,K).T
for i in range(K):
for j in range(M):
if j!=0 and t[i,j] == t[i,j-1]:
t[i,j] = 0
print(score[t].sum())
|
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
import numpy as np
score = np.array([0, R, S, P], dtype=int)
M = (1 + (N-1)//K)
addi = M * K - N
t = np.array([{'n':0, 's':1, 'p':2, 'r':3}[i] for i in T+'n'*addi], dtype=int)
t = t.reshape(M,K).T
for i in range(K):
for j in range(M):
if j!=0 and t[i,j] == t[i,j-1]:
t[i,j] = 0
print(score[t].sum())
|
[] | 625,674
| 625,675
|
u663093503
|
python
|
p02820
|
N,K = map(int,input().split())
R,S,P = map(int,input().split())
dicta = {'r':P,'s':R,'p':S}
T = input()
count = 0
for i in range(N):
if i >= K-1:
if T[i-K] == T[i]:
T = T[:i] + 'z' + T[i+1:]
else:
count += dicta[T[i]]
else:
count += dicta[T[i]]
print(count)
|
N,K = map(int,input().split())
R,S,P = map(int,input().split())
dicta = {'r':P,'s':R,'p':S}
T = input()
count = 0
for i in range(N):
if i >= K:
if T[i-K] == T[i]:
T = T[:i] + 'z' + T[i+1:]
else:
count += dicta[T[i]]
else:
count += dicta[T[i]]
print(count)
|
[
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 625,676
| 625,677
|
u540761833
|
python
|
p02820
|
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
ans = 0
buf = ""
for i in range(N):
t = T[i]
if t == "r":
if i >= K:
if buf[i - K] == "p":
buf = buf + " "
continue
ans += P
buf += buf + "p"
elif t == "p":
if i >= K:
if buf[i - K] == "s":
buf = buf + " "
continue
ans += S
buf += buf + "s"
elif t == "s":
if i >= K:
if buf[i - K] == "r":
buf = buf + " "
continue
ans += R
buf += buf + "r"
print(ans)
|
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
ans = 0
buf = ""
for i in range(N):
t = T[i]
if t == "r":
if i >= K:
if buf[i - K] == "p":
buf = buf + " "
continue
ans += P
buf = buf + "p"
elif t == "p":
if i >= K:
if buf[i - K] == "s":
buf = buf + " "
continue
ans += S
buf = buf + "s"
elif t == "s":
if i >= K:
if buf[i - K] == "r":
buf = buf + " "
continue
ans += R
buf = buf + "r"
print(ans)
|
[
"assignment.value.change"
] | 625,694
| 625,695
|
u168333670
|
python
|
p02821
|
#!python3
from itertools import accumulate
def my_bisect(a, x, key, lo=0, hi=None, side="left"):
if hi is None:
hi = len(a)
lov = key(a[lo])
hiv = key(a[hi])
if side == "left":
while lo < hi:
mid = (lo + hi) // 2
miv = key(a[mid])
if miv < val: lo, lov = mid+1, miv
else: hi, hiv = mid, miv
else:
while lo < hi:
mid = (lo + hi) // 2
miv = key(a[mid])
if val < miv: hi, hiv = mid, miv
else: lo, lov = mid+1, miv
return lo
from bisect import bisect_right
def resolve():
N, M = map(int, input().rstrip().split())
a = list(map(int, input().rstrip().split()))
a.sort(reverse=True)
b = list(accumulate(a))
c = [-i for i in a]
def count_shake(z):
n = 0
for i, x in enumerate(a):
y = x - z
#j = my_bisect(a, y, lambda x: -x, lo=i, side="right")
j = bisect_right(c, y, i)
if i == j:
break
n += 2 * (j - i) - 1
return n
lo = a[-1] * 2
hi = a[0] * 2
while True:
mid = (lo + hi) // 2
x = count_shake(mid)
if hi - lo <= 2:
break
if x < M: hi = mid
else: lo = mid
s = 0
d = [-1] * N
m = x
for i, x in enumerate(a):
y = x - mid
j = bisect_right(c, x - mid)
if j == 0: break
d[i] = j-1
s += b[j-1] + x * j
print(s - mid * (m-M))
if __name__ == "__main__":
resolve()
|
#!python3
from itertools import accumulate
def my_bisect(a, x, key, lo=0, hi=None, side="left"):
if hi is None:
hi = len(a)
lov = key(a[lo])
hiv = key(a[hi])
if side == "left":
while lo < hi:
mid = (lo + hi) // 2
miv = key(a[mid])
if miv < val: lo, lov = mid+1, miv
else: hi, hiv = mid, miv
else:
while lo < hi:
mid = (lo + hi) // 2
miv = key(a[mid])
if val < miv: hi, hiv = mid, miv
else: lo, lov = mid+1, miv
return lo
from bisect import bisect_right
def resolve():
N, M = map(int, input().rstrip().split())
a = list(map(int, input().rstrip().split()))
a.sort(reverse=True)
b = list(accumulate(a))
c = [-i for i in a]
def count_shake(z):
n = 0
for i, x in enumerate(a):
y = x - z
#j = my_bisect(a, y, lambda x: -x, lo=i, side="right")
j = bisect_right(c, y, i)
if i == j:
break
n += 2 * (j - i) - 1
return n
lo = a[-1] * 2
hi = a[0] * 2
while True:
mid = (lo + hi) // 2
x = count_shake(mid)
if hi - lo <= 1:
break
if x < M: hi = mid
else: lo = mid
s = 0
d = [-1] * N
m = x
for i, x in enumerate(a):
y = x - mid
j = bisect_right(c, x - mid)
if j == 0: break
d[i] = j-1
s += b[j-1] + x * j
print(s - mid * (m-M))
if __name__ == "__main__":
resolve()
|
[
"literal.number.integer.change",
"control_flow.branch.if.condition.change"
] | 625,725
| 625,726
|
u348805958
|
python
|
p02821
|
from itertools import accumulate
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
d = [0] * (A[0] * 2 + 1)
for i in range(N):
d[A[i]] += 1
d = list(accumulate(d[::-1]))[::-1]
S = list(accumulate([0] + A))
left = 0
right = A[0] * 2 + 1
while right - left > 1:
mid = (left + right) // 2
m = 0
for i in range(N):
m += d[max(1, mid - A[i])]
if m >= M:
left = mid
else:
right = mid
ans = 0
m = 0
for i in range(N):
t = min(d[max(0, left - A[i])], M - m)
ans += S[t] + A[i] * t
m += t
ans += left * (M - m)
print(ans)
|
from itertools import accumulate
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
d = [0] * (A[0] * 2 + 1)
for i in range(N):
d[A[i]] += 1
d = list(accumulate(d[::-1]))[::-1]
S = list(accumulate([0] + A))
left = 0
right = A[0] * 2 + 1
while right - left > 1:
mid = (left + right) // 2
m = 0
for i in range(N):
m += d[max(0, mid - A[i])]
if m >= M:
left = mid
else:
right = mid
ans = 0
m = 0
for i in range(N):
t = min(d[max(0, right - A[i])], M - m)
ans += S[t] + A[i] * t
m += t
ans += left * (M - m)
print(ans)
|
[
"literal.number.integer.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"assignment.value.change",
"identifier.change",
"expression.operation.binary.change"
] | 625,753
| 625,754
|
u374531474
|
python
|
p02821
|
from itertools import accumulate
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
d = [0] * (A[0] * 2 + 1)
for i in range(N):
d[A[i]] += 1
d = list(accumulate(d[::-1]))[::-1]
S = list(accumulate([0] + A))
left = 0
right = A[0] * 2 + 1
while right - left > 1:
mid = (left + right) // 2
m = 0
for i in range(N):
m += d[max(0, mid - A[i])]
if m >= M:
left = mid
else:
right = mid
ans = 0
m = 0
for i in range(N):
t = max(0, min(d[max(0, left - A[i])], M - m))
ans += S[t] + A[i] * t
m += t
ans += left * (M - m)
print(ans)
|
from itertools import accumulate
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
d = [0] * (A[0] * 2 + 1)
for i in range(N):
d[A[i]] += 1
d = list(accumulate(d[::-1]))[::-1]
S = list(accumulate([0] + A))
left = 0
right = A[0] * 2 + 1
while right - left > 1:
mid = (left + right) // 2
m = 0
for i in range(N):
m += d[max(0, mid - A[i])]
if m >= M:
left = mid
else:
right = mid
ans = 0
m = 0
for i in range(N):
t = min(d[max(0, right - A[i])], M - m)
ans += S[t] + A[i] * t
m += t
ans += left * (M - m)
print(ans)
|
[
"call.remove",
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 625,755
| 625,754
|
u374531474
|
python
|
p02821
|
from itertools import accumulate
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
d = [0] * (A[0] * 2 + 1)
for i in range(N):
d[A[i]] += 1
d = list(accumulate(d[::-1]))[::-1]
S = list(accumulate([0] + A))
left = 0
right = A[0] * 2 + 1
while right - left > 1:
mid = (left + right) // 2
m = 0
for i in range(N):
m += d[max(0, mid - A[i])]
if m >= M:
left = mid
else:
right = mid
ans = 0
m = 0
for i in range(N):
t = min(d[max(0, left - A[i])], M - m)
ans += S[t] + A[i] * t
m += t
ans += left * (M - m)
print(ans)
|
from itertools import accumulate
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
d = [0] * (A[0] * 2 + 1)
for i in range(N):
d[A[i]] += 1
d = list(accumulate(d[::-1]))[::-1]
S = list(accumulate([0] + A))
left = 0
right = A[0] * 2 + 1
while right - left > 1:
mid = (left + right) // 2
m = 0
for i in range(N):
m += d[max(0, mid - A[i])]
if m >= M:
left = mid
else:
right = mid
ans = 0
m = 0
for i in range(N):
t = min(d[max(0, right - A[i])], M - m)
ans += S[t] + A[i] * t
m += t
ans += left * (M - m)
print(ans)
|
[
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 625,756
| 625,754
|
u374531474
|
python
|
p02821
|
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 = a[0] * 2
inc_v = a[-1] * 2 + 1
while - cor_v + inc_v > 1:
bin_v = (cor_v + inc_v) // 2
cost = 0
#条件を満たすcostを全検索
for i in range(n-1, -1, -1):
cost += n - bisect.bisect_left(a, bin_v - a[i])
#costが制約を満たすか
if cost >= m:
cor_v = bin_v
else:
inc_v = bin_v
acm = list(itertools.accumulate([0] + a))
print(acm)
t = 0
c = 0
for i in range(n):
p = bisect.bisect_left(a, cor_v - a[i])
t += acm[-1] - acm[p] + a[i] * (n - p)
c += n - p
print(t - (c - m) * cor_v)
if __name__ == '__main__':
solve()
|
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 = a[0] * 2
inc_v = a[-1] * 2 + 1
while - cor_v + inc_v > 1:
bin_v = (cor_v + inc_v) // 2
cost = 0
#条件を満たすcostを全検索
for i in range(n-1, -1, -1):
cost += n - bisect.bisect_left(a, bin_v - a[i])
#costが制約を満たすか
if cost >= m:
cor_v = bin_v
else:
inc_v = bin_v
acm = list(itertools.accumulate([0] + a))
t = 0
c = 0
for i in range(n):
p = bisect.bisect_left(a, cor_v - a[i])
t += acm[-1] - acm[p] + a[i] * (n - p)
c += n - p
print(t - (c - m) * cor_v)
if __name__ == '__main__':
solve()
|
[
"call.remove"
] | 625,765
| 625,766
|
u753803401
|
python
|
p02821
|
def run(N, M, A):
A = sorted(A, reverse=True)
right = A[0] * 2
left = 0
while left < right:
X = (left + right) // 2
# 左手の相手がaで、満足度がX以上となる組合せの数
cnt = 0
for a in A:
cnt += search(A, X - a)
if cnt >= M:
res = X
left = X + 1
else:
right = X - 1
X = res
# Xが決まったので、累積和で組合せの数分の値を求める
sum_A = [0]
for a in sorted(A):
sum_A.append(sum_A[-1] + a)
sum_cnt = 0
ans = 0
for a in A:
cnt = search(A, X - a)
sum_cnt += cnt
if cnt > 0:
ans += cnt * a + sum_A[-1] - sum_A[-cnt-1]
if sum_cnt > M:
ans -= X * (sum_cnt - M)
return ans
def search(A, X):
'''
AのリストからX以上となる数値がいくつか探す
Aはソート済み(降順)
二分探索で実装O(logN)
leftとrightはチェック未
middleはループ終了後チェック済み
'''
left = 0
right = len(A) - 1
res = 0
while left <= right:
middle = (left + right) // 2
if A[middle] >= X:
res = middle + 1
left = middle + 1
else:
right = middle - 1
return res
def main():
N, M = map(int, input().split())
A = list(map(int, input().split()))
print(run(N, M, A))
if __name__ == '__main__':
main()
|
def run(N, M, A):
A = sorted(A, reverse=True)
right = A[0] * 2
left = 0
while left <= right:
X = (left + right) // 2
# 左手の相手がaで、満足度がX以上となる組合せの数
cnt = 0
for a in A:
cnt += search(A, X - a)
if cnt >= M:
res = X
left = X + 1
else:
right = X - 1
X = res
# Xが決まったので、累積和で組合せの数分の値を求める
sum_A = [0]
for a in sorted(A):
sum_A.append(sum_A[-1] + a)
sum_cnt = 0
ans = 0
for a in A:
cnt = search(A, X - a)
sum_cnt += cnt
if cnt > 0:
ans += cnt * a + sum_A[-1] - sum_A[-cnt-1]
if sum_cnt > M:
ans -= X * (sum_cnt - M)
return ans
def search(A, X):
'''
AのリストからX以上となる数値がいくつか探す
Aはソート済み(降順)
二分探索で実装O(logN)
leftとrightはチェック未
middleはループ終了後チェック済み
'''
left = 0
right = len(A) - 1
res = 0
while left <= right:
middle = (left + right) // 2
if A[middle] >= X:
res = middle + 1
left = middle + 1
else:
right = middle - 1
return res
def main():
N, M = map(int, input().split())
A = list(map(int, input().split()))
print(run(N, M, A))
if __name__ == '__main__':
main()
|
[
"expression.operator.compare.change",
"control_flow.loop.condition.change"
] | 625,907
| 625,908
|
u633105820
|
python
|
p02821
|
N, M = map(int, input().split())
a = [10**18] + sorted(map(int, input().split()), reverse=True)
def solve(x):
count = 0
j = N
for i in range(1, N+1):
while a[i] + a[j] < x:
j -= 1
count += j
return count
left, right = 0, 10**18
while left < right - 1:
mid = (left + right) // 2
if solve(mid) >= M:
left = mid
else:
right = mid
acc = a
acc[0] = 0
for i in range(N):
acc[i+1] += acc[i]
ans = 0
j = N
for i in range(1, N+1):
while a[i] + a[j] < left+1:
j -= 1
ans += a[i]*j + acc[j]
M -= j
if M:
ans += left * M
print(ans)
|
N, M = map(int, input().split())
a = [10**18] + sorted(map(int, input().split()), reverse=True)
def solve(x):
count = 0
j = N
for i in range(1, N+1):
while a[i] + a[j] < x:
j -= 1
count += j
return count
left, right = 0, 10**18
while left < right - 1:
mid = (left + right) // 2
if solve(mid) >= M:
left = mid
else:
right = mid
acc = a[:]
acc[0] = 0
for i in range(N):
acc[i+1] += acc[i]
ans = 0
j = N
for i in range(1, N+1):
while a[i] + a[j] < left+1:
j -= 1
ans += a[i]*j + acc[j]
M -= j
if M:
ans += left * M
print(ans)
|
[] | 625,936
| 625,937
|
u079022693
|
python
|
p02821
|
N,M = map(int,input().split())
*A, = map(int,input().split())
A.sort(reverse=True)
def count(i,B):
B = B - A[i]
l = -1
r = N
while l+1<r:
j = (l+r)//2
if A[j] >= B:
l = j
else:
r = j
return r
l = 0
r = 10**5*3
while l+1<r:
i = (l+r)//2
S = 0
for j in range(N):
S += count(j,i)
if S==M:
l = i
break
elif S>M:
l = i
else:
r = i
ans = 0
tmp = 0
SA = [0]*(N+1)
for j in range(N):
SA[j+1] = SA[j] + A[j]
for j in range(N):
c = count(j,i)
ans += A[j]*c + SA[c]
tmp += c
if M>tmp:
n = 0
for j in range(N):
c = count(j,i)
if c==N: continue
n = max(n,A[j] + A[c])
ans += n*(M-tmp)
print(ans)
|
N,M = map(int,input().split())
*A, = map(int,input().split())
A.sort(reverse=True)
def count(i,B):
B = B - A[i]
l = -1
r = N
while l+1<r:
j = (l+r)//2
if A[j] >= B:
l = j
else:
r = j
return r
l = 0
r = 10**5*3
while l+1<r:
i = (l+r)//2
S = 0
for j in range(N):
S += count(j,i)
if S==M:
r = i
break
elif S>M:
l = i
else:
r = i
ans = 0
tmp = 0
SA = [0]*(N+1)
for j in range(N):
SA[j+1] = SA[j] + A[j]
for j in range(N):
c = count(j,r)
ans += A[j]*c + SA[c]
tmp += c
if M>tmp:
n = 0
for j in range(N):
c = count(j,r)
if c==N: continue
n = max(n,A[j] + A[c])
ans += n*(M-tmp)
print(ans)
|
[
"assignment.variable.change",
"identifier.change",
"assignment.value.change",
"call.arguments.change"
] | 625,994
| 625,995
|
u391731808
|
python
|
p02821
|
n,m=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr,reverse=True)
acum=[arr[0]]
for i in range(1,n):
acum.append(acum[-1]+arr[i])
print(acum)
l=0
r=2*10**5+1
while r-l!=1:
mid=(l+r)//2
tmp=0
cnt=0
pos=n-1
for i in range(n):
while pos!=-1:
if arr[i]+arr[pos]>=mid:
cnt+=pos+1
tmp+=arr[i]*(pos+1)+acum[pos]
break
else:
pos-=1
if pos==-1:
break
if cnt<=m:
r=mid
else:
l=mid
tmp+=(m-cnt)*l
print(tmp)
|
n,m=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr,reverse=True)
acum=[arr[0]]
for i in range(1,n):
acum.append(acum[-1]+arr[i])
l=0
r=2*10**5+1
while r-l!=1:
mid=(l+r)//2
tmp=0
cnt=0
pos=n-1
for i in range(n):
while pos!=-1:
if arr[i]+arr[pos]>=mid:
cnt+=pos+1
tmp+=arr[i]*(pos+1)+acum[pos]
break
else:
pos-=1
if pos==-1:
break
if cnt<=m:
r=mid
else:
l=mid
tmp+=(m-cnt)*l
print(tmp)
|
[
"call.remove"
] | 626,041
| 626,042
|
u163320134
|
python
|
p02821
|
import sys
input = sys.stdin.readline
import bisect
from itertools import accumulate
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
A.sort()
left = -1
right = 1 + 2 * 10 ** 5
def shake(x):
cnt = 0
for i in A:
cnt += N - bisect.bisect_left(A, x - i)
if cnt >= M:
return 1
else:
return 0
while True:
mid = (left + right) // 2
if shake(mid):
if not shake(mid + 1):
X = mid
break
else:
left = mid
else:
if shake(mid - 1):
X = mid - 1
break
else:
right = mid
happy = 0
cumsum_A = [0] + list(accumulate(A))
for j in A:
idx = bisect.bisect_right(A, X - j)
cnt = N - idx
happy += cumsum_A[-1] - cumsum_A[idx - 1] + cnt * j
M -= cnt
happy += M * X
print(happy)
|
import sys
input = sys.stdin.readline
import bisect
from itertools import accumulate
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
A.sort()
left = -1
right = 1 + 2 * 10 ** 5
def shake(x):
cnt = 0
for i in A:
cnt += N - bisect.bisect_left(A, x - i)
if cnt >= M:
return 1
else:
return 0
while True:
mid = (left + right) // 2
if shake(mid):
if not shake(mid + 1):
X = mid
break
else:
left = mid
else:
if shake(mid - 1):
X = mid - 1
break
else:
right = mid
happy = 0
cumsum_A = [0] + list(accumulate(A))
for j in A:
idx = bisect.bisect_right(A, X - j)
cnt = N - idx
happy += cumsum_A[-1] - cumsum_A[idx] + cnt * j
M -= cnt
happy += M * X
print(happy)
|
[
"expression.operation.binary.remove"
] | 626,047
| 626,048
|
u609061751
|
python
|
p02821
|
def main():
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
def helper(x):
p = len(A) - 1
t = 0
for a in A:
while p >= 0 and A[p] + a < x:
p -= 1
t += p + 1
return t
l, r = 0, A[0] * 2 + 1
while r - l > 1:
m = (l + r) // 2
if helper(m) > M:
l = m
else:
r = m
print(l)
k = sum(A)
p = len(A) - 1
t = (M - helper(l)) * l
for a in A:
while p >= 0 and A[p] + a < l:
k -= A[p]
p -= 1
t += a * (p + 1) + k
print(t)
main()
|
def main():
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
def helper(x):
p = len(A) - 1
t = 0
for a in A:
while p >= 0 and A[p] + a < x:
p -= 1
t += p + 1
return t
l, r = 0, A[0] * 2 + 1
while r - l > 1:
m = (l + r) // 2
if helper(m) > M:
l = m
else:
r = m
k = sum(A)
p = len(A) - 1
t = (M - helper(l)) * l
for a in A:
while p >= 0 and A[p] + a < l:
k -= A[p]
p -= 1
t += a * (p + 1) + k
print(t)
main()
|
[
"call.remove"
] | 626,061
| 626,062
|
u858742833
|
python
|
p02821
|
def main():
import bisect
import sys
from itertools import accumulate
input = sys.stdin.readline
def hsnum(x):
num = 0
for i in a:
y = x-i
num += n-bisect.bisect_left(a,y)
return num
n,m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
suma = [0]+list(accumulate(a))
lx = 0
rx = 2*10**5+2
error = 0
while lx+1 < rx:
mx = (lx+rx)//2
if hsnum(mx) < m:
rx = mx
elif hsnum(mx) > m:
lx = mx + 1
else:
lx = mx
break
if hsnum(lx)>m:
lx += 1
error = hsnum(lx)-m
ans = 0
for i in a:
rema = lx - i
j = bisect.bisect_left(a,rema)
ans += (n-j)*i-suma[j]
ans += suma[n]*n
print(ans-error*lx)
if __name__ == "__main__":
main()
|
def main():
import bisect
import sys
from itertools import accumulate
input = sys.stdin.readline
def hsnum(x):
num = 0
for i in a:
y = x-i
num += n-bisect.bisect_left(a,y)
return num
n,m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
suma = [0]+list(accumulate(a))
lx = 0
rx = 2*10**5+2
error = 0
while lx+1 < rx:
mx = (lx+rx)//2
if hsnum(mx) < m:
rx = mx
elif hsnum(mx) > m:
lx = mx + 1
else:
lx = mx
break
if hsnum(lx)<m:
lx -= 1
error = hsnum(lx)-m
ans = 0
for i in a:
rema = lx - i
j = bisect.bisect_left(a,rema)
ans += (n-j)*i-suma[j]
ans += suma[n]*n
print(ans-error*lx)
if __name__ == "__main__":
main()
|
[
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"expression.operator.change"
] | 626,137
| 626,138
|
u905582793
|
python
|
p02821
|
def main():
import bisect
import sys
from itertools import accumulate
input = sys.stdin.readline
def hsnum(x):
num = 0
for i in a:
y = x-i
num += n-bisect.bisect_left(a,y)
return num
n,m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
suma = [0]+list(accumulate(a))
lx = 0
rx = 2*10**5+2
error = 0
while lx+1 < rx:
mx = (lx+rx)//2
if hsnum(mx) < m:
rx = mx
elif hsnum(mx) > m:
lx = mx + 1
else:
lx = mx
break
if hsnum(lx)<m:
lx += 1
error = hsnum(lx)-m
ans = 0
for i in a:
rema = lx - i
j = bisect.bisect_left(a,rema)
ans += (n-j)*i-suma[j]
ans += suma[n]*n
print(ans-error*lx)
if __name__ == "__main__":
main()
|
def main():
import bisect
import sys
from itertools import accumulate
input = sys.stdin.readline
def hsnum(x):
num = 0
for i in a:
y = x-i
num += n-bisect.bisect_left(a,y)
return num
n,m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
suma = [0]+list(accumulate(a))
lx = 0
rx = 2*10**5+2
error = 0
while lx+1 < rx:
mx = (lx+rx)//2
if hsnum(mx) < m:
rx = mx
elif hsnum(mx) > m:
lx = mx + 1
else:
lx = mx
break
if hsnum(lx)<m:
lx -= 1
error = hsnum(lx)-m
ans = 0
for i in a:
rema = lx - i
j = bisect.bisect_left(a,rema)
ans += (n-j)*i-suma[j]
ans += suma[n]*n
print(ans-error*lx)
if __name__ == "__main__":
main()
|
[
"expression.operator.change"
] | 626,139
| 626,138
|
u905582793
|
python
|
p02821
|
from bisect import bisect_left
def calc(N, A, cumsum, x):
num = N ** 2
total = cumsum[N] * N * 2
for a in A:
idx = bisect_left(A, x - a)
num -= idx
total -= cumsum[idx] + idx * a
return num, total
def main():
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
cumsum = [0] * (N+1)
for i in range(N):
cumsum[i+1] = cumsum[i] + A[i]
lo = 0
hi = int(2e5)
while lo < hi:
mid = (lo + hi) // 2
num, total = calc(N, A, cumsum, mid)
if num <= M:
hi = mid
else:
lo = mid + 1
num, total = calc(N, A, cumsum, lo)
ans = total - (num - M) * (mid-1)
print(ans)
if __name__ == "__main__":
main()
|
from bisect import bisect_left
def calc(N, A, cumsum, x):
num = N ** 2
total = cumsum[N] * N * 2
for a in A:
idx = bisect_left(A, x - a)
num -= idx
total -= cumsum[idx] + idx * a
return num, total
def main():
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
cumsum = [0] * (N+1)
for i in range(N):
cumsum[i+1] = cumsum[i] + A[i]
lo = 0
hi = int(2e5+1)
while lo < hi:
mid = (lo + hi) // 2
num, total = calc(N, A, cumsum, mid)
if num <= M:
hi = mid
else:
lo = mid + 1
num, total = calc(N, A, cumsum, lo)
ans = total - (num - M) * (lo - 1)
print(ans)
if __name__ == "__main__":
main()
|
[
"assignment.value.change",
"identifier.change",
"expression.operation.binary.change"
] | 626,154
| 626,153
|
u155024797
|
python
|
p02821
|
from bisect import bisect_left
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
b = list(reversed(a))
rs = [0] * n
rs[0] = a[0]
for i, x in enumerate(a[1:]):
rs[i+1] = rs[i] + x
L = a[0] * 2
H = a[-1] * 2
while H - L > 1:
M = (L + H) // 2
count = 0
for x in a:
count += n - bisect_left(b, M - x)
if count == m:
L = M
break
elif count > m:
L = M
else:
H = M
ans = 0
count = 0
for x in a:
c = n - 1 - bisect_left(b, L - x)
count += c + 1
if c >= 0:
ans += rs[c] + x * (c+1)
print(ans - (count-m) * L)
|
from bisect import bisect_left
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
b = list(reversed(a))
rs = [0] * n
rs[0] = a[0]
for i, x in enumerate(a[1:]):
rs[i+1] = rs[i] + x
L = a[-1] * 2
H = a[0] * 2
while H - L > 1:
M = (L + H) // 2
count = 0
for x in a:
count += n - bisect_left(b, M - x)
if count == m:
L = M
break
elif count > m:
L = M
else:
H = M
ans = 0
count = 0
for x in a:
c = n - 1 - bisect_left(b, L - x)
count += c + 1
if c >= 0:
ans += rs[c] + x * (c+1)
print(ans - (count-m) * L)
|
[
"assignment.remove",
"assignment.add"
] | 626,172
| 626,173
|
u824237520
|
python
|
p02821
|
def ints():
return [int(x) for x in input().split()]
def ii():
return int(input())
N, M = ints()
A = ints()
A.sort()
def combinations(x):
s = 0
i = 0
j = N-1
while j>=0:
while i<N and A[i]+A[j]<x:
i += 1
s += N-i
j -= 1
return s
def koufukudo(x):
s = 0
si = 0
j = 0
i = N-1
while j<N:
while i>=0 and A[i]+A[j]>=x:
si += A[i]
i -= 1
s += si + A[j]*(N-1-i)
j += 1
return s
def bsearch(lower, upper):
l = lower
u = upper
m = (l+u)//2
c = combinations(m)
if c<M:
return bsearch(l, m)
else:
if l==m:
return (l, c-M)
return bsearch(m, u)
x, dm = bsearch(0, A[-1]*2+1)
print(x)
print(koufukudo(x)-dm*x)
|
def ints():
return [int(x) for x in input().split()]
def ii():
return int(input())
N, M = ints()
A = ints()
A.sort()
def combinations(x):
s = 0
i = 0
j = N-1
while j>=0:
while i<N and A[i]+A[j]<x:
i += 1
s += N-i
j -= 1
return s
def koufukudo(x):
s = 0
si = 0
j = 0
i = N-1
while j<N:
while i>=0 and A[i]+A[j]>=x:
si += A[i]
i -= 1
s += si + A[j]*(N-1-i)
j += 1
return s
def bsearch(lower, upper):
l = lower
u = upper
m = (l+u)//2
c = combinations(m)
if c<M:
return bsearch(l, m)
else:
if l==m:
return (l, c-M)
return bsearch(m, u)
x, dm = bsearch(0, A[-1]*2+1)
print(koufukudo(x)-dm*x)
|
[
"call.remove"
] | 626,248
| 626,249
|
u967136506
|
python
|
p02820
|
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
d={'r':p,'s':r,'p':s}
d_={'r':'p','s':'r','p':'s'}
s=0
for i in range(k):
a=0
z='0'
t_=t[i::k]
for a in range(len(t_)):
if a==0:
s+=d[t_[a]]
z=d_[t_[a]]
a+=1
else:
if z==d_[t_[a]]:
z=t_[a]
a+=1
else:
s+=d[t_[a]]
z=d_[t_[a]]
a+=1
print(s)
|
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
d={'r':p,'s':r,'p':s}
d_={'r':'p','s':'r','p':'s'}
s=0
for i in range(k):
a=0
z='0'
t_=t[i::k]
for a in range(len(t_)):
if a==0:
s+=d[t_[a]]
z=d_[t_[a]]
a+=1
else:
if z==d_[t_[a]]:
z='0'
a+=1
else:
s+=d[t_[a]]
z=d_[t_[a]]
a+=1
print(s)
|
[] | 626,317
| 626,318
|
u428199834
|
python
|
p02820
|
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=list(input())
ans=0
dic={'r':'p','s':'r','p':'s'}
score={'r':R,'s':S,'p':P}
past=[]
for i in range(len(T)):
if i>=K:
if dic[T[i]]==past[i-K]:
past.append(T[i])
continue
else:
ans+=score[dic[T[i]]]
past.append(dic[T[i]])
else:
ans+=score[dic[T[i]]]
past.append(dic[T[i]])
print(ans)
|
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=list(input())
ans=0
dic={'r':'p','s':'r','p':'s'}
score={'r':R,'s':S,'p':P}
past=[]
for i in range(len(T)):
if i>=K:
if dic[T[i]]==past[i-K]:
past.append('0')
continue
else:
ans+=score[dic[T[i]]]
past.append(dic[T[i]])
else:
ans+=score[dic[T[i]]]
past.append(dic[T[i]])
print(ans)
|
[
"call.arguments.change"
] | 626,319
| 626,320
|
u229518917
|
python
|
p02820
|
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
dp = [[0]*3 for _ in range(N+1)]
for i in range(1, N+1):
if i <= K:
dp[i][0] = int(T[i-1]=='s') * R
dp[i][1] = int(T[i-1]=='p') * P
dp[i][2] = int(T[i-1]=='r') * P
else:
dp[i][0] = max(dp[i-K][1], dp[i-K][2]) + int(T[i-1]=='s') * R
dp[i][1] = max(dp[i-K][0], dp[i-K][2]) + int(T[i-1]=='p') * P
dp[i][2] = max(dp[i-K][0], dp[i-K][1]) + int(T[i-1]=='r') * S
ans = 0
for d in dp[-K:]:
ans += max(d)
print(ans)
|
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
dp = [[0]*3 for _ in range(N+1)]
for i in range(1, N+1):
if i <= K:
dp[i][0] = int(T[i-1]=='s') * R
dp[i][1] = int(T[i-1]=='p') * S
dp[i][2] = int(T[i-1]=='r') * P
else:
dp[i][0] = max(dp[i-K][1], dp[i-K][2]) + int(T[i-1]=='s') * R
dp[i][1] = max(dp[i-K][0], dp[i-K][2]) + int(T[i-1]=='p') * S
dp[i][2] = max(dp[i-K][0], dp[i-K][1]) + int(T[i-1]=='r') * P
ans = 0
for d in dp[-K:]:
ans += max(d)
print(ans)
|
[
"assignment.value.change",
"identifier.change",
"expression.operation.binary.change"
] | 626,321
| 626,322
|
u439063038
|
python
|
p02820
|
N, K = [int(x) for x in input().split()]
r, s, p = [int(x) for x in input().split()]
win_point = {
'r': r,
's': s,
'p': p,
}
next_hands = {
'r': ['s', 'p'],
's': ['r', 'p'],
'p': ['r', 's'],
}
enemy_hands = input()
def can_win(enemy_hand, my_hands):
# 勝てる場合にはTrueと勝てる手を教えてくれる
if enemy_hand == 'r' and 'p' in my_hands:
return True, 'p'
if enemy_hand == 's' and 'r' in my_hands:
return True, 'r'
if enemy_hand == 'p' and 's' in my_hands:
return True, 's'
# 勝てる手がない場合
return False, None
point = 0
for index in range(K):
now_hands = ['r', 'p', 's']
for i in range(index, N, K):
win, hand = can_win(enemy_hands[i], now_hands)
if win:
point += win_point[hand]
now_hands = next_hands[hand]
else:
# 勝てない場合次似邪魔しない手を選ぶ
# 勝てない回の次は必ず勝てるため全手出せる前提とする
now_hans = ['r', 'p', 's']
print(point)
|
N, K = [int(x) for x in input().split()]
r, s, p = [int(x) for x in input().split()]
win_point = {
'r': r,
's': s,
'p': p,
}
next_hands = {
'r': ['s', 'p'],
's': ['r', 'p'],
'p': ['r', 's'],
}
enemy_hands = input()
def can_win(enemy_hand, my_hands):
# 勝てる場合にはTrueと勝てる手を教えてくれる
if enemy_hand == 'r' and 'p' in my_hands:
return True, 'p'
if enemy_hand == 's' and 'r' in my_hands:
return True, 'r'
if enemy_hand == 'p' and 's' in my_hands:
return True, 's'
# 勝てる手がない場合
return False, None
point = 0
for index in range(K):
now_hands = ['r', 'p', 's']
for i in range(index, N, K):
win, hand = can_win(enemy_hands[i], now_hands)
if win:
point += win_point[hand]
now_hands = next_hands[hand]
else:
# 勝てない場合次似邪魔しない手を選ぶ
# 勝てない回の次は必ず勝てるため全手出せる前提とする
now_hands = ['r', 'p', 's']
print(point)
|
[
"assignment.variable.change",
"identifier.change"
] | 626,328
| 626,329
|
u891516200
|
python
|
p02820
|
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
t2 = [[] for _ in range(k)]
score = [0]*n
for i,c in enumerate(t):
t2[i%k].append(c)
score = {'r':p,'s':r,'p':s}
total = 0
for t3 in t2:
if len(t3)==0: continue
if len(t3)==1:
total += score[c]
continue
for i in range(len(t3)-1):
if t3[i] == 'e': continue
total += score[t3[i]]
if t3[i] == t3[i+1]:
t3[i+1]='e'
if t3[-1] != 'e':
total += score[t3[-1]]
print(total)
|
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
t2 = [[] for _ in range(k)]
score = [0]*n
for i,c in enumerate(t):
t2[i%k].append(c)
score = {'r':p,'s':r,'p':s}
total = 0
for t3 in t2:
if len(t3)==0: continue
if len(t3)==1:
total += score[t3[0]]
continue
for i in range(len(t3)-1):
if t3[i] == 'e': continue
total += score[t3[i]]
if t3[i] == t3[i+1]:
t3[i+1]='e'
if t3[-1] != 'e':
total += score[t3[-1]]
print(total)
|
[
"identifier.change",
"variable_access.subscript.index.change"
] | 626,330
| 626,331
|
u221061152
|
python
|
p02820
|
# 初期入力
N,K = (int(x) for x in input().split(" "))
R,S,P = (int(x) for x in input().split(" "))
ten_janken_dic ={"R":R,"S":S,"P":P} #じゃんけんの役ごとの点を辞書
ten_janken_sort =sorted(ten_janken_dic.items(),key=lambda x: x[1])
T =input()
#合計点と高橋君が出す手を同時進行
sum_janken = 0 # 合計点
takahasi = [] # 高橋君が出す手,K回前の手も出せる=すべて勝つとした場合
for i in T:
if i =="r":
sum_janken += P #6
takahasi.append("P")
elif i == "s":
sum_janken += R #8
takahasi.append("R")
elif i == "p":
sum_janken += S #7
takahasi.append("S")
takahasi_mae =[]
from copy import deepcopy
takahasi_mae = deepcopy(takahasi)
# K回前の手は出せない
for i,v in enumerate(takahasi[K:]):
if v ==takahasi[(i+K)-K]:
sum_janken -= ten_janken_dic[v]
x = ["R","S","P"]
if takahasi[(i+K)-K] in x:
x.remove( takahasi[(i+K)-K] ) #K回前の手を消す
if i+K+K <=len(takahasi):
if takahasi[i+K+K] in x:
x.remove( takahasi[i+K+K] ) #K回後の手を消す
if len(x) ==1:
takahasi[i+K] =x[0]
elif x[0]==ten_janken_sort[2][0] or x[1] ==ten_janken_sort[2][0] : #高い点を選ぶ
takahasi[i+K] =ten_janken_sort[2][0]
else:
takahasi[i+K] =ten_janken_sort[1][0] #2番目に高い点のキー(点順でソートしてある)
print(sum_janken)
|
# 初期入力
N,K = (int(x) for x in input().split(" "))
R,S,P = (int(x) for x in input().split(" "))
ten_janken_dic ={"R":R,"S":S,"P":P} #じゃんけんの役ごとの点を辞書
ten_janken_sort =sorted(ten_janken_dic.items(),key=lambda x: x[1])
T =input()
#合計点と高橋君が出す手を同時進行
sum_janken = 0 # 合計点
takahasi = [] # 高橋君が出す手,K回前の手も出せる=すべて勝つとした場合
for i in T:
if i =="r":
sum_janken += P #6
takahasi.append("P")
elif i == "s":
sum_janken += R #8
takahasi.append("R")
elif i == "p":
sum_janken += S #7
takahasi.append("S")
takahasi_mae =[]
from copy import deepcopy
takahasi_mae = deepcopy(takahasi)
# K回前の手は出せない
for i,v in enumerate(takahasi[K:]):
if v ==takahasi[(i+K)-K]:
sum_janken -= ten_janken_dic[v]
x = ["R","S","P"]
if takahasi[(i+K)-K] in x:
x.remove( takahasi[(i+K)-K] ) #K回前の手を消す
if i+K+K < len(takahasi):
if takahasi[i+K+K] in x:
x.remove( takahasi[i+K+K] ) #K回後の手を消す
if len(x) ==1:
takahasi[i+K] =x[0]
elif x[0]==ten_janken_sort[2][0] or x[1] ==ten_janken_sort[2][0] : #高い点を選ぶ
takahasi[i+K] =ten_janken_sort[2][0]
else:
takahasi[i+K] =ten_janken_sort[1][0] #2番目に高い点のキー(点順でソートしてある)
print(sum_janken)
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 626,336
| 626,337
|
u116038906
|
python
|
p02820
|
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
did = "-" * k
ans = 0
for i in t:
if i == "r":
if did[-k] == "p":
did += "r"
else:
did += "p"
ans += p
elif i == "s":
if did[-k] == "r":
did += "s"
else:
did += "r"
ans += r
else:
if did[-k] == "s":
did += "p"
else:
did += "s"
ans += s
print(ans)
|
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
did = "-" * k
ans = 0
for i in t:
if i == "r":
if did[-k] == "p":
did += "-"
else:
did += "p"
ans += p
elif i == "s":
if did[-k] == "r":
did += "-"
else:
did += "r"
ans += r
else:
if did[-k] == "s":
did += "-"
else:
did += "s"
ans += s
print(ans)
|
[
"literal.string.change"
] | 626,344
| 626,345
|
u761989513
|
python
|
p02820
|
n,k=map(int,input().split())
r,s,p = map(int,input().split())
T=list(input())
a=[[] for i in range(k)]
for i in range(n):
a[i%k].append(T[i])
flg=0
score=0
for j in range(k):
b=a[j]
for l in range(len(b)):
if l==0:
if b[l]=='r':
score+=p
elif b[l]=='s':
score+=r
elif b[l]=='p':
score+=s
else:
if b[l-1]==b[l] and flg==0:
flg=1
continue
elif b[l-1]==b[l] and flg==1:
if b[l]=='r':
score+=p
elif b[l]=='s':
score+=r
elif b[l]=='p':
score+=s
flg=0
elif b[l-1]!=b[l]:
if b[l]=='r':
score+=p
elif b[l]=='s':
score+=r
elif b[l]=='p':
score+=s
flg=0
print(score)
|
n,k=map(int,input().split())
r,s,p = map(int,input().split())
T=list(input())
a=[[] for i in range(k)]
for i in range(n):
a[i%k].append(T[i])
score=0
for j in range(k):
b=a[j]
flg=0
for l in range(len(b)):
if l==0:
if b[l]=='r':
score+=p
elif b[l]=='s':
score+=r
elif b[l]=='p':
score+=s
else:
if b[l-1]==b[l] and flg==0:
flg=1
continue
elif b[l-1]==b[l] and flg==1:
if b[l]=='r':
score+=p
elif b[l]=='s':
score+=r
elif b[l]=='p':
score+=s
flg=0
elif b[l-1]!=b[l]:
if b[l]=='r':
score+=p
elif b[l]=='s':
score+=r
elif b[l]=='p':
score+=s
flg=0
print(score)
|
[
"assignment.remove",
"assignment.add"
] | 626,346
| 626,347
|
u485319545
|
python
|
p02820
|
def f(c):
"""
入力に対する勝ち手を出力
"""
if c=="r":
return "p"
elif c=="s":
return "r"
else:
return "s"
def main():
"""
まずは全て勝つ組み合わせを作って、合計ポイントを求める。
iを0からN-Kまで変化させ、T(i)=T(k+i)となる時、
T(k+i)をT(i)、T(i+2K)と異なる手に変更する。
※T(i)を変更すると、T(i)=T(i+k)=T(i+2K)=...=と連続した時に、
全て変更されてスコアが最大にならない。
T(k+i)は勝ちから"あいこまたは負け"に変化するので、合計ポイントから差っ引く。
"""
#input
N,K=map(int,input().strip().split())
R,S,P=map(int,input().strip().split())
T=list(input())
win_T=list(map(lambda x:f(x),T))
point={"r":R,"s":S,"p":P}
score=sum([point[win_T[n]] for n in range(N)])
for i in range(N-K):
l=["r","s","p"]
if win_T[i]==win_T[i+K]:
score-=point[win_T[i+K]]
l.remove(win_T[i])
if i<=N-2*K and win_T[i]!=win_T[i+2*K]:
l.remove(win_T[i+2*K])
win_T[i+K]=l[0]
return score
if __name__=="__main__":
print(main())
|
def f(c):
"""
入力に対する勝ち手を出力
"""
if c=="r":
return "p"
elif c=="s":
return "r"
else:
return "s"
def main():
"""
まずは全て勝つ組み合わせを作って、合計ポイントを求める。
iを0からN-Kまで変化させ、T(i)=T(k+i)となる時、
T(k+i)をT(i)、T(i+2K)と異なる手に変更する。
※T(i)を変更すると、T(i)=T(i+k)=T(i+2K)=...=と連続した時に、
全て変更されてスコアが最大にならない。
T(k+i)は勝ちから"あいこまたは負け"に変化するので、合計ポイントから差っ引く。
"""
#input
N,K=map(int,input().strip().split())
R,S,P=map(int,input().strip().split())
T=list(input())
win_T=list(map(lambda x:f(x),T))
point={"r":R,"s":S,"p":P}
score=sum([point[win_T[n]] for n in range(N)])
for i in range(N-K):
l=["r","s","p"]
if win_T[i]==win_T[i+K]:
score-=point[win_T[i+K]]
l.remove(win_T[i])
if i<=N-2*K-1 and win_T[i]!=win_T[i+2*K]:
l.remove(win_T[i+2*K])
win_T[i+K]=l[0]
return score
if __name__=="__main__":
print(main())
|
[
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 626,352
| 626,353
|
u613920660
|
python
|
p02820
|
n.k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
for i in range(n-k):
if t[k+i] == t[i]:
t[k+i] = 0
xs = t.count('r')*p+ t.count('s')*r+t.count('p')*s
print(x)
|
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
for i in range(n-k):
if t[k+i] == t[i]:
t[k+i] = 0
x = t.count('r')*p+ t.count('s')*r+t.count('p')*s
print(x)
|
[
"misc.typo",
"assignment.variable.change",
"identifier.change"
] | 626,354
| 626,355
|
u175590965
|
python
|
p02820
|
n.k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
for i in range(n-k):
if t[k+a] == t[a]:
t[k+a] = 0
xs = t.count('r')*p+ t.count('s')*r+t.count('p')*s
print(x)
|
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
for i in range(n-k):
if t[k+i] == t[i]:
t[k+i] = 0
x = t.count('r')*p+ t.count('s')*r+t.count('p')*s
print(x)
|
[
"misc.typo",
"assignment.variable.change",
"identifier.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change",
"expression.operation.binary.change"
] | 626,356
| 626,355
|
u175590965
|
python
|
p02820
|
import sys
def input(): return sys.stdin.readline().strip()
def resolve():
n,k=map(int, input().split())
r,s,p=map(int, input().split())
t=input()
def kachip(te):
if te=='r':
return p
elif te=='s':
return r
else:
return s
def kachite(te):
if te == 'r':
return 'p'
elif te == 's':
return 'r'
else:
return 's'
check=[0]*k # 出した手
ans=0
for i in range(n):
point=kachip(t[i])
te=kachite(t[i])
if check[i%k]==te:
check[i%k]=t[i]
else:
ans+=point
check[i%k]=te
print(ans)
resolve()
|
import sys
def input(): return sys.stdin.readline().strip()
def resolve():
n,k=map(int, input().split())
r,s,p=map(int, input().split())
t=input()
def kachip(te):
if te=='r':
return p
elif te=='s':
return r
else:
return s
def kachite(te):
if te == 'r':
return 'p'
elif te == 's':
return 'r'
else:
return 's'
check=[0]*k # 出した手
ans=0
for i in range(n):
point=kachip(t[i])
te=kachite(t[i])
if check[i%k]==te:
check[i%k]=0
else:
ans+=point
check[i%k]=te
print(ans)
resolve()
|
[
"assignment.value.change",
"identifier.replace.remove",
"literal.replace.add"
] | 626,377
| 626,378
|
u057964173
|
python
|
p02821
|
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
OK=0
NG=max(A)*2+1
import bisect
while NG-OK>2: #N*N個の中で,mid以上の個数がM個以上あればOK
mid=(OK+NG)//2
score=0
for a in A:
x=bisect.bisect_left(A,mid-a)
score+=N-x
if score>=M:
OK=mid
break
else:
NG=mid
from itertools import accumulate
S=list(accumulate(A))
ANS=0
ups=0
for a in A:
x=bisect.bisect_right(A,OK-a)
if x!=0:
ANS+=(N-x)*a+(S[-1]-S[x-1])
else:
ANS+=(N-x)*a+S[-1]
#print(x,ANS)
ups+=N-x
#print(ANS)
ANS+=(M-ups)*OK
print(ANS)
|
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
OK=0
NG=max(A)*2+1
import bisect
while NG-OK>1: #N*N個の中で,mid以上の個数がM個以上あればOK
mid=(OK+NG)//2
score=0
for a in A:
x=bisect.bisect_left(A,mid-a)
score+=N-x
if score>=M:
OK=mid
break
else:
NG=mid
from itertools import accumulate
S=list(accumulate(A))
ANS=0
ups=0
for a in A:
x=bisect.bisect_right(A,OK-a)
if x!=0:
ANS+=(N-x)*a+(S[-1]-S[x-1])
else:
ANS+=(N-x)*a+S[-1]
#print(x,ANS)
ups+=N-x
#print(ANS)
ANS+=(M-ups)*OK
print(ANS)
|
[
"literal.number.integer.change",
"control_flow.loop.condition.change"
] | 626,417
| 626,418
|
u695811449
|
python
|
p02822
|
from sys import stdin, setrecursionlimit
from collections import deque
setrecursionlimit(10 ** 9)
INF = 1 << 60
def input():
return stdin.readline().strip()
MOD = 1000000007
N = int(input())
m = map(int, stdin.buffer.read().split())
AB = zip(m, m)
G = [[] for _ in range(N)]
for a, b in AB:
G[a - 1].append(b - 1)
G[b - 1].append(a - 1)
pow2 = [1] * (N + 1)
for i in range(N):
pow2[i + 1] = pow2[i] * 2 % MOD
order = []
parent = [-1] * N
stack = deque([0])
while stack:
v = stack.pop()
order.append(v)
for nv in G[v]:
if parent[v] != nv:
parent[nv] = v
stack.append(nv)
numer = 0
nums = [0] * N
for v in reversed(order):
tmp = 1
for nv in G[v]:
if parent[v] != nv:
nums[v] += nums[nv] + 1
tmp += pow2[nums[nv] + 1] - 1
tmp += pow2[N - nums[v] - 1] - 1
numer = (numer + pow2[N - 1] - tmp) % MOD
denom = pow2[N]
ans = numer * pow(denom, MOD - 2, MOD) % MOD
print(ans)
|
from sys import stdin, setrecursionlimit
from collections import deque
setrecursionlimit(10 ** 9)
INF = 1 << 60
def input():
return stdin.readline().strip()
MOD = 1000000007
N = int(stdin.buffer.readline())
m = map(int, stdin.buffer.read().split())
AB = zip(m, m)
G = [[] for _ in range(N)]
for a, b in AB:
G[a - 1].append(b - 1)
G[b - 1].append(a - 1)
pow2 = [1] * (N + 1)
for i in range(N):
pow2[i + 1] = pow2[i] * 2 % MOD
order = []
parent = [-1] * N
stack = deque([0])
while stack:
v = stack.pop()
order.append(v)
for nv in G[v]:
if parent[v] != nv:
parent[nv] = v
stack.append(nv)
numer = 0
nums = [0] * N
for v in reversed(order):
tmp = 1
for nv in G[v]:
if parent[v] != nv:
nums[v] += nums[nv] + 1
tmp += pow2[nums[nv] + 1] - 1
tmp += pow2[N - nums[v] - 1] - 1
numer = (numer + pow2[N - 1] - tmp) % MOD
denom = pow2[N]
ans = numer * pow(denom, MOD - 2, MOD) % MOD
print(ans)
|
[
"assignment.value.change",
"call.arguments.change"
] | 626,456
| 626,457
|
u968166680
|
python
|
p02823
|
N,A,B = map(int,input().split())
if abs(A-B)%2 == 1:
print(min(A-1,N-B))+1+(B-A-1)//2
else:
print(abs(A-B)//2)
|
N,A,B = map(int,input().split())
if abs(A-B)%2 == 1:
print(min(A-1,N-B)+1+(B-A-1)//2)
else:
print(abs(A-B)//2)
|
[
"call.arguments.change"
] | 626,598
| 626,599
|
u514118270
|
python
|
p02823
|
n,a,b=map(int,input().split())
if (b-a)%2==0:
print((b-a)//2)
else:
print(min((b+a-1)//2),(2*n-a-b+1)//2)
|
n,a,b=map(int,input().split())
if (b-a)%2==0:
print((b-a)//2)
else:
print(min((b+a-1)//2,(2*n-a-b+1)//2))
|
[
"call.arguments.change"
] | 626,602
| 626,603
|
u474925961
|
python
|
p02823
|
N, *AB = [int(x) for x in input().split()]
A, B = sorted(AB)
print(A, B)
if (B - A) % 2 == 0:
ans = (B - A) // 2
else:
ans = (B - A + 2 * min(N - B, A - 1) + 1) // 2
print(ans)
|
N, *AB = [int(x) for x in input().split()]
A, B = sorted(AB)
if (B - A) % 2 == 0:
ans = (B - A) // 2
else:
ans = (B - A + 2 * min(N - B, A - 1) + 1) // 2
print(ans)
|
[
"call.remove"
] | 626,610
| 626,611
|
u197955752
|
python
|
p02823
|
n,a,b = map(int,input().split())
if (b-a)%2 == 0:
print((b-a)//2)
else:
left = a+((b-a)-1)//2
right = (n-b+1)+(n-a+(n-b+1))//2
print(min(right,left))
|
n,a,b = map(int,input().split())
if (b-a)%2 == 0:
print((b-a)//2)
else:
left = a+((b-a)-1)//2
right = (n-b+1)+(n-(a+n-b+1))//2
print(min(right,left))
|
[] | 626,628
| 626,629
|
u987164499
|
python
|
p02823
|
n,a,b=map(int,input().split())
if (b-a)%2==0:
print((b-a)//2)
else:
print(min(a+(b-a)//2,b+(b-a)//2))
|
n,a,b=map(int,input().split())
if (b-a)%2==0:
print((b-a)//2)
else:
print(min(a+(b-a)//2,(n-b+1)+(b-a)//2))
|
[] | 626,642
| 626,643
|
u366886346
|
python
|
p02823
|
N,A,B=map(int,input().split())
if (B-A)%2==0:
ans=(B-A)//2
else:
ans=min(A,N-B)+(B-A)//2
print(ans)
|
N,A,B=map(int,input().split())
if (B-A)%2==0:
ans=(B-A)//2
else:
ans=min(A-1,N-B)+(B-A+1)//2
print(ans)
|
[
"assignment.change"
] | 626,646
| 626,647
|
u391819434
|
python
|
p02823
|
n,a,b=map(int,input().split())
if (b-a-1)%2==1:
print((b-a-1)//2+1)
else:
print(min(a-1,n-b)+1+(b-a-1)//2+1)
|
n,a,b=map(int,input().split())
if (b-a-1)%2==1:
print((b-a-1)//2+1)
else:
print(min(a-1,n-b)+1+(b-a-2)//2+1)
|
[
"literal.number.integer.change",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 626,650
| 626,651
|
u453642820
|
python
|
p02823
|
n,a,b=map(int,input().split())
if (b-a)%2 == 0:
print((b-a)//2)
else:
if n-b >= a-1:
ans = a-1
ans += (b-ans-1)//2
print(ans+1)
else:
ans = n-b
ans += (b-(a+n-b))//2
print(ans+1)
|
n,a,b=map(int,input().split())
if (b-a)%2 == 0:
print((b-a)//2)
else:
if n-b >= a-1:
ans = a-1
ans += (b-a-1)//2
print(ans+1)
else:
ans = n-b
ans += (b-a-1)//2
print(ans+1)
|
[
"identifier.change",
"expression.operation.binary.change",
"expression.operation.binary.remove",
"identifier.replace.remove",
"literal.replace.add"
] | 626,674
| 626,675
|
u703214333
|
python
|
p02823
|
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache # @lru_cache(None)
from math import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return (int(x) for x in input().split())
def LI(): return list(Is())
def TI(): return tuple(Is())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(S())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #
n, a, b = Is()
if (a + b) % 2 == 0:
print((b-a)//2)
else:
print(min(n-a, b-1)+1+(b-a-1)//2)
|
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache # @lru_cache(None)
from math import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return (int(x) for x in input().split())
def LI(): return list(Is())
def TI(): return tuple(Is())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(S())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #
n, a, b = Is()
if (a + b) % 2 == 0:
print((b-a)//2)
else:
print(min(n-b, a-1)+1+(b-a-1)//2)
|
[
"call.arguments.change",
"call.arguments.add"
] | 626,714
| 626,715
|
u279460955
|
python
|
p02823
|
N,A,B = map(int,input().split())
A,B = min(A,B),max(A,B)
if abs(A-B)%2==0:
print(abs(A-B)//2)
else:
print(min(A,N-1-B)+abs((A-B)-1)//2)
|
N,A,B = map(int,input().split())
A,B = min(A,B),max(A,B)
if abs(A-B)%2==0:
print(abs(A-B)//2)
else:
print(min(A-1,N-B)+abs((A-B)-1)//2)
|
[
"call.arguments.change",
"call.arguments.add"
] | 626,740
| 626,741
|
u364862909
|
python
|
p02823
|
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
print((B - A) // 2)
else:
#A->1.1, B->B-A
a = A + (B-A-1)//2
#A->A+N-B+1, B->N.N
b = N-B+1 + (N - A + B - 1)//2
print(min(a,b))
|
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
print((B - A) // 2)
else:
#A->1.1, B->B-A
a = A + (B-A-1)//2
#A->A+N-B+1, B->N.N
b = N-B+1 + (- A + B - 1)//2
print(min(a,b))
|
[] | 626,746
| 626,747
|
u779728630
|
python
|
p02823
|
N, A, B = map(int, input().split())
C=B-A
D=min(A-1,N-B)+1 + (B - A - 1)/2
if C%2==1:
print (D)
else:
print(C)
|
N, A, B = map(int, input().split())
C=B-A
D=min(A-1,N-B)+1 + (B - A - 1)//2
if C%2==1:
print (D)
else:
print(C//2)
|
[
"expression.operator.arithmetic.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 626,750
| 626,749
|
u478417863
|
python
|
p02823
|
n,a,b = map(int,input().split())
ans = (b-a)//2
if (b-a)%2!=0 and (a-1)<(n-b):
ans += a
elif (b-a)%2!=0 and (a-1)>(n-b):
ans += n-b+1
print(ans)
|
n,a,b = map(int,input().split())
ans = (b-a)//2
if (b-a)%2!=0 and (a-1)<(n-b):
ans += a
elif (b-a)%2!=0 and (a-1)>=(n-b):
ans += n-b+1
print(ans)
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 626,753
| 626,754
|
u810288681
|
python
|
p02823
|
N,A,B=map(int,input().split())
if (A-B)%2==0:
print((A-B)/2)
exit()
print(min((A+B-1)//2,(N-B+N-A+1)//2))
|
N,A,B=map(int,input().split())
if (A-B)%2==0:
print((B-A)//2)
exit()
print(min((A+B-1)//2,(N-B+N-A+1)//2))
|
[
"expression.operation.binary.remove",
"expression.operator.arithmetic.change",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 626,757
| 626,756
|
u093861603
|
python
|
p02823
|
n, a, b = map(int, input().split())
if (b - a) % 2:
print((b - a) // 2)
else:
print(min(a - 1, n - b,) + 1 + (b - a - 1) // 2)
|
n, a, b = map(int, input().split())
if (b - a) % 2 == 0:
print((b - a) // 2)
else:
print(min(a - 1, n - b,) + 1 + (b - a - 1) // 2)
|
[
"control_flow.branch.if.condition.change"
] | 626,758
| 626,759
|
u945200821
|
python
|
p02823
|
n, a, b = map(int, input().split())
if (b - a) % 2:
print((b - a) % 2)
else:
print(min(a - 1, n - b,) + 1 + (b - a - 1) // 2)
|
n, a, b = map(int, input().split())
if (b - a) % 2 == 0:
print((b - a) // 2)
else:
print(min(a - 1, n - b,) + 1 + (b - a - 1) // 2)
|
[
"control_flow.branch.if.condition.change",
"expression.operator.arithmetic.change",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 626,760
| 626,759
|
u945200821
|
python
|
p02823
|
#dpでできないかな?
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,cos,radians,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n,a,b=MI()
l=b-a
if l%2==0:
ans=l//2
print(ans)
else:
edge=min(n-b,a-1)
ans=edge
ans+=1
l-=1
ans+=l//2
|
#dpでできないかな?
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,cos,radians,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n,a,b=MI()
l=b-a
if l%2==0:
ans=l//2
print(ans)
else:
edge=min(n-b,a-1)
#print(edge)
ans=edge
ans+=1
l-=1
ans+=l//2
print(ans)
|
[
"call.add"
] | 626,771
| 626,772
|
u029000441
|
python
|
p02823
|
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
print((B - A) // 2)
else:
print(min(A + (B - A - 1) % 2, N - B + 1 + (B - A - 1) % 2))
|
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
print((B - A) // 2)
else:
print(min(A + (B - A - 1) // 2, N - B + 1 + (B - A - 1) // 2))
|
[
"expression.operator.arithmetic.change",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 626,790
| 626,791
|
u673361376
|
python
|
p02823
|
# N = int(input())
N, A, B = [int(_) for _ in input().split()]
if (B - A) % 2 == 0:
print((B-A) // 2)
else:
print(min(N - B + 1 + N - (A + N-B+1) // 2, A + (B - A - 1)//2))
|
# N = int(input())
N, A, B = [int(_) for _ in input().split()]
if (B - A) % 2 == 0:
print((B-A) // 2)
else:
print(min(N - B + 1 + (N - (A + N-B+1)) // 2, A + (B - A - 1)//2))
|
[
"call.arguments.change"
] | 626,802
| 626,803
|
u504562455
|
python
|
p02823
|
n,a,b = map(int,input().split())
if (b-a)%2==0:
print((b-a)//2)
else:
m = min(b-1,n-a)
M = min(a-1,n-b)+(b-a-1)//2
print(min(m,M))
|
n,a,b = map(int,input().split())
if (b-a)%2==0:
print((b-a)//2)
else:
m = min(b-1,n-a)
M = min(a-1,n-b)+(b-a-1)//2+1
print(min(m,M))
|
[
"assignment.change"
] | 626,820
| 626,821
|
u785578220
|
python
|
p02823
|
n,a,b=map(int, input().split())
if (b-a)%2==0:
print((b-a)//2)
else:
print(min(a+(b-a-1)//2, b+1+(b-a-1)//2))
|
n,a,b=map(int, input().split())
if (b-a)%2==0:
print((b-a)//2)
else:
print(min(a+(b-a-1)//2, n-b+1+(b-a-1)//2))
|
[
"expression.operation.binary.add"
] | 626,839
| 626,840
|
u748311048
|
python
|
p02823
|
N,a,b = map(int,input().split())
if (b-a)%2 ==0:
ams = (b-a)//2
else:
ans = min(a-1,N-b)+1 + (b-a-1)//2
print(ans)
|
N,a,b = map(int,input().split())
if (b-a)%2 ==0:
ans = (b-a)//2
else:
ans = min(a-1,N-b)+1 + (b-a-1)//2
print(ans)
|
[
"assignment.variable.change",
"identifier.change"
] | 626,843
| 626,844
|
u821251381
|
python
|
p02823
|
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()
def resolve():
import sys
input = sys.stdin.readline
n, a, b = [int(x) for x in input().rstrip().split(" ")]
if a > n - b:
tmp = a
a = n - b
b = n - tmp
a = a - 1
b = b - 1
if (b - a) % 2 == 0:
print(abs(a - b) // 2)
else:
count = a + 1 + ((b - a - 1) // 2)
print(count)
if __name__ == "__main__":
resolve()
|
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()
def resolve():
import sys
input = sys.stdin.readline
n, a, b = [int(x) for x in input().rstrip().split(" ")]
if a > n - b + 1:
tmp = a
a = n - b
b = n - tmp
else:
a = a - 1
b = b - 1
if (b - a) % 2 == 0:
print(abs(a - b) // 2)
else:
count = a + 1 + ((b - a - 1) // 2)
print(count)
if __name__ == "__main__":
resolve()
|
[
"control_flow.branch.if.condition.change"
] | 626,849
| 626,850
|
u138083942
|
python
|
p02823
|
'''
Created on 2020/09/03
@author: harurun
'''
def main():
import sys
pin=sys.stdin.readline
pout=sys.stdout.write
perr=sys.stderr.write
N,A,B=map(int,pin().split())
if (B-A)%2==0:
print((B-A)//2)
return
if A<N-B:
print(A+(B-A-1)//2)
else:
print(N-B+(B-A-1)//2)
return
main()
|
'''
Created on 2020/09/03
@author: harurun
'''
def main():
import sys
pin=sys.stdin.readline
pout=sys.stdout.write
perr=sys.stderr.write
N,A,B=map(int,pin().split())
if (B-A)%2==0:
print((B-A)//2)
return
if A<N-B+1:
print(A+(B-A-1)//2)
else:
print(N-B+1+(B-A-1)//2)
return
main()
|
[
"control_flow.branch.if.condition.change"
] | 626,867
| 626,868
|
u519339498
|
python
|
p02823
|
def main():
n, a, b = map(int, input().split())
if (b - a) % 2 == 0:
ans = (b - a) // 2
else:
ans = min(n - a, b - 1) + 1 + (b - a - 1) // 2
print(ans)
if __name__ == "__main__":
main()
|
def main():
n, a, b = map(int, input().split())
if (b - a) % 2 == 0:
ans = (b - a) // 2
else:
ans = min(n - b, a - 1) + 1 + (b - a - 1) // 2
print(ans)
if __name__ == "__main__":
main()
|
[
"call.arguments.change",
"call.arguments.add"
] | 626,873
| 626,874
|
u359358631
|
python
|
p02823
|
N, A, B = map(int, input().split())
if A % 2 == B % 2:
print(abs(A - B) // 2)
else:
A_top = A - 1
B_top = B - 1
top = (
B_top + (A - B_top - 1) // 2 if A_top > B_top else A_top + (B - A_top - 1) // 2
)
A_btm = N - A
B_btm = N - B
btm = B_btm + (A - B_btm) // 2 if A_btm > B_btm else A_btm + (N - B - A_btm) // 2
print(min(top, btm) + 1)
|
N, A, B = map(int, input().split())
if A % 2 == B % 2:
print(abs(A - B) // 2)
else:
A_top = A - 1
B_top = B - 1
top = (
B_top + (A - B_top - 1) // 2 if A_top > B_top else A_top + (B - A_top - 1) // 2
)
A_btm = N - A
B_btm = N - B
btm = (
B_btm + (N - A - B_btm) // 2 if A_btm > B_btm else A_btm + (N - B - A_btm) // 2
)
print(min(top, btm) + 1)
|
[
"assignment.change"
] | 626,878
| 626,879
|
u888092736
|
python
|
p02823
|
import sys
input = sys.stdin.readline
def main():
n,a,b = [int(i) for i in input().strip().split()]
if (b-a) % 2 == 0:
print(abs(b - a) // 2)
else:
ans = min(a - 1, n - b) - 1 + (b - a - 1) // 2
print(ans)
return
if __name__ == "__main__":
main()
|
import sys
input = sys.stdin.readline
def main():
n,a,b = [int(i) for i in input().strip().split()]
if (b-a) % 2 == 0:
print(abs(b - a) // 2)
else:
ans = min(a - 1, n - b) + 1 + (b - a - 1) // 2
print(ans)
return
if __name__ == "__main__":
main()
|
[
"misc.opposites",
"expression.operator.arithmetic.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 626,918
| 626,919
|
u397496203
|
python
|
p02823
|
import sys
input = sys.stdin.readline
def main():
n,a,b = [int(i) for i in input().strip().split()]
if (b-a) % 2 == 0:
print(abs(b - a) // 2)
else:
ans = min(a - 1, n - b) - 1 + (b - a - 1) // 2
print(ans)
return
if __name__ == "__main__":
main()
|
import sys
input = sys.stdin.readline
def main():
n,a,b = [int(i) for i in input().strip().split()]
if (b-a) % 2 == 0:
print(abs(b - a) // 2)
else:
ans = min(a - 1, n - b) + 1 + (b - a - 1) // 2
print(ans)
return
if __name__ == "__main__":
main()
|
[
"misc.opposites",
"expression.operator.arithmetic.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 626,918
| 626,921
|
u397496203
|
python
|
p02823
|
n, a, b = map(int, input().split())
d = b - a
if d % 2 == 0:
print(d//2)
else:
dd = d//2
ans = min(dd + a, n - b + 1 - dd)
print(ans)
|
n, a, b = map(int, input().split())
d = b - a
if d % 2 == 0:
print(d//2)
else:
dd = d//2
ans = min(dd + a, n - b + 1 + dd)
print(ans)
|
[
"misc.opposites",
"expression.operator.arithmetic.change",
"assignment.value.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 626,926
| 626,927
|
u309141201
|
python
|
p02823
|
N,A,B=map(int,input().split())
ans=0
if (B-A)%2==0:
ans=(B-A)//2
else:
if A-1<N-B:
if B-A==1:
ans=B-1
else:
ans=A+(B-A-1)//2
else:
if B-A==1:
ans=N-A
else:
ans=N-B-1+(A+N-B-1)//2
print(ans)
|
N,A,B=map(int,input().split())
ans=0
if (B-A)%2==0:
ans=(B-A)//2
else:
if A-1<N-B:
if B-A==1:
ans=B-1
else:
ans=A+(B-A-1)//2
else:
if B-A==1:
ans=N-A
else:
ans=N-B+1+(N-(A+N-B+1))//2
print(ans)
|
[
"misc.opposites",
"expression.operator.arithmetic.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 626,944
| 626,945
|
u075303794
|
python
|
p02823
|
n, a, b = map(int, input().split())
if a % 2 == b % 2:
print((b - a) // 2)
else:
print(min(a-1,b-1)+1+(b-a-1)//2)
|
n, a, b = map(int, input().split())
if a % 2 == b % 2:
print((b - a) // 2)
else:
print(min(a-1,n-b)+1+(b-a-1)//2)
|
[
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change",
"identifier.replace.add",
"literal.replace.remove"
] | 626,970
| 626,971
|
u867826040
|
python
|
p02823
|
#!/usr/bin/env python3
n, a, b = map(int, input().split())
if (b - a) % 2 < 1:
print((b - a) // 2)
else:
print(min((a + b - 1) // 2, (2 * n - a - b + 1)))
|
#!/usr/bin/env python3
n, a, b = map(int, input().split())
if (b - a) % 2 < 1:
print((b - a) // 2)
else:
print(min((a + b - 1) // 2, (2 * n - a - b + 1) // 2))
|
[
"expression.operation.binary.add"
] | 626,984
| 626,985
|
u094999522
|
python
|
p02823
|
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
MOD = 10 ** 4 + 7
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
print((B - A) // 2)
else:
ans = []
l = (A - 1)
r = B - l - 1
x = l + 1 + (r - 1) // 2
ans.append(x)
r = (N - B)
l = A + r
x = r + 1 + (r - l + 1) // 2
ans.append(x)
print(min(ans))
|
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
MOD = 10 ** 4 + 7
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
print((B - A) // 2)
else:
# print(min(A - 1, N - B) + 1 + (B - A - 1) // 2)
ans = []
l = (A - 1)
r = B - l - 1
x = l + 1 + (r - 1) // 2
ans.append(x)
r = (N - B)
l = A + r + 1
x = r + 1 + (N - l) // 2
ans.append(x)
print(min(ans))
|
[
"assignment.value.change",
"identifier.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 626,993
| 626,994
|
u036104576
|
python
|
p02823
|
N, A, B = map(int, input().split())
if (B-A-1) % 2 == 0:
val = min(A-1, N-B)
print((N-A-val-1)//2+val+1)
else:
print((B-A)//2)
|
N, A, B = map(int, input().split())
if (B-A-1) % 2 == 0:
val = min(A-1, N-B)
print((B-A-1)//2+val+1)
else:
print((B-A)//2)
|
[
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change",
"expression.operation.binary.remove"
] | 627,001
| 627,002
|
u289288647
|
python
|
p02823
|
N, A, B = map(int, input().split())
if (B-A-1) % 2 == 0:
val = min(A-1, N-B)
print((B-1)//2+1)
else:
print((B-A)//2)
|
N, A, B = map(int, input().split())
if (B-A-1) % 2 == 0:
val = min(A-1, N-B)
print((B-A-1)//2+val+1)
else:
print((B-A)//2)
|
[
"expression.operation.binary.add"
] | 627,003
| 627,002
|
u289288647
|
python
|
p02823
|
x,a,b=map(int,input().split())
if (b-a)%2 == 0:
print((b-a)//2)
else:
print(min( a + (b-a-1)//2, n - b + 1 + (b-a-1)//2) )
|
x,a,b=map(int,input().split())
if (b-a)%2 == 0:
print((b-a)//2)
else:
print(min( a + (b-a-1)//2, x - b + 1 + (b-a-1)//2) )
|
[
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 627,056
| 627,057
|
u566529875
|
python
|
p02823
|
N,A,B=map(int,input().split())
if (B-A)%2==1:
a=min(A-1,N-B)+1
b=(B-A)-1//2
print(a+b)
elif (B-A)%2==0:
print((B-A)//2)
|
N,A,B=map(int,input().split())
if (B-A)%2==1:
a=min(A-1,N-B)+1
b=((B-A)-1)//2
print(a+b)
elif (B-A)%2==0:
print((B-A)//2)
|
[] | 627,062
| 627,063
|
u079022693
|
python
|
p02823
|
import sys
input = sys.stdin.readline
MOD = 1000000007
N,A,B = map(int,input().split())
if abs(A-B)%2 == 0:
print(abs(A-B)//2)
else:
if (A-1) < (N-B):
print((A-1)+1+(B-A-1)//2)
else:
print((N-B)+1+(N-B-A)//2)
|
import sys
input = sys.stdin.readline
MOD = 1000000007
N,A,B = map(int,input().split())
if abs(A-B)%2 == 0:
print(abs(A-B)//2)
else:
if (A-1) < (N-B):
print((A-1)+1+(B-A-1)//2)
else:
print((N-B)+1+(B-A-1)//2)
|
[
"expression.operation.binary.remove"
] | 627,064
| 627,065
|
u846226907
|
python
|
p02823
|
n,a,b=[int(x) for x in input().split()]
if (a-b)%2==0:
print((a+b)//2)
else:
print(min(a-1,n-b)+1+(b-a-1)//2)
|
n,a,b=[int(x) for x in input().split()]
if (a+b)%2==0:
print((b-a)//2)
else:
print(min(a-1,n-b)+1+(b-a-1)//2)
|
[
"misc.opposites",
"expression.operator.arithmetic.change",
"control_flow.branch.if.condition.change",
"expression.operation.binary.remove"
] | 627,073
| 627,074
|
u026788530
|
python
|
p02823
|
n,a,b=[int(x) for x in input().split()]
if (a-b)%2==0:
print((a-b)//2)
else:
print(min(a-1,n-b)+1+(b-a-1)//2)
|
n,a,b=[int(x) for x in input().split()]
if (a+b)%2==0:
print((b-a)//2)
else:
print(min(a-1,n-b)+1+(b-a-1)//2)
|
[
"misc.opposites",
"expression.operator.arithmetic.change",
"control_flow.branch.if.condition.change",
"expression.operation.binary.remove"
] | 627,076
| 627,074
|
u026788530
|
python
|
p02823
|
n,a,b = map(int,input().split())
if a%2 == b%2:
print((b-a)//2)
else:
min(a-1,n-b)+1+(b-a-1)//2
|
n,a,b = map(int,input().split())
if a%2 == b%2:
print((b-a)//2)
else:
print(min(a-1,n-b)+1+(b-a-1)//2)
|
[
"call.add",
"call.arguments.change"
] | 627,081
| 627,082
|
u141410514
|
python
|
p02823
|
n, a, b = map(int, input().split())
# 偶奇一致
if a % 2 == b % 2:
print((b - a) // 2)
else:
# left = a - 1
# right = n - b
# if left > right:
# cnt = right + 1
# left = min(a + cnt, n)
# print((n - left) // 2 + cnt)
# else:
# cnt = left + 1
# right = max(b - cnt, 1)
# print((right - 1) // 2 + cnt)
print(min(a - 1, n - b) + 1 + (b - a + 1) // 2)
|
n, a, b = map(int, input().split())
# 偶奇一致
if a % 2 == b % 2:
print((b - a) // 2)
else:
# left = a - 1
# right = n - b
# if left > right:
# cnt = right + 1
# left = min(a + cnt, n)
# print((n - left) // 2 + cnt)
# else:
# cnt = left + 1
# right = max(b - cnt, 1)
# print((right - 1) // 2 + cnt)
print(min(a - 1, n - b) + 1 + (b - a - 1) // 2)
|
[
"misc.opposites",
"expression.operator.arithmetic.change",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 627,083
| 627,084
|
u506910932
|
python
|
p02823
|
n,a,b=map(int,input().split())
if (a+b)%2==0:
print(abs(a-b)//2)
else:
temp=min(b-1,n-a)
if temp==b-1:
ans=(b+a-1)//2
else:
ans=(n-b+b-a-1)//2
print(ans)
|
n,a,b=map(int,input().split())
if (a+b)%2==0:
print(abs(a-b)//2)
else:
temp=min(b-1,n-a)
if temp==b-1:
ans=(b+a-1)//2
else:
ans=(n+1-b+n+1-a-1)//2
print(ans)
|
[
"assignment.value.change",
"identifier.change",
"expression.operation.binary.change"
] | 627,100
| 627,101
|
u106778233
|
python
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.