Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Sum this up CodeChef Solution

Problem -Sum this up CodeChef Solution

This website is dedicated for CodeChef solution where we will publish right solution of all your favourite CodeChef problems along with detailed explanatory of different competitive programming concepts and languages.

Sum this up CodeChef Solution in C++17

#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;

int main() {
	fastio
	int T, L;
	string S;
	cin >> T;
	while (T--) {
		cin >> L;
		ll total = 0, X;
		for (int i = 0; i < L; i++) {
			cin >> X;
			total += X;
		}
		cout << total / L << '\n';
	}
}

Sum this up CodeChef Solution in C++14

#include <bits/stdc++.h>
//for policy based ds //p.order_of_key() -> returns index of value //*p.find_by_order(3) ->value at index
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less

using namespace __gnu_pbds; //for policy based ds
using namespace std;

#define int long long
#define pii pair<int, int>
#define vi vector<int>
#define maxHeap priority_queue<int>;
#define minHeap priority_queue<int, vi, greater<int>>
#define mod 3046201
#define inf 1e18
#define rep(i, s, n) for (int i = s; i < n; i++)
#define sp(ans, pre) fixed << setprecision(pre) << y
#define pb push_back
#define srt(v) sort(v.begin(), v.end())
#define all(v) begin(v), end(v)
#define inputArr(i, arr) \
    for (int &i : arr)   \
        cin >> i;
#define ll long long
#define ull unsigned long long
#define lld long double
#define kickPrint(tt) cout << "Case #" << tt << ": "

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

time_t Begin;

//////////////////Debug///////////////
#define debug(x)       \
    cout << #x << " "; \
    _print(x);         \
    cout << endl;
void _print(ll t)
{
    cout << t;
}
//void _print(int t) {cout << t;}
void _print(string t) { cout << t; }
void _print(char t) { cout << t; }
void _print(lld t) { cout << t; }
void _print(double t) { cout << t; }
void _print(ull t) { cout << t; }
void display(ll a[], ll n)
{
    for (ll i = 0; i < n; i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;
}

template <class T, class V>
void _print(pair<T, V> p);
template <class T>
void _print(vector<T> v);
template <class T>
void _print(set<T> v);
template <class T, class V>
void _print(map<T, V> v);
template <class T>
void _print(multiset<T> v);
template <class T, class V>
void _print(pair<T, V> p)
{
    cout << "{";
    _print(p.ff);
    cout << ",";
    _print(p.ss);
    cout << "}";
}
template <class T>
void _print(vector<T> v)
{
    cout << "[ ";
    for (T i : v)
    {
        _print(i);
        cout << " ";
    }
    cout << "]";
}
template <class T>
void _print(set<T> v)
{
    cout << "[ ";
    for (T i : v)
    {
        _print(i);
        cout << " ";
    }
    cout << "]";
}
template <class T>
void _print(multiset<T> v)
{
    cout << "[ ";
    for (T i : v)
    {
        _print(i);
        cout << " ";
    }
    cout << "]";
}
template <class T, class V>
void _print(map<T, V> v)
{
    cout << "[ ";
    for (auto i : v)
    {
        _print(i);
        cout << " ";
    }
    cout << "]";
}
template <typename T, typename U>
inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }

void init()
{
    Begin = clock();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
void timeTaken()
{
#ifndef ONLINE_JUDGE
    double time_taken = double(clock() - Begin) / double(CLOCKS_PER_SEC);
    cout << "Execution Time: " << fixed << setprecision(5) << time_taken << "s\n";
#endif
}

vector<int> computeLps(string s, int M)
{
    int len = 0;
    vector<int> lps(M + 20);

    lps[0] = 0;

    int i = 1;
    while (i < M)
    {
        if (s[i] == s[len])
        {
            len++;
            lps[i] = len;
            i++;
        }
        else
        {
            if (len != 0)
            {
                len = lps[len - 1];
            }
            else
            {
                lps[i] = 0;
                i++;
            }
        }
    }
    // debug(len);
    return lps;
}

int ceiling(int x, int y)
{
    int res = x / y;
    if (x % y)
    {
        if (x >= 0)
            res++;
    }
    return res;
}

vector<vector<int>> makePrefix(vector<vector<int>> &grid)
{
    int n = grid.size(), m = grid[0].size();
    vector<vector<int>> prefix(n + 1, vector<int>(m + 1));

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            prefix[i + 1][j + 1] = grid[i][j] + prefix[i][j + 1] + prefix[i + 1][j] - prefix[i][j];
        }
    }

    return prefix;
}

int query(int x1, int y1, int x2, int y2, vector<vector<int>> &prefix)
{
    // cout << x1 << " " << y1 << " " << x2 << " " << y2 << endl;

    // cout << "query: " << prefix[x2 + 1][y2 + 1] << " " << prefix[x2 + 1][y1] << " " << prefix[x1][y2 + 1] << " " << prefix[x1][y2] << endl;
    return prefix[x2 + 1][y2 + 1] - prefix[x2 + 1][y1] - prefix[x1][y2 + 1] + prefix[x1][y1];
}

int toInt(string &s)
{
    int res = 0;
    for (char c : s)
        res = res * 10 + (c - '0');
    return res;
}

bool isValid(int i, int j, int n, int m)
{
    return i >= 0 && i < n && j >= 0 && j < m;
}

int dx[] = {-1, 0, 0, 1};
int dy[] = {0, 1, -1, 0};

int moduloExponentiation(int a, int b, int m)
{
    if (b == 0)
        return 1;

    int res = moduloExponentiation(a, b / 2, m);
    res = (res * res) % m;

    if (b % 2)
        res = (res * a) % m;
    return res;
}

class segmentTree
{
    vector<int> arr;
    vector<int> queryArr;

public:
    segmentTree(vector<int> &a)
    {
        arr = a;
        queryArr = vector<int>(a.size() * 4);
        build(0, 0, arr.size() - 1);
    }

    void build(int node, int low, int high)
    {
        if (low == high)
        {
            queryArr[node] = arr[low];
            return;
        }
        // cout << node << endl;
        int mid = low + (high - low) / 2;
        int leftChild = node * 2 + 1;
        int rightChild = node * 2 + 2;

        build(leftChild, low, mid);
        build(rightChild, mid + 1, high);
        queryArr[node] = (queryArr[leftChild] + queryArr[rightChild]);
    }

    void update(int node, int low, int high, int idx, int val)
    {
        if (low == high)
        {
            arr[idx] = val;
            queryArr[node] = val;
            return;
        }
        int mid = low + (high - low) / 2;
        if (low <= idx && idx <= mid)
            update(node * 2 + 1, low, mid, idx, val);
        else
            update(node * 2 + 2, mid + 1, high, idx, val);

        queryArr[node] = (queryArr[node * 2 + 1] + queryArr[node * 2 + 2]);
    }

    int query(int node, int low, int high, int left, int right)
    {
        if (right < low || left > high)
            return 0;

        if (left <= low && high <= right)
            return queryArr[node];

        int mid = low + (high - low) / 2;

        int leftRes = query(node * 2 + 1, low, mid, left, right);
        int rightRes = query(node * 2 + 2, mid + 1, high, left, right);

        return (leftRes + rightRes);
    }
};

vector<int> calcModInverse(int n, int m)
{
    vector<long long> modInverse(n + 1);
    modInverse[0] = 1;
    modInverse[1] = 1;
    for (long long i = 2; i <= n; i++)
        modInverse[i] = (m - ((m / i) * modInverse[m % i]) % m) % m;
    return modInverse;
}

vector<int> calcFac(int n)
{
    vector<int> fac(n + 1);
    fac[0] = 1;

    for (int i = 1; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % mod;

    return fac;
}

vector<int> calcFacModInverse(vector<int> modInverse, int n)
{
    vector<int> fac(n + 1);
    fac[0] = 0;

    for (int i = 1; i <= n; i++)
    {
        fac[i] = (fac[i - 1] * modInverse[i]) % mod;
    }

    return fac;
}

const int MX = 1e7 + 10;
// const int MX = 100000;
int32_t main()
{
    init();
    //--------------------
    int t = 1;
    cin >> t;
    for (int tt = 1; tt <= t; tt++)
    {
        int n;
        cin >> n;
        int sum = 0;
        for (int i = 0; i < n; i++)
        {
            int x;
            cin >> x;
            sum += x;
        }

        cout << sum / n << "\n";
    }
    //---------------------------
    timeTaken();
    return 0;
}

Sum this up CodeChef Solution in PYTH 3

i=input
for j in[0]*int(i()):i();*a,=map(int,i().split());print(sum(a)//len(a))

Sum this up CodeChef Solution in C

#include <stdio.h>

int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        long long int n,i;
        scanf("%lld",&n);
        long long int a[n+1],sum=0;
        for(i=0;i<n;i++){
            scanf("%lld",&a[i]);
            sum+=a[i];
        }
        printf("%d\n",sum/n);
    }
    return 0;
}

Sum this up 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 {
	public static void main (String[] args) throws java.lang.Exception {
		// your code goes here
		Scanner scanner = new Scanner(System.in);
		
		int test = Integer.parseInt(scanner.nextLine());
		
		while (test-- > 0) {
		    int length = Integer.parseInt(scanner.nextLine());
		    String[] input = scanner.nextLine().split(" ");
		    
		    long sum = 0; 
		    for (String number: input) {
		        sum += Long.parseLong(number);
		    }
		    
		    System.out.println(sum/input.length);
		    
		}
		
	}
}

Sum this up CodeChef Solution in PYPY 3

for _ in range(int(input())):
    n=int(input())
    print(sum(list(map(int,input().split())))//n)
    

Sum this up CodeChef Solution in GO

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		res := solve(A)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Println(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' {
			return s[:i]
		}
	}
	return s
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(A []int) int {
	var sum int64
	for _, num := range A {
		sum += int64(num)
	}

	return int(sum / int64(len(A)))
}
Sum this up CodeChef Solution Review:

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

Find on CodeChef

Conclusion:

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

More Coding Solutions >>

Cognitive Class Answer

CodeChef Solution

Microsoft Learn

Leave a Reply

Your email address will not be published. Required fields are marked *