This file contains hidden or 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
def solve(n,k): | |
pos=n//2 | |
if n%2!=0: | |
pos=pos+1 | |
if k<=pos: | |
return 1+(k-1)*2 | |
else: | |
k=k-pos | |
return 2+(k-1)*2 |
This file contains hidden or 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
## Read input as specified in the question. | |
## Print output as specified in the question. | |
n=int(input()) | |
if n%2==0: | |
print("YES") | |
else: | |
print("NO") |
This file contains hidden or 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
import math | |
n=int(input()) | |
print(math.factorial(n)) |
This file contains hidden or 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
import math | |
def find_lcm(a, b): | |
return abs(a * b) // math.gcd(a, b) | |
t=int(input()) | |
for i in range(t): | |
n,m,k=map(int,input().split()) | |
l = sorted(list(map(int,input().split()))) | |
num1 = l[0] | |
num2 = l[1] | |
lcm = find_lcm(num1, num2) |
This file contains hidden or 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
t=int(input()) | |
for i in range(t): | |
n = int(input()) | |
print((n * (n + 1) // 2) + 1) |
This file contains hidden or 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
def solve(n): | |
if n < 9: | |
return n | |
else: | |
return (n%9) + (10 * solve(n//9)) | |
while True: | |
try: | |
n = int(input()) | |
print(solve(n)) | |
except ValueError : |
This file contains hidden or 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
''' | |
# Sample code to perform I/O: | |
name = input() # Reading input from STDIN | |
print('Hi, %s.' % name) # Writing output to STDOUT | |
# Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail | |
''' | |
# Write your code here |
This file contains hidden or 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
import math | |
x=int(input()) | |
y=int(input()) | |
print(math.gcd(x,y)) |
This file contains hidden or 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
## Read input as specified in the question. | |
## Print output as specified in the question. | |
arr=list(map(int,input().split())) | |
i=len(arr)-1 | |
while i>0: | |
i=i-1 | |
if arr[i]!=-1: | |
print(arr[i],end=" ") |
This file contains hidden or 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
for i in range(int(input())): | |
n=int(input()) | |
m=list(map(int,input().split())) | |
c=n-1 | |
while c>0 and m[c-1]>=m[c]:c-=1 | |
while c>0 and m[c-1]<=m[c]:c-=1 | |
print(c) |