user_id
stringlengths 10
10
| problem_id
stringlengths 6
6
| language
stringclasses 1
value | submission_id_v0
stringlengths 10
10
| submission_id_v1
stringlengths 10
10
| cpu_time_v0
int64 10
38.3k
| cpu_time_v1
int64 0
24.7k
| memory_v0
int64 2.57k
1.02M
| memory_v1
int64 2.57k
869k
| status_v0
stringclasses 1
value | status_v1
stringclasses 1
value | improvement_frac
float64 7.51
100
| input
stringlengths 20
4.55k
| target
stringlengths 17
3.34k
| code_v0_loc
int64 1
148
| code_v1_loc
int64 1
184
| code_v0_num_chars
int64 13
4.55k
| code_v1_num_chars
int64 14
3.34k
| code_v0_no_empty_lines
stringlengths 21
6.88k
| code_v1_no_empty_lines
stringlengths 20
4.93k
| code_same
bool 1
class | relative_loc_diff_percent
float64 0
79.8
| diff
list | diff_only_import_comment
bool 1
class | measured_runtime_v0
float64 0.01
4.45
| measured_runtime_v1
float64 0.01
4.31
| runtime_lift
float64 0
359
| key
list |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u285891772
|
p02702
|
python
|
s571390522
|
s689967109
| 392 | 124 | 24,928 | 13,568 |
Accepted
|
Accepted
| 68.37 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
S = eval(input())
n = len(S)
s = [0]
for i, x in enumerate(S):
s.append(int(S[i])*pow(10, n-i-1, 2019)%2019)
tmp = 0
t = []
for x in s:
tmp = (tmp+x)%2019
t.append(tmp)
ans = 0
for v in list(Counter(t).values()):
ans += v*(v-1)//2
print(ans)
|
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
S = list(map(int, list(eval(input()))))[::-1]
l = [0]*2019
l[0] = 1
tmp = 0
z = 1
for i, s in enumerate(S):
tmp += s*z
z = z*10%2019
l[tmp%2019] += 1
ans = 0
for v in l:
ans += v*(v-1)//2
print(ans)
| 39 | 41 | 1,197 | 1,165 |
import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
log2,
gcd,
)
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# mod = 998244353
from decimal import *
# import numpy as np
# decimal.getcontext().prec = 10
S = eval(input())
n = len(S)
s = [0]
for i, x in enumerate(S):
s.append(int(S[i]) * pow(10, n - i - 1, 2019) % 2019)
tmp = 0
t = []
for x in s:
tmp = (tmp + x) % 2019
t.append(tmp)
ans = 0
for v in list(Counter(t).values()):
ans += v * (v - 1) // 2
print(ans)
|
import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
log2,
gcd,
)
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# mod = 998244353
from decimal import *
# import numpy as np
# decimal.getcontext().prec = 10
S = list(map(int, list(eval(input()))))[::-1]
l = [0] * 2019
l[0] = 1
tmp = 0
z = 1
for i, s in enumerate(S):
tmp += s * z
z = z * 10 % 2019
l[tmp % 2019] += 1
ans = 0
for v in l:
ans += v * (v - 1) // 2
print(ans)
| false | 4.878049 |
[
"-S = eval(input())",
"-n = len(S)",
"-s = [0]",
"-for i, x in enumerate(S):",
"- s.append(int(S[i]) * pow(10, n - i - 1, 2019) % 2019)",
"+S = list(map(int, list(eval(input()))))[::-1]",
"+l = [0] * 2019",
"+l[0] = 1",
"-t = []",
"-for x in s:",
"- tmp = (tmp + x) % 2019",
"- t.append(tmp)",
"+z = 1",
"+for i, s in enumerate(S):",
"+ tmp += s * z",
"+ z = z * 10 % 2019",
"+ l[tmp % 2019] += 1",
"-for v in list(Counter(t).values()):",
"+for v in l:"
] | false | 0.037458 | 0.08358 | 0.448172 |
[
"s571390522",
"s689967109"
] |
u952467214
|
p02702
|
python
|
s903524642
|
s464766012
| 434 | 339 | 9,588 | 9,548 |
Accepted
|
Accepted
| 21.89 |
s = eval(input()) #sys.stdin.readlineは最後が改行
n =len(s)
from collections import defaultdict
amari = defaultdict(lambda:0)
amari[0]=1
num=0
tmp=0
ans =0
for i in range(n):
num = tmp + int(s[-1-i])*pow(10,i,2019)
tmp = num%2019
amari[tmp]+=1
if amari[tmp]>1:
val = amari[tmp]
ans -= (val-1)*(val-2)//2
ans += (val)*(val-1)//2
print(ans)
|
s = eval(input()) #sys.stdin.readlineは最後が改行
n =len(s)
from collections import defaultdict
amari = defaultdict(lambda:0)
amari[0]=1
num=0
tmp=0
for i in range(n):
num = tmp + int(s[-1-i])*pow(10,i,2019)
tmp = num%2019
amari[tmp]+=1
from math import factorial
ans = 0
for key,val in list(amari.items()):
if val>1:
ans +=val*(val-1)//2
print(ans)
| 23 | 22 | 395 | 382 |
s = eval(input()) # sys.stdin.readlineは最後が改行
n = len(s)
from collections import defaultdict
amari = defaultdict(lambda: 0)
amari[0] = 1
num = 0
tmp = 0
ans = 0
for i in range(n):
num = tmp + int(s[-1 - i]) * pow(10, i, 2019)
tmp = num % 2019
amari[tmp] += 1
if amari[tmp] > 1:
val = amari[tmp]
ans -= (val - 1) * (val - 2) // 2
ans += (val) * (val - 1) // 2
print(ans)
|
s = eval(input()) # sys.stdin.readlineは最後が改行
n = len(s)
from collections import defaultdict
amari = defaultdict(lambda: 0)
amari[0] = 1
num = 0
tmp = 0
for i in range(n):
num = tmp + int(s[-1 - i]) * pow(10, i, 2019)
tmp = num % 2019
amari[tmp] += 1
from math import factorial
ans = 0
for key, val in list(amari.items()):
if val > 1:
ans += val * (val - 1) // 2
print(ans)
| false | 4.347826 |
[
"-ans = 0",
"- if amari[tmp] > 1:",
"- val = amari[tmp]",
"- ans -= (val - 1) * (val - 2) // 2",
"- ans += (val) * (val - 1) // 2",
"+from math import factorial",
"+",
"+ans = 0",
"+for key, val in list(amari.items()):",
"+ if val > 1:",
"+ ans += val * (val - 1) // 2"
] | false | 0.036865 | 0.057512 | 0.640999 |
[
"s903524642",
"s464766012"
] |
u673173160
|
p02600
|
python
|
s094123381
|
s042426844
| 101 | 78 | 61,712 | 65,068 |
Accepted
|
Accepted
| 22.77 |
x = int(eval(input()))
print((10 - x//200))
|
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
read = sys.stdin.buffer.read
x = int(read())
print((10 - x//200))
| 2 | 8 | 36 | 265 |
x = int(eval(input()))
print((10 - x // 200))
|
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8")
inf = float("inf")
mod = 10**9 + 7
mans = inf
ans = 0
count = 0
pro = 1
read = sys.stdin.buffer.read
x = int(read())
print((10 - x // 200))
| false | 75 |
[
"-x = int(eval(input()))",
"+import sys, math, itertools, collections, bisect",
"+",
"+input = lambda: sys.stdin.buffer.readline().rstrip().decode(\"utf-8\")",
"+inf = float(\"inf\")",
"+mod = 10**9 + 7",
"+mans = inf",
"+ans = 0",
"+count = 0",
"+pro = 1",
"+read = sys.stdin.buffer.read",
"+x = int(read())"
] | false | 0.039188 | 0.042752 | 0.916635 |
[
"s094123381",
"s042426844"
] |
u376420711
|
p03699
|
python
|
s636999333
|
s670802570
| 19 | 17 | 2,940 | 2,940 |
Accepted
|
Accepted
| 10.53 |
n = int(eval(input()))
s = sorted([int(eval(input())) for i in range(n)])
ans = 0
if sum(s) % 10 != 0:
print((sum(s)))
else:
for i in s:
if i % 10 != 0:
ans = sum(s) - i
print(ans)
break
if ans == 0:
print(ans)
|
n = int(eval(input()))
s = sorted([int(eval(input())) for i in range(n)])
total = sum(s)
ans = 0
if total % 10 != 0:
print(total)
else:
for i in s:
if i % 10 != 0:
ans = total - i
break
print((max(0, ans)))
| 14 | 12 | 275 | 248 |
n = int(eval(input()))
s = sorted([int(eval(input())) for i in range(n)])
ans = 0
if sum(s) % 10 != 0:
print((sum(s)))
else:
for i in s:
if i % 10 != 0:
ans = sum(s) - i
print(ans)
break
if ans == 0:
print(ans)
|
n = int(eval(input()))
s = sorted([int(eval(input())) for i in range(n)])
total = sum(s)
ans = 0
if total % 10 != 0:
print(total)
else:
for i in s:
if i % 10 != 0:
ans = total - i
break
print((max(0, ans)))
| false | 14.285714 |
[
"+total = sum(s)",
"-if sum(s) % 10 != 0:",
"- print((sum(s)))",
"+if total % 10 != 0:",
"+ print(total)",
"- ans = sum(s) - i",
"- print(ans)",
"+ ans = total - i",
"- if ans == 0:",
"- print(ans)",
"+ print((max(0, ans)))"
] | false | 0.0087 | 0.043146 | 0.201646 |
[
"s636999333",
"s670802570"
] |
u481250941
|
p03416
|
python
|
s194575840
|
s741489740
| 106 | 96 | 16,172 | 16,124 |
Accepted
|
Accepted
| 9.43 |
#
# abc090 b
#
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """11009 11332"""
output = """4"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """31415 92653"""
output = """612"""
self.assertIO(input, output)
def resolve():
A, B = list(map(int, input().split()))
ans = 0
for i in range(A, B+1):
s = str(i)
for j in range(3):
if s[j] != s[-1-j]:
break
else:
ans += 1
print(ans)
if __name__ == "__main__":
# unittest.main()
resolve()
|
#
# abc090 b
#
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """11009 11332"""
output = """4"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """31415 92653"""
output = """612"""
self.assertIO(input, output)
def resolve():
A, B = list(map(int, input().split()))
ans = 0
for i in range(A, B+1):
s = str(i)
if s[0] == s[-1] and s[1] == s[-2]:
ans += 1
print(ans)
if __name__ == "__main__":
# unittest.main()
resolve()
| 45 | 42 | 1,016 | 962 |
#
# abc090 b
#
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """11009 11332"""
output = """4"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """31415 92653"""
output = """612"""
self.assertIO(input, output)
def resolve():
A, B = list(map(int, input().split()))
ans = 0
for i in range(A, B + 1):
s = str(i)
for j in range(3):
if s[j] != s[-1 - j]:
break
else:
ans += 1
print(ans)
if __name__ == "__main__":
# unittest.main()
resolve()
|
#
# abc090 b
#
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """11009 11332"""
output = """4"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """31415 92653"""
output = """612"""
self.assertIO(input, output)
def resolve():
A, B = list(map(int, input().split()))
ans = 0
for i in range(A, B + 1):
s = str(i)
if s[0] == s[-1] and s[1] == s[-2]:
ans += 1
print(ans)
if __name__ == "__main__":
# unittest.main()
resolve()
| false | 6.666667 |
[
"- for j in range(3):",
"- if s[j] != s[-1 - j]:",
"- break",
"- else:",
"+ if s[0] == s[-1] and s[1] == s[-2]:"
] | false | 0.458727 | 0.338232 | 1.356247 |
[
"s194575840",
"s741489740"
] |
u811817592
|
p02660
|
python
|
s648086999
|
s647492517
| 163 | 148 | 9,464 | 9,496 |
Accepted
|
Accepted
| 9.2 |
# -*- coding: utf-8 -*-
import collections
# factrize
def factorize(target_number):
factor = 2
factor_list = []
while factor * factor <= target_number:
while target_number % factor == 0:
target_number //= factor
factor_list.append(factor)
factor = factor + 1
if target_number > 1:
factor_list.append(target_number)
return factor_list
N = int(eval(input()))
fact_list = factorize(N)
fact_counter_dict = collections.Counter(fact_list)
ans = 0
for fact, freq in list(fact_counter_dict.items()):
freq_copy = freq
for i in range(1, freq + 1):
freq_copy -= i
if freq_copy < 0:
break
ans += 1
print(ans)
|
# -*- coding: utf-8 -*-
import collections
# factrize
def factorize(target_number):
factor = 2
factor_list = []
while factor * factor <= target_number:
while target_number % factor == 0:
target_number //= factor
factor_list.append(factor)
factor += 1
if target_number > 1:
factor_list.append(target_number)
return factor_list
N = int(eval(input()))
fact_list = factorize(N)
fact_counter_dict = collections.Counter(fact_list)
ans = 0
for fact, freq in list(fact_counter_dict.items()):
freq_copy = freq
for i in range(1, freq + 1):
freq_copy -= i
if freq_copy < 0:
break
ans += 1
print(ans)
| 29 | 29 | 727 | 719 |
# -*- coding: utf-8 -*-
import collections
# factrize
def factorize(target_number):
factor = 2
factor_list = []
while factor * factor <= target_number:
while target_number % factor == 0:
target_number //= factor
factor_list.append(factor)
factor = factor + 1
if target_number > 1:
factor_list.append(target_number)
return factor_list
N = int(eval(input()))
fact_list = factorize(N)
fact_counter_dict = collections.Counter(fact_list)
ans = 0
for fact, freq in list(fact_counter_dict.items()):
freq_copy = freq
for i in range(1, freq + 1):
freq_copy -= i
if freq_copy < 0:
break
ans += 1
print(ans)
|
# -*- coding: utf-8 -*-
import collections
# factrize
def factorize(target_number):
factor = 2
factor_list = []
while factor * factor <= target_number:
while target_number % factor == 0:
target_number //= factor
factor_list.append(factor)
factor += 1
if target_number > 1:
factor_list.append(target_number)
return factor_list
N = int(eval(input()))
fact_list = factorize(N)
fact_counter_dict = collections.Counter(fact_list)
ans = 0
for fact, freq in list(fact_counter_dict.items()):
freq_copy = freq
for i in range(1, freq + 1):
freq_copy -= i
if freq_copy < 0:
break
ans += 1
print(ans)
| false | 0 |
[
"- factor = factor + 1",
"+ factor += 1"
] | false | 0.049704 | 0.046745 | 1.063297 |
[
"s648086999",
"s647492517"
] |
u627803856
|
p02792
|
python
|
s885885613
|
s392180734
| 173 | 86 | 3,188 | 73,528 |
Accepted
|
Accepted
| 50.29 |
n=int(eval(input()))
cnt=[[0]*10 for i in range(10)] #(10,10)サイズの配列
ret = 0
def hoge(m):
#return m[-1],m[0]
return (m%10, int(str(m)[0]))
for k in range(1,n+1):
a,b = hoge(k)
cnt[a][b] += 1
for i in range(1,10):
for j in range(1,10):
ret += cnt[i][j] * cnt[j][i]
print(ret)
|
n = int(eval(input()))
count = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
now = str(i)
pre, pos = int(now[0]), int(now[-1])
if pos == 0: continue
count[pre][pos] += 1
res = 0
for i in range(1, 10):
for j in range(1, 10):
res += count[i][j] * count[j][i]
print(res)
| 17 | 17 | 319 | 321 |
n = int(eval(input()))
cnt = [[0] * 10 for i in range(10)] # (10,10)サイズの配列
ret = 0
def hoge(m):
# return m[-1],m[0]
return (m % 10, int(str(m)[0]))
for k in range(1, n + 1):
a, b = hoge(k)
cnt[a][b] += 1
for i in range(1, 10):
for j in range(1, 10):
ret += cnt[i][j] * cnt[j][i]
print(ret)
|
n = int(eval(input()))
count = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
now = str(i)
pre, pos = int(now[0]), int(now[-1])
if pos == 0:
continue
count[pre][pos] += 1
res = 0
for i in range(1, 10):
for j in range(1, 10):
res += count[i][j] * count[j][i]
print(res)
| false | 0 |
[
"-cnt = [[0] * 10 for i in range(10)] # (10,10)サイズの配列",
"-ret = 0",
"-",
"-",
"-def hoge(m):",
"- # return m[-1],m[0]",
"- return (m % 10, int(str(m)[0]))",
"-",
"-",
"-for k in range(1, n + 1):",
"- a, b = hoge(k)",
"- cnt[a][b] += 1",
"+count = [[0] * 10 for _ in range(10)]",
"+for i in range(1, n + 1):",
"+ now = str(i)",
"+ pre, pos = int(now[0]), int(now[-1])",
"+ if pos == 0:",
"+ continue",
"+ count[pre][pos] += 1",
"+res = 0",
"- ret += cnt[i][j] * cnt[j][i]",
"-print(ret)",
"+ res += count[i][j] * count[j][i]",
"+print(res)"
] | false | 0.060473 | 0.126547 | 0.477865 |
[
"s885885613",
"s392180734"
] |
u806403461
|
p03944
|
python
|
s482220584
|
s351457853
| 67 | 23 | 3,188 | 9,140 |
Accepted
|
Accepted
| 65.67 |
w, h, n = list(map(int, input().split()))
l = list()
for i in range(0, n):
x, y, a = list(map(int, input().split()))
l.append([x, y, a])
white_check = list()
for a in range(0, h):
white_check.append([1]*w)
for i in range(0, n):
a = l[i][2]
height = l[i][1]
width = l[i][0]
if a == 1:
for y in range(0, h):
for x in range(0, width):
white_check[y][x] = 0
elif a == 2:
for y in range(0, h):
for x in range(width, w):
white_check[y][x] = 0
elif a == 3:
for y in range(0, height):
for x in range(0, w):
white_check[y][x] = 0
else:
for y in range(height, h):
for x in range(0, w):
white_check[y][x] = 0
s = 0
for a in range(h):
s += sum(white_check[a])
print(s)
|
W, H, N = list(map(int, input().split()))
X = Y = 0
for i in range(0, N):
x, y, a = list(map(int, input().split()))
if a == 1:
X = max(X, x)
elif a == 2:
W = min(W, x)
elif a == 3:
Y = max(Y, y)
else:
H = min(H, y)
print((max(W-X, 0)*max(H-Y, 0)))
| 38 | 17 | 876 | 306 |
w, h, n = list(map(int, input().split()))
l = list()
for i in range(0, n):
x, y, a = list(map(int, input().split()))
l.append([x, y, a])
white_check = list()
for a in range(0, h):
white_check.append([1] * w)
for i in range(0, n):
a = l[i][2]
height = l[i][1]
width = l[i][0]
if a == 1:
for y in range(0, h):
for x in range(0, width):
white_check[y][x] = 0
elif a == 2:
for y in range(0, h):
for x in range(width, w):
white_check[y][x] = 0
elif a == 3:
for y in range(0, height):
for x in range(0, w):
white_check[y][x] = 0
else:
for y in range(height, h):
for x in range(0, w):
white_check[y][x] = 0
s = 0
for a in range(h):
s += sum(white_check[a])
print(s)
|
W, H, N = list(map(int, input().split()))
X = Y = 0
for i in range(0, N):
x, y, a = list(map(int, input().split()))
if a == 1:
X = max(X, x)
elif a == 2:
W = min(W, x)
elif a == 3:
Y = max(Y, y)
else:
H = min(H, y)
print((max(W - X, 0) * max(H - Y, 0)))
| false | 55.263158 |
[
"-w, h, n = list(map(int, input().split()))",
"-l = list()",
"-for i in range(0, n):",
"+W, H, N = list(map(int, input().split()))",
"+X = Y = 0",
"+for i in range(0, N):",
"- l.append([x, y, a])",
"-white_check = list()",
"-for a in range(0, h):",
"- white_check.append([1] * w)",
"-for i in range(0, n):",
"- a = l[i][2]",
"- height = l[i][1]",
"- width = l[i][0]",
"- for y in range(0, h):",
"- for x in range(0, width):",
"- white_check[y][x] = 0",
"+ X = max(X, x)",
"- for y in range(0, h):",
"- for x in range(width, w):",
"- white_check[y][x] = 0",
"+ W = min(W, x)",
"- for y in range(0, height):",
"- for x in range(0, w):",
"- white_check[y][x] = 0",
"+ Y = max(Y, y)",
"- for y in range(height, h):",
"- for x in range(0, w):",
"- white_check[y][x] = 0",
"-s = 0",
"-for a in range(h):",
"- s += sum(white_check[a])",
"-print(s)",
"+ H = min(H, y)",
"+print((max(W - X, 0) * max(H - Y, 0)))"
] | false | 0.074525 | 0.07468 | 0.997918 |
[
"s482220584",
"s351457853"
] |
u315078622
|
p03568
|
python
|
s984205299
|
s527605808
| 20 | 17 | 3,060 | 2,940 |
Accepted
|
Accepted
| 15 |
N = int(eval(input()))
A = [int(x) for x in input().split()]
ret = 0
for state in range(1 << N):
flag = False
ans = 1
for i in range(N):
if (state >> i & 1):
if A[i] % 2 == 1:
flag = True
ans *= 2
else:
if A[i] % 2 == 0:
flag = True
if flag:
ret += ans
print(ret)
|
def main() -> None:
N = int(eval(input()))
ans = 3 ** N
odd = 1
for a in map(int, input().split()):
if a % 2 == 0:
odd *= 2
print((ans - odd))
if __name__ == '__main__':
main()
| 17 | 12 | 382 | 226 |
N = int(eval(input()))
A = [int(x) for x in input().split()]
ret = 0
for state in range(1 << N):
flag = False
ans = 1
for i in range(N):
if state >> i & 1:
if A[i] % 2 == 1:
flag = True
ans *= 2
else:
if A[i] % 2 == 0:
flag = True
if flag:
ret += ans
print(ret)
|
def main() -> None:
N = int(eval(input()))
ans = 3**N
odd = 1
for a in map(int, input().split()):
if a % 2 == 0:
odd *= 2
print((ans - odd))
if __name__ == "__main__":
main()
| false | 29.411765 |
[
"-N = int(eval(input()))",
"-A = [int(x) for x in input().split()]",
"-ret = 0",
"-for state in range(1 << N):",
"- flag = False",
"- ans = 1",
"- for i in range(N):",
"- if state >> i & 1:",
"- if A[i] % 2 == 1:",
"- flag = True",
"- ans *= 2",
"- else:",
"- if A[i] % 2 == 0:",
"- flag = True",
"- if flag:",
"- ret += ans",
"-print(ret)",
"+def main() -> None:",
"+ N = int(eval(input()))",
"+ ans = 3**N",
"+ odd = 1",
"+ for a in map(int, input().split()):",
"+ if a % 2 == 0:",
"+ odd *= 2",
"+ print((ans - odd))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.045839 | 0.043556 | 1.052402 |
[
"s984205299",
"s527605808"
] |
u513081876
|
p03814
|
python
|
s297750278
|
s401154479
| 41 | 37 | 10,396 | 8,860 |
Accepted
|
Accepted
| 9.76 |
S = list(eval(input()))
Z_max = [i for i, x in enumerate(S) if x == 'Z']
print((len(S[S.index('A'):max(Z_max)+1])))
|
S = list(eval(input()))
ind_A = S.index('A')
ind_Z = [index for index, x in enumerate(S) if x == 'Z']
print((ind_Z[-1]-ind_A+1))
| 3 | 5 | 109 | 125 |
S = list(eval(input()))
Z_max = [i for i, x in enumerate(S) if x == "Z"]
print((len(S[S.index("A") : max(Z_max) + 1])))
|
S = list(eval(input()))
ind_A = S.index("A")
ind_Z = [index for index, x in enumerate(S) if x == "Z"]
print((ind_Z[-1] - ind_A + 1))
| false | 40 |
[
"-Z_max = [i for i, x in enumerate(S) if x == \"Z\"]",
"-print((len(S[S.index(\"A\") : max(Z_max) + 1])))",
"+ind_A = S.index(\"A\")",
"+ind_Z = [index for index, x in enumerate(S) if x == \"Z\"]",
"+print((ind_Z[-1] - ind_A + 1))"
] | false | 0.127533 | 0.106796 | 1.194172 |
[
"s297750278",
"s401154479"
] |
u079022693
|
p02861
|
python
|
s253422648
|
s332112916
| 208 | 17 | 40,684 | 3,064 |
Accepted
|
Accepted
| 91.83 |
import math
import itertools
N=int(eval(input()))
X=list()
Y=list()
for i in range(N):
x,y=list(map(int,input().split()))
X.append(x)
Y.append(y)
numbers=[c for c in range(N)]
kyori=0
for i in itertools.permutations(numbers,N):
for j in range(N-1):
mae=i[j]
usiro=i[j+1]
kyori+=(((X[usiro]-X[mae])**2)+((Y[usiro]-Y[mae])**2))**0.5
N_f=math.factorial(N)
print((kyori/N_f))
|
from sys import stdin
def main():
#入力
readline=stdin.readline
N=int(readline())
N_kaijo=1
for i in range(1,N+1):
N_kaijo*=i
x=[]
y=[]
for i in range(N):
x_i,y_i=list(map(int,readline().split()))
x.append(x_i)
y.append(y_i)
res=0
for i in range(N-1):
for j in range(i+1,N):
l=((x[j]-x[i])**2+(y[j]-y[i])**2)**0.5
res+=l*2/N
print(res)
if __name__=="__main__":
main()
| 21 | 25 | 410 | 502 |
import math
import itertools
N = int(eval(input()))
X = list()
Y = list()
for i in range(N):
x, y = list(map(int, input().split()))
X.append(x)
Y.append(y)
numbers = [c for c in range(N)]
kyori = 0
for i in itertools.permutations(numbers, N):
for j in range(N - 1):
mae = i[j]
usiro = i[j + 1]
kyori += (((X[usiro] - X[mae]) ** 2) + ((Y[usiro] - Y[mae]) ** 2)) ** 0.5
N_f = math.factorial(N)
print((kyori / N_f))
|
from sys import stdin
def main():
# 入力
readline = stdin.readline
N = int(readline())
N_kaijo = 1
for i in range(1, N + 1):
N_kaijo *= i
x = []
y = []
for i in range(N):
x_i, y_i = list(map(int, readline().split()))
x.append(x_i)
y.append(y_i)
res = 0
for i in range(N - 1):
for j in range(i + 1, N):
l = ((x[j] - x[i]) ** 2 + (y[j] - y[i]) ** 2) ** 0.5
res += l * 2 / N
print(res)
if __name__ == "__main__":
main()
| false | 16 |
[
"-import math",
"-import itertools",
"+from sys import stdin",
"-N = int(eval(input()))",
"-X = list()",
"-Y = list()",
"-for i in range(N):",
"- x, y = list(map(int, input().split()))",
"- X.append(x)",
"- Y.append(y)",
"-numbers = [c for c in range(N)]",
"-kyori = 0",
"-for i in itertools.permutations(numbers, N):",
"- for j in range(N - 1):",
"- mae = i[j]",
"- usiro = i[j + 1]",
"- kyori += (((X[usiro] - X[mae]) ** 2) + ((Y[usiro] - Y[mae]) ** 2)) ** 0.5",
"-N_f = math.factorial(N)",
"-print((kyori / N_f))",
"+",
"+def main():",
"+ # 入力",
"+ readline = stdin.readline",
"+ N = int(readline())",
"+ N_kaijo = 1",
"+ for i in range(1, N + 1):",
"+ N_kaijo *= i",
"+ x = []",
"+ y = []",
"+ for i in range(N):",
"+ x_i, y_i = list(map(int, readline().split()))",
"+ x.append(x_i)",
"+ y.append(y_i)",
"+ res = 0",
"+ for i in range(N - 1):",
"+ for j in range(i + 1, N):",
"+ l = ((x[j] - x[i]) ** 2 + (y[j] - y[i]) ** 2) ** 0.5",
"+ res += l * 2 / N",
"+ print(res)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.082944 | 0.040148 | 2.065977 |
[
"s253422648",
"s332112916"
] |
u185896732
|
p02947
|
python
|
s726759634
|
s164528046
| 604 | 335 | 68,696 | 64,220 |
Accepted
|
Accepted
| 44.54 |
import os,re,sys,operator
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
from copy import deepcopy
import heapq
setrecursionlimit(10**6)
n=int(eval(input()))
s=["".join(sorted(eval(input()))) for _ in range(n)]
t=list(Counter(s).values())
ans=0
for i in t:
ans+=sum(range(1,i))
print(ans)
|
import os,re,sys,operator
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
from copy import deepcopy
import heapq
setrecursionlimit(10**6)
n=int(stdin.readline().rstrip())
s=["".join(sorted(stdin.readline().rstrip())) for _ in range(n)]
t=list(Counter(s).values())
ans=0
for i in t:
ans+=sum(range(1,i))
print(ans)
| 17 | 17 | 409 | 445 |
import os, re, sys, operator
from collections import Counter, deque
from operator import itemgetter
from itertools import accumulate, combinations, groupby
from sys import stdin, setrecursionlimit
from copy import deepcopy
import heapq
setrecursionlimit(10**6)
n = int(eval(input()))
s = ["".join(sorted(eval(input()))) for _ in range(n)]
t = list(Counter(s).values())
ans = 0
for i in t:
ans += sum(range(1, i))
print(ans)
|
import os, re, sys, operator
from collections import Counter, deque
from operator import itemgetter
from itertools import accumulate, combinations, groupby
from sys import stdin, setrecursionlimit
from copy import deepcopy
import heapq
setrecursionlimit(10**6)
n = int(stdin.readline().rstrip())
s = ["".join(sorted(stdin.readline().rstrip())) for _ in range(n)]
t = list(Counter(s).values())
ans = 0
for i in t:
ans += sum(range(1, i))
print(ans)
| false | 0 |
[
"-n = int(eval(input()))",
"-s = [\"\".join(sorted(eval(input()))) for _ in range(n)]",
"+n = int(stdin.readline().rstrip())",
"+s = [\"\".join(sorted(stdin.readline().rstrip())) for _ in range(n)]"
] | false | 0.045617 | 0.045839 | 0.99516 |
[
"s726759634",
"s164528046"
] |
u327466606
|
p02744
|
python
|
s727655411
|
s337484429
| 593 | 523 | 13,576 | 13,576 |
Accepted
|
Accepted
| 11.8 |
N = int(input())
def it(remain,n):
if remain == 0:
yield []
else:
for x in range(n+1):
for d in it(remain-1,max(x+1,n)):
d.append(x)
yield d
print(*(''.join(chr(x+ord('a')) for x in reversed(d)) for d in it(N,0)), sep='\n')
|
N = int(input())
def it(i,n):
if i == N:
yield [None]*N
else:
for x in range(n):
for d in it(i+1,n):
d[i] = x
yield d
for d in it(i+1,n+1):
d[i] = n
yield d
print(*(''.join(chr(x+ord('a')) for x in d) for d in it(0,0)), sep='\n')
| 14 | 16 | 309 | 348 |
N = int(input())
def it(remain, n):
if remain == 0:
yield []
else:
for x in range(n + 1):
for d in it(remain - 1, max(x + 1, n)):
d.append(x)
yield d
print(*("".join(chr(x + ord("a")) for x in reversed(d)) for d in it(N, 0)), sep="\n")
|
N = int(input())
def it(i, n):
if i == N:
yield [None] * N
else:
for x in range(n):
for d in it(i + 1, n):
d[i] = x
yield d
for d in it(i + 1, n + 1):
d[i] = n
yield d
print(*("".join(chr(x + ord("a")) for x in d) for d in it(0, 0)), sep="\n")
| false | 12.5 |
[
"-def it(remain, n):",
"- if remain == 0:",
"- yield []",
"+def it(i, n):",
"+ if i == N:",
"+ yield [None] * N",
"- for x in range(n + 1):",
"- for d in it(remain - 1, max(x + 1, n)):",
"- d.append(x)",
"+ for x in range(n):",
"+ for d in it(i + 1, n):",
"+ d[i] = x",
"+ for d in it(i + 1, n + 1):",
"+ d[i] = n",
"+ yield d",
"-print(*(\"\".join(chr(x + ord(\"a\")) for x in reversed(d)) for d in it(N, 0)), sep=\"\\n\")",
"+print(*(\"\".join(chr(x + ord(\"a\")) for x in d) for d in it(0, 0)), sep=\"\\n\")"
] | false | 0.038302 | 0.037152 | 1.030961 |
[
"s727655411",
"s337484429"
] |
u773265208
|
p02995
|
python
|
s936473396
|
s686682882
| 36 | 22 | 5,076 | 3,572 |
Accepted
|
Accepted
| 38.89 |
import math
from decimal import *
getcontext().prec = 50
a,b,c,d = list(map(int,input().split()))
from functools import reduce
def gcd(a,b):
if a < b:
a, b = b, a
while a % b != 0:
a, b = b, a % b
return b
def lcm_base(x, y):
return (x * y) // gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
gcd = lcm_list([c,d])
def solve(n):
start = n * math.ceil(Decimal(a) / Decimal(n))
end = n * (Decimal(b) // Decimal(n))
#print(start,end)
return (end - start) // n + 1
#print(solve(c),solve(d),solve(gcd))
ans = solve(c) + solve(d) - solve(gcd)
#print(ans)
print((b - a - ans + 1))
|
from functools import reduce
def gcd(a,b):
if a < b:
a, b = b, a
while a % b != 0:
a, b = b, a % b
return b
def lcm_base(x, y):
return (x * y) // gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
a,b,c,d = list(map(int,input().split()))
lcm = lcm_list([c,d])
res1 = a - 1 - ((a - 1) // c + (a - 1) // d - (a - 1) // lcm)
res2 = b - (b // c + b // d - b // lcm)
print((res2 - res1))
| 31 | 23 | 644 | 440 |
import math
from decimal import *
getcontext().prec = 50
a, b, c, d = list(map(int, input().split()))
from functools import reduce
def gcd(a, b):
if a < b:
a, b = b, a
while a % b != 0:
a, b = b, a % b
return b
def lcm_base(x, y):
return (x * y) // gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
gcd = lcm_list([c, d])
def solve(n):
start = n * math.ceil(Decimal(a) / Decimal(n))
end = n * (Decimal(b) // Decimal(n))
# print(start,end)
return (end - start) // n + 1
# print(solve(c),solve(d),solve(gcd))
ans = solve(c) + solve(d) - solve(gcd)
# print(ans)
print((b - a - ans + 1))
|
from functools import reduce
def gcd(a, b):
if a < b:
a, b = b, a
while a % b != 0:
a, b = b, a % b
return b
def lcm_base(x, y):
return (x * y) // gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
a, b, c, d = list(map(int, input().split()))
lcm = lcm_list([c, d])
res1 = a - 1 - ((a - 1) // c + (a - 1) // d - (a - 1) // lcm)
res2 = b - (b // c + b // d - b // lcm)
print((res2 - res1))
| false | 25.806452 |
[
"-import math",
"-from decimal import *",
"-",
"-getcontext().prec = 50",
"-a, b, c, d = list(map(int, input().split()))",
"-gcd = lcm_list([c, d])",
"-",
"-",
"-def solve(n):",
"- start = n * math.ceil(Decimal(a) / Decimal(n))",
"- end = n * (Decimal(b) // Decimal(n))",
"- # print(start,end)",
"- return (end - start) // n + 1",
"-",
"-",
"-# print(solve(c),solve(d),solve(gcd))",
"-ans = solve(c) + solve(d) - solve(gcd)",
"-# print(ans)",
"-print((b - a - ans + 1))",
"+a, b, c, d = list(map(int, input().split()))",
"+lcm = lcm_list([c, d])",
"+res1 = a - 1 - ((a - 1) // c + (a - 1) // d - (a - 1) // lcm)",
"+res2 = b - (b // c + b // d - b // lcm)",
"+print((res2 - res1))"
] | false | 0.061396 | 0.082331 | 0.745725 |
[
"s936473396",
"s686682882"
] |
u222668979
|
p03169
|
python
|
s359292281
|
s563733644
| 1,390 | 1,234 | 254,088 | 254,600 |
Accepted
|
Accepted
| 11.22 |
from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
cnt = Counter(a)
p, q, r = cnt[1], cnt[2], cnt[3]
dp = [[[0.0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
for k in range(r + 1):
for j in range(r + q + 1):
for i in range(n + 1):
if not (0 < i + j + k <= n):
continue
tmp = 0.0
if i > 0:
tmp += dp[i - 1][j][k] * i
if j > 0:
tmp += dp[i + 1][j - 1][k] * j
if k > 0:
tmp += dp[i][j + 1][k - 1] * k
tmp += n
dp[i][j][k] = tmp / (i + j + k)
print((dp[p][q][r]))
|
from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
cnt = Counter(a)
p, q, r = cnt[1], cnt[2], cnt[3]
dp = [[[0.0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
for k in range(r + 1):
for j in range(r + q + 1):
for i in range(n + 1):
if not (0 < i + j + k <= n):
continue
if i > 0:
dp[i][j][k] += dp[i - 1][j][k] * i
if j > 0:
dp[i][j][k] += dp[i + 1][j - 1][k] * j
if k > 0:
dp[i][j][k] += dp[i][j + 1][k - 1] * k
dp[i][j][k] += n
dp[i][j][k] /= (i + j + k)
print((dp[p][q][r]))
| 25 | 24 | 692 | 696 |
from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
cnt = Counter(a)
p, q, r = cnt[1], cnt[2], cnt[3]
dp = [[[0.0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
for k in range(r + 1):
for j in range(r + q + 1):
for i in range(n + 1):
if not (0 < i + j + k <= n):
continue
tmp = 0.0
if i > 0:
tmp += dp[i - 1][j][k] * i
if j > 0:
tmp += dp[i + 1][j - 1][k] * j
if k > 0:
tmp += dp[i][j + 1][k - 1] * k
tmp += n
dp[i][j][k] = tmp / (i + j + k)
print((dp[p][q][r]))
|
from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
cnt = Counter(a)
p, q, r = cnt[1], cnt[2], cnt[3]
dp = [[[0.0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
for k in range(r + 1):
for j in range(r + q + 1):
for i in range(n + 1):
if not (0 < i + j + k <= n):
continue
if i > 0:
dp[i][j][k] += dp[i - 1][j][k] * i
if j > 0:
dp[i][j][k] += dp[i + 1][j - 1][k] * j
if k > 0:
dp[i][j][k] += dp[i][j + 1][k - 1] * k
dp[i][j][k] += n
dp[i][j][k] /= i + j + k
print((dp[p][q][r]))
| false | 4 |
[
"- tmp = 0.0",
"- tmp += dp[i - 1][j][k] * i",
"+ dp[i][j][k] += dp[i - 1][j][k] * i",
"- tmp += dp[i + 1][j - 1][k] * j",
"+ dp[i][j][k] += dp[i + 1][j - 1][k] * j",
"- tmp += dp[i][j + 1][k - 1] * k",
"- tmp += n",
"- dp[i][j][k] = tmp / (i + j + k)",
"+ dp[i][j][k] += dp[i][j + 1][k - 1] * k",
"+ dp[i][j][k] += n",
"+ dp[i][j][k] /= i + j + k"
] | false | 0.114327 | 0.038381 | 2.978711 |
[
"s359292281",
"s563733644"
] |
u840247626
|
p02260
|
python
|
s904431129
|
s285416482
| 30 | 20 | 5,604 | 5,608 |
Accepted
|
Accepted
| 33.33 |
n = int(eval(input()))
a = list(map(int, input().split()))
count = 0
for i in range(0, n):
minj = min(list(range(i, n)), key=lambda j: a[j])
if i != minj:
a[i], a[minj] = a[minj], a[i]
count += 1
print((*a))
print(count)
|
n = int(eval(input()))
a = list(map(int, input().split()))
count = 0
for i in range(n):
minj = min(list(range(i, n)), key=lambda j: a[j])
if i != minj:
a[i], a[minj] = a[minj], a[i]
count += 1
print((*a))
print(count)
| 10 | 10 | 222 | 219 |
n = int(eval(input()))
a = list(map(int, input().split()))
count = 0
for i in range(0, n):
minj = min(list(range(i, n)), key=lambda j: a[j])
if i != minj:
a[i], a[minj] = a[minj], a[i]
count += 1
print((*a))
print(count)
|
n = int(eval(input()))
a = list(map(int, input().split()))
count = 0
for i in range(n):
minj = min(list(range(i, n)), key=lambda j: a[j])
if i != minj:
a[i], a[minj] = a[minj], a[i]
count += 1
print((*a))
print(count)
| false | 0 |
[
"-for i in range(0, n):",
"+for i in range(n):"
] | false | 0.045859 | 0.045001 | 1.01907 |
[
"s904431129",
"s285416482"
] |
u729133443
|
p02555
|
python
|
s582591957
|
s017979379
| 370 | 170 | 9,816 | 9,764 |
Accepted
|
Accepted
| 54.05 |
from functools import*
M=10**9+7
@lru_cache(None)
def f(s):
if s<3:return 0
c=1
for i in range(s-2):
c+=f(i)
return(sum(map(f,list(range(s-2))))+1)%M
print((f(int(eval(input())))))
|
from functools import*
M=10**9+7
@lru_cache(None)
def f(s):
if s<3:return 0
return(sum(map(f,list(range(s-2))))+1)%M
print((f(int(eval(input())))))
| 10 | 7 | 199 | 147 |
from functools import *
M = 10**9 + 7
@lru_cache(None)
def f(s):
if s < 3:
return 0
c = 1
for i in range(s - 2):
c += f(i)
return (sum(map(f, list(range(s - 2)))) + 1) % M
print((f(int(eval(input())))))
|
from functools import *
M = 10**9 + 7
@lru_cache(None)
def f(s):
if s < 3:
return 0
return (sum(map(f, list(range(s - 2)))) + 1) % M
print((f(int(eval(input())))))
| false | 30 |
[
"- c = 1",
"- for i in range(s - 2):",
"- c += f(i)"
] | false | 0.240121 | 0.04995 | 4.807256 |
[
"s582591957",
"s017979379"
] |
u757117214
|
p02952
|
python
|
s357326758
|
s429085843
| 63 | 52 | 3,316 | 6,720 |
Accepted
|
Accepted
| 17.46 |
n=int(eval(input()))
cnt=0
for i in range(1,n+1):
if len(str(i))%2==1:
cnt+=1
print(cnt)
|
n=int(eval(input()))
print((len([i for i in range(1,n+1) if len(str(i))%2==1])))
| 6 | 2 | 97 | 73 |
n = int(eval(input()))
cnt = 0
for i in range(1, n + 1):
if len(str(i)) % 2 == 1:
cnt += 1
print(cnt)
|
n = int(eval(input()))
print((len([i for i in range(1, n + 1) if len(str(i)) % 2 == 1])))
| false | 66.666667 |
[
"-cnt = 0",
"-for i in range(1, n + 1):",
"- if len(str(i)) % 2 == 1:",
"- cnt += 1",
"-print(cnt)",
"+print((len([i for i in range(1, n + 1) if len(str(i)) % 2 == 1])))"
] | false | 0.060046 | 0.069914 | 0.858866 |
[
"s357326758",
"s429085843"
] |
u957167787
|
p02900
|
python
|
s568392024
|
s982828387
| 201 | 110 | 3,064 | 3,064 |
Accepted
|
Accepted
| 45.27 |
import math
A, B = list(map(int, input().split()))
# 素因数の個数(cnt)は使わないので省いた
def prime_factorize(n):
res = [] # 結果を格納
tmp = n # tmpにnをコピーしておく
for i in range(2, int(math.sqrt(n))+1):
if tmp % i == 0:
while tmp % i == 0:
tmp //= i
res.append(i)
# tmpに余った素数の処理
if tmp != 1:
res.append(tmp)
# 何も割れなかったらnは素数なのでそのまま入れておく
if res == [] and n != 1:
res.append(n)
return(res)
A_fac = set(prime_factorize(A))
B_fac = set(prime_factorize(B))
C = A_fac & B_fac
ans = len(C) + 1
print(ans)
|
import math
A, B = list(map(int, input().split()))
def gcd(a, b):
if b == 0:
return(a)
else:
return(gcd(b, a % b))
def prime_factorize(n):
res = []
tmp = n
for i in range(2, int(math.sqrt(n))+1):
if tmp % i == 0:
cnt = 0
while tmp % i == 0:
cnt += 1
tmp //= i
res.append([i, cnt])
if tmp != 1:
res.append([tmp, 1])
if len(res) == 0 and n != 1:
res.append([n, 1])
return(res)
c = gcd(A, B)
#print(c)
div = prime_factorize(c)
#print(div)
ans = len(div) + 1
print(ans)
| 31 | 37 | 601 | 645 |
import math
A, B = list(map(int, input().split()))
# 素因数の個数(cnt)は使わないので省いた
def prime_factorize(n):
res = [] # 結果を格納
tmp = n # tmpにnをコピーしておく
for i in range(2, int(math.sqrt(n)) + 1):
if tmp % i == 0:
while tmp % i == 0:
tmp //= i
res.append(i)
# tmpに余った素数の処理
if tmp != 1:
res.append(tmp)
# 何も割れなかったらnは素数なのでそのまま入れておく
if res == [] and n != 1:
res.append(n)
return res
A_fac = set(prime_factorize(A))
B_fac = set(prime_factorize(B))
C = A_fac & B_fac
ans = len(C) + 1
print(ans)
|
import math
A, B = list(map(int, input().split()))
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
def prime_factorize(n):
res = []
tmp = n
for i in range(2, int(math.sqrt(n)) + 1):
if tmp % i == 0:
cnt = 0
while tmp % i == 0:
cnt += 1
tmp //= i
res.append([i, cnt])
if tmp != 1:
res.append([tmp, 1])
if len(res) == 0 and n != 1:
res.append([n, 1])
return res
c = gcd(A, B)
# print(c)
div = prime_factorize(c)
# print(div)
ans = len(div) + 1
print(ans)
| false | 16.216216 |
[
"-# 素因数の個数(cnt)は使わないので省いた",
"+",
"+",
"+def gcd(a, b):",
"+ if b == 0:",
"+ return a",
"+ else:",
"+ return gcd(b, a % b)",
"+",
"+",
"- res = [] # 結果を格納",
"- tmp = n # tmpにnをコピーしておく",
"+ res = []",
"+ tmp = n",
"+ cnt = 0",
"+ cnt += 1",
"- res.append(i)",
"- # tmpに余った素数の処理",
"+ res.append([i, cnt])",
"- res.append(tmp)",
"- # 何も割れなかったらnは素数なのでそのまま入れておく",
"- if res == [] and n != 1:",
"- res.append(n)",
"+ res.append([tmp, 1])",
"+ if len(res) == 0 and n != 1:",
"+ res.append([n, 1])",
"-A_fac = set(prime_factorize(A))",
"-B_fac = set(prime_factorize(B))",
"-C = A_fac & B_fac",
"-ans = len(C) + 1",
"+c = gcd(A, B)",
"+# print(c)",
"+div = prime_factorize(c)",
"+# print(div)",
"+ans = len(div) + 1"
] | false | 0.046833 | 0.089237 | 0.52482 |
[
"s568392024",
"s982828387"
] |
u699089116
|
p02755
|
python
|
s899077381
|
s142459697
| 198 | 180 | 38,384 | 38,896 |
Accepted
|
Accepted
| 9.09 |
import math
a, b = list(map(int, input().split()))
def calc_a(n):
return n // 0.08
def calc_b(n):
return n / 0.1
estimate = int(min(calc_a(a), calc_b(b)))
for i in range(estimate, estimate*2):
if math.floor(i * 0.08) == a and math.floor(i * 0.1) == b:
print(i)
exit()
print((-1))
|
import math
a, b = list(map(int, input().split()))
for i in range(1, 1250):
if math.floor(i * 0.08) == a and math.floor(i * 0.1) == b:
print(i)
exit()
else:
print((-1))
| 19 | 9 | 324 | 193 |
import math
a, b = list(map(int, input().split()))
def calc_a(n):
return n // 0.08
def calc_b(n):
return n / 0.1
estimate = int(min(calc_a(a), calc_b(b)))
for i in range(estimate, estimate * 2):
if math.floor(i * 0.08) == a and math.floor(i * 0.1) == b:
print(i)
exit()
print((-1))
|
import math
a, b = list(map(int, input().split()))
for i in range(1, 1250):
if math.floor(i * 0.08) == a and math.floor(i * 0.1) == b:
print(i)
exit()
else:
print((-1))
| false | 52.631579 |
[
"-",
"-",
"-def calc_a(n):",
"- return n // 0.08",
"-",
"-",
"-def calc_b(n):",
"- return n / 0.1",
"-",
"-",
"-estimate = int(min(calc_a(a), calc_b(b)))",
"-for i in range(estimate, estimate * 2):",
"+for i in range(1, 1250):",
"-print((-1))",
"+else:",
"+ print((-1))"
] | false | 0.04674 | 0.048739 | 0.958987 |
[
"s899077381",
"s142459697"
] |
u576917603
|
p02720
|
python
|
s691214985
|
s560429325
| 207 | 160 | 14,120 | 13,884 |
Accepted
|
Accepted
| 22.71 |
def add():
for i in ans[cnt-1]:
i=str(i)
last=i[-1]
last=int(last)
for j in range(last-1,last+2):
if j==10 or j==-1:
continue
tmp=i
tmp+=str(j)
ans[cnt].append(int(tmp))
n=int(eval(input()))
ans=[[]for i in range(10)]
cnt=1
for i in range(1,10):
ans[0].append(i)
for i in range(9):
add()
cnt+=1
merged=[]
for i in ans:
merged+=i
merged=sorted(merged)
print((merged[n-1]))
|
def dfs(x):
ans.append(x)
if len(str(x))==10:
return
last=x%10
for i in [last-1,last,last+1]:
if 0<=i<=9:
dfs(10*x+i)
k=int(eval(input()))
ans=[]
for i in range(1,10):
dfs(i)
ans=sorted(ans)
print((ans[k-1]))
| 26 | 19 | 506 | 284 |
def add():
for i in ans[cnt - 1]:
i = str(i)
last = i[-1]
last = int(last)
for j in range(last - 1, last + 2):
if j == 10 or j == -1:
continue
tmp = i
tmp += str(j)
ans[cnt].append(int(tmp))
n = int(eval(input()))
ans = [[] for i in range(10)]
cnt = 1
for i in range(1, 10):
ans[0].append(i)
for i in range(9):
add()
cnt += 1
merged = []
for i in ans:
merged += i
merged = sorted(merged)
print((merged[n - 1]))
|
def dfs(x):
ans.append(x)
if len(str(x)) == 10:
return
last = x % 10
for i in [last - 1, last, last + 1]:
if 0 <= i <= 9:
dfs(10 * x + i)
k = int(eval(input()))
ans = []
for i in range(1, 10):
dfs(i)
ans = sorted(ans)
print((ans[k - 1]))
| false | 26.923077 |
[
"-def add():",
"- for i in ans[cnt - 1]:",
"- i = str(i)",
"- last = i[-1]",
"- last = int(last)",
"- for j in range(last - 1, last + 2):",
"- if j == 10 or j == -1:",
"- continue",
"- tmp = i",
"- tmp += str(j)",
"- ans[cnt].append(int(tmp))",
"+def dfs(x):",
"+ ans.append(x)",
"+ if len(str(x)) == 10:",
"+ return",
"+ last = x % 10",
"+ for i in [last - 1, last, last + 1]:",
"+ if 0 <= i <= 9:",
"+ dfs(10 * x + i)",
"-n = int(eval(input()))",
"-ans = [[] for i in range(10)]",
"-cnt = 1",
"+k = int(eval(input()))",
"+ans = []",
"- ans[0].append(i)",
"-for i in range(9):",
"- add()",
"- cnt += 1",
"-merged = []",
"-for i in ans:",
"- merged += i",
"-merged = sorted(merged)",
"-print((merged[n - 1]))",
"+ dfs(i)",
"+ans = sorted(ans)",
"+print((ans[k - 1]))"
] | false | 0.333957 | 0.251234 | 1.329267 |
[
"s691214985",
"s560429325"
] |
u564589929
|
p02935
|
python
|
s215910821
|
s135056632
| 20 | 17 | 3,316 | 3,064 |
Accepted
|
Accepted
| 15 |
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
from collections import deque
def solve():
n = II()
V = sorted(LI())
ans = V[0]
for i in range(1, n):
ans = (ans + V[i]) / 2
print(ans)
if __name__ == '__main__':
solve()
|
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def solve():
n = II()
V = sorted(LI())
ans = V[0]
for i in range(1, n):
ans = (ans + V[i]) / 2
print(ans)
if __name__ == '__main__':
solve()
| 23 | 21 | 535 | 502 |
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MI1():
return list(map(int1, input().split()))
def LI():
return list(map(int, input().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
from collections import deque
def solve():
n = II()
V = sorted(LI())
ans = V[0]
for i in range(1, n):
ans = (ans + V[i]) / 2
print(ans)
if __name__ == "__main__":
solve()
|
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MI1():
return list(map(int1, input().split()))
def LI():
return list(map(int, input().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def solve():
n = II()
V = sorted(LI())
ans = V[0]
for i in range(1, n):
ans = (ans + V[i]) / 2
print(ans)
if __name__ == "__main__":
solve()
| false | 8.695652 |
[
"-from collections import deque",
"-",
"-"
] | false | 0.081705 | 0.03441 | 2.374437 |
[
"s215910821",
"s135056632"
] |
u373047809
|
p02948
|
python
|
s771037961
|
s455527969
| 446 | 377 | 63,928 | 62,148 |
Accepted
|
Accepted
| 15.47 |
from heapq import*
(N, M), *t = [list(map(int, s.split())) for s in open(0)]
q = [0] * 10**5
v = [[] for _ in q]
for a, b in t:
v[a - 1] += b,
z = 0
for i in v[:M]:
for j in i:
heappush(q, -j)
z += -heappop(q)
print(z)
|
from heapq import*
(N, M), *t = [list(map(int, s.split())) for s in open(0)]
v = [[] for _ in [None] * 10**5]
for a, b in t:
v[a - 1] += b,
z = 0
q = []
for i in v[:M]:
for j in i:
heappush(q, -j)
if q:
z += -heappop(q)
print(z)
| 12 | 13 | 243 | 262 |
from heapq import *
(N, M), *t = [list(map(int, s.split())) for s in open(0)]
q = [0] * 10**5
v = [[] for _ in q]
for a, b in t:
v[a - 1] += (b,)
z = 0
for i in v[:M]:
for j in i:
heappush(q, -j)
z += -heappop(q)
print(z)
|
from heapq import *
(N, M), *t = [list(map(int, s.split())) for s in open(0)]
v = [[] for _ in [None] * 10**5]
for a, b in t:
v[a - 1] += (b,)
z = 0
q = []
for i in v[:M]:
for j in i:
heappush(q, -j)
if q:
z += -heappop(q)
print(z)
| false | 7.692308 |
[
"-q = [0] * 10**5",
"-v = [[] for _ in q]",
"+v = [[] for _ in [None] * 10**5]",
"+q = []",
"- z += -heappop(q)",
"+ if q:",
"+ z += -heappop(q)"
] | false | 0.070154 | 0.059984 | 1.169548 |
[
"s771037961",
"s455527969"
] |
u970899068
|
p02813
|
python
|
s878134851
|
s167243750
| 167 | 51 | 38,256 | 8,052 |
Accepted
|
Accepted
| 69.46 |
import math
n=int(eval(input()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
a=0
b=0
x=[i+1 for i in range(n)]
y=[i+1 for i in range(n)]
for i in range(n-1):
a+=x.index(p[i])*math.factorial(n-1-i)
b+=y.index(q[i])*math.factorial(n-1-i)
x.remove(p[i])
y.remove(q[i])
print((abs(a-b)))
|
import itertools
n=int(eval(input()))
p= list(map(int, input().split()))
q= list(map(int, input().split()))
x=[i+1 for i in range(n)]
x=list(itertools.permutations(x))
a=0
b=0
for i in range(len(x)):
if list(x[i])==p:
a=i
if list(x[i])==q:
b=i
print((abs(a-b)))
| 17 | 18 | 338 | 298 |
import math
n = int(eval(input()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
a = 0
b = 0
x = [i + 1 for i in range(n)]
y = [i + 1 for i in range(n)]
for i in range(n - 1):
a += x.index(p[i]) * math.factorial(n - 1 - i)
b += y.index(q[i]) * math.factorial(n - 1 - i)
x.remove(p[i])
y.remove(q[i])
print((abs(a - b)))
|
import itertools
n = int(eval(input()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
x = [i + 1 for i in range(n)]
x = list(itertools.permutations(x))
a = 0
b = 0
for i in range(len(x)):
if list(x[i]) == p:
a = i
if list(x[i]) == q:
b = i
print((abs(a - b)))
| false | 5.555556 |
[
"-import math",
"+import itertools",
"+x = [i + 1 for i in range(n)]",
"+x = list(itertools.permutations(x))",
"-x = [i + 1 for i in range(n)]",
"-y = [i + 1 for i in range(n)]",
"-for i in range(n - 1):",
"- a += x.index(p[i]) * math.factorial(n - 1 - i)",
"- b += y.index(q[i]) * math.factorial(n - 1 - i)",
"- x.remove(p[i])",
"- y.remove(q[i])",
"+for i in range(len(x)):",
"+ if list(x[i]) == p:",
"+ a = i",
"+ if list(x[i]) == q:",
"+ b = i"
] | false | 0.114807 | 0.047086 | 2.438257 |
[
"s878134851",
"s167243750"
] |
u186838327
|
p03775
|
python
|
s524094360
|
s429782315
| 184 | 68 | 38,896 | 68,124 |
Accepted
|
Accepted
| 63.04 |
import math
n = int(eval(input()))
m = math.ceil(math.sqrt(n))
min_f = float('inf')
for i in range(1, m+1):
x = n/i
if x.is_integer():
x = int(x)
i = int(i)
f = max(len(str(i)), len(str(x)))
if min_f > f:
min_f = f
print(min_f)
|
n = int(eval(input()))
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
#divisors.sort(reverse=True)
return divisors
d = make_divisors(n)
ans = 10**18
for a in d:
b = n//a
a = str(a)
b = str(b)
ans = min(ans, max(len(a), len(b)))
print(ans)
| 15 | 21 | 264 | 431 |
import math
n = int(eval(input()))
m = math.ceil(math.sqrt(n))
min_f = float("inf")
for i in range(1, m + 1):
x = n / i
if x.is_integer():
x = int(x)
i = int(i)
f = max(len(str(i)), len(str(x)))
if min_f > f:
min_f = f
print(min_f)
|
n = int(eval(input()))
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
# divisors.sort(reverse=True)
return divisors
d = make_divisors(n)
ans = 10**18
for a in d:
b = n // a
a = str(a)
b = str(b)
ans = min(ans, max(len(a), len(b)))
print(ans)
| false | 28.571429 |
[
"-import math",
"+n = int(eval(input()))",
"-n = int(eval(input()))",
"-m = math.ceil(math.sqrt(n))",
"-min_f = float(\"inf\")",
"-for i in range(1, m + 1):",
"- x = n / i",
"- if x.is_integer():",
"- x = int(x)",
"- i = int(i)",
"- f = max(len(str(i)), len(str(x)))",
"- if min_f > f:",
"- min_f = f",
"-print(min_f)",
"+",
"+def make_divisors(n):",
"+ divisors = []",
"+ for i in range(1, int(n**0.5) + 1):",
"+ if n % i == 0:",
"+ divisors.append(i)",
"+ if i != n // i:",
"+ divisors.append(n // i)",
"+ # divisors.sort(reverse=True)",
"+ return divisors",
"+",
"+",
"+d = make_divisors(n)",
"+ans = 10**18",
"+for a in d:",
"+ b = n // a",
"+ a = str(a)",
"+ b = str(b)",
"+ ans = min(ans, max(len(a), len(b)))",
"+print(ans)"
] | false | 0.053358 | 0.122818 | 0.434444 |
[
"s524094360",
"s429782315"
] |
u724687935
|
p03295
|
python
|
s259453777
|
s008495000
| 390 | 350 | 18,248 | 65,072 |
Accepted
|
Accepted
| 10.26 |
N, M = list(map(int, input().split()))
req = [tuple(map(int, input().split())) for _ in range(M)]
req.sort(key=lambda x: x[1])
res = 0
i = 1
for m in range(M):
if req[m][0] >= i:
i = req[m][1]
res += 1
print(res)
|
import sys
N, M = list(map(int, input().split()))
bridge = [[] for _ in range(N)]
for x in sys.stdin.readlines():
a, b = list(map(int, x.split()))
a -= 1; b -= 1
bridge[a].append(b)
ans = 0
near = N
for i in range(N):
if near == i:
ans += 1
near = N
for e in bridge[i]:
near = min(near, e)
print(ans)
| 12 | 20 | 240 | 356 |
N, M = list(map(int, input().split()))
req = [tuple(map(int, input().split())) for _ in range(M)]
req.sort(key=lambda x: x[1])
res = 0
i = 1
for m in range(M):
if req[m][0] >= i:
i = req[m][1]
res += 1
print(res)
|
import sys
N, M = list(map(int, input().split()))
bridge = [[] for _ in range(N)]
for x in sys.stdin.readlines():
a, b = list(map(int, x.split()))
a -= 1
b -= 1
bridge[a].append(b)
ans = 0
near = N
for i in range(N):
if near == i:
ans += 1
near = N
for e in bridge[i]:
near = min(near, e)
print(ans)
| false | 40 |
[
"+import sys",
"+",
"-req = [tuple(map(int, input().split())) for _ in range(M)]",
"-req.sort(key=lambda x: x[1])",
"-res = 0",
"-i = 1",
"-for m in range(M):",
"- if req[m][0] >= i:",
"- i = req[m][1]",
"- res += 1",
"-print(res)",
"+bridge = [[] for _ in range(N)]",
"+for x in sys.stdin.readlines():",
"+ a, b = list(map(int, x.split()))",
"+ a -= 1",
"+ b -= 1",
"+ bridge[a].append(b)",
"+ans = 0",
"+near = N",
"+for i in range(N):",
"+ if near == i:",
"+ ans += 1",
"+ near = N",
"+ for e in bridge[i]:",
"+ near = min(near, e)",
"+print(ans)"
] | false | 0.03621 | 0.037474 | 0.966291 |
[
"s259453777",
"s008495000"
] |
u556589653
|
p03210
|
python
|
s628224294
|
s835455561
| 19 | 17 | 3,060 | 2,940 |
Accepted
|
Accepted
| 10.53 |
x = int(eval(input()))
if x == 3 or x == 5 or x ==7:
print("YES")
else:
print("NO")
|
x=int(eval(input()))
l=[3,5,7]
print(("YES" if x in l else "NO"))
| 5 | 3 | 89 | 59 |
x = int(eval(input()))
if x == 3 or x == 5 or x == 7:
print("YES")
else:
print("NO")
|
x = int(eval(input()))
l = [3, 5, 7]
print(("YES" if x in l else "NO"))
| false | 40 |
[
"-if x == 3 or x == 5 or x == 7:",
"- print(\"YES\")",
"-else:",
"- print(\"NO\")",
"+l = [3, 5, 7]",
"+print((\"YES\" if x in l else \"NO\"))"
] | false | 0.072436 | 0.070652 | 1.025243 |
[
"s628224294",
"s835455561"
] |
u709304134
|
p02662
|
python
|
s185858578
|
s327840852
| 255 | 177 | 132,364 | 132,464 |
Accepted
|
Accepted
| 30.59 |
def solve(N,S,A):
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1
mod = 998244353
for i, a in enumerate(A, 1):
for s in range(S+1):
if s-a >= 0:
dp[i][s] = (dp[i-1][s] * 2 + dp[i-1][s-a]) % mod
else:
dp[i][s] = dp[i-1][s] * 2 % mod
print((dp[N][S]))
N, S = list(map(int, input().split()))
A = list(map(int, input().split()))
solve(N,S,A)
|
N, S = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 998244353
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1,N+1):
for s in range(S+1):
if s-A[i-1] >= 0:
dp[i][s] = (dp[i-1][s] * 2 + dp[i-1][s-A[i-1]]) % MOD
else:
dp[i][s] = dp[i-1][s] * 2 % MOD
print((dp[N][S]))
| 16 | 13 | 433 | 362 |
def solve(N, S, A):
dp = [[0] * (S + 1) for _ in range(N + 1)]
dp[0][0] = 1
mod = 998244353
for i, a in enumerate(A, 1):
for s in range(S + 1):
if s - a >= 0:
dp[i][s] = (dp[i - 1][s] * 2 + dp[i - 1][s - a]) % mod
else:
dp[i][s] = dp[i - 1][s] * 2 % mod
print((dp[N][S]))
N, S = list(map(int, input().split()))
A = list(map(int, input().split()))
solve(N, S, A)
|
N, S = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 998244353
dp = [[0] * (S + 1) for _ in range(N + 1)]
dp[0][0] = 1
for i in range(1, N + 1):
for s in range(S + 1):
if s - A[i - 1] >= 0:
dp[i][s] = (dp[i - 1][s] * 2 + dp[i - 1][s - A[i - 1]]) % MOD
else:
dp[i][s] = dp[i - 1][s] * 2 % MOD
print((dp[N][S]))
| false | 18.75 |
[
"-def solve(N, S, A):",
"- dp = [[0] * (S + 1) for _ in range(N + 1)]",
"- dp[0][0] = 1",
"- mod = 998244353",
"- for i, a in enumerate(A, 1):",
"- for s in range(S + 1):",
"- if s - a >= 0:",
"- dp[i][s] = (dp[i - 1][s] * 2 + dp[i - 1][s - a]) % mod",
"- else:",
"- dp[i][s] = dp[i - 1][s] * 2 % mod",
"- print((dp[N][S]))",
"-",
"-",
"-solve(N, S, A)",
"+MOD = 998244353",
"+dp = [[0] * (S + 1) for _ in range(N + 1)]",
"+dp[0][0] = 1",
"+for i in range(1, N + 1):",
"+ for s in range(S + 1):",
"+ if s - A[i - 1] >= 0:",
"+ dp[i][s] = (dp[i - 1][s] * 2 + dp[i - 1][s - A[i - 1]]) % MOD",
"+ else:",
"+ dp[i][s] = dp[i - 1][s] * 2 % MOD",
"+print((dp[N][S]))"
] | false | 0.04183 | 0.042353 | 0.987654 |
[
"s185858578",
"s327840852"
] |
u843175622
|
p02888
|
python
|
s515169368
|
s901355562
| 1,010 | 715 | 9,240 | 9,340 |
Accepted
|
Accepted
| 29.21 |
from bisect import bisect_left
n, *l = list(map(int, open(0).read().split()))
l.sort()
ans = 0
for i in range(n):
for j in range(i + 1, n):
ng = n - bisect_left(l, l[i] + l[j]) + 1
ans += (n - j) - ng
print(ans)
|
from bisect import bisect_left
n, *l = list(map(int, open(0).read().split()))
l.sort()
print((sum(bisect_left(l, l[i] + l[j]) - 1 - j for i in range(n)
for j in range(i + 1, n))))
| 10 | 6 | 236 | 188 |
from bisect import bisect_left
n, *l = list(map(int, open(0).read().split()))
l.sort()
ans = 0
for i in range(n):
for j in range(i + 1, n):
ng = n - bisect_left(l, l[i] + l[j]) + 1
ans += (n - j) - ng
print(ans)
|
from bisect import bisect_left
n, *l = list(map(int, open(0).read().split()))
l.sort()
print(
(
sum(
bisect_left(l, l[i] + l[j]) - 1 - j
for i in range(n)
for j in range(i + 1, n)
)
)
)
| false | 40 |
[
"-ans = 0",
"-for i in range(n):",
"- for j in range(i + 1, n):",
"- ng = n - bisect_left(l, l[i] + l[j]) + 1",
"- ans += (n - j) - ng",
"-print(ans)",
"+print(",
"+ (",
"+ sum(",
"+ bisect_left(l, l[i] + l[j]) - 1 - j",
"+ for i in range(n)",
"+ for j in range(i + 1, n)",
"+ )",
"+ )",
"+)"
] | false | 0.04338 | 0.081784 | 0.53043 |
[
"s515169368",
"s901355562"
] |
u064505481
|
p02683
|
python
|
s737879667
|
s694273949
| 367 | 88 | 85,488 | 69,212 |
Accepted
|
Accepted
| 76.02 |
from sys import stdin, stdout
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: list(map(int, stdin.readline().split()))
INF, NINF = float('inf'), float('-inf')
def submasks(m):
s = m
while s > 0:
s = (s-1)&m
yield s
def main():
n, m, x = rli()
A = []
for _ in range(n):
A.append(list(rli()))
mask = 0
for i in range(n):
mask |= (1 << i)
opt = INF
def process(s):
nonlocal opt
i = 0
cost = 0
algs = [0 for _ in range(m)]
while s:
s, bit = divmod(s, 2)
if bit:
cost += A[i][0]
for j in range(1, m+1):
algs[j-1] += A[i][j]
i += 1
if all(skill >= x for skill in algs):
opt = min(opt, cost)
process(mask)
for s in submasks(mask):
process(s)
print((opt if opt < INF else -1))
stdout.close()
if __name__ == "__main__":
main()
|
from sys import stdin, stdout
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: list(map(int, stdin.readline().split()))
INF, NINF = float('inf'), float('-inf')
def main():
n, m, x = rli()
A = []
for _ in range(n):
A.append(list(rli()))
mask = 0
for i in range(n):
mask |= (1 << i)
opt = INF
def process(s):
nonlocal opt
i = 0
cost = 0
algs = [0 for _ in range(m)]
while s:
s, bit = divmod(s, 2)
if bit:
cost += A[i][0]
for j in range(1, m+1):
algs[j-1] += A[i][j]
i += 1
if all(skill >= x for skill in algs):
opt = min(opt, cost)
process(mask)
s = mask
while s > 0:
process(s)
s = (s-1) & mask
print((opt if opt < INF else -1))
stdout.close()
if __name__ == "__main__":
main()
| 49 | 45 | 862 | 812 |
from sys import stdin, stdout
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: list(map(int, stdin.readline().split()))
INF, NINF = float("inf"), float("-inf")
def submasks(m):
s = m
while s > 0:
s = (s - 1) & m
yield s
def main():
n, m, x = rli()
A = []
for _ in range(n):
A.append(list(rli()))
mask = 0
for i in range(n):
mask |= 1 << i
opt = INF
def process(s):
nonlocal opt
i = 0
cost = 0
algs = [0 for _ in range(m)]
while s:
s, bit = divmod(s, 2)
if bit:
cost += A[i][0]
for j in range(1, m + 1):
algs[j - 1] += A[i][j]
i += 1
if all(skill >= x for skill in algs):
opt = min(opt, cost)
process(mask)
for s in submasks(mask):
process(s)
print((opt if opt < INF else -1))
stdout.close()
if __name__ == "__main__":
main()
|
from sys import stdin, stdout
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: list(map(int, stdin.readline().split()))
INF, NINF = float("inf"), float("-inf")
def main():
n, m, x = rli()
A = []
for _ in range(n):
A.append(list(rli()))
mask = 0
for i in range(n):
mask |= 1 << i
opt = INF
def process(s):
nonlocal opt
i = 0
cost = 0
algs = [0 for _ in range(m)]
while s:
s, bit = divmod(s, 2)
if bit:
cost += A[i][0]
for j in range(1, m + 1):
algs[j - 1] += A[i][j]
i += 1
if all(skill >= x for skill in algs):
opt = min(opt, cost)
process(mask)
s = mask
while s > 0:
process(s)
s = (s - 1) & mask
print((opt if opt < INF else -1))
stdout.close()
if __name__ == "__main__":
main()
| false | 8.163265 |
[
"-",
"-",
"-def submasks(m):",
"- s = m",
"- while s > 0:",
"- s = (s - 1) & m",
"- yield s",
"- for s in submasks(mask):",
"+ s = mask",
"+ while s > 0:",
"+ s = (s - 1) & mask"
] | false | 0.042149 | 0.120558 | 0.349615 |
[
"s737879667",
"s694273949"
] |
u102461423
|
p02986
|
python
|
s424338009
|
s999525485
| 2,875 | 1,713 | 141,056 | 149,772 |
Accepted
|
Accepted
| 40.42 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N,Q = list(map(int,readline().split()))
data = np.array(read().split(),np.int64)
ABCD = data[:4*N-4].reshape(-1,4).tolist()
graph = [[] for _ in range(N+1)]
for a,b,c,d in ABCD:
graph[a].append((b,c,d))
graph[b].append((a,c,d))
color = [0] * (N+1) # 自身と親を結ぶ辺の色
length = [0] * (N+1) # 自身と親を結ぶ辺の長さ
def EulerTour(graph,start=1):
"""
1-indexed graph
graphを破壊しているので場合によっては注意
"""
V = len(graph)
par = [0] * V
depth = [0] * V; depth[start] = 0
tour = [start]; st = [start]
while st:
x = st[-1]
if not graph[x]:
st.pop()
tour.append(par[x])
continue
y,c,d = graph[x].pop()
if y == par[x]:
continue
par[y] = x
color[y] = c
length[y] = d
depth[y] = depth[x] + 1
st.append(y)
tour.append(y)
return tour,depth
tour,depth = EulerTour(graph)
Ltour = len(tour)
tour_arr = np.array(tour)
depth_arr = np.array(depth)
tour_d = depth_arr[tour_arr]
idx = np.arange(len(depth))
idx[tour_arr] = np.arange(Ltour)
# depth最小を実現するインデックスのsparse tableを作る
sp = np.empty((Ltour.bit_length(),Ltour),np.int32)
sp[0] = np.arange(Ltour)
for n in range(1,Ltour.bit_length()):
prev,width = sp[n-1],1<<(n-1)
x = prev[:-width]; y = prev[width:]
condition = tour_d[x] > tour_d[y]
sp[n] = prev
sp[n,:-width][condition] = y[condition]
def LCA(A,B):
AB = np.vstack([A,B]).T
LR = idx[AB]
LR.sort(axis=1)
# [L,R] におけるRmQ
L = LR[:,0]; R = LR[:,1]
x = R-L
n = np.zeros_like(x) # 2^n <= R-L
for _ in range(20):
x >>= 1
n[x>0] += 1
x = sp[n,L]; y = sp[n,R-(1<<n)+1]
return np.where(tour_d[x] < tour_d[y], tour_arr[x], tour_arr[y])
XYUV = data[4*N-4:]
U = XYUV[2::4]; V = XYUV[3::4]
lca = LCA(U,V)
answer = [0] * Q
task = [[] for _ in range(N+1)]
for i,((x,y,u,v),w) in enumerate(zip(XYUV.reshape(-1,4),lca)):
# x,yの条件下での距離の何倍かをanswer[i]に加算する
task[u].append((x,y,1,i))
task[v].append((x,y,1,i))
task[w].append((x,y,-2,i))
color_cnt = [0] * N
color_sum = [0] * N
d = 0 # いじらないときの距離
for fr,to in zip(tour,tour[1:]):
d1 = depth[fr]; d2 = depth[to]
if d1 > d2:
# 上る前にクエリ処理
for x,y,coef,i in task[fr]:
answer[i] += coef * (d - color_sum[x] + color_cnt[x] * y)
if d1 < d2:
c = color[to]; l = length[to]
color_cnt[c] += 1
color_sum[c] += l; d += l
else:
c = color[fr]; l = length[fr]
color_cnt[c] -= 1
color_sum[c] -= l; d -= l
print(('\n'.join(map(str,answer))))
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N,Q = list(map(int,readline().split()))
data = np.array(read().split(),np.int64)
ABCD = data[:4*N-4].reshape(-1,4).tolist()
graph = [[] for _ in range(N+1)]
for a,b,c,d in ABCD:
graph[a].append((b,c,d))
graph[b].append((a,c,d))
color = [0] * (N+1) # 自身と親を結ぶ辺の色
length = [0] * (N+1) # 自身と親を結ぶ辺の長さ
def EulerTour(graph,start=1):
"""
1-indexed graph
graphを破壊しているので場合によっては注意
"""
V = len(graph)
par = [0] * V
depth = [0] * V; depth[start] = 0
tour = [start]; st = [start]
while st:
x = st[-1]
if not graph[x]:
st.pop()
tour.append(par[x])
continue
y,c,d = graph[x].pop()
if y == par[x]:
continue
par[y] = x
color[y] = c
length[y] = d
depth[y] = depth[x] + 1
st.append(y)
tour.append(y)
return tour,depth
tour,depth = EulerTour(graph)
Ltour = len(tour)
tour_arr = np.array(tour)
depth_arr = np.array(depth)
tour_d = depth_arr[tour_arr]
idx = np.arange(len(depth))
idx[tour_arr] = np.arange(Ltour)
# depth最小を実現するインデックスのsparse tableを作る
sp = np.empty((Ltour.bit_length(),Ltour),np.int32)
sp[0] = np.arange(Ltour)
for n in range(1,Ltour.bit_length()):
prev,width = sp[n-1],1<<(n-1)
x = prev[:-width]; y = prev[width:]
condition = tour_d[x] > tour_d[y]
sp[n] = prev
sp[n,:-width][condition] = y[condition]
def LCA(A,B):
AB = np.vstack([A,B]).T
LR = idx[AB]
LR.sort(axis=1)
# [L,R] におけるRmQ
L = LR[:,0]; R = LR[:,1]
x = R-L
n = np.zeros_like(x) # 2^n <= R-L
for _ in range(20):
x >>= 1
n[x>0] += 1
x = sp[n,L]; y = sp[n,R-(1<<n)+1]
return np.where(tour_d[x] < tour_d[y], tour_arr[x], tour_arr[y])
XYUV = data[4*N-4:]
U = XYUV[2::4]; V = XYUV[3::4]
lca = LCA(U,V)
answer = [0] * Q
task = [[] for _ in range(N+1)]
for i,((x,y,u,v),w) in enumerate(zip(XYUV.reshape(-1,4).tolist(),lca.tolist())):
# x,yの条件下での距離の何倍かをanswer[i]に加算する
task[u].append((x,y,1,i))
task[v].append((x,y,1,i))
task[w].append((x,y,-2,i))
color_cnt = [0] * N
color_sum = [0] * N
d = 0 # いじらないときの距離
for fr,to in zip(tour,tour[1:]):
d1 = depth[fr]; d2 = depth[to]
if d1 > d2:
# 上る前にクエリ処理
for x,y,coef,i in task[fr]:
answer[i] += coef * (d - color_sum[x] + color_cnt[x] * y)
if d1 < d2:
c = color[to]; l = length[to]
color_cnt[c] += 1
color_sum[c] += l; d += l
else:
c = color[fr]; l = length[fr]
color_cnt[c] -= 1
color_sum[c] -= l; d -= l
print(('\n'.join(map(str,answer))))
| 111 | 111 | 2,819 | 2,837 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N, Q = list(map(int, readline().split()))
data = np.array(read().split(), np.int64)
ABCD = data[: 4 * N - 4].reshape(-1, 4).tolist()
graph = [[] for _ in range(N + 1)]
for a, b, c, d in ABCD:
graph[a].append((b, c, d))
graph[b].append((a, c, d))
color = [0] * (N + 1) # 自身と親を結ぶ辺の色
length = [0] * (N + 1) # 自身と親を結ぶ辺の長さ
def EulerTour(graph, start=1):
"""
1-indexed graph
graphを破壊しているので場合によっては注意
"""
V = len(graph)
par = [0] * V
depth = [0] * V
depth[start] = 0
tour = [start]
st = [start]
while st:
x = st[-1]
if not graph[x]:
st.pop()
tour.append(par[x])
continue
y, c, d = graph[x].pop()
if y == par[x]:
continue
par[y] = x
color[y] = c
length[y] = d
depth[y] = depth[x] + 1
st.append(y)
tour.append(y)
return tour, depth
tour, depth = EulerTour(graph)
Ltour = len(tour)
tour_arr = np.array(tour)
depth_arr = np.array(depth)
tour_d = depth_arr[tour_arr]
idx = np.arange(len(depth))
idx[tour_arr] = np.arange(Ltour)
# depth最小を実現するインデックスのsparse tableを作る
sp = np.empty((Ltour.bit_length(), Ltour), np.int32)
sp[0] = np.arange(Ltour)
for n in range(1, Ltour.bit_length()):
prev, width = sp[n - 1], 1 << (n - 1)
x = prev[:-width]
y = prev[width:]
condition = tour_d[x] > tour_d[y]
sp[n] = prev
sp[n, :-width][condition] = y[condition]
def LCA(A, B):
AB = np.vstack([A, B]).T
LR = idx[AB]
LR.sort(axis=1)
# [L,R] におけるRmQ
L = LR[:, 0]
R = LR[:, 1]
x = R - L
n = np.zeros_like(x) # 2^n <= R-L
for _ in range(20):
x >>= 1
n[x > 0] += 1
x = sp[n, L]
y = sp[n, R - (1 << n) + 1]
return np.where(tour_d[x] < tour_d[y], tour_arr[x], tour_arr[y])
XYUV = data[4 * N - 4 :]
U = XYUV[2::4]
V = XYUV[3::4]
lca = LCA(U, V)
answer = [0] * Q
task = [[] for _ in range(N + 1)]
for i, ((x, y, u, v), w) in enumerate(zip(XYUV.reshape(-1, 4), lca)):
# x,yの条件下での距離の何倍かをanswer[i]に加算する
task[u].append((x, y, 1, i))
task[v].append((x, y, 1, i))
task[w].append((x, y, -2, i))
color_cnt = [0] * N
color_sum = [0] * N
d = 0 # いじらないときの距離
for fr, to in zip(tour, tour[1:]):
d1 = depth[fr]
d2 = depth[to]
if d1 > d2:
# 上る前にクエリ処理
for x, y, coef, i in task[fr]:
answer[i] += coef * (d - color_sum[x] + color_cnt[x] * y)
if d1 < d2:
c = color[to]
l = length[to]
color_cnt[c] += 1
color_sum[c] += l
d += l
else:
c = color[fr]
l = length[fr]
color_cnt[c] -= 1
color_sum[c] -= l
d -= l
print(("\n".join(map(str, answer))))
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N, Q = list(map(int, readline().split()))
data = np.array(read().split(), np.int64)
ABCD = data[: 4 * N - 4].reshape(-1, 4).tolist()
graph = [[] for _ in range(N + 1)]
for a, b, c, d in ABCD:
graph[a].append((b, c, d))
graph[b].append((a, c, d))
color = [0] * (N + 1) # 自身と親を結ぶ辺の色
length = [0] * (N + 1) # 自身と親を結ぶ辺の長さ
def EulerTour(graph, start=1):
"""
1-indexed graph
graphを破壊しているので場合によっては注意
"""
V = len(graph)
par = [0] * V
depth = [0] * V
depth[start] = 0
tour = [start]
st = [start]
while st:
x = st[-1]
if not graph[x]:
st.pop()
tour.append(par[x])
continue
y, c, d = graph[x].pop()
if y == par[x]:
continue
par[y] = x
color[y] = c
length[y] = d
depth[y] = depth[x] + 1
st.append(y)
tour.append(y)
return tour, depth
tour, depth = EulerTour(graph)
Ltour = len(tour)
tour_arr = np.array(tour)
depth_arr = np.array(depth)
tour_d = depth_arr[tour_arr]
idx = np.arange(len(depth))
idx[tour_arr] = np.arange(Ltour)
# depth最小を実現するインデックスのsparse tableを作る
sp = np.empty((Ltour.bit_length(), Ltour), np.int32)
sp[0] = np.arange(Ltour)
for n in range(1, Ltour.bit_length()):
prev, width = sp[n - 1], 1 << (n - 1)
x = prev[:-width]
y = prev[width:]
condition = tour_d[x] > tour_d[y]
sp[n] = prev
sp[n, :-width][condition] = y[condition]
def LCA(A, B):
AB = np.vstack([A, B]).T
LR = idx[AB]
LR.sort(axis=1)
# [L,R] におけるRmQ
L = LR[:, 0]
R = LR[:, 1]
x = R - L
n = np.zeros_like(x) # 2^n <= R-L
for _ in range(20):
x >>= 1
n[x > 0] += 1
x = sp[n, L]
y = sp[n, R - (1 << n) + 1]
return np.where(tour_d[x] < tour_d[y], tour_arr[x], tour_arr[y])
XYUV = data[4 * N - 4 :]
U = XYUV[2::4]
V = XYUV[3::4]
lca = LCA(U, V)
answer = [0] * Q
task = [[] for _ in range(N + 1)]
for i, ((x, y, u, v), w) in enumerate(zip(XYUV.reshape(-1, 4).tolist(), lca.tolist())):
# x,yの条件下での距離の何倍かをanswer[i]に加算する
task[u].append((x, y, 1, i))
task[v].append((x, y, 1, i))
task[w].append((x, y, -2, i))
color_cnt = [0] * N
color_sum = [0] * N
d = 0 # いじらないときの距離
for fr, to in zip(tour, tour[1:]):
d1 = depth[fr]
d2 = depth[to]
if d1 > d2:
# 上る前にクエリ処理
for x, y, coef, i in task[fr]:
answer[i] += coef * (d - color_sum[x] + color_cnt[x] * y)
if d1 < d2:
c = color[to]
l = length[to]
color_cnt[c] += 1
color_sum[c] += l
d += l
else:
c = color[fr]
l = length[fr]
color_cnt[c] -= 1
color_sum[c] -= l
d -= l
print(("\n".join(map(str, answer))))
| false | 0 |
[
"-for i, ((x, y, u, v), w) in enumerate(zip(XYUV.reshape(-1, 4), lca)):",
"+for i, ((x, y, u, v), w) in enumerate(zip(XYUV.reshape(-1, 4).tolist(), lca.tolist())):"
] | false | 0.732842 | 1.121171 | 0.65364 |
[
"s424338009",
"s999525485"
] |
u926678805
|
p03545
|
python
|
s163596738
|
s296762900
| 19 | 17 | 3,188 | 3,060 |
Accepted
|
Accepted
| 10.53 |
# coding: utf-8
import itertools
s='%d%s%d%s%d%s%d'
a,b,c,d=list(map(int,eval(input())))
for n in itertools.permutations(('+++---'),3):
ans=s%(a,n[0],b,n[1],c,n[2],d)
if eval(ans)==7:
print((ans+'=7'))
break
|
a,b,c,d=map(int,list(input()))
for i in range(2):
for j in range(2):
for k in range(2):
if a+(i*2-1)*b+(j*2-1)*c+(k*2-1)*d==7:
print(a,'-+'[i],b,'-+'[j],c,'-+'[k],d,'=7',sep='')
exit()
| 9 | 7 | 225 | 246 |
# coding: utf-8
import itertools
s = "%d%s%d%s%d%s%d"
a, b, c, d = list(map(int, eval(input())))
for n in itertools.permutations(("+++---"), 3):
ans = s % (a, n[0], b, n[1], c, n[2], d)
if eval(ans) == 7:
print((ans + "=7"))
break
|
a, b, c, d = map(int, list(input()))
for i in range(2):
for j in range(2):
for k in range(2):
if a + (i * 2 - 1) * b + (j * 2 - 1) * c + (k * 2 - 1) * d == 7:
print(a, "-+"[i], b, "-+"[j], c, "-+"[k], d, "=7", sep="")
exit()
| false | 22.222222 |
[
"-# coding: utf-8",
"-import itertools",
"-",
"-s = \"%d%s%d%s%d%s%d\"",
"-a, b, c, d = list(map(int, eval(input())))",
"- ans = s % (a, n[0], b, n[1], c, n[2], d)",
"- if eval(ans) == 7:",
"- print((ans + \"=7\"))",
"- break",
"+a, b, c, d = map(int, list(input()))",
"+for i in range(2):",
"+ for j in range(2):",
"+ for k in range(2):",
"+ if a + (i * 2 - 1) * b + (j * 2 - 1) * c + (k * 2 - 1) * d == 7:",
"+ print(a, \"-+\"[i], b, \"-+\"[j], c, \"-+\"[k], d, \"=7\", sep=\"\")",
"+ exit()"
] | false | 0.050635 | 0.051101 | 0.990895 |
[
"s163596738",
"s296762900"
] |
u189479417
|
p02836
|
python
|
s800907723
|
s472990212
| 19 | 17 | 3,064 | 3,060 |
Accepted
|
Accepted
| 10.53 |
S = list(eval(input()))
A = list(reversed(S))
LEN=len(S)
ans=0
if LEN%2==0:
for i in range(LEN//2):
if S[i]!=A[i]:
ans+=1
else:
for i in range((LEN-1)//2):
if S[i]!=A[i]:
ans+=1
print(ans)
|
S = list(eval(input()))
R = list(reversed(S))
ans = 0
for i in range(len(S)):
if S[i] != R[i]:
ans += 1
print((ans//2))
| 13 | 7 | 242 | 129 |
S = list(eval(input()))
A = list(reversed(S))
LEN = len(S)
ans = 0
if LEN % 2 == 0:
for i in range(LEN // 2):
if S[i] != A[i]:
ans += 1
else:
for i in range((LEN - 1) // 2):
if S[i] != A[i]:
ans += 1
print(ans)
|
S = list(eval(input()))
R = list(reversed(S))
ans = 0
for i in range(len(S)):
if S[i] != R[i]:
ans += 1
print((ans // 2))
| false | 46.153846 |
[
"-A = list(reversed(S))",
"-LEN = len(S)",
"+R = list(reversed(S))",
"-if LEN % 2 == 0:",
"- for i in range(LEN // 2):",
"- if S[i] != A[i]:",
"- ans += 1",
"-else:",
"- for i in range((LEN - 1) // 2):",
"- if S[i] != A[i]:",
"- ans += 1",
"-print(ans)",
"+for i in range(len(S)):",
"+ if S[i] != R[i]:",
"+ ans += 1",
"+print((ans // 2))"
] | false | 0.069491 | 0.037569 | 1.849699 |
[
"s800907723",
"s472990212"
] |
u708378905
|
p04001
|
python
|
s278615151
|
s852359118
| 26 | 21 | 3,060 | 3,060 |
Accepted
|
Accepted
| 19.23 |
s = eval(input())
result_sum = 0
plus_count = len(s) - 1
for bit in range(1 << plus_count):
splitted_string = s[0]
for iter_plus in range(plus_count):
if bit & (1 << iter_plus):
splitted_string += '+'
splitted_string += s[iter_plus+1]
result_sum += eval(splitted_string)
print(result_sum)
|
s = eval(input())
result_sum = 0 # 総和
plus_count = len(s) - 1 # 集合の要素数
for bit in range(1 << plus_count): # bit全探索
splitted_string = s[0] # 最初の数字を取る
for iter_plus in range(plus_count):
if bit & (1 << iter_plus): # ビットを立てる -> +を挿入する
splitted_string += '+'
splitted_string += s[iter_plus+1] # 適宜+が入った状態で数字列が構築
# +で区切って,それぞれintに変換し合計
splitted_integer = [int(x) for x in splitted_string.split('+')]
result_sum += sum(splitted_integer)
print(result_sum)
| 13 | 15 | 316 | 487 |
s = eval(input())
result_sum = 0
plus_count = len(s) - 1
for bit in range(1 << plus_count):
splitted_string = s[0]
for iter_plus in range(plus_count):
if bit & (1 << iter_plus):
splitted_string += "+"
splitted_string += s[iter_plus + 1]
result_sum += eval(splitted_string)
print(result_sum)
|
s = eval(input())
result_sum = 0 # 総和
plus_count = len(s) - 1 # 集合の要素数
for bit in range(1 << plus_count): # bit全探索
splitted_string = s[0] # 最初の数字を取る
for iter_plus in range(plus_count):
if bit & (1 << iter_plus): # ビットを立てる -> +を挿入する
splitted_string += "+"
splitted_string += s[iter_plus + 1] # 適宜+が入った状態で数字列が構築
# +で区切って,それぞれintに変換し合計
splitted_integer = [int(x) for x in splitted_string.split("+")]
result_sum += sum(splitted_integer)
print(result_sum)
| false | 13.333333 |
[
"-result_sum = 0",
"-plus_count = len(s) - 1",
"-for bit in range(1 << plus_count):",
"- splitted_string = s[0]",
"+result_sum = 0 # 総和",
"+plus_count = len(s) - 1 # 集合の要素数",
"+for bit in range(1 << plus_count): # bit全探索",
"+ splitted_string = s[0] # 最初の数字を取る",
"- if bit & (1 << iter_plus):",
"+ if bit & (1 << iter_plus): # ビットを立てる -> +を挿入する",
"- splitted_string += s[iter_plus + 1]",
"- result_sum += eval(splitted_string)",
"+ splitted_string += s[iter_plus + 1] # 適宜+が入った状態で数字列が構築",
"+ # +で区切って,それぞれintに変換し合計",
"+ splitted_integer = [int(x) for x in splitted_string.split(\"+\")]",
"+ result_sum += sum(splitted_integer)"
] | false | 0.052044 | 0.039208 | 1.327389 |
[
"s278615151",
"s852359118"
] |
u977661421
|
p04030
|
python
|
s222314433
|
s349073876
| 19 | 17 | 2,940 | 2,940 |
Accepted
|
Accepted
| 10.53 |
# -*- coding: utf-8 -*-
s = list(eval(input()))
ans = []
for i in range(len(s)):
if s[i] == '0':
ans.append('0')
if s[i] == '1':
ans.append('1')
if len(ans) >= 1 and s[i] == 'B':
ans.pop()
print((''.join(ans)))
|
# -*- coding: utf-8 -*-
s = list(eval(input()))
ans = []
for i in s:
if len(ans) > 0 and i == 'B':
ans.pop()
if i == '0':
ans.append('0')
if i == '1':
ans.append('1')
print((''.join(ans)))
| 12 | 12 | 251 | 229 |
# -*- coding: utf-8 -*-
s = list(eval(input()))
ans = []
for i in range(len(s)):
if s[i] == "0":
ans.append("0")
if s[i] == "1":
ans.append("1")
if len(ans) >= 1 and s[i] == "B":
ans.pop()
print(("".join(ans)))
|
# -*- coding: utf-8 -*-
s = list(eval(input()))
ans = []
for i in s:
if len(ans) > 0 and i == "B":
ans.pop()
if i == "0":
ans.append("0")
if i == "1":
ans.append("1")
print(("".join(ans)))
| false | 0 |
[
"-for i in range(len(s)):",
"- if s[i] == \"0\":",
"+for i in s:",
"+ if len(ans) > 0 and i == \"B\":",
"+ ans.pop()",
"+ if i == \"0\":",
"- if s[i] == \"1\":",
"+ if i == \"1\":",
"- if len(ans) >= 1 and s[i] == \"B\":",
"- ans.pop()"
] | false | 0.043369 | 0.044138 | 0.982572 |
[
"s222314433",
"s349073876"
] |
u724687935
|
p02744
|
python
|
s410409706
|
s006522522
| 1,527 | 141 | 15,404 | 14,464 |
Accepted
|
Accepted
| 90.77 |
import sys
sys.setrecursionlimit(10 ** 6)
N = int(input())
ans = set()
a = ord('a')
def f(c, A, done):
global N, a
B = list(A)
done = set(done)
for i in range(N):
if i not in done:
B[i] = c
done.add(i)
break
if len(done) == N:
ans.add(''.join(B))
else:
for i in range(2 ** (N - len(done)) - 1, -1, -1):
k = i
C = B[:]
tDone = set(x for x in range(N))
nDone = set(x for x in done)
for t in done:
tDone.remove(t)
while k > 0:
y = min(tDone)
if k & 1 == 1:
C[y] = c
nDone.add(y)
tDone.remove(y)
k >>= 1
f(chr(ord(c) + 1), tuple(C), tuple(nDone))
A = [0] * N
f('a', tuple(A), ())
ans = list(ans)
ans.sort()
print(*ans, sep='\n')
|
import sys
sys.setrecursionlimit(10 ** 6)
N = int(input())
ans = []
a = ord('a')
def dfs(S, mx):
global N
if len(S) == N:
ans.append(S)
else:
for c in range(0, mx + 2):
dfs(S + chr(c + a), max(mx, c))
dfs('a', 0)
print(*ans, sep='\n')
| 43 | 20 | 961 | 300 |
import sys
sys.setrecursionlimit(10**6)
N = int(input())
ans = set()
a = ord("a")
def f(c, A, done):
global N, a
B = list(A)
done = set(done)
for i in range(N):
if i not in done:
B[i] = c
done.add(i)
break
if len(done) == N:
ans.add("".join(B))
else:
for i in range(2 ** (N - len(done)) - 1, -1, -1):
k = i
C = B[:]
tDone = set(x for x in range(N))
nDone = set(x for x in done)
for t in done:
tDone.remove(t)
while k > 0:
y = min(tDone)
if k & 1 == 1:
C[y] = c
nDone.add(y)
tDone.remove(y)
k >>= 1
f(chr(ord(c) + 1), tuple(C), tuple(nDone))
A = [0] * N
f("a", tuple(A), ())
ans = list(ans)
ans.sort()
print(*ans, sep="\n")
|
import sys
sys.setrecursionlimit(10**6)
N = int(input())
ans = []
a = ord("a")
def dfs(S, mx):
global N
if len(S) == N:
ans.append(S)
else:
for c in range(0, mx + 2):
dfs(S + chr(c + a), max(mx, c))
dfs("a", 0)
print(*ans, sep="\n")
| false | 53.488372 |
[
"-ans = set()",
"+ans = []",
"-def f(c, A, done):",
"- global N, a",
"- B = list(A)",
"- done = set(done)",
"- for i in range(N):",
"- if i not in done:",
"- B[i] = c",
"- done.add(i)",
"- break",
"- if len(done) == N:",
"- ans.add(\"\".join(B))",
"+def dfs(S, mx):",
"+ global N",
"+ if len(S) == N:",
"+ ans.append(S)",
"- for i in range(2 ** (N - len(done)) - 1, -1, -1):",
"- k = i",
"- C = B[:]",
"- tDone = set(x for x in range(N))",
"- nDone = set(x for x in done)",
"- for t in done:",
"- tDone.remove(t)",
"- while k > 0:",
"- y = min(tDone)",
"- if k & 1 == 1:",
"- C[y] = c",
"- nDone.add(y)",
"- tDone.remove(y)",
"- k >>= 1",
"- f(chr(ord(c) + 1), tuple(C), tuple(nDone))",
"+ for c in range(0, mx + 2):",
"+ dfs(S + chr(c + a), max(mx, c))",
"-A = [0] * N",
"-f(\"a\", tuple(A), ())",
"-ans = list(ans)",
"-ans.sort()",
"+dfs(\"a\", 0)"
] | false | 0.04008 | 0.057385 | 0.69845 |
[
"s410409706",
"s006522522"
] |
u790710233
|
p03031
|
python
|
s155648484
|
s413470328
| 30 | 25 | 3,064 | 3,064 |
Accepted
|
Accepted
| 16.67 |
n, m = list(map(int, input().split()))
ls = []
for _ in range(m):
k, *s, = [int(x)-1 for x in input().split()]
ls.append(s)
p = list(map(int, input().split()))
ans = 0
def dfs(x, s):
global ans
if x == n:
for j in range(m):
switchs = ls[j]
cond = p[j]
on_cnt = 0
for switch in switchs:
if int(s[switch]):
on_cnt += 1
if on_cnt % 2 != cond:
break
else:
ans += 1
else:
for c in "01":
dfs(x+1, s+c)
dfs(0, "")
print(ans)
|
from itertools import product
n, m = list(map(int, input().split()))
S = []
for _ in range(m):
k, *s = [int(x)-1 for x in input().split()]
S.append(s)
P = list(map(int, input().split()))
ans = 0
for bit in product((0, 1), repeat=n):
for j in range(m):
switch_cnt = sum(bit[idx] for idx in S[j])
if P[j] != switch_cnt % 2:
break
else:
ans += 1
print(ans)
| 30 | 16 | 630 | 419 |
n, m = list(map(int, input().split()))
ls = []
for _ in range(m):
(
k,
*s,
) = [int(x) - 1 for x in input().split()]
ls.append(s)
p = list(map(int, input().split()))
ans = 0
def dfs(x, s):
global ans
if x == n:
for j in range(m):
switchs = ls[j]
cond = p[j]
on_cnt = 0
for switch in switchs:
if int(s[switch]):
on_cnt += 1
if on_cnt % 2 != cond:
break
else:
ans += 1
else:
for c in "01":
dfs(x + 1, s + c)
dfs(0, "")
print(ans)
|
from itertools import product
n, m = list(map(int, input().split()))
S = []
for _ in range(m):
k, *s = [int(x) - 1 for x in input().split()]
S.append(s)
P = list(map(int, input().split()))
ans = 0
for bit in product((0, 1), repeat=n):
for j in range(m):
switch_cnt = sum(bit[idx] for idx in S[j])
if P[j] != switch_cnt % 2:
break
else:
ans += 1
print(ans)
| false | 46.666667 |
[
"+from itertools import product",
"+",
"-ls = []",
"+S = []",
"- (",
"- k,",
"- *s,",
"- ) = [int(x) - 1 for x in input().split()]",
"- ls.append(s)",
"-p = list(map(int, input().split()))",
"+ k, *s = [int(x) - 1 for x in input().split()]",
"+ S.append(s)",
"+P = list(map(int, input().split()))",
"-",
"-",
"-def dfs(x, s):",
"- global ans",
"- if x == n:",
"- for j in range(m):",
"- switchs = ls[j]",
"- cond = p[j]",
"- on_cnt = 0",
"- for switch in switchs:",
"- if int(s[switch]):",
"- on_cnt += 1",
"- if on_cnt % 2 != cond:",
"- break",
"- else:",
"- ans += 1",
"+for bit in product((0, 1), repeat=n):",
"+ for j in range(m):",
"+ switch_cnt = sum(bit[idx] for idx in S[j])",
"+ if P[j] != switch_cnt % 2:",
"+ break",
"- for c in \"01\":",
"- dfs(x + 1, s + c)",
"-",
"-",
"-dfs(0, \"\")",
"+ ans += 1"
] | false | 0.047267 | 0.03484 | 1.356686 |
[
"s155648484",
"s413470328"
] |
u340781749
|
p03183
|
python
|
s043772692
|
s277376680
| 315 | 281 | 42,204 | 42,220 |
Accepted
|
Accepted
| 10.79 |
import sys
n = int(eval(input()))
blocks = []
for line in sys.stdin.readlines():
w, s, v = list(map(int, line.split()))
blocks.append((w + s, w, s, v))
blocks.sort()
dp = [-1] * 20001
dp[0] = 0
for _, w, s, v in blocks:
for i in range(min(s, 20000 - w), -1, -1):
dp[i + w] = max(dp[i + w], dp[i] + v)
print((max(dp)))
|
import sys
n = int(eval(input()))
blocks = []
for line in sys.stdin.readlines():
w, s, v = list(map(int, line.split()))
blocks.append((w + s, w, s, v))
blocks.sort()
dp = [-1] * 20001
dp[0] = 0
for _, w, s, v in blocks:
for i in range(s, -1, -1):
if dp[i] == -1:
continue
dp[i + w] = max(dp[i + w], dp[i] + v)
print((max(dp)))
| 15 | 17 | 340 | 371 |
import sys
n = int(eval(input()))
blocks = []
for line in sys.stdin.readlines():
w, s, v = list(map(int, line.split()))
blocks.append((w + s, w, s, v))
blocks.sort()
dp = [-1] * 20001
dp[0] = 0
for _, w, s, v in blocks:
for i in range(min(s, 20000 - w), -1, -1):
dp[i + w] = max(dp[i + w], dp[i] + v)
print((max(dp)))
|
import sys
n = int(eval(input()))
blocks = []
for line in sys.stdin.readlines():
w, s, v = list(map(int, line.split()))
blocks.append((w + s, w, s, v))
blocks.sort()
dp = [-1] * 20001
dp[0] = 0
for _, w, s, v in blocks:
for i in range(s, -1, -1):
if dp[i] == -1:
continue
dp[i + w] = max(dp[i + w], dp[i] + v)
print((max(dp)))
| false | 11.764706 |
[
"- for i in range(min(s, 20000 - w), -1, -1):",
"+ for i in range(s, -1, -1):",
"+ if dp[i] == -1:",
"+ continue"
] | false | 0.084544 | 0.077229 | 1.094719 |
[
"s043772692",
"s277376680"
] |
u440566786
|
p02851
|
python
|
s869598404
|
s853303799
| 934 | 302 | 99,928 | 105,704 |
Accepted
|
Accepted
| 67.67 |
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from itertools import groupby
def resolve():
n,k=list(map(int,input().split()))
A=list([int(x)-1 for x in input().split()])
S=[0]*(n+1)
for i in range(n):
S[i+1]=S[i]+A[i]
S[i+1]%=k
T=[(s,i) for i,s in enumerate(S)]
T.sort()
ans=0
for key,group in groupby(T,lambda x:x[0]):
G=[i for s,i in group]
n=len(G)
r=0
for l in range(n):
while(r+1<n and G[r+1]-G[l]<k):
r+=1
ans+=r-l
print(ans)
resolve()
|
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from collections import deque,defaultdict
def resolve():
n,k=list(map(int,input().split()))
A=list([int(x)-1 for x in input().split()])
S=[0]*(n+1)
for i in range(n):
S[i+1]=(S[i]+A[i])%k
ans=0
C=defaultdict(int)
Q=deque()
for s in S:
ans+=C[s]
C[s]+=1
Q.append(s)
if(len(Q)==k):
C[Q.popleft()]-=1
print(ans)
resolve()
| 27 | 24 | 661 | 545 |
import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
from itertools import groupby
def resolve():
n, k = list(map(int, input().split()))
A = list([int(x) - 1 for x in input().split()])
S = [0] * (n + 1)
for i in range(n):
S[i + 1] = S[i] + A[i]
S[i + 1] %= k
T = [(s, i) for i, s in enumerate(S)]
T.sort()
ans = 0
for key, group in groupby(T, lambda x: x[0]):
G = [i for s, i in group]
n = len(G)
r = 0
for l in range(n):
while r + 1 < n and G[r + 1] - G[l] < k:
r += 1
ans += r - l
print(ans)
resolve()
|
import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
from collections import deque, defaultdict
def resolve():
n, k = list(map(int, input().split()))
A = list([int(x) - 1 for x in input().split()])
S = [0] * (n + 1)
for i in range(n):
S[i + 1] = (S[i] + A[i]) % k
ans = 0
C = defaultdict(int)
Q = deque()
for s in S:
ans += C[s]
C[s] += 1
Q.append(s)
if len(Q) == k:
C[Q.popleft()] -= 1
print(ans)
resolve()
| false | 11.111111 |
[
"-from itertools import groupby",
"+from collections import deque, defaultdict",
"- S[i + 1] = S[i] + A[i]",
"- S[i + 1] %= k",
"- T = [(s, i) for i, s in enumerate(S)]",
"- T.sort()",
"+ S[i + 1] = (S[i] + A[i]) % k",
"- for key, group in groupby(T, lambda x: x[0]):",
"- G = [i for s, i in group]",
"- n = len(G)",
"- r = 0",
"- for l in range(n):",
"- while r + 1 < n and G[r + 1] - G[l] < k:",
"- r += 1",
"- ans += r - l",
"+ C = defaultdict(int)",
"+ Q = deque()",
"+ for s in S:",
"+ ans += C[s]",
"+ C[s] += 1",
"+ Q.append(s)",
"+ if len(Q) == k:",
"+ C[Q.popleft()] -= 1"
] | false | 0.038016 | 0.036875 | 1.03094 |
[
"s869598404",
"s853303799"
] |
u075492837
|
p03478
|
python
|
s198642166
|
s020055996
| 32 | 25 | 2,940 | 3,060 |
Accepted
|
Accepted
| 21.88 |
N, A, B = list(map(int, input().split()))
res = 0
for i in range(N+1):
if A <= sum([int(s) for s in str(i)]) <= B:
res += i
print(res)
|
N, A, B = list(map(int, input().split()))
def keta_sum(x):
m = 0
while x:
m += x%10
x //= 10
return(m)
res = 0
for i in range(N+1):
if A <= keta_sum(i) <= B:
res += i
print(res)
| 6 | 12 | 145 | 222 |
N, A, B = list(map(int, input().split()))
res = 0
for i in range(N + 1):
if A <= sum([int(s) for s in str(i)]) <= B:
res += i
print(res)
|
N, A, B = list(map(int, input().split()))
def keta_sum(x):
m = 0
while x:
m += x % 10
x //= 10
return m
res = 0
for i in range(N + 1):
if A <= keta_sum(i) <= B:
res += i
print(res)
| false | 50 |
[
"+",
"+",
"+def keta_sum(x):",
"+ m = 0",
"+ while x:",
"+ m += x % 10",
"+ x //= 10",
"+ return m",
"+",
"+",
"- if A <= sum([int(s) for s in str(i)]) <= B:",
"+ if A <= keta_sum(i) <= B:"
] | false | 0.120627 | 0.047106 | 2.560754 |
[
"s198642166",
"s020055996"
] |
u399721252
|
p03044
|
python
|
s898155718
|
s337502866
| 1,047 | 942 | 36,376 | 36,376 |
Accepted
|
Accepted
| 10.03 |
n = int(eval(input()))
connect_list = [ [] for i in range(n) ]
distance_list = [ -1 for i in range(n) ]
color_list = [ "Gray" for i in range(n) ]
distance_list[0] = 0
for i in range(n-1):
u, v, w = [ int(v) for v in input().split() ]
w %= 2
connect_list[u-1].append((v-1,w))
connect_list[v-1].append((u-1,w))
search_list = [0]
while search_list != []:
s = search_list[0]
for i in connect_list[s]:
if distance_list[i[0]] == -1:
distance_list[i[0]] = (distance_list[s] + i[1]) % 2
search_list.append(i[0])
del search_list[0]
for i in distance_list:
print(i)
|
import sys
input = sys.stdin.readline
n = int(eval(input()))
connect_list = [ [] for i in range(n) ]
distance_list = [ -1 for i in range(n) ]
color_list = [ "Gray" for i in range(n) ]
distance_list[0] = 0
for i in range(n-1):
u, v, w = [ int(v) for v in input().split() ]
w %= 2
connect_list[u-1].append((v-1,w))
connect_list[v-1].append((u-1,w))
search_list = [0]
while search_list != []:
s = search_list[0]
for i in connect_list[s]:
if distance_list[i[0]] == -1:
distance_list[i[0]] = (distance_list[s] + i[1]) % 2
search_list.append(i[0])
del search_list[0]
for i in distance_list:
print(i)
| 27 | 31 | 599 | 643 |
n = int(eval(input()))
connect_list = [[] for i in range(n)]
distance_list = [-1 for i in range(n)]
color_list = ["Gray" for i in range(n)]
distance_list[0] = 0
for i in range(n - 1):
u, v, w = [int(v) for v in input().split()]
w %= 2
connect_list[u - 1].append((v - 1, w))
connect_list[v - 1].append((u - 1, w))
search_list = [0]
while search_list != []:
s = search_list[0]
for i in connect_list[s]:
if distance_list[i[0]] == -1:
distance_list[i[0]] = (distance_list[s] + i[1]) % 2
search_list.append(i[0])
del search_list[0]
for i in distance_list:
print(i)
|
import sys
input = sys.stdin.readline
n = int(eval(input()))
connect_list = [[] for i in range(n)]
distance_list = [-1 for i in range(n)]
color_list = ["Gray" for i in range(n)]
distance_list[0] = 0
for i in range(n - 1):
u, v, w = [int(v) for v in input().split()]
w %= 2
connect_list[u - 1].append((v - 1, w))
connect_list[v - 1].append((u - 1, w))
search_list = [0]
while search_list != []:
s = search_list[0]
for i in connect_list[s]:
if distance_list[i[0]] == -1:
distance_list[i[0]] = (distance_list[s] + i[1]) % 2
search_list.append(i[0])
del search_list[0]
for i in distance_list:
print(i)
| false | 12.903226 |
[
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.03821 | 0.037538 | 1.017902 |
[
"s898155718",
"s337502866"
] |
u633068244
|
p00856
|
python
|
s747128689
|
s156456200
| 340 | 190 | 4,504 | 4,672 |
Accepted
|
Accepted
| 44.12 |
while 1:
N,T,L,B = list(map(int,input().split()))
if N == 0: break
lose = [int(input()) for i in range(L)]
back = [int(input()) for i in range(B)]
dp = [[0.0]*(N+1) for i in range(T+2)]
dp[0][0] = 1.0
ans = 0.0
p = 1.0/6.0
for t in range(T):
for i in range(N):
tt = t-1 if i in lose else t
for j in range(i+1,i+7):
if j > N: j = N-j%N
if j in back:
dp[t+1][0] += p*dp[tt][i]
else:
dp[t+1][j] += p*dp[tt][i]
dp[t+1][N] += dp[t][N]
print("%.6f"%dp[T][N])
|
while 1:
N,T,L,B = list(map(int,input().split()))
if N == 0: break
lose = set([int(input()) for i in range(L)])
back = set([int(input()) for i in range(B)])
dp = [[0.]*(N+1) for i in range(T+1)]
dp[0][0] = 1.
p = 1./6.
for t in range(T):
for i in range(N):
tt = t-1 if i in lose else t
for j in range(i+1,i+7):
if j > N: j = N-j%N
if j in back: j = 0
dp[t+1][j] += p*dp[tt][i]
dp[t+1][N] += dp[t][N]
print("%.6f"%dp[T][N])
| 21 | 17 | 652 | 573 |
while 1:
N, T, L, B = list(map(int, input().split()))
if N == 0:
break
lose = [int(input()) for i in range(L)]
back = [int(input()) for i in range(B)]
dp = [[0.0] * (N + 1) for i in range(T + 2)]
dp[0][0] = 1.0
ans = 0.0
p = 1.0 / 6.0
for t in range(T):
for i in range(N):
tt = t - 1 if i in lose else t
for j in range(i + 1, i + 7):
if j > N:
j = N - j % N
if j in back:
dp[t + 1][0] += p * dp[tt][i]
else:
dp[t + 1][j] += p * dp[tt][i]
dp[t + 1][N] += dp[t][N]
print("%.6f" % dp[T][N])
|
while 1:
N, T, L, B = list(map(int, input().split()))
if N == 0:
break
lose = set([int(input()) for i in range(L)])
back = set([int(input()) for i in range(B)])
dp = [[0.0] * (N + 1) for i in range(T + 1)]
dp[0][0] = 1.0
p = 1.0 / 6.0
for t in range(T):
for i in range(N):
tt = t - 1 if i in lose else t
for j in range(i + 1, i + 7):
if j > N:
j = N - j % N
if j in back:
j = 0
dp[t + 1][j] += p * dp[tt][i]
dp[t + 1][N] += dp[t][N]
print("%.6f" % dp[T][N])
| false | 19.047619 |
[
"- lose = [int(input()) for i in range(L)]",
"- back = [int(input()) for i in range(B)]",
"- dp = [[0.0] * (N + 1) for i in range(T + 2)]",
"+ lose = set([int(input()) for i in range(L)])",
"+ back = set([int(input()) for i in range(B)])",
"+ dp = [[0.0] * (N + 1) for i in range(T + 1)]",
"- ans = 0.0",
"- dp[t + 1][0] += p * dp[tt][i]",
"- else:",
"- dp[t + 1][j] += p * dp[tt][i]",
"+ j = 0",
"+ dp[t + 1][j] += p * dp[tt][i]"
] | false | 0.135977 | 0.080462 | 1.689954 |
[
"s747128689",
"s156456200"
] |
u919633157
|
p03673
|
python
|
s962104413
|
s878442383
| 205 | 177 | 26,300 | 24,516 |
Accepted
|
Accepted
| 13.66 |
n=int(eval(input()))
a=list(input().split())
even,odd=[],[]
for i in range(n):
if i%2==0:even+=[a[i]]
else:odd+=[a[i]]
if n%2==0:print((*odd[::-1]+even))
else:print((*even[::-1]+odd))
|
from collections import deque
n=int(eval(input()))
a=list(input().split())
que=deque()
for i in range(n):
if n%2==i%2:que.append(a[i])
else:que.appendleft(a[i])
print((*que))
| 11 | 11 | 195 | 188 |
n = int(eval(input()))
a = list(input().split())
even, odd = [], []
for i in range(n):
if i % 2 == 0:
even += [a[i]]
else:
odd += [a[i]]
if n % 2 == 0:
print((*odd[::-1] + even))
else:
print((*even[::-1] + odd))
|
from collections import deque
n = int(eval(input()))
a = list(input().split())
que = deque()
for i in range(n):
if n % 2 == i % 2:
que.append(a[i])
else:
que.appendleft(a[i])
print((*que))
| false | 0 |
[
"+from collections import deque",
"+",
"-even, odd = [], []",
"+que = deque()",
"- if i % 2 == 0:",
"- even += [a[i]]",
"+ if n % 2 == i % 2:",
"+ que.append(a[i])",
"- odd += [a[i]]",
"-if n % 2 == 0:",
"- print((*odd[::-1] + even))",
"-else:",
"- print((*even[::-1] + odd))",
"+ que.appendleft(a[i])",
"+print((*que))"
] | false | 0.086401 | 0.075875 | 1.138727 |
[
"s962104413",
"s878442383"
] |
u630554891
|
p02550
|
python
|
s442259989
|
s599112204
| 60 | 54 | 12,360 | 12,172 |
Accepted
|
Accepted
| 10 |
n,x,m=list(map(int, input().split()))
a=x
ans=a
flg=[0]*m
flg[a]=1
l=[a]
lp=-1
for i in range(1,m+1):
if n <= i:
break
tmp=(a*a)%m
a=tmp
if flg[a]==1:
lp = l.index(a)
break
else:
ans+=tmp
l.append(a)
flg[a]=1
if lp != -1:
l2 = l[lp:]
tmp = sum(l2)
b=(n-len(l))//len(l2)
c=n-len(l)-b*len(l2)
ans=ans+(b*tmp)+sum(l2[:c])
print(ans)
|
n,x,m=list(map(int, input().split()))
a=x
ans=a
flg=[0]*m
flg[a]=1
l=[a]
lp=-1
for i in range(1,n):
tmp=(a*a)%m
a=tmp
if flg[a]==1:
lp = l.index(a)
break
else:
ans+=tmp
l.append(a)
flg[a]=1
if lp != -1:
l2 = l[lp:]
tmp = sum(l2)
b=(n-len(l))//len(l2)
c=n-len(l)-b*len(l2)
ans=ans+(b*tmp)+sum(l2[:c])
print(ans)
| 29 | 27 | 449 | 413 |
n, x, m = list(map(int, input().split()))
a = x
ans = a
flg = [0] * m
flg[a] = 1
l = [a]
lp = -1
for i in range(1, m + 1):
if n <= i:
break
tmp = (a * a) % m
a = tmp
if flg[a] == 1:
lp = l.index(a)
break
else:
ans += tmp
l.append(a)
flg[a] = 1
if lp != -1:
l2 = l[lp:]
tmp = sum(l2)
b = (n - len(l)) // len(l2)
c = n - len(l) - b * len(l2)
ans = ans + (b * tmp) + sum(l2[:c])
print(ans)
|
n, x, m = list(map(int, input().split()))
a = x
ans = a
flg = [0] * m
flg[a] = 1
l = [a]
lp = -1
for i in range(1, n):
tmp = (a * a) % m
a = tmp
if flg[a] == 1:
lp = l.index(a)
break
else:
ans += tmp
l.append(a)
flg[a] = 1
if lp != -1:
l2 = l[lp:]
tmp = sum(l2)
b = (n - len(l)) // len(l2)
c = n - len(l) - b * len(l2)
ans = ans + (b * tmp) + sum(l2[:c])
print(ans)
| false | 6.896552 |
[
"-for i in range(1, m + 1):",
"- if n <= i:",
"- break",
"+for i in range(1, n):"
] | false | 0.046763 | 0.046735 | 1.000599 |
[
"s442259989",
"s599112204"
] |
u163320134
|
p02696
|
python
|
s054727864
|
s531073548
| 22 | 19 | 9,164 | 9,168 |
Accepted
|
Accepted
| 13.64 |
a,b,n=list(map(int,input().split()))
if b-1<=n:
x=b-1
else:
x=n
print(((a*x)//b-a*(x//b)))
|
a,b,n=list(map(int,input().split()))
x=min(b-1,n)
print(((a*x)//b-a*(x//b)))
| 6 | 3 | 91 | 70 |
a, b, n = list(map(int, input().split()))
if b - 1 <= n:
x = b - 1
else:
x = n
print(((a * x) // b - a * (x // b)))
|
a, b, n = list(map(int, input().split()))
x = min(b - 1, n)
print(((a * x) // b - a * (x // b)))
| false | 50 |
[
"-if b - 1 <= n:",
"- x = b - 1",
"-else:",
"- x = n",
"+x = min(b - 1, n)"
] | false | 0.039113 | 0.076722 | 0.509797 |
[
"s054727864",
"s531073548"
] |
u642874916
|
p02948
|
python
|
s770902524
|
s447730643
| 805 | 470 | 35,792 | 67,800 |
Accepted
|
Accepted
| 41.61 |
import heapq
class Job:
def __repr__(self):
return "%d,%d".format(self.days, self.reward)
def __lt__(self, other):
return self.reward < other.reward
def __init__(self, job_id, reward, days):
self.id = job_id
self.reward = reward
self.days = days
N, M = list(map(int, input().split()))
h = []
jobs = []
for i in range(N):
A, B = list(map(int, input().split()))
jobs.append(Job(job_id=i, reward=B, days=A))
jobs = sorted(jobs, key=lambda j: j.days)
idx = 0
c = 0
for i in range(1, M+1):
while idx < N and jobs[idx].days <= i:
heapq.heappush(h, -jobs[idx].reward)
idx += 1
if len(h) != 0:
c += -heapq.heappop(h)
print(c)
|
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
def I(): return int(input())
def MI(): return map(int, input().split())
def S(): return input()
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def show(*inp, end='\n'):
if show_flg:
print(*inp, end=end)
YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = True
show_flg = False
def main():
N, M = MI()
jobs = {}
ans = 0
for i in range(N):
A, B = MI()
if A not in jobs:
jobs[A] = []
jobs[A].append(B)
h = []
remaining_days = 1
while remaining_days <= M:
if remaining_days in jobs:
for rewards in jobs[remaining_days]:
heappush(h, -rewards)
if len(h) > 0:
rewards = heappop(h)
ans += -rewards
remaining_days += 1
print(ans)
if __name__ == '__main__':
main()
| 38 | 86 | 759 | 1,593 |
import heapq
class Job:
def __repr__(self):
return "%d,%d".format(self.days, self.reward)
def __lt__(self, other):
return self.reward < other.reward
def __init__(self, job_id, reward, days):
self.id = job_id
self.reward = reward
self.days = days
N, M = list(map(int, input().split()))
h = []
jobs = []
for i in range(N):
A, B = list(map(int, input().split()))
jobs.append(Job(job_id=i, reward=B, days=A))
jobs = sorted(jobs, key=lambda j: j.days)
idx = 0
c = 0
for i in range(1, M + 1):
while idx < N and jobs[idx].days <= i:
heapq.heappush(h, -jobs[idx].reward)
idx += 1
if len(h) != 0:
c += -heapq.heappop(h)
print(c)
|
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
def I():
return int(input())
def MI():
return map(int, input().split())
def S():
return input()
def MS():
return map(str, input().split())
def LI():
return [int(i) for i in input().split()]
def LI_():
return [int(i) - 1 for i in input().split()]
def StoI():
return [ord(i) - 97 for i in input()]
def ItoS(nn):
return chr(nn + 97)
def input():
return sys.stdin.readline().rstrip()
def show(*inp, end="\n"):
if show_flg:
print(*inp, end=end)
YN = ["No", "Yes"]
MOD = 10**9 + 7
inf = float("inf")
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
show_flg = True
show_flg = False
def main():
N, M = MI()
jobs = {}
ans = 0
for i in range(N):
A, B = MI()
if A not in jobs:
jobs[A] = []
jobs[A].append(B)
h = []
remaining_days = 1
while remaining_days <= M:
if remaining_days in jobs:
for rewards in jobs[remaining_days]:
heappush(h, -rewards)
if len(h) > 0:
rewards = heappop(h)
ans += -rewards
remaining_days += 1
print(ans)
if __name__ == "__main__":
main()
| false | 55.813953 |
[
"-import heapq",
"+from heapq import heappush, heappop, heapify",
"+from collections import deque, defaultdict, Counter",
"+import itertools",
"+from itertools import permutations, combinations, accumulate",
"+import sys",
"+import bisect",
"+import string",
"+import math",
"+import time",
"-class Job:",
"- def __repr__(self):",
"- return \"%d,%d\".format(self.days, self.reward)",
"-",
"- def __lt__(self, other):",
"- return self.reward < other.reward",
"-",
"- def __init__(self, job_id, reward, days):",
"- self.id = job_id",
"- self.reward = reward",
"- self.days = days",
"+def I():",
"+ return int(input())",
"-N, M = list(map(int, input().split()))",
"-h = []",
"-jobs = []",
"-for i in range(N):",
"- A, B = list(map(int, input().split()))",
"- jobs.append(Job(job_id=i, reward=B, days=A))",
"-jobs = sorted(jobs, key=lambda j: j.days)",
"-idx = 0",
"-c = 0",
"-for i in range(1, M + 1):",
"- while idx < N and jobs[idx].days <= i:",
"- heapq.heappush(h, -jobs[idx].reward)",
"- idx += 1",
"- if len(h) != 0:",
"- c += -heapq.heappop(h)",
"-print(c)",
"+def MI():",
"+ return map(int, input().split())",
"+",
"+",
"+def S():",
"+ return input()",
"+",
"+",
"+def MS():",
"+ return map(str, input().split())",
"+",
"+",
"+def LI():",
"+ return [int(i) for i in input().split()]",
"+",
"+",
"+def LI_():",
"+ return [int(i) - 1 for i in input().split()]",
"+",
"+",
"+def StoI():",
"+ return [ord(i) - 97 for i in input()]",
"+",
"+",
"+def ItoS(nn):",
"+ return chr(nn + 97)",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline().rstrip()",
"+",
"+",
"+def show(*inp, end=\"\\n\"):",
"+ if show_flg:",
"+ print(*inp, end=end)",
"+",
"+",
"+YN = [\"No\", \"Yes\"]",
"+MOD = 10**9 + 7",
"+inf = float(\"inf\")",
"+IINF = 10**10",
"+l_alp = string.ascii_lowercase",
"+u_alp = string.ascii_uppercase",
"+ts = time.time()",
"+sys.setrecursionlimit(10**6)",
"+nums = [\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\"]",
"+show_flg = True",
"+show_flg = False",
"+",
"+",
"+def main():",
"+ N, M = MI()",
"+ jobs = {}",
"+ ans = 0",
"+ for i in range(N):",
"+ A, B = MI()",
"+ if A not in jobs:",
"+ jobs[A] = []",
"+ jobs[A].append(B)",
"+ h = []",
"+ remaining_days = 1",
"+ while remaining_days <= M:",
"+ if remaining_days in jobs:",
"+ for rewards in jobs[remaining_days]:",
"+ heappush(h, -rewards)",
"+ if len(h) > 0:",
"+ rewards = heappop(h)",
"+ ans += -rewards",
"+ remaining_days += 1",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.044912 | 0.051509 | 0.871918 |
[
"s770902524",
"s447730643"
] |
u759412327
|
p03208
|
python
|
s789857295
|
s473883242
| 247 | 180 | 8,280 | 16,624 |
Accepted
|
Accepted
| 27.13 |
N,K = list(map(int,input().split()))
H = sorted([int(eval(input())) for n in range(N)])
a = 1e+9
for n in range(N-K+1):
a = min(a,H[n+K-1]-H[n])
print(a)
|
N,K = list(map(int,input().split()))
H = sorted([int(eval(input())) for n in range(N)])
A = []
for n in range(N-K+1):
A+=[H[n+K-1]-H[n]]
print((min(A)))
| 8 | 8 | 152 | 149 |
N, K = list(map(int, input().split()))
H = sorted([int(eval(input())) for n in range(N)])
a = 1e9
for n in range(N - K + 1):
a = min(a, H[n + K - 1] - H[n])
print(a)
|
N, K = list(map(int, input().split()))
H = sorted([int(eval(input())) for n in range(N)])
A = []
for n in range(N - K + 1):
A += [H[n + K - 1] - H[n]]
print((min(A)))
| false | 0 |
[
"-a = 1e9",
"+A = []",
"- a = min(a, H[n + K - 1] - H[n])",
"-print(a)",
"+ A += [H[n + K - 1] - H[n]]",
"+print((min(A)))"
] | false | 0.098169 | 0.036423 | 2.695245 |
[
"s789857295",
"s473883242"
] |
u212328220
|
p03087
|
python
|
s351540963
|
s982488805
| 490 | 450 | 30,716 | 22,900 |
Accepted
|
Accepted
| 8.16 |
N, Q = list(map(int,input().split()))
S = eval(input())
Q_lst = []
for i in range(Q):
Q_lst.append(list(map(int,input().split())))
ruiseki_lst = [0 for i in range(N)]
ruiseki_lst[0] = 0
for i in range(1,N):
if S[i] == 'C' and S[i-1] == 'A':
ruiseki_lst[i] = ruiseki_lst[i-1] + 1
else:
ruiseki_lst[i] = ruiseki_lst[i - 1]
for q in Q_lst:
left = q[0]-1
right = q[1]-1
print((ruiseki_lst[right] - ruiseki_lst[left]))
|
N ,Q = list(map(int,input().split()))
S = eval(input())
lst = []
for i in range(Q):
s,e = list(map(int,input().split()))
lst.append([s-1,e-1])
#print(lst)
cum = [0]*N
for i in range(1,N):
if S[i-1] == 'A' and S[i] == 'C':
cum[i] = cum[i-1] + 1
else:
cum[i] = cum[i - 1]
for v in lst:
print((cum[v[1]] - cum[v[0]]))
| 19 | 17 | 460 | 348 |
N, Q = list(map(int, input().split()))
S = eval(input())
Q_lst = []
for i in range(Q):
Q_lst.append(list(map(int, input().split())))
ruiseki_lst = [0 for i in range(N)]
ruiseki_lst[0] = 0
for i in range(1, N):
if S[i] == "C" and S[i - 1] == "A":
ruiseki_lst[i] = ruiseki_lst[i - 1] + 1
else:
ruiseki_lst[i] = ruiseki_lst[i - 1]
for q in Q_lst:
left = q[0] - 1
right = q[1] - 1
print((ruiseki_lst[right] - ruiseki_lst[left]))
|
N, Q = list(map(int, input().split()))
S = eval(input())
lst = []
for i in range(Q):
s, e = list(map(int, input().split()))
lst.append([s - 1, e - 1])
# print(lst)
cum = [0] * N
for i in range(1, N):
if S[i - 1] == "A" and S[i] == "C":
cum[i] = cum[i - 1] + 1
else:
cum[i] = cum[i - 1]
for v in lst:
print((cum[v[1]] - cum[v[0]]))
| false | 10.526316 |
[
"-Q_lst = []",
"+lst = []",
"- Q_lst.append(list(map(int, input().split())))",
"-ruiseki_lst = [0 for i in range(N)]",
"-ruiseki_lst[0] = 0",
"+ s, e = list(map(int, input().split()))",
"+ lst.append([s - 1, e - 1])",
"+# print(lst)",
"+cum = [0] * N",
"- if S[i] == \"C\" and S[i - 1] == \"A\":",
"- ruiseki_lst[i] = ruiseki_lst[i - 1] + 1",
"+ if S[i - 1] == \"A\" and S[i] == \"C\":",
"+ cum[i] = cum[i - 1] + 1",
"- ruiseki_lst[i] = ruiseki_lst[i - 1]",
"-for q in Q_lst:",
"- left = q[0] - 1",
"- right = q[1] - 1",
"- print((ruiseki_lst[right] - ruiseki_lst[left]))",
"+ cum[i] = cum[i - 1]",
"+for v in lst:",
"+ print((cum[v[1]] - cum[v[0]]))"
] | false | 0.043812 | 0.043391 | 1.009695 |
[
"s351540963",
"s982488805"
] |
u219417113
|
p03038
|
python
|
s990059220
|
s904193726
| 948 | 329 | 96,280 | 23,740 |
Accepted
|
Accepted
| 65.3 |
import heapq
from sys import exit
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = sorted([tuple(map(int, input().split())) for _ in range(M)], key=lambda x: x[1], reverse=True)
heapq.heapify(A)
ans = sum(A)
for b, c in BC:
for _ in range(b):
if len(A) == 0:
print(ans)
exit()
a = heapq.heappop(A)
if a < c:
ans += c - a
else:
print(ans)
exit()
print(ans)
|
def main():
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
BC = sorted([tuple(map(int, input().split())) for _ in range(M)], key=lambda x: x[1], reverse=True)
ind = 0
for b, c in BC:
for i in range(b):
if ind == N or A[ind] >= c:
break
A[ind] = c
ind += 1
print((sum(A)))
if __name__ == '__main__':
main()
| 20 | 18 | 497 | 486 |
import heapq
from sys import exit
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = sorted(
[tuple(map(int, input().split())) for _ in range(M)],
key=lambda x: x[1],
reverse=True,
)
heapq.heapify(A)
ans = sum(A)
for b, c in BC:
for _ in range(b):
if len(A) == 0:
print(ans)
exit()
a = heapq.heappop(A)
if a < c:
ans += c - a
else:
print(ans)
exit()
print(ans)
|
def main():
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
BC = sorted(
[tuple(map(int, input().split())) for _ in range(M)],
key=lambda x: x[1],
reverse=True,
)
ind = 0
for b, c in BC:
for i in range(b):
if ind == N or A[ind] >= c:
break
A[ind] = c
ind += 1
print((sum(A)))
if __name__ == "__main__":
main()
| false | 10 |
[
"-import heapq",
"-from sys import exit",
"+def main():",
"+ import sys",
"-N, M = list(map(int, input().split()))",
"-A = list(map(int, input().split()))",
"-BC = sorted(",
"- [tuple(map(int, input().split())) for _ in range(M)],",
"- key=lambda x: x[1],",
"- reverse=True,",
"-)",
"-heapq.heapify(A)",
"-ans = sum(A)",
"-for b, c in BC:",
"- for _ in range(b):",
"- if len(A) == 0:",
"- print(ans)",
"- exit()",
"- a = heapq.heappop(A)",
"- if a < c:",
"- ans += c - a",
"- else:",
"- print(ans)",
"- exit()",
"-print(ans)",
"+ input = sys.stdin.readline",
"+ N, M = list(map(int, input().split()))",
"+ A = sorted(list(map(int, input().split())))",
"+ BC = sorted(",
"+ [tuple(map(int, input().split())) for _ in range(M)],",
"+ key=lambda x: x[1],",
"+ reverse=True,",
"+ )",
"+ ind = 0",
"+ for b, c in BC:",
"+ for i in range(b):",
"+ if ind == N or A[ind] >= c:",
"+ break",
"+ A[ind] = c",
"+ ind += 1",
"+ print((sum(A)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.153555 | 0.035297 | 4.350439 |
[
"s990059220",
"s904193726"
] |
u318029285
|
p03999
|
python
|
s085856793
|
s594669983
| 20 | 18 | 3,060 | 3,060 |
Accepted
|
Accepted
| 10 |
s = eval(input())
n = len(s)
ans = 0
for bit in range(1 << (n - 1)):
f = s[0]
for i in range(n - 1):
if bit & (1 << i):
f += "+"
f += s[i + 1]
ans += sum(map(int, f.split("+")))
print(ans)
|
s = eval(input())
n = len(s)
def dfs(i, f):
if i == n - 1:
return sum(list(map(int, f.split("+"))))
return dfs(i + 1, f + s[i + 1]) + dfs(i + 1, f + "+" + s[i + 1])
print((dfs(0, s[0])))
| 16 | 12 | 242 | 210 |
s = eval(input())
n = len(s)
ans = 0
for bit in range(1 << (n - 1)):
f = s[0]
for i in range(n - 1):
if bit & (1 << i):
f += "+"
f += s[i + 1]
ans += sum(map(int, f.split("+")))
print(ans)
|
s = eval(input())
n = len(s)
def dfs(i, f):
if i == n - 1:
return sum(list(map(int, f.split("+"))))
return dfs(i + 1, f + s[i + 1]) + dfs(i + 1, f + "+" + s[i + 1])
print((dfs(0, s[0])))
| false | 25 |
[
"-ans = 0",
"-for bit in range(1 << (n - 1)):",
"- f = s[0]",
"- for i in range(n - 1):",
"- if bit & (1 << i):",
"- f += \"+\"",
"- f += s[i + 1]",
"- ans += sum(map(int, f.split(\"+\")))",
"-print(ans)",
"+",
"+",
"+def dfs(i, f):",
"+ if i == n - 1:",
"+ return sum(list(map(int, f.split(\"+\"))))",
"+ return dfs(i + 1, f + s[i + 1]) + dfs(i + 1, f + \"+\" + s[i + 1])",
"+",
"+",
"+print((dfs(0, s[0])))"
] | false | 0.039578 | 0.037396 | 1.05836 |
[
"s085856793",
"s594669983"
] |
u370331385
|
p03658
|
python
|
s017820034
|
s690088447
| 21 | 17 | 3,316 | 3,060 |
Accepted
|
Accepted
| 19.05 |
a=input().split()
b=input().split()
N=int(a[0])
K=int(a[1])
c=[]
s=0
for i in range(N):
l=int(b[i])
c.append(l)
c.sort(reverse=True)
for i in range(K):
s +=c[i]
print(s)
|
N,K = list(map(int,input().split()))
l = input().split()
sum = 0
for i in range(N):
l[i] = int(l[i])
l.sort()
for i in range(K):
sum += l.pop(-1)
print(sum)
| 14 | 11 | 186 | 166 |
a = input().split()
b = input().split()
N = int(a[0])
K = int(a[1])
c = []
s = 0
for i in range(N):
l = int(b[i])
c.append(l)
c.sort(reverse=True)
for i in range(K):
s += c[i]
print(s)
|
N, K = list(map(int, input().split()))
l = input().split()
sum = 0
for i in range(N):
l[i] = int(l[i])
l.sort()
for i in range(K):
sum += l.pop(-1)
print(sum)
| false | 21.428571 |
[
"-a = input().split()",
"-b = input().split()",
"-N = int(a[0])",
"-K = int(a[1])",
"-c = []",
"-s = 0",
"+N, K = list(map(int, input().split()))",
"+l = input().split()",
"+sum = 0",
"- l = int(b[i])",
"- c.append(l)",
"-c.sort(reverse=True)",
"+ l[i] = int(l[i])",
"+l.sort()",
"- s += c[i]",
"-print(s)",
"+ sum += l.pop(-1)",
"+print(sum)"
] | false | 0.040492 | 0.090744 | 0.44622 |
[
"s017820034",
"s690088447"
] |
u519939795
|
p02898
|
python
|
s974617630
|
s004672523
| 54 | 49 | 11,912 | 11,908 |
Accepted
|
Accepted
| 9.26 |
n,k=list(map(int,input().split()))
l=0
ll=list(map(int,input().split()))
for i in range(n):
if ll[i]>=k:
l+=1
print(l)
|
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
count = 0
for h in H:
if h >= K:
count += 1
print(count)
| 7 | 7 | 130 | 143 |
n, k = list(map(int, input().split()))
l = 0
ll = list(map(int, input().split()))
for i in range(n):
if ll[i] >= k:
l += 1
print(l)
|
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
count = 0
for h in H:
if h >= K:
count += 1
print(count)
| false | 0 |
[
"-n, k = list(map(int, input().split()))",
"-l = 0",
"-ll = list(map(int, input().split()))",
"-for i in range(n):",
"- if ll[i] >= k:",
"- l += 1",
"-print(l)",
"+N, K = list(map(int, input().split()))",
"+H = list(map(int, input().split()))",
"+count = 0",
"+for h in H:",
"+ if h >= K:",
"+ count += 1",
"+print(count)"
] | false | 0.047978 | 0.092947 | 0.516192 |
[
"s974617630",
"s004672523"
] |
u823885866
|
p03105
|
python
|
s676082733
|
s549466838
| 124 | 28 | 27,036 | 9,144 |
Accepted
|
Accepted
| 77.42 |
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: list(map(int, sys.stdin.buffer.readline().split()))
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7
a, b, c = rm()
print((min(c, b//a)))
|
import sys
rm = lambda: list(map(int, sys.stdin.buffer.readline().split()))
a, b, c = rm()
print((min(c, b//a)))
| 31 | 17 | 464 | 134 |
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: list(map(int, sys.stdin.buffer.readline().split()))
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float("inf")
mod = 10**9 + 7
a, b, c = rm()
print((min(c, b // a)))
|
import sys
rm = lambda: list(map(int, sys.stdin.buffer.readline().split()))
a, b, c = rm()
print((min(c, b // a)))
| false | 45.16129 |
[
"-import math",
"-import itertools",
"-import collections",
"-import heapq",
"-import re",
"-import numpy as np",
"-rr = lambda: sys.stdin.readline().rstrip()",
"-rs = lambda: sys.stdin.buffer.readline().split()",
"-ri = lambda: int(sys.stdin.readline())",
"-rl = lambda: list(map(int, sys.stdin.readline().split()))",
"-inf = float(\"inf\")",
"-mod = 10**9 + 7"
] | false | 0.109634 | 0.098345 | 1.114792 |
[
"s676082733",
"s549466838"
] |
u189023301
|
p03503
|
python
|
s746007999
|
s168838312
| 229 | 150 | 9,196 | 9,160 |
Accepted
|
Accepted
| 34.5 |
n = int(eval(input()))
arr = [list(map(int, input().split())) for i in range(n)]
arm = [list(map(int, input().split())) for j in range(n)]
ans = -9999999999
for item in range(1, 1024):
fund = 0
for i in range(n):
cou = 0
for x in range(10):
if (item >> x) % 2 == 1 and arr[i][x] == 1:
cou += 1
fund += arm[i][cou]
ans = max(ans, fund)
print(ans)
|
def solve():
n = int(eval(input()))
oc = [list(map(int, input().split())) for _ in range(n)]
prof = [list(map(int, input().split())) for _ in range(n)]
ans = -9999999999
for a in range(1, 1 << 10):
res = 0
for i in range(n):
cnt = 0
for x in range(10):
if (a >> x) % 2 == 1 and oc[i][x] == 1:
cnt += 1
res += prof[i][cnt]
ans = max(ans, res)
print(ans)
solve()
| 16 | 20 | 420 | 498 |
n = int(eval(input()))
arr = [list(map(int, input().split())) for i in range(n)]
arm = [list(map(int, input().split())) for j in range(n)]
ans = -9999999999
for item in range(1, 1024):
fund = 0
for i in range(n):
cou = 0
for x in range(10):
if (item >> x) % 2 == 1 and arr[i][x] == 1:
cou += 1
fund += arm[i][cou]
ans = max(ans, fund)
print(ans)
|
def solve():
n = int(eval(input()))
oc = [list(map(int, input().split())) for _ in range(n)]
prof = [list(map(int, input().split())) for _ in range(n)]
ans = -9999999999
for a in range(1, 1 << 10):
res = 0
for i in range(n):
cnt = 0
for x in range(10):
if (a >> x) % 2 == 1 and oc[i][x] == 1:
cnt += 1
res += prof[i][cnt]
ans = max(ans, res)
print(ans)
solve()
| false | 20 |
[
"-n = int(eval(input()))",
"-arr = [list(map(int, input().split())) for i in range(n)]",
"-arm = [list(map(int, input().split())) for j in range(n)]",
"-ans = -9999999999",
"-for item in range(1, 1024):",
"- fund = 0",
"- for i in range(n):",
"- cou = 0",
"- for x in range(10):",
"- if (item >> x) % 2 == 1 and arr[i][x] == 1:",
"- cou += 1",
"- fund += arm[i][cou]",
"- ans = max(ans, fund)",
"-print(ans)",
"+def solve():",
"+ n = int(eval(input()))",
"+ oc = [list(map(int, input().split())) for _ in range(n)]",
"+ prof = [list(map(int, input().split())) for _ in range(n)]",
"+ ans = -9999999999",
"+ for a in range(1, 1 << 10):",
"+ res = 0",
"+ for i in range(n):",
"+ cnt = 0",
"+ for x in range(10):",
"+ if (a >> x) % 2 == 1 and oc[i][x] == 1:",
"+ cnt += 1",
"+ res += prof[i][cnt]",
"+ ans = max(ans, res)",
"+ print(ans)",
"+",
"+",
"+solve()"
] | false | 0.042685 | 0.040932 | 1.042829 |
[
"s746007999",
"s168838312"
] |
u977389981
|
p03326
|
python
|
s952573656
|
s427898391
| 137 | 31 | 3,304 | 3,292 |
Accepted
|
Accepted
| 77.37 |
N, M = list(map(int, input().split()))
A = [[int(i) for i in input().split()] for i in range(N)]
ans = 0
for i in range(1 << 3):
x = bin(i)[2:]
while len(x) < 3:
x = '0' + x
op = ''
for j in x:
if j == '1':
op += '+'
else:
op += '-'
B = []
for j in range(N):
B.append(eval(op[0] + str(A[j][0]) + op[1] + str(A[j][1]) + op[2] + str(A[j][2])))
B.sort(reverse = True)
ans = max(ans, sum(B[:M]))
print(ans)
|
N, M = list(map(int, input().split()))
A = [[int(i) for i in input().split()] for i in range(N)]
def f(x):
if x == 1:
return 1
else:
return -1
ans = 0
for i in range(1 << 3):
B = []
for x, y, z in A:
B.append(f((i >> 2) & 1) * x + f((i >> 1) & 1) * y + f(i & 1) * z)
B.sort(reverse = True)
ans = max(ans, sum(B[:M]))
print(ans)
| 21 | 18 | 510 | 393 |
N, M = list(map(int, input().split()))
A = [[int(i) for i in input().split()] for i in range(N)]
ans = 0
for i in range(1 << 3):
x = bin(i)[2:]
while len(x) < 3:
x = "0" + x
op = ""
for j in x:
if j == "1":
op += "+"
else:
op += "-"
B = []
for j in range(N):
B.append(
eval(op[0] + str(A[j][0]) + op[1] + str(A[j][1]) + op[2] + str(A[j][2]))
)
B.sort(reverse=True)
ans = max(ans, sum(B[:M]))
print(ans)
|
N, M = list(map(int, input().split()))
A = [[int(i) for i in input().split()] for i in range(N)]
def f(x):
if x == 1:
return 1
else:
return -1
ans = 0
for i in range(1 << 3):
B = []
for x, y, z in A:
B.append(f((i >> 2) & 1) * x + f((i >> 1) & 1) * y + f(i & 1) * z)
B.sort(reverse=True)
ans = max(ans, sum(B[:M]))
print(ans)
| false | 14.285714 |
[
"+",
"+",
"+def f(x):",
"+ if x == 1:",
"+ return 1",
"+ else:",
"+ return -1",
"+",
"+",
"- x = bin(i)[2:]",
"- while len(x) < 3:",
"- x = \"0\" + x",
"- op = \"\"",
"- for j in x:",
"- if j == \"1\":",
"- op += \"+\"",
"- else:",
"- op += \"-\"",
"- for j in range(N):",
"- B.append(",
"- eval(op[0] + str(A[j][0]) + op[1] + str(A[j][1]) + op[2] + str(A[j][2]))",
"- )",
"+ for x, y, z in A:",
"+ B.append(f((i >> 2) & 1) * x + f((i >> 1) & 1) * y + f(i & 1) * z)"
] | false | 0.044392 | 0.043688 | 1.016123 |
[
"s952573656",
"s427898391"
] |
u548976218
|
p02689
|
python
|
s925693752
|
s685362645
| 315 | 248 | 31,888 | 20,060 |
Accepted
|
Accepted
| 21.27 |
n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
way = [list(map(int, input().split())) for _ in range(m)]
ans = [0]*n
for w in way:
a = w[0]
b = w[1]
if h[a-1] < h[b-1]:
ans[a-1] += 1
elif h[a-1] > h[b-1]:
ans[b-1] += 1
else:
ans[a-1] += 1
ans[b-1] += 1
count = 0
for a in ans:
if a == 0:
count += 1
print(count)
|
n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
ans = [0]*n
for i in range(m):
a, b = list(map(int, input().split()))
if h[a-1] < h[b-1]:
ans[a-1] += 1
elif h[a-1] > h[b-1]:
ans[b-1] += 1
else:
ans[a-1] += 1
ans[b-1] += 1
print((ans.count(0)))
| 21 | 15 | 419 | 320 |
n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
way = [list(map(int, input().split())) for _ in range(m)]
ans = [0] * n
for w in way:
a = w[0]
b = w[1]
if h[a - 1] < h[b - 1]:
ans[a - 1] += 1
elif h[a - 1] > h[b - 1]:
ans[b - 1] += 1
else:
ans[a - 1] += 1
ans[b - 1] += 1
count = 0
for a in ans:
if a == 0:
count += 1
print(count)
|
n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
ans = [0] * n
for i in range(m):
a, b = list(map(int, input().split()))
if h[a - 1] < h[b - 1]:
ans[a - 1] += 1
elif h[a - 1] > h[b - 1]:
ans[b - 1] += 1
else:
ans[a - 1] += 1
ans[b - 1] += 1
print((ans.count(0)))
| false | 28.571429 |
[
"-way = [list(map(int, input().split())) for _ in range(m)]",
"-for w in way:",
"- a = w[0]",
"- b = w[1]",
"+for i in range(m):",
"+ a, b = list(map(int, input().split()))",
"-count = 0",
"-for a in ans:",
"- if a == 0:",
"- count += 1",
"-print(count)",
"+print((ans.count(0)))"
] | false | 0.088462 | 0.045501 | 1.944185 |
[
"s925693752",
"s685362645"
] |
u729133443
|
p03836
|
python
|
s809588706
|
s962174626
| 168 | 17 | 38,256 | 3,060 |
Accepted
|
Accepted
| 89.88 |
a,b,x,y=list(map(int,input().split()));r,c=y-b,x-a;print(('R'*c+'U'*r+'L'*c+'D'*-~r+'R'*-~c+'U'*-~r+'LU'+'L'*-~c+'D'*-~r+'R'))
|
a,b,x,y=list(map(int,input().split()));r,c=y-b,x-a;R,L,U,D='RLUD';print((R*c+U*r+L*c+D*-~r+R*-~c+U*-~r+L+U+L*-~c+D*-~r+R))
| 1 | 1 | 118 | 114 |
a, b, x, y = list(map(int, input().split()))
r, c = y - b, x - a
print(
(
"R" * c
+ "U" * r
+ "L" * c
+ "D" * -~r
+ "R" * -~c
+ "U" * -~r
+ "LU"
+ "L" * -~c
+ "D" * -~r
+ "R"
)
)
|
a, b, x, y = list(map(int, input().split()))
r, c = y - b, x - a
R, L, U, D = "RLUD"
print(
(
R * c
+ U * r
+ L * c
+ D * -~r
+ R * -~c
+ U * -~r
+ L
+ U
+ L * -~c
+ D * -~r
+ R
)
)
| false | 0 |
[
"+R, L, U, D = \"RLUD\"",
"- \"R\" * c",
"- + \"U\" * r",
"- + \"L\" * c",
"- + \"D\" * -~r",
"- + \"R\" * -~c",
"- + \"U\" * -~r",
"- + \"LU\"",
"- + \"L\" * -~c",
"- + \"D\" * -~r",
"- + \"R\"",
"+ R * c",
"+ + U * r",
"+ + L * c",
"+ + D * -~r",
"+ + R * -~c",
"+ + U * -~r",
"+ + L",
"+ + U",
"+ + L * -~c",
"+ + D * -~r",
"+ + R"
] | false | 0.056686 | 0.036805 | 1.540185 |
[
"s809588706",
"s962174626"
] |
u101839330
|
p02796
|
python
|
s130151283
|
s746881188
| 1,996 | 529 | 44,452 | 43,688 |
Accepted
|
Accepted
| 73.5 |
from collections import deque
n = int(eval(input()))
list = [list(map(int,input().split())) for i in range(n)]
p = deque()
for i in list:
p.append([i[0] - i[1],i[0] + i[1]])
p = sorted(p,key = lambda x: x[1])
ex = []
ex.append(p.pop(0))
for i in range(len(p)):
if(ex[-1][1] <= p[0][0]):
ex.append(p.pop(0))
else:
p.pop(0)
print((len(ex)))
|
from collections import deque
n = int(eval(input()))
list = [list(map(int,input().split())) for i in range(n)]
p = []
for i in list:
p.append([i[0] - i[1],i[0] + i[1]])
p = sorted(p,key = lambda x: x[1])
p = deque(p)
ex = []
ex.append(p.popleft())
for i in range(len(p)):
if(ex[-1][1] <= p[0][0]):
ex.append(p.popleft())
else:
p.popleft()
print((len(ex)))
| 25 | 25 | 380 | 396 |
from collections import deque
n = int(eval(input()))
list = [list(map(int, input().split())) for i in range(n)]
p = deque()
for i in list:
p.append([i[0] - i[1], i[0] + i[1]])
p = sorted(p, key=lambda x: x[1])
ex = []
ex.append(p.pop(0))
for i in range(len(p)):
if ex[-1][1] <= p[0][0]:
ex.append(p.pop(0))
else:
p.pop(0)
print((len(ex)))
|
from collections import deque
n = int(eval(input()))
list = [list(map(int, input().split())) for i in range(n)]
p = []
for i in list:
p.append([i[0] - i[1], i[0] + i[1]])
p = sorted(p, key=lambda x: x[1])
p = deque(p)
ex = []
ex.append(p.popleft())
for i in range(len(p)):
if ex[-1][1] <= p[0][0]:
ex.append(p.popleft())
else:
p.popleft()
print((len(ex)))
| false | 0 |
[
"-p = deque()",
"+p = []",
"+p = deque(p)",
"-ex.append(p.pop(0))",
"+ex.append(p.popleft())",
"- ex.append(p.pop(0))",
"+ ex.append(p.popleft())",
"- p.pop(0)",
"+ p.popleft()"
] | false | 0.038761 | 0.085797 | 0.451782 |
[
"s130151283",
"s746881188"
] |
u935558307
|
p02955
|
python
|
s263840337
|
s604561228
| 186 | 139 | 74,612 | 68,472 |
Accepted
|
Accepted
| 25.27 |
"""
まず、答えは必ずAの総和以下になる。なぜなら、A同士の差の最大値がAの総和だからである。
移動回数が足りるのであれば、一つだけAの総和になるような項を作って、他を全部0にするのがよい。
ここからわかるのは、数を移動させ終わった後の各Aは全て0以上になるということである。
また答えはからなずAの総和の約数になる。
理由:
答えをXとすると、各AはbXと表すことができる。
したがって、Aの総和=(bの総和*X)となる。
ゆえに、答えXはAの総和の約数である。
解法としては、Aの総和の約数を列挙して、大きい順に実現可能かどうかを試していく。
実現可能かどうかを試すには、各Aを総和の約数dで割ったときの余りをもとめて、小さい順にソートする。
そのうえで、左からL番目までを「数を与える側」、L+1番目以降を「数をもらう側」として余りが0になるように調整できないかを確かめる。
これは累積和を活用することですくない計算量で実行可能である。
最後に、移動した数がK以下かどうかを確認する。
"""
from itertools import accumulate
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
sumA = sum(A)
yakusu = []
d = 1
while d*d < sumA:
if sumA%d == 0:
yakusu.append(d)
yakusu.append(sumA//d)
d += 1
if d*d == sumA:
yakusu.append(d)
yakusu.sort(reverse=True)
for d in yakusu:
#約数の大きい順に、実現可能かどうかを試していく。
rest = [a%d for a in A]
rest.sort()
rest = [a%d for a in A]
rest.sort()
Rrest = [d-r for r in rest]
Rrest = Rrest[::-1]
rest = [0]+list(accumulate(rest))
Rrest = [0]+list(accumulate(Rrest))
for i in range(N+1):
if rest[i] == Rrest[N-i]:
if rest[i] <= K:
print(d)
exit()
break
|
"""
どんなに操作をおこなっても、全てのi,j(i<j)に関して、Ai,Ajの絶対値の差がsum(A)より大きくなることはない。
したがって、答えがsum(A)より大きくなることはない。
さらに言うなら、数値の状態がワイルドカードである0がベストなので負の値にする必要もない。
また、答えはsum(A)の約数になる。
答えをXとおくと、全ての数はXで割り切れる=Xの倍数である。
Ai/X = Biとおくと、XBi = Ai と表すことができる。。
X*sum(B) = sum(A)なので、答えXはsum(A)の約数であることがわかる。
解法:
基本方針としては、sum(A)の約数を列挙して、K回以内の操作で大きい順に実現可能かどうかを調べる。
実現可能かどうかは、各Aiを数が引かれる方と足される方に分けることで考えることができる。
"""
from itertools import accumulate
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
sumA = sum(A)
#sumAの約数を列挙する。
yakusu = []
d = 1
while d*d < sumA:
if sumA%d == 0:
yakusu.append(d)
yakusu.append(sumA//d)
d += 1
if d*d == sumA:
yakusu.append(d)
yakusu.sort(reverse=True)
for d in yakusu:
X = [A[i]%d for i in range(N)]
X.sort()
Y = [d-x for x in X]
Y.sort()
X = list(accumulate(X))
Y = list(accumulate(Y))
Y = Y[::-1]
for i in range(N-1):
if X[i] == Y[i+1] and X[i]<=K:
print(d)
exit()
if X[N-1] == 0:
print(d)
exit()
| 49 | 47 | 1,229 | 1,070 |
"""
まず、答えは必ずAの総和以下になる。なぜなら、A同士の差の最大値がAの総和だからである。
移動回数が足りるのであれば、一つだけAの総和になるような項を作って、他を全部0にするのがよい。
ここからわかるのは、数を移動させ終わった後の各Aは全て0以上になるということである。
また答えはからなずAの総和の約数になる。
理由:
答えをXとすると、各AはbXと表すことができる。
したがって、Aの総和=(bの総和*X)となる。
ゆえに、答えXはAの総和の約数である。
解法としては、Aの総和の約数を列挙して、大きい順に実現可能かどうかを試していく。
実現可能かどうかを試すには、各Aを総和の約数dで割ったときの余りをもとめて、小さい順にソートする。
そのうえで、左からL番目までを「数を与える側」、L+1番目以降を「数をもらう側」として余りが0になるように調整できないかを確かめる。
これは累積和を活用することですくない計算量で実行可能である。
最後に、移動した数がK以下かどうかを確認する。
"""
from itertools import accumulate
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
sumA = sum(A)
yakusu = []
d = 1
while d * d < sumA:
if sumA % d == 0:
yakusu.append(d)
yakusu.append(sumA // d)
d += 1
if d * d == sumA:
yakusu.append(d)
yakusu.sort(reverse=True)
for d in yakusu:
# 約数の大きい順に、実現可能かどうかを試していく。
rest = [a % d for a in A]
rest.sort()
rest = [a % d for a in A]
rest.sort()
Rrest = [d - r for r in rest]
Rrest = Rrest[::-1]
rest = [0] + list(accumulate(rest))
Rrest = [0] + list(accumulate(Rrest))
for i in range(N + 1):
if rest[i] == Rrest[N - i]:
if rest[i] <= K:
print(d)
exit()
break
|
"""
どんなに操作をおこなっても、全てのi,j(i<j)に関して、Ai,Ajの絶対値の差がsum(A)より大きくなることはない。
したがって、答えがsum(A)より大きくなることはない。
さらに言うなら、数値の状態がワイルドカードである0がベストなので負の値にする必要もない。
また、答えはsum(A)の約数になる。
答えをXとおくと、全ての数はXで割り切れる=Xの倍数である。
Ai/X = Biとおくと、XBi = Ai と表すことができる。。
X*sum(B) = sum(A)なので、答えXはsum(A)の約数であることがわかる。
解法:
基本方針としては、sum(A)の約数を列挙して、K回以内の操作で大きい順に実現可能かどうかを調べる。
実現可能かどうかは、各Aiを数が引かれる方と足される方に分けることで考えることができる。
"""
from itertools import accumulate
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
sumA = sum(A)
# sumAの約数を列挙する。
yakusu = []
d = 1
while d * d < sumA:
if sumA % d == 0:
yakusu.append(d)
yakusu.append(sumA // d)
d += 1
if d * d == sumA:
yakusu.append(d)
yakusu.sort(reverse=True)
for d in yakusu:
X = [A[i] % d for i in range(N)]
X.sort()
Y = [d - x for x in X]
Y.sort()
X = list(accumulate(X))
Y = list(accumulate(Y))
Y = Y[::-1]
for i in range(N - 1):
if X[i] == Y[i + 1] and X[i] <= K:
print(d)
exit()
if X[N - 1] == 0:
print(d)
exit()
| false | 4.081633 |
[
"-まず、答えは必ずAの総和以下になる。なぜなら、A同士の差の最大値がAの総和だからである。",
"-移動回数が足りるのであれば、一つだけAの総和になるような項を作って、他を全部0にするのがよい。",
"-ここからわかるのは、数を移動させ終わった後の各Aは全て0以上になるということである。",
"-また答えはからなずAの総和の約数になる。",
"-理由:",
"-答えをXとすると、各AはbXと表すことができる。",
"-したがって、Aの総和=(bの総和*X)となる。",
"-ゆえに、答えXはAの総和の約数である。",
"-解法としては、Aの総和の約数を列挙して、大きい順に実現可能かどうかを試していく。",
"-実現可能かどうかを試すには、各Aを総和の約数dで割ったときの余りをもとめて、小さい順にソートする。",
"-そのうえで、左からL番目までを「数を与える側」、L+1番目以降を「数をもらう側」として余りが0になるように調整できないかを確かめる。",
"-これは累積和を活用することですくない計算量で実行可能である。",
"-最後に、移動した数がK以下かどうかを確認する。",
"+どんなに操作をおこなっても、全てのi,j(i<j)に関して、Ai,Ajの絶対値の差がsum(A)より大きくなることはない。",
"+したがって、答えがsum(A)より大きくなることはない。",
"+さらに言うなら、数値の状態がワイルドカードである0がベストなので負の値にする必要もない。",
"+また、答えはsum(A)の約数になる。",
"+答えをXとおくと、全ての数はXで割り切れる=Xの倍数である。",
"+Ai/X = Biとおくと、XBi = Ai と表すことができる。。",
"+X*sum(B) = sum(A)なので、答えXはsum(A)の約数であることがわかる。",
"+解法:",
"+基本方針としては、sum(A)の約数を列挙して、K回以内の操作で大きい順に実現可能かどうかを調べる。",
"+実現可能かどうかは、各Aiを数が引かれる方と足される方に分けることで考えることができる。",
"+# sumAの約数を列挙する。",
"- # 約数の大きい順に、実現可能かどうかを試していく。",
"- rest = [a % d for a in A]",
"- rest.sort()",
"- rest = [a % d for a in A]",
"- rest.sort()",
"- Rrest = [d - r for r in rest]",
"- Rrest = Rrest[::-1]",
"- rest = [0] + list(accumulate(rest))",
"- Rrest = [0] + list(accumulate(Rrest))",
"- for i in range(N + 1):",
"- if rest[i] == Rrest[N - i]:",
"- if rest[i] <= K:",
"- print(d)",
"- exit()",
"- break",
"+ X = [A[i] % d for i in range(N)]",
"+ X.sort()",
"+ Y = [d - x for x in X]",
"+ Y.sort()",
"+ X = list(accumulate(X))",
"+ Y = list(accumulate(Y))",
"+ Y = Y[::-1]",
"+ for i in range(N - 1):",
"+ if X[i] == Y[i + 1] and X[i] <= K:",
"+ print(d)",
"+ exit()",
"+ if X[N - 1] == 0:",
"+ print(d)",
"+ exit()"
] | false | 0.036034 | 0.036688 | 0.98217 |
[
"s263840337",
"s604561228"
] |
u943057856
|
p02831
|
python
|
s390911704
|
s080915696
| 36 | 30 | 5,176 | 9,144 |
Accepted
|
Accepted
| 16.67 |
import fractions
try:
A,B = list(map(int,input().split()))
def lcm(x, y):
return (x * y) // fractions.gcd(x, y)
print((lcm(A,B)))
except EOFError:
pass
|
a,b=list(map(int,input().split()))
#a,bの最大公約数
def gcd(a, b):
while b:
a, b = b, a % b
return a
#a,bの最小公倍数
def lcm(a, b):
return a * b // gcd (a, b)
print((lcm(a,b)))
| 8 | 13 | 174 | 192 |
import fractions
try:
A, B = list(map(int, input().split()))
def lcm(x, y):
return (x * y) // fractions.gcd(x, y)
print((lcm(A, B)))
except EOFError:
pass
|
a, b = list(map(int, input().split()))
# a,bの最大公約数
def gcd(a, b):
while b:
a, b = b, a % b
return a
# a,bの最小公倍数
def lcm(a, b):
return a * b // gcd(a, b)
print((lcm(a, b)))
| false | 38.461538 |
[
"-import fractions",
"+a, b = list(map(int, input().split()))",
"+# a,bの最大公約数",
"+def gcd(a, b):",
"+ while b:",
"+ a, b = b, a % b",
"+ return a",
"-try:",
"- A, B = list(map(int, input().split()))",
"- def lcm(x, y):",
"- return (x * y) // fractions.gcd(x, y)",
"+# a,bの最小公倍数",
"+def lcm(a, b):",
"+ return a * b // gcd(a, b)",
"- print((lcm(A, B)))",
"-except EOFError:",
"- pass",
"+",
"+print((lcm(a, b)))"
] | false | 0.046439 | 0.0388 | 1.196894 |
[
"s390911704",
"s080915696"
] |
u928784113
|
p03424
|
python
|
s321491420
|
s525302705
| 19 | 17 | 2,940 | 2,940 |
Accepted
|
Accepted
| 10.53 |
N = int(eval(input()))
S = list(map(str,input().split()))
if S.count("Y") == 0:
print("Three")
else:
print("Four")
|
N = int(eval(input()))
for i in (list(input().split())):
if i == "Y":
print("Four")
exit()
print("Three")
| 6 | 7 | 117 | 146 |
N = int(eval(input()))
S = list(map(str, input().split()))
if S.count("Y") == 0:
print("Three")
else:
print("Four")
|
N = int(eval(input()))
for i in list(input().split()):
if i == "Y":
print("Four")
exit()
print("Three")
| false | 14.285714 |
[
"-S = list(map(str, input().split()))",
"-if S.count(\"Y\") == 0:",
"- print(\"Three\")",
"-else:",
"- print(\"Four\")",
"+for i in list(input().split()):",
"+ if i == \"Y\":",
"+ print(\"Four\")",
"+ exit()",
"+print(\"Three\")"
] | false | 0.050746 | 0.057312 | 0.885444 |
[
"s321491420",
"s525302705"
] |
u821262411
|
p02633
|
python
|
s200965520
|
s113051145
| 31 | 23 | 9,072 | 9,044 |
Accepted
|
Accepted
| 25.81 |
import math
x=int(eval(input()))
print((x*360//(math.gcd(x,360))//x))
|
import math
x=int(eval(input()))
print((360//math.gcd(x,360)))
| 3 | 3 | 64 | 57 |
import math
x = int(eval(input()))
print((x * 360 // (math.gcd(x, 360)) // x))
|
import math
x = int(eval(input()))
print((360 // math.gcd(x, 360)))
| false | 0 |
[
"-print((x * 360 // (math.gcd(x, 360)) // x))",
"+print((360 // math.gcd(x, 360)))"
] | false | 0.048643 | 0.047712 | 1.019527 |
[
"s200965520",
"s113051145"
] |
u976225138
|
p03574
|
python
|
s135684751
|
s180120554
| 37 | 27 | 9,228 | 9,140 |
Accepted
|
Accepted
| 27.03 |
h, w = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
t = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
for j in range(w):
if s[i][j] == ".":
bombs = 0
for k in range(i - 1, i + 2):
for l in range(j - 1, j + 2):
if 0 <= k < h and 0 <= l < w:
if s[k][l] == "#":
bombs += 1
else:
t[i][j] = str(bombs)
else:
t[i][j] = "#"
else:
for i in range(h):
print(("".join(t[i])))
|
h, w = list(map(int, input().split()))
wall = ["." * (w + 2)]
s = wall + ["." + eval(input()) + "." for _ in range(h)] + wall
for i in range(1, h + 1):
for j in range(1, w + 1):
if s[i][j] == ".":
t = s[i-1][j-1:j+2] + s[i][j-1:j+2] + s[i+1][j-1:j+2]
s[i] = s[i][:j] + str(t.count("#")) + s[i][j+1:]
else:
print((s[i][1:-1]))
| 20 | 12 | 594 | 372 |
h, w = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
t = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
for j in range(w):
if s[i][j] == ".":
bombs = 0
for k in range(i - 1, i + 2):
for l in range(j - 1, j + 2):
if 0 <= k < h and 0 <= l < w:
if s[k][l] == "#":
bombs += 1
else:
t[i][j] = str(bombs)
else:
t[i][j] = "#"
else:
for i in range(h):
print(("".join(t[i])))
|
h, w = list(map(int, input().split()))
wall = ["." * (w + 2)]
s = wall + ["." + eval(input()) + "." for _ in range(h)] + wall
for i in range(1, h + 1):
for j in range(1, w + 1):
if s[i][j] == ".":
t = s[i - 1][j - 1 : j + 2] + s[i][j - 1 : j + 2] + s[i + 1][j - 1 : j + 2]
s[i] = s[i][:j] + str(t.count("#")) + s[i][j + 1 :]
else:
print((s[i][1:-1]))
| false | 40 |
[
"-s = [eval(input()) for _ in range(h)]",
"-t = [[0 for _ in range(w)] for _ in range(h)]",
"-for i in range(h):",
"- for j in range(w):",
"+wall = [\".\" * (w + 2)]",
"+s = wall + [\".\" + eval(input()) + \".\" for _ in range(h)] + wall",
"+for i in range(1, h + 1):",
"+ for j in range(1, w + 1):",
"- bombs = 0",
"- for k in range(i - 1, i + 2):",
"- for l in range(j - 1, j + 2):",
"- if 0 <= k < h and 0 <= l < w:",
"- if s[k][l] == \"#\":",
"- bombs += 1",
"- else:",
"- t[i][j] = str(bombs)",
"- else:",
"- t[i][j] = \"#\"",
"-else:",
"- for i in range(h):",
"- print((\"\".join(t[i])))",
"+ t = s[i - 1][j - 1 : j + 2] + s[i][j - 1 : j + 2] + s[i + 1][j - 1 : j + 2]",
"+ s[i] = s[i][:j] + str(t.count(\"#\")) + s[i][j + 1 :]",
"+ else:",
"+ print((s[i][1:-1]))"
] | false | 0.035941 | 0.035256 | 1.019449 |
[
"s135684751",
"s180120554"
] |
u519130434
|
p03835
|
python
|
s638974894
|
s075633100
| 1,286 | 18 | 3,060 | 3,060 |
Accepted
|
Accepted
| 98.6 |
K, S = list(map(int, input().split()))
Xs = [i for i in range(K+1)]
Ys = Xs[:]
count = 0
for x in Xs:
for y in Ys:
if 0<= S - x - y <= K:
count += 1
print(count)
|
K, S = list(map(int, input().split()))
Xs = [i for i in range(K+1)]
count = 0
for x in Xs:
yz = S - x
if 0 <= yz <= K*2:
count += K+1-abs(K-yz)
print(count)
| 11 | 11 | 191 | 184 |
K, S = list(map(int, input().split()))
Xs = [i for i in range(K + 1)]
Ys = Xs[:]
count = 0
for x in Xs:
for y in Ys:
if 0 <= S - x - y <= K:
count += 1
print(count)
|
K, S = list(map(int, input().split()))
Xs = [i for i in range(K + 1)]
count = 0
for x in Xs:
yz = S - x
if 0 <= yz <= K * 2:
count += K + 1 - abs(K - yz)
print(count)
| false | 0 |
[
"-Ys = Xs[:]",
"- for y in Ys:",
"- if 0 <= S - x - y <= K:",
"- count += 1",
"+ yz = S - x",
"+ if 0 <= yz <= K * 2:",
"+ count += K + 1 - abs(K - yz)"
] | false | 0.06569 | 0.042986 | 1.528185 |
[
"s638974894",
"s075633100"
] |
u532966492
|
p03805
|
python
|
s986360664
|
s693385345
| 39 | 28 | 8,052 | 3,064 |
Accepted
|
Accepted
| 28.21 |
N,M=list(map(int,input().split()))
inp=[list(map(int,input().split())) for _ in range(M)]
g=[[] for _ in range(N)]
[g[a-1].append(b-1) for a,b in inp]
[g[b-1].append(a-1) for a,b in inp]
from itertools import permutations
seq=[i for i in range(N)]
test=list(permutations(seq))
cnt=0
for t in test:
if t[0]==0:
for i in range(N-1):
if t[i+1] not in g[t[i]]:
break
else:
cnt+=1
print(cnt)
|
n,m=list(map(int,input().split()))
ab=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append(b-1) for a,b in ab]
[g[b-1].append(a-1) for a,b in ab]
from itertools import permutations
cnt=0
for i in permutations(list(range(1,n))):
i=(0,)+i
for j in range(n-1):
if i[j+1] not in g[i[j]]:
break
else:
cnt+=1
print(cnt)
| 18 | 17 | 459 | 391 |
N, M = list(map(int, input().split()))
inp = [list(map(int, input().split())) for _ in range(M)]
g = [[] for _ in range(N)]
[g[a - 1].append(b - 1) for a, b in inp]
[g[b - 1].append(a - 1) for a, b in inp]
from itertools import permutations
seq = [i for i in range(N)]
test = list(permutations(seq))
cnt = 0
for t in test:
if t[0] == 0:
for i in range(N - 1):
if t[i + 1] not in g[t[i]]:
break
else:
cnt += 1
print(cnt)
|
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in [0] * m]
g = [[] for _ in [0] * n]
[g[a - 1].append(b - 1) for a, b in ab]
[g[b - 1].append(a - 1) for a, b in ab]
from itertools import permutations
cnt = 0
for i in permutations(list(range(1, n))):
i = (0,) + i
for j in range(n - 1):
if i[j + 1] not in g[i[j]]:
break
else:
cnt += 1
print(cnt)
| false | 5.555556 |
[
"-N, M = list(map(int, input().split()))",
"-inp = [list(map(int, input().split())) for _ in range(M)]",
"-g = [[] for _ in range(N)]",
"-[g[a - 1].append(b - 1) for a, b in inp]",
"-[g[b - 1].append(a - 1) for a, b in inp]",
"+n, m = list(map(int, input().split()))",
"+ab = [list(map(int, input().split())) for _ in [0] * m]",
"+g = [[] for _ in [0] * n]",
"+[g[a - 1].append(b - 1) for a, b in ab]",
"+[g[b - 1].append(a - 1) for a, b in ab]",
"-seq = [i for i in range(N)]",
"-test = list(permutations(seq))",
"-for t in test:",
"- if t[0] == 0:",
"- for i in range(N - 1):",
"- if t[i + 1] not in g[t[i]]:",
"- break",
"- else:",
"- cnt += 1",
"+for i in permutations(list(range(1, n))):",
"+ i = (0,) + i",
"+ for j in range(n - 1):",
"+ if i[j + 1] not in g[i[j]]:",
"+ break",
"+ else:",
"+ cnt += 1"
] | false | 0.059766 | 0.038977 | 1.533359 |
[
"s986360664",
"s693385345"
] |
u547085427
|
p03347
|
python
|
s767201912
|
s446328530
| 422 | 357 | 11,048 | 11,052 |
Accepted
|
Accepted
| 15.4 |
n = int(eval(input()))
A = [-1]
for _ in range(n):
A.append(int(eval(input())))
num = 0
count = 0
if A[1] != 0:
print((-1))
else:
for i in range(n,0,-1):
if A[i] > num:
num = A[i]
count += num
elif A[i] < num:
print((-1))
break
num -= 1
else:
print(count)
|
n = int(eval(input()))
list = [int(eval(input())) for _ in range(n)]
def main(n, list):
result = 0
num = 0
if list[0] != 0:
return -1
for i in range(n - 1, - 1, - 1):
if list[i] >= num:
result += list[i]
num = list[i]
elif list[i] == num - 1:
num -= 1
else:
return -1
return result
print((main(n, list)))
| 21 | 20 | 361 | 416 |
n = int(eval(input()))
A = [-1]
for _ in range(n):
A.append(int(eval(input())))
num = 0
count = 0
if A[1] != 0:
print((-1))
else:
for i in range(n, 0, -1):
if A[i] > num:
num = A[i]
count += num
elif A[i] < num:
print((-1))
break
num -= 1
else:
print(count)
|
n = int(eval(input()))
list = [int(eval(input())) for _ in range(n)]
def main(n, list):
result = 0
num = 0
if list[0] != 0:
return -1
for i in range(n - 1, -1, -1):
if list[i] >= num:
result += list[i]
num = list[i]
elif list[i] == num - 1:
num -= 1
else:
return -1
return result
print((main(n, list)))
| false | 4.761905 |
[
"-A = [-1]",
"-for _ in range(n):",
"- A.append(int(eval(input())))",
"-num = 0",
"-count = 0",
"-if A[1] != 0:",
"- print((-1))",
"-else:",
"- for i in range(n, 0, -1):",
"- if A[i] > num:",
"- num = A[i]",
"- count += num",
"- elif A[i] < num:",
"- print((-1))",
"- break",
"- num -= 1",
"- else:",
"- print(count)",
"+list = [int(eval(input())) for _ in range(n)]",
"+",
"+",
"+def main(n, list):",
"+ result = 0",
"+ num = 0",
"+ if list[0] != 0:",
"+ return -1",
"+ for i in range(n - 1, -1, -1):",
"+ if list[i] >= num:",
"+ result += list[i]",
"+ num = list[i]",
"+ elif list[i] == num - 1:",
"+ num -= 1",
"+ else:",
"+ return -1",
"+ return result",
"+",
"+",
"+print((main(n, list)))"
] | false | 0.046904 | 0.044777 | 1.047506 |
[
"s767201912",
"s446328530"
] |
u375695365
|
p03610
|
python
|
s518118296
|
s727861811
| 83 | 19 | 5,288 | 3,192 |
Accepted
|
Accepted
| 77.11 |
s=str(input())
s=list(s)
for i in range(len(s)):
if i%2==0:
print(s[i],end="")
|
print((input()[::2]))
| 5 | 2 | 94 | 21 |
s = str(input())
s = list(s)
for i in range(len(s)):
if i % 2 == 0:
print(s[i], end="")
|
print((input()[::2]))
| false | 60 |
[
"-s = str(input())",
"-s = list(s)",
"-for i in range(len(s)):",
"- if i % 2 == 0:",
"- print(s[i], end=\"\")",
"+print((input()[::2]))"
] | false | 0.086973 | 0.057597 | 1.510026 |
[
"s518118296",
"s727861811"
] |
u565149926
|
p03574
|
python
|
s071993445
|
s928833094
| 31 | 27 | 3,444 | 3,188 |
Accepted
|
Accepted
| 12.9 |
def count_bombs(S, h, w):
count = 0
for i in range(h-1, h+2):
for j in range(w-1, w+2):
if i < 0 or j < 0 or i >= len(S) or j >= len(S[0]):
continue
if S[i][j] == "#":
count += 1
return count
H, W = map(int, input().split())
S = [input() for _ in range(H)]
for h in range(H):
for w in range(W):
if S[h][w] == "#":
print("#", end="")
continue
print(count_bombs(S, h, w), end="")
print()
|
H, W = list(map(int, input().split()))
S = [["."] * (W + 2)] + [["."] + list(eval(input())) + ["."] for _ in range(H)] + [["."] * (W + 2)]
for h in range(1, H + 1):
for w in range(1, W + 1):
if S[h][w] == "#":
continue
count = 0
for dh in range(-1, 2):
for dw in range(-1, 2):
if S[h + dh][w + dw] == "#":
count += 1
S[h][w] = str(count)
print(("".join(S[h][1:W+1])))
| 20 | 13 | 531 | 466 |
def count_bombs(S, h, w):
count = 0
for i in range(h - 1, h + 2):
for j in range(w - 1, w + 2):
if i < 0 or j < 0 or i >= len(S) or j >= len(S[0]):
continue
if S[i][j] == "#":
count += 1
return count
H, W = map(int, input().split())
S = [input() for _ in range(H)]
for h in range(H):
for w in range(W):
if S[h][w] == "#":
print("#", end="")
continue
print(count_bombs(S, h, w), end="")
print()
|
H, W = list(map(int, input().split()))
S = (
[["."] * (W + 2)]
+ [["."] + list(eval(input())) + ["."] for _ in range(H)]
+ [["."] * (W + 2)]
)
for h in range(1, H + 1):
for w in range(1, W + 1):
if S[h][w] == "#":
continue
count = 0
for dh in range(-1, 2):
for dw in range(-1, 2):
if S[h + dh][w + dw] == "#":
count += 1
S[h][w] = str(count)
print(("".join(S[h][1 : W + 1])))
| false | 35 |
[
"-def count_bombs(S, h, w):",
"- count = 0",
"- for i in range(h - 1, h + 2):",
"- for j in range(w - 1, w + 2):",
"- if i < 0 or j < 0 or i >= len(S) or j >= len(S[0]):",
"- continue",
"- if S[i][j] == \"#\":",
"- count += 1",
"- return count",
"-",
"-",
"-H, W = map(int, input().split())",
"-S = [input() for _ in range(H)]",
"-for h in range(H):",
"- for w in range(W):",
"+H, W = list(map(int, input().split()))",
"+S = (",
"+ [[\".\"] * (W + 2)]",
"+ + [[\".\"] + list(eval(input())) + [\".\"] for _ in range(H)]",
"+ + [[\".\"] * (W + 2)]",
"+)",
"+for h in range(1, H + 1):",
"+ for w in range(1, W + 1):",
"- print(\"#\", end=\"\")",
"- print(count_bombs(S, h, w), end=\"\")",
"- print()",
"+ count = 0",
"+ for dh in range(-1, 2):",
"+ for dw in range(-1, 2):",
"+ if S[h + dh][w + dw] == \"#\":",
"+ count += 1",
"+ S[h][w] = str(count)",
"+ print((\"\".join(S[h][1 : W + 1])))"
] | false | 0.033933 | 0.035808 | 0.947642 |
[
"s071993445",
"s928833094"
] |
u843175622
|
p02804
|
python
|
s530391170
|
s571699020
| 502 | 130 | 108,252 | 29,128 |
Accepted
|
Accepted
| 74.1 |
import numpy as np
import sys
from numba import njit, i8
mod = 10 ** 9 + 7
@njit((i8, i8, i8[:]), cache=True)
def main(n, k, a):
fac = np.full(n + 3, 1, dtype = np.int64)
for i in range(1, n + 1):
fac[i] = fac[i - 1] * i % mod
def inv(x):
res = 1
e = mod - 2
while e > 0:
if e & 1:
res = res * x % mod
x = x * x % mod
e >>= 1
return res
def c(n, k):
return fac[n] * inv(fac[n - k] * fac[k] % mod) % mod
ans = 0
for i in range(n - k + 1):
ans += (a[n - 1 - i] - a[i]) * c(n - 1 - i, k - 1)
ans %= mod
print(ans)
if __name__ == '__main__':
stdin = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
n, k = stdin[:2]
a = np.sort(stdin[2:])
main(n, k, a)
|
import numpy as np
import sys
mod = 10 ** 9 + 7
if sys.argv[-1] == 'ONLINE_JUDGE':
from numba.pycc import CC
cc = CC('unko')
@cc.export('main', '(i8, i8, i8[:])')
def main(n, k, a):
fac = np.full(n + 3, 1, dtype = np.int64)
for i in range(1, n + 1):
fac[i] = fac[i - 1] * i % mod
def inv(x):
res = 1
e = mod - 2
while e > 0:
if e & 1:
res = res * x % mod
x = x * x % mod
e >>= 1
return res
def c(n, k):
return fac[n] * inv(fac[n - k] * fac[k] % mod) % mod
ans = 0
for i in range(n - k + 1):
ans += (a[n - 1 - i] - a[i]) * c(n - 1 - i, k - 1)
ans %= mod
print(ans)
cc.compile()
exit()
if __name__ == '__main__':
from unko import main
stdin = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
n, k = stdin[:2]
a = np.sort(stdin[2:])
main(n, k, a)
| 35 | 41 | 737 | 866 |
import numpy as np
import sys
from numba import njit, i8
mod = 10**9 + 7
@njit((i8, i8, i8[:]), cache=True)
def main(n, k, a):
fac = np.full(n + 3, 1, dtype=np.int64)
for i in range(1, n + 1):
fac[i] = fac[i - 1] * i % mod
def inv(x):
res = 1
e = mod - 2
while e > 0:
if e & 1:
res = res * x % mod
x = x * x % mod
e >>= 1
return res
def c(n, k):
return fac[n] * inv(fac[n - k] * fac[k] % mod) % mod
ans = 0
for i in range(n - k + 1):
ans += (a[n - 1 - i] - a[i]) * c(n - 1 - i, k - 1)
ans %= mod
print(ans)
if __name__ == "__main__":
stdin = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=" ")
n, k = stdin[:2]
a = np.sort(stdin[2:])
main(n, k, a)
|
import numpy as np
import sys
mod = 10**9 + 7
if sys.argv[-1] == "ONLINE_JUDGE":
from numba.pycc import CC
cc = CC("unko")
@cc.export("main", "(i8, i8, i8[:])")
def main(n, k, a):
fac = np.full(n + 3, 1, dtype=np.int64)
for i in range(1, n + 1):
fac[i] = fac[i - 1] * i % mod
def inv(x):
res = 1
e = mod - 2
while e > 0:
if e & 1:
res = res * x % mod
x = x * x % mod
e >>= 1
return res
def c(n, k):
return fac[n] * inv(fac[n - k] * fac[k] % mod) % mod
ans = 0
for i in range(n - k + 1):
ans += (a[n - 1 - i] - a[i]) * c(n - 1 - i, k - 1)
ans %= mod
print(ans)
cc.compile()
exit()
if __name__ == "__main__":
from unko import main
stdin = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=" ")
n, k = stdin[:2]
a = np.sort(stdin[2:])
main(n, k, a)
| false | 14.634146 |
[
"-from numba import njit, i8",
"+if sys.argv[-1] == \"ONLINE_JUDGE\":",
"+ from numba.pycc import CC",
"+ cc = CC(\"unko\")",
"-@njit((i8, i8, i8[:]), cache=True)",
"-def main(n, k, a):",
"- fac = np.full(n + 3, 1, dtype=np.int64)",
"- for i in range(1, n + 1):",
"- fac[i] = fac[i - 1] * i % mod",
"+ @cc.export(\"main\", \"(i8, i8, i8[:])\")",
"+ def main(n, k, a):",
"+ fac = np.full(n + 3, 1, dtype=np.int64)",
"+ for i in range(1, n + 1):",
"+ fac[i] = fac[i - 1] * i % mod",
"- def inv(x):",
"- res = 1",
"- e = mod - 2",
"- while e > 0:",
"- if e & 1:",
"- res = res * x % mod",
"- x = x * x % mod",
"- e >>= 1",
"- return res",
"+ def inv(x):",
"+ res = 1",
"+ e = mod - 2",
"+ while e > 0:",
"+ if e & 1:",
"+ res = res * x % mod",
"+ x = x * x % mod",
"+ e >>= 1",
"+ return res",
"- def c(n, k):",
"- return fac[n] * inv(fac[n - k] * fac[k] % mod) % mod",
"+ def c(n, k):",
"+ return fac[n] * inv(fac[n - k] * fac[k] % mod) % mod",
"- ans = 0",
"- for i in range(n - k + 1):",
"- ans += (a[n - 1 - i] - a[i]) * c(n - 1 - i, k - 1)",
"- ans %= mod",
"- print(ans)",
"+ ans = 0",
"+ for i in range(n - k + 1):",
"+ ans += (a[n - 1 - i] - a[i]) * c(n - 1 - i, k - 1)",
"+ ans %= mod",
"+ print(ans)",
"+ cc.compile()",
"+ exit()",
"+if __name__ == \"__main__\":",
"+ from unko import main",
"-if __name__ == \"__main__\":"
] | false | 0.177187 | 0.228459 | 0.775575 |
[
"s530391170",
"s571699020"
] |
u077291787
|
p03448
|
python
|
s482790780
|
s630911488
| 63 | 18 | 3,064 | 3,060 |
Accepted
|
Accepted
| 71.43 |
## ABC087B - Coins
import sys
input = sys.stdin.readline
a, b, c, x = list(map(int, [input().rstrip() for _ in range(4)]))
count = 0
for i in range(min(a, int(x / 500)) + 1):
for j in range(min(b, int((x - i * 500) / 100)) + 1):
for k in range(c + 1):
if i * 500 + j * 100 + k * 50 > x:
break
if i * 500 + j * 100 + k * 50 == x:
count += 1
print(count)
|
##### ABC087B - Coins
a, b, c, x = list(map(int, [input().rstrip() for _ in range(4)]))
count = 0
for i in range(min(a, int(x / 500)) + 1):
for j in range(min(b, int((x - i * 500) / 100)) + 1):
if (x - i * 500 - j * 100) // 50 <= c and (x - i * 500 - j * 100) % 50 == 0:
count += 1
print(count)
| 15 | 9 | 436 | 327 |
## ABC087B - Coins
import sys
input = sys.stdin.readline
a, b, c, x = list(map(int, [input().rstrip() for _ in range(4)]))
count = 0
for i in range(min(a, int(x / 500)) + 1):
for j in range(min(b, int((x - i * 500) / 100)) + 1):
for k in range(c + 1):
if i * 500 + j * 100 + k * 50 > x:
break
if i * 500 + j * 100 + k * 50 == x:
count += 1
print(count)
|
##### ABC087B - Coins
a, b, c, x = list(map(int, [input().rstrip() for _ in range(4)]))
count = 0
for i in range(min(a, int(x / 500)) + 1):
for j in range(min(b, int((x - i * 500) / 100)) + 1):
if (x - i * 500 - j * 100) // 50 <= c and (x - i * 500 - j * 100) % 50 == 0:
count += 1
print(count)
| false | 40 |
[
"-## ABC087B - Coins",
"-import sys",
"-",
"-input = sys.stdin.readline",
"+##### ABC087B - Coins",
"- for k in range(c + 1):",
"- if i * 500 + j * 100 + k * 50 > x:",
"- break",
"- if i * 500 + j * 100 + k * 50 == x:",
"- count += 1",
"+ if (x - i * 500 - j * 100) // 50 <= c and (x - i * 500 - j * 100) % 50 == 0:",
"+ count += 1"
] | false | 0.046368 | 0.075224 | 0.616389 |
[
"s482790780",
"s630911488"
] |
u585482323
|
p03409
|
python
|
s083973368
|
s008083471
| 223 | 172 | 43,252 | 38,384 |
Accepted
|
Accepted
| 22.87 |
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = SR()
return l
mod = 1000000007
#A
def A():
return
#B
def B():
return
#C
def C():
def bfs(s,g,n):
bfs_map = [-1 for i in range(n)]
bfs_map[s] = 0
q = deque()
q.append(s)
fin = False
while q:
x = q.popleft()
for y in range(n):
if c[x][y] > 0 and bfs_map[y] < 0:
bfs_map[y] = bfs_map[x]+1
if y == g:
fin = True
break
q.append(y)
if fin:
break
if bfs_map[g] == -1:
return [None,0]
path = [None for i in range(bfs_map[g]+1)]
m = float("inf")
path[bfs_map[g]] = g
y = g
for i in range(bfs_map[g])[::-1]:
for x in range(n+1):
if c[x][y] > 0 and bfs_map[x] == bfs_map[y]-1:
path[i] = x
if c[x][y] < m:
m = c[x][y]
y = x
break
return [path,m]
def ford_fulkerson(s,g,c,n):
while 1:
p,m = bfs(s,g,n)
if not m:break
for i in range(len(p)-1):
c[p[i]][p[i+1]] -= m
c[p[i+1]][p[i]] += m
return sum(c[g])
n = I()
r = LIR(n)
b = LIR(n)
c = [[0 for i in range(2*n+2)] for i in range(2*n+2)]
for i in range(n):
c[0][i+1] = 1
for j in range(n):
if r[i][0] < b[j][0] and r[i][1] < b[j][1]:
c[i+1][n+j+1] = 1
for j in range(n):
c[n+j+1][2*n+1] = 1
print((ford_fulkerson(0,2*n+1,c,2*n+2)))
#D
def D():
n = I()
a = LI()
b = LI()
ans = 0
p = 1
for k in range(30):
s = 0
c = [b[i]%(p*2) for i in range(n)]
a_ = [a[i]%(p*2) for i in range(n)]
c.sort()
a_.sort()
l1,l2,l3 = 0,0,0
y = float("inf")
for x in a_[::-1]:
if x != y:
while l1 < n and c[l1] < p-x:l1 += 1
while l2 < n and c[l2] < 2*p-x:l2 += 1
while l3 < n and c[l3] < 3*p-x:l3 += 1
s += n-l2-l1-l3
y = x
ans += (s%2)*p
p *= 2
print(ans)
#E
def E():
return
#F
def F():
return
#G
def G():
return
#H
def H():
return
#Solve
if __name__ == "__main__":
C()
|
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n = I()
p = LIR(n)
q = LIR(n)
s = [(p[i][0],p[i][1],0) for i in range(n)]+[(q[i][0],q[i][1],1) for i in range(n)]
s.sort()
q = []
ans = 0
for x,y,i in s:
if not i:
q.append(y)
q.sort()
else:
j = bisect.bisect_left(q,y)-1
if j >= 0:
q.pop(j)
ans += 1
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
| 139 | 50 | 3,284 | 1,202 |
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return list(map(list, sys.stdin.readline().split()))
def S():
return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = SR()
return l
mod = 1000000007
# A
def A():
return
# B
def B():
return
# C
def C():
def bfs(s, g, n):
bfs_map = [-1 for i in range(n)]
bfs_map[s] = 0
q = deque()
q.append(s)
fin = False
while q:
x = q.popleft()
for y in range(n):
if c[x][y] > 0 and bfs_map[y] < 0:
bfs_map[y] = bfs_map[x] + 1
if y == g:
fin = True
break
q.append(y)
if fin:
break
if bfs_map[g] == -1:
return [None, 0]
path = [None for i in range(bfs_map[g] + 1)]
m = float("inf")
path[bfs_map[g]] = g
y = g
for i in range(bfs_map[g])[::-1]:
for x in range(n + 1):
if c[x][y] > 0 and bfs_map[x] == bfs_map[y] - 1:
path[i] = x
if c[x][y] < m:
m = c[x][y]
y = x
break
return [path, m]
def ford_fulkerson(s, g, c, n):
while 1:
p, m = bfs(s, g, n)
if not m:
break
for i in range(len(p) - 1):
c[p[i]][p[i + 1]] -= m
c[p[i + 1]][p[i]] += m
return sum(c[g])
n = I()
r = LIR(n)
b = LIR(n)
c = [[0 for i in range(2 * n + 2)] for i in range(2 * n + 2)]
for i in range(n):
c[0][i + 1] = 1
for j in range(n):
if r[i][0] < b[j][0] and r[i][1] < b[j][1]:
c[i + 1][n + j + 1] = 1
for j in range(n):
c[n + j + 1][2 * n + 1] = 1
print((ford_fulkerson(0, 2 * n + 1, c, 2 * n + 2)))
# D
def D():
n = I()
a = LI()
b = LI()
ans = 0
p = 1
for k in range(30):
s = 0
c = [b[i] % (p * 2) for i in range(n)]
a_ = [a[i] % (p * 2) for i in range(n)]
c.sort()
a_.sort()
l1, l2, l3 = 0, 0, 0
y = float("inf")
for x in a_[::-1]:
if x != y:
while l1 < n and c[l1] < p - x:
l1 += 1
while l2 < n and c[l2] < 2 * p - x:
l2 += 1
while l3 < n and c[l3] < 3 * p - x:
l3 += 1
s += n - l2 - l1 - l3
y = x
ans += (s % 2) * p
p *= 2
print(ans)
# E
def E():
return
# F
def F():
return
# G
def G():
return
# H
def H():
return
# Solve
if __name__ == "__main__":
C()
|
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n = I()
p = LIR(n)
q = LIR(n)
s = [(p[i][0], p[i][1], 0) for i in range(n)] + [
(q[i][0], q[i][1], 1) for i in range(n)
]
s.sort()
q = []
ans = 0
for x, y, i in s:
if not i:
q.append(y)
q.sort()
else:
j = bisect.bisect_left(q, y) - 1
if j >= 0:
q.pop(j)
ans += 1
print(ans)
return
# Solve
if __name__ == "__main__":
solve()
| false | 64.028777 |
[
"-from collections import defaultdict",
"-from collections import deque",
"+from collections import defaultdict, deque",
"+from itertools import permutations",
"-import random",
"- return list(map(int, sys.stdin.readline().split()))",
"+ return [int(x) for x in sys.stdin.readline().split()]",
"- return list(map(list, sys.stdin.readline().split()))",
"+ return [list(x) for x in sys.stdin.readline().split()]",
"- return list(sys.stdin.readline())[:-1]",
"+ res = list(sys.stdin.readline())",
"+ if res[-1] == \"\\n\":",
"+ return res[:-1]",
"+ return res",
"- l = [None for i in range(n)]",
"- for i in range(n):",
"- l[i] = I()",
"- return l",
"+ return [I() for i in range(n)]",
"- l = [None for i in range(n)]",
"- for i in range(n):",
"- l[i] = LI()",
"- return l",
"+ return [LI() for i in range(n)]",
"- l = [None for i in range(n)]",
"- for i in range(n):",
"- l[i] = S()",
"- return l",
"+ return [S() for i in range(n)]",
"- l = [None for i in range(n)]",
"- for i in range(n):",
"- l[i] = SR()",
"- return l",
"+ return [LS() for i in range(n)]",
"+sys.setrecursionlimit(1000000)",
"-# A",
"-def A():",
"- return",
"-# B",
"-def B():",
"- return",
"-",
"-",
"-# C",
"-def C():",
"- def bfs(s, g, n):",
"- bfs_map = [-1 for i in range(n)]",
"- bfs_map[s] = 0",
"- q = deque()",
"- q.append(s)",
"- fin = False",
"- while q:",
"- x = q.popleft()",
"- for y in range(n):",
"- if c[x][y] > 0 and bfs_map[y] < 0:",
"- bfs_map[y] = bfs_map[x] + 1",
"- if y == g:",
"- fin = True",
"- break",
"- q.append(y)",
"- if fin:",
"- break",
"- if bfs_map[g] == -1:",
"- return [None, 0]",
"- path = [None for i in range(bfs_map[g] + 1)]",
"- m = float(\"inf\")",
"- path[bfs_map[g]] = g",
"- y = g",
"- for i in range(bfs_map[g])[::-1]:",
"- for x in range(n + 1):",
"- if c[x][y] > 0 and bfs_map[x] == bfs_map[y] - 1:",
"- path[i] = x",
"- if c[x][y] < m:",
"- m = c[x][y]",
"- y = x",
"- break",
"- return [path, m]",
"-",
"- def ford_fulkerson(s, g, c, n):",
"- while 1:",
"- p, m = bfs(s, g, n)",
"- if not m:",
"- break",
"- for i in range(len(p) - 1):",
"- c[p[i]][p[i + 1]] -= m",
"- c[p[i + 1]][p[i]] += m",
"- return sum(c[g])",
"-",
"+def solve():",
"- r = LIR(n)",
"- b = LIR(n)",
"- c = [[0 for i in range(2 * n + 2)] for i in range(2 * n + 2)]",
"- for i in range(n):",
"- c[0][i + 1] = 1",
"- for j in range(n):",
"- if r[i][0] < b[j][0] and r[i][1] < b[j][1]:",
"- c[i + 1][n + j + 1] = 1",
"- for j in range(n):",
"- c[n + j + 1][2 * n + 1] = 1",
"- print((ford_fulkerson(0, 2 * n + 1, c, 2 * n + 2)))",
"-",
"-",
"-# D",
"-def D():",
"- n = I()",
"- a = LI()",
"- b = LI()",
"+ p = LIR(n)",
"+ q = LIR(n)",
"+ s = [(p[i][0], p[i][1], 0) for i in range(n)] + [",
"+ (q[i][0], q[i][1], 1) for i in range(n)",
"+ ]",
"+ s.sort()",
"+ q = []",
"- p = 1",
"- for k in range(30):",
"- s = 0",
"- c = [b[i] % (p * 2) for i in range(n)]",
"- a_ = [a[i] % (p * 2) for i in range(n)]",
"- c.sort()",
"- a_.sort()",
"- l1, l2, l3 = 0, 0, 0",
"- y = float(\"inf\")",
"- for x in a_[::-1]:",
"- if x != y:",
"- while l1 < n and c[l1] < p - x:",
"- l1 += 1",
"- while l2 < n and c[l2] < 2 * p - x:",
"- l2 += 1",
"- while l3 < n and c[l3] < 3 * p - x:",
"- l3 += 1",
"- s += n - l2 - l1 - l3",
"- y = x",
"- ans += (s % 2) * p",
"- p *= 2",
"+ for x, y, i in s:",
"+ if not i:",
"+ q.append(y)",
"+ q.sort()",
"+ else:",
"+ j = bisect.bisect_left(q, y) - 1",
"+ if j >= 0:",
"+ q.pop(j)",
"+ ans += 1",
"-",
"-",
"-# E",
"-def E():",
"- return",
"-",
"-",
"-# F",
"-def F():",
"- return",
"-",
"-",
"-# G",
"-def G():",
"- return",
"-",
"-",
"-# H",
"-def H():",
"- C()",
"+ solve()"
] | false | 0.042217 | 0.05143 | 0.820858 |
[
"s083973368",
"s008083471"
] |
u989345508
|
p02692
|
python
|
s223554725
|
s196891885
| 711 | 396 | 135,036 | 16,412 |
Accepted
|
Accepted
| 44.3 |
n,a,b,c=list(map(int,input().split()))
s_=[eval(input()) for i in range(n)]
ans=""
for i in range(n):
s1,s2=s_[i]
if s2=="B":
if a==1 and b==1 and i!=n-1:
if s_[i+1][0]=="A":
a,b,ans=(a+1,b-1,ans+"A")
else:
a,b,ans=(a-1,b+1,ans+"B")
continue
a,b,ans=(a-1,b+1,ans+"B") if a>b else (a+1,b-1,ans+"A")
if min(a,b)==-1:
print("No")
break
elif s1=="A":
if a==1 and c==1 and i!=n-1:
if s_[i+1][1]=="C":
a,c,ans=(a-1,c+1,ans+"C")
else:
a,c,ans=(a+1,c-1,ans+"A")
continue
a,c,ans=(a-1,c+1,ans+"C") if a>c else (a+1,c-1,ans+"A")
if min(a,c)==-1:
print("No")
break
else:
if c==1 and b==1 and i!=n-1:
if s_[i+1][1]=="C":
b,c,ans=(b-1,c+1,ans+"C")
else:
b,c,ans=(b+1,c-1,ans+"B")
continue
b,c,ans=(b-1,c+1,ans+"C") if b>c else (b+1,c-1,ans+"B")
if min(b,c)==-1:
print("No")
break
else:
print("Yes")
for j in range(n):
print((ans[j]))
|
n,a,b,c=list(map(int,input().split()))
s_=[eval(input()) for i in range(n)]
ans=""
for i in range(n):
s1,s2=s_[i]
if s2=="B":
if i!=n-1:
if s_[i+1]=="AC" and c==0 and a<=1:
a,b,ans=(a+1,b-1,ans+"A")
elif s_[i+1]=="BC" and c==0 and b<=1:
a,b,ans=(a-1,b+1,ans+"B")
else:
a,b,ans=(a-1,b+1,ans+"B") if a>b else (a+1,b-1,ans+"A")
else:
a,b,ans=(a-1,b+1,ans+"B") if a>b else (a+1,b-1,ans+"A")
if min(a,b)==-1:
print("No")
break
elif s1=="A":
if i!=n-1:
if s_[i+1]=="AB" and b==0 and a<=1:
a,c,ans=(a+1,c-1,ans+"A")
elif s_[i+1]=="BC" and b==0 and c<=1:
a,c,ans=(a-1,c+1,ans+"C")
else:
a,c,ans=(a-1,c+1,ans+"C") if a>c else (a+1,c-1,ans+"A")
else:
a,c,ans=(a-1,c+1,ans+"C") if a>c else (a+1,c-1,ans+"A")
if min(a,c)==-1:
print("No")
break
else:
if i!=n-1:
if s_[i+1]=="AB" and a==0 and b<=1:
b,c,ans=(b+1,c-1,ans+"B")
elif s_[i+1]=="AC" and a==0 and c<=1:
b,c,ans=(b-1,c+1,ans+"C")
else:
b,c,ans=(b-1,c+1,ans+"C") if b>c else (b+1,c-1,ans+"B")
else:
b,c,ans=(b-1,c+1,ans+"C") if b>c else (b+1,c-1,ans+"B")
if min(b,c)==-1:
print("No")
break
else:
print("Yes")
for j in range(n):
print((ans[j]))
| 43 | 49 | 1,230 | 1,587 |
n, a, b, c = list(map(int, input().split()))
s_ = [eval(input()) for i in range(n)]
ans = ""
for i in range(n):
s1, s2 = s_[i]
if s2 == "B":
if a == 1 and b == 1 and i != n - 1:
if s_[i + 1][0] == "A":
a, b, ans = (a + 1, b - 1, ans + "A")
else:
a, b, ans = (a - 1, b + 1, ans + "B")
continue
a, b, ans = (a - 1, b + 1, ans + "B") if a > b else (a + 1, b - 1, ans + "A")
if min(a, b) == -1:
print("No")
break
elif s1 == "A":
if a == 1 and c == 1 and i != n - 1:
if s_[i + 1][1] == "C":
a, c, ans = (a - 1, c + 1, ans + "C")
else:
a, c, ans = (a + 1, c - 1, ans + "A")
continue
a, c, ans = (a - 1, c + 1, ans + "C") if a > c else (a + 1, c - 1, ans + "A")
if min(a, c) == -1:
print("No")
break
else:
if c == 1 and b == 1 and i != n - 1:
if s_[i + 1][1] == "C":
b, c, ans = (b - 1, c + 1, ans + "C")
else:
b, c, ans = (b + 1, c - 1, ans + "B")
continue
b, c, ans = (b - 1, c + 1, ans + "C") if b > c else (b + 1, c - 1, ans + "B")
if min(b, c) == -1:
print("No")
break
else:
print("Yes")
for j in range(n):
print((ans[j]))
|
n, a, b, c = list(map(int, input().split()))
s_ = [eval(input()) for i in range(n)]
ans = ""
for i in range(n):
s1, s2 = s_[i]
if s2 == "B":
if i != n - 1:
if s_[i + 1] == "AC" and c == 0 and a <= 1:
a, b, ans = (a + 1, b - 1, ans + "A")
elif s_[i + 1] == "BC" and c == 0 and b <= 1:
a, b, ans = (a - 1, b + 1, ans + "B")
else:
a, b, ans = (
(a - 1, b + 1, ans + "B") if a > b else (a + 1, b - 1, ans + "A")
)
else:
a, b, ans = (
(a - 1, b + 1, ans + "B") if a > b else (a + 1, b - 1, ans + "A")
)
if min(a, b) == -1:
print("No")
break
elif s1 == "A":
if i != n - 1:
if s_[i + 1] == "AB" and b == 0 and a <= 1:
a, c, ans = (a + 1, c - 1, ans + "A")
elif s_[i + 1] == "BC" and b == 0 and c <= 1:
a, c, ans = (a - 1, c + 1, ans + "C")
else:
a, c, ans = (
(a - 1, c + 1, ans + "C") if a > c else (a + 1, c - 1, ans + "A")
)
else:
a, c, ans = (
(a - 1, c + 1, ans + "C") if a > c else (a + 1, c - 1, ans + "A")
)
if min(a, c) == -1:
print("No")
break
else:
if i != n - 1:
if s_[i + 1] == "AB" and a == 0 and b <= 1:
b, c, ans = (b + 1, c - 1, ans + "B")
elif s_[i + 1] == "AC" and a == 0 and c <= 1:
b, c, ans = (b - 1, c + 1, ans + "C")
else:
b, c, ans = (
(b - 1, c + 1, ans + "C") if b > c else (b + 1, c - 1, ans + "B")
)
else:
b, c, ans = (
(b - 1, c + 1, ans + "C") if b > c else (b + 1, c - 1, ans + "B")
)
if min(b, c) == -1:
print("No")
break
else:
print("Yes")
for j in range(n):
print((ans[j]))
| false | 12.244898 |
[
"- if a == 1 and b == 1 and i != n - 1:",
"- if s_[i + 1][0] == \"A\":",
"+ if i != n - 1:",
"+ if s_[i + 1] == \"AC\" and c == 0 and a <= 1:",
"+ elif s_[i + 1] == \"BC\" and c == 0 and b <= 1:",
"+ a, b, ans = (a - 1, b + 1, ans + \"B\")",
"- a, b, ans = (a - 1, b + 1, ans + \"B\")",
"- continue",
"- a, b, ans = (a - 1, b + 1, ans + \"B\") if a > b else (a + 1, b - 1, ans + \"A\")",
"+ a, b, ans = (",
"+ (a - 1, b + 1, ans + \"B\") if a > b else (a + 1, b - 1, ans + \"A\")",
"+ )",
"+ else:",
"+ a, b, ans = (",
"+ (a - 1, b + 1, ans + \"B\") if a > b else (a + 1, b - 1, ans + \"A\")",
"+ )",
"- if a == 1 and c == 1 and i != n - 1:",
"- if s_[i + 1][1] == \"C\":",
"+ if i != n - 1:",
"+ if s_[i + 1] == \"AB\" and b == 0 and a <= 1:",
"+ a, c, ans = (a + 1, c - 1, ans + \"A\")",
"+ elif s_[i + 1] == \"BC\" and b == 0 and c <= 1:",
"- a, c, ans = (a + 1, c - 1, ans + \"A\")",
"- continue",
"- a, c, ans = (a - 1, c + 1, ans + \"C\") if a > c else (a + 1, c - 1, ans + \"A\")",
"+ a, c, ans = (",
"+ (a - 1, c + 1, ans + \"C\") if a > c else (a + 1, c - 1, ans + \"A\")",
"+ )",
"+ else:",
"+ a, c, ans = (",
"+ (a - 1, c + 1, ans + \"C\") if a > c else (a + 1, c - 1, ans + \"A\")",
"+ )",
"- if c == 1 and b == 1 and i != n - 1:",
"- if s_[i + 1][1] == \"C\":",
"+ if i != n - 1:",
"+ if s_[i + 1] == \"AB\" and a == 0 and b <= 1:",
"+ b, c, ans = (b + 1, c - 1, ans + \"B\")",
"+ elif s_[i + 1] == \"AC\" and a == 0 and c <= 1:",
"- b, c, ans = (b + 1, c - 1, ans + \"B\")",
"- continue",
"- b, c, ans = (b - 1, c + 1, ans + \"C\") if b > c else (b + 1, c - 1, ans + \"B\")",
"+ b, c, ans = (",
"+ (b - 1, c + 1, ans + \"C\") if b > c else (b + 1, c - 1, ans + \"B\")",
"+ )",
"+ else:",
"+ b, c, ans = (",
"+ (b - 1, c + 1, ans + \"C\") if b > c else (b + 1, c - 1, ans + \"B\")",
"+ )"
] | false | 0.080443 | 0.039513 | 2.035878 |
[
"s223554725",
"s196891885"
] |
u498487134
|
p03014
|
python
|
s971947926
|
s169369486
| 750 | 656 | 124,376 | 363,204 |
Accepted
|
Accepted
| 12.53 |
H,W =list(map(int,input().split()))
S=[[] for _ in range(H+2)]
for i in range(H):
S[i+1]="#"+eval(input())+"#"
S[0]="#"*(W+2)
S[-1]="#"*(W+2)
hori=[[0]*(W+2) for _ in range(H+2)]
ver=[[0]*(W+2) for _ in range(H+2)]
def count(i,j):
if hori[i][j-1]==0:
count=0
for k in range(W):
if S[i][j+k]==".":
count+=1
else:
break
hori[i][j]=count
else:
hori[i][j]=hori[i][j-1]
if ver[i-1][j]==0:
count=0
for k in range(H):
if S[i+k][j]==".":
count+=1
else:
break
ver[i][j]=count
else:
ver[i][j]=ver[i-1][j]
return hori[i][j]+ver[i][j]-1
ans=0
for i in range(1,H+1):
for j in range(1,W+1):
if S[i][j]==".":
ans=max(ans,count(i,j))
print(ans)
|
import sys
input = sys.stdin.readline
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
H,W=MI()
S=[]
S.append(["#"]*(W+2))
for i in range(H):
s=["#"]+list(eval(input()))+["#"]
S.append(s)
S.append(["#"]*(W+2))
L=[[-1]*(W+2) for _ in range(H+2)]
R=[[-1]*(W+2) for _ in range(H+2)]
U=[[-1]*(W+2) for _ in range(H+2)]
D=[[-1]*(W+2) for _ in range(H+2)]
for i in range(1,H+1):
for j in range(1,W+1):
if S[i][j]!="#":
L[i][j]=L[i][j-1]+1
U[i][j]=U[i-1][j]+1
for i in range(H,0,-1):
for j in range(W,0,-1):
if S[i][j]!="#":
R[i][j]=R[i][j+1]+1
D[i][j]=D[i+1][j]+1
ans=0
for i in range(H+2):
for j in range(W+2):
if S[i][j]!="#":
temp=L[i][j]+R[i][j]+U[i][j]+D[i][j]+1
ans=max(ans,temp)
# for i in range(H+2):
# print(L[i])
# for i in range(H+2):
# print(R[i])
# for i in range(H+2):
# print(U[i])
# for i in range(H+2):
# print(D[i])
print(ans)
main()
| 41 | 54 | 897 | 1,355 |
H, W = list(map(int, input().split()))
S = [[] for _ in range(H + 2)]
for i in range(H):
S[i + 1] = "#" + eval(input()) + "#"
S[0] = "#" * (W + 2)
S[-1] = "#" * (W + 2)
hori = [[0] * (W + 2) for _ in range(H + 2)]
ver = [[0] * (W + 2) for _ in range(H + 2)]
def count(i, j):
if hori[i][j - 1] == 0:
count = 0
for k in range(W):
if S[i][j + k] == ".":
count += 1
else:
break
hori[i][j] = count
else:
hori[i][j] = hori[i][j - 1]
if ver[i - 1][j] == 0:
count = 0
for k in range(H):
if S[i + k][j] == ".":
count += 1
else:
break
ver[i][j] = count
else:
ver[i][j] = ver[i - 1][j]
return hori[i][j] + ver[i][j] - 1
ans = 0
for i in range(1, H + 1):
for j in range(1, W + 1):
if S[i][j] == ".":
ans = max(ans, count(i, j))
print(ans)
|
import sys
input = sys.stdin.readline
def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
def main():
mod = 10**9 + 7
H, W = MI()
S = []
S.append(["#"] * (W + 2))
for i in range(H):
s = ["#"] + list(eval(input())) + ["#"]
S.append(s)
S.append(["#"] * (W + 2))
L = [[-1] * (W + 2) for _ in range(H + 2)]
R = [[-1] * (W + 2) for _ in range(H + 2)]
U = [[-1] * (W + 2) for _ in range(H + 2)]
D = [[-1] * (W + 2) for _ in range(H + 2)]
for i in range(1, H + 1):
for j in range(1, W + 1):
if S[i][j] != "#":
L[i][j] = L[i][j - 1] + 1
U[i][j] = U[i - 1][j] + 1
for i in range(H, 0, -1):
for j in range(W, 0, -1):
if S[i][j] != "#":
R[i][j] = R[i][j + 1] + 1
D[i][j] = D[i + 1][j] + 1
ans = 0
for i in range(H + 2):
for j in range(W + 2):
if S[i][j] != "#":
temp = L[i][j] + R[i][j] + U[i][j] + D[i][j] + 1
ans = max(ans, temp)
# for i in range(H+2):
# print(L[i])
# for i in range(H+2):
# print(R[i])
# for i in range(H+2):
# print(U[i])
# for i in range(H+2):
# print(D[i])
print(ans)
main()
| false | 24.074074 |
[
"-H, W = list(map(int, input().split()))",
"-S = [[] for _ in range(H + 2)]",
"-for i in range(H):",
"- S[i + 1] = \"#\" + eval(input()) + \"#\"",
"-S[0] = \"#\" * (W + 2)",
"-S[-1] = \"#\" * (W + 2)",
"-hori = [[0] * (W + 2) for _ in range(H + 2)]",
"-ver = [[0] * (W + 2) for _ in range(H + 2)]",
"+import sys",
"+",
"+input = sys.stdin.readline",
"-def count(i, j):",
"- if hori[i][j - 1] == 0:",
"- count = 0",
"- for k in range(W):",
"- if S[i][j + k] == \".\":",
"- count += 1",
"- else:",
"- break",
"- hori[i][j] = count",
"- else:",
"- hori[i][j] = hori[i][j - 1]",
"- if ver[i - 1][j] == 0:",
"- count = 0",
"- for k in range(H):",
"- if S[i + k][j] == \".\":",
"- count += 1",
"- else:",
"- break",
"- ver[i][j] = count",
"- else:",
"- ver[i][j] = ver[i - 1][j]",
"- return hori[i][j] + ver[i][j] - 1",
"+def I():",
"+ return int(eval(input()))",
"-ans = 0",
"-for i in range(1, H + 1):",
"- for j in range(1, W + 1):",
"- if S[i][j] == \".\":",
"- ans = max(ans, count(i, j))",
"-print(ans)",
"+def MI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def LI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def main():",
"+ mod = 10**9 + 7",
"+ H, W = MI()",
"+ S = []",
"+ S.append([\"#\"] * (W + 2))",
"+ for i in range(H):",
"+ s = [\"#\"] + list(eval(input())) + [\"#\"]",
"+ S.append(s)",
"+ S.append([\"#\"] * (W + 2))",
"+ L = [[-1] * (W + 2) for _ in range(H + 2)]",
"+ R = [[-1] * (W + 2) for _ in range(H + 2)]",
"+ U = [[-1] * (W + 2) for _ in range(H + 2)]",
"+ D = [[-1] * (W + 2) for _ in range(H + 2)]",
"+ for i in range(1, H + 1):",
"+ for j in range(1, W + 1):",
"+ if S[i][j] != \"#\":",
"+ L[i][j] = L[i][j - 1] + 1",
"+ U[i][j] = U[i - 1][j] + 1",
"+ for i in range(H, 0, -1):",
"+ for j in range(W, 0, -1):",
"+ if S[i][j] != \"#\":",
"+ R[i][j] = R[i][j + 1] + 1",
"+ D[i][j] = D[i + 1][j] + 1",
"+ ans = 0",
"+ for i in range(H + 2):",
"+ for j in range(W + 2):",
"+ if S[i][j] != \"#\":",
"+ temp = L[i][j] + R[i][j] + U[i][j] + D[i][j] + 1",
"+ ans = max(ans, temp)",
"+ # for i in range(H+2):",
"+ # print(L[i])",
"+ # for i in range(H+2):",
"+ # print(R[i])",
"+ # for i in range(H+2):",
"+ # print(U[i])",
"+ # for i in range(H+2):",
"+ # print(D[i])",
"+ print(ans)",
"+",
"+",
"+main()"
] | false | 0.093315 | 0.08842 | 1.055367 |
[
"s971947926",
"s169369486"
] |
u624475441
|
p03503
|
python
|
s241527577
|
s442139578
| 71 | 57 | 3,064 | 3,064 |
Accepted
|
Accepted
| 19.72 |
N=int(eval(input()))
F=[int(input().replace(' ',''),2)for _ in[0]*N]
P=[list(map(int,input().split()))for _ in[0]*N]
ans = -float('inf')
for i in range(1,2**10):
sum = 0
for k in range(N):
sum += P[k][bin(F[k]&i).count('1')]
if ans < sum:
ans = sum
print(ans)
|
N=int(eval(input()))
F=[int(input().replace(' ',''),2)for _ in[0]*N]
P=[list(map(int,input().split()))for _ in[0]*N]
print((max(sum([p[bin(f&i).count('1')]for f,p in zip(F,P)])for i in range(1,2**10))))
| 11 | 4 | 291 | 197 |
N = int(eval(input()))
F = [int(input().replace(" ", ""), 2) for _ in [0] * N]
P = [list(map(int, input().split())) for _ in [0] * N]
ans = -float("inf")
for i in range(1, 2**10):
sum = 0
for k in range(N):
sum += P[k][bin(F[k] & i).count("1")]
if ans < sum:
ans = sum
print(ans)
|
N = int(eval(input()))
F = [int(input().replace(" ", ""), 2) for _ in [0] * N]
P = [list(map(int, input().split())) for _ in [0] * N]
print(
(
max(
sum([p[bin(f & i).count("1")] for f, p in zip(F, P)])
for i in range(1, 2**10)
)
)
)
| false | 63.636364 |
[
"-ans = -float(\"inf\")",
"-for i in range(1, 2**10):",
"- sum = 0",
"- for k in range(N):",
"- sum += P[k][bin(F[k] & i).count(\"1\")]",
"- if ans < sum:",
"- ans = sum",
"-print(ans)",
"+print(",
"+ (",
"+ max(",
"+ sum([p[bin(f & i).count(\"1\")] for f, p in zip(F, P)])",
"+ for i in range(1, 2**10)",
"+ )",
"+ )",
"+)"
] | false | 0.124055 | 0.115308 | 1.075864 |
[
"s241527577",
"s442139578"
] |
u597374218
|
p03495
|
python
|
s726762058
|
s364212576
| 372 | 92 | 56,984 | 35,996 |
Accepted
|
Accepted
| 75.27 |
from collections import Counter
n,k=list(map(int,input().split()))
a=Counter(input().split())
ans=0
keys,counts=list(zip(*a.most_common()))
for num,(key,count) in enumerate(zip(keys,counts)):
if int(num)>k-1:ans+=count
print(ans)
|
from collections import Counter
n,k=list(map(int,input().split()))
a=Counter(input().split())
print((sum(sorted(list(a.values()),reverse=True)[k:])))
| 8 | 4 | 228 | 138 |
from collections import Counter
n, k = list(map(int, input().split()))
a = Counter(input().split())
ans = 0
keys, counts = list(zip(*a.most_common()))
for num, (key, count) in enumerate(zip(keys, counts)):
if int(num) > k - 1:
ans += count
print(ans)
|
from collections import Counter
n, k = list(map(int, input().split()))
a = Counter(input().split())
print((sum(sorted(list(a.values()), reverse=True)[k:])))
| false | 50 |
[
"-ans = 0",
"-keys, counts = list(zip(*a.most_common()))",
"-for num, (key, count) in enumerate(zip(keys, counts)):",
"- if int(num) > k - 1:",
"- ans += count",
"-print(ans)",
"+print((sum(sorted(list(a.values()), reverse=True)[k:])))"
] | false | 0.083911 | 0.04498 | 1.865523 |
[
"s726762058",
"s364212576"
] |
u447562175
|
p02267
|
python
|
s348513600
|
s235472847
| 100 | 50 | 6,552 | 6,552 |
Accepted
|
Accepted
| 50 |
N = int(eval(input()))
S = [int(x) for x in input().split()]
T = int(eval(input()))
Q = [int(x) for x in input().split()]
c = set()
for s in S:
for q in Q:
if s == q:
c.add(s)
print((len(c)))
|
N = int(eval(input()))
S = [int(x) for x in input().split()]
T = int(eval(input()))
Q = [int(x) for x in input().split()]
c = 0
def seach(A, n, key):
i = 0
A = A + [key]
while A[i] != key:
i += 1
return i != n
for q in Q:
if seach(S, N, q):
c += 1
print(c)
| 13 | 19 | 217 | 311 |
N = int(eval(input()))
S = [int(x) for x in input().split()]
T = int(eval(input()))
Q = [int(x) for x in input().split()]
c = set()
for s in S:
for q in Q:
if s == q:
c.add(s)
print((len(c)))
|
N = int(eval(input()))
S = [int(x) for x in input().split()]
T = int(eval(input()))
Q = [int(x) for x in input().split()]
c = 0
def seach(A, n, key):
i = 0
A = A + [key]
while A[i] != key:
i += 1
return i != n
for q in Q:
if seach(S, N, q):
c += 1
print(c)
| false | 31.578947 |
[
"-c = set()",
"-for s in S:",
"- for q in Q:",
"- if s == q:",
"- c.add(s)",
"-print((len(c)))",
"+c = 0",
"+",
"+",
"+def seach(A, n, key):",
"+ i = 0",
"+ A = A + [key]",
"+ while A[i] != key:",
"+ i += 1",
"+ return i != n",
"+",
"+",
"+for q in Q:",
"+ if seach(S, N, q):",
"+ c += 1",
"+print(c)"
] | false | 0.161278 | 0.036335 | 4.438676 |
[
"s348513600",
"s235472847"
] |
u241190159
|
p03645
|
python
|
s782747357
|
s941807708
| 572 | 142 | 18,892 | 46,660 |
Accepted
|
Accepted
| 75.17 |
def main():
N, M = list(map(int, input().split()))
inter, goalable = set(), set()
for i in range(M):
a, b = list(map(int, input().split()))
if a == 1:
inter.add(b)
if b == N:
goalable.add(a)
flag = inter & goalable
print(("POSSIBLE" if flag else "IMPOSSIBLE"))
if __name__ == "__main__":
main()
|
def main():
N, M, *AB = list(map(int, open(0).read().split()))
inter, goalable = set(), set()
iterator = iter(AB)
for a, b in zip(iterator, iterator):
if a == 1:
inter.add(b)
if b == N:
goalable.add(a)
flag = inter & goalable
print(("POSSIBLE" if flag else "IMPOSSIBLE"))
if __name__ == "__main__":
main()
| 17 | 18 | 351 | 371 |
def main():
N, M = list(map(int, input().split()))
inter, goalable = set(), set()
for i in range(M):
a, b = list(map(int, input().split()))
if a == 1:
inter.add(b)
if b == N:
goalable.add(a)
flag = inter & goalable
print(("POSSIBLE" if flag else "IMPOSSIBLE"))
if __name__ == "__main__":
main()
|
def main():
N, M, *AB = list(map(int, open(0).read().split()))
inter, goalable = set(), set()
iterator = iter(AB)
for a, b in zip(iterator, iterator):
if a == 1:
inter.add(b)
if b == N:
goalable.add(a)
flag = inter & goalable
print(("POSSIBLE" if flag else "IMPOSSIBLE"))
if __name__ == "__main__":
main()
| false | 5.555556 |
[
"- N, M = list(map(int, input().split()))",
"+ N, M, *AB = list(map(int, open(0).read().split()))",
"- for i in range(M):",
"- a, b = list(map(int, input().split()))",
"+ iterator = iter(AB)",
"+ for a, b in zip(iterator, iterator):"
] | false | 0.046963 | 0.048588 | 0.966567 |
[
"s782747357",
"s941807708"
] |
u968166680
|
p03721
|
python
|
s201824393
|
s510460787
| 234 | 114 | 108,236 | 103,864 |
Accepted
|
Accepted
| 51.28 |
import sys
from collections import Counter
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, K, *AB = list(map(int, read().split()))
c = Counter()
for a, b in zip(*[iter(AB)] * 2):
c[a] += b
num = 0
for k, n in sorted(c.items()):
num += n
if num >= K:
ans = k
break
print(ans)
return
if __name__ == '__main__':
main()
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, K, *AB = list(map(int, read().split()))
vec = [0] * (10 ** 5 + 1)
for a, b in zip(*[iter(AB)] * 2):
vec[a] += b
total = 0
for i, n in enumerate(vec):
total += n
if total >= K:
ans = i
break
print(ans)
return
if __name__ == '__main__':
main()
| 30 | 29 | 539 | 523 |
import sys
from collections import Counter
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, K, *AB = list(map(int, read().split()))
c = Counter()
for a, b in zip(*[iter(AB)] * 2):
c[a] += b
num = 0
for k, n in sorted(c.items()):
num += n
if num >= K:
ans = k
break
print(ans)
return
if __name__ == "__main__":
main()
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, K, *AB = list(map(int, read().split()))
vec = [0] * (10**5 + 1)
for a, b in zip(*[iter(AB)] * 2):
vec[a] += b
total = 0
for i, n in enumerate(vec):
total += n
if total >= K:
ans = i
break
print(ans)
return
if __name__ == "__main__":
main()
| false | 3.333333 |
[
"-from collections import Counter",
"- c = Counter()",
"+ vec = [0] * (10**5 + 1)",
"- c[a] += b",
"- num = 0",
"- for k, n in sorted(c.items()):",
"- num += n",
"- if num >= K:",
"- ans = k",
"+ vec[a] += b",
"+ total = 0",
"+ for i, n in enumerate(vec):",
"+ total += n",
"+ if total >= K:",
"+ ans = i"
] | false | 0.03584 | 0.062467 | 0.573737 |
[
"s201824393",
"s510460787"
] |
u858885710
|
p02257
|
python
|
s181247053
|
s210184539
| 950 | 870 | 8,224 | 7,816 |
Accepted
|
Accepted
| 8.42 |
from sys import stdin
n = int(eval(input()))
xs = [int(eval(input())) for _ in range(n)]
ans = 0
for x in xs:
flg = True
for y in range(2, int(x**0.5+1)):
if x % y == 0:
flg = False
break
if flg:
ans += 1
print(ans)
|
n = int(eval(input()))
ans = 0
for x in (int(eval(input())) for _ in range(n)):
flg = True
for y in range(2, int(x**0.5+1)):
if x % y == 0:
flg = False
break
if flg:
ans += 1
print(ans)
| 17 | 13 | 275 | 239 |
from sys import stdin
n = int(eval(input()))
xs = [int(eval(input())) for _ in range(n)]
ans = 0
for x in xs:
flg = True
for y in range(2, int(x**0.5 + 1)):
if x % y == 0:
flg = False
break
if flg:
ans += 1
print(ans)
|
n = int(eval(input()))
ans = 0
for x in (int(eval(input())) for _ in range(n)):
flg = True
for y in range(2, int(x**0.5 + 1)):
if x % y == 0:
flg = False
break
if flg:
ans += 1
print(ans)
| false | 23.529412 |
[
"-from sys import stdin",
"-",
"-xs = [int(eval(input())) for _ in range(n)]",
"-for x in xs:",
"+for x in (int(eval(input())) for _ in range(n)):"
] | false | 0.153861 | 0.04329 | 3.554155 |
[
"s181247053",
"s210184539"
] |
u677440371
|
p03212
|
python
|
s184747580
|
s947664767
| 94 | 77 | 3,060 | 3,060 |
Accepted
|
Accepted
| 18.09 |
n = int(eval(input()))
def dfs(x):
if int(x) > n:
return 0
if all(x.count(i) > 0 for i in "753"):
ret = 1
else:
ret = 0
for i in "753":
ret += dfs(x+i)
return ret
print((dfs("0")))
|
n = int(eval(input()))
count = 0
def dfs(x):
global count
if int(x) > n:
return 0
for i in ('753'):
dfs(x+i)
check = True
for j in ('753'):
if x.find(j) == -1:
check = False
if check:
count += 1
return count
print((dfs('0')))
| 15 | 20 | 257 | 329 |
n = int(eval(input()))
def dfs(x):
if int(x) > n:
return 0
if all(x.count(i) > 0 for i in "753"):
ret = 1
else:
ret = 0
for i in "753":
ret += dfs(x + i)
return ret
print((dfs("0")))
|
n = int(eval(input()))
count = 0
def dfs(x):
global count
if int(x) > n:
return 0
for i in "753":
dfs(x + i)
check = True
for j in "753":
if x.find(j) == -1:
check = False
if check:
count += 1
return count
print((dfs("0")))
| false | 25 |
[
"+count = 0",
"+ global count",
"- if all(x.count(i) > 0 for i in \"753\"):",
"- ret = 1",
"- else:",
"- ret = 0",
"- ret += dfs(x + i)",
"- return ret",
"+ dfs(x + i)",
"+ check = True",
"+ for j in \"753\":",
"+ if x.find(j) == -1:",
"+ check = False",
"+ if check:",
"+ count += 1",
"+ return count"
] | false | 0.07157 | 0.066908 | 1.069688 |
[
"s184747580",
"s947664767"
] |
u708255304
|
p03069
|
python
|
s856652287
|
s957641856
| 331 | 191 | 12,804 | 12,772 |
Accepted
|
Accepted
| 42.3 |
N = int(eval(input()))
S = str(eval(input()))
# '.'の場合は白, '#'の場合は黒
if S[0] == '.':
count_white = [1]
count_black = [0]
else:
count_white = [0]
count_black = [1]
for i in range(1, N):
if S[i] == '.':
# 見ている石が白なら
count_white.append(count_white[i-1]+1)
count_black.append(count_black[i-1])
else:
# 見ている石が黒なら
count_white.append(count_white[i-1])
count_black.append(count_black[i-1]+1)
tmp = 9999999999
for i in range(1, N):
min_sum = 0
min_sum += count_black[i-1]
min_sum += (count_white[N-1] - count_white[i])
tmp = min(tmp, min_sum)
# print(tmp)
cnt = 0
target = S[0]
for i in range(1, N):
if target == '#' and S[i] == '.':
cnt += 1
target = '#' # 黒に変える
continue
if S[i] == '#':
target = '#'
else:
target = '.'
cnt_2 = 0
aim = S[-1]
for i in range(N-1, -1, -1):
if aim == '.' and S[i] == '#':
cnt_2 += 1
aim = '.'
continue
if S[i] == '#':
aim = '#'
else:
aim = '.'
print((int(min(cnt, cnt_2, tmp))))
|
n = int(eval(input()))
s = eval(input())
b = [0] # 黒の累積和
w = [0] # 白の累積和
count_b = 0
count_w = 0
for i in range(n):
if s[i] == "#":
# 黒なら
count_b += 1
else:
# 白なら
count_w += 1
b.append(count_b)
w.append(count_w)
ans = n
for i in range(n+1):
ans = min(ans, b[i]+w[-1]-w[i])
print(ans)
| 60 | 22 | 1,148 | 350 |
N = int(eval(input()))
S = str(eval(input()))
# '.'の場合は白, '#'の場合は黒
if S[0] == ".":
count_white = [1]
count_black = [0]
else:
count_white = [0]
count_black = [1]
for i in range(1, N):
if S[i] == ".":
# 見ている石が白なら
count_white.append(count_white[i - 1] + 1)
count_black.append(count_black[i - 1])
else:
# 見ている石が黒なら
count_white.append(count_white[i - 1])
count_black.append(count_black[i - 1] + 1)
tmp = 9999999999
for i in range(1, N):
min_sum = 0
min_sum += count_black[i - 1]
min_sum += count_white[N - 1] - count_white[i]
tmp = min(tmp, min_sum)
# print(tmp)
cnt = 0
target = S[0]
for i in range(1, N):
if target == "#" and S[i] == ".":
cnt += 1
target = "#" # 黒に変える
continue
if S[i] == "#":
target = "#"
else:
target = "."
cnt_2 = 0
aim = S[-1]
for i in range(N - 1, -1, -1):
if aim == "." and S[i] == "#":
cnt_2 += 1
aim = "."
continue
if S[i] == "#":
aim = "#"
else:
aim = "."
print((int(min(cnt, cnt_2, tmp))))
|
n = int(eval(input()))
s = eval(input())
b = [0] # 黒の累積和
w = [0] # 白の累積和
count_b = 0
count_w = 0
for i in range(n):
if s[i] == "#":
# 黒なら
count_b += 1
else:
# 白なら
count_w += 1
b.append(count_b)
w.append(count_w)
ans = n
for i in range(n + 1):
ans = min(ans, b[i] + w[-1] - w[i])
print(ans)
| false | 63.333333 |
[
"-N = int(eval(input()))",
"-S = str(eval(input()))",
"-# '.'の場合は白, '#'の場合は黒",
"-if S[0] == \".\":",
"- count_white = [1]",
"- count_black = [0]",
"-else:",
"- count_white = [0]",
"- count_black = [1]",
"-for i in range(1, N):",
"- if S[i] == \".\":",
"- # 見ている石が白なら",
"- count_white.append(count_white[i - 1] + 1)",
"- count_black.append(count_black[i - 1])",
"+n = int(eval(input()))",
"+s = eval(input())",
"+b = [0] # 黒の累積和",
"+w = [0] # 白の累積和",
"+count_b = 0",
"+count_w = 0",
"+for i in range(n):",
"+ if s[i] == \"#\":",
"+ # 黒なら",
"+ count_b += 1",
"- # 見ている石が黒なら",
"- count_white.append(count_white[i - 1])",
"- count_black.append(count_black[i - 1] + 1)",
"-tmp = 9999999999",
"-for i in range(1, N):",
"- min_sum = 0",
"- min_sum += count_black[i - 1]",
"- min_sum += count_white[N - 1] - count_white[i]",
"- tmp = min(tmp, min_sum)",
"-# print(tmp)",
"-cnt = 0",
"-target = S[0]",
"-for i in range(1, N):",
"- if target == \"#\" and S[i] == \".\":",
"- cnt += 1",
"- target = \"#\" # 黒に変える",
"- continue",
"- if S[i] == \"#\":",
"- target = \"#\"",
"- else:",
"- target = \".\"",
"-cnt_2 = 0",
"-aim = S[-1]",
"-for i in range(N - 1, -1, -1):",
"- if aim == \".\" and S[i] == \"#\":",
"- cnt_2 += 1",
"- aim = \".\"",
"- continue",
"- if S[i] == \"#\":",
"- aim = \"#\"",
"- else:",
"- aim = \".\"",
"-print((int(min(cnt, cnt_2, tmp))))",
"+ # 白なら",
"+ count_w += 1",
"+ b.append(count_b)",
"+ w.append(count_w)",
"+ans = n",
"+for i in range(n + 1):",
"+ ans = min(ans, b[i] + w[-1] - w[i])",
"+print(ans)"
] | false | 0.043451 | 0.044319 | 0.980414 |
[
"s856652287",
"s957641856"
] |
u729133443
|
p03295
|
python
|
s710150283
|
s390435085
| 734 | 271 | 29,140 | 25,020 |
Accepted
|
Accepted
| 63.08 |
n,m=list(map(int,input().split()))
s=[list(map(int,input().split()))for _ in range(m)]
s.sort(key=lambda x:x[0])
c=a=0
while c<m:
i=1
t=s[0][1]
while i<len(s)and s[i][0]<t:
t=min(t,s[i][1])
i+=1
c+=i
s=s[i:]
a+=1
print(a)
|
x=c=0
for b,a in sorted([[*list(map(int,t.split()))][::-1]for t in open(0)][1:]):
if a>x:x=b-1;c+=1
print(c)
| 14 | 4 | 268 | 106 |
n, m = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(m)]
s.sort(key=lambda x: x[0])
c = a = 0
while c < m:
i = 1
t = s[0][1]
while i < len(s) and s[i][0] < t:
t = min(t, s[i][1])
i += 1
c += i
s = s[i:]
a += 1
print(a)
|
x = c = 0
for b, a in sorted([[*list(map(int, t.split()))][::-1] for t in open(0)][1:]):
if a > x:
x = b - 1
c += 1
print(c)
| false | 71.428571 |
[
"-n, m = list(map(int, input().split()))",
"-s = [list(map(int, input().split())) for _ in range(m)]",
"-s.sort(key=lambda x: x[0])",
"-c = a = 0",
"-while c < m:",
"- i = 1",
"- t = s[0][1]",
"- while i < len(s) and s[i][0] < t:",
"- t = min(t, s[i][1])",
"- i += 1",
"- c += i",
"- s = s[i:]",
"- a += 1",
"-print(a)",
"+x = c = 0",
"+for b, a in sorted([[*list(map(int, t.split()))][::-1] for t in open(0)][1:]):",
"+ if a > x:",
"+ x = b - 1",
"+ c += 1",
"+print(c)"
] | false | 0.042959 | 0.127334 | 0.337375 |
[
"s710150283",
"s390435085"
] |
u323680411
|
p03807
|
python
|
s923580604
|
s143294270
| 387 | 68 | 3,064 | 14,112 |
Accepted
|
Accepted
| 82.43 |
import sys
def next_str() -> str:
result = ""
while True:
tmp = sys.stdin.read(1)
if tmp.strip() != "":
result += tmp
elif tmp != '\r':
break
return result
def next_int() -> int:
return int(next_str())
def main() -> None:
n = next_int()
od = 0
ev = 0
for i in range(n):
a = next_int()
if a % 2 == 0:
ev += 1
else:
od += 1
if od == 2:
od = 0
ev += 1
if ev == 2:
ev = 1
print(("YES" if ev + od == 1 else "NO"))
if __name__ == '__main__':
main()
|
def main() -> None:
n = int(eval(input()))
a = [int(s) for s in input().split()]
od = 0
ev = 0
for i in range(n):
if a[i] % 2 == 0:
ev += 1
else:
od += 1
if od == 2:
od = 0
ev += 1
if ev == 2:
ev = 1
print(("YES" if ev + od == 1 else "NO"))
if __name__ == '__main__':
main()
| 42 | 24 | 685 | 415 |
import sys
def next_str() -> str:
result = ""
while True:
tmp = sys.stdin.read(1)
if tmp.strip() != "":
result += tmp
elif tmp != "\r":
break
return result
def next_int() -> int:
return int(next_str())
def main() -> None:
n = next_int()
od = 0
ev = 0
for i in range(n):
a = next_int()
if a % 2 == 0:
ev += 1
else:
od += 1
if od == 2:
od = 0
ev += 1
if ev == 2:
ev = 1
print(("YES" if ev + od == 1 else "NO"))
if __name__ == "__main__":
main()
|
def main() -> None:
n = int(eval(input()))
a = [int(s) for s in input().split()]
od = 0
ev = 0
for i in range(n):
if a[i] % 2 == 0:
ev += 1
else:
od += 1
if od == 2:
od = 0
ev += 1
if ev == 2:
ev = 1
print(("YES" if ev + od == 1 else "NO"))
if __name__ == "__main__":
main()
| false | 42.857143 |
[
"-import sys",
"-",
"-",
"-def next_str() -> str:",
"- result = \"\"",
"- while True:",
"- tmp = sys.stdin.read(1)",
"- if tmp.strip() != \"\":",
"- result += tmp",
"- elif tmp != \"\\r\":",
"- break",
"- return result",
"-",
"-",
"-def next_int() -> int:",
"- return int(next_str())",
"-",
"-",
"- n = next_int()",
"+ n = int(eval(input()))",
"+ a = [int(s) for s in input().split()]",
"- a = next_int()",
"- if a % 2 == 0:",
"+ if a[i] % 2 == 0:"
] | false | 0.134048 | 0.121442 | 1.103806 |
[
"s923580604",
"s143294270"
] |
u460386402
|
p02773
|
python
|
s051606626
|
s851971297
| 640 | 480 | 32,988 | 35,624 |
Accepted
|
Accepted
| 25 |
n=int(eval(input()))
d={}
a=[]
for i in range(n):
s=eval(input())
if s not in d:
d[s]=1
else:
d[s]+=1
m=max(d.values())
for keys in list(d.keys()):
if d[keys]==m:
a.append(keys)
a=sorted(a)
for word in a:
print(word)
|
n=int(eval(input()))
s={}
l=[]
for i in range(n):
a=eval(input())
if a in s:
s[a]+=1
else:
s[a]=1
cou=max(s.values())
for k,v in list(s.items()):
if v==cou:
l.append(k)
ans=sorted(l)
for i in ans:
print(i)
| 19 | 20 | 245 | 240 |
n = int(eval(input()))
d = {}
a = []
for i in range(n):
s = eval(input())
if s not in d:
d[s] = 1
else:
d[s] += 1
m = max(d.values())
for keys in list(d.keys()):
if d[keys] == m:
a.append(keys)
a = sorted(a)
for word in a:
print(word)
|
n = int(eval(input()))
s = {}
l = []
for i in range(n):
a = eval(input())
if a in s:
s[a] += 1
else:
s[a] = 1
cou = max(s.values())
for k, v in list(s.items()):
if v == cou:
l.append(k)
ans = sorted(l)
for i in ans:
print(i)
| false | 5 |
[
"-d = {}",
"-a = []",
"+s = {}",
"+l = []",
"- s = eval(input())",
"- if s not in d:",
"- d[s] = 1",
"+ a = eval(input())",
"+ if a in s:",
"+ s[a] += 1",
"- d[s] += 1",
"-m = max(d.values())",
"-for keys in list(d.keys()):",
"- if d[keys] == m:",
"- a.append(keys)",
"-a = sorted(a)",
"-for word in a:",
"- print(word)",
"+ s[a] = 1",
"+cou = max(s.values())",
"+for k, v in list(s.items()):",
"+ if v == cou:",
"+ l.append(k)",
"+ans = sorted(l)",
"+for i in ans:",
"+ print(i)"
] | false | 0.036689 | 0.03595 | 1.02056 |
[
"s051606626",
"s851971297"
] |
u887207211
|
p03712
|
python
|
s805083979
|
s573496996
| 19 | 17 | 3,060 | 3,060 |
Accepted
|
Accepted
| 10.53 |
H, W = list(map(int,input().split()))
A = [eval(input()) for _ in range(H)]
result = []
for a in A:
result.append('#' + a +'#')
waku = '#' * (W+2)
result.insert(0,waku)
result.insert(len(A)+1,waku)
for r in result:
print(r)
"""
お前の目は節穴か?
"""
|
H, W = list(map(int,input().split()))
A = ['#' + eval(input()) + '#' for _ in range(H)]
result = []
result.append('#' * (W+2))
for a in A:
result.append(a)
result.append('#' * (W+2))
for r in result:
print(r)
| 15 | 9 | 249 | 208 |
H, W = list(map(int, input().split()))
A = [eval(input()) for _ in range(H)]
result = []
for a in A:
result.append("#" + a + "#")
waku = "#" * (W + 2)
result.insert(0, waku)
result.insert(len(A) + 1, waku)
for r in result:
print(r)
"""
お前の目は節穴か?
"""
|
H, W = list(map(int, input().split()))
A = ["#" + eval(input()) + "#" for _ in range(H)]
result = []
result.append("#" * (W + 2))
for a in A:
result.append(a)
result.append("#" * (W + 2))
for r in result:
print(r)
| false | 40 |
[
"-A = [eval(input()) for _ in range(H)]",
"+A = [\"#\" + eval(input()) + \"#\" for _ in range(H)]",
"+result.append(\"#\" * (W + 2))",
"- result.append(\"#\" + a + \"#\")",
"-waku = \"#\" * (W + 2)",
"-result.insert(0, waku)",
"-result.insert(len(A) + 1, waku)",
"+ result.append(a)",
"+result.append(\"#\" * (W + 2))",
"-\"\"\"",
"-お前の目は節穴か?",
"-\"\"\""
] | false | 0.037681 | 0.046071 | 0.817885 |
[
"s805083979",
"s573496996"
] |
u150984829
|
p02397
|
python
|
s949477496
|
s628309213
| 50 | 30 | 5,616 | 5,884 |
Accepted
|
Accepted
| 40 |
a=[]
while 1:
n=input()
if n=='0 0':break
x,y=map(int,n.split())
print(y,x) if x>y else print(n)
|
a=[]
while 1:
n=input()
if n=='0 0':break
a.append(n)
for s in a:
x,y=map(int,s.split())
print(f'{y} {x}') if x>y else print(s)
| 6 | 8 | 105 | 139 |
a = []
while 1:
n = input()
if n == "0 0":
break
x, y = map(int, n.split())
print(y, x) if x > y else print(n)
|
a = []
while 1:
n = input()
if n == "0 0":
break
a.append(n)
for s in a:
x, y = map(int, s.split())
print(f"{y} {x}") if x > y else print(s)
| false | 25 |
[
"- x, y = map(int, n.split())",
"- print(y, x) if x > y else print(n)",
"+ a.append(n)",
"+for s in a:",
"+ x, y = map(int, s.split())",
"+ print(f\"{y} {x}\") if x > y else print(s)"
] | false | 0.036869 | 0.037515 | 0.982776 |
[
"s949477496",
"s628309213"
] |
u377989038
|
p02743
|
python
|
s071397851
|
s051782615
| 34 | 18 | 5,076 | 2,940 |
Accepted
|
Accepted
| 47.06 |
from decimal import *
a, b, c = list(map(int, input().split()))
if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():
print("Yes")
else:
print("No")
|
a, b, c = list(map(int, input().split()))
if a + b >= c:
print("No")
else:
if (a + b - c) ** 2 > 4 * a * b:
print("Yes")
else:
print("No")
| 7 | 8 | 165 | 167 |
from decimal import *
a, b, c = list(map(int, input().split()))
if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():
print("Yes")
else:
print("No")
|
a, b, c = list(map(int, input().split()))
if a + b >= c:
print("No")
else:
if (a + b - c) ** 2 > 4 * a * b:
print("Yes")
else:
print("No")
| false | 12.5 |
[
"-from decimal import *",
"-",
"-if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():",
"- print(\"Yes\")",
"+if a + b >= c:",
"+ print(\"No\")",
"- print(\"No\")",
"+ if (a + b - c) ** 2 > 4 * a * b:",
"+ print(\"Yes\")",
"+ else:",
"+ print(\"No\")"
] | false | 0.038053 | 0.061452 | 0.619226 |
[
"s071397851",
"s051782615"
] |
u054514819
|
p03078
|
python
|
s471744024
|
s765582181
| 200 | 170 | 78,416 | 79,352 |
Accepted
|
Accepted
| 15 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
X, Y, Z, K = mapint()
Xs = list(mapint())
Ys = list(mapint())
Zs = list(mapint())
Xs.sort(reverse=True)
Ys.sort(reverse=True)
Zs.sort(reverse=True)
x, y, z = 0, 0, 0
from heapq import heappop, heappush
Q = []
heappush(Q, (-(Xs[x]+Ys[y]+Zs[z]), (x, y, z)))
s = set()
s.add((x, y, z))
for _ in range(K):
ans, (x, y, z) = heappop(Q)
print((-ans))
origin = [x, y, z]
for i in range(3):
xyz = origin[:]
xyz[i] += 1
x, y, z = xyz
if x>=X or y>=Y or z>=Z: continue
if not tuple(xyz) in s:
heappush(Q, (-(Xs[x]+Ys[y]+Zs[z]), (x, y, z)))
s.add((x, y, z))
|
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
X, Y, Z, K = mapint()
As = list(mapint())
Bs = list(mapint())
Cs = list(mapint())
As.sort(reverse=True)
Bs.sort(reverse=True)
Cs.sort(reverse=True)
from heapq import heappop, heappush
Q = []
heappush(Q, (-(As[0]+Bs[0]+Cs[0]), 0, 0, 0))
s = set()
for _ in range(K):
v, a, b, c = heappop(Q)
print((-v))
if a+1<X and not (a+1, b, c) in s:
s.add((a+1, b, c))
heappush(Q, (-(As[a+1]+Bs[b]+Cs[c]), a+1, b, c))
if b+1<Y and not (a, b+1, c) in s:
s.add((a, b+1, c))
heappush(Q, (-(As[a]+Bs[b+1]+Cs[c]), a, b+1, c))
if c+1<Z and not (a, b, c+1) in s:
s.add((a, b, c+1))
heappush(Q, (-(As[a]+Bs[b]+Cs[c+1]), a, b, c+1))
| 31 | 29 | 801 | 841 |
import sys
def input():
return sys.stdin.readline().strip()
def mapint():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
X, Y, Z, K = mapint()
Xs = list(mapint())
Ys = list(mapint())
Zs = list(mapint())
Xs.sort(reverse=True)
Ys.sort(reverse=True)
Zs.sort(reverse=True)
x, y, z = 0, 0, 0
from heapq import heappop, heappush
Q = []
heappush(Q, (-(Xs[x] + Ys[y] + Zs[z]), (x, y, z)))
s = set()
s.add((x, y, z))
for _ in range(K):
ans, (x, y, z) = heappop(Q)
print((-ans))
origin = [x, y, z]
for i in range(3):
xyz = origin[:]
xyz[i] += 1
x, y, z = xyz
if x >= X or y >= Y or z >= Z:
continue
if not tuple(xyz) in s:
heappush(Q, (-(Xs[x] + Ys[y] + Zs[z]), (x, y, z)))
s.add((x, y, z))
|
import sys
def input():
return sys.stdin.readline().strip()
def mapint():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
X, Y, Z, K = mapint()
As = list(mapint())
Bs = list(mapint())
Cs = list(mapint())
As.sort(reverse=True)
Bs.sort(reverse=True)
Cs.sort(reverse=True)
from heapq import heappop, heappush
Q = []
heappush(Q, (-(As[0] + Bs[0] + Cs[0]), 0, 0, 0))
s = set()
for _ in range(K):
v, a, b, c = heappop(Q)
print((-v))
if a + 1 < X and not (a + 1, b, c) in s:
s.add((a + 1, b, c))
heappush(Q, (-(As[a + 1] + Bs[b] + Cs[c]), a + 1, b, c))
if b + 1 < Y and not (a, b + 1, c) in s:
s.add((a, b + 1, c))
heappush(Q, (-(As[a] + Bs[b + 1] + Cs[c]), a, b + 1, c))
if c + 1 < Z and not (a, b, c + 1) in s:
s.add((a, b, c + 1))
heappush(Q, (-(As[a] + Bs[b] + Cs[c + 1]), a, b, c + 1))
| false | 6.451613 |
[
"-Xs = list(mapint())",
"-Ys = list(mapint())",
"-Zs = list(mapint())",
"-Xs.sort(reverse=True)",
"-Ys.sort(reverse=True)",
"-Zs.sort(reverse=True)",
"-x, y, z = 0, 0, 0",
"+As = list(mapint())",
"+Bs = list(mapint())",
"+Cs = list(mapint())",
"+As.sort(reverse=True)",
"+Bs.sort(reverse=True)",
"+Cs.sort(reverse=True)",
"-heappush(Q, (-(Xs[x] + Ys[y] + Zs[z]), (x, y, z)))",
"+heappush(Q, (-(As[0] + Bs[0] + Cs[0]), 0, 0, 0))",
"-s.add((x, y, z))",
"- ans, (x, y, z) = heappop(Q)",
"- print((-ans))",
"- origin = [x, y, z]",
"- for i in range(3):",
"- xyz = origin[:]",
"- xyz[i] += 1",
"- x, y, z = xyz",
"- if x >= X or y >= Y or z >= Z:",
"- continue",
"- if not tuple(xyz) in s:",
"- heappush(Q, (-(Xs[x] + Ys[y] + Zs[z]), (x, y, z)))",
"- s.add((x, y, z))",
"+ v, a, b, c = heappop(Q)",
"+ print((-v))",
"+ if a + 1 < X and not (a + 1, b, c) in s:",
"+ s.add((a + 1, b, c))",
"+ heappush(Q, (-(As[a + 1] + Bs[b] + Cs[c]), a + 1, b, c))",
"+ if b + 1 < Y and not (a, b + 1, c) in s:",
"+ s.add((a, b + 1, c))",
"+ heappush(Q, (-(As[a] + Bs[b + 1] + Cs[c]), a, b + 1, c))",
"+ if c + 1 < Z and not (a, b, c + 1) in s:",
"+ s.add((a, b, c + 1))",
"+ heappush(Q, (-(As[a] + Bs[b] + Cs[c + 1]), a, b, c + 1))"
] | false | 0.008814 | 0.044605 | 0.197594 |
[
"s471744024",
"s765582181"
] |
u489959379
|
p02684
|
python
|
s595940912
|
s383227356
| 669 | 550 | 288,248 | 278,064 |
Accepted
|
Accepted
| 17.79 |
import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
tree = [[] for _ in range(n)]
for idx, a in enumerate(A):
tree[idx].append(a - 1)
start = []
depth = [0 for _ in range(n)]
def dfs(v, p, d, cnt):
depth[v] = d
for u in tree[v]:
if visited[u]:
start.append([u + 1, depth[u], cnt + 1])
return
else:
visited[u] = True
dfs(u, v, d + 1, cnt + 1)
return
visited = [False for _ in range(n)]
visited[0] = True
dfs(0, -1, 0, 0)
if k <= start[0][1]:
print((depth.index(k) + 1))
else:
cnt = (k - start[0][1]) % (start[0][2] - start[0][1])
res = start[0][1] + cnt
print((depth.index(res) + 1))
if __name__ == '__main__':
resolve()
|
import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
tree = [[] for _ in range(n)]
for idx, a in enumerate(A):
tree[idx].append(a - 1)
def dfs(pre, dist):
depth[pre] = dist
for to in tree[pre]:
if depth[to] != f_inf:
cycle.append([depth[to], depth[pre] + 1])
return
else:
dfs(to, dist + 1)
cycle = []
depth = [f_inf for _ in range(n)]
dfs(0, 0)
cycle_start = cycle[0][0]
cycle_end = cycle[0][1]
if k <= cycle_start:
print((depth.index(k) + 1))
else:
remainder = (k - cycle_start) % (cycle_end - cycle_start)
res = cycle_start + remainder
print((depth.index(res) + 1))
if __name__ == '__main__':
resolve()
| 43 | 40 | 985 | 941 |
import sys
sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7
def resolve():
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
tree = [[] for _ in range(n)]
for idx, a in enumerate(A):
tree[idx].append(a - 1)
start = []
depth = [0 for _ in range(n)]
def dfs(v, p, d, cnt):
depth[v] = d
for u in tree[v]:
if visited[u]:
start.append([u + 1, depth[u], cnt + 1])
return
else:
visited[u] = True
dfs(u, v, d + 1, cnt + 1)
return
visited = [False for _ in range(n)]
visited[0] = True
dfs(0, -1, 0, 0)
if k <= start[0][1]:
print((depth.index(k) + 1))
else:
cnt = (k - start[0][1]) % (start[0][2] - start[0][1])
res = start[0][1] + cnt
print((depth.index(res) + 1))
if __name__ == "__main__":
resolve()
|
import sys
sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7
def resolve():
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
tree = [[] for _ in range(n)]
for idx, a in enumerate(A):
tree[idx].append(a - 1)
def dfs(pre, dist):
depth[pre] = dist
for to in tree[pre]:
if depth[to] != f_inf:
cycle.append([depth[to], depth[pre] + 1])
return
else:
dfs(to, dist + 1)
cycle = []
depth = [f_inf for _ in range(n)]
dfs(0, 0)
cycle_start = cycle[0][0]
cycle_end = cycle[0][1]
if k <= cycle_start:
print((depth.index(k) + 1))
else:
remainder = (k - cycle_start) % (cycle_end - cycle_start)
res = cycle_start + remainder
print((depth.index(res) + 1))
if __name__ == "__main__":
resolve()
| false | 6.976744 |
[
"- start = []",
"- depth = [0 for _ in range(n)]",
"- def dfs(v, p, d, cnt):",
"- depth[v] = d",
"- for u in tree[v]:",
"- if visited[u]:",
"- start.append([u + 1, depth[u], cnt + 1])",
"+ def dfs(pre, dist):",
"+ depth[pre] = dist",
"+ for to in tree[pre]:",
"+ if depth[to] != f_inf:",
"+ cycle.append([depth[to], depth[pre] + 1])",
"- visited[u] = True",
"- dfs(u, v, d + 1, cnt + 1)",
"- return",
"+ dfs(to, dist + 1)",
"- visited = [False for _ in range(n)]",
"- visited[0] = True",
"- dfs(0, -1, 0, 0)",
"- if k <= start[0][1]:",
"+ cycle = []",
"+ depth = [f_inf for _ in range(n)]",
"+ dfs(0, 0)",
"+ cycle_start = cycle[0][0]",
"+ cycle_end = cycle[0][1]",
"+ if k <= cycle_start:",
"- cnt = (k - start[0][1]) % (start[0][2] - start[0][1])",
"- res = start[0][1] + cnt",
"+ remainder = (k - cycle_start) % (cycle_end - cycle_start)",
"+ res = cycle_start + remainder"
] | false | 0.044649 | 0.039748 | 1.123296 |
[
"s595940912",
"s383227356"
] |
u017603316
|
p02819
|
python
|
s017663786
|
s802748246
| 169 | 62 | 38,512 | 63,712 |
Accepted
|
Accepted
| 63.31 |
X= int(eval(input()))
while True:
pf={}
m=X
for i in range(2,int(m**0.5)+1):
while m%i==0:
pf[i]=pf.get(i,0)+1
m//=i
if m>1:pf[m]=1
#print(pf)
if (len(pf)==1) and (list(pf.values())[0]==1):
break
else:
X +=1
print(m)
|
X = int(eval(input()))
while True:
pf={}
m=X
for i in range(2,int(m**0.5)+1):
while m%i==0:
pf[i]=pf.get(i,0)+1
m//=i
if m>1:pf[m]=1
#print(i,pf)
#print(len(list(pf)))
if len(list(pf))==1 and list(pf.values())[0]==1:
break
else:
X+=1
print(m)
| 18 | 20 | 314 | 340 |
X = int(eval(input()))
while True:
pf = {}
m = X
for i in range(2, int(m**0.5) + 1):
while m % i == 0:
pf[i] = pf.get(i, 0) + 1
m //= i
if m > 1:
pf[m] = 1
# print(pf)
if (len(pf) == 1) and (list(pf.values())[0] == 1):
break
else:
X += 1
print(m)
|
X = int(eval(input()))
while True:
pf = {}
m = X
for i in range(2, int(m**0.5) + 1):
while m % i == 0:
pf[i] = pf.get(i, 0) + 1
m //= i
if m > 1:
pf[m] = 1
# print(i,pf)
# print(len(list(pf)))
if len(list(pf)) == 1 and list(pf.values())[0] == 1:
break
else:
X += 1
print(m)
| false | 10 |
[
"- # print(pf)",
"- if (len(pf) == 1) and (list(pf.values())[0] == 1):",
"+ # print(i,pf)",
"+ # print(len(list(pf)))",
"+ if len(list(pf)) == 1 and list(pf.values())[0] == 1:"
] | false | 0.03593 | 0.034304 | 1.047416 |
[
"s017663786",
"s802748246"
] |
u612975321
|
p02782
|
python
|
s298320919
|
s045505126
| 768 | 225 | 167,316 | 204,928 |
Accepted
|
Accepted
| 70.7 |
import copy
def prepare(n, MOD):
# 1! - n! の計算
f = 1
factorials = [1] # 0!の分
for m in range(1, n + 1):
f *= m
f %= MOD
factorials.append(f)
# n!^-1 の計算
inv = pow(f, MOD - 2, MOD)
# n!^-1 - 1!^-1 の計算
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= MOD
invs[m - 1] = inv
return factorials, invs
def func(r, c):
return f[r+1+c+1] * i[r+1] % MOD * i[c+1] % MOD
MOD = 10**9+7
f, i = prepare(2*10**6 + 2, MOD)
r1, c1, r2, c2 = list(map(int,input().split()))
combi = func(r2, c2) - func(r2, c1-1) - func(r1-1, c2) + func(r1-1, c1-1)
print((combi % MOD))
|
def prepare(n, MOD):
# 1! - n! の計算
f = 1
factorials = [1] # 0!の分
for m in range(1, n + 1):
f *= m
f %= MOD
factorials.append(f)
# n!^-1 の計算
inv = pow(f, MOD - 2, MOD)
# n!^-1 - 1!^-1 の計算
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= MOD
invs[m - 1] = inv
return factorials, invs
def func(r, c):
return f[r+c] * i[r] % MOD * i[c] % MOD
MOD = 10**9+7
f, i = prepare(2*10**6 + 2, MOD)
r1, c1, r2, c2 = list(map(int,input().split()))
combi = func(r2+1, c2+1) - func(r2+1, c1) - func(r1, c2+1) + func(r1, c1)
print((combi % MOD))
| 35 | 32 | 716 | 689 |
import copy
def prepare(n, MOD):
# 1! - n! の計算
f = 1
factorials = [1] # 0!の分
for m in range(1, n + 1):
f *= m
f %= MOD
factorials.append(f)
# n!^-1 の計算
inv = pow(f, MOD - 2, MOD)
# n!^-1 - 1!^-1 の計算
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= MOD
invs[m - 1] = inv
return factorials, invs
def func(r, c):
return f[r + 1 + c + 1] * i[r + 1] % MOD * i[c + 1] % MOD
MOD = 10**9 + 7
f, i = prepare(2 * 10**6 + 2, MOD)
r1, c1, r2, c2 = list(map(int, input().split()))
combi = func(r2, c2) - func(r2, c1 - 1) - func(r1 - 1, c2) + func(r1 - 1, c1 - 1)
print((combi % MOD))
|
def prepare(n, MOD):
# 1! - n! の計算
f = 1
factorials = [1] # 0!の分
for m in range(1, n + 1):
f *= m
f %= MOD
factorials.append(f)
# n!^-1 の計算
inv = pow(f, MOD - 2, MOD)
# n!^-1 - 1!^-1 の計算
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= MOD
invs[m - 1] = inv
return factorials, invs
def func(r, c):
return f[r + c] * i[r] % MOD * i[c] % MOD
MOD = 10**9 + 7
f, i = prepare(2 * 10**6 + 2, MOD)
r1, c1, r2, c2 = list(map(int, input().split()))
combi = func(r2 + 1, c2 + 1) - func(r2 + 1, c1) - func(r1, c2 + 1) + func(r1, c1)
print((combi % MOD))
| false | 8.571429 |
[
"-import copy",
"-",
"-",
"- return f[r + 1 + c + 1] * i[r + 1] % MOD * i[c + 1] % MOD",
"+ return f[r + c] * i[r] % MOD * i[c] % MOD",
"-combi = func(r2, c2) - func(r2, c1 - 1) - func(r1 - 1, c2) + func(r1 - 1, c1 - 1)",
"+combi = func(r2 + 1, c2 + 1) - func(r2 + 1, c1) - func(r1, c2 + 1) + func(r1, c1)"
] | false | 1.894739 | 1.180089 | 1.60559 |
[
"s298320919",
"s045505126"
] |
u553987207
|
p03043
|
python
|
s927089800
|
s429420641
| 157 | 55 | 15,584 | 12,540 |
Accepted
|
Accepted
| 64.97 |
from math import fsum
from functools import lru_cache
N, K = list(map(int, input().split()))
@lru_cache(maxsize=None)
def f(x):
return f(x * 2) * 0.5 if x < K else 1
ans = fsum(f(i + 1) for i in range(N)) / N
print(ans)
|
import math
N, K = list(map(int, input().split()))
p = [0] * N
for i in range(N):
n = i + 1
x = 1 / N
while n < K:
x *= 0.5
n *= 2
p[i] = x
ans = math.fsum(p)
print(ans)
| 10 | 12 | 228 | 206 |
from math import fsum
from functools import lru_cache
N, K = list(map(int, input().split()))
@lru_cache(maxsize=None)
def f(x):
return f(x * 2) * 0.5 if x < K else 1
ans = fsum(f(i + 1) for i in range(N)) / N
print(ans)
|
import math
N, K = list(map(int, input().split()))
p = [0] * N
for i in range(N):
n = i + 1
x = 1 / N
while n < K:
x *= 0.5
n *= 2
p[i] = x
ans = math.fsum(p)
print(ans)
| false | 16.666667 |
[
"-from math import fsum",
"-from functools import lru_cache",
"+import math",
"-",
"-",
"-@lru_cache(maxsize=None)",
"-def f(x):",
"- return f(x * 2) * 0.5 if x < K else 1",
"-",
"-",
"-ans = fsum(f(i + 1) for i in range(N)) / N",
"+p = [0] * N",
"+for i in range(N):",
"+ n = i + 1",
"+ x = 1 / N",
"+ while n < K:",
"+ x *= 0.5",
"+ n *= 2",
"+ p[i] = x",
"+ans = math.fsum(p)"
] | false | 0.189348 | 0.06238 | 3.035376 |
[
"s927089800",
"s429420641"
] |
u729133443
|
p03325
|
python
|
s082862663
|
s471788027
| 194 | 24 | 42,476 | 3,828 |
Accepted
|
Accepted
| 87.63 |
eval(input());print((sum(bin(int(x))[::-1].index('1')for x in input().split())))
|
_,a=open(0);print((sum(bin(int(x))[::-1].index('1')for x in a.split())))
| 1 | 1 | 72 | 70 |
eval(input())
print((sum(bin(int(x))[::-1].index("1") for x in input().split())))
|
_, a = open(0)
print((sum(bin(int(x))[::-1].index("1") for x in a.split())))
| false | 0 |
[
"-eval(input())",
"-print((sum(bin(int(x))[::-1].index(\"1\") for x in input().split())))",
"+_, a = open(0)",
"+print((sum(bin(int(x))[::-1].index(\"1\") for x in a.split())))"
] | false | 0.037071 | 0.035101 | 1.056143 |
[
"s082862663",
"s471788027"
] |
u987164499
|
p03436
|
python
|
s419274081
|
s291191220
| 37 | 33 | 9,436 | 9,532 |
Accepted
|
Accepted
| 10.81 |
from collections import deque
inf = 10**10
h,w = list(map(int,input().split()))
field = [eval(input()) for _ in range(h)]
length = [[inf for j in range(w)]for i in range(h)]
visited = [[0 for j in range(w)]for i in range(h)]
move = [[-1,0],[1,0],[0,-1],[0,1]]
que = deque([])
que.append([0,0])
length[0][0] = 0
visited[0][0] = 1
white = 0
for i in range(h):
white += field[i].count(".")
while que:
y,x = que.popleft()
for i,j in move:
ny,nx = y+i,x+j
if ny < 0 or ny >= h or nx < 0 or nx >= w:
continue
elif field[ny][nx] == "#":
continue
elif visited[ny][nx] == 1:
continue
visited[ny][nx] = 1
que.append([ny,nx])
length[ny][nx] = length[y][x] + 1
if length[h-1][w-1] == inf:
print((-1))
else:
print((white-(length[h-1][w-1]+1)))
|
from collections import deque
inf = 10**10
h,w = list(map(int,input().split()))
field = [eval(input()) for _ in range(h)]
length = [[inf for j in range(w)]for i in range(h)]
visited = [[0 for j in range(w)]for i in range(h)]
move = [[-1,0],[1,0],[0,-1],[0,1]]
que = deque([])
que.append([0,0])
length[0][0] = 1 # 1スタート
visited[0][0] = 1
white = 0
for i in range(h):
white += field[i].count(".")
while que:
y,x = que.popleft()
for i,j in move:
ny,nx = y+i,x+j
if ny < 0 or ny >= h or nx < 0 or nx >= w:
continue
elif field[ny][nx] == "#":
continue
elif visited[ny][nx] == 1:
continue
visited[ny][nx] = 1
que.append([ny,nx])
length[ny][nx] = length[y][x] + 1
if length[h-1][w-1] == inf:
print((-1))
else:
print((white-length[h-1][w-1])) # 白の総数から最小距離分引く
| 43 | 43 | 888 | 908 |
from collections import deque
inf = 10**10
h, w = list(map(int, input().split()))
field = [eval(input()) for _ in range(h)]
length = [[inf for j in range(w)] for i in range(h)]
visited = [[0 for j in range(w)] for i in range(h)]
move = [[-1, 0], [1, 0], [0, -1], [0, 1]]
que = deque([])
que.append([0, 0])
length[0][0] = 0
visited[0][0] = 1
white = 0
for i in range(h):
white += field[i].count(".")
while que:
y, x = que.popleft()
for i, j in move:
ny, nx = y + i, x + j
if ny < 0 or ny >= h or nx < 0 or nx >= w:
continue
elif field[ny][nx] == "#":
continue
elif visited[ny][nx] == 1:
continue
visited[ny][nx] = 1
que.append([ny, nx])
length[ny][nx] = length[y][x] + 1
if length[h - 1][w - 1] == inf:
print((-1))
else:
print((white - (length[h - 1][w - 1] + 1)))
|
from collections import deque
inf = 10**10
h, w = list(map(int, input().split()))
field = [eval(input()) for _ in range(h)]
length = [[inf for j in range(w)] for i in range(h)]
visited = [[0 for j in range(w)] for i in range(h)]
move = [[-1, 0], [1, 0], [0, -1], [0, 1]]
que = deque([])
que.append([0, 0])
length[0][0] = 1 # 1スタート
visited[0][0] = 1
white = 0
for i in range(h):
white += field[i].count(".")
while que:
y, x = que.popleft()
for i, j in move:
ny, nx = y + i, x + j
if ny < 0 or ny >= h or nx < 0 or nx >= w:
continue
elif field[ny][nx] == "#":
continue
elif visited[ny][nx] == 1:
continue
visited[ny][nx] = 1
que.append([ny, nx])
length[ny][nx] = length[y][x] + 1
if length[h - 1][w - 1] == inf:
print((-1))
else:
print((white - length[h - 1][w - 1])) # 白の総数から最小距離分引く
| false | 0 |
[
"-length[0][0] = 0",
"+length[0][0] = 1 # 1スタート",
"- print((white - (length[h - 1][w - 1] + 1)))",
"+ print((white - length[h - 1][w - 1])) # 白の総数から最小距離分引く"
] | false | 0.034247 | 0.034028 | 1.00643 |
[
"s419274081",
"s291191220"
] |
u674588203
|
p02583
|
python
|
s660717470
|
s879263869
| 81 | 34 | 9,156 | 9,156 |
Accepted
|
Accepted
| 58.02 |
# AtCoder Beginner Contest 175
# B - Making Triangle
N=int(eval(input()))
L=list(map(int,input().split()))
L.sort()
ans=0
for i in range (N):
for j in range (i+1,N):
for k in range (j+1,N):
if L[i]+L[j]>L[k] and L[i]<L[j]<L[k]:
ans+=1
print(ans)
|
# AtCoder Beginner Contest 175
# B - Making Triangle
import bisect
N=int(eval(input()))
L=list(map(int,input().split()))
L.sort()
ans=0
for i in range (N):
for j in range (i+1,N):
if L[i]==L[j]:
pass
else:
ab=L[i]+L[j]
c=bisect.bisect_left(L,ab)
bequalc=bisect.bisect_right(L,L[j])
ans+=c-(bequalc)
print(ans)
| 16 | 23 | 298 | 411 |
# AtCoder Beginner Contest 175
# B - Making Triangle
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N):
for j in range(i + 1, N):
for k in range(j + 1, N):
if L[i] + L[j] > L[k] and L[i] < L[j] < L[k]:
ans += 1
print(ans)
|
# AtCoder Beginner Contest 175
# B - Making Triangle
import bisect
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N):
for j in range(i + 1, N):
if L[i] == L[j]:
pass
else:
ab = L[i] + L[j]
c = bisect.bisect_left(L, ab)
bequalc = bisect.bisect_right(L, L[j])
ans += c - (bequalc)
print(ans)
| false | 30.434783 |
[
"+import bisect",
"+",
"- for k in range(j + 1, N):",
"- if L[i] + L[j] > L[k] and L[i] < L[j] < L[k]:",
"- ans += 1",
"+ if L[i] == L[j]:",
"+ pass",
"+ else:",
"+ ab = L[i] + L[j]",
"+ c = bisect.bisect_left(L, ab)",
"+ bequalc = bisect.bisect_right(L, L[j])",
"+ ans += c - (bequalc)"
] | false | 0.053896 | 0.008152 | 6.611396 |
[
"s660717470",
"s879263869"
] |
u225020286
|
p02791
|
python
|
s293064687
|
s438029666
| 180 | 121 | 26,012 | 24,744 |
Accepted
|
Accepted
| 32.78 |
n = int(eval(input()))
p_n = list(map(int, input().split()))
ans = 1
p_i_1 = [p_n[0]]
m = p_n[0]
for i in range(1, n):
if m > p_n[i]:
ans += 1
m = min(m, p_n[i])
p_i_1.append(p_n[i])
if m == 1:
break
print(ans)
|
N=int(eval(input()))
P=list(map(int,input().split()))
min=10**8
count=0
for i in range(N):
if P[i]==1:
print((count+1))
exit()
elif min>=P[i]:
count+=1
min=P[i]
| 13 | 11 | 248 | 182 |
n = int(eval(input()))
p_n = list(map(int, input().split()))
ans = 1
p_i_1 = [p_n[0]]
m = p_n[0]
for i in range(1, n):
if m > p_n[i]:
ans += 1
m = min(m, p_n[i])
p_i_1.append(p_n[i])
if m == 1:
break
print(ans)
|
N = int(eval(input()))
P = list(map(int, input().split()))
min = 10**8
count = 0
for i in range(N):
if P[i] == 1:
print((count + 1))
exit()
elif min >= P[i]:
count += 1
min = P[i]
| false | 15.384615 |
[
"-n = int(eval(input()))",
"-p_n = list(map(int, input().split()))",
"-ans = 1",
"-p_i_1 = [p_n[0]]",
"-m = p_n[0]",
"-for i in range(1, n):",
"- if m > p_n[i]:",
"- ans += 1",
"- m = min(m, p_n[i])",
"- p_i_1.append(p_n[i])",
"- if m == 1:",
"- break",
"-print(ans)",
"+N = int(eval(input()))",
"+P = list(map(int, input().split()))",
"+min = 10**8",
"+count = 0",
"+for i in range(N):",
"+ if P[i] == 1:",
"+ print((count + 1))",
"+ exit()",
"+ elif min >= P[i]:",
"+ count += 1",
"+ min = P[i]"
] | false | 0.03785 | 0.037125 | 1.019541 |
[
"s293064687",
"s438029666"
] |
u700805562
|
p02727
|
python
|
s434478586
|
s457830405
| 364 | 288 | 112,620 | 22,460 |
Accepted
|
Accepted
| 20.88 |
x, y, a, b, c = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
ans = r
for i in range(x):
ans.append(p[i])
for i in range(y):
ans.append(q[i])
r.sort(reverse=True)
print((sum(ans[:x+y])))
|
x, y, a, b, c = list(map(int, input().split()))
p = sorted(list(map(int, input().split())))
q = sorted(list(map(int, input().split())))
r = list(map(int, input().split()))
for i in range(x): r.append(p[a-i-1])
for i in range(y): r.append(q[b-i-1])
r.sort()
print((sum(r[len(r)-x-y:])))
| 13 | 8 | 334 | 284 |
x, y, a, b, c = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
ans = r
for i in range(x):
ans.append(p[i])
for i in range(y):
ans.append(q[i])
r.sort(reverse=True)
print((sum(ans[: x + y])))
|
x, y, a, b, c = list(map(int, input().split()))
p = sorted(list(map(int, input().split())))
q = sorted(list(map(int, input().split())))
r = list(map(int, input().split()))
for i in range(x):
r.append(p[a - i - 1])
for i in range(y):
r.append(q[b - i - 1])
r.sort()
print((sum(r[len(r) - x - y :])))
| false | 38.461538 |
[
"-p = list(map(int, input().split()))",
"-q = list(map(int, input().split()))",
"+p = sorted(list(map(int, input().split())))",
"+q = sorted(list(map(int, input().split())))",
"-p.sort(reverse=True)",
"-q.sort(reverse=True)",
"-ans = r",
"- ans.append(p[i])",
"+ r.append(p[a - i - 1])",
"- ans.append(q[i])",
"-r.sort(reverse=True)",
"-print((sum(ans[: x + y])))",
"+ r.append(q[b - i - 1])",
"+r.sort()",
"+print((sum(r[len(r) - x - y :])))"
] | false | 0.042433 | 0.088904 | 0.477294 |
[
"s434478586",
"s457830405"
] |
u472065247
|
p04000
|
python
|
s890347924
|
s251818193
| 1,521 | 1,010 | 152,040 | 152,976 |
Accepted
|
Accepted
| 33.6 |
from collections import defaultdict, Counter
H, W, N = list(map(int, input().split()))
D = defaultdict(int)
for _ in range(N):
a, b = list(map(int, input().split()))
for i in range(a - 2, a + 1):
if 1 <= i <= H - 2:
for j in range(b - 2, b + 1):
if 1 <= j <= W - 2:
D[(i, j)] += 1
print(((H - 2) * (W - 2) - len(D)))
c = Counter(list(D.values()))
for i in range(1, 10):
print((c.get(i, 0)))
|
from collections import defaultdict, Counter
def main():
H, W, N, *A = list(map(int,open(0).read().split()))
D = defaultdict(int)
while A:
b, a = A.pop(), A.pop()
for i in [a - 2, a - 1, a]:
if 1 <= i <= H - 2:
for j in [b - 2, b - 1, b]:
if 1 <= j <= W - 2:
D[(i, j)] += 1
print(((H - 2) * (W - 2) - len(D)))
c = Counter(list(D.values()))
for i in range(1, 10):
print((c.get(i, 0)))
if __name__ == '__main__':
main()
| 19 | 22 | 425 | 489 |
from collections import defaultdict, Counter
H, W, N = list(map(int, input().split()))
D = defaultdict(int)
for _ in range(N):
a, b = list(map(int, input().split()))
for i in range(a - 2, a + 1):
if 1 <= i <= H - 2:
for j in range(b - 2, b + 1):
if 1 <= j <= W - 2:
D[(i, j)] += 1
print(((H - 2) * (W - 2) - len(D)))
c = Counter(list(D.values()))
for i in range(1, 10):
print((c.get(i, 0)))
|
from collections import defaultdict, Counter
def main():
H, W, N, *A = list(map(int, open(0).read().split()))
D = defaultdict(int)
while A:
b, a = A.pop(), A.pop()
for i in [a - 2, a - 1, a]:
if 1 <= i <= H - 2:
for j in [b - 2, b - 1, b]:
if 1 <= j <= W - 2:
D[(i, j)] += 1
print(((H - 2) * (W - 2) - len(D)))
c = Counter(list(D.values()))
for i in range(1, 10):
print((c.get(i, 0)))
if __name__ == "__main__":
main()
| false | 13.636364 |
[
"-H, W, N = list(map(int, input().split()))",
"-D = defaultdict(int)",
"-for _ in range(N):",
"- a, b = list(map(int, input().split()))",
"- for i in range(a - 2, a + 1):",
"- if 1 <= i <= H - 2:",
"- for j in range(b - 2, b + 1):",
"- if 1 <= j <= W - 2:",
"- D[(i, j)] += 1",
"-print(((H - 2) * (W - 2) - len(D)))",
"-c = Counter(list(D.values()))",
"-for i in range(1, 10):",
"- print((c.get(i, 0)))",
"+",
"+def main():",
"+ H, W, N, *A = list(map(int, open(0).read().split()))",
"+ D = defaultdict(int)",
"+ while A:",
"+ b, a = A.pop(), A.pop()",
"+ for i in [a - 2, a - 1, a]:",
"+ if 1 <= i <= H - 2:",
"+ for j in [b - 2, b - 1, b]:",
"+ if 1 <= j <= W - 2:",
"+ D[(i, j)] += 1",
"+ print(((H - 2) * (W - 2) - len(D)))",
"+ c = Counter(list(D.values()))",
"+ for i in range(1, 10):",
"+ print((c.get(i, 0)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.038088 | 0.071159 | 0.535254 |
[
"s890347924",
"s251818193"
] |
u882359130
|
p03078
|
python
|
s013330700
|
s556558431
| 151 | 122 | 9,544 | 9,544 |
Accepted
|
Accepted
| 19.21 |
X, Y, Z, K = [int(x) for x in input().split()]
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)
ABC = []
for a in range(len(A)):
for b in range(len(B)):
if (a+1)*(b+1) > K:
break
for c in range(len(C)):
if (a+1)*(c+1) > K:
break
elif (b+1)*(c+1) > K:
break
elif (a+1)*(b+1)*(c+1) > K:
break
ABC.append(A[a] + B[b] + C[c])
ABC = sorted(ABC, reverse=True)
for i in range(K):
print((ABC[i]))
|
X, Y, Z, K = [int(x) for x in input().split()]
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)
ABC = []
for a in range(len(A)):
for b in range(len(B)):
if (a+1)*(b+1) > K:
break
for c in range(len(C)):
if (a+1)*(b+1)*(c+1) > K:
break
ABC.append(A[a] + B[b] + C[c])
ABC = sorted(ABC, reverse=True)
for i in range(K):
print((ABC[i]))
| 23 | 19 | 689 | 573 |
X, Y, Z, K = [int(x) for x in input().split()]
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)
ABC = []
for a in range(len(A)):
for b in range(len(B)):
if (a + 1) * (b + 1) > K:
break
for c in range(len(C)):
if (a + 1) * (c + 1) > K:
break
elif (b + 1) * (c + 1) > K:
break
elif (a + 1) * (b + 1) * (c + 1) > K:
break
ABC.append(A[a] + B[b] + C[c])
ABC = sorted(ABC, reverse=True)
for i in range(K):
print((ABC[i]))
|
X, Y, Z, K = [int(x) for x in input().split()]
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)
ABC = []
for a in range(len(A)):
for b in range(len(B)):
if (a + 1) * (b + 1) > K:
break
for c in range(len(C)):
if (a + 1) * (b + 1) * (c + 1) > K:
break
ABC.append(A[a] + B[b] + C[c])
ABC = sorted(ABC, reverse=True)
for i in range(K):
print((ABC[i]))
| false | 17.391304 |
[
"- if (a + 1) * (c + 1) > K:",
"- break",
"- elif (b + 1) * (c + 1) > K:",
"- break",
"- elif (a + 1) * (b + 1) * (c + 1) > K:",
"+ if (a + 1) * (b + 1) * (c + 1) > K:"
] | false | 0.047808 | 0.045443 | 1.052048 |
[
"s013330700",
"s556558431"
] |
u098968285
|
p03088
|
python
|
s334312963
|
s591192783
| 792 | 386 | 3,188 | 3,188 |
Accepted
|
Accepted
| 51.26 |
import re
def makelist(n, m):
return [[0 for i in range(m)] for j in range(n)]
N = int(eval(input()))
MOD = int(1e9) + 7
acgt = ["A", "C", "G", "T"]
changed = [".*AGC", ".*GAC", ".*ACG", ".*A.GC", ".*AG.C"]
abcl = [ a+b+c for a in acgt for b in acgt for c in acgt]
dp = {}
for now in abcl:
if any([re.match(ch, now) for ch in changed]):
dp[now] = 0
else:
dp[now] = 1
N -= 3
while N > 0:
dpNow = {}
for abc in abcl:
abc = abc[:min(N, 3)]
dpNow[abc] = 0
for key, value in list(dp.items()):
now = key + abc
if not any([re.match(ch, now) for ch in changed]):
dpNow[abc] += value
dpNow[abc] %= MOD
dp = dpNow
N -= 3
ans = 0
for v in list(dp.values()):
ans += v
ans %= MOD
print(ans)
|
import re
def makelist(n, m):
return [[0 for i in range(m)] for j in range(n)]
N = int(eval(input()))
MOD = int(1e9) + 7
acgt = ["A", "C", "G", "T"]
changed = list([re.compile(pat) for pat in [r".*AGC", r".*GAC", r".*ACG", r".*A.GC", r".*AG.C"]])
abcl = [ a+b+c for a in acgt for b in acgt for c in acgt]
dp = {}
for now in abcl:
if any([ch.match(now) for ch in changed]):
dp[now] = 0
else:
dp[now] = 1
N -= 3
while N > 0:
dpNow = {}
for abc in abcl:
abc = abc[:min(N, 3)]
dpNow[abc] = 0
for key, value in list(dp.items()):
now = key + abc
if not any([ch.match(now) for ch in changed]):
dpNow[abc] += value
dpNow[abc] %= MOD
dp = dpNow
N -= 3
ans = 0
for v in list(dp.values()):
ans += v
ans %= MOD
print(ans)
| 41 | 41 | 851 | 888 |
import re
def makelist(n, m):
return [[0 for i in range(m)] for j in range(n)]
N = int(eval(input()))
MOD = int(1e9) + 7
acgt = ["A", "C", "G", "T"]
changed = [".*AGC", ".*GAC", ".*ACG", ".*A.GC", ".*AG.C"]
abcl = [a + b + c for a in acgt for b in acgt for c in acgt]
dp = {}
for now in abcl:
if any([re.match(ch, now) for ch in changed]):
dp[now] = 0
else:
dp[now] = 1
N -= 3
while N > 0:
dpNow = {}
for abc in abcl:
abc = abc[: min(N, 3)]
dpNow[abc] = 0
for key, value in list(dp.items()):
now = key + abc
if not any([re.match(ch, now) for ch in changed]):
dpNow[abc] += value
dpNow[abc] %= MOD
dp = dpNow
N -= 3
ans = 0
for v in list(dp.values()):
ans += v
ans %= MOD
print(ans)
|
import re
def makelist(n, m):
return [[0 for i in range(m)] for j in range(n)]
N = int(eval(input()))
MOD = int(1e9) + 7
acgt = ["A", "C", "G", "T"]
changed = list(
[re.compile(pat) for pat in [r".*AGC", r".*GAC", r".*ACG", r".*A.GC", r".*AG.C"]]
)
abcl = [a + b + c for a in acgt for b in acgt for c in acgt]
dp = {}
for now in abcl:
if any([ch.match(now) for ch in changed]):
dp[now] = 0
else:
dp[now] = 1
N -= 3
while N > 0:
dpNow = {}
for abc in abcl:
abc = abc[: min(N, 3)]
dpNow[abc] = 0
for key, value in list(dp.items()):
now = key + abc
if not any([ch.match(now) for ch in changed]):
dpNow[abc] += value
dpNow[abc] %= MOD
dp = dpNow
N -= 3
ans = 0
for v in list(dp.values()):
ans += v
ans %= MOD
print(ans)
| false | 0 |
[
"-changed = [\".*AGC\", \".*GAC\", \".*ACG\", \".*A.GC\", \".*AG.C\"]",
"+changed = list(",
"+ [re.compile(pat) for pat in [r\".*AGC\", r\".*GAC\", r\".*ACG\", r\".*A.GC\", r\".*AG.C\"]]",
"+)",
"- if any([re.match(ch, now) for ch in changed]):",
"+ if any([ch.match(now) for ch in changed]):",
"- if not any([re.match(ch, now) for ch in changed]):",
"+ if not any([ch.match(now) for ch in changed]):"
] | false | 0.381386 | 0.330487 | 1.154012 |
[
"s334312963",
"s591192783"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.