Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
#include <bits/stdc++.h>
using namespace std;
#define int long long int
const int MOD = 1000000000 + 7;
int power(int x, int n)
{
int result = 1;
while (n) {
if (n%2!=0){
result = result * x % MOD;}
n = n / 2;
x = x * x % MOD;
}
return result;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while(t--){
int k,a,b;
cin>>k>>a>>b;
int m=abs(a-b)-1;
int n=k-m-2;
if(m==n){
cout<<0<<endl;
}
else{
cout<<min(m,n)<<endl;
}
}
return 0;
}
# cook your dish here
t = int(input())
for tc in range(t):
k,A,B=map(int,input().split())
c = abs(A-B) - 1
d = k - c - 2
s = k&1
if c+1==k//2 and ~s+2:
print(0)
else:
print(min(c,d))
#include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while( t>0 )
{
int k,a,b;
scanf("%d %d %d",&k,&a,&b);
if(b>a)
{
if( (b-a) == (k-b+a) )
{
printf("0\n");
}
else
{
printf("%d\n",((b-a) > (k-b+a))?(k-b+a-1):(b-a-1));
}
}
else
{
if( (a-b) == (k-a+b) )
{
printf("0\n");
}
else
{
printf("%d\n",((a-b) > (k-a+b))?(k-a+b-1):(a-b-1));
}
}
t--;
}
return 0;
}
/*
Solution of Codechef Problem - Real obtuse
Problem Code - OBTTRNGL
Link - https://www.codechef.com/problems/OBTTRNGL
*/
import java.util.*;
import java.io.*;
import java.lang.*;
class OBTTRNGL {
private static InputStream stream;
private static byte[] buf = new byte[1024];
private static int curChar;
private static int numChars;
private static SpaceCharFilter filter;
static BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws IOException {
InputReader(System.in);
int testCases = nI();
while(testCases-- > 0) {
long k = nL();
long a = nL();
long b = nL();
if(Math.abs(a - b) == 1 || (k % 2 == 0 && Math.abs(a - b) == k / 2)) {
log.write("0");
} else {
long x = Math.abs(a - b) - 1L;
long y = k - Math.max(a, b) + Math.min(a, b) - 1L;
if(x < y) {
log.write(String.valueOf(x));
} else {
log.write(String.valueOf(y));
}
}
log.write("\n");
log.flush();
}
}
public static void InputReader(InputStream stream1) {
stream = stream1;
}
private static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private static boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
private static int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
private static int nI() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
private static long nL() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
private static String nS() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
private static String nLi() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
private static boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
private interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
tc = int(input())
for _ in range(tc):
k,a,b=map(int,input().split())
if k%2==0 and abs(a-b) == k/2:
print(0)
else:
diff = abs(a-b)
count = min(diff-1,k-diff-1)
print(count)
t = int(raw_input())
for i in range(t):
st = raw_input().split()
k = int(st[0])
A = int(st[1])
B = int(st[2])
d = abs(A-B)
if d > k/2:
d = k-d
# endif
if (d == k/2) and (k%2 == 0):
r = 0
else:
r = d-1
# endif
print r
# endfor i
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LecTrans
{
class Program
{
static void Main(string[] args)
{
int n = Int32.Parse(Console.ReadLine());
while (n-- != 0)
{
string txt = Console.ReadLine();
string[] inp = txt.Split(' ');
long k = long.Parse(inp[0]);
long a = long.Parse(inp[1]);
long b = long.Parse(inp[2]);
//if (k < 6)
//{
// Console.WriteLine("0");
// continue;
//}
long min = Math.Min((k+a-b) % k, (k+b-a) % k);
if (min * 2 == k)
{
Console.WriteLine("0");
continue;
}
Console.WriteLine("{0}", (min - 1));
}
}
}
}
package main
import (
"fmt"
)
func main() {
t := 0
k := 0
a := 0
b := 0
n1 := 0
n2 := 0
c := 0
fmt.Scanf("%d", &t);
for t != 0 {
t--;
fmt.Scanf("%d%d%d", &k, &a, &b);
if k == 3 || k == 4 {
fmt.Printf("0\n");
continue;
}
if a > b {
c = a;
a = b;
b = c;
}
if a == 1 {
n1 = k - b;
} else {
n1 = k - b + a - 1;
}
n2 = b - a - 1;
if n1 == n2 {
fmt.Printf("0\n");
} else if n1 > n2 {
fmt.Printf("%d\n", n2);
} else {
fmt.Printf("%d\n", n1);
}
}
}
In our experience, we suggest you solve this Real obtuse CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the Real obtuse CodeChef Solution.
I hope this Real obtuse CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.
Keep Learning!