-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1,024 changed files
with
266,215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
def main(): | ||
for _ in range(int(input())): | ||
n = int(input()) | ||
d = {} | ||
arr = list(map(int, input().split())) | ||
flag = 0 | ||
for i in arr: | ||
if ((i > 1) or (i < -1)) and i in d: | ||
print('no') | ||
flag = 1 | ||
break | ||
if i in d: | ||
d[i] += 1 | ||
else: | ||
d[i] = 1 | ||
if flag: | ||
continue | ||
l = list(d.keys()) | ||
if len(l) == 1: | ||
if n == 1: | ||
print('yes') | ||
else: | ||
if (1 in l) or (0 in l): | ||
print('yes') | ||
else: | ||
print('no') | ||
elif len(l) == 2: | ||
if (0 in l): | ||
if -1 in d: | ||
if d[-1] == 1: | ||
print('yes') | ||
else: | ||
print('no') | ||
else: | ||
print('yes') | ||
elif 1 in l: | ||
print('yes') | ||
else: | ||
print('no') | ||
elif len(l) == 3: | ||
if (0 in l) and (1 in l): | ||
print('yes') | ||
else: | ||
print('no') | ||
else: | ||
print('no') | ||
|
||
|
||
if __name__== '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def main(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
def main(): | ||
for _ in range(int(input())): | ||
(x1, y1, x2, y2) = map(int, input().split()) | ||
if x1 == x2: | ||
if y2> y1: | ||
print('up') | ||
else: | ||
print('down') | ||
elif y1 == y2: | ||
if x2> x1 : | ||
print('right') | ||
else: | ||
print('left') | ||
else: | ||
print('sad') | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
def main(): | ||
for _ in range(int(input())): | ||
d = int(input()) | ||
print(d%9+1) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
def main(): | ||
t = int(input()) | ||
for _ in range(t): | ||
n = int(input()) | ||
arr = list(map(int, input().split())) | ||
d = {} | ||
for i in arr: | ||
if i in d: | ||
d[i] += 1 | ||
else: | ||
d[i] = 1 | ||
l = list(d.keys()) | ||
#print(d) | ||
m = max(l) | ||
for i in l: | ||
if d[i] == 1 and i < m: | ||
m = i | ||
print(m) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
def main(): | ||
for _ in range(int(input())): | ||
(m,n) = map(int, input().split()) | ||
if m==1: | ||
print(0) | ||
continue | ||
if m==2: | ||
print(n) | ||
continue | ||
a=(m-1) + 2 * (n-1) | ||
print(a) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
def check(arr): | ||
mul, sum = 1, 0 | ||
for i in arr: | ||
mul *= i | ||
sum += i | ||
if mul == sum: | ||
#print(arr, 'true') | ||
return 1 | ||
else: | ||
#print(arr, 'false') | ||
return 0 | ||
|
||
def check1(arr): | ||
pass | ||
|
||
|
||
def main(): | ||
t = int(input()) | ||
for _ in range(t): | ||
n = int(input()) | ||
arr = list(map(int, input().split())) | ||
count = 0 | ||
for i in range(n): | ||
for j in range(i, n): | ||
a = arr[i:j+1] | ||
count += check(a) | ||
print(count) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
def main(): | ||
for _ in range(int(input())): | ||
n, k = map(int, input().split()) | ||
arr = list(map(int, input().split())) | ||
arr1 = [] | ||
arr2 = [] | ||
count = 0 | ||
for i in arr: | ||
if i > k: | ||
arr1.append(i-k) | ||
count += 1 | ||
else: | ||
arr2.append(i) | ||
if len(arr1)>1: | ||
arr1.sort() | ||
a = abs(sum(arr1[:-2]) - arr1[-2]) | ||
print(abs(a - arr1[-1]) + sum(arr2) + k * count) | ||
else: | ||
print(sum(arr)) | ||
|
||
|
||
|
||
if __name__ =='__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
def minize(arr): | ||
pass | ||
|
||
def main(): | ||
for _ in range(int(input())): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
def rmv(n, i): | ||
n = list(n) | ||
res = n[:i] + n[i+1:] | ||
res = ''.join(res) | ||
return int(res) | ||
|
||
def main(): | ||
t = int(input()) | ||
for _ in range(t): | ||
n = int(input()) | ||
m = [] | ||
l = str(n) | ||
for i in range(len(l)): | ||
m.append(rmv(l, i)) | ||
print(min(m)) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from itertools import combinations as comb | ||
def common(arr): | ||
arr.sort() | ||
#print(arr, 'pair') | ||
#print(arr[0][1], arr[1][0], arr[2][0]) | ||
if (arr[0][1] >= arr[1][0]) & (arr[0][1] >= arr[2][0]): | ||
#print('yeah') | ||
return True | ||
return False | ||
|
||
|
||
def check(arr, n): | ||
for i in range(n): | ||
for j in range(i + 1, n): | ||
for k in range(j + 1, n): | ||
a = [arr[i], arr[j], arr[k]] | ||
if common(a): | ||
return False | ||
''' | ||
a = list(comb(arr, 3)) | ||
print(a, 'comb') | ||
for i in a: | ||
if common(list(i)): | ||
return False | ||
return True | ||
''' | ||
def main(): | ||
for _ in range(int(input())): | ||
n = int(input()) | ||
d = {} | ||
for i in range(n): | ||
(l, r, v) = map(int, input().split()) | ||
if v in d: | ||
d[v].append((l, r)) | ||
else: | ||
d[v] = [(l, r)] | ||
|
||
#print(d, 'v') | ||
l = list(d.keys()) | ||
flag = True | ||
for i in l: | ||
if len(d[i]) > 2: | ||
flag = check(d[i], len(d[i])) | ||
if flag == False: | ||
break | ||
if flag == False: | ||
print('NO') | ||
else: | ||
print('YES') | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
def main(): | ||
t = int(input()) | ||
for _ in range(t): | ||
n = int(input()) | ||
zero = {} | ||
one = {} | ||
for i in range(n): | ||
s, flag = input().split() | ||
if flag == '0': | ||
if s in zero: | ||
zero[s] += 1 | ||
else: | ||
zero[s] = 1 | ||
if s not in one: | ||
one[s] = 0 | ||
else: | ||
if s in one: | ||
one[s] += 1 | ||
else: | ||
one[s] = 1 | ||
if s not in zero: | ||
zero[s] = 0 | ||
l = list(zero.keys()) | ||
res = 0 | ||
for i in l: | ||
res += max(zero[i], one[i]) | ||
print(res) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
def main(): | ||
for _ in range(int(input())): | ||
n, k = map(int, input().split()) | ||
s = input() | ||
a = [] | ||
d = {} | ||
for i in range(k): | ||
s1 = input() | ||
for j in s1: | ||
pass | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
def main(): | ||
for _ in range(int(input())): | ||
(n,m) = map(int, input().split()) | ||
print((n-1)*(m-1)) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
def main(): | ||
t = int(input()) | ||
for _ in range(t): | ||
[n, s] = list(input().split()) | ||
n = int(n) | ||
one, zero = 0, 0 | ||
for i in range(n): | ||
s1 = input() | ||
if s1[0] == '0': | ||
zero += s1.count('0') | ||
else: | ||
one += s1.count('1') | ||
if zero > one: | ||
print('Dee') | ||
elif zero < one: | ||
print('Dum') | ||
else: | ||
if s == 'Dee': | ||
print('Dum') | ||
else: | ||
print('Dee') | ||
|
||
if __name__ == "__main__": | ||
main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def main(): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
def main(): | ||
for _ in range(int(input())): | ||
n = int(input()) | ||
arr = list(map(int, input().split())) | ||
arr1 = [arr[0]] | ||
for i in range(1, n): | ||
arr1.append(arr1[i-1] + arr[i]) | ||
(yb, mb, db) = map(int, input().split()) | ||
(yc, mc, dc) = map(int, input().split()) | ||
|
||
if mb == 1: | ||
late_birth = db | ||
else: | ||
late_birth = arr1[mb-2] + db | ||
|
||
if mc == 1: | ||
extra_date = dc | ||
else: | ||
extra_date = arr1[mc-2] + dc | ||
|
||
no_days = (yc-yb)*arr1[-1] + 1 | ||
no_days += extra_date | ||
no_days -= late_birth | ||
leep = yc//4 - yb//4 | ||
if yb%4==0: | ||
leep += 1 | ||
if yc%4 == 0: | ||
leep -= 1 | ||
|
||
print(no_days+leep) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.