akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include "bits/stdc++.h" // define macro "/D__MAI"

using namespace std;
typedef unsigned int uint;
typedef long long int ll;
typedef unsigned long long int ull;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define debugaar(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[y][x]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define repeat(l) for(auto cnt=0;cnt<(l);++cnt)
#define upto(l,r) for(auto cnt=l;cnt<=r;++cnt)
#define downto(r,l) for(auti cnt=r;cnt>=l;--cnt)
#define BIGINT 0x7FFFFFFF
#define MD 1000000007ll
#define PI 3.1415926535897932384626433832795

#define TIME chrono::system_clock::now()
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())
namespace {
    std::chrono::system_clock::time_point ttt;
    void tic() { ttt = TIME; }
    void toc() { fprintf(stderr, "TIME : %lldms\n", MILLISEC(TIME - ttt)); }
    std::chrono::system_clock::time_point tle = TIME;
#ifdef __MAI
    void safe_tle(int msec) { assert(MILLISEC(TIME - tle) < msec); }
#else
#define safe_tle(k) ;
#endif
}

#ifdef __MAI //_getchar_nolock
#define getchar_unlocked getchar
#endif
namespace {
    class MaiScanner {
    public:
        template<typename T>
        void input_integer(T& var) {
            var = 0;
            T sign = 1;
            int cc = getchar_unlocked();
            for (; cc<'0' || '9'<cc; cc = getchar_unlocked())
                if (cc == '-') sign = -1;
            for (; '0' <= cc&&cc <= '9'; cc = getchar_unlocked())
                var = (var << 3) + (var << 1) + cc - '0';
            var = var*sign;
        }
        inline int c() { return getchar_unlocked(); }
        inline MaiScanner& operator>>(int& var) {
            input_integer<int>(var);
            return *this;
        }
        inline MaiScanner& operator>>(long long& var) {
            input_integer<long long>(var);
            return *this;
        }
    };
}
MaiScanner scanner;



int width, height;
int m, n, kei;

int main() {
    int i, j, k;
    ll x, y, z, a, b, c;

    scanner >> x >> y >> z;

    set<pair<ll, ll>> s;

    repeat(100000) {
        //cout << x << " " << y << " " << z << endl;
        if ((x & 1) || (y & 1) || (z & 1)) {
            cout << cnt << endl;
            return 0;
        }
        pair<ll, ll> key = make_pair(x, (y << 32ll) | z);
        if (s.count(key)) {
            cout << -1 << endl;
            return 0;
        }
        s.insert(key);

        a = x / 2;
        b = y / 2;
        c = z / 2;
        x = b + c;
        y = a + c;
        z = a + b;
    }

    cout << -1 << endl;

    return 0;
}

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

const int N = 5010;
string str[N * 6];
char s[N];
int n, k, cnt;

int main() {
    ios::sync_with_stdio(false);
    cin >> s >> k;
    n = strlen(s);
    for (int i = 0, T; i < n; i++) {
        str[++cnt] = s[i];
        T = min(k, n - i);
        for (int j = 1; j < T; j++, cnt++) str[cnt + 1] = str[cnt] + s[i + j];
    }
    sort(str + 1, str + cnt + 1);
    unique(str + 1, str + cnt + 1);
    cout << str[k] << endl;
    return 0;
}


Measured memory_bytes: 1664
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		Set<Integer> set = new HashSet<>();
		
		set.add(a);
		set.add(b);
		set.add(c);

		System.out.println(set.size());

		sc.close();

	}

}

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

struct node{
  int key;
  struct node *p;
  struct node *l;
  struct node *r;
};

typedef struct node *NodePointer;

NodePointer r,NIL;

NodePointer getMinimum(NodePointer x){
  while(x->l != NIL){
    x = x->l;
  }
  return x;
}


NodePointer find(NodePointer x,int k){
  while(x != NIL && k != x->key){
    if(k < x->key){
      x = x->l;
    }else{
      x = x->r;
    }
  }
  return x;
}

NodePointer getSuccessor(NodePointer x){
  NodePointer y;
  if(x->r != NIL){
    return getMinimum(x->r);
  }

  y = x->p;
  while(y != NIL && x ==y->r){
    x = y;
    y = y->p;
  }

  return y;
}

void delete(NodePointer z){
  NodePointer x;
  NodePointer y;

  if(z->l == NIL || z->r == NIL){
    y = z;
  }else{
    y = getSuccessor(z);
  }

  if(y->l != NIL){
    x = y->l;
  }else{
    x = y->r;
  }

  if(x != NIL){
    x->p = y->p;
  }

  if(y->p == NIL){
    r = x;
  }else{
    if(y == y->p->l){
      y->p->l = x;
    }else{
      y->p->r = x;
    }
  }

  if(y != z){
    z->key = y->key;
  }
}

void insert(int k){
  NodePointer y = NIL;
  NodePointer x = r;

  NodePointer z = (NodePointer)malloc(sizeof(struct node));
  z->key = k;
  z->l = NIL;
  z->r = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->l;
    }else{
      x = x->r;
    }
  }
  z->p = y;

  if(y == NIL){
    r = z;
  }else if(z->key < y->key){
    y->l = z;
  }else{
    y->r = z;
  }
}

void inorder(NodePointer u){
  if(u == NIL){
    return;
  }
  inorder(u->l);
  printf(" %d",u->key);
  inorder(u->r);
}

void preorder(NodePointer u){
  if(u == NIL){
    return;
  }
  printf(" %d",u->key);
  preorder(u->l);
  preorder(u->r);
}

void print(){
  inorder(r);
  puts("");
  preorder(r);
  puts("");
}

int main(){
  int n,i,j,z,x;
  char s[10];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",s);
    if(s[0] == 'f'){
      scanf("%d",&x);
      NodePointer t = find(r,x);
      if(t == NIL)printf("no\n");
      else printf("yes\n");

    }else if(s[0] == 'i'){
      scanf("%d",&z);
      insert(z);
    }else if(s[0] == 'd'){
      scanf("%d",&z);
      delete(find(r,z));
    }else{
      print();
    }
  }

  return 0;
}



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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define maxs(a,b) a=max(a,b)
#define mins(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

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

    int x=(double)(n+1)*100/108;

    if(x*108/100==n)cout<<x<<endl;
    else cout<<":("<<endl;
    
    return 0;
}

Measured memory_bytes: 256
MOD = 10**9 + 7
S = input()

d = "ABC".index
s = [0]*4

s[0] = 1
for c in S:
    if c == "?":
        s = [s[0]*3, s[1]*3 + s[0], s[2]*3 + s[1], s[3]*3 + s[2]]
        for i in range(4):
            s[i] %= MOD
    else:
        i = d(c)
        s[i+1] += s[i] % MOD
print(s[3] % MOD)


Measured memory_bytes: 3188
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = n * 2;
        if(n % 2 == 0){
            System.out.println(n);
            return;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
n,x = map(int,input().split())
A = list(map(int,input().split()))
 
ans = 0
if A[0] > x:
    ans = A[0] - x
    A[0] = x

for i in range(n-1):
    if A[i] + A[i+1] > x:
        ans += A[i] + A[i+1] - x
        A[i+1] -= A[i] + A[i+1] - x
print(ans)

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

int bubbleSortAndReturnCount(int[], int);
void displayElements(int[], int);

int main() {
  int n, a[100];
  int count;
  cin >> n;
  for(int i = 0; i < n ; i++) cin >> a[i];
  count = bubbleSortAndReturnCount(a, n);
  displayElements(a, n);
  cout << count << "\n";
  return 0;
}

int bubbleSortAndReturnCount(int a[], int n) {
  int count = 0;
  int flag = 1;
  int headOfSortedData = 0;
  while(flag) {
    flag = 0;
    for(int i = n - 1; i >= headOfSortedData + 1; i--) {
      if(a[i] < a[i-1]) {
        swap(a[i], a[i-1]);
        flag = 1;
        count++;
      }
    }
    headOfSortedData++;
  }
  return count;
}

void displayElements(int a[], int n) {
  cout << a[0];
  for(int i = 1; i < n; i++) cout << " " << a[i];
  cout << "\n";
}


Measured memory_bytes: 3116
#include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 1000000007
#define inf 1000000000000000000ll
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x,ll y, ll md=inf){ll res = 1;x%=md;while(y){if(y&1)res = (res*x)%md;x *= x; if(x>=md) x %= md; y >>= 1;}return res;}
 
using namespace std;


#define endl '\n'
#define int ll

signed main() {
	fast;

	int h,w;
	cin>>h>>w;

	vector<pii> v(h);
	for(int i=0;i<h;i++) cin>>v[i].f>>v[i].s;

	map<int,int> mp;
	for(int i=1;i<=w;i++) mp[i] = 0;

	map<int, int> mini = {{0,w}};

	for(int i=0;i<h;i++) {
		int l = v[i].f;
		int r = v[i].s;

		auto it = mp.lower_bound(l);
		int mn = inf;

		while(it!=mp.end() && it->f <= r) {
			mn = min(mn, r+1-(it->f)+(it->s));
			auto it1 = it++;
			mini[it1->s]--;
			if(mini[it1->s]==0) mini.erase(it1->s);
			mp.erase(it1);
		}

		if(r+1<=w && mn<inf) {
			if(mp.count(r+1) && mp[r+1] > mn) {
				mini[mp[r+1]]--;
				if(mini[mp[r+1]]==0) mini.erase(mp[r+1]);
				mini[mn]++;
				mp[r+1] = mn;
			}
			else if(!mp.count(r+1)){
				mp[r+1] = mn;
				mini[mn]++;
			}
		}

		if(mini.size()) cout<<mini.begin()->f+i+1<<endl;
		else cout<<-1<<endl;

	}
}

Measured memory_bytes: 18720
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
template<class T> inline bool chmin(T& a, T 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; }


int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())
#define rSORT(v) std::sort(v.begin(), v.end(),std::greater<int>())


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n ,k;
    cin >> n >>k;
    
    cout <<n-k+1 <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int prime[1000000];

int main(void)
{
	int n;
	int i, j;
	int count;
	
	prime[0] = 0;
	prime[1] = 0;
	
	for (i = 2; i < 1000000; i++){
		prime[i] = 1;
	}
	
	for (i = 2; i * i < 10000000; i++){
		if (prime[i] == 1){
			for (j = i * i; j < 1000000; j += i){
				prime[j] = 0;
			}
		}
	}
	
	while (scanf("%d", &n) != EOF){
		count = 0;
		for (i = 0; i <= n; i++){
			if (prime[i] == 1){
				count++;
			}
		}
		printf("%d\n", count);
	}
	return (0);
}

Measured memory_bytes: 4496
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	int n, s1, s2, mi=99999999;
	vector<int> v;

	cin>> n;
	v.resize(n);
	for(int i=0;i<n;i++){
		cin>> v[i];
	}
	
	for(int i=0;i<v.size();i++){
		s1=0;
		s2=0;
		for(int j=0;j<i;j++) s1+=v[j];
		for(int j=i;j<n;j++) s2+=v[j];
		mi=min(mi, abs(s2-s1));
	//cout<< s1 << " " << s2 << endl;
	}

	cout<< mi << endl;


}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d%d", $n, $d);
for ($i = 0; $i < $n; $i++) $x[$i] = explode(" ", trim(fgets(STDIN)));
$ans = 0;
for ($i = 0; $i < $n; $i++) for ($j = 0; $j < $n; $j++) {
  if ($i < $j) {
    $tmp = 0;
    for ($k = 0; $k < $d; $k++) $tmp += pow($x[$i][$k] - $x[$j][$k], 2);
    if (sqrt($tmp) == (int)sqrt($tmp)) $ans++;
  }
}
echo $ans;
?>

Measured memory_bytes: 4728
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())

using namespace std;


int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,A,B;
    cin >> N >> A >> B;
    int Acount = 0;
    int ABcount = 0;
    int Bcount = 0;
    int tmp;
    REP(i,N){
        cin >> tmp;
        if(tmp <= A){
            Acount++;
        }else if(tmp <= B){
            ABcount++;
        }else{
            Bcount++;
        }
    }

    int count = Acount;
    if(count > ABcount) count = ABcount;
    if(count > Bcount) count = Bcount;

    cout << count << endl;


    

    return 0;
}

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

#define fast ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define fl(i,a,n) for(int i=a; i<n; i++)
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define test()  int tt;  cin>>tt;  while(tt--)
#define nl  cout<<"\n"
#define pii pair<int,int>
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)    {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}
const int mod=1e9+7;


void solve()    {
        int n;  cin>>n;
        ll cnt=0;
        fl(i,1,n+1)     {
                if(i%3!=0 && i%5!=0)    cnt+=i;
        }
        cout<<cnt;
}
/*  Integer Overflow  */
int main()  {
    fast;
    //test()
        solve();
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
vector <char> v;
vector<int> num;
string s ;
int table[2][101];
int main(){
  long int a,b;
  s = "Odd";
  cin >> a>>b;
  if ((a*b)%2==0)s = "Even";
  cout <<s <<endl;
  return 0;
}


Measured memory_bytes: 256
#include<cmath>
#include<iostream>
bool prime(int x){
    if(x==2){
        return true;
    }
    if(x<2 || x%2==0){
        return false;
    }
    int loop=3;
    while(loop<=std::sqrt(x)){
        if(x%loop==0){
            return false;
        }
        loop+=2;
    }
    return true;
}
int main(void){
    int n,x,ans=0;
    std::cin>>n;
    for(int loop=0;loop<n;loop++){
        std::cin>>x;
        bool tr_fa=prime(x);
        if(tr_fa==true){
            ans+=1;
        }
    }
    std::cout<<ans<<std::endl;
    return 0;
}


Measured memory_bytes: 3116
# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
  return pow(a, mod-2, mod)

# nCr mod m
# modinvが必要
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
  r = min(r, n-r)
  res = 1
  for i in range(r):
    res = res * (n - i) * modinv(i+1, mod) % mod
  return res

n, a, b = map(int, input().split())
MOD=10**9+7

# すべての組み合わせ = 2 ** n - 1
all_comb = 2 ** n - 1

NG_comb_a = combination(n, a)
NG_comb_b = combination(n, b)

ans = (all_comb - NG_comb_a - NG_comb_b) % MOD

print(ans)

Measured memory_bytes: 405792
N = int(input())
S = input()
arr = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
c = ""
for s in S:
    c = c + arr[arr.find(s)+N:arr.find(s)+N+1]
print(c)

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


#define ll long long
#define ld long double

int main()
{

    double n;

    cin>>n;


    double x=n/3;


    cout<<showpoint;
    cout<<setprecision(13);

    cout<<x*x*x<<endl;




    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 240000
typedef long long LL;
const LL mod = 1000000007;
LL A[maxn], D;
LL mi[2][maxn * 4];
void build(int p, int o, int l, int r){
	if(l == r){
		mi[p][o] = p ? D * l + A[l] : - D * l + A[l];
		return;
	}
	int m = (l + r) >> 1;
	build(p, o * 2, l, m);
	build(p, o * 2 + 1, m + 1, r);
	mi[p][o] = min(mi[p][o * 2], mi[p][o * 2 + 1]);
}
LL ask(int p, int o, int l, int r, int L, int R){
	if(l >= L && r <= R) return mi[p][o];
	int m = (l + r) >> 1;
	LL ret = 1E18;
	if(L <= m) ret = min(ret, ask(p, o * 2, l, m, L, R));
	if(R > m) ret = min(ret, ask(p, o * 2 + 1, m + 1, r, L, R));
	return ret;
}
void update(int p, int o, int l, int r, int i){
	if(l == r) mi[p][o] = 1E18;
	else{
		int m = (l + r) >> 1;
		if(i <= m) update(p, o * 2, l, m, i);
		else update(p, o * 2 + 1, m + 1, r, i);
		mi[p][o] = min(mi[p][o * 2], mi[p][o * 2 + 1]);
	}
}
vector<pair<LL, int> > v;
int main(){
	int N;
	cin >> N >> D;
	LL ans = D * (N - 1);
	for(int i = 1; i <= N; i += 1){
		cin >> A[i];
		ans += A[i] << 1;
	}
	ans -= A[1] + A[N];
	for(int i = 2; i < N; i += 1) v.push_back(make_pair(A[i], i));
	sort(v.begin(), v.end());
	build(0, 1, 1, N);
	build(1, 1, 1, N);
	for(auto p : v){
		int i = p.second;
		LL L = ask(0, 1, 1, N, 1, i - 1) + D * i - A[i];
		LL R = ask(1, 1, 1, N, i + 1, N) - D * i - A[i];
		if(L >= 0 && R >= 0) continue;
		ans += min(L, R);
		update(0, 1, 1, N, i);
		update(1, 1, 1, N, i);
	}
	cout << ans;
}

Measured memory_bytes: 18924
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
A,B,C = map(int, input().split())

cnt = 0
while A % 2 == B % 2 == C % 2 == 0:
    cnt += 1
    A, B, C = B // 2 + C // 2, A // 2 + C // 2, A //2 + B // 2
    if cnt == int(1e6):
        break
if cnt == 1e6:
    print(-1)
else:
    print(cnt)


Measured memory_bytes: 3316
import java.io.*;
import java.util.Scanner;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		sc.nextInt();
		int k = sc.nextInt();
		
		char[] s = sc.next().toCharArray();
		
		s[k - 1] = (char)(s[k - 1] - 'A' + 'a');
		
		pr.println(s);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


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

int main(){
    int K,N;
	cin >> K >> N;
    vector<int> A(N);
    vector<int> B(N);
    for (int i = 0; i < N; i++) {
    cin >> A[i]; 
    }
    for (int i = 0; i < N-1; i++){
    B[i] = A[i+1]-A[i];
    }
    B[N-1]=K+A[0]-A[N-1];
    sort(B.begin(), B.end());
    cout << K-B[N-1] <<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

const int N = 2e5 + 10;
int a[N], pre[N];

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

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

//  int ops = 0;
  while (k--) {
    memset(pre, 0, sizeof pre);
    for (int i = 1; i <= n; i++) {
      pre[max(1, i - a[i])]++;
      pre[min(n, i + a[i]) + 1]--;
    }
    bool done = true;
    for (int i = 1; i <= n; i++) {
      pre[i] += pre[i - 1];
      a[i] = pre[i];
      if (a[i] < n) done = false;
    }
//    ops++;
    if (done) break;
  }

//  cerr << "> ops = " << ops << endl;

  for (int i = 1; i <= n; i++) {
    cout << a[i] << ' ';
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 5208
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define debug int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<int, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7

int main(){
    int n;
    VE a, small, big;
    cin >> n;
    ll A;
    REP(i, n){
        cin >> A;
        a.push_back(A);
    }
    sort(a.begin(), a.end());
    ll ans = 0;
    if(n % 2 == 0){
        REP(i, n){
            if(i < n / 2){
                small.push_back(a[i]);
            }else{
                big.push_back(a[i]);
            }
        }
        sort(big.rbegin(), big.rend());
        REP(i, big.size() - 1){
            ans += 2 * big[i];
        }
        REP(i, small.size() - 1){
            ans -= 2 * small[i];
        }
        ans = ans + big[big.size() - 1] - small[small.size() - 1];
    }else{
        REP(i, n){
            if(i < n / 2){
                small.push_back(a[i]);
            }else{
                big.push_back(a[i]);
            }
        }
        sort(big.rbegin(), big.rend());
        REP(i, big.size() - 2){
            ans += 2 * big[i];
        }
        ans += big[big.size() - 2] + big[big.size() - 1];
        REP(i, small.size()){
            ans -= 2 * small[i];
        }

        small = {};
        big = {};
        ll tmp = 0;
        REP(i, n){
            if(i < n / 2 + 1){
                small.push_back(a[i]);
            }else{
                big.push_back(a[i]);
            }
        }
        sort(big.rbegin(), big.rend());
        REP(i, big.size()){
            tmp += 2 * big[i];
        }
        REP(i, small.size() - 2){
            tmp -= 2 * small[i];
        }
        tmp = tmp - small[small.size() - 2] - small[small.size() - 1];
        ans = max(ans, tmp);
    }


    print(ans);
}


Measured memory_bytes: 2292
#include<bits/stdc++.h>
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
 
template<class T> inline bool chmin(T &a, T 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;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;
struct PrimalDual{
	struct edge{
		int to,cap,cost,rev;
	};
	vector<vector<edge>>graph;
	bool negative=false;
	void add_edge(int from,int to,int cap,int cost){
		graph[from].push_back({to,cap,cost,len(graph[to])});
		graph[to].push_back({from,0ll,-cost,len(graph[from])-1});
		if(cost<0)negative=true;
	}
	int minCostFlow(int s,int t,int f){
		int V=len(graph);
		vector<int>potential(V),minCost,prevv(V,-1),preve(V,-1);
		int res=0;
		if(negative){
			minCost.assign(V,inf);
			minCost[s]=0;
			rep(_,V-1){
				rep(i,V){
					rep(j,len(graph[i])){
						edge &e=graph[i][j];
						if(e.cap>0&&chmin(minCost[e.to],minCost[i]+e.cost+potential[i]-potential[e.to])){
							prevv[e.to]=i;
							preve[e.to]=j;
						}
					}
				}
			}
			if(minCost[t]==inf)return -1;
			rep(i,V)potential[i]+=minCost[i];
			for(int i=t;i!=s;i=prevv[i]){
				graph[prevv[i]][preve[i]].cap--;
				graph[i][graph[prevv[i]][preve[i]].rev].cap++;
			}
			res+=potential[t];
			f--;
		}

		while(f>0){
			minCost.assign(V,inf);
			minCost[s]=0;
			priority_queue<P,vector<P>,greater<>>que;
			que.push({0,s});
			while(!que.empty()){
				P p=que.top();que.pop();
				if(minCost[p.second]<p.first)continue;
				rep(i,len(graph[p.second])){
					edge &e=graph[p.second][i];
					if(e.cap>0&&chmin(minCost[e.to],p.first+e.cost+potential[p.second]-potential[e.to])){
						prevv[e.to]=p.second;
						preve[e.to]=i;
						que.push({minCost[e.to],e.to});
					}
				}
			}

			if(minCost[t]==inf)return -1;
			rep(i,V)potential[i]+=minCost[i];
			int addflow=f;
			for(int i=t;i!=s;i=prevv[i])chmin(addflow,graph[prevv[i]][preve[i]].cap);
			f-=addflow;
			res+=addflow*potential[t];
			for(int i=t;i!=s;i=prevv[i]){
				edge &e=graph[prevv[i]][preve[i]];
				e.cap-=addflow;
				graph[i][e.rev].cap+=addflow;
			}
		}
		return res;
	}
	PrimalDual(int V):graph(V){};
};

int N,M;
char c[55][55];
bool used[55][55];
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	cin>>N>>M;
	rep(i,N)rep(j,M)cin>>c[i][j];
	PrimalDual F(N*M+2);
	int cnt=0;
	rep(i,N)rep(j,M){
		if(c[i][j]=='o'){
			F.add_edge(N*M,i*M+j,1,0);
			cnt++;
		}
		if(c[i][j]!='#'){
			F.add_edge(i*M+j,N*M+1,1,0);
			if(i<N-1&&c[i+1][j]!='#')F.add_edge(i*M+j,i*M+j+M,100,-1);
			if(j<M-1&&c[i][j+1]!='#')F.add_edge(i*M+j,i*M+j+1,100,-1);
		}
	}
	cout<<-F.minCostFlow(N*M,N*M+1,cnt)<<"\n";
}


Measured memory_bytes: 4472
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Dynamic;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int X = int.Parse(Console.ReadLine());
            if (30 <= X)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    } 
}


//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 27520
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N,K;
	string S;
	cin>>N>>K>>S;
	string ans;
	rep(i,N){
		if(i == K-1){
			cout<<char(S[i]-'A'+'a');
		}
		else{
			cout<<S[i];
		}
	}
	cout<<endl;
}

Measured memory_bytes: 256
#include<cstdio>

int main(void){
    int N;
    scanf("%d",&N);
    char S[101]={};
    scanf("%s",S);
    if((N+1)%2 ==0){
        printf("No");
        return 0;
    }
    for(int i=0;i<N/2;i++){
        if(S[i]!=S[N/2+i]){
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;

}

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

using namespace std;

const long long INF = 1e18L + 18;

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int N;
  cin >> N;
  vector < long long > a(N);
  vector < vector < long long > > dp(N, vector < long long >(N));
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    if (i > 0)
      a[i] += a[i - 1];
  }
  auto sum = [&](int st, int dr) {
    if (st == 0)
      return a[dr];
    return a[dr] - a[st - 1];
  };
  for (int L = N - 2; L >= 0; --L)
    for (int R = L + 1; R < N; ++R) {
      dp[L][R] = INF;
      for (int i = L; i < R; ++i)
        dp[L][R] = min (dp[L][R], dp[L][i] + dp[i + 1][R] + sum(L, R));
    }
  cout << dp[0][N - 1];
}


Measured memory_bytes: 4460
#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<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#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
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
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)
{
  string str;
  cin>>str;
  if(str[0] =='7' || str[1] =='7' ||str[2] =='7')
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<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: 3588
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
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; }
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    map<ll,ll> mii1,mii2;
    rep(i,n){
        int x;
        cin >> x;
        mii1[i + x]++;
        mii2[i - x]++;
    }
    ll ans = 0;
    for(auto u : mii1){
        ans += u.second  * mii2[u.first];
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 37736
<?php
function get_two_int(){
	$two_data = trim(fgets(STDIN));
	$two_int = explode(" ", $two_data);
	for ($i = 0; $i < count($two_int); $i++){
		//foreachで$valueを変えていっても無駄
		$two_int[$i] = (int) $two_int[$i];
	}
	return $two_int;
	}

function make_deck($deck_num){
	$deck = array_fill(0, $deck_num, 0);
	$order = 0;
	for ($i = $deck_num; $i >= 1; $i--) {
		$deck[$order] = $i;
		$order += 1;
	}
	return $deck;
}

function make_change_set($start_num, $set_num, $deck){
	$change_set = array_slice($deck, $start_num, $set_num);
	return $change_set;
}

function shuffle_deck($first_set, $second_set, $deck){
	$change_set = array_merge($second_set, $first_set);
	for ($i = 0; $i < count($change_set); $i++) {
		$deck[$i] = $change_set[$i];
	}
	return $deck;
}

while (True) {
	list($deck_num, $shuffle_num) = get_two_int();
	if ($deck_num === 0){
		break;
	}
	$deck = make_deck($deck_num);
	for ($i = 0; $i < $shuffle_num; $i++){
		list($p, $c) = get_two_int();
		$first_set_num = $p - 1;
		$second_set_num = $c;
		$first_set = make_change_set(0, $first_set_num, $deck);
		$second_set = make_change_set($first_set_num, $second_set_num, $deck);
		$deck = shuffle_deck($first_set, $second_set, $deck);
	}
	echo $deck[0] . PHP_EOL;
}



Measured memory_bytes: 9360
n = gets.to_i
while n >= 4 do
    if n-4 > -1 && n % 7 != 0
        n = n-4
    elsif n-7 > -1 && n % 4 != 0
        n = n-7
    elsif n % 4 == 0 && n % 7 == 0
        n = n - 7
    end
end

if n == 0 
    print 'Yes'
else
    print 'No'
end

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int x1 = Integer.parseInt(sc.next());
    int y1 = Integer.parseInt(sc.next());
    int x2 = Integer.parseInt(sc.next());
    int y2 = Integer.parseInt(sc.next());
    
    int vectorX = x2 - x1;
    int vectorY = y2 - y1;
    
    int tmp = vectorX;
    vectorX = -1 * vectorY;
    vectorY = tmp;
    
    int x3 = x2 + vectorX;
    int y3 = y2 + vectorY;
    
    tmp = vectorX;
    vectorX = -1 * vectorY;
    vectorY = tmp;
    
    int x4 = x3 + vectorX;
    int y4 = y3 + vectorY;
    
    System.out.println(x3 + " " + y3 + " " + x4 + " " + y4);
    
  }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
    ll pMOD(ll x,ll y){
        ll res = 1;
        rep(i,y){
            res = res * x % MOD;
        }
        return res;
    }
int main(){
    int n;
    cin >> n;
    ll ans = pMOD(10,n) - pMOD(9,n) -pMOD(9,n) + pMOD(8,n);
    ans %= MOD;
    ans = (ans + MOD) % MOD;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <random>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1ll<<61 ;

void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
void fix_cout(){cout << fixed << setprecision(20) ;}
void chmax(ll &a,ll b){	if(a<b) a = b ;}
void chmin(ll &a,ll b){ if(a>b) a = b ;}

int main(){
	int n,m ;
	cin >> n >> m ;
	vector<vector<bool>> e(n,vector<bool>(n,false)) ;
	for(int i=0;i<m;i++){
		int a,b ;
		cin >> a >> b ;
		a-- ; b-- ;
		e.at(a).at(b) = e.at(b).at(a) = true ;
	}
	vector<int> num ;
	for(int i=0;i<n;i++) num.push_back(i) ;
	int ans = 0 ;
	do{
		if(num.at(0)!=0) break ;
		bool ok = true ;
		for(int i=1;i<n;i++) ok &= e.at(num.at(i-1)).at(num.at(i)) ;
		ans += ok ;
	}while(next_permutation(all(num))) ;
	cout << ans << endl ;
}


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

int main(){
  int n;
  cin >>n;
  int h = n/2;
  if(n%2 == 0) cout << h*h << endl;
  else cout <<h*(h+1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <vector>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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; }

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<int> dp(n+100);
  dp[0] = 0;
  dp[1] = 1;

  for (int i = 1; i < n+100; ++i) {
    dp[i] = dp[i-1] + 1;
    int tmp = 1;
    while(i - pow(6, tmp) >= 0){
      dp[i] = min(dp[i], dp[i - int(pow(6, tmp))] + 1);
      tmp++;
    }
    tmp = 1;
    while(i - pow(9, tmp) >= 0){
      dp[i] = min(dp[i], dp[i - int(pow(9, tmp))] + 1);
      tmp++;
    }
  }

  cout << dp[n] << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
/* END OF TEMPLATE */

vll dp(100010);

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vll h(n);
    rep(i, n){
        cin >> h[i];
    }
    dp[0] = 0;
    repr(i, 1, n){
        ll anstemp = INF;
        for(int j = i-1; j >= 0 && j >= i-k; j--){
            anstemp = min(anstemp, dp[j]+abs(h[i]-h[j]));
        }
        dp[i] = anstemp;
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

// http://noshi91.hatenablog.com/entry/2019/03/31/174006
template <uint_fast64_t Mod = 1'000'000'007>
struct modint {
  using u64 = uint_fast64_t;

  u64 n;

  modint(const u64 x = 0) : n(x % Mod) {}
  modint operator+(const modint r) const { return modint(*this) += r; }
  modint operator-(const modint r) const { return modint(*this) -= r; }
  modint operator*(const modint r) const { return modint(*this) *= r; }
  modint operator/(const modint r) const { return modint(*this) /= r; }
  modint &operator+=(const modint r) {
    n += r.n;
    if (n >= Mod) n -= Mod;
    return *this;
  }
  modint &operator-=(const modint r) {
    if (n < r.n) n += Mod;
    n -= r.n;
    return *this;
  }
  modint &operator*=(const modint r) {
    n = n * r.n % Mod;
    return *this;
  }
  modint &operator/=(modint r) {
    n = n * inv();
    return *this;
  }
  modint pow(u64 x) const {
    modint<Mod> ret(1), tmp(*this);
    while (x) {
      if (x&1) ret *= tmp;
      tmp *= tmp;
      x >>= 1;
    }
    return ret;
  }
  modint inv() const {
    return pow(Mod-2);
  }
};
using mint = modint<1'000'000'007>;

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

  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) {
    cin >> a[i];
  }
  sort(all(a));
  vector<mint> c(n);
  rep(i, n) {
    c[i] = mint(a[i]);
  }

  vector<mint> pow_2(2*n+1);
  pow_2[0] = 1;
  rep(i, 2*n) {
    pow_2[i+1] = pow_2[i]*2;
  }

  mint ans(0);
  rep(i, n) {
    ll r = n-1-i;
    ans += c[i]*(2+r);
  }
  ans *= pow_2[2*n-2];

  cout << ans.n << endl;
}


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

long long MOD = 1000000007;

vector<long long> F, RF;

void init(long long N) {
	F.resize(N + 1), RF.resize(N + 1);
	vector<long long> inv(N + 1);
	inv[1] = 1;
	F[0] = F[1] = RF[0] = RF[1] = 1;
	for (int i = 2; i <= N; i++) {
		F[i] = (F[i - 1] * i) % MOD;
		inv[i] = MOD - (inv[MOD % i] * (MOD / i)) % MOD;
		RF[i] = (RF[i - 1] * inv[i]) % MOD;
	}
}

long long Comb(long long A, long long B) {
	if (B < 0 || A < B) return 0;
	return (F[A] * ((RF[A - B] * RF[B]) % MOD)) % MOD;
}

int main() {
	long long N, K, MAXS = 0, MINS = 0;
	cin >> N >> K;
	init(N);
	vector<long long> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A.begin(), A.end());
	for (int i = 0; i < N; i++) {
		MAXS = (MAXS + Comb(i, K - 1) * A[i]) % MOD;
	}
	reverse(A.begin(), A.end());
	for (int i = 0; i < N; i++) {
		MINS = (MINS + Comb(i, K - 1) * A[i]) % MOD;
	}
	cout << (MOD + MAXS - MINS) % MOD << endl;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <time.h>

using namespace std;
typedef long long int ll;

int main()
{
	char s[100000];
	scanf("%s", s);
	string str;
	vector<int> v;
	int n=strlen(s);
	for(int i=0; i<n; i++){
		if(s[i]!='x'){
			str+=s[i];
			v.push_back(i);
		}
	}
	int m=str.length();
	if(m==0){
		printf("%d\n", 0);
		return 0;
	}
	for(int i=0; i<m; i++){
		if(str[i]!=str[m-1-i]){
			printf("%d\n", -1);
			return 0;
		}
	}
	int sum1=0, sum2=0;
	if(m%2==1){
		int mid=v[(m-1)/2];
		for(int i=(m-1)/2-1; i>=0; i--){
			if(mid-v[i]+sum1>v[m-1-i]-mid+sum2){
				sum2+=((mid-v[i]+sum1)-(v[m-1-i]-mid+sum2));
			}else{
				sum1+=((v[m-1-i]-mid+sum2)-(mid-v[i]+sum1));
			}
		}
		printf("%d\n", sum1+sum2+abs(v[0]-(n-1-v[m-1])));
	}else{
		int mid1=v[m/2-1], mid2=v[m/2];
		for(int i=m/2-2; i>=0; i--){
			if(mid1-v[i]+sum1>v[m-1-i]-mid2+sum2){
				sum2+=((mid1-v[i]+sum1)-(v[m-1-i]-mid2+sum2));
			}else{
				sum1+=((v[m-1-i]-mid1+sum2)-(mid2-v[i]+sum1));
			}
		}
		printf("%d\n", sum1+sum2+abs(v[0]-(n-1-v[m-1])));
	}
	return 0;
}


Measured memory_bytes: 1152
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

n,m = map(int,input().split())
li = [input() for i in range(n)]
li2 = [input() for i in range(m)]

d = []
for i in range( n - m + 1):
    for j in range( n - m + 1):
        koho = []
        for k in range(m):
            c = ""
            for l in range(m):
                c += li[i+k][j+l]
            koho.append(c)
        if koho == li2:
            print("Yes")
            sys.exit()
print("No")

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main() {
    long int n,w;
    cin>>n>>w;
    long int weight[n],val[n];
    for(int i=0;i<n;i++)
        cin>>weight[i]>>val[i];
    long long int dp[n+1][w+1];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=w;j++){
            if(i==0||j==0){
                dp[i][j]=0;
            }
            else if(j-weight[i-1]>=0){
                dp[i][j]=max(dp[i-1][j],val[i-1]+dp[i-1][j-weight[i-1]]);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 82388
from sys import stdin, setrecursionlimit
def input():
    return stdin.readline().strip()

setrecursionlimit(10**5)

n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n-1):
    i, j = map(int, input().split())
    i -= 1
    j -= 1
    edge[i].append(j)
    edge[j].append(i)

# root: 0
# edge1: parent→children
# edge2: child→parent
# tfに探索済かどうかを保存する
tf = [False] * n
tf[0] = True
edge1 = [[] for _ in range(n)]
edge2 = [-1] * n

def divide(i):
    for j in edge[i]:
        if tf[j]:
            continue
        else:
            tf[j] = True
            edge1[i].append(j)
            edge2[j] = i
            divide(j)

divide(0)

now = n - 1
l = [n-1]
while edge2[now] != -1:
    now = edge2[now]
    l.append(now)

root = l[len(l)//2 - 1]

def divide2(i):
    ans = 1
    for j in edge1[i]:
        ans += divide2(j)
    return ans

Snuke = divide2(root)
Fennec = n - Snuke

if Snuke < Fennec:
    print('Fennec')
else:
    print('Snuke')

Measured memory_bytes: 202180
'use strict'
const Main = (input) => {
  let tmp = input.split('\n');
  let CardN = tmp[0].split(' ').map(Number)[0];
  let GateN = tmp[0].split(' ').map(Number)[1];
  let NumTop = 1;
  let NumBtm = CardN;

  for (let i = 1; i <= GateN; i++) {
    let top = tmp[i].split(' ').map(Number)[0];
    let btm = tmp[i].split(' ').map(Number)[1];
    NumTop = NumTop <= top ? top : NumTop;
    NumBtm = NumBtm >= btm ? btm : NumBtm;
    if (NumTop > NumBtm) {
      break;
    }
  }
  let Ans = NumBtm - (NumTop - 1);
  console.log(Ans > 0 ? Ans : 0);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29904
# AGC011A - Airport Bus
import sys
input = sys.stdin.readline

def main():
    N, C, K = tuple(map(int, input().rstrip().split()))
    T = sorted(map(int, [input().rstrip() for _ in range(N)]))
    ans, cur, cnt = 0, T[0] + K, 0
    for i in T:
        if i > cur or cnt == C:  # need a new bus
            cur = i + K
            cnt = 1
            ans += 1
        else:  # ride on the current bus
            cnt += 1
    print(ans + 1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14236
#include <bits/stdc++.h>
#include <string>
//#define local
#ifdef local
    #include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
    #include <boost/multiprecision/cpp_int.hpp>
#endif
#define p std::pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define vi std::vector<int>
#define pi std::pair<int, int>
#define mp std::make_pair
#define stdabs std::abs
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
#define npm next_permutation
#define Yes std::cout << "Yes" << std::endl
#define No std::cout << "No" << std::endl
#define YES std::cout << "YES" << std::endl
#define NO std::cout << "NO" << std::endl
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy8[8] = {0, 1, 0, -1, 1, -1, 1, -1};
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
ll extgcd(ll a, ll b, ll& x, ll& y);
ll nCr(ll n, ll r);
void stat();
template <typename T> T fact(T num);
unsigned long long modpow(int x__, int n__, long long mod__);
template <typename T> void debug(const T& t);
constexpr ll mod10_9p7 = 1000000000 + 7;

/**************************************************************/
int main()
{
    stat();
    ll n;
    cin>>n;
    ll ans=0;
    for(int i=1;i!=n;++i){
	    if(n%i==0){--ans;}
	    ans+=(n/i);
    }
cout<<ans<<endl;
    return 0;
}
/**************************************************************/
ll extgcd(ll a, ll b, ll& x, ll& y)
{
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) {
        is_prime[i] = true;
    }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++) {
        if (is_prime[i]) {
            for (unsigned ll j = 2 * i; j <= N; j += i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}

void stat(){
#ifdef local
    rep(i, 2){std::cout << "local enable" << std::endl;
}
#endif
#ifdef hacks
rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}

ll nCr(ll n, ll r)
{
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

template <typename T> T fact(T num)
{
    if (num == 1) { return 1; }
    return num * fact(num - 1);
}

unsigned long long modpow(int x__, int n__, long long mod__)
{
    long long ret__ = 1;
    for (long long i__ = 0; i__ < n__; ++i__) {
        ret__ = ret__ * x__ % mod__;
    }
    return ret__;
}

template <typename T> void debug(const T& t)
{
#ifdef local
    dbg(t);
#endif
}


Measured memory_bytes: 3628