304 North Cardinal St.
Dorchester Center, MA 02124

# SnackUp CodeChef Solution

## SnackUp CodeChef Solution in C++14

``````#include <iostream>
#define ll long long int
using namespace std;

int main()
{ ll t; cin >> t;
// seive();
while (t--) {

ll n; cin >> n;
cout<<n<<endl;
for (ll j = 0; j <n; j++)
{

cout<<n<<endl;
for (ll i = 0; i < n; i++)
{
cout<<i+1<<" "<<((i+j)%n)+1<<" "<<((i+j+1)%n)+1<<endl;
}

}

}
return 0;}``````

## SnackUp CodeChef Solution in PYTH 3

``````def soln(n):
arr = [(i, i+1) for i in range(1, n)]
arr.append((1, n))
print(n)
for i in range(n):
print(n)
for j in range(n):
print(j+1, *arr[(i+j)%n])

for _ in range(int(input())):
n = int(input())
soln(n)``````

## SnackUp CodeChef Solution in C

``````#include <stdio.h>

int main(void) {
int i,t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
printf("%d\n",n);
for(i=1;i<=n;i++){
printf("%d\n",n);
for(int j=1;j<=n;j++){
int x=j+i-1 , y=j+i;
if(x>n && x%n!=0)
{
x=x%n;
}
else if(x%n==0){
x=n;
}
if(y>n && y%n!=0){
y=y%n;
}
else if(y%n==0){
y=n;
}
printf("%d %d %d\n",j,x,y);
}
}
}
return 0;
}
``````

## SnackUp CodeChef Solution in JAVA

``````/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
StringTokenizer st;
}
String next(){
while(st==null || !st.hasMoreTokens()){
try {
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str="";
try {
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
static class FastWriter {
private final BufferedWriter bw;

public FastWriter() {
this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
}

public void print(Object object) throws IOException {
bw.append("" + object);
}

public void println(Object object) throws IOException {
print(object);
bw.append("\n");
}

public void close() throws IOException {
bw.close();
}
}
public static void main (String[] args) throws java.lang.Exception
{
FastWriter out = new FastWriter();
int T=in.nextInt();
while(T--!=0){
int N=in.nextInt();
out.println(N);
int c=0;
for(int i=1;i<=N;i++){
out.println(N);
int initial=1+c;
for(int j=1;j<=N;j++){
int next=initial+1;
if(next==N+1)
next=1;
out.println(j+" "+initial+" "+next);
initial=next;
}
c++;
}
}
out.close();
}
}
``````

## SnackUp CodeChef Solution in PYPY 3

``````import collections

def solve():
n=int(input())
q=collections.deque()
for i in range(n):
q.append((i+1,(i+1)%n +1))
print(n)
for _ in range(n):
print(n)
for i, (x,y) in enumerate(q,start=1):
print(i,x,y)
q.append(q.popleft())
for _ in range(int(input())):
solve()``````

## SnackUp CodeChef Solution in PYTH

``````t = int(raw_input())
for i in range(t):
N = int(raw_input())
print N
for k in range(N):
print N
for j in range(N):
p = (j+k)%N
q = (p+1)%N
print j+1, p+1, q+1
# endfor j
# endfor k
# endfor i
``````

## SnackUp CodeChef Solution in C#

``````using System;
using System.Text;

public class Test
{
{
}

{
}

public static void Main()
{
checked
{
StringBuilder sb = new StringBuilder();
for (int test = 0; test < testsCount; test++)
{
var n = int.Parse(str);

if (n % 2 == 0)
{
sb.AppendLine((n * n / 2).ToString());
for (int i = 0; i < n; i+=2)
{
for (int j = 0; j < n; j+=2)
{
for (int k = 0; k < 2; k++)
{
sb.AppendLine(2.ToString());
sb.AppendLine(\$"{j + 1} {i + 1} {i + 2}");
sb.AppendLine(\$"{j + 2} {i + 1} {i + 2}");
}
}
}
}
else
{
sb.AppendLine((1 + (n * n - n) / 2).ToString());

int[][] row = new int[n][];
for (int i = 0; i < n; i++)
{
row[i] = new[] {i, (i + 1) % n};
}
int[][][] pairs = new int[n][][];
for (int i = 0; i < n; i++)
{
pairs[i] = row;
}

sb.AppendLine(n.ToString());
for (int i = 0; i < n; i++)
{
sb.AppendLine(\$"{i + 1} {pairs[i][i][0] + 1} {pairs[i][i][1] + 1}");
}

for (int c = 0; c < n; c++)
{
int r0 = 0;
int r1 = 1;
while (r1 < n && r0 < n)
{
if (r1 == c)
{
r1++;
continue;
}

if (r0 == c)
{
r0++;
r1 = r0 + 1;
continue;
}

sb.AppendLine(2.ToString());
sb.AppendLine(\$"{r0 + 1} {pairs[r0][c][0] + 1} {pairs[r0][c][1] + 1}");
sb.AppendLine(\$"{r1 + 1} {pairs[r0][c][0] + 1} {pairs[r0][c][1] + 1}");

r0 = r1 + 1;
r1 = r0 + 1;
}
}

}
}
Console.WriteLine(sb.ToString());
}
}
}``````

## SnackUp CodeChef Solution in GO

``````package main

import (
"bufio"
"fmt"
"os"
)

var out = bufio.NewWriter(os.Stdout)

func main() {
defer out.Flush()
var t int
for fmt.Scan(&t); t > 0; t-- {
solve()
}
}

func solve() {
var n int
fmt.Scan(&n)
fmt.Fprintln(out, n)
for i := 0; i < n; i++ {
fmt.Fprintln(out, n)
for j := 0; j < n; j++ {
fmt.Fprintln(out, j+1, (j+i)%n+1, (j+i+1)%n+1)
}
}
}``````
##### SnackUp CodeChef Solution Review:

In our experience, we suggest you solve this SnackUp 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 SnackUp CodeChef Solution.

Find on CodeChef

##### Conclusion:

I hope this SnackUp 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!