Having already mastered cooking, Chef has now decided to learn how to play the guitar. Often while trying to play a song, Chef has to skip several strings to reach the string he has to pluck. Eg. he may have to pluck the 1st string and then the 6th string. This is easy in guitars with only 6 strings; However, Chef is playing a guitar with 106 strings. In order to simplify his task, Chef wants you to write a program that will tell him the total number of strings he has to skip while playing his favourite song.
This is how guitar strings are numbered (In ascending order from right to left). Eg. to switch from string 1 to 6, Chef would have to skip 4 strings (2,3,4,5).
*Input:
First line will contain T, number of testcases. Then the testcases follow.
The first line of each test case contains N, the number of times Chef has to pluck a string
The second line of each test case contains N space separated integers - S1, S2, …, SN, where Si is the number of the ith string Chef has to pluck.\
Output:*
For each testcase, output the total number of strings Chef has to skip over while playing his favourite song.
*Constraints
1≤T≤10
2≤N≤105
1≤Si≤106
For each valid i, Si≠Si+1
Subtasks
30 points : for each valid i, Si<Si+1
70 points : No additional constraints\
Sample Input:
2
6
1 6 11 6 10 11
4
1 3 5 7\
Sample Output:
15
3\
Explanation:\
Test Case 1*
Chef skips 4 strings (2,3,4,5) to move from 1 to 6
Chef skips 4 strings (7,8,9,10) to move from 6 to 11
Chef skips 4 strings (10,9,8,7) to move from 11 to 6
Chef skips 3 strings (7,8,9) to move from 6 to 10
Chef skips 0 strings to move from 10 to 11
Therefore, the answer is 4+4+4+3+0=15
*Test Case 2*
Chef skips 1 string to move from 1 to 3
Chef skips 1 string to move from 3 to 5
Chef skips 1 string to move from 5 to 7
Therefore, the answer is 1+1+1=3
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(1,n):
c+=abs(a[i]-a[i-1])-1
print(c)
15
Chef is playing a card game with his friend Morty Smith.
The rules of the game are as follows:
There are two piles of cards, pile A and pile B, each with N cards in it. Pile A belongs to Chef and pile B belongs to Morty.
Each card has one positive integer on it
The ‘power’ of a card is defined as the sum of digits of the integer on that card
The game consists of N rounds
In each round, both players simultaneously draw one card each from the top of their piles and the player who draws the card with higher power wins this round and gets a point. If the powers of both players' cards are equal then they get 1 point each.
The winner of the game is the player who has more points at the end of N rounds. If both players have equal number of points then the game ends in a draw.
The game is now over and Chef has told Morty to find the winner. Unfortunately, this task is too complex for him. Help Morty find the winner.
*Input:
First line will contain T, number of testcases.
The first line of each test case will contain N, the number of rounds played.
The ith of the next N lines of each test case will contain Ai and Bi, the number on the card drawn by Chef and Morty respectively in round i.\
Output:*
For each test case, output two space separated integers on a new line:
Output
0 if Chef wins,
1 if Morty wins,
2 if it is a draw,
followed by the number of points the winner had.
(If it is a draw then output either player’s points).
*Constraints
1≤T≤1000
1≤N≤100
1≤Ai,Bi≤109
Subtasks
100 points : No additional constraints\
Sample Input:
2
3
10 4
8 12
7 6
2
5 10
3 4\
Sample Output:
0 2
2 1\
Explanation:\
Test Case 1:*
*Round 1:*
Chef’s card has power 1+0 = 1,
Morty’s card has power 4.
Therefore, Morty wins the round.
*Round 2:*
Chef’s card has power 8,
Morty’s card has power 1+2 = 3.
Therefore, Chef wins the round.
*Round 3:*
Chef’s card has power 7,
Morty’s card has power 6.
Therefore, Chef wins the round.
Therefore, Chef wins the game with 2 points (Morty has 1 point).
*Test Case 2:*
*Round 1:*
Chef’s card has power 5,
Morty’s card has power 1+0=1.
Therefore, Chef wins the round.
*Round 2:*
Chef’s card has power 3,
Morty’s card has power 4.
Therefore, Morty wins the round.
Therefore, the game ends in a draw and both players have 1 point each.
def digit_sum(n):
sum_n=0
while n>0:
r=n%10
sum_n+=r
n//=10
return sum_n
digit_sum(324)
9
for _ in range(int(input())):
c1=0
c2=0
for i in range(int(input())):
n1,n2=input().split()
if digit_sum(int(n1))>digit_sum(int(n2)):
c1+=1
elif digit_sum(int(n1))<digit_sum(int(n2)):
c2+=1
else:
c1+=1
c2+=1
if c1>c2:
print('0',c1)
elif c1<c2:
print('1',c2)
else:
print('2',c1)
0 2
2 1
for _ in range(int(input())):
n=int(input())
l1=[]
l2=[]
for i in range(4*n-1):
n1,n2=input().split()
if n1 in l1:
l1.remove(n1)
else:
l1.append(n1)
if n2 in l2:
l2.remove(n2)
else:
l2.append(n2)
print(l1[0],l2[0])
2 2
from functools import reduce
for _ in range(int(input())):
n=int(input())
l1=[]
l2=[]
for i in range(4*n-1):
m,n=map(int,input().split())
l1.append(m)
l2.append(n)
print(reduce(lambda x, y: x ^ y,l1),reduce(lambda x, y: x ^ y,l2))
2 2
for _ in range(int(input())):
n1,n2=map(int,input().split())
a=list(map(int,input().split()))
c=len(a)
m=max(a)
if (m-n2)>0:
m-=n2
n2*=2
while m>0:
c+=1
print(m)
if (m-n2)>0:
m-=n2
n2*=2
else:
break
print(c)
else:
print(c)
49 47 43 35 19 10
c
10