fork download
  1. ///Bismillahir Rahmanir Rahim
  2.  
  3. #include<cstdio>
  4. #include<iomanip>
  5. #include<cstring>
  6. #include<cmath>
  7. #include<cstdlib>
  8. #include<cctype>
  9. #include<algorithm>
  10. #include<string>
  11. #include<vector>
  12. #include<queue>
  13. #include<map>
  14. #include<set>
  15. #include<sstream>
  16. #include<stack>
  17. #include<list>
  18. #include<iostream>
  19. #include<assert.h>
  20. #include<bits/stdc++.h>
  21.  
  22. /**Define file I/O **/
  23. #define f_input freopen("input.txt","r",stdin)
  24. #define f_output freopen("output.txt","w",stdout)
  25.  
  26. /**Define memory set function**/
  27. #define mem(x,y) memset(x,y,sizeof(x))
  28. #define CLEAR(x) memset(x,0,sizeof(x))
  29.  
  30. /**Define function and object**/
  31. #define pb push_back
  32. #define Sort(v) sort(v.begin(),v.end())
  33. #define RSort(v) sort(v.rbegin(),v.rend())
  34. #define CSort(v,C) sort(v.begin(),v.end(),C)
  35. #define all(v) (v).begin(),(v).end()
  36. #define sqr(x) ((x)*(x))
  37. #define find_dist(a,b) sqrt(sqr(a.x-b.x)+sqr(a.y-b.y))
  38.  
  39. /**Define constant value**/
  40. #define ERR 1e-9
  41. #define pi (2*acos(0))
  42. #define PI 3.141592653589793
  43.  
  44. /**Define input**/
  45. #define scanint(a) scanf("%d",&a)
  46. #define scanLLD(a) scanf("%lld",&a)
  47. #define scanstr(s) scanf("%s",s)
  48. #define scanline(l) scanf(" %[^\n]",l)
  49. #define scandouble(d) scanf("%lf",&d)
  50. #define scanchar(c) scanf("%c",&c)
  51.  
  52. /**Define Bitwise operation**/
  53. #define check(n, pos) (n & (1ll<<(pos)))
  54. #define biton(n, pos) (n | (1ll<<(pos)))
  55. #define bitoff(n, pos) (n & ~(1ll<<(pos)))
  56.  
  57. /**Define color**/
  58. enum {WHITE,GREY,BLACK};
  59.  
  60. /**Sync off with stdio**/
  61. #define __ cin.sync_with_stdio(false);\
  62.   cin.tie();
  63.  
  64. /**Debug tools**/
  65. #define what_is(x) cerr<<(#x)<<" is "<<x<<endl
  66. using namespace std;
  67.  
  68. /**Typedef**/
  69. typedef vector<int> vint;
  70. typedef vector< vint > vint2D;
  71. typedef vector<string> vstr;
  72. typedef vector<char>vchar;
  73. typedef vector< vchar >vchar2D;
  74. typedef queue<int> Qi;
  75. typedef queue< Qi > Qii;
  76. typedef map<int,int> Mii;
  77. typedef map<string,int> Msi;
  78. typedef map<int,string> Mis;
  79. typedef stack<int> stk;
  80. typedef pair<int,int> pp;
  81. typedef pair<int, pp > ppp;
  82. typedef long long int ll;
  83. ll inf=1e18;
  84.  
  85. /**Template & structure**/
  86.  
  87. template<class T>T gcd(T a,T b){return b == 0 ? a : gcd(b, a % b);}
  88.  
  89. template<typename T>T lcm(T a, T b) {return a / gcd(a,b) * b;}
  90.  
  91. template<typename T>T last_bit(T n) { return n & 1; }
  92.  
  93. template<class T>T big_mod(T n,T p,T m){if(p==0)return (T)1;T x=big_mod(n,p/2,m);x=(x*x)%m;if(p&1)x=(x*n)%m;return x;}
  94.  
  95. template<class T>T modInv(T a, T m){T x, y; extgcd(a, m, x, y); x %= m; while (x < 0){x += m;} return x;}
  96.  
  97. template<class T> T extgcd(T a,T b,T& x,T& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
  98.  
  99. template<class T>T multiplication(T n,T p,T m){if(p==0)return (T)0;T x=multiplication(n,p/2,m);x=(x+x)%m;if(p&1)x=(x+n)%m;return x;}
  100.  
  101. template<class T>T my_pow(T n,T p){if(p==0)return 1;T x=my_pow(n,p/2);x=(x*x);if(p&1)x=(x*n);return x;} ///n to the power p
  102.  
  103. template <class T> double getdist(T a, T b){return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));}/// distance between a & b
  104.  
  105. template <class T> T extract(string s, T ret) {stringstream ss(s); ss >> ret; return ret;}/// extract words or numbers from a line
  106.  
  107. template <class T> string tostring(T n) {stringstream ss; ss << n; return ss.str();}/// convert a number to string
  108.  
  109. template<class T> T Mod(T n,T m) {return (n%m+m)%m;} ///For Positive Negative No.
  110.  
  111. template<class T> T MIN3(T a,T b,T c) {return min(a,min(b,c));} /// minimum of 3 number
  112.  
  113. template<class T> T MAX3(T a,T b,T c) {return max(a,max(b,c));} ///maximum of 3 number
  114.  
  115. template <class T> void print_vector(T &v){int sz=v.size();if(sz)cout<<v[0];for(int i = 1; i < sz; i++)cout << ' '<<v[i];cout<<"\n";}/// prints all elements in a vector
  116.  
  117. bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
  118.  
  119. bool isConsonant(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}
  120.  
  121. template <class R> R Josephus(R n,R k){R ans=1;for(R i=2;i<=n;i++)ans=(ans+k-1)%i+1;return ans;}
  122.  
  123. template <class R> R toitent_Phi2(R a){R result = a;for(R i=2;i*i<=a;i++){if(a%i==0) result=result-result/i;while(a%i==0) a=a/i;}if(a>1) result=result-result/a;return result;}
  124.  
  125. template <typename T> T Angle(T x1,T y1,T x2, T y2){ return atan( double(y1-y2) / double(x1-x2));}
  126.  
  127.  
  128. //namespace debug{
  129. // int sum(){return 0;}
  130. // template<typename T,typename... Args> T sum(T a,Args... args) {return a+sum(args...);}
  131. // void print(){cout<<"\n";return;}template<typename T, typename... Args>void print(T a,Args... args){cout<<a<<" ";print(args...);}
  132. //}
  133.  
  134.  
  135. /**Direction**/
  136. ///int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1}; ///8 Direction
  137. ///int dx[4] = {1, 0, -1, 0};int dy[4] = {0, 1, 0, -1}; ///4 Direction
  138. ///int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};///Knight Direction
  139. ///int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; ///Hexagonal Direction
  140.  
  141.  
  142. /******************************End******************************/
  143.  
  144. #define mxn 300009
  145. //#define mod
  146. ll a[mxn];
  147.  
  148. int main()
  149. { //freopen("largeinput.txt","r",stdin);
  150. //freopen("largeoutput.txt","w",stdout);
  151. __;
  152.  
  153. ll T,t;
  154. ll n;
  155. ll i,j,k;
  156. ll ans=0;
  157.  
  158. cin>>T;
  159. for(t=1;t<=T;t++){
  160. cin>>n;
  161. for(i=1;i<=n;i++){
  162. cin>>a[i];
  163. }
  164.  
  165. ll mod=1000000007LL;
  166. sort(a+1,a+1+n);
  167. for(i=1;i<=n;i++){
  168. ans+=(a[i]*big_mod(2ll,i-1ll,mod)+mod)%mod;
  169. ans=(ans-a[i]*big_mod(2ll,n-i,mod)+mod)%mod;
  170. }
  171.  
  172. cout<<"Case #"<<t<<": ";
  173. cout<<(ans+mod)%mod<<"\n";
  174. }
  175. }
  176.  
  177.  
  178.  
Time limit exceeded #stdin #stdout 5s 18400KB
stdin
Standard input is empty
stdout
Standard output is empty