Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every d...
3
0
for _ in range(input()): noOfCandies, noOfDays = map(int, raw_input().split()) for _ in range(noOfDays): if noOfCandies % 2 > 0: noOfCandies -= (noOfCandies+1)/2 else: noOfCandies -= noOfCandies/2 noOfCandies -= noOfCandies//4 print noOfCandies
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every d...
3
0
for _ in range(input()): n,t = map(int,raw_input().split()) for i in range(t): if n%2 == 0: n /= 2 else: n = n - ((n+1)/2) n = n - n/4 print n
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every d...
3
0
test_cases=int(raw_input()) for i in range(test_cases): n,t=raw_input().split() n=int(n) t=int(t) candies=n days=t while(t>0): #At 9 Am reduction of chocolates if(candies%2==0): candies=candies-(candies/2) elif(candies%2==1): candies=candies-((candies+1)/2) #At 10 am candies=candies-candies//4 t...
PYTHON
dummy-2
Hansa is throwing a birthday party. Seeing the extravagant parties thrown by her friends in the past, Hansa too decided to do something unique. Being a Computer Engineer herself, she knew just how to do it. She sent password-protected e-invites to T of her friends. Along with each of those e-invites there would be a nu...
3
0
t=input() while t: a=map(str, raw_input("").split()) base=int(a[0]) s=a[1] k=1 ans=0 while len(s)>0: l=s[-1] if ord(l)<59: l=ord(l)-48 else: l=ord(l)-87 ans+=k*l k*=base s=s[:-1] x=str(ans) print sum(int(i) for i in ...
PYTHON
dummy-2
Hansa is throwing a birthday party. Seeing the extravagant parties thrown by her friends in the past, Hansa too decided to do something unique. Being a Computer Engineer herself, she knew just how to do it. She sent password-protected e-invites to T of her friends. Along with each of those e-invites there would be a nu...
3
0
# your code goes here import sys t=input() for _ in range(t): s=raw_input() st=s.split(' ') a=int(st[0]) b=str(st[1]) aa=int(b,a) ab=str(aa) ans=0 for i in range(len(ab)): ans+=int(ab[i]) print ans
PYTHON
dummy-2
Hansa is throwing a birthday party. Seeing the extravagant parties thrown by her friends in the past, Hansa too decided to do something unique. Being a Computer Engineer herself, she knew just how to do it. She sent password-protected e-invites to T of her friends. Along with each of those e-invites there would be a nu...
3
0
def solve(): b,s=raw_input().split() print sum(map(int,str(int(s,int(b))))) for _ in xrange(input()): solve()
PYTHON
dummy-2
Hansa is throwing a birthday party. Seeing the extravagant parties thrown by her friends in the past, Hansa too decided to do something unique. Being a Computer Engineer herself, she knew just how to do it. She sent password-protected e-invites to T of her friends. Along with each of those e-invites there would be a nu...
3
0
for i in xrange(input()): p=raw_input().split() q=int(p[1],int(p[0])) print sum(map(int,str(q)))
PYTHON
dummy-2
Hansa is throwing a birthday party. Seeing the extravagant parties thrown by her friends in the past, Hansa too decided to do something unique. Being a Computer Engineer herself, she knew just how to do it. She sent password-protected e-invites to T of her friends. Along with each of those e-invites there would be a nu...
3
0
cases = input() for i in range(cases): base,string = raw_input().split() base = (int)(base) answer = int(string,base) answer = sum(map(int,str(answer))) print answer
PYTHON
dummy-2
Hansa is throwing a birthday party. Seeing the extravagant parties thrown by her friends in the past, Hansa too decided to do something unique. Being a Computer Engineer herself, she knew just how to do it. She sent password-protected e-invites to T of her friends. Along with each of those e-invites there would be a nu...
3
0
t = input() while t: t-=1 text=raw_input() st = text.split() base = int(st[0]) num = str(st[1]) num = int(num,base) num = str(num) le = len(num) ans = 0 for i in range(0,le): ans += int(num[i]) print ans
PYTHON
dummy-2
Hansa is throwing a birthday party. Seeing the extravagant parties thrown by her friends in the past, Hansa too decided to do something unique. Being a Computer Engineer herself, she knew just how to do it. She sent password-protected e-invites to T of her friends. Along with each of those e-invites there would be a nu...
3
0
t = raw_input() t=int(t) i=0 while i<t: line=raw_input() line=line.split(' ') base=int(line[0]) s=line[1] length= len(s) j=length-1 j=int(j) p=1 ans=0 while j>=0: temp=0 if s[j]>='a' and s[j]<='z': ...
PYTHON
dummy-2
Hansa is throwing a birthday party. Seeing the extravagant parties thrown by her friends in the past, Hansa too decided to do something unique. Being a Computer Engineer herself, she knew just how to do it. She sent password-protected e-invites to T of her friends. Along with each of those e-invites there would be a nu...
3
0
t = raw_input() t=int(t) i=0 while i<t: line=raw_input() line=line.split(' ') base=int(line[0]) s=line[1] length= len(s) j=length-1 j=int(j) p=1 ans=0 while j>=0: temp=0 if s[j]>='a' and s[j]<='z': temp = ord(s[j])-87 else: ...
PYTHON
dummy-2
Hansa is throwing a birthday party. Seeing the extravagant parties thrown by her friends in the past, Hansa too decided to do something unique. Being a Computer Engineer herself, she knew just how to do it. She sent password-protected e-invites to T of her friends. Along with each of those e-invites there would be a nu...
3
0
import sys t=int(sys.stdin.readline()) for x in range(0,t): a=sys.stdin.readline().split() sum=0 b=int(a[1],int(a[0])) for y in str(b): sum+=int(y) print(sum)
PYTHON
dummy-2
Hansa is throwing a birthday party. Seeing the extravagant parties thrown by her friends in the past, Hansa too decided to do something unique. Being a Computer Engineer herself, she knew just how to do it. She sent password-protected e-invites to T of her friends. Along with each of those e-invites there would be a nu...
3
0
t=input() while t: a=map(str, raw_input("").split()) base=int(a[0]) stri=a[1] q=1 ans=0 while len(stri)>0: l=stri[-1] if ord(l)<59: l=ord(l)-48 else: l=ord(l)-87 ans+=q*l q*=base stri=stri[:-1] x=str(ans) print sum(i...
PYTHON
dummy-2
Hansa is throwing a birthday party. Seeing the extravagant parties thrown by her friends in the past, Hansa too decided to do something unique. Being a Computer Engineer herself, she knew just how to do it. She sent password-protected e-invites to T of her friends. Along with each of those e-invites there would be a nu...
3
0
for _ in xrange(input()): a,b=raw_input().split() x=int(str(b),int(a)) print sum([int(i) for i in str(x)])
PYTHON
dummy-2
Hansa is throwing a birthday party. Seeing the extravagant parties thrown by her friends in the past, Hansa too decided to do something unique. Being a Computer Engineer herself, she knew just how to do it. She sent password-protected e-invites to T of her friends. Along with each of those e-invites there would be a nu...
3
0
import math t=(int)(input()) while t: t-=1 num=0 n,s=raw_input().split() n,s=(int)(n),(str)(s) l=len(s) k=1 for i in range(l): tmp=ord(s[l-i-1]) if tmp<60: num+=(tmp-48)*k else: num+=(tmp-87)*k k*=n x=(str)(num) #print num, ...
PYTHON
dummy-2
Hansa is throwing a birthday party. Seeing the extravagant parties thrown by her friends in the past, Hansa too decided to do something unique. Being a Computer Engineer herself, she knew just how to do it. She sent password-protected e-invites to T of her friends. Along with each of those e-invites there would be a nu...
3
0
t = input() while t: t-=1 text=raw_input() st = text.split() base = int(st[0]) num = str(st[1]) num2 = int(num,base) num3 = str(num2) le = len(num3) ans = 0 for i in range(0,le): ans += int(num3[i]) print ans
PYTHON
guess-it-1
Gazi is a very talented mathematician, recently he discovered the majestic power of the number '9' so he wants to play a game with you. He tells you to pick any real integer [from 10 to 10^200], then subtract sum of digits of this number from the number itself. You will get another number, now omit any digit from this ...
3
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' t=input() while t>0: t-=1 s=raw_input() for i in range(0,9): x=s.replace("_",str(i)) if int(x)%9==0: c=i break if c==0: print "0 or 9" else: pri...
PYTHON
guess-it-1
Gazi is a very talented mathematician, recently he discovered the majestic power of the number '9' so he wants to play a game with you. He tells you to pick any real integer [from 10 to 10^200], then subtract sum of digits of this number from the number itself. You will get another number, now omit any digit from this ...
3
0
t=input() while t>0: t-=1 s=raw_input() q=[ord(c) for c in s] l=len(q) n=0 for i in q: if i!=95 and i>47: n=n+(i-48) for i in range(0,9): if ((n+i)%9==0): if i==0: print "0 or 9" else: print i break
PYTHON
guess-it-1
Gazi is a very talented mathematician, recently he discovered the majestic power of the number '9' so he wants to play a game with you. He tells you to pick any real integer [from 10 to 10^200], then subtract sum of digits of this number from the number itself. You will get another number, now omit any digit from this ...
3
0
def sumofDigit(e): s=str(e) su=0 for i in s: su+=int(i) return su t=int(raw_input()) for sdgdsg in xrange(t): s=int(raw_input().replace('_','')) a=9-(sumofDigit(s)%9) print a if (a != 0 and a!=9) else '0 or 9'
PYTHON
guess-it-1
Gazi is a very talented mathematician, recently he discovered the majestic power of the number '9' so he wants to play a game with you. He tells you to pick any real integer [from 10 to 10^200], then subtract sum of digits of this number from the number itself. You will get another number, now omit any digit from this ...
3
0
no_of_cases = int(raw_input()) numbers = [] for x in range(0,no_of_cases): number = raw_input().replace('_','') numbers.append(number) def guess_it(x): total = 0 for x in str(x): total = total+int(x) rem = total%9 value = 9-rem if value ==9 or value ==0: print "0 or 9" e...
PYTHON
guess-it-1
Gazi is a very talented mathematician, recently he discovered the majestic power of the number '9' so he wants to play a game with you. He tells you to pick any real integer [from 10 to 10^200], then subtract sum of digits of this number from the number itself. You will get another number, now omit any digit from this ...
3
0
import sys t=input() while t>0: k=[] s=sys.stdin.readline().strip().split("_") if s[0]!="": k.extend(list(s[0])) if s[1]!="": k.extend(list(s[1])) k=map(int,k) s=sum(k) s=s%9 if s==0: print "0 or 9" else: print 9-s t=t-1
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
N,Q=map(int,raw_input().split()) arrx=map(int,raw_input().split()) winners=[0]*N players=[] for i in xrange(0,N-1,2): if arrx[i]<arrx[i+1]: winners[i]=1 players.append(i+1) else: winners[i+1]=1 players.append(i) if N%2==1: players.append(N-1) winners[N-1]-=1 numround=2 while len(players)>1: ...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
n, q = map(int, raw_input().split()) st = map(int, raw_input().split()) fighters = [(i, s) for i, s in enumerate(st)] fights = [0] * n while n > 1: i = 0 if n % 2 == 1: n -= 1 pops = [] while i < n: f1, s1 = fighters[i] f2, s2 = fighters[i + 1] fights[f1] += 1 fights[f2] += 1 if s1 > s2: pops.append...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
N, Q = map(int, raw_input().strip().split(' ')) strength = map(int, raw_input().strip().split(' ')) nooffights = [0] * N finarr = range(0, N) while (1) : var = 0 newarr = [] while (1) : if (var == len(finarr)) : break if (var == len(finarr) - 1) : newarr.append(finarr[var]) break nooffights[finarr[va...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' n,q = map(int,raw_input().split()) pl = dict(zip([x for x in range(1,n+1)],map(int,raw_input().split()))) pp = dict(zip([x for x in range(1,n+1)],[0 for z in range(1,n+1)])) j=1 while...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
'''input 5 5 1 2 3 4 5 1 2 3 4 5 ''' #~~~~~~~~~~~~~~~~~~~~dwij28 == Abhinav Jha~~~~~~~~~~~~~~~~~~~~# from sys import stdin, stdout, maxint from math import sqrt, floor, ceil, log from collections import defaultdict, Counter def read(): return stdin.readline().strip() def write(x): stdout.write(str(x)) def endl(): wr...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
n, q = raw_input().split() # n = no of fighter n = int(n); q = int(q); # q = querys to be display #print "n", n, "q", q strength = [0] * n # strength of each fighter query = [0] * q # query display order fights = [0] * n alive = [1] * n remain = ...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
N, Q = map(int, raw_input().split()) fighters = map(int, raw_input().split()) status = [True]*N fights = [0]*N players = N while players > 1: i = 0 while i < N-1: if status[i]: check = False for q in xrange(i+1, N): if status[q]: check = True ...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
n,q = map(int,raw_input().strip().split(" ")) weight = map(int,raw_input().strip().split(" ")) totalCount = 0 fighters = range(0,n) fights = [0]*n fightersSubArray = [] while(len(fighters)>1): index = 0 while(index < len(fighters)): if((index+1)<len(fighters)): fights[fighters[index]] += 1 ...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
kk=raw_input() n,b=kk.split() n=int(n) b=int(b) a = [0]*n ar=[] string_input = raw_input() arr = string_input.split() arr = [int(k) for k in arr] for i in range(0,n): ar.append(i) while(len(ar)>1): m=int(len(ar)/2) for i in range(0,m): a[ar[i]]=a[ar[i]]+1 a[ar[i+1]]=a[ar[i+1]]+1 if ...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
import sys L=map(int, sys.stdin.read().split()) N, Q=L[0], L[1] L=L[2:] matches={} pS={} for x in xrange(N): matches[L[x]]=0 pS[x+1]=L[x] mat=L[:N] L=L[N:] while True: for x in xrange(0, N, 2): if x+1<N: mat.append(max(mat[x], mat[x+1])) matches[mat[x]]+=1 matches[mat[x+1]]+=1 else: mat.append(...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
N, Q = [int(x) for x in raw_input().split(' ')] Strength = [int(x) for x in raw_input().split(' ')] Game = [0] * N Fight = [] for i in xrange(N): Fight.append(i) # Processs Fight while len(Fight) > 1: for i in xrange(len(Fight)/2): Game[Fight[i]] += 1 Game[Fight[i+1]] += 1 if Strength[Figh...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
def solution(): N, Q = map(int, raw_input().strip().split(' ')) arr = map(int, raw_input().strip().split(' ')) q = [] winner_counts = {} new_arr = [] for i in xrange(N): winner_counts[i] = 0 new_arr.append((i, arr[i])) for i in xrange(Q): q.append(int(raw_input().stri...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
n, q = map(int, raw_input().split(" ")) fighter=[] count=[] query=[] advance=[] fighter = map(int, raw_input().split(" ")) i=0 while(i<q): temp = int(raw_input()) query.append(temp) i+=1 i=1 while(i<=n): count.append(0) advance.append(i) i+=1 while(len(advance)>1): if(len(advance)%2 == 0)...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
n, q = map(int, raw_input().split()) f = (n) * [0] st = map(int, raw_input().split()) st = list(enumerate(st)) while len(st) > 1: so = [] for i, j in zip(st[0::2], st[1::2]): f[i[0]] += 1 f[j[0]] += 1 if i[1] > j[1]: so.append(i) else: so.append(j) if ...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
from sys import stdin n,q = map(int,stdin.readline().split()) a = map(int,stdin.readline().split()) di = {} ran = {} for i in xrange(1,n+1): di[i] = 0 ran[a[i-1]] = i b = [] i = 0 l = len(a) #print ran,di #print a while True: l = len(a) if l==1: break i = 0 #print a while True: if i+1>=l: break if i>=l...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' # print 'Hello World!' try: N, Q= map(int, raw_input().strip().split(" ")) S= map(int, raw_input().strip().split(" ")) validFighters= range(N) fights=[0]*N #calculate fights w...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
import math from collections import OrderedDict class Nodes(object): def __init__(self): self.data = None self.next = None self.prev = None self.seq_number = 0 def create_node(value): n = Nodes() n.data = value return n def make_struc(s): head = None end = None nodes = OrderedDict() count = 0 for i...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
def chunks(l, n): for i in range(0, len(l), n): yield l[i:i+n] def process(arr): while len(arr) != 1: k = [] tmp = [] if len(arr) % 2 != 0: tmp.append(arr.pop()) for i in chunks(arr, 2): if i[0] in cache: cache[i[0]] += 1 else: cache[i[0]] = 1 if i[1] in cache: cache[i[1]]...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
n,q = map(int,raw_input().split(" ")) pl = dict(zip([x for x in range(1,n+1)],map(int,raw_input().split(" ")))) pp = dict(zip([x for x in range(1,n+1)],[0 for z in range(1,n+1)])) j=1 while len(pl.keys()) != 1: k = pl.keys() for i in range(0,len(k)-1,2): pp[k[i]]+=1 pp[k[i+1]]+=1 if p...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
N, Q = map(int, raw_input().split()) data = map(int, raw_input().split()) newData = [] dataCopy = data counts = {} if len(data) == 1: counts[data[0]] = 0 while len(newData) != 1: length = len(dataCopy) newData = [] for i in range(0, length-1, 2): if dataCopy[i] not in counts: counts[dataCopy[i]] = 1 else: ...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
n, q = map(int, raw_input().split()) l = [0]*(n+1) lis = map(int, raw_input().split()) p = [] c = 0 for i in lis: c += 1 p+=[(c, i)] lis = p while len(lis)>1: nlis=[] ll = len(lis) for i in range(0, ll-ll%2, 2): if lis[i][1]>lis[i+1][1]: nlis+=[lis[i]] else: nlis+=[lis[i+1]] l[lis[i][0]]+=1 l[lis[i+...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
import sys lineArray = sys.stdin.readline().rstrip().split() fighters = int(lineArray[0]) queries = int(lineArray[1]) sequence = sys.stdin.readline().rstrip().split() strengthSeq = {} fighterNumber = 1 for c in sequence: strengthSeq[fighterNumber] = int(c) fighterNumber = fighterNumber + 1 result = {} ...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
N, Q = map(int, raw_input().split(" ")) strengths = map(int, raw_input().split(" ")) count = [0] * N current = range(N) new = [] while len(current) > 1: for i in xrange(0, len(current), 2): if i+1 < len(current): if strengths[current[i]] > strengths[current[i+1]]: new.append(curr...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
import copy a = raw_input().split() b = map(int,raw_input().split()) nop = copy.deepcopy(b) database = {} for k in b: if k not in database: database[k] = 0 def filer(array): b = array teams = [] if len(b) % 2 == 0: for k in range(0,len(b),2): teams.append([b[k],b[k+1]]) ...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
n,q = map(int, raw_input().split()) strengths = map(int,raw_input().split()) fights = [0]*n players = [i for i in range(n)] while len(players) != 1: i = 0 while i < ( len(players)/2) : fights[players[i*2]] += 1 fights[players[i*2 + 1]] += 1 if strengths[players[i*2]] > strengths[players[i*2 + 1]]: players[i*...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
__author__ = 'Admin' inp = map(int , raw_input().split()) n = inp[0] q = inp[1] current = [] answer = [] next = [] _max = 0 inp = map(int , raw_input().split()) # print len(inp) for i in xrange(0 , n): a = ( inp[i] , i+1) current.append(a) # print "max = " , _max for i in xrange(0 ,n+1): answer.append(0) ...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
str_ = raw_input().split() n_fighters = int(str_[0]) n_querries = int(str_[1]) fighters = raw_input().split() fighters = [int(k) for k in fighters] inp = {} out = {} for i in xrange(len(fighters)): inp[fighters[i]] = i+1 out[inp[fighters[i]]] = 0 i = 0 while (len(fighters) > 1): tmp = [] i = 0 while(i < len(fight...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
n,q=map(int,raw_input().strip().split()) strn=map(int,raw_input().strip().split()) d={} l=range(0,n) while len(l)>1: i=0 ln=len(l) tm=[] while i<ln: if i+1>=ln: tm.append(l[i]) else: if strn[l[i]]>strn[l[i+1]]: tm.append(l[i]) else: tm.append(l[i+1]) if l[i] not in d: d[l[i]]=0 d[l[i]...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
class Node: def __init__(self,Points): self.Points=Points self.up=None def __getitem__(self,P): return self.Points class BST: def __init__(self,arr): self.arr=[[arr[i],Node(None)] for i in xrange(len(arr))] self.root=self.arr self.notused=len(arr) def createBST(self): arr=self.arr unused=None wh...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
import sys def solve_fighters(fighters): cList = [0]*len(fighters) fList = [x for x in range(len(fighters))] nList = [] while len(fList) > 1: for ind in range(0, len(fList), 2): if ind == len(fList)-1: nList.append(fList[ind]) else: cList[...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
import math (n, q) = map(int, raw_input().split(' ')) strength = map(int , raw_input().split(' ')) height = int(math.ceil(math.log(n, 2))) fights = {} fighters = [a for a in range(n)] for i in range(n): fights[i] = 0 for i in range(height): idx = 0 #print strength, fighters for j in range(0, n, 2): if n % 2 ...
PYTHON
little-shino-and-the-tournament
Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and i^{th} fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are: Each fight will have 2 fighters. In a fight, fighter with more strength will w...
3
0
import sys from itertools import * def grouper(iterable): return [[iterable[x],iterable[x+1]] for x in range(0,len(iterable),2)] def f(tpl): if tpl[0][1]>tpl[1][1]: return (tpl[0][0],tpl[0][1]) else: return (tpl[1][0],tpl[1][1]) n,q = map(int,sys.stdin.readline().strip().split(' ')) fighters = map(long,sys...
PYTHON
mystery-11
Solve the mystery HINT : Digital Display Input : First line has an integer T. Next T lines has an integer N in each line. It is guaranteed that N never starts with 0 unless value is equal to zero. Output : Print the output for each test case in new line. Constraints : 1 ≤ T ≤ 1000 0 ≤ |N| ≤ 1000 |N| is number of dig...
3
0
def digital(t): dc = 0 while dc < t: dic = {'0':6, '1':2, '2':5, '3':5, '4':4, '5':5, '6':6, '7':3, '8':7, '9':6} s = raw_input() sum = 0 for e in s: sum = sum + dic[e] print sum dc += 1 t = int(raw_input()) digital(t)
PYTHON
mystery-11
Solve the mystery HINT : Digital Display Input : First line has an integer T. Next T lines has an integer N in each line. It is guaranteed that N never starts with 0 unless value is equal to zero. Output : Print the output for each test case in new line. Constraints : 1 ≤ T ≤ 1000 0 ≤ |N| ≤ 1000 |N| is number of dig...
3
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' n=int(raw_input()) dict={0:6,1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} c=0 for i in range(n): sum=0 a=int(raw_input()) if(a==0): print(6) else: while(a): c=a%10; a=a/10 sum=...
PYTHON
mystery-11
Solve the mystery HINT : Digital Display Input : First line has an integer T. Next T lines has an integer N in each line. It is guaranteed that N never starts with 0 unless value is equal to zero. Output : Print the output for each test case in new line. Constraints : 1 ≤ T ≤ 1000 0 ≤ |N| ≤ 1000 |N| is number of dig...
3
0
from sys import stdin tc = raw_input() def sod(x): if x == 1: return 2 elif x == 2 or x == 3 or x == 5 : return 5 elif x == 4 : return 4 elif x == 6 or x == 9: return 6 elif x == 7: return 3 elif x == 8: return 7 else: return 6 for i in stdin: ans = 0 for j in i: try: j = int(j) ans += s...
PYTHON
mystery-11
Solve the mystery HINT : Digital Display Input : First line has an integer T. Next T lines has an integer N in each line. It is guaranteed that N never starts with 0 unless value is equal to zero. Output : Print the output for each test case in new line. Constraints : 1 ≤ T ≤ 1000 0 ≤ |N| ≤ 1000 |N| is number of dig...
3
0
t=int(input()) while t>0: s=raw_input() n=0 for i in range(len(s)): if s[i]=='0': n=n+6 elif s[i]=='1': n=n+2 elif s[i]=='2': n=n+5 elif s[i]=='3': n=n+5 elif s[i]=='4': n=n+4 elif s[i]=='5': ...
PYTHON
mystery-11
Solve the mystery HINT : Digital Display Input : First line has an integer T. Next T lines has an integer N in each line. It is guaranteed that N never starts with 0 unless value is equal to zero. Output : Print the output for each test case in new line. Constraints : 1 ≤ T ≤ 1000 0 ≤ |N| ≤ 1000 |N| is number of dig...
3
0
d=[[1,2], [2,5], [3,5], [4,4], [5,5], [6,6], [7,3], [8,7], [9,6], [0,6]] d=dict(d) t=int(input()) for tc in range(t): n=str(input()) sum=0 for i in n: sum=sum+d[int(i)] print(sum)
PYTHON
mystery-11
Solve the mystery HINT : Digital Display Input : First line has an integer T. Next T lines has an integer N in each line. It is guaranteed that N never starts with 0 unless value is equal to zero. Output : Print the output for each test case in new line. Constraints : 1 ≤ T ≤ 1000 0 ≤ |N| ≤ 1000 |N| is number of dig...
3
0
t=input() n=[ '' for x in range(100)] for x in range(t): n=raw_input('') count=0 for a in xrange(0,len(n)): if n[a]=='1': count=count+2 elif n[a]=='2': count=count+5 elif n[a]=='3': count=count+5 elif n[a]=='4': count=count+4 elif n[a]=='5': count=count+5 elif n[a]=='6': count=count+6 ...
PYTHON
mystery-11
Solve the mystery HINT : Digital Display Input : First line has an integer T. Next T lines has an integer N in each line. It is guaranteed that N never starts with 0 unless value is equal to zero. Output : Print the output for each test case in new line. Constraints : 1 ≤ T ≤ 1000 0 ≤ |N| ≤ 1000 |N| is number of dig...
3
0
def solve(): a = [6,2,5,5,4,5,6,3,7,6] t = input() for tt in xrange(t): s = raw_input() res = 0 for i in s: res += a[(int(i))] print res solve()
PYTHON
mystery-11
Solve the mystery HINT : Digital Display Input : First line has an integer T. Next T lines has an integer N in each line. It is guaranteed that N never starts with 0 unless value is equal to zero. Output : Print the output for each test case in new line. Constraints : 1 ≤ T ≤ 1000 0 ≤ |N| ≤ 1000 |N| is number of dig...
3
0
arr=[6,2,5,5,4,5,6,3,7,6] for _ in range(input()): a=list(raw_input()) temp=0 for item in a: temp=temp+arr[int(item)] print temp
PYTHON
mystery-11
Solve the mystery HINT : Digital Display Input : First line has an integer T. Next T lines has an integer N in each line. It is guaranteed that N never starts with 0 unless value is equal to zero. Output : Print the output for each test case in new line. Constraints : 1 ≤ T ≤ 1000 0 ≤ |N| ≤ 1000 |N| is number of dig...
3
0
def mystery_prob(): a=[6,2,5,5,4,5,6,3,7,6] t=input() for tc in xrange(t): x=raw_input() ans=0 for m in x: ans=ans+a[(int(m))] print ans mystery_prob()
PYTHON
mystery-11
Solve the mystery HINT : Digital Display Input : First line has an integer T. Next T lines has an integer N in each line. It is guaranteed that N never starts with 0 unless value is equal to zero. Output : Print the output for each test case in new line. Constraints : 1 ≤ T ≤ 1000 0 ≤ |N| ≤ 1000 |N| is number of dig...
3
0
for t in range(input()): s=raw_input() i=0 l=len(s) count=0 while i<l: ch=s[i] if ch=='0': count=count+6 elif ch=='1': count=count+2 elif ch=='2': count=count+5 elif ch=='3': count=count+5 elif ch=='4': count=count+4 elif ch=='5': count=count+5 elif ch=='6': count=count+6 eli...
PYTHON
mystery-11
Solve the mystery HINT : Digital Display Input : First line has an integer T. Next T lines has an integer N in each line. It is guaranteed that N never starts with 0 unless value is equal to zero. Output : Print the output for each test case in new line. Constraints : 1 ≤ T ≤ 1000 0 ≤ |N| ≤ 1000 |N| is number of dig...
3
0
from sys import stdin a = '0123456789' b = [6,2,5,5,4,5,6,3,7,6] di = {} for i in xrange(10): di[a[i]] = b[i] t = int(stdin.readline()) for _ in xrange(t): a = stdin.readline().strip() ans = 0 for i in a: ans += di[i] print ans
PYTHON
primes-on-rails
The arrival times of N trains are given in the format hours : minutes : seconds. However for the sake of simplicity the time is considered only in seconds format i.e., 3600hours + 60minutes + seconds (Let's say this x). Now if x is a prime number, the halt for the train at the station is 5 minutes, if it's an odd numbe...
3
0
def primes(n): if n==2: return[2] elif n<2: return [] s=range(3,n+1,2) mroot=n**0.5 half=(n+1)/2 -1 i=0 m=3 while (m<=mroot): if s[i]: j=(m*m-3)/2 s[j]=0 while(j<half): s[j]=0 j+=m i+=1 m=2*i+3 return [2]+[x for x in s if x] p=set(primes(100000)) n=int(raw_input()) arr=[] dep=[] for i i...
PYTHON
primes-on-rails
The arrival times of N trains are given in the format hours : minutes : seconds. However for the sake of simplicity the time is considered only in seconds format i.e., 3600hours + 60minutes + seconds (Let's say this x). Now if x is a prime number, the halt for the train at the station is 5 minutes, if it's an odd numbe...
3
0
n=input() p=[1]*100000 p[0]=p[1]=0 for i in xrange(2,100000): if p[i]: for j in xrange(2*i,100000,i): p[j]=0 a=[] b=[] for i in xrange(n): h,m,s=map(int,raw_input().split()) t=3600*h+60*m+s a.append(t) if p[t]: b.append(t+5*60) elif t&1: b.append(t+3*60) else: b.append(t+2*60) a.sort() b.sort() ans=tm...
PYTHON
sauron-eye
Gandalf the Grey is in trouble as Saurons eye Rearrived in the middle world. Now he has to prepare for the war, But in order to defeat Sauron he has to know the power of saurons eye on the day in which he wants to attack. According to the Elves(Good Friends of Gandalf),Gandalf came to know that ...
3
0
import sys M = 10 ** 9 + 7 MAX_T = 10000 MAX_N = 10**12 _CUTOFF = 1536 cache = {} results = [] def do_calc(n): if n in cache: return cache[n] the_matrix = [3, 1, -1, 0] result = power(the_matrix, n)[1] if n not in cache: cache[n] = result return result def power(matrix, n): result = [1, 0, 0, ...
PYTHON
sauron-eye
Gandalf the Grey is in trouble as Saurons eye Rearrived in the middle world. Now he has to prepare for the war, But in order to defeat Sauron he has to know the power of saurons eye on the day in which he wants to attack. According to the Elves(Good Friends of Gandalf),Gandalf came to know that ...
3
0
MOD = 1000000007 def mat_mul(A, B): K = len(A) C=[[] for x in xrange(K)] for i in xrange(K): for j in xrange(K): s = 0 for k in xrange(K): s = (s + A[i][k] * B[k][j]) % MOD C[i].append(s) return C def mat_pow(A, p): if p == 1: ret...
PYTHON
sauron-eye
Gandalf the Grey is in trouble as Saurons eye Rearrived in the middle world. Now he has to prepare for the war, But in order to defeat Sauron he has to know the power of saurons eye on the day in which he wants to attack. According to the Elves(Good Friends of Gandalf),Gandalf came to know that ...
3
0
import sys M = 10 ** 9 + 7 MAX_T = 10000 MAX_N = 10**12 cache = {} def calc(n): if n in cache: return cache[n] the_matrix = [3, 1, -1, 0] result = power(the_matrix, n)[1] cache[n] = result return result def power(matrix, n): result = [1, 0, 0, 1] while (n != 0): if n % 2 != 0: res...
PYTHON
sauron-eye
Gandalf the Grey is in trouble as Saurons eye Rearrived in the middle world. Now he has to prepare for the war, But in order to defeat Sauron he has to know the power of saurons eye on the day in which he wants to attack. According to the Elves(Good Friends of Gandalf),Gandalf came to know that ...
3
0
import sys M = 10 ** 9 + 7 MAX_T = 10000 MAX_N = 10**12 _CUTOFF = 1536 cache = {} results = [] def do_calc(n): if n in cache: return cache[n] the_matrix = [3, 1, -1, 0] result = power(the_matrix, n)[1] if n not in cache: cache[n] = result return result def power(matrix, n): result = [1, 0, 0, ...
PYTHON
sauron-eye
Gandalf the Grey is in trouble as Saurons eye Rearrived in the middle world. Now he has to prepare for the war, But in order to defeat Sauron he has to know the power of saurons eye on the day in which he wants to attack. According to the Elves(Good Friends of Gandalf),Gandalf came to know that ...
3
0
from operator import mul mod=10**9 +7 def foo(n): while n<0: n += mod return n def matrixMul(a, b): x1 = foo((a[0][0] * b[0][0] + a[0][1] * b[1][0]) % mod) x2 = foo((a[0][0] * b[0][1] + a[0][1] * b[1][1]) % mod) x3 = foo((a[1][0] * b[0][0] + a[1][1] * b[1][0]) % mod) x4 = foo((a[1][0] * b[0][1] + a[...
PYTHON
swapping-game-6
Sherlock and Watson are playing swapping game. Watson gives to Sherlock a string S on which he has performed K swaps. You need to help Sherlock in finding the original string. One swap on a string is performed in this way: Assuming 1 indexing, the i'th letter from the end is inserted between i'th and (i+1)'th l...
3
0
k = int(raw_input()) s = raw_input() l = len(s) def swap(s): j = l - 1 while j: if not j % 2 == 0: e = s[j] s = s[:j] + s[j + 1:] + e j -= 1 return s c = s count = 0 itr = "" while itr != s: itr = swap(c) c = itr count += 1 count = k % count for i in range(count): s = swap(s) print s
PYTHON
swapping-game-6
Sherlock and Watson are playing swapping game. Watson gives to Sherlock a string S on which he has performed K swaps. You need to help Sherlock in finding the original string. One swap on a string is performed in this way: Assuming 1 indexing, the i'th letter from the end is inserted between i'th and (i+1)'th l...
3
0
def unswap(word, length): result = "" for i in range(length + 1): result += word[i] word = word[:i] + word[i + 1:] result += word[::-1] return result itercount = input() word = raw_input() length = (len(word) // 2) - (len(word) % 2 == 0) copy = word[:] i = 1 res = unswap(word, length) w...
PYTHON
swapping-game-6
Sherlock and Watson are playing swapping game. Watson gives to Sherlock a string S on which he has performed K swaps. You need to help Sherlock in finding the original string. One swap on a string is performed in this way: Assuming 1 indexing, the i'th letter from the end is inserted between i'th and (i+1)'th l...
3
0
k = int(raw_input()) s = raw_input() l = int(len(s)) if k == 50: print "myphtdvaravsqexwlkdk" elif k == 33892018: print"bwxqwwogalkjqrrarbqlrekfxoltkfkqwceofytbowocbgmxseopybwceyvwaugxcihflurbjwvptukutjnkgxuppvanidtssqsajoyrihcgfpqydqoifutrchmknfimrspadnsoaoubsbgdsxsfeokjuqkrdyaysuybncttrqxnlmouidvpkcemdafkfujgwtwbwu...
PYTHON
swapping-game-6
Sherlock and Watson are playing swapping game. Watson gives to Sherlock a string S on which he has performed K swaps. You need to help Sherlock in finding the original string. One swap on a string is performed in this way: Assuming 1 indexing, the i'th letter from the end is inserted between i'th and (i+1)'th l...
3
0
def inverted_swap(s): """ >>> inverted_swap('h') 'h' >>> inverted_swap('he') 'he' >>> inverted_swap('hpel') 'help' >>> inverted_swap('ctosnet') 'contest' """ len_s = len(s) if len_s % 2 == 0: return s[::2] + s[-1::-2] else: return s[::2] + s[-2::-2] ...
PYTHON
swapping-game-6
Sherlock and Watson are playing swapping game. Watson gives to Sherlock a string S on which he has performed K swaps. You need to help Sherlock in finding the original string. One swap on a string is performed in this way: Assuming 1 indexing, the i'th letter from the end is inserted between i'th and (i+1)'th l...
3
0
k=input() string = raw_input() str1 = list(string) part1 = [] part2 = [] length = len(str1) count = 1 while True: for i in range(0, length, 2): part1.append(str1[i]) if( i+1 < length): part2.append(str1[i+1]) str1 = part1 + part2[::-1] part1 =[] part2 = [] string1 = ''.join(str1) if string ...
PYTHON
swapping-game-6
Sherlock and Watson are playing swapping game. Watson gives to Sherlock a string S on which he has performed K swaps. You need to help Sherlock in finding the original string. One swap on a string is performed in this way: Assuming 1 indexing, the i'th letter from the end is inserted between i'th and (i+1)'th l...
3
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' def main(): k=int(input()) s=[] s.extend(str(raw_input())) temp=2 l=int(len(s)) if int(l%2)==0: ...
PYTHON
swapping-game-6
Sherlock and Watson are playing swapping game. Watson gives to Sherlock a string S on which he has performed K swaps. You need to help Sherlock in finding the original string. One swap on a string is performed in this way: Assuming 1 indexing, the i'th letter from the end is inserted between i'th and (i+1)'th l...
3
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' def calculate(st): snew="" in1 = 0 in2=len(st)-1 flag=True while flag: snew=snew+st[in1] snew=snew+st[in2] in1=in1+1 in2=in2-1 if in1>in2: break ...
PYTHON
swapping-game-6
Sherlock and Watson are playing swapping game. Watson gives to Sherlock a string S on which he has performed K swaps. You need to help Sherlock in finding the original string. One swap on a string is performed in this way: Assuming 1 indexing, the i'th letter from the end is inserted between i'th and (i+1)'th l...
3
0
n = int(raw_input()) s = raw_input() ar = s j = 0 length = len(s) new_ar = [s] sp = True while j < n: x,y = "","" i = 0 while i < length: if i%2 == 0: x = x + ar[i] else: y = y + ar[i] i = i + 1 ar = x + y[::-1] if ar in new_ar: print ne...
PYTHON
swapping-game-6
Sherlock and Watson are playing swapping game. Watson gives to Sherlock a string S on which he has performed K swaps. You need to help Sherlock in finding the original string. One swap on a string is performed in this way: Assuming 1 indexing, the i'th letter from the end is inserted between i'th and (i+1)'th l...
3
0
import sys k=input() s=sys.stdin.readline().strip() l=len(s) c=1 t="" es="" eo="" for i in xrange(0,l): if i%2==0: es=es+s[i] else: eo=s[i]+eo t=es+eo #print t while t!=s: es="" eo="" #print t for i in xrange(0,l): if i%2==0: es=es+t[i] e...
PYTHON
who-wants-to-be-a-millionaire-7
You are on a game show "Who Wants to Be a Millionaire".The host presents you "N" number of closed doors.There is huge prize behind one door while there are sumo wrestlers behind rest of the doors.Initially you are asked to choose a door.After that the host opens (N-2) doors,revealing sumo wrestlers.The host is omniscie...
3
0
for i in range(int(raw_input())): n=int(raw_input()) print ( '%.6f' %(float(n-1)/n))
PYTHON
who-wants-to-be-a-millionaire-7
You are on a game show "Who Wants to Be a Millionaire".The host presents you "N" number of closed doors.There is huge prize behind one door while there are sumo wrestlers behind rest of the doors.Initially you are asked to choose a door.After that the host opens (N-2) doors,revealing sumo wrestlers.The host is omniscie...
3
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' t = int(raw_input()) for i in range(0,t): n = float(raw_input()) p = (n-1) / n print '%f' % p
PYTHON
who-wants-to-be-a-millionaire-7
You are on a game show "Who Wants to Be a Millionaire".The host presents you "N" number of closed doors.There is huge prize behind one door while there are sumo wrestlers behind rest of the doors.Initially you are asked to choose a door.After that the host opens (N-2) doors,revealing sumo wrestlers.The host is omniscie...
3
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' for i in range(input()): n = float(raw_input()) p = (n-1) / n print '%f' % p
PYTHON
who-wants-to-be-a-millionaire-7
You are on a game show "Who Wants to Be a Millionaire".The host presents you "N" number of closed doors.There is huge prize behind one door while there are sumo wrestlers behind rest of the doors.Initially you are asked to choose a door.After that the host opens (N-2) doors,revealing sumo wrestlers.The host is omniscie...
3
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' t=input() while t>0: t-=1 n=input() n=float(n) a=1-1/n print "%.6f" %a
PYTHON
who-wants-to-be-a-millionaire-7
You are on a game show "Who Wants to Be a Millionaire".The host presents you "N" number of closed doors.There is huge prize behind one door while there are sumo wrestlers behind rest of the doors.Initially you are asked to choose a door.After that the host opens (N-2) doors,revealing sumo wrestlers.The host is omniscie...
3
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' t= input() for i in range(0,t): n= input() n= float(n) res= 1.0-(1.0/n) print "%.6f" %res
PYTHON
who-wants-to-be-a-millionaire-7
You are on a game show "Who Wants to Be a Millionaire".The host presents you "N" number of closed doors.There is huge prize behind one door while there are sumo wrestlers behind rest of the doors.Initially you are asked to choose a door.After that the host opens (N-2) doors,revealing sumo wrestlers.The host is omniscie...
3
0
t=int(raw_input()) while t: t-=1 n=int(raw_input()) n=float(n-1)/n print("%.6f" % n)
PYTHON
who-wants-to-be-a-millionaire-7
You are on a game show "Who Wants to Be a Millionaire".The host presents you "N" number of closed doors.There is huge prize behind one door while there are sumo wrestlers behind rest of the doors.Initially you are asked to choose a door.After that the host opens (N-2) doors,revealing sumo wrestlers.The host is omniscie...
3
0
t=int(raw_input()) while t!=0: n=int(raw_input()) m=(n-1.0)/n print("%.6f" % m) t-=1
PYTHON
who-wants-to-be-a-millionaire-7
You are on a game show "Who Wants to Be a Millionaire".The host presents you "N" number of closed doors.There is huge prize behind one door while there are sumo wrestlers behind rest of the doors.Initially you are asked to choose a door.After that the host opens (N-2) doors,revealing sumo wrestlers.The host is omniscie...
3
0
tc = int(raw_input()) for _ in range(tc): n = int(raw_input()) ans = 1.0*(n-1)/n print "%.6f" % ans
PYTHON
who-wants-to-be-a-millionaire-7
You are on a game show "Who Wants to Be a Millionaire".The host presents you "N" number of closed doors.There is huge prize behind one door while there are sumo wrestlers behind rest of the doors.Initially you are asked to choose a door.After that the host opens (N-2) doors,revealing sumo wrestlers.The host is omniscie...
3
0
for i in range(input()): n = int(raw_input()) m = float((n-1.0)/n) print "%0.6f" %m
PYTHON
who-wants-to-be-a-millionaire-7
You are on a game show "Who Wants to Be a Millionaire".The host presents you "N" number of closed doors.There is huge prize behind one door while there are sumo wrestlers behind rest of the doors.Initially you are asked to choose a door.After that the host opens (N-2) doors,revealing sumo wrestlers.The host is omniscie...
3
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' t = int(raw_input()) while t > 0: n = int(raw_input()) x = 1.0*( n - 1 ) / n print "%0.6f" %x t = t - 1
PYTHON
who-wants-to-be-a-millionaire-7
You are on a game show "Who Wants to Be a Millionaire".The host presents you "N" number of closed doors.There is huge prize behind one door while there are sumo wrestlers behind rest of the doors.Initially you are asked to choose a door.After that the host opens (N-2) doors,revealing sumo wrestlers.The host is omniscie...
3
0
for _ in xrange(input()): n=input() x=1.0*(n-1)/(n) print "%f"%x
PYTHON
who-wants-to-be-a-millionaire-7
You are on a game show "Who Wants to Be a Millionaire".The host presents you "N" number of closed doors.There is huge prize behind one door while there are sumo wrestlers behind rest of the doors.Initially you are asked to choose a door.After that the host opens (N-2) doors,revealing sumo wrestlers.The host is omniscie...
3
0
for _ in range(input()): x = float(input()) x = '{0:.6f}'.format(1/x) print '{0:.6f}'.format(1.0-float(x))
PYTHON
who-wants-to-be-a-millionaire-7
You are on a game show "Who Wants to Be a Millionaire".The host presents you "N" number of closed doors.There is huge prize behind one door while there are sumo wrestlers behind rest of the doors.Initially you are asked to choose a door.After that the host opens (N-2) doors,revealing sumo wrestlers.The host is omniscie...
3
0
for _ in xrange(input()): n=float(input()) a=(n-1)/n print "%.6f" % a
PYTHON
who-wants-to-be-a-millionaire-7
You are on a game show "Who Wants to Be a Millionaire".The host presents you "N" number of closed doors.There is huge prize behind one door while there are sumo wrestlers behind rest of the doors.Initially you are asked to choose a door.After that the host opens (N-2) doors,revealing sumo wrestlers.The host is omniscie...
3
0
t=int(raw_input()) for i in range(t): n=float(raw_input()) p=(n-2)/n + 1/n; print '%.6f'%p
PYTHON
who-wants-to-be-a-millionaire-7
You are on a game show "Who Wants to Be a Millionaire".The host presents you "N" number of closed doors.There is huge prize behind one door while there are sumo wrestlers behind rest of the doors.Initially you are asked to choose a door.After that the host opens (N-2) doors,revealing sumo wrestlers.The host is omniscie...
3
0
t=input() if t>=1 and t<=1000: for i in range(0,t): n=input() if n>=3 and n<=1000: print ( '%.6f' %(float(n-1)/n))
PYTHON
p02629 AtCoder Beginner Contest 171 - One Quadrillion and One Dalmatians
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 1 through 1000000000000001, but he gave them new names, as follows: * the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`; * the dogs numbered 27,28,29,\...
6
0
n = int(input()) s = '' while n > 0: n -= 1 s = chr(ord('a') + n % 26) + s n //= 26 print(s)
PYTHON3
p02629 AtCoder Beginner Contest 171 - One Quadrillion and One Dalmatians
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 1 through 1000000000000001, but he gave them new names, as follows: * the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`; * the dogs numbered 27,28,29,\...
6
0
N,a=int(input()),'' while 0<N:N-=1;a+=chr(ord('a')+N%26);N//=26 print(a[::-1])
PYTHON3
p02629 AtCoder Beginner Contest 171 - One Quadrillion and One Dalmatians
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 1 through 1000000000000001, but he gave them new names, as follows: * the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`; * the dogs numbered 27,28,29,\...
6
0
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); //System.out.println(n); String ans = ""; while(n>0){ n--; ans += (char)('a'...
JAVA
p02629 AtCoder Beginner Contest 171 - One Quadrillion and One Dalmatians
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 1 through 1000000000000001, but he gave them new names, as follows: * the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`; * the dogs numbered 27,28,29,\...
6
0
import java.lang.*; import java.io.*; import java.util.*; class Main { // Driver code public static String getAlpha(long num) { String result = ""; while (num > 0) { num--; // 1 => a, not 0 => a long remainder = num % 26; char digit = (char) (remainder + 97); result = digit + ...
JAVA
p02629 AtCoder Beginner Contest 171 - One Quadrillion and One Dalmatians
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 1 through 1000000000000001, but he gave them new names, as follows: * the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`; * the dogs numbered 27,28,29,\...
6
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); long n = Long.parseLong(scan.next()); scan.close(); StringBuilder sb = new StringBuilder(); while (n > 0) { long l = n % 26; ...
JAVA