akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m; cin>>m;
    ll now = 0, ans = 0;
    rep(i, m){
        int d; ll c; cin>>d>>c;
        now += d*c;
        ans += c;
        ans += now / 9;
        now = now % 9;
    }
    if (now%9==0) ans--;
    cout << ans-1 << endl;
    return 0;
}


Measured memory_bytes: 256
def slove():
    import sys
    import heapq
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    ls =[]
    v = []
    heapq.heapify(v)
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        ls.append([a, b])
    ls.sort(reverse=True)
    r = 0
    for i in range(1, m + 1):
        while True:
            if len(ls) != 0:
                a, b = ls.pop()
                if a <= i:
                    heapq.heappush(v, -b)
                else:
                    ls.append([a, b])
                    break
            else:
                break
        if len(v) != 0:
            r += -heapq.heappop(v)
    print(r)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 75740
#include <iostream>

int main(int argc, char const* argv[]) {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int A, B;
    std::cin >> A >> B;
    int w, b;
    if (A < B) {
        w = A;
        b = B;
    }
    else {
        w = B;
        b = A;
    }

    const int N = 100;
    bool grid[N][N];
    std::fill((bool*)grid, (bool*)(grid+N), false);

    w--; b--;
    grid[0][0] = true;
    if (b > 0) {
        grid[1][1] = true;
        b--;
    }
    int x = 1, y = 1;
    while (w > 0) {
        if (x > 0) {
            x--;
            y++;
            w--;
            b--;
        }
        else {
            x = (x+y)/2;
            y = x;
            x++;
            y++;
            b--;
        }
        grid[y][x] = true;
    }

    if (b > 0) {
        x = (x+y)/2;
        y = x;
        x++; y++; b--;
        grid[y][x] = true;
        x++; y++; b--;
        grid[y][x] = true;
        while (b > 0) {
            if (x > 1) {
                x--; y++; b--;
                grid[y][x] = true;
            }
            else {
                x = (x+y)/2;
                y = x;
                x++; y++;
                grid[y][x] = true;
                x++; y++;
                grid[y][x] = true;
                b -= 2;
            }
        }
    }

    x = 1;
    y = 0;
    while (b < 0) {
        grid[y][x] = true;
        x++; y++; b++;
    }

    std::cout << "100 100\n";
    for (int i=0; i<N; i++) {
        for (int j=0; j<N; j++) {
            std::cout << ((grid[j][i] ^ (A < B)) ? '.' : '#');
        }
        std::cout << '\n';
    }
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef pair<ll, ll> PLL;

signed main() {
    ll N,M;
    cin>>N>>M;
    map<ll,ll> m;
    vector<ll> a(N+1);
    rep(i,1,N+1){
        cin>>a[i];
        a[i] += a[i-1];
    }

    // rep(i,0,N+1){
    //     printf("%3d ", a[i]);
    // }
    // cout<<endl;

    rep(i,1,N+1){
        a[i] %= M;
        m[a[i]]++;
    }

    // rep(i,0,N+1){
    //     printf("%3d ", a[i]);
    // }
    // cout<<endl;

    ll ans = 0;
    for (auto e: m){
        if (e.first == 0){
            ans += e.second;
        }

        // e.second _C_ 2
        if (e.second >= 2){
            ans += e.second * (e.second-1)/2;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4992
N=int(input())
ind=[0]
maxA=0
A=[]
for i in range(N):
    a=int(input())
    if a>maxA:
        ind=[i]
        maxA=a
    elif a==maxA:
        ind.append(i)
    A.append(a)

if len(ind)>1:
    for _ in A:
        print(maxA)
else:
    tmp=A.copy()
    tmp.sort(reverse=True)
    for t in tmp:
        if t!=maxA:
            secondA=t
            break
    for a in A:
        if a==maxA:
            print(secondA)
        else:
            print(maxA)

Measured memory_bytes: 20460
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
//int a[100005];
//int b[100005];
int main()
{
    int i,j,k;
    int p,q;
    int tt;
    scanf("%d",&tt);
    while(tt--)
    {
        int cnt=0;
        scanf("%d%d",&p,&q);
        int te=p*p+q*q;
        for(i=-200;i<=200;i++)
        {
            for(j=-200;j<=200;j++)
            {
                if(i*i+j*j==0)
                    continue;
                else if(i*i+j*j<20000&&te%(i*i+j*j)==0)
                {
                    int t1=i*p+j*q;
                    int t2=i*q-j*p;
                    int t3=i*i+j*j;
                    if(t1%t3==0&&t2%t3==0)
                        cnt++;
                }
            }
        }
        if(cnt==8)
            printf("P\n");
        else printf("C\n");
        //printf("%d\n",cnt);
    }
    return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ld long double
#define pb push_back
#define fe first
#define se second
#define nl "\n"
#define pp pair < ll , ll > 
#define sz(x) (ll)x.size()
#define st(x) sort(x.begin(),x.end())
#define rst(x) sort(x.rbegin(), x.rend())
#define all(x) x.begin(),x.end()
long double pi = 3.14159265358979323;
 
const double EPS = 1e-12;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
 

vector < ll > v[N];
bool vis[N];
ll dp[N];
void dfs(ll s){

    vis[s] = 1;
    dp[s] = 1;
    for(auto it : v[s]){
        if(!vis[it]){
           dfs(it);
        }
        dp[s] = max(dp[s] , 1 + dp[it]);
    }
    //cout << s << " " << dp[s] << "\n";
}
 
 
int main()
{

    fast;
    ll n, m;
    cin >> n >> m ;
    for(int i = 0 ;  i < m ; i++ ){
        ll a ,b;
        cin >> a >> b ;
        v[a].pb(b);
    }
    
    ll ans = 1;
    for(int i = 1 ; i <= n ;i++ ){
        if(!vis[i]){
            dfs(i);
        }
    }
    for(int i = 1 ; i <= n ; i++ ){
        ans = max(ans , dp[i]);
    }
    cout << ans - 1;





















    
    return 0;
    
}

Measured memory_bytes: 32256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> ok(n, true);
  rep(i,n) cin >> h[i];
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    if (h[a] <= h[b]) ok[a] = false;
    if (h[b] <= h[a]) ok[b] = false;
  }
  int ans = 0;
  rep(i,n) if (ok[i]) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3792
import time


def main():

    N, Q = map(int, input().split())
    S = input()

    sum = [0] * (N + 100)

    for i in range(N-1):
        if S[i] == 'A' and S[i+1] == 'C': sum[i+1] = sum[i] + 1
        else: sum[i+1] = sum[i]

    for i in range(Q):
        l, r = map(int, input().split())
        print(sum[r-1] - sum[l-1])


if __name__ == '__main__':
    start = time.perf_counter()

    main()

    end = time.perf_counter()
    # print(end - start)


Measured memory_bytes: 6184
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];

int main()
{
    ll n,m,i,j,cc=0;
    cin>>n>>m;
    ll x,y;cin>>x>>y;
    i=n*m;
    j=m*x+(y*(n-x));
    cout<<i-j<<endl;
return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <stdlib.h>

int main() {
  int n = 0;
  int h = 0;
  int destn = 0;
  int lx;
  int ly;
  int x;
  int y;
  int result = 0;
  int big;
  int small;
  int xs;
  int ys;
  int i = 0;

  scanf("%d%d%d", &n, &h, &destn);
  for(i = 0; i < destn; ++i) {
    scanf("%d%d", &x, &y);
    if(i >= 1) {
      xs = lx - x;
      ys = ly - y;
      if((xs > 0 && ys > 0) || (xs < 0 && ys < 0)) {
        xs = abs(xs);
        ys = abs(ys);
        if(xs > ys) {
          big = xs;
          small = ys;
        } else {
          big = ys;
          small = xs;
        }
        result += (small + big - small);
      } else {
        result += (abs(xs) + abs(ys));
      }
    }
    lx = x;
    ly = y;
  }
  printf("%d\n", result);
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	int a,b,h;
	cin>>a>>b>>h;
	cout<<(a+b)*h/2;
}


Measured memory_bytes: 256
//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = 1e6 + 5;

/***************************************************************************/

ll X[N], V[N];
ll bestL[N], bestR[N];

int main() {

	boost;
	int n; cin>>n;
	ll c; cin>>c;

	ll sum = 0;
	ll ans = 0;

	for(int i=1; i<=n; i++) {
		cin>>X[i]>>V[i];
		sum += V[i];
		bestL[i] = max(bestL[i-1], sum-X[i]);
		ans = max(ans, bestL[i]);
	}

	sum = 0;
	for(int i=n; i>=1; i--) {
		sum += V[i];
		bestR[i] = max(bestR[i+1], sum-c+X[i]);
		ans = max(ans, bestR[i]);
		ans = max(ans, sum-c+X[i]-c+X[i]+bestL[i-1]);
	}

	sum = 0;
	for(int i=1; i<=n; i++) {
		sum += V[i];
		ans = max(ans, sum-X[i]-X[i]+bestR[i+1]);
	}

	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 11264
import scala.io.StdIn._
import scala.math._

object Main extends App with StdInHelper {
  val s = readLine().toCharArray()
  val t = readLine().toCharArray()

  var count = 0
  for (i <- 0 to s.length - 1) {
    if (s(i) != t(i)) count += 1
  }

  println(count)
}

trait StdInHelper {
  def readStrings = readLine.split(" ")
  def readInts = readStrings.map(_.toInt)
  def readLongs = readStrings.map(_.toLong)
  def readDoubles = readStrings.map(_.toDouble)
  def readBigInts = readStrings.map(BigInt.apply(_))
  def readBigDecimals = readStrings.map(BigDecimal.apply(_))
}


Measured memory_bytes: 57068
#include <iostream>
using namespace std;
 
int main() {
  int a1,b1;
  cin >> a1 >> b1;
  int a2,b2;
  cin >> a2 >> b2;
  int a3,b3;
  cin >> a3 >> b3;
 
  if (a1==a2 || a1==b2) {
    if(a1==a3 || a1 ==b3){
      cout << "NO" << endl;
      return 0;
    }
  }
  
  if (b1==a2 || b1==b2) {
    if(b1==a3 || b1 ==b3){
      cout << "NO" << endl;
      return 0;
    }
  }
  
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;

#define endl '\n'


int main()
{

    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


    ll n,k;
    cin>>n>>k;

    vector < pair <ll,ll> > ans;

    if( ((n-1)*(n-2))/2 < k ){
        cout<<-1<<endl;
        return 0;
    }

    for(ll i=1;i<n;i++){
        ans.push_back({1,i+1});
    }

    ll res = ((n-1)*(n-2))/2 - k;

    for(ll k=0;k<res;k++){
        for(ll i=1;i<n;i++){
            for(ll j=i+1;j<n;j++){
                if(res>0){
                    ans.push_back({i+1,j+1});
                    res--;
                }
            }
        }
    }
    cout<<ans.size()<<endl;
    for(ll i=0;i<ans.size();++i){
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }


}


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int r = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'R') r++;
  }
  cout << (r > n - r ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
      string s;int n;
      cin>>n>>s;
      int ans=0;
      for(int i=0;i<n-2;i++)
      {
          if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
          ans++;
      }
      cout<<ans;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long

void solve()
{
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a) cout<<k<<"\n";
    else if(k <= a+b) cout<<a<<"\n";
    else
    {
        ll remaing=k-a-b;
        cout<<a-remaing<<"\n";
    }    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3652
n, m = map(int, input().split())
a = [[0 for i in range(m)] for j in range(n)] 
b = []

for i in range(n):
    ai = list(map(int,input().split()))
    for j in range(m):
        a[i] [j] = ai[j]

for i in range(m):
    b.append(int(input()))

for i in range(n):
    c = 0
    for j in range(m):
        c = c + a[i][j] * b[j]
    print(c)


Measured memory_bytes: 6000
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less   
using namespace __gnu_pbds;  
using namespace std;  
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> set1;
ll find(ll a,ll p[])
{
   //cout<<"find "<<a<<endl;
   if(a==p[a])
   return a;
   else return p[a]=find(p[a],p);

}
void join(ll a,ll b,ll p[],ll sz[])
{
   a=find(a,p);
   b=find(b,p);
   if(a!=b)
   {
      if(sz[a]<sz[b])
      swap(a,b);
      sz[a]+=sz[b];
      p[b]=a;
   }
}
ll power(ll a,ll b,ll mod)
{
   ll res=1;
   while(b>0)
   {
      if(b&1)
      res=(res*a)%mod;
      b=b/2;
      a=(a*a)%mod;
   }
   return res;
}
ll inverse(ll x, ll p)
{
   return power(x,p-2,p);
}
ll hash1(ll x,ll y)
{
   return x+y+x*y;
}
//ll f[200000]={0};
ll mod=1000000007;
/*void ini()
{
   f[0]=1;
   for(ll i=1;i<=200000;i++)
   f[i]=(i*f[i-1])%mod;
}*/



/*ll ncr(ll n,ll r)
{
   ll res=1;
   ll k=f[n];
   ll v=inverse(f[n-r],mod);
   ll u=inverse(f[r],mod);
   ll x=(u*v)%mod;
   k=(k*x)%mod;
   return k;
}*/
/*struct edge
{
   ll from;
   ll to;
};
void dfs(ll v,ll vis[],ll dp[],vector<ll> adj[])
{
   ll k=adj[v].size();
   for(ll i=0;i<k;i++)
   {
      ll u=adj[v].at(i);
      if(vis[u]==0)
      {
         vis[u]=1;
         dfs(u,vis,dp,adj);
         dp[v]=max(dp[v],dp[u]+1);
      }
      else
      dp[v]=max(dp[v],dp[u]+1);
   }
}*/
ll f1(ll l,ll r,ll dp[][401],ll w[])
{
   if(dp[l][r]!=-1)
   return dp[l][r];
   else if(l==r)
   {
      return dp[l][r]=0;
   }
   else if(r-l==1 && l!=0)
   return dp[l][r]=w[r]-w[l-1];
   else if(r-l==1)
   return dp[l][r]=w[r];
   else
   {
      ll cost1=1e18;
      ll add;
      if(l==0)
      add=w[r];
      else
      add=w[r]-w[l-1];

      for(ll i=l+1;i<=r;i++)
      {
         ll cost=f1(l,i-1,dp,w)+f1(i,r,dp,w)+add;
         cost1=min(cost,cost1);
      }
      return dp[l][r]=cost1;
      
   }
   

}
      


int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
    cin>>a[i];
    ll w[n]={0};
    w[0]=a[0];
    for(ll i=1;i<n;i++)
    w[i]=w[i-1]+a[i];
   ll dp[n+1][400+1];
   ll l1=-1;
   for(ll i=0;i<=n;i++)
   {
      for(ll j=0;j<=n;j++)
      dp[i][j]=-1;
      
   }
   ll ans=1e18;
   
   for(ll i=1;i<n;i++)
   {
      ll cost=f1(0,i-1,dp,w)+f1(i,n-1,dp,w)+w[n-1];
      ans=min(cost,ans);
   }
 /*  for(ll i=0;i<n;i++)
   {
      for(ll j=i;j<n;j++)
      cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
   }*/
   cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
map<string,int>arr;

int main(void)
{       
        string a,b;
        cin >>a>> b;
        int x,y;
        cin >> x>>y;
        arr[a] = x;
        arr[b] = y;

        string nya;
        cin >>nya;
        arr[nya] --;
        cout << arr[a] <<" "<< arr[b] << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main ()
{    
    int r;
    int g;
    int b;
    scanf("%d",&r);
    scanf("%d",&g);
    scanf("%d",&b);
    int c;
    c=r*100+g*10+b;
    if(c%4==0)
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }
return 0;
} 


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;

class Food
{
	public:
		long totalHappy(vector<int> &taste)
		{
			long ans=0;
			long total_taste=0;
			for(auto v:taste)
				total_taste+=v;
			for(auto v:taste)
			{
				total_taste-=v;
				ans+=v*total_taste;
}
return ans;
}
};
int main()
{
	int n;
cin>>n;
vector<int> taste(n);
for(int i=0;i<n;i++)
{
	cin>>taste[i];
}
Food food;
cout<<food.totalHappy(taste);
}


Measured memory_bytes: 256
dic = {"0":"* = ****",
       "1":"* =* ***",
       "2":"* =** **",
       "3":"* =*** *",
       "4":"* =**** ",
       "5":" *= ****",
       "6":" *=* ***",
       "7":" *=** **",
       "8":" *=*** *",
       "9":" *=**** "}
def trans(lst):
  ylen = len(lst)
  xlen = len(lst[0])
  ret = [[None] * ylen for _ in range(xlen)]
  for y in range(ylen):
    for x in range(xlen):
      ret[x][y] = lst[y][x]
  return ret

def print_abac(num):
  num = num.zfill(5)
  lst = [dic[c] for c in num]
  lst = trans(lst)
  for line in lst:
    print("".join(line))

cnt = 0
while True:
  try:
    num = input()
    if cnt != 0:
      print()
    else:
      cnt += 1
    print_abac(num)
  
  except EOFError:
    break



Measured memory_bytes: 5576
/*
Author - Glitched
Yeet!!
*/
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define loop(i,x,n) for(ll i = x;i<n;i++)

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll n;
    cin>>n;
    vector<ll> v[n+1];
    loop(i,1,n){
        ll x;
        cin>>x;
        v[x].push_back(i+1);
    }
    loop(i,1,n+1){
        cout<<v[i].size()<<endl;
    }
}

Measured memory_bytes: 14552
name=['A','B','C','D','E']
shop = []
while True:
  a,b = map(int,input().split())
  if a == 0 and b == 0:
    break
  shop.append(a+b)
  if len(shop) == 5:
    m = max(shop)
    print(name[shop.index(m)],m)
    shop = []


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
#define ll long long
#define ld long double

#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll, ll>
#define sq(x) ((x) * (x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
const ll MOD = 1000 * 1000 * 1000 + 7;
using namespace std;



ll dp[1010][1010]={0};
bool dpvisit[1010][1010]={false};

int N;


int H,W;


char A[1005][1005];


ll seno(ll idx1, ll idx2)
{


if(dpvisit[idx1][idx2]==true)
return dp[idx1][idx2];	

if (idx1==W&&idx2==H)
{dpvisit[idx1][idx2]=true;
	return dp[W][H]=1;	
}
if (A[idx1][idx2]=='#')
{
	dpvisit[idx1][idx2]=true;
	return dp[idx1][idx2]=0;
}	

if (idx2+1<=H)
{	
if (A[idx1][idx2+1]=='.')
{
	dp[idx1][idx2]=(dp[idx1][idx2]+seno(idx1,idx2+1))%MOD;
	
}
}	

if (idx1+1<=W)
{	
if (A[idx1+1][idx2]=='.')
{
   dp[idx1][idx2]=(dp[idx1][idx2]+seno(idx1+1,idx2))%MOD;

}	
}
dpvisit[idx1][idx2]=true;

return dp[idx1][idx2];

}



int main() 
{ 



fastio();

cin>>H>>W;
	
for (int i=1;i<=H;i++)
{
for (int j=1;j<=W;j++)
cin>>A[j][i];	
}	




ll x=seno(1,1);

cout<<x;

return 0;
} 




Measured memory_bytes: 10240
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string S;
	scan(S);
	int N=S.size();
	int count=0;
	int ans=0;
	rep(i,N){
		if(count>0&&S[i]=='0'){
			ans+=2;
		}
		else if(count<0&&S[i]=='1'){
			ans+=2;
		}
		count+=(S[i]-'0')*2-1;
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;

int main() {
	string s;
	cin >> s;
	ll a = 0, b = 0, c = 0;

	rep(i, s.size()) {
		if (s[i] == 'a') {
			a++;
		}
		else if (s[i] == 'b') {
			b++;
		}
		else {
			c++;
		}
	}

	if (abs(max(a, max(b, c)) - min(a, min(b, c))) <= 1) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}

	return 0;
}

Measured memory_bytes: 3668
n = int(input())
ls = [[int(_) for _ in input().split()] for _ in range(n)]

ls.sort(key=lambda x: x[1])

t = 0

for i in range(n):
    t += ls[i][0]
    if t > ls[i][1]:
        print("No")
        break
    elif i == n - 1:
        print("Yes")

Measured memory_bytes: 41180
import scala.io.StdIn._
import scala.annotation.tailrec

object Main {
    def main(args: Array[String]): Unit = { 
        digit(readLine().split(" ").map(_.toDouble))
    }   

    @tailrec
    def digit(n: Seq[Double]): Unit = {
       val d: Double = n(1) * n(3) - n(0) * n(4)
       val x: Double = zero((n(1) * n(5) - n(4) * n(2)) / d)
       val y: Double = zero((n(2) * n(3) - n(0) * n(5)) / d)
       println(f"$x%.3f $y%.3f")
       val next: String = readLine()
       if(next == null) Unit else digit(next.split(" ").map(_.toDouble))
    }

    def zero(n: Double): Double = if(n == -0) 0 else n
}

Measured memory_bytes: 43916
#include<iostream>
using namespace std;

int main() {
  int n, fib[50];

  cin >> n;

  fib[0] = 1;
  fib[1] = 1;
  for (int i = 2; i <= n; i++) {
    fib[i] = fib[i-2] + fib[i-1];
  }
  
  cout << fib[n] << endl;

  return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };

int main() {
	IN(int, Q);
	
	auto diff = [](auto a, auto b) { return abs(a - b); };
	
	vector<LL> T(31);
	inc(i, 31) { T[i] = (i == 0 ? 1 : T[i - 1] * 3); }
	
	inc(q, Q) {
		IN(LL, ax, ay, AX, AY);
		ax--; ay--; AX--; AY--;
		if_not(ax <= AX) { swap(ax, AX); }
		if_not(ay <= AY) { swap(ay, AY); }
		
		LL ans = diff(ax, AX) + diff(ay, AY);
		dec(k, 30) {
			LL ox = (fl(ax - T[k], T[k + 1]) + 1) * T[k + 1] + T[k];
			LL oy = (fl(ay - T[k], T[k + 1]) + 1) * T[k + 1] + T[k];
			
			LL px = ox - T[k + 1];
			LL py = oy;
			LL PX = px + T[k] - 1;
			LL PY = py + T[k] - 1;
			
			LL qx = ox;
			LL qy = oy - T[k + 1];
			LL QX = qx + T[k] - 1;
			LL QY = qy + T[k] - 1;
			
			if(px <= ax && AX <= PX && ay <= py && PY <= AY) {
				ans += 2 * (min(diff(ax, px), diff(AX, PX)) + 1);
				break;
			}
			if(qy <= ay && AY <= QY && ax <= qx && QX <= AX) {
				ans += 2 * (min(diff(ay, qy), diff(AY, QY)) + 1);
				break;
			}
		}
		OUT(ans);
	}
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using ll = long long;
#define AC ios::sync_with_stdio(0),cin.tie(0);

int main()
{
    AC
    string s,t,r="";
    cin>>s>>t;
    int a=s.size(),b=t.size();
    vector<vector<int>> dp(s.size()+1,vector<int>(t.size()+1,0));
    for(int i=1;i<=s.size();i++)
        for(int j=1;j<=t.size();j++)
            if(s[i-1]==t[j-1]) dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    while(a&&b)
    {
        if(s[a-1]==t[b-1]) r.push_back(s[a-1]),a--,b--;
        else if(dp[a][b-1]>=dp[a][b]) b--;
        else a--;
    }
    reverse(r.begin(),r.end());
    cout<<r<<'\n';
}


Measured memory_bytes: 35584
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

struct Main {}

impl Main {}

fn main() {
    let r: f64 = read();
    println!("{}", r * 2.0 * 3.14);
}


Measured memory_bytes: 2184
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define double long double
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    int n, m, x;
    cin >> n >> m >> x;
    int a[n][m];
    int c[n];
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    int ans = inf;
    for (int i = 0; i < (1 << n); i++) {
        int s[m] = {0};
        int sum = 0;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                sum += c[j];
                for (int k = 0; k < m; k++)
                    s[k] += a[j][k];
            }
        }
        for (int j = 0; j < n; j++) {
            int flag = 1;
            for (int k = 0; k < m; k++) {
                if (s[k] < x) flag = 0;
            }
            if (flag) ans = min(ans, sum);
        }
    }
    if (ans == inf) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.TokioMarine_2020
{
    class C
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] nk = ReadInts();
            int n = nk[0];
            int k = nk[1];
            int[] array = ReadInts();
            for(int i = 0; i < k; i++)
            {
                int[] next = new int[n];
                for (int j = 0; j < n; j++)
                {
                    next[Max(j - array[j], 0)]++;
                    if (j + array[j] + 1 < n)
                    {
                        next[j + array[j] + 1]--;
                    }
                }

                int maxCnt = 0;
                for (int j = 0; j < n; j++)
                {
                    if (j > 0)
                    {
                        next[j] += next[j - 1];
                    }
                    if (next[j] == n)
                    {
                        maxCnt++;
                    }
                }

                array = next;
                if (maxCnt == n)
                {
                    break;
                }
            }

            for(int i = 0; i < n; i++)
            {
                Write(array[i] + " ");
            }
            WriteLine();
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 61928
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

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


//////////////////////////////////////////////////////////////////////////////////////b,cl
int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    double total = 0;
    for (int i = 0;i < n;i++){
        cin >> a[i];
        total += a[i];
    }
    int cnt = 0;
    double judge = total/(4*m*1.0);

    for (int i = 0;i < n;i++){
        if (a[i] < judge){
            continue;
        }
        else{
            cnt++;
        }
    }

    if (cnt >= m){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;

int main(){
  int n;
  cin >> n;
  int i=1;
  while(++i<=n){
    int x=i;
    if(x%3==0){
      cout << " " << i;
      continue;
    }
    while(x){
      if(x%10==3){
	cout << " " << i;
	break;
      }
      x/=10;
    }
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  long long int ret = (4 * 1e18);
  vector<long long int> xs, ys;
  vector<pair<long long int, long long int>> ps;
  for (int i = 0; i < N; i++) {
    long long int x, y;
    cin >> x >> y;
    xs.push_back(x);
    ys.push_back(y);
    ps.push_back(make_pair(x, y));
  }

  sort(xs.begin(), xs.end());
  sort(ys.begin(), ys.end());

  for (int xi = 0; xi < N; xi++) {
    for (int xj = xi + 1; xj < N; xj++) {
      for (int yi = 0; yi < N; yi++) {
        for (int yj = yi + 1; yj < N; yj++) {
          int cnt = 0;
          for (int k = 0; k < N; k++) {
            pair<long long int, long long int> p = ps[k];
            if (xs[xi] <= p.first && p.first <= xs[xj] && ys[yi] <= p.second &&
                p.second <= ys[yj]) {
              cnt++;
            }
          }
          if (cnt >= K) {
            ret = min((xs[xj] - xs[xi]) * (ys[yj] - ys[yi]), ret);
          }
        }
      }
    }
  }

  cout << ret << endl;
}


Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)
cities = gets.split.map(&:to_i).map(&:pred)
memo = Array.new(n, -1)
current = 0
count = 0
memo[0] = 0
rest = 0
loop do
  dest = cities[current]
  count += 1
  if count >= k
    puts dest + 1
    exit
  end
  if memo[dest] == -1
    memo[dest] = count
    current = dest
  else
    loop_count = count - memo[dest]
    rest = k - memo[dest]
    rest %= loop_count
    current = dest
    break
  end
end
dest = current
rest.times do
  dest = cities[current]
  current = dest
end
puts dest + 1


Measured memory_bytes: 30476
#include<iostream>
using namespace std;

int main(){
    int n,m,l;
    cin>>n>>m>>l;
    int a[n][m];
    int b[m][l];
    long long c[n][l];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<l;j++){
            cin>>b[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            c[i][j]=0;
            for(int k=0;k<m;k++){
                c[i][j]+=a[i][k]*b[k][j];
            }
            if(j==l-1){
                cout<<c[i][j]<<endl;
            }else{
                cout<<c[i][j]<<" ";
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3236
def minToggle(arr, n): 
  
    zero =[0 for i in range(n + 1+1)] 
    zero[0] = 0
   
    # Fill entries in zero[] 
    # such that zero[i] 
    # stores count of zeroes 
    # to the left of i 
    # (exl 
    for i in range(1, n + 1): 
      
        # If zero found 
        # update zero[] array 
        if (arr[i-1] == 0): 
            zero[i] = zero[i-1] + 1
        else: 
            zero[i] = zero[i-1] 
   
    # Finding the minimum 
    # toggle required from 
    # every index(0 to n-1) 
    ans = n 
    for i in range(1, n + 1): 
        ans = min(ans, i - zero[i] + zero[n] - zero[i]) 
   
    return ans 
      
# Driver Program 
n=int(input())
s=input().rstrip()
arr=[]
ansi=min(s.count('.'),s.count('#'))
for i in s:
    if i=='.':
        arr.append(0)
    else:
        arr.append(1)
n = len(arr) 
  
p=minToggle(arr, n)
ansi=min(ansi,p)
print(ansi)
  
# This code is contributed 
# by Anant Agarwal. 

Measured memory_bytes: 13032
#include<stdio.h>

int main(void)
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a<b){
        printf("a < b\n");
    }else if(a>b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }
    return 0;
}

Measured memory_bytes: 580
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 200010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}

void solve(){
  ll N;
  cin >> N;
  vector<ll> C(N);
  rep(i, N) cin >> C[i];
  sort(C.begin(), C.end());
  reverse(C.begin(), C.end());
  ll ans = 0;
  rep(i, N){
    ll add = pow_mod(4, N-1-i);
    add *= pow_mod(2, i+1);
    add %= MOD;
    ll plus = (pow_mod(2, i) + i * pow_mod(2, i-1) % MOD) % MOD;
    add *= plus;
    add %= MOD;
    ans += add * C[i] % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  char a[100];
  for(int i=0;i<n;++i)cin>>a[i];
  a[k-1]-='A'-'a';
  for(int i=0;i<n;++i)cout<<a[i];
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	long long cnt=0;
	for(int i=0;i<m;i++){
		long long a;
		cin>>a;
		cnt+=a;
	}
	cnt=n-cnt;
	if(cnt<0)cnt=-1;
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3596
h,n = map(int, input().split())

INF = 1e100

dp = [[INF] * (10 ** 4 + 1) for i in range(10 ** 3 + 1)]

dp[0][0] = 0

for i in range(n):
    a, b = map(int, input().split())
    for j in range(h+1):
        dp[i+1][j] = min(dp[i+1][j] , dp[i][j])
        dp[i+1][min(h, (j+a))] = min(dp[i+1][min(h, (j+a))], dp[i+1][j] + b)

print(dp[n][h])

Measured memory_bytes: 291720
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        
        while(stdIn.hasNext()){
            int count = 0;
            
            int n = stdIn.nextInt();
            
            if(n <= 36){
                for(int a = 0; a <= 9; a++){
                    for(int b = 0; b <= 9; b++){
                        for(int c = 0; c <= 9; c++){
                            for(int d = 0; d <= 9; d++){
                                if(a + b + c + d == n){
                                    count++;
                                }
                            }
                        }   
                    }   
                }
            }
            
            System.out.println(count);
        }
    }
}



Measured memory_bytes: 26644
#include <stdio.h>

int main(void) {
	int n,i,j,k[10],buy;
	while (1) {
		scanf("%d",&n);
		if (n==0) break;

		for (i=0;i<10;i++) k[i] = 0;
		for (i=0;i<n;i++) {
			scanf("%d",&buy);
			k[buy]++;
		}
		for (i=0;i<10;i++) {
			if (k[i]==0) puts("-");
			else {
				for (j=0;j<k[i];j++) {
					putchar('*');
				}
				putchar('\n');
			}
		}
	}

	return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define ROF(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

void solve() {
    int n; cin >> n;
    vi k(n + 1), l(n + 1), r(n + 1);
    vvi a(n + 1), b(n + 1);
    ll ans = 0, cl = 0;
    FOR(i, 1, n) {
        cin >> k[i] >> l[i] >> r[i];
        if (l[i] > r[i] || k[i] == n) {
            a[k[i]].pb(i);
            cl++;
        }
        else b[k[i] + 1].pb(i);
        ans += min(l[i], r[i]);
    }
    priority_queue <int> pq;
    int ap = cl, bp = cl + 1;
    FOR(i, ap + 1, n) {
        for (int j : a[i])
            pq.push(max(0, l[j] - r[j]));
    }
    ROF(i, ap, 1) {
        for (int j : a[i])
            pq.push(max(0, l[j] - r[j]));
        if (!pq.empty()) {
            ans += pq.top(); pq.pop();
        }
    }
    while (!pq.empty()) pq.pop();
    FOR(i, 1, ap)
        for (int j : b[i])
            pq.push(r[j] - l[j]);
    FOR(i, bp, n) {
        for (int j : b[i])
            pq.push(r[j] - l[j]);
        if (!pq.empty()) {
            ans += pq.top(); pq.pop();
        }
    }
    cout << ans << endl;
}
 
int main() {
    int t; cin >> t;
    while (t--) solve();
}

Measured memory_bytes: 20016
#include <stdio.h>
#include <math.h>

int main(void)
{
    int n, m, i, result;
    int tmp, a = 0;
    
    scanf("%d %d", &n, &m);
    for(i = 0; i < m; i++) {
        scanf("%d", &tmp);
        a += tmp;
    }
    
    result = n - a;
    
    if(result < 0)
        puts("-1");
    else
        printf("%d\n", result);
    
    return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <queue>
#include <vector>
#include <set>


using namespace std;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

template<class T> inline bool chmin(T& a, T b) {
  //aの方が大きければbに値を更新、そうでなければ何もしない
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
bool compare_a_big(pair<int,int> l,pair<int,int> r){
  //firstが大きい方からソート、firstが同じならbが小さい方から
  if(l.first != r.first){
    return l.first>r.first;
  }
  else{
    return l.second < r.second;
  }
}
bool compare_a_b_big(pair<int,int> l,pair<int,int> r){
  //firstが大きい方からソート、firstが同じならbが大きい方から
  if(l.first != r.first){
    return l.first>r.first;
  }
  else{
    return l.second > r.second;
  }
}
bool compare_b_small(pair<int,int> l,pair<int,int> r){
  //secondが小さい方からソート、firstが同じならfirstが小さい方から
  if(l.second != r.second){
    return l.second<r.second;
  }
  else{
    return l.first < r.first;
  }
}
const int INF = 1e9;
const int M = 1000000007;


typedef long long int ll;
vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算、a,b<=300000でないと使えない
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}



int main(){
  int k,x;
  cin >> k >> x;
  if(k*500 >= x) printf("Yes\n");
  else printf("No\n");



}


Measured memory_bytes: 4992