304 North Cardinal St.
Dorchester Center, MA 02124

# Chef and Strange Operations CodeChef Solution

## Chef and Strange Operations CodeChef Solution in C++17

``````#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 500009
#define mod 1000000007
#define vec array<ll,3>
long long binpow(long long a, long long b,ll modd) {
a %= modd;
if(a==0)
return 0;
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a % modd;
a = a * a % modd;
b >>= 1;
}
return res;
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
int test_case=1;

cin>>test_case;
for(int cs=1;cs<=test_case;cs++)
{
ll n,x,m;
cin>>n>>x>>m;
std::vector<ll> v(n+1);
for(int i=1;i<=n;i++)
{
cin>>v[i];
v[i]%=mod;
}
ll lst=1;
ll ans=v[x]%mod;
ll hor=m%mod,lov=1;

for(int i=x-1;i>=1;i--)
{
lst=(lst*hor)%(mod);
ll a1=binpow(lov,mod-2,mod);
lst=(lst*a1)%(mod);
//cout<<lst<<"\n";
ans+=(v[i]*lst);
hor++;
hor%=mod;
lov++;
ans%=mod;
}
cout<<ans<<"\n";
}

return 0;
}``````

## Chef and Strange Operations CodeChef Solution in C++14

``````#include <bits/stdc++.h>

#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("Ofast")//Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

using namespace std;

struct PairHash {inline std::size_t operator()(const std::pair<int, int> &v) const { return v.first * 31 + v.second; }};

// speed
#define Code ios_base::sync_with_stdio(false);
#define By ios::sync_with_stdio(0);
#define Sumfi cout.tie(NULL);

// alias
using ll = long long;
using ld = long double;
using ull = unsigned long long;

// constants
const ld PI = 3.14159265358979323846;  /* pi */
const ll INF = 1e18;
const ld EPS = 1e-9;
const ll MAX_N = 3030303;
const ll mod = 1e9 + 7;

// typedef
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef array<ll,3> all3;
typedef array<ll,5> all5;
typedef vector<all3> vall3;
typedef vector<all5> vall5;
typedef vector<ld> vld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef deque<ll> dqll;
typedef deque<pll> dqpll;
typedef pair<string, string> pss;
typedef vector<pss> vpss;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef unordered_set<ll> usll;
typedef unordered_set<pll, PairHash> uspll;
typedef unordered_map<ll, ll> umll;
typedef unordered_map<pll, ll, PairHash> umpll;

// macros
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,m,n) for(ll i=n;i>=m;i--)
#define all(a) begin(a), end(a)
#define rall(a) rbegin(a), rend(a)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define INF(a) memset(a,0x3f3f3f3f3f3f3f3fLL,sizeof(a))
#define ASCEND(a) iota(all(a),0)
#define sz(x) ll((x).size())
#define BIT(a,i) (a & (1ll<<i))
#define BITSHIFT(a,i,n) (((a<<i) & ((1ll<<n) - 1)) | (a>>(n-i)))
#define pyes cout<<"YES\n";
#define pno cout<<"NO\n";
#define endl "\n"
#define pneg1 cout<<"-1\n";
#define ppossible cout<<"Possible\n";
#define pimpossible cout<<"Impossible\n";
#define TC(x) cout<<"Case #"<<x<<": ";
#define X first
#define Y second

// utility functions
template <typename T>
void print(T &&t)  { cout << t << "\n"; }
template<typename T>
void printv(vector<T>v){ll n=v.size();rep(i,0,n){cout<<v[i];if(i+1!=n)cout<<' ';}cout<<endl;}
template<typename T>
void printvln(vector<T>v){ll n=v.size();rep(i,0,n)cout<<v[i]<<endl;}
void fileIO(string in = "input.txt", string out = "output.txt") {freopen(in.c_str(),"r",stdin); freopen(out.c_str(),"w",stdout);}
template<typename T>
template<typename T, typename U>
template<typename T, typename U>

struct Combination {
vll fac, inv;
ll n, MOD;

ll modpow(ll n, ll x, ll MOD = mod) { if(!x) return 1; ll res = modpow(n,x>>1,MOD); res = (res * res) % MOD; if(x&1) res = (res * n) % MOD; return res; }

Combination(ll _n, ll MOD = mod): n(_n + 1), MOD(MOD) {
inv = fac = vll(n,1);
rep(i,1,n) fac[i] = fac[i-1] * i % MOD;
inv[n - 1] = modpow(fac[n - 1], MOD - 2, MOD);
rrep(i,1,n - 2) inv[i] = inv[i + 1] * (i + 1) % MOD;
}

ll fact(ll n) {return fac[n];}
ll nCr(ll n, ll r) {
if(n < r or n < 0 or r < 0) return 0;
return fac[n] * inv[r] % MOD * inv[n-r] % MOD;
}
};

struct Matrix {
ll r,c;
vvll matrix;
Matrix(ll r, ll c, ll v = 0): r(r), c(c), matrix(vvll(r,vll(c,v))) {}

Matrix operator*(const Matrix& B) const {
Matrix res(r, B.c);
rep(i,0,r) rep(j,0,B.c) rep(k,0,B.r) {
res.matrix[i][j] = (res.matrix[i][j] + matrix[i][k] * B.matrix[k][j] % mod) % mod;
}
return res;
}

Matrix copy() {
Matrix copy(r,c);
copy.matrix = matrix;
return copy;
}

Matrix pow(ll n) {
assert(r == c);
Matrix res(r,r);
Matrix now = copy();
rep(i,0,r) res.matrix[i][i] = 1;
while(n) {
if(n & 1) res = res * now;
now = now * now;
n /= 2;
}
return res;
}
};

// geometry data structures
template <typename T>
struct Point {
T y,x;
Point(T y, T x) : y(y), x(x) {}
Point(pair<T,T> p) : y(p.first), x(p.second) {}
Point() {}
void input() {cin>>y>>x;}
friend ostream& operator<<(ostream& os, const Point<T>& p) { os<<p.y<<' '<<p.x<<'\n'; return os;}
Point<T> operator+(Point<T>& p) {return Point<T>(y + p.y, x + p.x);}
Point<T> operator-(Point<T>& p) {return Point<T>(y - p.y, x - p.x);}
Point<T> operator*(ll n) {return Point<T>(y*n,x*n); }
Point<T> operator/(ll n) {return Point<T>(y/n,x/n); }
bool operator<(const Point &other) const {if (x == other.x) return y < other.y;return x < other.x;}
Point<T> rotate(Point<T> center, ld angle) {
ld si = sin(angle * PI / 180.), co = cos(angle * PI / 180.);
ld y = this->y - center.y;
ld x = this->x - center.x;

return Point<T>(y * co - x * si + center.y, y * si + x * co + center.x);
}
ld distance(Point<T> other) {
T dy = abs(this->y - other.y);
T dx = abs(this->x - other.x);
return sqrt(dy * dy + dx * dx);
}

T norm() { return x * x + y * y; }
};

template<typename T>
struct Line {
Point<T> A, B;
Line(Point<T> A, Point<T> B) : A(A), B(B) {}
Line() {}

void input() {
A = Point<T>();
B = Point<T>();
A.input();
B.input();
}

T ccw(Point<T> &a, Point<T> &b, Point<T> &c) {
T res = a.x * b.y + b.x * c.y + c.x * a.y;
res -= (a.x * c.y + b.x * a.y + c.x * b.y);
return res;
}

bool isIntersect(Line<T> o) {
T p1p2 = ccw(A,B,o.A) * ccw(A,B,o.B);
T p3p4 = ccw(o.A,o.B,A) * ccw(o.A,o.B,B);
if (p1p2 == 0 && p3p4 == 0) {
pair<T,T> p1(A.y, A.x), p2(B.y,B.x), p3(o.A.y, o.A.x), p4(o.B.y, o.B.x);
if (p1 > p2) swap(p2, p1);
if (p3 > p4) swap(p3, p4);
return p3 <= p2 && p1 <= p4;
}
return p1p2 <= 0 && p3p4 <= 0;
}

pair<bool,Point<ld>> intersection(Line<T> o) {
if(!this->intersection(o)) return {false, {}};
ld det = 1. * (o.B.y-o.A.y)*(B.x-A.x) - 1.*(o.B.x-o.A.x)*(B.y-A.y);
ld t = ((o.B.x-o.A.x)*(A.y-o.A.y) - (o.B.y-o.A.y)*(A.x-o.A.x)) / det;
return {true, {A.y + 1. * t * (B.y - A.y), B.x + 1. * t * (B.x - A.x)}};
}

//@formula for : y = ax + b
//@return {a,b};
pair<ld, ld> formula() {
T y1 = A.y, y2 = B.y;
T x1 = A.x, x2 = B.x;
if(y1 == y2) return {1e9, 0};
if(x1 == x2) return {0, 1e9};
ld a = 1. * (y2 - y1) / (x2 - x1);
ld b = -x1 * a + y1;
return {a, b};
}
};

template<typename T>
struct Circle {
Point<T> center;
Circle() {}

void input() {
center = Point<T>();
center.input();
}

bool circumference(Point<T> p) {
return (center.x - p.x) * (center.x - p.x) + (center.y - p.y) * (center.y - p.y) == radius * radius;
}

bool intersect(Circle<T> c) {
T d = (center.x - c.center.x) * (center.x - c.center.x) + (center.y - c.center.y) * (center.y - c.center.y);
}

bool include(Circle<T> c) {
T d = (center.x - c.center.x) * (center.x - c.center.x) + (center.y - c.center.y) * (center.y - c.center.y);
}
};

ll __gcd(ll x, ll y) { return !y ? x : __gcd(y, x % y); }
all3 __exgcd(ll x, ll y) { if(!y) return {x,1,0}; auto [g,x1,y1] = __exgcd(y, x % y); return {g, y1, x1 - (x/y) * y1}; }
ll __lcm(ll x, ll y) { return x / __gcd(x,y) * y; }
ll modpow(ll n, ll x, ll MOD = mod) { n%=MOD; if(!x) return 1; ll res = modpow(n,x>>1,MOD); res = (res * res) % MOD; if(x&1) res = (res * n) % MOD; return res; }

ll solve(vll A, ll x, ll m) {
m %= mod;
ll res = 0, po = 1, p = 0;
rrep(i,0,x-1) {
res = (res + A[i] % mod * po % mod) % mod;
po = po * (m + p) % mod * modpow(p + 1, mod - 2) % mod;
p = p + 1;
}
return res;
}
int main() {
Code By Sumfi
cout.precision(12);
ll tc = 1;
cin>>tc;
rep(i,1,tc+1) {
ll n,m,x;
cin>>n>>x>>m;
vll A(n);
print(solve(A,x,m));
}
return 0;
}``````

## Chef and Strange Operations CodeChef Solution in PYTH 3

``````# cook your dish here
p = 10 ** 9 + 7
f = [0] * (10 ** 5 + 1)
f[0] = f[1] = 1
for z in range(2, 10 ** 5 + 1):
f[z] = (z * f[z - 1]) % p

t = int(input())

for i in range(t):
n, x, m = map(int, input().split())
a = list(map(int, input().split()))
c = [1] * (x)
ans = 0
j = 0
m %= p
for y in range(1, x):
c[y] = ((c[y - 1] * (m + (y - 1)) * f[y - 1]) * pow(f[y], p - 2, p)) % p
for u in range(x - 1, -1, -1):
ans = (ans + (c[u] * a[j])) % p
j += 1
print(ans % p)    ``````

## Chef and Strange Operations CodeChef Solution in C

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

typedef unsigned int uint;
typedef long long int lint;
typedef unsigned long long int ulint;

typedef void * T;
typedef const void * FT;
typedef char * pchar;
typedef int * pint;
typedef lint * plint;
typedef double * pdouble;

#define cast(a, type) (type)(a)
#define pcast(a, type) (type *)(a)
#define pvcast(a, type) *(pcast(a, type))

#define c_int(a) cast(a, int)
#define c_lint(a) cast(a, lint)
#define c_double(a) cast(a, double)

#define pc_int(a) pcast(a, int)
#define pc_lint(a) pcast(a, lint)
#define pc_double(a) pcast(a, double)

#define pvc_int(a) pvcast(a, int)
#define pvc_lint(a) pvcast(a, lint)
#define pvc_double(a) pvcast(a, double)

lint gcd(lint a, lint b) {
while(b != 0) {
lint c = (a % b);
a = b;
b = c;
}
return a;
}

lint modPow(lint a, lint p, lint m) {
if(p == 0) return (1%m);
lint t = modPow(a, p/2, m);
t = (t * t) % m;
if(p&1) return (t * a) % m;
return t;
}

lint modInv(lint a, lint m) {
/* m must be a prime */
return modPow(a, m-2, m);
}

#define N 100000
#define M 1000000007

lint a[N+10];

int main() {
int cc, tc;
scanf("%d", &tc);
for(cc=0; cc<tc; cc++) {
int n, x;
lint m;
scanf("%d %d %lld", &n, &x, &m);

int i;
for(i=1; i<=n; i++) scanf("%lld", &a[i]);

lint ans = a[x] % M;
lint u = 1;
lint d = 1;
for(i=1; i<x; i++) {
u = (u * ((m+i-1) % M)) % M;
d = (d * i) % M;
lint t = ((u * modInv(d, M)) % M) * (a[x-i] % M);
ans = (ans + (t % M)) % M;
}

printf("%lld\n", ans);
}

return 0;
}``````

## Chef and Strange Operations CodeChef Solution in JAVA

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

import java.io.PrintWriter;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;
import java.text.DecimalFormat;
class Main
{
static class Patient implements Comparable<Patient> {
int pos;
int illness;
Patient(int pos,int illness) {
this.pos=pos;
this.illness=illness;
}
@Override
public int compareTo(Patient p) {
return p.illness-this.illness;
}
}
/*
class Pair
{
int f,s;
Pair( int f, int s)
{
this.f=f;
this.s=s;
}
}*/
static class Dish{

int id;
int time;

Dish(int a, int b){
this.id = a;
this.time = b;
}
}

static class compare implements Comparator<Dish>{
public int compare(Dish a, Dish b){
if(a.time!=b.time)return a.time - b.time;
else return a.id - b.id;
}
}

static class Pair {
char prefix;
int suffixId;
Pair(char prefix, int suffixId) {
this.prefix = prefix;
this.suffixId = suffixId;
}

@Override
public int hashCode() {
final int prime = 199;
int hash = 0;
hash = prime * prefix + hash;
hash = prime * suffixId + hash;
return hash;
}

@Override
public boolean equals(Object obj) {
if(obj instanceof Pair) {
Pair p2 = (Pair) obj;
return this.prefix == p2.prefix && this.suffixId == p2.suffixId;
}
return false;
}
}
static class Circle{
long x;
long y;
long r;

public Circle(long x, long y, long r) {
this.x = x;
this.y = y;
this.r = r;
}
}

static class Distance{
long shortest;
long largest;

}
/*static class pair implements Comparable<pair>
{
long x;
int y;
pair(long x,int y)
{
this.x=x;
this.y=y;
}
public int compareTo(pair o)
{
return (int)(x-o.x);
}

}
static	class Pair
{
long x,y;
Pair(long x, long y)
{
this.x = x;
this.y = y;
}
}
static class PairComparator implements Comparator<Pair>
{
public long compare(Pair a, Pair b)
{
//if(a.x==b.x)
return a.y-b.y;
//	return a.x-b.x;
}
}
static class Point {
public double x, y;

private static final int MAX = (int) 1e6 + 1;

public Point(double x, double y) {
this.x = x;
this.y = y;
}

public int hashCode() {
return (int)x * MAX + (int)y;
}

public boolean equals(Object ob) {
if(ob instanceof Point) {
Point other = (Point) ob;
return other.x == x && other.y == y;
}

return false;
}

public String toString() {
return "(" + x + ", " + y + ")";
}
}*/
static int days4=0;
static int all;
static long phi[]=new long[1000001];
static long ans[]=new long[1000001];
//static int tree[],sum[];
//public static long mod = 1000000007;	public static long [][] tempMatrix;
public static long max = (long) Math.pow(10, 9) + 7;
static StringBuilder res = new StringBuilder();
//static Node tree[];
//static int a[];
//	static long mod = 998244353;
public static int rootColor=0;
static int MX = (1<<18);
//	 static boolean primes[]=new boolean[10000001];

static double pi = 3.1415926535;
private static final int MAXN = 5000;
private static final int MOD = 1000_000_007;
//   private static Modular modular_nCr = new Modular(MOD);
//  private static Modular modular = new Modular(MOD);
private static final long[][] nCr = new long[MAXN+5][MAXN+5];
//  static int[] maxval = new int[1000000];
//   static int[] minval = new int[1000000];
//  private static long bruteAns = 1;
//   static double eps = 1e-7;
static {
nCr[0][0]=1;
for(int i=0;i<=MAXN;i++)
nCr[i][0]=1;
for(int i=1;i<=MAXN;i++){
for(int j=1;j<=i;j++){
nCr[i][j]=(nCr[i-1][j-1]+nCr[i-1][j])%MOD;
}
}
}

/*    static { nCr[0][0] = 1;
for (int i = 1; i < MAXN; i++) {
nCr[i][0] = 1;
for (int j = 1; j <= i; j++) {
nCr[i][j] = modular_nCr.add(nCr[i - 1][j - 1], nCr[i - 1][j]);
} }
}*/

static int arr[] , dp[][][];
//		static int n ;
static int final_sum=0;
static int mod=1000000007;
static ArrayList<Integer> graph[];
static boolean vis[];
static int seive[]=new int[1000001];
static int primes[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
static int[] calcPower() {
int[] arr = new int[26];
for (int i = 0; i < 26; i++) {
arr[i] = (int) Math.pow(2, i);
}
return arr;
}
// static int p[] = new int[1000001], size[] = new int[1000001], n, m;
static int bits=32;
static class Trie
{
Trie tree[]=new Trie[2];
int val=0;
public Trie()
{
val=0;
tree[0]=null;tree[1]=null;
}
}
static Trie root;
static void insert(int xor)
{
Trie temp=root;
for(int i=bits-1;i>=0;i--)
{
int v = (xor & (1<<i)) >=1 ? 1 : 0;
if(temp.tree[v]==null)
temp.tree[v]=new Trie();
temp=temp.tree[v];
}
temp.val=xor;
}
static int query(int xor)
{
Trie temp=root;
for(int i=bits-1;i>=0;i--)
{
int v = (xor & (1<<i)) >=1 ? 1 : 0;
if(temp.tree[1-v]!=null)
temp=temp.tree[1-v];
else if(temp.tree[v]!=null)
temp=temp.tree[v];
}
return xor^temp.val;
}
public static int getBit(int n, int pos) {
return (n & (1 << pos)) == 0 ? 0 : 1;
}
private static int n, m, ci, cj;
private static char[][] g;
private static boolean[][] vs;
private static int[] v = new int[]{-1, 0, 1, 0};
private static int[] h = new int[]{0, 1, 0, -1};
private static char[] d = new char[]{'U', 'R', 'D', 'L'};

private static boolean v(int i, int j) {
return (i >= 0 && i < n && j >= 0 && j < m);
}

private static boolean pr(int i, int j) {
return g[i][j] == '*';
}
private static double dh, dl, dr, k;
public static void main (String[] args) throws java.lang.Exception
{
PrintWriter pw=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
StringBuilder sb = new StringBuilder();
FastScanner in=new FastScanner();
//	Scanner sc = new Scanner(System.in);
PrintWriter out=new PrintWriter(System.out);

HashMap<Character, Integer> h = new HashMap<Character, Integer>();
//	TreeMap<Integer, Integer> h1 = new TreeMap<Integer, Integer>();
//	HashMap<Integer, Integer> h2 = new HashMap<Integer, Integer>();
//	HashSet<Point> s = new HashSet<Point>();

//	HashSet<Double> s2 = new HashSet<Double>();
//	HashSet<Double> s3 = new HashSet<Double>();
//	HashSet<Character> h2 = new HashSet<Character>();
//long t= in.nextLong();
//	long t = in.nextLong();
//DecimalFormat df = new DecimalFormat("#,###,##0.000000");

/*	 boolean prime[]=new boolean[10000000];
int p[]=new int[10000000];
int k=1;
Arrays.fill(prime, true);
prime[0]=false;
prime[1]=false;for(int i=2;i<10000000;i++)
{
if(!prime[i])
{
p[i]=p[i-1];
continue;
}
p[i]=k; k++;
for(long j=(long)i*i;j<10000000;j+=i)
prime[(int)j]=false;
}
/*    int pri[]=new int[1000005];
int p=2;
List<Integer> list=new ArrayList<>();
while(p*p <=1000005)
{
if(pri[p]==0)
{
for(int i=p*2;i<=1000004;i=i+p)
{
pri[i]=1;
}
}
p++;
}*/
//System.out.println(list);

int[] power = calcPower();

int t = in.nextInt();
while(t-->0)
{
int n = in.nextInt();
int x = in.nextInt();
long m = in.nextLong();
long arr[]=new long[n];
for(int i=0;i<n;i++){
arr[i] = in.nextLong();
}
long x1=1;
long y=m-1;
long z=0;
long ans=(arr[x-1])%1000000007;
long zp=1;
for(int i=1;i<x;i++){
y++;
z++;
zp=((zp*(y%1000000007)%1000000007)*mpow(z%1000000007,1000000005)%1000000007)%1000000007;
ans=(ans+(zp*(arr[x-i-1]%1000000007))%1000000007)%1000000007;
}
out.println(ans);
}
out.close();
}

public static long mpow(long base, long exp){
long ans=1;
while(exp!=0){
if(exp%2!=0)
ans=(ans*base)%1000000007;
base=base*base;
base=base%1000000007;
exp=exp/2;
}
return ans;
}

public static long gcd(long a,long b,long n){
if(a==b){
return (power(a,n,mod)+power(b,n,mod))%mod;
}
long res=1l;
long num=a-b;
for(long i=1;i*i<=num;i++){
if(num%i==0){
long temp= (power(a,n,i)+ power(b,n,i))%i;
if(temp==0){
res=Math.max(res,i);
}
temp= (power(a,n,num/i) + power(b,n,num/i))%(num/i);
if(temp==0){
res=Math.max(res,num/i);
}
}
}
return res%mod;
}
public static long power(long a,long n,long d){
long res=1l;
while(n>0){
if(n%2==1){
res =((res%d)*(a%d))%d;
n--;
}else{
a=((a%d)*(a%d))%d;
n=n/2;
}
}
return res%mod;
}
/*	static long power(long x,long y) {
long res=1;
x%=m;
while(y>0) {
if(y%2!=0)
res=(res*x)%m;
y=y>>1;
x=(x*x)%m;
}
return res;
}
*/

static long gcd(long a, long b)
{
if(b==0)
return a;
else
return gcd(b, a%b);
}
static long  nextPower_2 (  long x, long y )
{

long  count  =  0 ;
while ( y < x )
{count ++ ;
y  =  y <<  1 ;
}
return  count ;
}
/*
static long power(long a, long b, long p)
{ 	long x = 1, y = a;
while (b > 0) {
if (b % 2 == 1) {
x = (x * y);
if (x >= p) x %= p;
}
y = (y * y); if (y >= p) y %= p;
b /= 2;}
return x;
}*/
public static class Modular {

private int MOD;

Modular(int MOD) {
this.MOD = MOD;
}

public long add(long a, long b) {
return (a + b) % MOD;
}

public long sub(long a, long b) {
return (a - b + MOD) % MOD;
}

public long mul(long a, long b) {
return (a * b) % MOD;
}

public long div(long a, long b) {
return mul(a, inverseEuler(b));
}	public long power(long a, long b) {
long x = 1, y = a;
while (b > 0) {
if (b % 2 == 1) {
x = (x * y);if (x >= MOD) x %= MOD;
}
y = (y * y);
if (y >= MOD) y %= MOD;
b /= 2;}
return x;
}

public long inverseEuler(long n) {
return power(n, MOD - 2);
}
}
byte[] buf = new byte[2048];
int index, total;
in = is;
}	int scan() throws IOException {
if (index >= total) {
index = 0;
if (total <= 0) { return -1;
}
}
return buf[index++];
}

String next() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan()) ;
StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) {
sb.append((char) c);}
return sb.toString();
}String nextLine() throws IOException {
int c;for (c = scan(); c <= 32; c = scan()) ;
StringBuilder sb = new StringBuilder();
for (; c != 10 && c != 13; c = scan()) {
sb.append((char) c);
} return sb.toString();
}char nextChar() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan()) ;
return (char) c;
}	int nextInt() throws IOException {
int c, val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan(); }
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}long nextLong() throws IOException {
int c;long val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
}

static class FastScanner{
StringTokenizer st;
String nextToken(){
while(st==null||!st.hasMoreElements())
return st.nextToken();
}
int nextInt(){return Integer.parseInt(nextToken());}
long nextLong(){return Long.parseLong(nextToken());}
double nextDouble(){return Double.parseDouble(nextToken());}
}
}``````

## Chef and Strange Operations CodeChef Solution in PYTH

``````import sys

def inverse(x):
t=0
newt=1
r=1000000007
newr=x
while newr!=0:
q=r/newr
aux=t
t=newt
newt=aux-q*newt
aux=r
r=newr
newr=aux-q*newr
if t<0:
t+=1000000007
return t

line=0
ncases=int(lines[line])
line+=1
for case in xrange(ncases):
n,x,m=map(int,lines[line].split())
line+=1
numbers=map(int,lines[line].split())
line+=1
acc=den=1
total=0
for i in xrange(x-1,-1,-1):
total+=acc*numbers[i]
total%=1000000007
acc*=m
acc*=inverse(den)
acc%=1000000007
m+=1
den+=1
print total
``````

## Chef and Strange Operations CodeChef Solution in C#

``````using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;

namespace Test
{
class STROPR
{
const ulong Mod = 1000000007;

static void Main(string[] args)
{
Sol1();
//Gen();
}

static void Gen()
{
using (StreamWriter sw = new StreamWriter("kuten.txt"))
{
sw.Write("2\n");
sw.Write("100000 99999 1000000000000000000\n");
for (int i = 0; i < 100000; i++)
sw.Write("{0} ", i);
sw.Write("\n100000 99999 1000000000000000000\n");
for (int i = 0; i < 100000; i++)
sw.Write("{0} ", i);
Console.WriteLine();
}
}

static void Sol1()
{
for (int test = 0; test < t; test++)
{

//Console.WriteLine("Preloop N {0} x {1} M {2}", N, x, M);
ulong result = 0, bin = 1;
for (int i = 0; i <= x; i++)
{
result = (result + (bin * (values[x - i]%Mod)) % Mod) % Mod;
bin = (((M%Mod + (ulong)i) % Mod * ReverseModulo(i + 1, (int)Mod)) % Mod * bin) % Mod;
//Console.WriteLine(i);
}
Console.WriteLine("{0}", result);
}
}

static ulong ReverseModulo(int v, int m)
{
int a1 = 1, a2 = 0, b1 = 0, b2 = 1;
int r1 = v, r2 = m;
while (r1 != 0)
{
int c = r2/r1;
int ta1 = a2 - c*a1, tb1 = b2 - c*b1, tr1 = r2 - c*r1;
a2 = a1;
b2 = b1;
r2 = r1;
a1 = ta1;
b1 = tb1;
r1 = tr1;
}
return (ulong)((a2 + m)%m);
}
}

static class InputHanlder
{
{
}

{
}

{
int ch;
var builder = new StringBuilder();

while ((ch = reader.Read()) == ' ' || ch == '\n' || ch == '\r' || ch == -1) ;
do
{
builder.Append((char) ch);
} while (ch != ' ' && ch != '\n' && ch != '\r' && ch != -1);

//Console.WriteLine("aye! -" + builder.ToString() + "-");
//Console.WriteLine("lol");
return builder.ToString();
}

{
ulong[] values = new ulong[size];

for (int i = 0; i < size; i++)

return values;
}
}
}``````
##### Chef and Strange Operations CodeChef Solution Review:

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

Find on CodeChef

##### Conclusion:

I hope this Chef and Strange Operations 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!