akhauriyash/Code-Regression huggingface dataset:
#088_D
import queue
h, w = map(int, input().split())
inf = 10 ** 5
s = [input() for _ in range(h)]
d = [[inf]*w for _ in range(h)]

que = queue.Queue()
que.put((0, 0))
d[0][0] = 0
while not que.empty():
    qx, qy = que.get()
    if qx == h-1 and qy == w-1:
        break
        
    for dx, dy in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
        px, py = qx+dx, qy+dy
        if 0 <= px < h and 0<= py < w:
            if s[px][py] == '#':
                continue
            elif d[px][py] != inf:
                continue
            d[px][py] = d[qx][qy] + 1
            que.put((px, py))
            
if d[h-1][w-1] == inf:
    print(-1)
else:
    print(h * w - (d[h-1][w-1]+1) - sum(s[i].count('#') for i in range(h)))

Measured memory_bytes: 4080
#include<bits/stdc++.h>

#define ll long long int
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define pb push_back
#define el '\n'
#define N 1000000007
#define re return
#define PI 3.14159265
#define take(a,n) for(int i=0;i<(n);i++) cin>>(a)[i]
#define out(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";
#define all(a) (a).begin(),(a).end()
#define forup(i,n) for(int (i)=0;i<(n);(i)++)
#define ford(i,n) for(int (i)=(n)-1;i>=0;(i)--)
using namespace std;


ll poww(ll a,ll b)
{
  ll ans=1;
  for(int i=1;i<=b;i++)
  {
    ans*=a;
  }
  return ans;
}


int max(int a,int b,int c)
{
  if(a>=b && a>=c) return a;
  if(b>=a && b>=c) return b;
  return c;
}


int main()
{
  string s;
  int n;
  cin>>n;
  int a[n];
  take(a,n);
  cout<<fixed<<setprecision(9);
  double sum=0.000000000;
  forup(i,n)
  sum+=(double)1.000000000/(double)a[i];
  double x=1.000000000;
  cout<<x/sum;
}


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

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var book = new Dictionary<int, string>(N);
            var P = new int[N];
            for(int i = 0; i < N; i++)
            {
                var s = cin.Read;
                var p = cin.ReadInt;
                P[i] = p;
                book.Add(p, s);
            }
            var tbook = book.OrderByDescending(a => a.Key).OrderBy(a => a.Value);
            foreach(var item in tbook)
            {
                var ans = Array.IndexOf(P, item.Key);
                WriteLine(ans + 1);
            }

        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 11732
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ll = long long int;

int main(){
    string S;
    cin >> S;
    if(S[2] == S[3]&&S[4] == S[5]){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
 
int main(){
    ll x; cin >> x;
    if(x<1200) puts("ABC");
    else puts("ARC");
}


Measured memory_bytes: 256
def main():
  num,capacity,*wv =map(int,open(0).read().split())
  weights,values = wv[::2], wv[1::2]
  DP=[-1]*(capacity+1)
  DP[0]=0
  for weight,value in zip(weights, values):
    left=capacity-weight
    DP[weight:]=[max(DP[i]+value,DP[i+weight]) for i in range(left,-1,-1)][::-1]
  print(max(DP))
      
if __name__=="__main__":
  main()

Measured memory_bytes: 123824
x, y = input().split(' ')
x=int(x)
y=int(y)
lista1=[1,3,5,7,8,10,12]
lista2=[4,6,9,11]
lista3=[2]
if x in lista1 and y in lista1:
    print('Yes')
elif x in lista2 and y in lista2:
    print('Yes')
elif x in lista3 and y in lista3:
    print('Yes')
else:
    print ('No')

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  while (n > 0) {
    ans++;
    n = n / k;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  string ans(N, 'X');
  for (int i{}; i < M; ++i) {
    int s;
    char c;
    cin >> s >> c;
    --s;
    if ((ans[s] != 'X' && ans[s] != c) || N > 1 && s == 0 && c == '0') {
      cout << -1 << endl;
      return 0;
    }
    ans[s] = c;
  }
  if (ans[0] == 'X') {
    if (N == 1)
      ans[0] = '0';
    else
      ans[0] = '1';
  }
  for (int i{1}; i < N; ++i) {
    if (ans[i] == 'X') ans[i] = '0';
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <atcoder/all>

// g++-10 a.cpp -std=c++17 -I .

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int p[225816],q[225816],ans[225816];

int main(void){
	int n,i,x,y;
	std::cin >> n;
	atcoder::scc_graph g(n);
	for(i=0; i<n; ++i){
		std::cin >> x >> y;
		--x; --y;
		p[x] = i; q[y] = i;
	}
	for(i=1; i<n; ++i){
		g.add_edge(p[i-1],p[i]);
		g.add_edge(q[i],q[i-1]);
	}
	for(auto v: g.scc()){
		for(auto e: v){
			ans[e] = v.l_ength();
		}
	}
	for(i=0; i<n; ++i){
		std::cout << ans[i] << std::endl;
	}
	return 0;
}


Measured memory_bytes: 31892
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll, ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // Emily <3
  int n, w;
  cin >> n >> w;
  const int v = 1e5+3;
  VL dp(v, LINF); //dp[i] is the min weight to achieve value i
  dp[0] = 0;
  forx(i,n) {
    ll w1, v1;
    cin >> w1 >> v1;
    for(int i = v-v1; i >= 0; --i) {
      if (dp[i] < LINF) {
        ll temp = dp[i] + w1;
        if (temp <= w) {
          dp[i+v1] = min(dp[i+v1], temp);
        }
      }
    }
  }
  int ans = 0;
  forx(i,v) {
    if (dp[i] != LINF) {
      ans = i;
    }
  }

  cout << ans << nl;
  
  cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl;
  return 0;
}



Measured memory_bytes: 1024
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
using namespace std;

#define ul unsigned long long int

ul choco(ul w, ul h)
{
	ul ans;
	ul dmin = w*h;

	if (w % 3 == 0) {
		return 0;
	}
	else {
		double half = (double)h / 2;
		ul h2 = (ul)floor(half);
		ul h3 = (ul)ceil(half);


		for (int i = 1; i < w; i++) {

			initializer_list<ul> s = { i*h, (w - i)*h2, (w - i)*h3 };
			ul c = max(s) - min(s);
			dmin = min(c, dmin);

			double halfw = (double)(w - i) / 2;
			ul w2 = (ul)floor(halfw);
			ul w3 = (ul)ceil(halfw);
			initializer_list<ul> s2 = { i*h, w2*h, w3*h };
			c = max(s2) - min(s2);
			dmin = min(c, dmin);


		}
	}

	return dmin;
}


int main() {
	ul h, w;
	cin >> h >> w;

	cout << min(choco(w, h), choco(h, w)) << endl;
	return 0;
}






Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	string s="CODEFESTIVAL2016";
  	string t;cin>>t;
  	int ans=0;
  	for(int i=0;i<s.size();i++){
    	if(s[i]!=t[i]) ans++;
    }
  	cout<<ans<<endl;
}

Measured memory_bytes: 256
// KOI NI YAAR SAB SAHI HOEGA  BAS  CHORRO MAT
// ENJOR KARO YAAR
// HAAR MAT MAANO
// // APNA TIME AAYEGA
// BEILIEVE IN GOD
#include<bits/stdc++.h>
using namespace std;
#define lli int
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define loopb(i,a,b) for (lli i=a;i>=b;i--)
#define pb push_back
#define mod 1000000007
#define fast() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) (__gcd((a),(b)))
#define lcm(a,b)(((a)*(b))/gcd((a),(b)))
#define ma 1e18
#define bc __builtin_popcountll
#define vi vector<lli>
#define pr pair<lli,lli>
#define vp vector<pr>
#define F  first
#define S   second
#define lld long double
#define PI  3.14159265358979
#define pri  priority_queue<ll>
#define prim  priority_queue<ll,vector<ll>,greater<ll>>
#define flush  cout<<flush

const lli  N=3e3+10;
 
vector<vector<lld>> dp(N,vector<lld>(N,-1)); 
lli n;
vector<lld>a;
lli ans;



lld solve(lli index , lli tails)
{if(index == n)
{if(tails<=n/2)
{return 1;
}
else
{return 0;
}
}
if(dp[index][tails]!=-1)
{return dp[index][tails];
}
return dp[index][tails] =  ((a[index] * 1 * solve(index+1,tails)) + (1-a[index]) * 1 *  solve(index+1,tails+1));
}

int main()
{fast();
cin>>n;

a.resize(n);
loop(i,0,n)
{cin>>a[i];
}

cout<<fixed<<setprecision(10)<<solve(0,0)<<"\n";
}


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

// マクロ //
#define rep(i,N) for(int i = 0; i < (int)(N); i++)
#define req(i,f,N) for(int i = f; i < (int)(N); i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)
#define db(i) cout << #i << " = " << i;

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vpii = vector<pii>;
using plili = pair<lint, lint>;
using vplili = vector<plili>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvli = vector<vli>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vvs = vector<vs>;
using mii = map<int, int>;
using mili = map<int, lint>;
using mci = map<char, int>;
using mcli = map<char, lint>;
using msi = map<string, int>;
using msli = map<string, lint>;


// 関数 //
template<class T, class Q> lint gcd_(T a, Q b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T, class Q> lint lcm_(T a, Q b) {
    return a * b / gcd_(a, b);
}

using pdd = pair<double, double>;

double distance(pdd a, pdd b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

template<class T, class Q> inline bool chmin(T& a, Q b) {
    if (a > b) { 
        a = b;
        return true; 
    }
    return false;
}

template<class T, class Q> inline bool chmax(T& a, Q b) {
    if (a < b) { 
        a = b; 
        return true; 
    }
    return false;
}

// 定数 //
const double pi = acos(-1);
const int mod = 1000000007;
const int MOD = 998244353;
const int inf = 1045141919;
const lint linf = ((1LL << 62) - 1);


// キーワード //
#define elif else if

// End of Template //



int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    double A, B;
    double H, M;
    cin >> A >> B >> H >> M;
    pair<double, double> a, b;
    a.first = A * sin(((H + (M / 60.0)) * pi) / 6.0);
    a.second = A * cos(((H + (M / 60.0)) * pi) / 6.0);
    b.first = B * sin(M * pi / 30.0);
    b.second = B * cos(M * pi / 30.0);
    cou(distance(a, b));

}

Measured memory_bytes: 4092
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	int N;
	cin >> N;
	long long int cnt[100] = {};
	for(int i = 0; i < N; i++){
		long long int A;
		cin >> A;
		for(int j = 0; j < 61; j++){
			if(A & (1LL << j)){
				cnt[j] += 1;
			}
		}
	}
	long long int ans = 0;
	for(int i = 0; i < 61; i++){
		ans += (1LL << i) % MOD * cnt[i] % MOD * (N - cnt[i]) % MOD;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<ll> a(n + 1), b(n);
	rep (i, n + 1) cin >> a[i];
	rep (i, n) cin >> b[i];
	ll res = 0;
	rep (i, n) {
	  if (a[i] > b[i]) {
		res += b[i];
	  } else {
		res += a[i];
		b[i] -= a[i];
		if (a[i + 1] > b[i]) {
		  a[i + 1] -= b[i];
		  res += b[i];
		} else {
		  res += a[i + 1];
		  a[i + 1] = 0;
		}
	  }
	}
	cout << res << endl;
    
    return 0;
}



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

bool win_check(char c, char d, char e)
{
  if ( c == 'b' && d == 'b' && e == 'b' )
  {
    cout << 'b' << endl;
    return true;
  }
  else if ( c == 'w' && d == 'w' && e == 'w' )
  {
    cout << 'w' << endl;
    return true;
  }
  return false;
}

int main()
{
  while (true)
  {
    char board[3][3];
    for (int i=0; i<3; i++)
    {
      for (int j=0; j<3; j++)
      {
        cin >> board[i][j];
        if (board[i][j] == '0') return 0;
      }
    }

    bool flag = false;

    for (int i=0; i<3; i++)
    {
      flag = win_check(board[i][0], board[i][1], board[i][2]);
      if ( flag ) break;
    }
    if ( flag ) continue;
    
    for (int j=0; j<3; j++)
    {
      flag = win_check(board[0][j], board[1][j], board[2][j]);
      if ( flag ) break;
    }
    if ( flag ) continue;

    flag = win_check(board[0][0], board[1][1], board[2][2]);
    if ( flag ) continue;
    flag = win_check(board[0][2], board[1][1], board[2][0]);
    if ( flag ) continue;

    cout << "NA" << endl;
  }
}

Measured memory_bytes: 1140
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

using static Input;
using static Util;
class Program
{
    static int[] N;
    static void INPUT()
    {
        N = LineInt();
    }
    static void OUT()
    {
        if (1 <= N[0] && N[0] <= 9 && 1 <= N[1] && N[1] <= 9)
        {
            Console.WriteLine(N[0] * N[1]);
        }
        else
            Console.WriteLine(-1);
    }
    static void Main(string[] args)
    {
#if DEBUG  
        TESTINPUT();
        //INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




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

int main()
{
    int x, a, b;
    cin >> x >> a >> b;

    if (a - b >= 0)
    {
        cout << "delicious" << endl;
    }
    else if (b - a <= x)
    {
        cout << "safe" << endl;
    }
    else
    {
        cout << "dangerous" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define INF 1e9
typedef long long llong;
using namespace std;

int main(){
	int n;
	cin>>n;
	
	vector<int> a(n),b(n),c(n);
	REP(i,n) cin>>a[i]>>b[i]>>c[i];
	
	vector<vector<int> > dp(n,vector<int>(3,-INF));
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];
	
	for(int i=1;i<n;++i){
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
	}
	
	cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
	return 0;
}//解答参考.

Measured memory_bytes: 6912
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1 , n):
            if l[i] != l[j] and l[i] != l[k] and l[j] != l[k]:
                if l[i] + l[j] > l[k] and l[i] + l[k] > l[j] and l[k] + l[j] > l[i]:
                    ans += 1
print(ans)


Measured memory_bytes: 9192
// 01/02/20 // 5:08 PM //

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int MAXN = (int)1e2 + 10;
const int MAXK = (int)1e5 + 10;
const int MOD  = (int)1e9 + 7;

int n, k, a[MAXN];
int memo[2][MAXK], prefix[MAXK];

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    cin >> n >> k;
    for(int i=1; i<=n; i++) cin >> a[i];


    for(int i=0; i<=n; i++)            memo[i&1][0] = 1;
    for(int j=0; j<=min(k,a[1]); j++)  memo[1][j] = 1;

    // i = 1
    prefix[0] = memo[1][0];
    for(int j=1; j<=k; j++) prefix[j] = memo[1][j] + prefix[j-1];

    for(int i=2; i<=n; i++){

        for(int j=0; j<=k; j++){

            if(j<=a[i])
                memo[i&1][j] = prefix[j];
            else
                memo[i&1][j] = (prefix[j] - prefix[j-a[i]-1] + MOD)%MOD;

        }

        prefix[0] = memo[i&1][0];
        for(int j=1; j<=k; j++)
            prefix[j] = (memo[i&1][j] + prefix[j-1])%MOD;
    }

    cout << memo[n&1][k] << endl;

    return 0;
}


Measured memory_bytes: 2560
# include <stdio.h>

int main(){
  int s;
  scanf("%d", &s);
  int s1, s2, s3;
  s1 = s/100;
  s2 = (s/10)%10;
  s3 = s%10;
  printf("%d\n",s1 + s2 + s3);
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<list>
#include<ctype.h>
#include<iterator>

using namespace std;

class point{
 public:
  int x;
  int y;
  point(){}
  point(int xa,int ya){
    x=xa;
    y=ya;
  }
};

class chain{
 public:
  list<point> lst;
  char val;
  chain(){
  }
  chain(char v,list<point> ls);
};
chain::chain(char v,list<point> ls){
  val=v;
  lst=ls;
}
char map[8][14];
int isColor(char val){
  return isalpha(val)&&val!='O';
}
int c2i(char c){
  return c=='R'?1:c=='G'?2:c=='B'?3:c=='Y'?4:c=='P'?5:6;
}
char i2c(int i){
  return i==1?'R':i==2?'G':i==3?'B':i==4?'Y':i==5?'P':'?';
}
int sch(chain *chn){
  int i,k,j,ci,prev,s,l,x,y,first;
  chain c;
  list<point>::iterator it;
  list<point> buf,next;
  int dic[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
  for(i=1;i<14;i++)
    for(j=1;j<8;j++)
      if(isColor(map[i][j])){
	first=i;
	goto find;
      }
 find:;
  for(i=first,ci=0;i<14;i++){
    for(j=1;j<8;j++){
      if(isColor(map[i][j])){
	c.val=map[i][j];
	map[i][j]=c2i(c.val);
	buf.push_back(*(new point(j,i)));
	next.clear();
	do{
	  prev=0;
	  it=buf.begin();
	  while(it!=buf.end()){	    
	    for(l=0;l<4;l++){
	      x=it->x+dic[l][1];
	      y=it->y+dic[l][0];
	      if(c.val==map[y][x]){
		next.push_back(*(new point(x,y)));
		map[y][x]=c2i(c.val);
		prev++;
	      }
	    }
	    c.lst.push_back(*it);
	    it++;
	  }
	  buf.clear();
	  copy(next.begin(),next.end(),back_inserter(buf));
	  next.clear();
	}while(prev);
	if(c.lst.size()>=4){
	  chn[ci].val=c.val;
	  it=c.lst.begin();
	  while(it!=c.lst.end()){
	    chn[ci].lst.push_back(*it);
	    it++;
	  }
	  ci++;
	}
	c.lst.clear();
      }
    }
  }
  for(i=first;i<14;i++){
    for(j=1;j<8;j++){
      if(map[i][j]>=1&&map[i][j]<=5){
	map[i][j]=i2c(map[i][j]);
      }
    }
  }
  return ci;
}
int main(){
  int i,k,n,cn,bs,p,j,count;
  chain ch[18];
  int dic[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
  list<point>::iterator it;
  scanf("%d",&n);
  for(p=0;p<n;p++){
    count=0;
    for(i=1,bs=0;i<13;i++) scanf("%s",map[i]+1);
    do{
      cn=sch(ch);
      if(!cn) break;
      count++;
      for(i=0;i<cn;i++){
	it=ch[i].lst.begin();
	while(it!=ch[i].lst.end()){
	  for(k=0;k<4;k++)
	    if(map[it->y+dic[k][0]][it->x+dic[k][1]]=='O')
	      map[it->y+dic[k][0]][it->x+dic[k][1]]='F';
	  map[it->y][it->x]='F';
	  it++;
	}
      }
      for(i=1;i<13;i++){
	for(j=1;j<8;j++){
	  if(map[i][j]=='F'){
	    for(k=i-1;k>0;k--){
	      if(map[k][j]!='.'){
		map[k+1][j]=map[k][j];
	      }else{
		break;
	      }
	    }
	    map[k+1][j]='.';
	  }
	}
      }
      for(i=0;i<cn;i++){
	ch[i].lst.clear();
      }
    }while(1);
    printf("%d\n",count);
  }
  return 0;
}

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



#define bstN 600000
struct bst{

  int size;
  int t[bstN];
  int lc[bstN];
  int rc[bstN];
  
  void init(){
    size=0;
  }
  
  void insert(int v){
    int i=0;
    while(i<size){
      int& child=(v<t[i]?lc[i]:rc[i]);
      if(child==-1)child=size;
      i=child; 
    }
    lc[size]=rc[size]=-1;
    t[size++]=v;
  }

  void preord(int pos){
    if(pos==-1||pos==size)return;
    preord(lc[pos]);
    printf(" %d",t[pos]);
    preord(rc[pos]);
  }
  
  void inord(int pos){
    if(pos==-1||pos==size)return;
    printf(" %d",t[pos]);
    inord(lc[pos]);
    inord(rc[pos]);
  }
};


bst T;

int main(){
  T.init();
  int n,a;
  char str[100];
  scanf("%d",&n);
  
  while(n--){
    scanf("%s",str);
    if(str[0]=='i'){
      scanf("%d",&a);
      T.insert(a);
    }else{
      T.preord(0);
      printf("\n");
      T.inord(0);
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 7756
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>   
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
 
int n;
int main(){
    while(cin>>n,n){
        map<string,int>ma;
        vs name(n);
        vi b(n),co(n);
        vector<vs>in(n);
        rep(i,n){
            cin>>name[i]>>b[i]>>co[i];
            ma[name[i]]=1;
            in[i]=vs(co[i]);
            rep(j,co[i]){
                cin>>in[i][j];
                ma[in[i][j]]=1;
            }
        }
        int t=0;
        rep(i,n)ma[name[i]]=i;
     
        vector<ll>A(n);
        rep(i,n)rep(j,in[i].size()){
            int from=ma[name[i]],to=ma[in[i][j]];
            A[from]|=1ll<<to;
        }
        int N=n/2,nN=n-N;
         
//      rep(i,n){
//          cout<<name[i]<<" ";
//          rep(j,n)cout<<((A[i]&1<<j)>>j)<<" ";cout<<endl;
//      }
        vi dp(1<<nN);
        rep(i,1<<nN){
            bool h=true;
            rep(j,nN)if((i&1<<j)&&((i&A[j+N]>>N)))h=false;
            if(h){
                int sum=0;
                rep(j,nN)if(i&1<<j)sum+=b[N+j];
                dp[i]=max(dp[i],sum);
            }
            rep(j,nN)if((i&1<<j)==0)
                dp[i|1<<j]=max(dp[i|1<<j],dp[i]);
        }
         
        int out=0;
        rep(i,1<<N)if(i&1){
            bool h=true;
            int sum=0;
            rep(j,N)if((i&1<<j)){
                sum+=b[j];
                if(i&A[j])h=false;
            }
            if(h){
                t=(1<<nN)-1;
                rep(j,N)if((i&1<<j))t&=~(A[j]>>N);
                out=max(out,sum+dp[t]);
            }           
        }
        cout<<out<<endl;
    }
}
 


Measured memory_bytes: 7300
#include "bits/stdc++.h"
using namespace std;

int main() {
	int M, K;
	cin >> M >> K;
	if (K == 0) {
		for (int i = 0; i < pow(2, M); i++) {
			if (i != 0) cout << " ";
			cout << i << " " << i;
		}
	}
	else if (M == 1 && K == 1) cout << -1;
	else if (K < pow(2, M)) {
		cout << K << " ";
		for (int i = 0; i < pow(2, M); i++) {
			if (i != K) cout << i << " ";
		}
		cout << K;
		for (int i = pow(2, M) - 1; i >= 0; i--) {
			if (i != K) cout << " " << i;
		}
	}
	else cout << -1;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long int ll;
typedef pair<int,int> ii;
vector<int> v;

int n,x;
double sum;
double ans;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);

	cin>>n;
	while(n--)
	{
		cin>>x;
		v.push_back(x);
	}

	sort(v.begin(),v.end());
	sum = v[0];

	for(int i=1;i<v.size();++i)
	{
		sum = double(v[i]+sum)/2;
	}

	cout<<fixed<<setprecision(6);
	cout<<sum<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
constexpr long long INF = 1e18;

int dp[303][303][303];
map<int,int>mp;

signed main(){
	int N,K;
	cin>>N>>K;
	vector<int>a(N);
	int cnt = 0;
	REP(i,N){
		cin>>a[i];
		if(!mp.count(a[i]))mp[a[i]]=cnt++;
	}
	REP(i,303)REP(j,303)REP(k,303)dp[i][j][k]=INF;
	mp[0]=cnt++;
	vector<int>mpInv(cnt);
	for(auto e:mp){
		mpInv[e.second]=e.first;
	}
	dp[0][0][mp[0]]=0;
	REP(i,N){
		REP(j,K+1){
			REP(k,cnt){
				if(dp[i][j][k]==INF)continue;
				CHMIN(dp[i+1][j+1][k],dp[i][j][k]);
				CHMIN(dp[i+1][j][mp[a[i]]],dp[i][j][k]+max(0ll,a[i]-mpInv[k]));
			}
		}
	}
	int ans = INF;
	REP(i,cnt)CHMIN(ans,dp[N][K][i]);
	cout<<ans<<endl;
}

Measured memory_bytes: 217600
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
  int n;
  cin >> n;
  vector<vector<int> > v(n,vector<int>(3));
  vector<vector<int> > dp(n,vector<int>(3));
  for(int i=0;i<n;i++){
    cin >> v[i][0] >> v[i][1] >> v[i][2];
  }

  dp[0][0]=v[0][0];
  dp[0][1]=v[0][1];
  dp[0][2]=v[0][2];

  for(int i=1;i<n;i++){
    dp[i][0]=v[i][0]+((dp[i-1][1] > dp[i-1][2])
      ?dp[i-1][1]
      :dp[i-1][2]);
    dp[i][1]=v[i][1]+((dp[i-1][0] > dp[i-1][2])
      ?dp[i-1][0]
      :dp[i-1][2]);
    dp[i][2]=v[i][2]+((dp[i-1][1] > dp[i-1][0])
      ?dp[i-1][1]
      :dp[i-1][0]);
  }

  cout << *(max_element(dp[n-1].cbegin(),dp[n-1].cend())) << endl;
  return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{
  int N,A,B;
  cin>>N>>A>>B;
  vector<int> data(N);
  for (int i = 0; i < N; i++)
  {
    cin>>data[i];
  }
  vector<int> diff(N);
  for (int i = 0; i < N-1; i++)
  {
    diff[i+1] = data[i+1] - data[i];
  }
  diff[0] = 0;

  for (int i = 0; i < N; i++)
  {
    if(diff[i]*A > B)
    {
      diff[i] = -1;
    }
  }

  int ANS = 0;
  for (int i = 0; i < N; i++)
  {
    if(diff[i] == -1) ANS += B;
    else
    {
      ANS += diff[i]*A;
    }
  }
  cout<<ANS<<endl;
  
  
  

  
  

  return; 
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			int n=in.nextInt();
			TreeMap<String, Integer> m1 = new TreeMap<String, Integer>();
			TreeMap<String, Integer> m2 = new TreeMap<String, Integer>();
			TreeMap<String, Integer> m3 = new TreeMap<String, Integer>();
			TreeMap<String, Integer> m4 = new TreeMap<String, Integer>();
			TreeMap<String, Integer> m5 = new TreeMap<String, Integer>();

			for(int i=0;i<n;i++)
			{
				String s=in.next();
				int cnt=in.nextInt();

				if(s.length()==1)
				{
					if(m1.containsKey(s))
					{
						cnt+= m1.get(s);
						
					}
					m1.put(s,cnt);
				}
				else if(s.length()==2)
				{
					if(m2.containsKey(s))
					{
						cnt+=m2.get(s);
						
					}
					m2.put(s,cnt);
				}
				else if(s.length()==3)
				{
					if(m3.containsKey(s))
					{
						cnt+=m3.get(s);
						
					}
					m3.put(s,cnt);
				}
				else if(s.length()==4)
				{
					if(m4.containsKey(s))
					{
						cnt+=m4.get(s);
						
					}
					m4.put(s,cnt);
				}
				else if(s.length()==5)
				{
					if(m5.containsKey(s))
					{
						cnt+=m5.get(s);
						
					}
					m5.put(s,cnt);
				}
			}
			
			 for (Map.Entry<String, Integer>   entry : m1.entrySet()) {
		            System.out.println(entry.getKey()+" "+entry.getValue());
		        }
		    for (Map.Entry<String, Integer>   entry : m2.entrySet()) {
		            System.out.println(entry.getKey()+" "+entry.getValue());
		        }
		    for (Map.Entry<String, Integer>   entry : m3.entrySet()) {
		            System.out.println(entry.getKey()+" "+entry.getValue());
		        }
		    for (Map.Entry<String, Integer>   entry : m4.entrySet()) {
		            System.out.println(entry.getKey()+" "+entry.getValue());
		        }
		    for (Map.Entry<String, Integer>   entry : m5.entrySet()) {
		            System.out.println(entry.getKey()+" "+entry.getValue());
		        }
			
		}
	}

	static public void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 38292
def parent(i):
    return i//2

def left(i):
    return 2 * i

def right(i):
    return (2 * i) + 1

def maxHeapify(A, i):
    l = left(i)
    r = right(i)

    if l <= n and A[l] > A[i]:
        largest = l
    else:
        largest = i

    if r <=n and A[r] > A[largest]:
        largest = r

    if largest != i:
        A[largest], A[i] = A[i], A[largest]
        maxHeapify(A, largest)

def buildMaxHeap(A):
    for i in range(n//2, 0, -1):
        maxHeapify(A, i)
    
if __name__ == "__main__":
    n = int(input())
    A = [None]
    A.extend(list(map(int, input().split())))
    buildMaxHeap(A)
    print(" " + ' '.join(map(str, A[1:])))


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


int main(){
    string S,T,U;
    int A,B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;
    if(U==S) cout << A-1 << " " << B;
    else cout << A << " " << B-1;
    return 0;
}


Measured memory_bytes: 504
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main(){
  long long mod = 1e9+7;
  long long N, K;
  cin >> N >> K;
  vector<int> A(N);
  for(auto &a : A) cin >> a;
  long long ans = 0;
  for(int i = 0; i < N; ++i){
    for(int j = i+1; j < N; ++j){
      ans += (A[i] > A[j]);
    }
  }
  ans *= K;
  ans %= mod;
  vector<int> B = A;
  sort(B.begin(), B.end());
  for(int i = 0; i < N; ++i){
    long long t = K*(K-1)/2;
    t %= mod;
    long long x = lower_bound(B.begin(), B.end(), A[i]) - B.begin();
    ans += t*x%mod;
    ans %= mod;
  }
  cout << ans << endl;
}


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

int main() {


  int n,a,b;
  cin >> n >> a >> b;

  int total = 0;
  for(int i=1 ; i <= n ; i++){
    int sum = 0;
    int tmp = i;
    while(tmp > 0){
      sum += tmp%10;
      tmp /= 10;
    }
    if(a<=sum && sum<=b){
      //cout << "i=" << i << " -- sum"<<sum << endl;
      total += i;
    }
  }
  cout << total << endl;
  
  
  return 0;
}



Measured memory_bytes: 256
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	"reflect"
)

func showType(obj interface{}){
	v:=reflect.ValueOf(obj)
	fmt.Println(v.Type())
}

func main(){
	//stdinから読み込み
	sc:=bufio.NewScanner(os.Stdin)
	//1行読み込む(Splitの設定が1行になっているため)
	//scanner.Split(bufio.ScanWords) // 1単語ごと
	//scanner.Split(bufio.ScanLines) // 1行ごと（デフォルト）と変更可能
	

	num_slice:=make([]int,0)

	//読み込み
	//0が出現するまで読み込みを継続する
	for{
		sc.Scan()
		line:=sc.Text()
		num,_:=strconv.Atoi(line)

		if num==0{
			break
		}
		num_slice=append(num_slice,num)
	}
	

	//エラー処理
	if err:=sc.Err();err!=nil{
		fmt.Println("fail to read stdio")
	}

	for idx,num:=range(num_slice){
		fmt.Printf("Case %d: %d\n",idx+1,num)
	}


}


Measured memory_bytes: 1672
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

string s;
int main(void){
    cin >> s;
    for(int i=0;i<s.length();i++){
        if (s[i] == '?') cout << 'D';
        else cout << s[i];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3744
#include <iostream>

using namespace std;

const int MAX_N = 1e5 + 5;

int arr [MAX_N];

int main () {
  ios::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;

  int ans = 4e8 + 5;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }

  for (int i = 0; i + k - 1 < n; i++) {
    int l = arr[i];
    int r = arr[i + k - 1];

    if (r <= 0) {
      ans = min(ans, abs(l));
    } else if (l <= 0 && 0 <= r) {
      ans = min(ans, abs(l) + r - l);
      ans = min(ans, abs(r) + r - l);
    } else {
      ans = min(ans, r);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
#![macro_use]

use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::mem::*;
use std::num::*;
use std::slice::*;
use std::*;

fn main() {
    let (r, w, e) = (stdin(), stdout(), stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    // =============================================== //
    let n: usize = io.read();
    let mut c = io.readn::<i64>(n);
    c.sort();
    let mut ans = 0;
    let MOD = 1e9 as i64 + 7;
    let p = mod_pow(4, (n - 1) as u64, MOD as u64) as i64;

    for i in 0..n {
        ans += (c[i] * (2i64 + (n - i - 1) as i64) % MOD) * p % MOD;
        ans %= MOD;
        ans += MOD;
        ans %= MOD;
    }
    io.writeln(ans);
}
fn mod_pow(x: u64, n: u64, m: u64) -> u64 {
    let mut res = 1;
    let mut x = x % m;
    let mut n = n;
    while n > 0 {
        if n & 1 == 1 {
            res = (res * x) % m;
        }
        x = (x * x) % m;
        n >>= 1;
    }
    res
}

// IO
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug ) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
}


Measured memory_bytes: 6396
#include<iostream>
using namespace std;
int main()
{
int a ,s;
cin>>a>>s;
int m=0;
for(int p=1;p<=s;p++)
{
int b;
cin>>b;
m=m+b;
}
if(m>=a)
{
cout<<"Yes";
}
else
{
cout<<"No";
}
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

#define REP(i,n)    for(int i = 0; i < (n); i++)

using namespace std;

int main(int argc, const char * argv[]) {
    int A = 0;
    int B = 0;
    int C = 0;
    cin >> A >> B >> C;

    int free = A - B;// free space of container 1
    int left = max(C-free, 0);
    cout << left << endl;

    return 0;
}

/**
 cheat sheet

 vector<int> v{ 1, 5, 8, 9, 6, 7, 3, 4, 2, 0 };
 sort(v.begin(), v.end());
 => 0 1 2 3 4 5 6 7 8 9

 vector<int> v{ 1, 5, 8, 9, 6, 7, 3, 4, 2, 0 };
 sort(v.begin(), v.end(), greater<int>());
 => 9 8 7 6 5 4 3 2 1 0

 struct A { int x, y; };
 bool comp(A i1, A i2) { return (i1.y < i2.y); }
 vector<A> v { { 6, 8 }, { 1, 9 }, { 2, 4 }, { 4, 7 } };
 sort(v.begin(), v.end(), comp);
 => [1, 9] [2, 4] [4, 7] [6, 8]

 */


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define ALL(x) (x).begin(),(x).end()
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main(){
	string S;
	cin >> S;
	int N = S.size();
	deque<char> D;
	for(int i = 0; i < N; i++){
		if(S[i] == '0' || S[i] == '1'){
			D.push_back(S[i]);
		}else{
			if(D.empty()){
				continue;
			}else{
				D.pop_back();
			}
		}
	}
	while(!D.empty()){
		cout << D.front();
		D.pop_front();
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")

using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)

#define ynmes(a) (a) ? mes("Yes") : mes("No")
#define YNmes(a) (a) ? mes("YES") : mes("NO")
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

ll nlcm(vector<ll> numbers) {
    ll res;
    res = numbers[0];
    for (ll i = 1; i < (ll)numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}


signed main() {
    ll n;
    cin >> n;
    
    vll a(n);
    rep(i, n) {
        cin >> a[i];
    }
    
    mes(nlcm(a));
    
    
    
}


Measured memory_bytes: 3636
// Tax Rate Changed
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			boolean onTheFloor = true;
			boolean lf = true;
			boolean rf = true;
			int result = 0;
			for (int i = 0; i < n; i++) {
				String input = sc.next();
				if (input.equals("lu"))
					lf = false;
				else if (input.equals("ru"))
					rf = false;
				else if (input.equals("ld"))
					lf = true;
				else
					rf = true;
				if (!onTheFloor && lf && rf) {
					onTheFloor = true;
					result++;
				}
				if (onTheFloor && !lf && !rf) {
					onTheFloor = false;
					result++;
				}
			}
			System.out.println(result);
		}
		sc.close();
	}
}

Measured memory_bytes: 27080