buggy
stringlengths
1
618k
fixed
stringlengths
16
618k
buggy_submission_id
stringlengths
10
10
fixed_submission_id
stringlengths
10
10
problem_id
stringlengths
6
6
lang
stringclasses
1 value
buggy_verdict
stringclasses
2 values
mod = 10**9 + 7 N = int(input()) A = list(map(int,input().split())) ans = 0 for i in range(61): cnt_0 = 0 cnt_1 = 0 for j in range(N): if (A[j] >> i & 1): cnt_1 += 1 else: cnt_0 += 1 ans += (cnt_1 * cnt_0 * (2**i)) % mod print(ans % mod)
import numpy as np mod = 10**9+7 N = int(input()) A = list(map(int,input().split())) A = np.array(A, dtype = np.int64) tmp = 0 for i in range(61): tmp_1 = np.count_nonzero(A & 1) tmp += ((tmp_1)*(N - tmp_1)*(2**i)) % mod A = A >> 1 print(tmp % mod)
s445781952
s606565937
p02838
python
Time Limit Exceeded
import math import heapq A,B = list(map(int,input().split())) GCD = math.gcd(A,B) CD = [] for i in range(1,int(GCD**(0.5))+1): if GCD % i == 0: CD.append(i) if not i == GCD//i: CD.append(GCD//i) CD.sort() ans = 1 tmp_idx = 0 CD.pop(0) CD_old = CD[:] while (len(CD_old)>0): tmp = CD_ol...
def gcd(a,b): while b != 0: a,b = b,a%b return a A,B = list(map(int,input().split())) GCD = gcd(A,B) CD = [] for i in range(1,int(GCD**(0.5))+1): if GCD % i == 0: CD.append(i) if not i == GCD//i: CD.append(GCD//i) CD.sort() ans = 1 tmp_idx = 0 CD.pop(0) CD_old = CD[:] wh...
s129527107
s854682143
p02900
python
Runtime Error
N = int(input()) S = str(input()) #N = int(input()) #S = str(input()) #N = 13 #S = "strangeorange" lb = 0 ub = N //2 + 1 flag = False while (ub - lb > 1): mid = (lb + ub) // 2 s = [""]*(N - 2*mid + 1) for i in range(N - 2*mid + 1): s[i] = S[i:mid+i] if S[mid+i:i+2*mid] in s: f...
N = int(input()) S = str(input()) #N = 13 #S = "strangeorange" lb = 0 ub = N //2 + 1 flag = False while (ub - lb > 1): mid = (lb + ub) // 2 s = set() for i in range(N - 2*mid + 1): s.add(S[i:mid+i]) if S[mid+i:i+2*mid] in s: flag = True break else: ...
s864876933
s450398711
p02913
python
Time Limit Exceeded
N = 13 S = "strangeorange" #N = int(input()) #S = str(input()) N = int(input()) S = str(input()) #N = 13 #S = "strangeorange" lb = 0 ub = N //2 + 1 flag = False while (ub - lb > 1): mid = (lb + ub) // 2 s = [] for i in range(N - 2*mid + 1): if not (S[i:mid+i] in s): s.append(S[i:mid+...
N = int(input()) S = str(input()) #N = 13 #S = "strangeorange" lb = 0 ub = N //2 + 1 flag = False while (ub - lb > 1): mid = (lb + ub) // 2 s = set() for i in range(N - 2*mid + 1): s.add(S[i:mid+i]) if S[mid+i:i+2*mid] in s: flag = True break else: ...
s413237076
s450398711
p02913
python
Time Limit Exceeded
N = int(input()) S = str(input()) #N = 13 #S = "strangeorange" lb = 0 ub = N //2 + 1 flag = False while (ub - lb > 1): mid = (lb + ub) // 2 s = [] for i in range(N - 2*mid + 1): s.append(S[i:mid+i]) if S[mid+i:i+2*mid] in s: flag = True break else: ...
N = int(input()) S = str(input()) #N = 13 #S = "strangeorange" lb = 0 ub = N //2 + 1 flag = False while (ub - lb > 1): mid = (lb + ub) // 2 s = set() for i in range(N - 2*mid + 1): s.add(S[i:mid+i]) if S[mid+i:i+2*mid] in s: flag = True break else: ...
s795226867
s450398711
p02913
python
Time Limit Exceeded
N = int(input()) S = str(input()) lb = 0 ub = N //2 + 1 while (ub - lb > 1): mid = (lb + ub) // 2 s = [] for i in range(N - 2*mid + 1): s.append(S[mid+i : 2*mid + i]) for i in range(N - 2*mid + 1): if S[i:i+mid] in s: flag = True break else: f...
N = int(input()) S = str(input()) #N = 13 #S = "strangeorange" lb = 0 ub = N //2 + 1 flag = False while (ub - lb > 1): mid = (lb + ub) // 2 s = set() for i in range(N - 2*mid + 1): s.add(S[i:mid+i]) if S[mid+i:i+2*mid] in s: flag = True break else: ...
s034690659
s450398711
p02913
python
Time Limit Exceeded
s = input() S = [0]*len(s) for i in range(len(s)): S[i] = int(s[i]) # 0:-, 1:+ for i in range(2**len(op)): op = [0]*(len(S) - 1) for j in range(len(op)): if (i >> j & 1): op[j] = 1 tmp = S[0] for j in range(len(op)): if op[j] == 0: tmp -= S[j+1] else: ...
s = input() S = [0]*len(s) for i in range(len(s)): S[i] = int(s[i]) # 0:-, 1:+ op = [0]*(len(S) - 1) for i in range(2**len(op)): op = [0]*(len(S) - 1) for j in range(len(op)): if (i >> j & 1): op[j] = 1 tmp = S[0] for j in range(len(op)): if op[j] == 0: tmp -...
s163306827
s895780934
p03545
python
Runtime Error
import sys input = sys.stdin.readline N,Q = map(int, input().split()) ki = [[] for i in range(N+1)] val = [0 for _ in range(N+1)] for _ in range(N-1): a,b = map(int, input().split()) ki[a].append(b) for _ in range(Q): p,x = map(int, input().split()) val[p] += x touched = [] def add_num(p): touched....
N,Q = map(int, input().split()) ki = [[] for i in range(N+1)] val = [0 for _ in range(N+1)] for _ in range(N-1): a,b = map(int, input().split()) ki[a].append(b) ki[b].append(a) for _ in range(Q): p,x = map(int, input().split()) val[p] += x q = [(1,0)] while q: c,p = q.pop() val[c] += val[p] for x in k...
s600519823
s226868436
p02936
python
Runtime Error
def search_add_num(p,x): for k in ki[p]: if k!=p: search_add_num(k,x) else: k_values[p] += x N,Q = map(int, input().split()) ki = [[i] for i in range(N+1)] k_values = [0 for _ in range(N+1)] for _ in range(N-1): a,b = map(int, input().split()) ki[a].append(b) for _ i...
N,Q = map(int, input().split()) ki = [[] for i in range(N+1)] val = [0 for _ in range(N+1)] for _ in range(N-1): a,b = map(int, input().split()) ki[a].append(b) ki[b].append(a) for _ in range(Q): p,x = map(int, input().split()) val[p] += x q = [(1,0)] while q: c,p = q.pop() val[c] += val[p] for x in k...
s805406993
s226868436
p02936
python
Runtime Error
S = input() S = list(S.replace('RL', '11')) lp,rp = 0,0 for i,s in enumerate(S): #l並びが終わったとき if (lp>0)&(!='L'): S[i-lp-1] = int(S[i-lp-1])+lp//2 S[i-lp-2] = int(S[i-lp-2])+lp-lp//2 lp = 0 #最後がL(RLで11になっていない) if (i==len(S)-1)&(s=='L'): lp += 1 S[i] = 0 S[i-...
S = input() S = list(S.replace('RL', '11')) lp,rp = 0,0 for i,s in enumerate(S): #l並びが終わったとき if (lp>0)&(s!='L'): S[i-lp-1] = int(S[i-lp-1])+lp//2 S[i-lp-2] = int(S[i-lp-2])+lp-lp//2 lp = 0 #最後がL(RLで11になっていない) if (i==len(S)-1)&(s=='L'): lp += 1 S[i] = 0 S[i...
s648233068
s051024428
p02954
python
Runtime Error
import sys input = sys.stdin.readline N = int(input()) A = [int(input()) for _ in range(N)] A_max = max(A) for a in A: if a==A_max: print(sorted(A)[-2]) else: print(A_max)
import sys input = sys.stdin.readline N = int(input()) A = [int(input()) for _ in range(N)] A_max = max(A) A_max2 = sorted(A)[-2] for a in A: if a==A_max: print(A_max2) else: print(A_max)
s212651943
s142199188
p02971
python
Time Limit Exceeded
import sys input = sys.stdin.readline n, q = map(int, input().split()) s = input() for _ in range(q): first, last = map(int, input().split()) print(s[first-1:last].count("AC"))
print('ATCG'['TAGC'.find(input())])
s753788272
s305696414
p03085
python
Runtime Error
import sys input = sys.stdin.readline n, q = map(int, input().split()) s = input() for _ in range(q): first, last = map(int, input().split()) print(s[first-1:last].count("AC"))
import sys input = sys.stdin.readline n, q = map(int, input().split()) s = input() ac_list = [0] for i in range(1, n): if s[i-1:i+1] == 'AC': ac_list.append(ac_list[i-1]+1) else: ac_list.append(ac_list[i-1]) for _ in range(q): first, last = map(int, input().split()) print(ac_list[last-1] - ac_list[fi...
s439847862
s057208428
p03087
python
Time Limit Exceeded
import sys input_ = sys.stdin.readline n, q = map(int, input().split()) s = input() for _ in range(q): first, last = map(int, input().split()) print(s[first-1:last].count("AC"))
import sys input = sys.stdin.readline n, q = map(int, input().split()) s = input() ac_list = [0] for i in range(1, n): if s[i-1:i+1] == 'AC': ac_list.append(ac_list[i-1]+1) else: ac_list.append(ac_list[i-1]) for _ in range(q): first, last = map(int, input().split()) print(ac_list[last-1] - ac_list[fi...
s306378196
s057208428
p03087
python
Time Limit Exceeded
n, q = map(int, input().split()) s = input() for _ in range(q): first, last = map(int, input().split()) print(s[first-1:last].count("AC"))
import sys input = sys.stdin.readline n, q = map(int, input().split()) s = input() ac_list = [0] for i in range(1, n): if s[i-1:i+1] == 'AC': ac_list.append(ac_list[i-1]+1) else: ac_list.append(ac_list[i-1]) for _ in range(q): first, last = map(int, input().split()) print(ac_list[last-1] - ac_list[fi...
s976622648
s057208428
p03087
python
Time Limit Exceeded
n, m = map(int, input().split()) ab = [] for _ in range(n): a, b = map(int, input().split()) ab.extend([a for _ in range(b)]) ab.sort() print(sum(ab[:m]))
n,m,*t = map(int, open(0).read().split()) ans = 0 for a, b in sorted(zip(t[::2], t[1::2])): ans += min(b, m)*a m -= b if m <= 0: print(ans) break
s432449659
s087244207
p03103
python
Time Limit Exceeded
a,b = int(input()) if a*b%2 == 0: print("Even") else: print("Odd")
a, b = map(int, input().split()) if a*b%2 == 0: print("Even") else: print("Odd")
s250045918
s686867421
p03455
python
Runtime Error
import collections n, k = map(int, input().split()) a = map(int, input().split()) c = collections.Counter(a) if len(c) <= k: print(0) else: c = c.most_common() print(sum(c[:k-1][0]))
str = list(input()) c = 0 for s in str: c += int(s) print(c)
s968793899
s545611893
p03493
python
Runtime Error
import collections n, k = map(int, input().split()) a = map(int, input().split()) c = collections.Counter(a) if len(c) <= K: print(0) else: c = c.most_common() print(sum(c[:K-1][0]))
from collections import Counter n,k = map(int, input().split()) a = list(map(int, input().split())) ct = sorted(list(Counter(a).values()), reverse=True) print(sum(ct[k:]))
s622660212
s405806813
p03495
python
Runtime Error
N, K = map(int, input().split()) A = list(map(int, input().split())) dic = list(set(A)) if len(dic) <= K: print(0) else: count_list = [] for i in range(len(dic)): count_list.append(A.count(dic[i])) count_list.sort() print(sum(count_list[:len(dic)-K]))
from collections import Counter n,k = map(int, input().split()) a = list(map(int, input().split())) ct = sorted(list(Counter(a).values()), reverse=True) print(sum(ct[k:]))
s699868879
s405806813
p03495
python
Time Limit Exceeded
N = int(input()) temp = N while temp > 0: test += temp %10 temp //= 10 if N % test == 0: print('Yes') else: print('No')
N = int(input()) temp = N test = 0 while temp > 0: test += temp %10 temp //= 10 if N % test == 0: print('Yes') else: print('No')
s455202254
s476445295
p03502
python
Runtime Error
N = int(input()) temp = N while temp > 0: test += temp %10 temp //= 10 if N % test == 0: print('Yes') else: print('No')
N = int(input()) temp = N test = 0 while temp > 0: test += temp %10 temp //= 10 if N % test == 0: print('Yes') else: print('No')
s818269426
s476445295
p03502
python
Runtime Error
n, c, k = map(int, input().split()) t = [] for i in range(n): t.append(int(input())) t.sort() result = 1 count = 0 for i in range(n): if (t[count] - t[0]) > k or c == count: result += 1 t = t[count:] count = 1 else: count += 1 print(result)
n, c, k = map(int, input().split()) t = [int(input()) for i in range(n)] t.sort() result = 1 count = 0 f = 0 for i in range(n): if (t[i] - t[f]) > k or c == count: result += 1 count = 1 f = i else: count += 1 print(result)
s031773658
s084762238
p03785
python
Time Limit Exceeded
n, c, k = map(int, input().split()) t = [] for i in range(n): t.append(int(input())) t.sort() result = 1 j = 0 for i in range(n): if (t[j] - t[0]) > k or c == count: result += 1 t = t[j:] j = 1 else: j += 1 print(result)
n, c, k = map(int, input().split()) t = [int(input()) for i in range(n)] t.sort() result = 1 count = 0 f = 0 for i in range(n): if (t[i] - t[f]) > k or c == count: result += 1 count = 1 f = i else: count += 1 print(result)
s705304685
s084762238
p03785
python
Runtime Error
import sys sys.stdin.readline() count = 0 a_list = list(map(int, sys.stdin.readline().split())) for a in x_list: count += a%2 print("YES") if count%2==0 else print("NO")
import sys input() count = 0 a_list = list(map(int, input().split())) for a in a_list: count += a%2 print("YES") if count%2==0 else print("NO")
s013588731
s152566113
p03807
python
Runtime Error
import sys input_ = sys.stdin.readline input_() x_list = list(map(int, input_().split())) for x in x_list: if x%2==0: a += 1 if a%2==0: print("YES") else: print("NO")
import sys input() count = 0 a_list = list(map(int, input().split())) for a in a_list: count += a%2 print("YES") if count%2==0 else print("NO")
s165841384
s152566113
p03807
python
Runtime Error
s = input()[::-1] while True: if s[:5] == "maerd": s = s[5:] elif s[:7] == "remaerd": s - s[7:] elif s[:5] == "esare": s = s[5:] elif s[:6] == "resare": s - s[6:] else: break if s == "": print("YES") else: print("NO")
#C - 白昼夢 / Daydream s = input()[::-1] while True: if s[:5] == "maerd": s = s[5:] elif s[:7] == "remaerd": s = s[7:] elif s[:5] == "esare": s = s[5:] elif s[:6] == "resare": s = s[6:] else: break if s == "": print("YES") else: print("NO")
s679432199
s487785130
p03854
python
Runtime Error
import re s = input() def trans_word(text): replacements = {'01': '', '10': ''} return re.sub('({})'.format('|'.join(map(re.escape, replacements.keys()))), lambda m: replacements[m.group()], text) ans = 0 flag = True while flag: s_tmp = s s = trans_word(s) ans += (len(s_tmp) - len(s)) flag =...
import re s = input() c0, c1 = 0, 0 for i in s: if i=='0': c0 += 1 else: c1 += 1 print(min(c0, c1)*2) """TLE def trans_word(text): replacements = {'01': '', '10': ''} return re.sub('({})'.format('|'.join(map(re.escape, replacements.keys()))), lambda m: replacements[m.group()], text) ...
s608401507
s012026869
p03107
python
Time Limit Exceeded
s = input() ans = 0 flag = True while flag: s_tmp = s s = s.replace('01', '') s = s.replace('10', '') ans += (len(s_tmp) - len(s)) flag = len(s_tmp) - len(s) print(ans)
import re s = input() c0, c1 = 0, 0 for i in s: if i=='0': c0 += 1 else: c1 += 1 print(min(c0, c1)*2) """TLE def trans_word(text): replacements = {'01': '', '10': ''} return re.sub('({})'.format('|'.join(map(re.escape, replacements.keys()))), lambda m: replacements[m.group()], text) ...
s517430529
s012026869
p03107
python
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int h, w; cin >> h >> w; vector<string> a(h); for (int i=0; i<h; i++) { cin >> a.at(i); } vector<bool> row(h, false); vector<bool> col(w, false); for (int i=0; i<h; i++) { for (int j=0; j<w; j++) { if...
h, w = map(int, input().split()) a = [''] * h for i in range(h): a[i] = input() row = [False] * h col = [False] * w for i in range(h): for j in range(w): if a[i][j] == '#': row[i] = True col[j] = True for i in range(h): if row[i]: for j in range(w): if col[j]: print(a[i][j], end = '') print()
s251067004
s786599579
p03273
python
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; if (n>=2 && m>=2) { cout << n*m - (n-2)*2 - (m-2)*2 - 4 << endl; } else if (n==1 && m==1) { cout << 1 << endl; } else if (n==1 && m>=2) { cout << m-2 << endl; } else { cout << n-2 << end...
n, m = map(int, input().split()) if n>=2 and m>=2: print(n*m - (n-2)*2 - (m-2)*2 - 4) elif n==1 and m==1: print(1) elif n==1 and m>=2: print(m-2) else: print(n-2)
s357453030
s273272690
p03417
python
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (n>=2 && m>=2) { cout << n*m - (n-2)*2 - (m-2)*2 - 4 << endl; } else if (n==1 && m==1) { cout << 1 << endl; } else if (n==1 && m>=2) { cout << m-2 << endl; } else { cout << n-2 << endl; }...
n, m = map(int, input().split()) if n>=2 and m>=2: print(n*m - (n-2)*2 - (m-2)*2 - 4) elif n==1 and m==1: print(1) elif n==1 and m>=2: print(m-2) else: print(n-2)
s722933125
s273272690
p03417
python
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (n>=2 && m>=2) { cout << n*m - (n-2)*2 - (m-2)*2 - 4 << endl; } else if (n==1 && m==1) { cout << 1 << endl; } else if (n==1 && m>=2) { cout << m-2 << endl; } else { cout << n-2 << endl; }...
n, m = map(int, input().split()) if n>=2 and m>=2: print(n*m - (n-2)*2 - (m-2)*2 - 4) elif n==1 and m==1: print(1) elif n==1 and m>=2: print(m-2) else: print(n-2)
s100626497
s273272690
p03417
python
Runtime Error
input() S = input() K = int(input()) c = S[K] print("".join([v if v == c else "*" for v in S]))
input() S = input() K = int(input()) c = S[K-1] print("".join([v if v == c else "*" for v in S]))
s178532684
s858942770
p03068
python
Runtime Error
A, B, M = map(int, input().split(' ')) a = list(map(int, input().split(' '))) b = list(map(int, input().split(' '))) discountDic = {} for i in range(M): x, y, c = map(int, input().split(' ')) key = (x-1)*B+(y-1) if key not in discountDic or discountDic[key] < c: discountDic[key] = c priceList = [] f...
A, B, M = map(int, input().split(' ')) a = list(map(int, input().split(' '))) b = list(map(int, input().split(' '))) discountDic = {} for i in range(M): x, y, c = map(int, input().split(' ')) key = (x-1)*B+(y-1) if key not in discountDic or discountDic[key] > a[x-1] + b[y-1] - c: discountDic[key] = ...
s117381144
s001036195
p02748
python
Time Limit Exceeded
S = input() Q = int(input()) reverseFlag = False for i in range(Q): tmp = input() if tmp[0] == '1': reverseFlag = not reverseFlag else: tmpt, tmpf, tmpc = tmp.split(' ') if tmpf == '1' and reverseFlag == False or tmpf == '2' and reverseFlag == True: S = ''.join([tmpc, S])...
S = input() Q = int(input()) reverseFlag = False forwardList = [] backwardList = [] for i in range(Q): tmp = input() if tmp[0] == '1': reverseFlag = not reverseFlag else: tmpt, tmpf, tmpc = tmp.split(' ') if tmpf == '1' and reverseFlag == False or tmpf == '2' and reverseFlag == True:...
s771617305
s062050736
p02756
python
Time Limit Exceeded
S = input() Q = int(input()) reverseFlag = False for i in range(Q): tmp = input() if tmp[0] == '1': reverseFlag = not reverseFlag else: tmpt, tmpf, tmpc = tmp.split(' ') if tmpf == '1' and reverseFlag == False or tmpf == '2' and reverseFlag == True: S = tmpc + S e...
S = input() Q = int(input()) reverseFlag = False forwardList = [] backwardList = [] for i in range(Q): tmp = input() if tmp[0] == '1': reverseFlag = not reverseFlag else: tmpt, tmpf, tmpc = tmp.split(' ') if tmpf == '1' and reverseFlag == False or tmpf == '2' and reverseFlag == True:...
s303678272
s062050736
p02756
python
Time Limit Exceeded
S = input() Q = int(input()) for i in range(Q): tmp = input() if tmp[0] == '1': S = S[::-1] else: tmpt, tmpf, tmpc = tmp.split(' ') if tmpf == '1': S = tmpc + S else: S = S + tmpc print(S)
S = input() Q = int(input()) reverseFlag = False forwardList = [] backwardList = [] for i in range(Q): tmp = input() if tmp[0] == '1': reverseFlag = not reverseFlag else: tmpt, tmpf, tmpc = tmp.split(' ') if tmpf == '1' and reverseFlag == False or tmpf == '2' and reverseFlag == True:...
s954801954
s062050736
p02756
python
Time Limit Exceeded
N = int(input()) A = list(map(int, input().split(' '))) answer = 'YES' max_val = max(A) + 1 check = [False] * max_val for a in A: if check[a] == True: answer = 'NO' break else: check[a] = True print(answer)
N = int(input()) A = list(map(int, input().split(' '))) answer = 'YES' check_dic = {} for a in A: if a in check_dic: answer = 'NO' break else: check_dic[a] = True print(answer)
s459128568
s605799377
p02779
python
Runtime Error
N = int(input()) A = list(map(int, input().split(' '))) answer = 'YES' check = [False] * max(A) for a in A: if check[a-1] == True: answer = 'NO' break else: check[a-1] = True print(answer)
N = int(input()) A = list(map(int, input().split(' '))) answer = 'YES' check_dic = {} for a in A: if a in check_dic: answer = 'NO' break else: check_dic[a] = True print(answer)
s424709662
s605799377
p02779
python
Runtime Error
N, K = map(int, input().split(' ')) p = list(map(int, input().split())) psum = [] for i in range(N-K+1): psum.append(sum(p[i:i+K])) print((max(psum)+K)/2)
N, K = map(int, input().split(' ')) p = list(map(int, input().split())) psum = [] pini = sum(p[:K]) psum.append(pini) for i in range(1, N-K+1): pini = pini - p[i-1] + p[i+K-1] psum.append(pini) print((max(psum)+K)/2)
s049709079
s614187934
p02780
python
Time Limit Exceeded
N, K = map(int, input().split(' ')) p = list(map(int, input().split())) exp_val = [n/2+0.5 for n in p] ksum = [] for i in range(N-K+1): ksum.append(sum(exp_val[i:i+K])) print(max(ksum))
N, K = map(int, input().split(' ')) p = list(map(int, input().split())) psum = [] pini = sum(p[:K]) psum.append(pini) for i in range(1, N-K+1): pini = pini - p[i-1] + p[i+K-1] psum.append(pini) print((max(psum)+K)/2)
s750617884
s614187934
p02780
python
Time Limit Exceeded
N = int(input()) P = list(map(int, input().split(' '))) count = 0 for i, value in enumerate(P): if min(P[:i+1]) == value: count += 1 print(count)
N = int(input()) P = list(map(int, input().split(' '))) count = 1 min_value = P[0] for i in range(1, N): if P[i] <= min_value: min_value = P[i] count += 1 print(count)
s093273145
s838206201
p02791
python
Time Limit Exceeded
N=input() A=list(map(int, input().split())) B=list(map(int, input().split())) if sum(A) < sum(B) : print(-1) else : diff=[A[i] - B[i] for i in range(len(A))] pos=sorted([x for x in diff if x > 0]) neg=[x for x in diff if x < 0] nes=sum(neg) if nes >= 0 : print(0) else: item...
print("YES" if "".join(sorted(input().split())) == "1479" else "NO")
s499962763
s688245733
p03149
python
Runtime Error
[N, K] = map(int, input().split()) A = list(map(int, input().split())) count = 0 while len(A) != 1: A = A[K:] + [0] count = count + 1 print(count)
[N, K] = map(int, input().split()) A = list(map(int, input().split())) print(-(-(N - 1) // (K - 1)))
s909856925
s334027871
p03317
python
Time Limit Exceeded
A, B, C, D, E, F = map(int, input().split()) W = sorted(list({a*100*A + b*100*B for a in range(F // 100 // A + 1) for b in range(F // 100 // B + 1) if a*100*A + b*100*B <= F})) S = [max([c*C + d*D for c in range(int((E*w / 100) / C) + 1) for d in range(int((E*w / 100) / D) + 1) if ((c*C + d*D)*100 <= E*w) and (c*C + d...
A, B, C, D, E, F = map(int, input().split()) W = sorted(list({a*100*A + b*100*B for a in range(F // 100 // A + 1) for b in range(F // 100 // B + 1) if a*100*A + b*100*B <= F})) S = [max([c*C + d*D for c in range(int((E*w / 100) / C) + 1) for d in range(int((E*w / 100) / D) + 1) if ((c*C + d*D)*100 <= E*w) and (c*C + d...
s446628531
s361556963
p03599
python
Runtime Error
A, B, C, D, E, F = map(int, input().split()) W = sorted(list({a*100*A + b*100*B for a in range(F // 100 // A + 1) for b in range(F // 100 // B + 1) if a*100*A + b*100*B <= F})) S = [max([c*C + d*D for c in range((E*w / 100) / C + 1) for d in range((E*w / 100) / D + 1) if ((c*C + d*D)*100 <= E*w) and (c*C + d*D + w <= ...
A, B, C, D, E, F = map(int, input().split()) W = sorted(list({a*100*A + b*100*B for a in range(F // 100 // A + 1) for b in range(F // 100 // B + 1) if a*100*A + b*100*B <= F})) S = [max([c*C + d*D for c in range(int((E*w / 100) / C) + 1) for d in range(int((E*w / 100) / D) + 1) if ((c*C + d*D)*100 <= E*w) and (c*C + d...
s847598203
s361556963
p03599
python
Runtime Error
def gcd(a, b): while a != b: if a > b : a -= b else: b -= a return a N, X=map(int, input().split()) print(3*(N - gcd(N, X)))
def gcd(a, b): while a != b: if a == 0: return b elif b == 0: return a if a > b : a %= b else: b %= a return a N, X=map(int, input().split()) ...
s007882360
s908752596
p04048
python
Time Limit Exceeded
from math import gcd N, X=map(int, input().split()) print(3*(N - gcd(N, X)))
def gcd(a, b): while a != b: if a == 0: return b elif b == 0: return a if a > b : a %= b else: b %= a return a N, X=map(int, input().split()) ...
s580800768
s908752596
p04048
python
Runtime Error
N, M = [int(i) for i in input().split(" ")] conds = [] for _ in range(M): conds.append([int(i) for i in input().split(" ")]) exists = True A = [None for _ in range(N)] for s, c in conds: idx = s-1 if A[idx] != None and A[idx] != c: exists = False break A[idx] = c def check(): if n...
N, M = [int(i) for i in input().split(" ")] conds = [] for _ in range(M): conds.append([int(i) for i in input().split(" ")]) exists = True A = [None for _ in range(N)] for s, c in conds: idx = s-1 if A[idx] != None and A[idx] != c: exists = False break A[idx] = c def check(): if n...
s644692493
s639428756
p02761
python
Runtime Error
N = int(input()) S = [input() for _ in range(N)] count = dict() for x in S: count[x] = count.get(x, 0) + 1 sorted_kv = list(sorted(count.items(), key=lambda x: (-x[1], x[0]))) max_val = sorted_kv[0][1] res = [] for k, v in sorted_kv: if v == max_val: print(k) else: break
N = int(input()) count = dict() for _ in range(N): x = input() count[x] = count.get(x, 0) + 1 max_val = -float("infinity") for k, v in sorted(count.items(), key=lambda x: (-x[1], x[0])): max_val = max(v, max_val) if v == max_val: print(k) else: break
s937830184
s245849519
p02773
python
Time Limit Exceeded
H, W = [int(x) for x in input().split(" ")] class Node: def __init__(self, text, pos): self.text = text self.pos = pos self.next_nodes = [] def add_next(self, node): self.next_nodes.append(node) nodes = dict() for i in range(H): for j, text in enumerate(input()): ...
class Node: def __init__(self, text, pos): self.text = text self.pos = pos self.next_nodes = [] def add_next(self, node): self.next_nodes.append(node) def all_pats(): pat = [] for i in range(H): for j in range(W): pat.append((i, j)) return pat ...
s647564856
s112628194
p02803
python
Time Limit Exceeded
H, W = [int(x) for x in input().split(" ")] class Node: def __init__(self, text, pos): self.text = text self.pos = pos self.next_nodes = [] def add_next(self, node): self.next_nodes.append(node) nodes = dict() for i in range(H): for j, text in enumerate(input()): ...
class Node: def __init__(self, text, pos): self.text = text self.pos = pos self.next_nodes = [] def add_next(self, node): self.next_nodes.append(node) def all_pats(): pat = [] for i in range(H): for j in range(W): pat.append((i, j)) return pat ...
s949623873
s112628194
p02803
python
Time Limit Exceeded
H, W = [int(x) for x in input().split(" ")] class Node: def __init__(self, text, pos): self.text = text self.pos = pos self.next_nodes = [] def add_next(self, node): self.next_nodes.append(node) nodes = dict() for i in range(H): for j, text in enumerate(input()): ...
class Node: def __init__(self, text, pos): self.text = text self.pos = pos self.next_nodes = [] def add_next(self, node): self.next_nodes.append(node) def all_pats(): pat = [] for i in range(H): for j in range(W): pat.append((i, j)) return pat ...
s597101743
s112628194
p02803
python
Time Limit Exceeded
import math X, Y = [int(x) for x in input().split(" ")] N = (X + Y) / 3 i = (2 * X - Y) / 3 if N < 0 or N != int(N): print(0) if i < 0 or i != int(i): print(0) N = int(N) i = int(i) ans = math.factorial(N) / (math.factorial(i) * math.factorial(N-i)) print(ans)
MOD = 10**9+7 fact = [1, 1] for i in range(2, 10**6+1): fact.append((fact[i-1] * i) % MOD) def comb(n, k): return (fact[n] * pow(fact[k], MOD-2, MOD) * pow(fact[n-k], MOD-2, MOD)) % MOD X, Y = [int(x) for x in input().split(" ")] n = (2 * X - Y) / 3 m = (2 * Y - X) / 3 if n < 0 or n != int(n): print(0...
s189207110
s616682429
p02862
python
Runtime Error
def power(a, b, P): if b == 0: return 1 elif b == 1: return a % P elif b % 2 == 0: return (power(a, b//2, P) ** 2) % P else: return (power(a, b//2, P) ** 2 * a) % P N, P = (int(i) for i in input().split()) S = input() l = [0]*N ls = [0]*(N+1) if P != 2 and P != 5: d = [0]*P d[0] = 1 b = 0 ...
def power(a, b, P): if b == 0: return 1 elif b == 1: return a % P elif b % 2 == 0: return (power(a, b//2, P) ** 2) % P else: return (power(a, b//2, P) ** 2 * a) % P N, P = (int(i) for i in input().split()) S = input() l = [0]*N ls = [0]*(N+1) if P != 2 and P != 5: po = [1]*N for i in range(N-1): ...
s303223878
s663323599
p02757
python
Time Limit Exceeded
def power(a, b, P): if b == 0: return 1 elif b == 1: return a % P elif b % 2 == 0: return (power(a, b//2, P) ** 2) % P else: return (power(a, b//2, P) ** 2 * a) % P N, P = (int(i) for i in input().split()) S = input() l = [0]*N ls = [0]*(N+1) if P != 2 and P != 5: for i in range(N): a = int(S...
def power(a, b, P): if b == 0: return 1 elif b == 1: return a % P elif b % 2 == 0: return (power(a, b//2, P) ** 2) % P else: return (power(a, b//2, P) ** 2 * a) % P N, P = (int(i) for i in input().split()) S = input() l = [0]*N ls = [0]*(N+1) if P != 2 and P != 5: po = [1]*N for i in range(N-1): ...
s667591455
s663323599
p02757
python
Time Limit Exceeded
import sys input = sys.stdin.readline class SegmentTree(object): def __init__(self, init_array, seg_func=min, seg_func_null=10 ** 9 + 7): self.seg_func = seg_func self.seg_func_null = seg_func_null self.n = 1 while self.n < len(init_array): self.n *= 2 self.d...
import sys input = sys.stdin.readline class SegmentTree(object): def __init__(self, init_array, seg_func=min, seg_func_null=10 ** 9 + 7): self.seg_func = seg_func self.seg_func_null = seg_func_null self.n = 1 while self.n < len(init_array): self.n *= 2 self.d...
s063402647
s110246502
p02758
python
Time Limit Exceeded
class SegmentTree(object): def __init__(self, init_array, seg_func=min, seg_func_null=10 ** 9 + 7): self.seg_func = seg_func self.seg_func_null = seg_func_null self.n = 1 while self.n < len(init_array): self.n *= 2 self.dat = [0] * (2 * self.n - 1) for...
import sys input = sys.stdin.readline class SegmentTree(object): def __init__(self, init_array, seg_func=min, seg_func_null=10 ** 9 + 7): self.seg_func = seg_func self.seg_func_null = seg_func_null self.n = 1 while self.n < len(init_array): self.n *= 2 self.d...
s156229279
s110246502
p02758
python
Time Limit Exceeded
def init_max(init_max_val): #set_val for i in range(N): seg_max[i+num_max-1]=init_max_val[i] #built for i in range(num_max-2,-1,-1) : seg_max[i]=max(seg_max[2*i+1],seg_max[2*i+2]) def update_max(k,x): k += num_max-1 seg_max[k] = x while k: k = (k-1)//2 ...
import sys input = sys.stdin.readline class SegmentTree(object): def __init__(self, init_array, seg_func=min, seg_func_null=10 ** 9 + 7): self.seg_func = seg_func self.seg_func_null = seg_func_null self.n = 1 while self.n < len(init_array): self.n *= 2 self.d...
s230542423
s110246502
p02758
python
Time Limit Exceeded
def kouyaku(a,b): aa = max(a,b) bb = min(a,b) if bb == 0: return aa else: return kouyaku(bb,aa%bb) def power(a, b): if b == 0: return 1 elif b == 1: return a % 1000000007 elif b % 2 == 0: return (power(a, b//2) ** 2) % 1000000007 else: return (power(a, b//2) ** 2 * a) % 1000...
def kouyaku(a,b): aa = max(a,b) bb = min(a,b) if bb == 0: return aa else: return kouyaku(bb,aa%bb) def power(a, b): if b == 0: return 1 elif b == 1: return a % 1000000007 elif b % 2 == 0: return (power(a, b//2) ** 2) % 1000000007 else: return (power(a, b//2) ** 2 * a) % 1000...
s768269600
s728179443
p02793
python
Time Limit Exceeded
def kouyaku(a,b): aa = max(a,b) bb = min(a,b) if bb == 0: return aa else: return kouyaku(bb,aa%bb) def power(a, b): if b == 0: return 1 elif b == 1: return a % 1000000007 elif b % 2 == 0: return (power(a, b//2) ** 2) % 1000000007 else: return (power(a, b//2) ** 2 * a) % 1000...
def kouyaku(a,b): aa = max(a,b) bb = min(a,b) if bb == 0: return aa else: return kouyaku(bb,aa%bb) def power(a, b): if b == 0: return 1 elif b == 1: return a % 1000000007 elif b % 2 == 0: return (power(a, b//2) ** 2) % 1000000007 else: return (power(a, b//2) ** 2 * a) % 1000...
s473317961
s728179443
p02793
python
Runtime Error
def kouyaku(a,b): aa = max(a,b) bb = min(a,b) if bb == 0: return aa else: return kouyaku(bb,aa%bb) def power(a, b): if b == 0: return 1 elif b == 1: return a % 1000000007 elif b % 2 == 0: return (power(a, b//2) ** 2) % 1000000007 else: return (power(a, b//2) ** 2 * a) % 1000...
def kouyaku(a,b): aa = max(a,b) bb = min(a,b) if bb == 0: return aa else: return kouyaku(bb,aa%bb) def power(a, b): if b == 0: return 1 elif b == 1: return a % 1000000007 elif b % 2 == 0: return (power(a, b//2) ** 2) % 1000000007 else: return (power(a, b//2) ** 2 * a) % 1000...
s855286290
s728179443
p02793
python
Runtime Error
def kouyaku(a,b): aa = max(a,b) bb = min(a,b) if bb == 0: return aa else: return kouyaku(bb,aa%bb) def power(a, b): if b == 0: return 1 elif b == 1: return a % 1000000007 elif b % 2 == 0: return (power(a, b//2) ** 2) % 1000000007 else: return (power(a, b//2) ** 2 * a) % 1000...
def kouyaku(a,b): aa = max(a,b) bb = min(a,b) if bb == 0: return aa else: return kouyaku(bb,aa%bb) def power(a, b): if b == 0: return 1 elif b == 1: return a % 1000000007 elif b % 2 == 0: return (power(a, b//2) ** 2) % 1000000007 else: return (power(a, b//2) ** 2 * a) % 1000...
s188767383
s728179443
p02793
python
Time Limit Exceeded
def kouyaku(a,b): aa = max(a,b) bb = min(a,b) if bb == 0: return aa else: return kouyaku(bb,aa%bb) def power(a, b): if b == 0: return 1 elif b == 1: return a % 1000000007 elif b % 2 == 0: return (power(a, b//2) ** 2) % 1000000007 else: return (power(a, b//2) ** 2 * a) % 1000...
def kouyaku(a,b): aa = max(a,b) bb = min(a,b) if bb == 0: return aa else: return kouyaku(bb,aa%bb) def power(a, b): if b == 0: return 1 elif b == 1: return a % 1000000007 elif b % 2 == 0: return (power(a, b//2) ** 2) % 1000000007 else: return (power(a, b//2) ** 2 * a) % 1000...
s875353571
s728179443
p02793
python
Time Limit Exceeded
N, M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] A.sort(reverse=True) As = [0]*(N+1) for i in range(N): As[i+1] = As[i] + A[i] A.reverse() import bisect def flag(x): ans = 0 for i in range(N): a = x - A[i] res = bisect.bisect_left(A, a) ans += (N-res) ...
N, M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] A.sort(reverse=True) As = [0]*(N+1) for i in range(N): As[i+1] = As[i] + A[i] A.reverse() import bisect def flag(x): ans = 0 for i in range(N): a = x - A[i] res = bisect.bisect_left(A, a) ans += (N-res) ...
s577535836
s067421416
p02821
python
Runtime Error
N, M, L = (int(i) for i in input().split()) import heapq def Dijkstra(graph, start): N = len(graph) d = {} prev = {} for i in range(N): prev[i] = None if i == start: d[i] = 0 else: d[i] = float('inf') Q = [] heapq.heappush(Q, (0, start)) while...
N, M, L = (int(i) for i in input().split()) import numpy as np from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix graph = [[0]*N for i in range(N)] for i in range(M): a, b, c = (int(i) for i in input().split()) graph[a-1][b-1] = c graph[b-1][a-1] = c graph = csr_matrix(gr...
s936070879
s400576954
p02889
python
Time Limit Exceeded
n = int(input()) g = [[-1, -1] for i in range(n*n)] z = [0] * (n*n) a = [] for _ in range(n): a.append([int(i) for i in input().split()]) for i in range(n): for j in range(n-2): p, q = (i, a[i][j]-1) r, s = (i, a[i][j+1]-1) r, s = (min(r, s), max(r ,s)) if p < q: g[...
n = int(input()) g = [[-1, -1] for i in range(n*n)] z = [0] * (n*n) a = [] for _ in range(n): a.append([int(i) for i in input().split()]) for i in range(n): for j in range(n-2): p, q = (i, a[i][j]-1) r, s = (i, a[i][j+1]-1) r, s = (min(r, s), max(r ,s)) if p < q: g[...
s717128556
s730056901
p02925
python
Time Limit Exceeded
def BF(N, edges, start): D = {} P = {} for i in range(N): P[i] = None if i == start: D[i] = 0 else: D[i] = float("inf") for i in range(N-1): for edge in edges: a, b, c = edge if D[b] > D[a] + c: D[b] = D[a] ...
def BF(v, start, edges): INF = 10**18 nega = False d = [INF] * v d[start] = 0 for _ in range(v): f = False for a, b, c in edges: cost = d[a] + c if cost < d[b]: d[b] = cost f = True if not f: break else: ...
s483644992
s972063731
p02949
python
Time Limit Exceeded
N, K = (int(i) for i in input().split()) A = [int(i) for i in input().split()] L = [0]*N P = [-1]*(2*10**5+1) for i in range(2*N): j = i%N a = A[j] if P[a] == -1: P[a] = i else: L[P[a]] = j P[a] = j s = 0 start = 0 v = [True]*N h = [(0, 0)] h_app = h.append while v[start]: v[...
import sys input = sys.stdin.readline N, K = (int(i) for i in input().split()) A = [int(i) for i in input().split()] L = [0]*N P = [-1]*(2*10**5+1) for i in range(2*N): j = i%N a = A[j] if P[a] == -1: P[a] = i else: L[P[a]] = j P[a] = j s = 0 start = 0 v = [True]*N h = [(0, 0)] ...
s052744099
s250064256
p02964
python
Runtime Error
import sys input = sys.stdin.readline N, Q = (int(i) for i in input().split()) L = [0] * 2 * N P = {} for i in range(N): S, T, X = (int(i) for i in input().split()) L[2 * i] = (S-X, X, 1) L[2 * i + 1] = (T-X, X, 0) L.sort(reverse=True) Xs = set([]) for i in range(Q): D = int(input()) ans = 0 ...
import sys input = sys.stdin.readline import heapq N, Q = (int(i) for i in input().split()) L = [0] * (2 * N + Q) for i in range(N): S, T, X = (int(i) for i in input().split()) L[2 * i] = (S-X, 1, X) L[2 * i + 1] = (T-X, -1, X) for i in range(Q): D = int(input()) L[2 * N + i] = (D, 2, 0) L.sort() ...
s627995727
s964390268
p03033
python
Time Limit Exceeded
import heapq N, Q = (int(i) for i in input().split()) L = [0] * (2 * N + Q) for i in range(N): S, T, X = (int(i) for i in input().split()) L[2 * i] = (S-X, X, 1) L[2 * i + 1] = (T-X, X, -1) for i in range(Q): D = int(input()) L[2 * N + i] = (D, 10**9+1, 0) L.sort() Xs = set([]) XH = [] heapq.heapif...
import sys input = sys.stdin.readline import heapq N, Q = (int(i) for i in input().split()) L = [0] * (2 * N + Q) for i in range(N): S, T, X = (int(i) for i in input().split()) L[2 * i] = (S-X, 1, X) L[2 * i + 1] = (T-X, -1, X) for i in range(Q): D = int(input()) L[2 * N + i] = (D, 2, 0) L.sort() ...
s112774694
s964390268
p03033
python
Time Limit Exceeded
import heapq N, Q = (int(i) for i in input().split()) L = [0] * 2 * N for i in range(N): S, T, X = (int(i) for i in input().split()) L[2 * i] = (S-X, X, 1) L[2 * i + 1] = (T-X, X, 0) L.sort(reverse=True) Xs = set([]) XH = [] heapq.heapify(XH) for i in range(Q): D = int(input()) ans = 0 while T...
import sys input = sys.stdin.readline import heapq N, Q = (int(i) for i in input().split()) L = [0] * (2 * N + Q) for i in range(N): S, T, X = (int(i) for i in input().split()) L[2 * i] = (S-X, 1, X) L[2 * i + 1] = (T-X, -1, X) for i in range(Q): D = int(input()) L[2 * N + i] = (D, 2, 0) L.sort() ...
s253214222
s964390268
p03033
python
Time Limit Exceeded
import heapq N, Q = (int(i) for i in input().split()) L = [0] * 2 * N for i in range(N): S, T, X = (int(i) for i in input().split()) L[2 * i] = (S-X, X, 1) L[2 * i + 1] = (T-X, X, 0) L.sort(reverse=True) Xs = set([]) XH = [] heapq.heapify(XH) for i in range(Q): D = int(input()) ans = 0 while T...
import sys input = sys.stdin.readline import heapq N, Q = (int(i) for i in input().split()) L = [0] * (2 * N + Q) for i in range(N): S, T, X = (int(i) for i in input().split()) L[2 * i] = (S-X, 1, X) L[2 * i + 1] = (T-X, -1, X) for i in range(Q): D = int(input()) L[2 * N + i] = (D, 2, 0) L.sort() ...
s990174661
s964390268
p03033
python
Runtime Error
N, Q = (int(i) for i in input().split()) L = [0] * 2 * N for i in range(N): S, T, X = (int(i) for i in input().split()) L[2 * i] = (S-X, X, 1) L[2 * i + 1] = (T-X, X, 0) L.sort(reverse=True) Xs = set([]) for i in range(Q): D = int(input()) ans = 0 while True: if L: t, X, f ...
import sys input = sys.stdin.readline import heapq N, Q = (int(i) for i in input().split()) L = [0] * (2 * N + Q) for i in range(N): S, T, X = (int(i) for i in input().split()) L[2 * i] = (S-X, 1, X) L[2 * i + 1] = (T-X, -1, X) for i in range(Q): D = int(input()) L[2 * N + i] = (D, 2, 0) L.sort() ...
s820599188
s964390268
p03033
python
Time Limit Exceeded
N, Q = (int(i) for i in input().split()) L = [0] * 2 * N P = {} for i in range(N): S, T, X = (int(i) for i in input().split()) L[2 * i] = (S-X, X, 1) L[2 * i + 1] = (T-X, X, 0) L.sort(reverse=True) Xs = set([]) for i in range(Q): D = int(input()) ans = 0 while True: if not L: ...
import sys input = sys.stdin.readline import heapq N, Q = (int(i) for i in input().split()) L = [0] * (2 * N + Q) for i in range(N): S, T, X = (int(i) for i in input().split()) L[2 * i] = (S-X, 1, X) L[2 * i + 1] = (T-X, -1, X) for i in range(Q): D = int(input()) L[2 * N + i] = (D, 2, 0) L.sort() ...
s130308847
s964390268
p03033
python
Time Limit Exceeded
N = int(input()) DP = [0] * (N+1) DP[0] = 1 su = [0] * (2*(10**5)) prev = None for i in range(N): C = int(input()) if prev == C: DP[i+1] = DP[i] else: su[C] += DP[i] DP[i+1] = su[C] prev = C print(DP[N])
N = int(input()) DP = [0] * (N+1) DP[0] = 1 su = [0] * (2*(10**5)+1) prev = None MOD = 10**9+7 for i in range(N): C = int(input()) if prev == C: DP[i+1] = DP[i] else: su[C] += DP[i] su[C] %= MOD DP[i+1] = su[C] DP[i+1] %= MOD prev = C print(DP[N])
s966206026
s356220062
p03096
python
Runtime Error
, B = (int(i) for i in input().split()) if A%2 == 0: a = 0 else: a = A A = A + 1 if B%2 == 1: b = 0 else: b = B B = B - 1 if (B-A+1)%4==0: c = 0 else: c = 1 print(a^b^c)
A, B = (int(i) for i in input().split()) if A%2 == 0: a = 0 else: a = A A = A + 1 if B%2 == 1: b = 0 else: b = B B = B - 1 if (B-A+1)%4==0: c = 0 else: c = 1 print(a^b^c)
s946505771
s637537066
p03104
python
Runtime Error
N, M = (int(i) for i in input().split()) L = [] for i in range(M): a, b = (int(j) for j in input().split()) L.append((a-1, b-1)) L.reverse() uf = [-1]*N def parent(v): if uf[v] < 0: return v else: uf[v] = parent(uf[v]) return uf[v] res = [0]*M ans = (N*(N-1))//2 res[0] = ans f...
import sys input = sys.stdin.readline sys.setrecursionlimit(100000) N, M = (int(i) for i in input().split()) L = [] for i in range(M): a, b = (int(j) for j in input().split()) L.append((a-1, b-1)) L.reverse() uf = [-1]*N def parent(v): if uf[v] < 0: return v else: uf[v] = parent(uf[v]...
s309084439
s818964932
p03108
python
Runtime Error
import numpy as np import bisect import sys input = sys.stdin.readline (A,B,Q) = map(int,input().split()) inf = 10**12 s = np.empty(A+2,dtype=np.int64) t = np.empty(B+2,dtype=np.int64) s[0] = -inf t[0] = -inf s[A+1] = inf t[B+1] = inf for i in range(A): s[i+1] = np.int64(input()) for i in range(B): t[i+1] = n...
import numpy as np import bisect import sys input = sys.stdin.readline (A,B,Q) = map(int,input().split()) inf = 10**12 s = [0] * (A+2) t = [0] * (B+2) s[0] = -inf t[0] = -inf s[A+1] = inf t[B+1] = inf for i in range(A): s[i+1] = int(input()) for i in range(B): t[i+1] = int(input()) for _ in range(Q): x =...
s531498281
s905523911
p03112
python
Time Limit Exceeded
import numpy as np import bisect (A,B,Q) = map(int,input().split()) inf = 10**12 s = np.empty(A+2,dtype=np.int64) t = np.empty(B+2,dtype=np.int64) s[0] = -inf t[0] = -inf s[A+1] = inf t[B+1] = inf for i in range(A): s[i+1] = int(input()) for i in range(B): t[i+1] = int(input()) for _ in range(Q): x = int...
import numpy as np import bisect import sys input = sys.stdin.readline (A,B,Q) = map(int,input().split()) inf = 10**12 s = [0] * (A+2) t = [0] * (B+2) s[0] = -inf t[0] = -inf s[A+1] = inf t[B+1] = inf for i in range(A): s[i+1] = int(input()) for i in range(B): t[i+1] = int(input()) for _ in range(Q): x =...
s103131813
s905523911
p03112
python
Time Limit Exceeded
import bisect A, B, Q = (int(i) for i in input().split()) s = [0]*A t = [0]*B for i in range(A): s[i] = int(input()) for i in range(B): t[i] = int(input()) s_diff = [0]*A t_diff = [0]*B for i in range(A): ind = bisect.bisect_left(t, s[i]) if ind == 0: sm = float("inf") else: sm = s...
import numpy as np import bisect import sys input = sys.stdin.readline (A,B,Q) = map(int,input().split()) inf = 10**12 s = [0] * (A+2) t = [0] * (B+2) s[0] = -inf t[0] = -inf s[A+1] = inf t[B+1] = inf for i in range(A): s[i+1] = int(input()) for i in range(B): t[i+1] = int(input()) for _ in range(Q): x =...
s808756690
s905523911
p03112
python
Time Limit Exceeded
N, M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] num = [0,2,5,5,4,5,6,3,7,6] DP = [0] * (N+1) for i in range(N+1): for j in range(M): n = num[A[j]] if i - n >= 0: DP[i] = max(DP[i], DP[i-n]+1) A.sort(reverse = True) ans = "" remain = DP[N] match = N whil...
import sys N, M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] A.sort() A.reverse() num = [0,2,5,5,4,5,6,3,7,6] A_num = [(num[a], -a) for a in A] A_num.sort() min_A = -A_num[0][1] min_num = A_num[0][0] keta_max = N//min_num DP = [-1] * (N+1) DP[0] = 0 for i in range(N+1): for j in r...
s996796526
s893255025
p03128
python
Time Limit Exceeded
N, M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] num = [0,2,5,5,4,5,6,3,7,6] DP = [0] * (N+1) for i in range(N+1): for j in range(M): n = num[A[j]] if i - n >= 0: DP[i] = max(DP[i], DP[i-n]+1) A.sort(reverse = True) ans = "" remain = DP[N] match = N whil...
import sys N, M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] A.sort() A.reverse() num = [0,2,5,5,4,5,6,3,7,6] A_num = [(num[a], -a) for a in A] A_num.sort() min_A = -A_num[0][1] min_num = A_num[0][0] keta_max = N//min_num DP = [-1] * (N+1) DP[0] = 0 for i in range(N+1): for j in r...
s380459567
s893255025
p03128
python
Time Limit Exceeded
import sys N, M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] A.sort() A.reverse() sys.setrecursionlimit(10000) num = [0,2,5,5,4,5,6,3,7,6] A_num = [(num[a], -a) for a in A] A_num.sort() min_A = -A_num[0][1] min_num = A_num[0][0] keta_max = N//min_num def solve(d, amari): if d == 0...
import sys N, M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] A.sort() A.reverse() num = [0,2,5,5,4,5,6,3,7,6] A_num = [(num[a], -a) for a in A] A_num.sort() min_A = -A_num[0][1] min_num = A_num[0][0] keta_max = N//min_num DP = [-1] * (N+1) DP[0] = 0 for i in range(N+1): for j in r...
s189324176
s893255025
p03128
python
Runtime Error
import sys N, M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] A.sort() A.reverse() sys.setrecursionlimit(10000) num = [0,2,5,5,4,5,6,3,7,6] A_num = [(num[a], -a) for a in A] A_num.sort() min_A = -A_num[0][1] min_num = A_num[0][0] keta_max = N//min_num def solve(d, amari): if amari ...
import sys N, M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] A.sort() A.reverse() num = [0,2,5,5,4,5,6,3,7,6] A_num = [(num[a], -a) for a in A] A_num.sort() min_A = -A_num[0][1] min_num = A_num[0][0] keta_max = N//min_num DP = [-1] * (N+1) DP[0] = 0 for i in range(N+1): for j in r...
s338605271
s893255025
p03128
python
Runtime Error
N, M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] A.sort() A.reverse() num = [0,2,5,5,4,5,6,3,7,6] A_num = [(num[a], -a) for a in A] A_num.sort() min_A = -A_num[0][1] min_num = A_num[0][0] keta_max = N//min_num def solve(d, amari): if amari < 0: return None elif amari ==...
import sys N, M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] A.sort() A.reverse() num = [0,2,5,5,4,5,6,3,7,6] A_num = [(num[a], -a) for a in A] A_num.sort() min_A = -A_num[0][1] min_num = A_num[0][0] keta_max = N//min_num DP = [-1] * (N+1) DP[0] = 0 for i in range(N+1): for j in r...
s851046703
s893255025
p03128
python
Runtime Error
N, K = (int(i) for i in input().split()) A = [int(i) for i in input().split()] C = [[0]*2 for i in range(40)] for i in range(40): cc = 0 for a in A: if a & (2**(39-i)): cc += 1 C[i][0] = cc * 2**(39-i) C[i][1] = (N-cc) * 2**(39-i) INF = float("inf") dp = [[-INF]*2 for i in range(41)] dp[0][0] = 0 for ...
N, K = (int(i) for i in input().split()) A = [int(i) for i in input().split()] A = [format(a,'b').zfill(40) for a in A] C = [0]*40 for i in range(40): cc = 0 for a in A: keta = 39 - i if a[keta] == "1": cc += 1 C[keta] = cc ans = 0 for i in range(40): b = 39 - i if C[i] <...
s329977644
s782525796
p03138
python
Runtime Error
N, K = (int(i) for i in input().split()) A = [int(i) for i in input().split()] C = [0]*40 for i in range(40): for a in A: if a & (2**(39-i)): C[i] += 1 dp = [[0]*2 for in range(41)] for i in range(40): if K & (2**(39-i)): temp1 = dp[i][0] + 2**(39-i)*C[i] temp2 = dp[i][1] + 2**(39-i)*max(C[i],N-C[...
N, K = (int(i) for i in input().split()) A = [int(i) for i in input().split()] A = [format(a,'b').zfill(40) for a in A] C = [0]*40 for i in range(40): cc = 0 for a in A: keta = 39 - i if a[keta] == "1": cc += 1 C[keta] = cc ans = 0 for i in range(40): b = 39 - i if C[i] <...
s742393376
s782525796
p03138
python
Runtime Error
s = int(input()) if s == 1 or s == 2: print(4) res = 1 else: while True: if s == 4: break else: if s % 2 == 0: s = s // 2 else: s = 3 * s + 1 res += 1 print(res+3)
s = int(input()) if s == 1 or s == 2: print(4) else: res = 1 while True: if s == 4: break else: if s % 2 == 0: s = s // 2 else: s = 3 * s + 1 res += 1 print(res+3)
s640564554
s289649733
p03146
python
Runtime Error
N, K = (int(i) for i in input().split()) L = [] for i in range(N): t,d = (int(i) for i in input().split()) L.append((t,d)) L = sorted(L, key = lambda x:(x[0], -x[1])) for i in range(N): if i == 0: ra = 0 L[i] = (L[i][0], L[i][1], ra) else: if L[i][0] == L[i-1][0]: ra...
N, K = (int(i) for i in input().split()) L = [] for i in range(N): t,d = (int(i) for i in input().split()) L.append((t,d)) L = sorted(L, key = lambda x:(x[0], -x[1])) for i in range(N): if i == 0: ra = 0 L[i] = (L[i][0], L[i][1], ra) else: if L[i][0] == L[i-1][0]: ra...
s676637210
s049175960
p03148
python
Runtime Error
H, W = ( int(i) for i in input().split() ) S = [input() for i in range(H)] cc = 0 for ss in S: for st in ss: if st == ".": cc += 1 for i in range(len(S)): S[i] = "#" + S[i] + "#" temp = ["#" * (W + 2)] S = temp + S + temp dd = [[float("inf")] * W for i in range(H)] def DFS(a, b, d): ...
import sys H, W = ( int(i) for i in input().split() ) S = [input() for i in range(H)] cc = 0 for ss in S: for st in ss: if st == ".": cc += 1 for i in range(len(S)): S[i] = "#" + S[i] + "#" temp = ["#" * (W + 2)] S = temp + S + temp dd = [[float("inf")] * W for i in range(H)] def DFS(a...
s604887811
s599562534
p03436
python
Runtime Error
N, H = ( int(i) for i in input().split() ) ka = [] kb = [] for i in range(N): a, b = ( int(i) for i in input().split() ) ka.append(a) kb.append(b) kb.sort() kb.reverse() hp = H res = 0 for b in kb: if b < max(ka): continue hp = hp - b res += 1 if hp <= 0: break else: res += (hp + max(ka) - 1)//max(ka) ...
N, H = ( int(i) for i in input().split() ) ka = [] kb = [] for i in range(N): a, b = ( int(i) for i in input().split() ) ka.append(a) kb.append(b) kb.sort() kb.reverse() ma = max(ka) hp = H res = 0 for b in kb: if b < ma: continue hp = hp - b res += 1 if hp <= 0: break else: res += (hp + ma - 1)//ma pr...
s785280733
s394281641
p03472
python
Time Limit Exceeded
N, H = ( int(i) for i in input().split() ) ka = [] kb = [] for i in range(N): a, b = ( int(i) for i in input().split() ) ka.append(a) kb.append(b) kb.sort() kb.reverse() hp = H res = 0 for b in kb: if b < max(a): continue hp = hp - b res += 1 if hp <= 0: break else: res += (hp + max(ka) - 1)//max(ka) p...
N, H = ( int(i) for i in input().split() ) ka = [] kb = [] for i in range(N): a, b = ( int(i) for i in input().split() ) ka.append(a) kb.append(b) kb.sort() kb.reverse() ma = max(ka) hp = H res = 0 for b in kb: if b < ma: continue hp = hp - b res += 1 if hp <= 0: break else: res += (hp + ma - 1)//ma pr...
s356744070
s394281641
p03472
python
Runtime Error
prime = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,...
likeprime = [3,5,13,37,61,73,157,193,277,313,397,421,457,541,613,661,673,733,757,877,997,1093,1153,1201,1213,1237,1321,1381,1453,1621,1657,1753,1873,1933,1993,2017,2137,2341,2473,2557,2593,2797,2857,2917,3061,3217,3253,3313,3517,3733,4021,4057,4177,4261,4273,4357,4441,4561,4621,4933,5077,5101,5113,5233,5413,5437,5581,5...
s748772077
s492763644
p03476
python
Time Limit Exceeded
prime = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,...
likeprime = [3,5,13,37,61,73,157,193,277,313,397,421,457,541,613,661,673,733,757,877,997,1093,1153,1201,1213,1237,1321,1381,1453,1621,1657,1753,1873,1933,1993,2017,2137,2341,2473,2557,2593,2797,2857,2917,3061,3217,3253,3313,3517,3733,4021,4057,4177,4261,4273,4357,4441,4561,4621,4933,5077,5101,5113,5233,5413,5437,5581,5...
s166234303
s492763644
p03476
python
Time Limit Exceeded
import sys input = sys.stdin.readline N, C = (int(i) for i in input().split()) pp = [[0] * 100000 for i in range(C)] for i in range(N): s, t, c = (int(i) for i in input().split()) for j in range(s, t+1): pp[c-1][j] = 1 res = 0 for i in range(100000): cc = 0 for j in range(C): if pp[j...
import sys input = sys.stdin.readline N, C = (int(i) for i in input().split()) pp = [[0] * 100001 for i in range(C)] for i in range(N): s, t, c = (int(i) for i in input().split()) for j in range(s, t+1): pp[c-1][j] = 1 res = 0 for i in range(100001): cc = 0 for j in range(C): if pp[j...
s577694900
s311078950
p03504
python
Runtime Error
Sdash = str(input()) T = str(input()) reslis = [] N = len(Sdash) - len(T) + 1 for i in range(N): Tdash = Sdash[i:i+len(T)] for j in range(len(T)): if Tdash[j] == T[j] or Tdash[j] == "?": pass else: break else: if i == 0: reslis.append(T + Sdash[i+...
Sdash = str(input()) T = str(input()) reslis = [] if len(Sdash) >= len(T): for i in range(len(Sdash) - len(T) + 1): res = Sdash temp = Sdash[i:i+len(T)] for k in range(len(T)): if T[k] == temp[k] or temp[k] == "?": res = list(res) res[k+i] = T[k]...
s095656573
s501794339
p03565
python
Runtime Error
Sdash = str(input()) T = str(input()) reslis = [] N = len(Sdash) - len(T) + 1 for i in range(N): Tdash = Sdash[i:i+len(T)] for j in range(len(T)): if Tdash[j] == T[j] or Tdash[j] == "?": pass else: break else: print(Tdash) if i == 0: resli...
Sdash = str(input()) T = str(input()) reslis = [] if len(Sdash) >= len(T): for i in range(len(Sdash) - len(T) + 1): res = Sdash temp = Sdash[i:i+len(T)] for k in range(len(T)): if T[k] == temp[k] or temp[k] == "?": res = list(res) res[k+i] = T[k]...
s551733518
s501794339
p03565
python
Runtime Error
N = int(input()) L = [] for i in range(N): a = int(input()) if a in L: L.remove(a) else: L.append(a) L = set(L) print(len(L))
N = int(input()) L = [] for i in range(N): a = int(input()) L.append(a) L.sort() ptr = 0 temp = 0 num = 1 ans = 0 while ptr < N: cc = L[ptr] f = 0 while ptr < N and L[ptr] == cc:#同じ数字が続く終了条件 f += 1 ptr += 1 ans += f%2 print(ans)
s274202454
s392660831
p03607
python
Time Limit Exceeded