akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int n,k;
    cin >> n>>k;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    sort(h.begin(),h.end());
    int min = big;
    for(int i=0;i<n-k+1;i++){//imax=2
        if(h[i+k-1]-h[i]<min){
            min = h[i+k-1]-h[i];
            
        }
    }
    cout <<min <<endl;

}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repA(i,a,b) for(int i=a;i<=b;i++)
#define repD(i,b,a) for(int i=b;i>=a;i--)
#define mset(a,val) memset(a,val,sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main()
{
    int h,w,k;
    cin>>h>>w>>k;
    vector<vector<char>>grid(h,vector<char>(w));
    rep(i,0,h)
    {
        rep(j,0,w)
        {
            cin>>grid[i][j];
        }
    }
    int res=0;
    for(int i=0;i<(1<<h);i++)
    {
        for(int j=0;j<(1<<w);j++)
        {
            int cnt=0;
            for(int r=0;r<h;r++)
            {
                for(int c=0;c<w;c++)
                {
                    if(!(i&(1<<r)) && !(j&(1<<c)))
                    {
                        if(grid[r][c]=='#')
                            cnt++;
                    }
                }
            }
            if(cnt==k)
                res++;
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3624
from collections import defaultdict
N = int(input())
D = list(map(int,input().split()))
M = int(input())
T = list(map(int,input().split()))
if N < M:
  print("NO")
  exit()
d = defaultdict(int)
for i in range(N):
  d[D[i]] += 1
#print(d)
for i in range(M):
  if not d[T[i]]:
    print("NO")
    exit()
  d[T[i]] -= 1
print("YES")

Measured memory_bytes: 41700
#include <bits/stdc++.h>
using namespace std;
//関数
const long INF=1000000000000000;

int main(void){
    long L,R;
    cin>>L>>R;
    
    vector<bool> able(2019,false);
    
    for(int i=L;i<=min(R,L+2019);i++) able.at(i%2019)=true;
    
    //cout<<able.at(2)<<endl;
    
    long ans=INF;
    for(long i=1;i<2019;i++){
        for(long j=0;j<i;j++){
            if(able.at(i) && able.at(j)) {
                ans=min(ans,(i*j)%2019);
                //cout<<i<<j<<endl;
            }
        }
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<climits>
#include<cstdlib>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
#define ULL unsigned long long
int read(){
	int f=1,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f*x;
}
#define MAXN 200005
#define INF 0x3f3f3f3f
bool f[MAXN+5],pan;
vector<int> G[MAXN+5];
void DFS(int u,int fa){
	int cnt=0;
	for(int i=0;i<int(G[u].size());i++){
		int v=G[u][i];
		if(v==fa) continue;
		DFS(v,u);
		if(f[v]==1)
			cnt++;
	}
	if(cnt>=2){
		puts("First");
		exit(0);
	}
	f[u]=cnt^1;
	return ;
}
int main(){
	int n=read();
	for(int i=2;i<=n;i++){
		int u=read(),v=read();
		G[u].push_back(v);
		G[v].push_back(u);
	}
	DFS(1,0);
	puts(f[1]?"First":"Second");
	return 0;
}//

Measured memory_bytes: 8320
#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll a[10],e,ans,bigOne,bigTwo;

int main(){

	cin>>a[0]>>a[1]>>a[2]>>a[3];
	cin>>e;
	a[0]*=4;
	a[1]*=2;
	bigOne=min(a[0],min(a[1],a[2]));
	bigTwo=min(2*bigOne,a[3]);
	ll tmp = e;
	if(tmp>1){
		ll total = tmp/2;
		ans = total*bigTwo;
		if(tmp%2==1){
			ans+=bigOne;
		}
	}else{
		cout << bigOne<<endl;
		return 0;
	}
	cout << ans<<endl;


	return 0;
}


Measured memory_bytes: 256
n = int(input())
s = list(input())
a_li = []
b_li = []
c_li = []
for i,ss in enumerate(s):
    if ss == 'R':
        a_li.append(i+1)
    elif ss == 'G':
        b_li.append(i+1)
    else:
        c_li.append(i+1)
count = 0
for i in range(1,n+1):
    for d in range(1,n):
        if i + 2*d > n:
            break
        if s[i-1] != s[i+d-1] and s[i+d-1] != s[i+2*d-1] and s[i-1] != s[i+2*d-1]:
            count += 1
#print(len(a_li),len(b_li),len(c_li),count)
#print(count)
print(len(a_li)*len(b_li)*len(c_li)-count)


Measured memory_bytes: 68460
import fractions
import math
n, m = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
a = [int(i/2) for i in a]
num_gcd = a[0]
for i in range(1, n):
    num_gcd = num_gcd * a[i] // fractions.gcd(num_gcd, a[i])
flag = False
c = 0
p = a[0]
while True:
    if p % 2 != 0:
        break
    p /= 2
    c += 1
for i in range(1, n):
    if a[i] % (2 ** c) == 0 and (a[i] // (2 ** c)) % 2 != 0:
        pass
    else:
        flag = True
if flag:
    print(0)
else:
    print(math.ceil((m // num_gcd) / 2))


Measured memory_bytes: 16320
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long int
#define ff first
#define ss second
#define S size()
#define mod (ll)(1e9+7)
#define mset(a,k) memset(a,k,sizeof(a))
#define fr(i, x, y) for ( ll i = x; i < y;i++)
#define dr(i, x, y) for ( ll i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define pqueue priority_queue<ll>
#define piqueue priority_queue<ll,vll ,greater<ll>>
#define mapcl map<char,ll>
#define mapll map<ll,ll>
#define mapsl map<string,ll>
#define vi vector<ll>
#define vs vector<string>
#define vb vector<bool>
#define psi pair<string,ll>
#define pii pair<ll,ll>
#define piii pair<ll,pii>
#define vii vector<pii>
#define vvi vector<vi>
#define vvii vector<vii>
using namespace std;
void fast() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}
//----------------------------------------FUNCTIONS-------------------------------------
ll gcd(ll x, ll y )						{if (y == 0) return x; return gcd(y, x % y);}
ll lcm(ll a, ll b)						{return (a * b) / gcd(a, b);}
ll logx(ll base, ll num)				{int cnt = 0; while (num != 1) {num /= base; ++cnt;} return cnt;}
vi vin(ll n)							{vi a(n); fr(i, 0, n) cin >> a[i]; return a;}
void out(vi a)							{for (int i = 0; i < (ll)a.S; i++) { cout << a[i] << " "; } cout << endl;}
void in(ll *a, ll n)        			{for (ll i = 0; i < n; i++)cin >> a[i];}
void out(ll *a, ll n)					{fr(i, 0, n) {cout << a[i] << " ";} cout << '\n';}
void out1(vi v)							{fr(i, 0, (ll)v.S) {cout << v[i] << " ";} cout << endl;}
const ll MAXN = (ll)(1 * 1e6 + 5 ), level = 22;

void solve()
{
	ll n;
	cin >> n;
	ll a[n];
	in(a, n);
	ll ans = 0;
	fr(i, 0, n - 1)
	{
		if (a[i] > a[i + 1])
		{
			ans += (a[i] - a[i + 1]);
			a[i + 1] = a[i];
		}
	}
	cout << ans << '\n';
}
int main()
{

#ifndef ONLINE_JUDGE
	freopen ("inp4.txt", "r", stdin);
	freopen ("out4.txt", "w", stdout);
#endif
	fast();
	ll t = 1;
	//cin >> t;
	fr(i, 0, t)
	{
		solve();
	}
}

Measured memory_bytes: 5172
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    long long a,b;
    while(cin>>a>>b)
    {
        if((a+b)%3==0)
            printf("Possible\n");
        else if(a%3==0)
         printf("Possible\n");
         else if(b%3==0)
            printf("Possible\n");
        else printf("Impossible\n");
    }

}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

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

    vector<int> A[2];
    A[0].resize(N);
    A[1].resize(N);

    for (int& a : A[0])
        cin >> a;
    for (int& a : A[1])
        cin >> a;

    vector<int> state = {A[0][0], A[0][0] + A[1][0]};
    for (int i = 1; i < N; ++i) {
        int nst0 = state[0] + A[0][i];
        int nst1 = max(state[1] + A[1][i], state[0] + A[0][i] + A[1][i]);
        state = {nst0, nst1};
    }
    cout << state[1] << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

const int maxn = 100100;
ll delta[maxn];
ll ans[maxn];
vector<ll> m;
vector<ll> mul;

void go(ll x, ll bon) {
    if (x == 0)
        return;
    if (x <= m[0]) {
        delta[x] += bon;
        //cerr << "sooka " << x << '\n';
        return;
    }
    int i = upper_bound(all(m), x) - m.begin() - 1;
    assert(i >= 0);
    //cerr << "xx " << m[i] << ' ' << x / m[i] * bon << '\n';
    mul[i] += (x / m[i]) * bon;
    go(x % m[i], bon);
}

int main() {
    #ifdef LOCAL
    assert(freopen("e.in", "r", stdin));
    #else
    #endif
    int n, q;
    cin >> n >> q;
    m.push_back(n);
    forn (i, q) {
        ll x;
        cin >> x;
        while (!m.empty() && m.back() >= x)
            m.pop_back();
        m.push_back(x);
    }
    //for (auto xx: m)
        //cerr << xx << ' ';
    //cerr << '\n';
    ll need = m.back();
    mul.resize(sz(m));
    mul.back() = 1;
    while (sz(m) > 1) {
        ll bon = mul.back();
        ll x = m.back();
        m.pop_back();
        mul.pop_back();
        go(x, bon);
    }
    delta[m[0]] += mul[0];
    ll cnt = 0;
    ll sum = 0;
    for (int i = m[0] - 1; i >= 0; --i) {
        cnt += delta[i + 1];
        ans[i] = cnt;
        sum += cnt;
    }
    assert(sum == need);
    forn (i, n)
        cout << ans[i] << '\n';
}


Measured memory_bytes: 4980
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
double pi=acos(-1);
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    ll sum=0;
    ll a[1006];
    for (int i=0;i<n-1;i++)
    {
        cin>>a[i];

    }
    for (int i=0;i<n-2;i++)
    {
        if (a[i]<=a[i+1])
            sum+=a[i];
            else
            sum+=a[i+1];
    }
    cout<<a[0]+a[n-2]+sum<<endl;
    //cout<<a[0]+sum<<endl;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    string s, t, u;
    ll a, b;
    cin >> s >> t >> a >> b >> u;
    if (u == s) a--;
    else if (u == t) b--;
    printf("%lld %lld\n", a, b);
    return 0;
}


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

long long f (long long x) {
    if (x==1) return 1;
    return f(x/2) * 2 + 1;
}

int main() {
    long long H;
    cin >> H;
    cout << f(H) << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <queue>

using namespace std;

long long h[200000];
long long dp[200000];

int main() {
    int n, i;
    long long c;
    deque <int> d;
    
    scanf("%d %lld", &n, &c);
    
    for (i = 0; i < n; i++) scanf("%lld", &h[i]);
    
    d.push_back(0);
    
    for (i = 1; i < n; i++) {
        while (d.size() >= 2) {
            int x = d[0];
            int y = d[1];
            
            if (dp[x] + (h[i] - h[x]) * (h[i] - h[x]) < dp[y] + (h[i] - h[y]) * (h[i] - h[y])) break;
            
            d.pop_front();
        }
        
        dp[i] = dp[d[0]] + (h[i] - h[d[0]]) * (h[i] - h[d[0]]) + c;
        
        while (d.size() >= 2) {
            int x = d[d.size() - 2];
            int y = d[d.size() - 1];
            long long a1 = -2 * h[x];
            long long b1 = dp[x] + h[x] * h[x];
            long long a2 = -2 * h[y];
            long long b2 = dp[y] + h[y] * h[y];
            long long a3 = -2 * h[i];
            long long b3 = dp[i] + h[i] * h[i];
            
            if ((a2 - a1) * (b3 - b2) < (b2 - b1) * (a3 - a2)) break;
            
            d.pop_back();
        }
        
        d.push_back(i);
    }
    
    printf("%lld\n", dp[n - 1]);
    
    return 0;
}


Measured memory_bytes: 3840
#include<iostream>
#include<algorithm>
using namespace std;
int x[10][10000],H,W;
int main(){
	while(true){
		cin>>H>>W;if(H+W==0)break;
		for(int i=0;i<H;i++){for(int j=0;j<W;j++)cin>>x[i][j];}
		int maxn=0;
		for(int i=0;i<(1<<H);i++){
			int cnt=0;
			for(int j=0;j<W;j++){
				int r=0;
				for(int k=0;k<H;k++){
					int Y=(i/(1<<k))%2;r+=(x[k][j]+Y)%2;
				}
				cnt+=max(r,H-r);
			}
			maxn=max(maxn,cnt);
		}
		cout<<maxn<<endl;
	}
	return 0;
}

Measured memory_bytes: 3432
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    S = input()
    x = 0
    ans = 0
    for s in S:
        if s == "I":
            x += 1
        else:
            x -= 1
        ans = max(x, ans)
    print(ans)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 61968
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=s;i<t;i++)
typedef long long ll;
ll dp[44][44][44],isused[44][44][44];char isok[44][44];
ll solve(int l,int mid,int r)
{
    if(r-l<=0)return 1;
    if(mid<=l||mid>=r)return 0;
    if(isused[l][mid][r])return dp[l][mid][r];
    isused[l][mid][r]=1;
    rep(i,l,mid)rep(j,mid+1,r+1)if(isok[i][j]=='1')
    rep(k1,i,mid)rep(k2,mid,j)
    dp[l][mid][r]+=solve(l,i,k1)*solve(k1+1,mid,k2)*solve(k2+1,j,r);
    return dp[l][mid][r];
}
int main()
{
    int n;scanf("%d",&n);
    rep(i,1,n*2+1)scanf("%s",isok[i]+1);
    ll res=0;
    rep(i,2,n*2+1)if(isok[1][i]=='1')
        res+=solve(2,i,n*2);
    printf("%lld\n",res);
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string.h>
#include <deque>
#define REP(i,j,n) for(int i=j;i<n;i++)
#define SORT(x) sort(x.begin(),x.end())

using namespace std;

int main() {
	string s, t;
	int n, tarou = 0, hanako = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s >> t;
		int count = 0;
		bool judge = true;
		while (count < s.length() || count < t.length()) {
			if (s[count] > t[count]) {
				tarou += 3;
				judge = false;
				break;
			}
			else if (s[count] < t[count]) {
				hanako += 3;
				judge = false;
				break;
			}
			else {
				count++;
			}
		}
		if (judge) {
			tarou++; hanako++;
		}
	}
	cout << tarou << " " << hanako << endl;
	return 0;
}

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

int main(){

    //freopen("in.txt", "r", stdin);

    int n; cin >> n;
    vector<string> s(n);

    int sMax = 0;
    map<string, int> mm;
    for (int i = 0; i < n; i++) {
            cin >> s[i];
            mm[s[i]]++;
            if (mm[s[i]] > sMax) sMax = mm[s[i]];
            //cout << mm[s[i]];
    }

    vector<string> ans;
    for (int i = 0; i < n; i++){
        if (mm[s[i]] == sMax){
            mm[s[i]] = 0;
            ans.push_back(s[i]);
        }
    }

    sort(ans.begin(), ans.end());

    for (auto x : ans) cout << x << endl;


}


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,M;
int edge [10] [10];
const int INF = 1e9;

int main()
{
	while(scanf("%d",&M),M){
		fill(edge [0],edge [10],INF);
		N = 0;
		FOR(i,0,M){
			int u,v,w;
			scanf("%d%d%d",&u,&v,&w);
			chmin(edge [u] [v],w);
			chmin(edge [v] [u],w);
			chmax(N,max(u,v) + 1);
		}
		FOR(i,0,N) edge [i] [i] = 0;

		FOR(k,0,N) FOR(i,0,N) FOR(j,0,N){
			chmin(edge [i] [j],edge [i] [k] + edge [k] [j]);
			chmin(edge [j] [i],edge [i] [k] + edge [k] [j]);
		}

		int mn = INF,ans = -1;
		FOR(i,0,N){
			int sum = 0;
			FOR(j,0,N) if(edge [i] [j] < INF){
				sum += edge [i] [j];
			}
			if(sum < mn){
				mn = sum;
				ans = i;
			}
		}

		printf("%d %d\n",ans,mn);
	}

	return 0;
}

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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

void doit(){
	ll n,ans=0;
	cin >> n;
	ans = n + (n*n) + (n*n*n);
	cout << ans << nl;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt","r",stdin);
	freopen("output1.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t = 1;
	// cin >> t;
	for(ll i = 1; i <= t; i++){
		doit();
	}
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,m;
    cin>>n>>m;
    long long int sum=1;
    if (n==m) {
        for (long long int i=n;i>0;i--) {
            sum=(sum*i)%1000000007;
        }
        for (long long int j=m;j>0;j--) {
            sum=(sum*j)%1000000007;
        }
        cout<<(sum*2)%1000000007<<endl;
    } else if (n-m==1||m-n==1)  {
        for (long long int i=max(n,m);i>0;i--) {
            sum=(sum*i)%1000000007;
        }
        for (long long int j=min(n,m);j>0;j--) {
            sum=(sum*j)%1000000007;
        }
        cout<<sum%1000000007<<endl;
    } else {
        cout<<0<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];

int main(){
  int N ;
  cin >> N ;
  int min = 10000000 ;
  for(int i=1 ;i<N;i++){
    int sum1=0,sum2=0 ;
    int A=i,B=N-i ;
    while(A > 0){
      sum1 += A%10 ;
      A /= 10 ;
    }
    while(B >0){
      sum2 += B%10 ;
      B /= 10 ;
    }
    if(sum1 + sum2 < min)
      min = sum1 + sum2 ;
  }
  cout << min << endl;
}

Measured memory_bytes: 256
package main

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

var nextString func() string

func init() {
	nextString = newReadString(os.Stdin)
}

func main() {
	var (
		a   = nextInt()
		b   = nextInt()
		c   = nextInt()
		ans = 0
	)
	for i := 1; ; i++ {
		switch (a * i) % b {
		case 0:
		case c:
			ans++
		default:
			continue
		}
		break
	}
	fmt.Println([]string{"NO", "YES"}[ans])
}

func nextInt() (result int) {
	result, _ = strconv.Atoi(nextString())
	return
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
		}
		return r.Text()
	}
}


Measured memory_bytes: 640
S = gets.strip.chars

a = (0..(S.size - 2)).to_a

tot = 0
(0..a.size).each do |n|
  a.combination(n) do |x|
    op = Array.new(10, '')
    x.each {|i| op[i] = '+'}
    tot += eval(S.zip(op).flatten.join)
  end
end
puts tot

Measured memory_bytes: 2044
//package AtCoder.C114;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;


public class Main {

    static InputStream inputStream = System.in;
    static OutputStream outputStream = System.out;
    static InputReader in = new InputReader(inputStream);
    static PrintWriter out = new PrintWriter(outputStream);

    public static void main(String[] args) {
        int n = in.NI() + 1; int m = in.NI();
        String que = in.next();

        if (que.charAt(n-1) == '1') {
            out.println(-1); out.close(); return;
        }

        int[] presum = new int[n];
        for (int i=0;i<n;i++) {
            presum[i] = (que.charAt(i)-'0');
        }

        for (int i=1;i<n;i++) presum[i]+=presum[i-1];

        int pos = n-1;

        List<Integer> answers = new ArrayList<>();

        while(pos>0) {
            int target = Integer.max(pos - m, 0);

            int subtractsum = target==0? 0: presum[target-1];

            int ans = -1;
            int ll = target; int ul = pos;
            while(ll<=ul) {
                int mid = (ll+ul)/2;
                if (presum[mid] - subtractsum == mid-target+1) {
                    ll = mid+1; continue;
                } else {
                    ans = mid;
                    ul = mid-1;
                }
            }

            if (ans == -1 || ans == pos) {
                out.println(-1); out.close(); return;
            }

            answers.add(pos-ans);
            pos = ans;
        }

        for (int i=answers.size()-1;i>=0;i--) {
            out.printf("%d ", answers.get(i));
        }

        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int NI() {
            return Integer.parseInt(next());
        }

        public long NL() {
            return Long.parseLong(next());
        }

    }

}


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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

ll N;
ll LEN;

ll dfs( ll key, ll len , set<ll> & num)
{
    if( LEN < len ) return 0;
    ll ans = 0;
    if( key <= N && num.size() == 3 )
    {
        ans++;
    }

    set<ll> tmp = num;
    tmp.insert(3);
    ans += dfs( key + pow(10,len) * 3, len+1, tmp );
    tmp = num;
    tmp.insert(5);
    ans += dfs( key + pow(10,len) * 5, len+1, tmp );
    tmp = num;
    tmp.insert(7);
    ans += dfs( key + pow(10,len) * 7, len+1, tmp );
    return ans;
}

int main()
{
    cin >> N;
    LEN = to_string(N).size();
    set<ll> tmp;

    cout << dfs(0, 0, tmp) << endl;
}


Measured memory_bytes: 256
using System;

namespace MSTrust2019B
{
    class Program
    {
        private static void Solve(int n)
        {
            for (int i = 1; i < 50001; ++i)
            {
                if ((int) Math.Floor(i * 1.08) == n)
                {
                    Console.WriteLine(i);
                    return;
                }
            }
            Console.WriteLine(":(");
        }

        static void Main(string[] args)
        {
            var line = Console.ReadLine();
            var n = Convert.ToInt32(line);
            Solve(n);
        }
    }
}


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

int main() {
  int i,j;
  int N;
  cin >> N;
  vector<int> di(N);
  for (i=0;i<N;i++){
    cin >> di.at(i);
  }

  int temp;
  for (i=0;i<N;i++){
    for (j=di.size()-1;j>i;j--){
      if(di.at(j)>di.at(j-1)){
        temp = di.at(j);
        di.at(j) = di.at(j-1);
        di.at(j-1)=temp;
      }
    }
  }

  int num = N;
  for (i=0;i<N-1;i++){
    if (di.at(i)==di.at(i+1)){
      num--;
    }
  }

  cout << num << endl;
}

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

signed main(void)
{
	int n, ans, s;
	cin >> n;
	vector<pair<int, int>> r(n), p(n);

	rep(i, n) cin >> r[i].first >> r[i].second;
	rep(i, n)
		p[i] = make_pair(r[i].first + r[i].second, r[i].first - r[i].second);
	sort(p.begin(), p.end());
	ans = 1;
	s = p[0].first;
	for(int i = 1; i < n; i++)
	{
		if (s <= p[i].second)
		{
			ans++;
			s = p[i].first;
		}

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


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int64_t abs(int64_t n) {
  if (n < 0) {
    n = -n;
  }
  return n;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

int main() {
  int n;
  cin >> n;
  vector <int64_t> v(n);
  rep(i, n) cin >> v.at(i);
  sort(v.begin(), v.end());
  int ans = 0, tmp = 1;
  rep(i, n-1) {
    if (i == n-2) {
      if (v.at(i) == v.at(i+1)) {
        tmp++;
        if (tmp%2 == 1) {
          ans++;
        }
      } else {
        ans++;
        if (tmp%2 == 1) {
          ans++;
        }
      }
    } else {
      if (v.at(i) == v.at(i+1)) {
        tmp++;
      } else {
        if (tmp%2 == 1) {
          ans++;
        }
        tmp = 1;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
"""
At Coder :: Beginner Contest 178 :: D - Redistribution 
https://atcoder.jp/contests/abc178/tasks/abc178_d
"""


MOD = pow(10, 9) + 7


def solve(S):
    """Solve problem."""
    if S < 3:
        return 0
    A = [1 for _ in range(S+1)]
    A[0] = A[1] = A[2] = 0
    for i in range(3, S+1):
        k = 3
        while i - k >= 0:
            A[i] = A[i-k] + A[i] % MOD
            k += 1
    return A[S]


def main():
    """Main program."""
    import sys
    S = int(sys.stdin.readline())
    print(solve(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9080
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

int collatz(int N)
{
    if(N % 2 == 0)
        return N / 2;
    return 3 * N + 1;
}

int main()
{
    int s;
    cin >> s;
    set<int> t;
    int i = 2;
    t.insert(s);
    while(true)
    {
        s = collatz(s);
        auto r = t.insert(s);
        if(!r.second)
            break;
        i++;
    }
    cout << i << endl;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Moving Piece
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 5000;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;

/* global variables */

int ps[MAX_N], cs[MAX_N], q[MAX_N * 2];
bool used[MAX_N];
ll css[MAX_N * 2 + 1];

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", ps + i), ps[i]--;
  for (int i = 0; i < n; i++) scanf("%d", cs + i);

  ll maxsum = -LINF;
  for (int st = 0; st < n; st++)
    if (! used[st]) {
      int m = 0;
      for (int u = st; ! used[u]; u = ps[u], m++) {
	used[u] = true;
	css[m + 1] = css[m] + cs[u];
      }
      for (int i = 0; i < m; i++) css[i + m + 1] = css[i + 1] + css[m];
      //for (int i = 0; i <= m * 2; i++) printf("%lld ", css[i]);
      //putchar('\n');

      int t = k / m, r = k % m;
      if (r == 0) t--, r = m;
      else if (t > 0 && css[m] <= 0) t = 0, r = m;

      ll maxd = -LINF;
      int qh = 0, qt = 0;
      for (int i = 0, j = 1; i < m; i++) {
	while (qh < qt && q[qh] <= i) qh++;
	while (j <= i + r) {
	  while (qh < qt && css[q[qt - 1]] <= css[j]) qt--;
	  q[qt++] = j++;
	}

	ll d = css[q[qh]] - css[i];
	if (maxd < d) maxd = d;
      }

      ll sum = maxd + css[m] * t;
      if (maxsum < sum) maxsum = sum;
    }

  printf("%lld\n", maxsum);
  return 0;
}


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

int main() {
  int a,b,c;
  c=0;
  cin>>a>>b;
  if(a==1)c+=300000;
  else if(a==2)c+=200000;
  else if(a==3)c+=100000;
  if(b==1)c+=300000;
  else if(b==2)c+=200000;
  else if(b==3)c+=100000;
  if(a==1&&b==1)c+=400000;
  cout<<c<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,flg;
	flg=0;
	scanf("%d",&a);
	if(a%10==7){
		flg=1;
	}
	a=a/10;
	if(a%10==7){
		flg=1;
	}
	a=a/10;
	if(a%10==7){
		flg=1;
	}
	if(flg==1){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1640
'use strict';

function Main(input) {
  const N = Number(input.split(' ')[0]);
  const K = Number(input.split(' ')[1]);

  if(N % K === 0) {
    console.log(0);
  } else {
    console.log(1);
  }

};

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

int fx[]={1,-1,0,0};
int fy[]={0,0,-1,1};

ll inp[3];

int main(){
    for(int i = 1; i <= 3; i++){
        fastScan(inp[i]);
    }
    sort(inp + 1, inp + 4);
    printf("%lld\n", inp[3] - inp[1]);
}


Measured memory_bytes: 256
/*input
3
100
100
100
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
vector<int> v;
int main(){
	IOS;
	int n;
	cin>>n;
	int x=0;
	REP(i,n){
		int tmp;
		cin>>tmp;
		x^=tmp;
		v.pb(tmp^(tmp-1));
	}
	SORT_UNIQUE(v);
	reverse(ALL(v));
	int ans=0;
	for(int i:v){
		if((x^i)<x){
			ans++;
			x^=i;
		}
	}
	if(x!=0){
		cout<<"-1\n";
	}
	else cout<<ans<<'\n';
	return 0;
}


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

int main() {
  int X, p = 0;
  cin >> X;
  for (int i = 0; i < 360; i++) {
    p = (p+X)%360;
    if (p == 0) {
      cout << i+1 << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef long long ll;
typedef pair<int,int> P;
int n;
double a[3000];
double dp[3000][3000];
signed main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=i;j++){
			if(i-j-1>=0)dp[j][i-j]+=dp[j][i-j-1]*(1-a[i-1]);
			if(j-1>=0)dp[j][i-j]+=dp[j-1][i-j]*a[i-1];
		}
	}
	double ans=0;
	for(int j=n;j>n-j;j--)ans+=dp[j][n-j];
	printf("%.12lf\n",ans);
	return 0;
}


Measured memory_bytes: 70016
N = int(input())
A = list(map(int, input().split()))

prev = 0
es = []
for a in reversed(sorted(A)):
    if(prev == a):
        es.append(a)
        prev = 0
        if len(es) == 2:
            print(es[0] * es[1])
            break
    else:
        prev = a
else:
    print(0)


Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
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;
}

//a^n mod を計算する関数
long long modpow(long long a,long long n,long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n % 2 == 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//a^(-1) mod すなわちaの逆元を返す関数
long long modinv(long long a,long long mod) {
    return modpow(a,mod-2,mod);
}

//最大公約数をを返す関数
long long gcd (long long a,long long b) {
    if(a % b == 0) {
        return b;
    }else {
        return (gcd(b,a%b));
    }
}

const long long INF = 1LL << 60;
const long long P = 1000000007;

//nCkを求める関数
long long conbi (long long n,long long k) {
    long long res = 1;
    long long inv;
    for(long long i = n-k+1; i <= n; i++) {
        res *= i;
        res %= P;
    }
    for(long long i = 1; i <= k; i++) {
        inv = modinv(i,P);
        res *= inv;
        res %= P;
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    long long power = 1;
    for(int i = 1; i <= n; i++) {
        power *= i;
        power %= P;
    }
    cout << power;
    return 0;
}


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

int main(){
  int a,b,n,i,min=1000000,sum=0;

  cin >> n;
  for(i=1;i<(n/2)+1;i++){
    a=i;
    b=n-i;
    sum=0;
    while(a>0){
      sum+=a%10;
      a/=10;
    }
    while(b>0){
      sum+=b%10;
      b/=10;
    }
    if(min>sum)min=sum;
  }
  cout << min;
  return 0;
}
    


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int count=0,i;
    char word[6];
    cin>>word;
    if(word[2]==word[3])
    {
        count++;
    }
    if(word[4]==word[5])
    {
        count++;
    }
    if(count==2)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
import sys

class graph:
  def __init__(self):
    nm = input().split()
    # # vertices
    self.nv = int(nm[0])
    # # edges
    self.ne = int(nm[1])
    # vertices
    self.vertices = [i for i in range(self.nv)]
    # edge [edge id][0,1]
    self.edges = [[0, 0] for i in range(self.ne)]
    # accessible_edge [vertex id][connected vertex id]
    self.accessible_edge = [[] for i in range(self.nv)]
    for i in range(self.ne):
      e = list(map(lambda x: int(x)-1, input().split()))
      self.edges[i] = e
      self.accessible_edge[e[0]].append(e[1])
      self.accessible_edge[e[1]].append(e[0])
  
  def remove_edge(self, i):
    removed_accessible_edge = [[] for i in range(self.nv)]
    for j in range(self.ne):
      if j!=i:
        e = self.edges[j]
        removed_accessible_edge[e[0]].append(e[1])
        removed_accessible_edge[e[1]].append(e[0])
    return removed_accessible_edge

  def BFS(self, mod_edge):
    visited = [False for i in range(self.nv)]
    queue = []

    #initial id
    I = 0
    # stack, [0]=  vertex id, [1] = # searched children index
    queue.append(I)
    visited[I] = True
    while len(queue)!=0:
      # vertex id
      vid = queue.pop(0)
      # print(vid+1)
      v_edges = mod_edge[vid]
      # if not all([visited[e] for e in v_edges]):
      for e in v_edges:
        if not visited[e]:
          visited[e] = True
          queue.append(e)
    return all(visited)
    

if __name__ == "__main__":
  g = graph()
  count = 0
  g.BFS(g.accessible_edge)
  for i in range(g.ne):
    mod_edge = g.remove_edge(i)
    # print(mod_edge)
    count += 1 if not g.BFS(mod_edge) else 0
  print(count)

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




int main() {
   #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
 ios_base::sync_with_stdio(0);
 cin.tie(0);
 cout.tie(0);
 ll a,b,x; 
 cin>>a>>b>>x;
 ll u=b/x;
 ll l=(a+(x-1))/x;
 cout<<u-l+1<<endl;

  return 0;
}


Measured memory_bytes: 3660
#include <stdio.h>
#include <ctype.h>
int a[15];
int str(char s[]){
  int i;
  for(i=0;i<11;i++){
    if(isupper(s[i])!=0)
    a[i]=1;
    else
    a[i]=0;
    if(s[i]=='\0')
    return i;
  }
  return 0;
}
int main(int argc, char const *argv[]) {
  int i,cm=0,x,y;
  char  S[15];
  scanf("%s",S);
  if(S[0]!='A'){
  printf("WA\n" );
  return 0;
}
x=str(S);
  for(i=1;i<=x;i++){
    if(a[i]==1){
    cm++;
    y=i;
  }
  }
  if(cm!=1 || a[1]==1 || a[x-1]==1 || S[y]!='C'){
  printf("WA\n" );
  return 0;
}
printf("AC\n" );
  return 0;
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //a
  int a, b;
  cin >> a >> b;
  cout << max({a + b, a - b, a * b}) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>  
#include<map>
#include<set>
using namespace std;

int main(){
	bool f[13][13]={};
	int TT[15][15]={};
	string p,q;
	for(int i=1;i<=4;i++){
		cin>>p>>q;
		for(int j=0;j<p.size();j++)
			if(p[j]=='1')f[2*i-1][j+1]=1;
		for(int j=0;j<q.size();j++)
			if(q[j]=='1')f[i*2][j+1]=1;
	}
	cin>>p;
		for(int j=0;j<p.size();j++)
			if(p[j]=='1')f[9][j+1]=1;
	/*for(int i=0;i<=10;i++){
		for(int j=0;j<=5;j++)
			cout<<f[i][j];
		cout<<endl;
	}*/
	int x=1,y=1;
	char z='R';int v=0;
	while(1){
		if(z=='R'){
			if(f[y-1][x]){
				cout<<"U";z='U';y-=2;
			}
			else if(f[y][x]){
				cout<<"R";z='R';x++;
			}
			else if(f[y+1][x]){
				cout<<"D";z='D';y+=2;
			}
			else{
				cout<<"L";z='L';x--;
			}


		}
		else if(z=='L'){
			if(f[y+1][x]){
				cout<<"D";z='D';y+=2;
			}
			else if(f[y][x-1]){
				cout<<"L";z='L';x--;
			}
			else if(f[y-1][x]){
				cout<<"U";z='U';y-=2;
			}
			else{
				cout<<"R";z='R';x++;
			}
		}

		else if(z=='U'){
			if(f[y][x-1]){
				cout<<"L";z='L';x--;
			}
			else if(f[y-1][x]){
				cout<<"U";z='U';y-=2;
			}
			else if(f[y][x]){
				cout<<"R";z='R';x++;
			}
			else{
				cout<<"D";z='D';y+=2;
			}
		}
		else if(z=='D'){
			if(f[y][x]){
				cout<<"R";z='R';x++;
			}
			else if(f[y+1][x]){
				cout<<"D";z='D';y+=2;
			}
			else if(f[y][x-1]){
				cout<<"L";z='L';x--;
			}
			else{
				cout<<"U";z='U';y-=2;
			}
		}
		if(x==1&&y==1)break;
		v++;
		//if(v>30)break;
		//cout<<x<<" "<<y<<"#"<<v<<endl;
		TT[y][x]=v;
	}/*
	for(int i=0;i<=10;i++){
		for(int j=0;j<=5;j++)
			cout<<TT[i][j];
		cout<<endl;
	}
	*/

	cout<<endl;
	return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define RNG(x, a, n) begin(x)+(a), begin(x)+(n)
#define ADD(a, b) ((((a)%MOD+MOD)%MOD+((b)%MOD+MOD)%MOD)%MOD)
#define SUB(a, b) ((((a)%MOD+MOD)%MOD-((b)%MOD+MOD)%MOD+MOD)%MOD)
#define MUL(a, b) (((((a)%MOD+MOD)%MOD)*(((b)%MOD+MOD)%MOD))%MOD)
#define CHADD(a, b) (a = ADD(a, b))
#define CHMUL(a, b) (a = MUL(a, b))
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b){ if(a<b){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b){ if(a>b){ a=b; return true; } return false; }


int N, C[200010];


signed main(){
    cin >> N;
    rep(i, 0, N) cin >> C[i];

    sort(RNG(C, 0, N), greater<int>());

    int p4 = 1LL;
    rep(i, 1, N) CHMUL(p4, 4);

    int ans = 0;
    rep(i, 0, N) CHADD(ans, MUL(p4, MUL(C[i], i+2)));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n = I()
A = LI()
if all([a > 0 for a in A]):
    now = min(A)
    print(sum(A) - now * 2)
    A.remove(now)
    last = A.pop()
    while A:
        nxt = A.pop()
        print(now, nxt)
        now -= nxt
    print(last, now)
elif all([a < 0 for a in A]):
    now = max(A)
    print(-sum(A) + now * 2)
    A.remove(now)
    while A:
        nxt = A.pop()
        print(now, nxt)
        now -= nxt
else:
    print(sum([abs(i) for i in A]))
    minus = []
    plus = []
    for a in A:
        if a > 0:
            plus += [a]
        elif a < 0:
            minus += [a]
        else:
            if not plus:
                plus += [a]
            else:
                minus += [a]
    minus_now = minus.pop()
    plus_now = plus.pop()
    while plus:
        nxt = plus.pop()
        print(minus_now, nxt)
        minus_now -= nxt
    while minus:
        nxt = minus.pop()
        print(plus_now, nxt)
        plus_now -= nxt
    print(plus_now, minus_now)


Measured memory_bytes: 61712
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/abc075/editorial.pdf
・自力ACしたのがO(N^4)でこれはO(N^5)の愚直解
・制約からして何とかなりそうだし、こっちのが実装全然軽いし実戦向きぽいね。
　→O(N^5)=50^5=3億1250万はpypyでも無理だったわ。
・添字見づらくなったけど定数倍改善。多分半分で約1憶5000万かと。
"""

N, K = map(int, input().split())

X, Y = [0]*N, [0]*N
for i in range(N):
    X[i], Y[i] = map(int, input().split())

X2 = sorted(set(X))
Y2 = sorted(set(Y))

ans = float('inf')
# 可能性のある全長方形ループ
for i in range(len(X2)):
    for j in range(len(Y2)):
        for k in range(i+1, len(X2)):
            for l in range(j+1, len(Y2)):
                cnt = 0
                # 各頂点ループで範囲内にあるか1つずつ確認する
                for m in range(N):
                    if X2[i] <= X[m] <= X2[k] and Y2[j] <= Y[m] <= Y2[l]:
                        cnt += 1
                if cnt >= K:
                    ans = min((X2[k] - X2[i]) * (Y2[l] - Y2[j]), ans)
print(ans)


Measured memory_bytes: 47196
# -*- coding: utf-8 -*-
while True:
    a, op, b= input().split(" ")
    a = int(a)
    b = int(b)
    
    if op == "?":
        break
    elif op == "+":
        print(a+b)
    elif op == "-":
        print(a-b)
    elif op == "*":
        print(a*b)
    elif op == "/":
        print(a//b)

Measured memory_bytes: 7680
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC
{
    class Program
    {
        static void Main(string[] args)
        {
            AGC012_A();
        }

        static void AGC012_A()
        {
            var N = int.Parse(Console.ReadLine());
            var an = Console.ReadLine().Split(' ').Select(long.Parse).OrderByDescending(x => x).ToArray();
            var dict = new Dictionary<int, List<long>>()
;
            for (var i = 0; i < N; i++)
                dict.Add(i, new List<long>());

            var k = 0;
            while (k < an.Length)
            {
                for (var i = 0; i < N; i++)
                {
                    dict[i].Add(an[k]);
                    k++;
                    if (k == an.Length) break;
                    dict[i].Add(an[k]);
                    k++;
                    if (k == an.Length) break;
                }
            }
            Console.WriteLine(dict.Values.Sum(x => x[1]));
        }
    }
}

Measured memory_bytes: 61736
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <fstream>
using namespace std;
#define mp make_pair

vector<int> median(vector<int> v) {
	sort(v.begin(), v.end());
	int n = v.size();
	vector<int> ret(1, v[n/2]);
	if (n % 2 == 0) {
		ret.push_back(v[n/2-1]);
	}
	return ret;
}

int main() {
	int W, H, N;
	cin >> W >> H >> N;
	vector<int> xs(N), ys(N);
	for (int i=0; i<N; ++i) {
		cin >> xs[i] >> ys[i];
	}
	vector<int> mx = median(xs);
	vector<int> my = median(ys);
	long long res = LLONG_MAX;
	int x, y;
	for (int i=0; i<(int)mx.size(); ++i) {
		for (int j=0; j<(int)my.size(); ++j) {
			long long time = 0, m = 0;
			for (int k=0; k<N; ++k) {
				long long t = abs(xs[k] - mx[i]) + abs(ys[k] - my[j]);
				time += t;
				m = max(m, t);
			}
			long long res2 = 2 * time - m;
			if (mp(res2, mp(mx[i], my[j])) < mp(res, mp(x, y))) {
				res = res2;
				x = mx[i];
				y = my[j];
			}
		}
	}
	cout << res << endl;
	cout << x << " " << y << endl;
	return 0;
}

Measured memory_bytes: 2328
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((LL)1e9+7) 
#define INF ((LL)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

int main(){
	LL N;
	cin >> N;
	cout << (N-1) * N / 2 << endl;
	return 0;
}


Measured memory_bytes: 256