In this HackerRank Save the Prisoner! problem A jail has a number of prisoners and a number of treats to pass out to them. Their jailer decides the fairest way to divide the treats is to seat the prisoners around a circular table in sequentially numbered chairs. A chair number will be drawn from a hat. Beginning with the prisoner in that chair, one candy will be handed to each prisoner sequentially around the table until all have been distributed.

The jailer is playing a little joke, though. The last piece of candy looks like all the others, but it tastes awful. Determine the chair number occupied by the prisoner who will receive that candy.

## Problem solution in Python programming.

```t = int(input())
for _ in range(t):
parts = list(map(int, input().split(' ')))
# print('parts', parts)
print((parts + parts - 2) % parts + 1)```

## Problem solution in Java Programming.

```import java.io.*;
import java.util.*;

public class Solution {

public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner scan = new Scanner(System.in);
int c = Integer.parseInt(scan.nextLine());
for(int i=0;i<c;i++){
String[] sp = scan.nextLine().split("\\s+");
int N = Integer.parseInt(sp);
int M = Integer.parseInt(sp);
int S = Integer.parseInt(sp);
int next = M+S;
next=(next-1)%N;
if(next == 0)next = N;
System.out.println(next);
}
}
}```

### Problem solution in C++ programming.

```#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <cmath>

typedef long long ll;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forv(i, v) forn(i, v.size())

using namespace std;

void solve() {
int n, m, s;
cin >> n >> m >> s;
cout << 1 + (s - 1 + m - 1) % n << endl;
}

int main() {
#ifdef NEREVAR_PROJECT
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int tc;
cin >> tc;
forn(it, tc) solve();
return 0;
}```

### Problem solution in C programming.

```#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {

/* Enter your code here. Read input from STDIN. Print output to STDOUT */
long int t,n,m,s,tot;
scanf("%ld",&t);
while(t--)
{
scanf("%ld %ld %ld",&n,&m,&s);
tot=m+s-1;
if(tot%n==0)
printf("%ld\n",n);
else printf("%ld\n",tot%n);
}

return 0;
}```

### Problem solution in JavaScript programming.

```function processData(input) {
var a = input.split("\n");
var n = a.shift();

for(var i = 0; i < n; i++) {
var b = a[i].split(" ");

var prisoners = parseInt(b);
var sweets = parseInt(b);
var id = parseInt(b);
var last = 0;

last = (sweets+id-1)%prisoners;

if(last === 0) {
last = prisoners;
}

console.log(last);
}
}

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
_input += input;
});

process.stdin.on("end", function () {
processData(_input);
});```