akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

import copy

H,W = map(int,input().split())
a = [list(input().split()) for _ in range(H)]
for i in range(H):
    a[i] = list(a[i][0])
a_copy = copy.copy(a)
ans = [[] for _ in range(H)]
h=0
for i in range(H):
    Flag = True
    for j in range(W):
        if a[i][j] != ".":
            Flag = False
            break
    if not(Flag):
        for j in range(W):
            ans[h].append(a[i][j])
        h+=1
ans_H=h

ans2 = [[] for _ in range(H)]

for i in range(W):
    Flag = True
    for j in range(ans_H):
        if ans[j][i] != ".":
            Flag = False
            break
    if not(Flag):
        for j in range(ans_H):
            ans2[j].append(ans[j][i])


for i in range(ans_H):
    print("".join(ans2[i]))





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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A, B = [0]*N, [0]*N
sm = [[0]*2 for i in range(N)]
for i in range(N):
    A[i], B[i] = MAP()
    sm[i][0] = A[i] + B[i]
    sm[i][1] = i

sm.sort(key=itemgetter(0), reverse=True)

ans = 0
for i in range(N):
    if i % 2 == 0:
        ans += A[sm[i][1]]
    else:
        ans -= B[sm[i][1]]
print(ans)


Measured memory_bytes: 31244
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 10;
const int MOD = (int)1e9 + 7;

int n, l;
int go[N][2];
int dp[2][N];
char s[300000 + 5];

void solve()
{
    n = 8;
    go[0][0] = 2;
    go[0][1] = 3;
    go[1][0] = 4;
    go[1][1] = 5;
    go[2][0] = 0;
    go[2][1] = 0;
    go[3][0] = 0;
    go[3][1] = 1;
    go[4][0] = 6;
    go[4][1] = 1;
    go[5][0] = 5;
    go[5][1] = 5;
    go[6][0] = 4;
    go[6][1] = 4;
    go[7][0] = 0;
    go[7][1] = 1;

    scanf("%s", s);
    l = strlen(s);

    memset(dp, 0, sizeof dp);
    dp[0][7] = 1;
    for(int i = 0; i < l; ++ i) {
        int cur = i & 1;
        int nxt = 1 - cur;
        memset(dp[nxt], 0, sizeof dp[nxt]);

        for(int c = 0; c < 2; ++ c) {
            if (c == 0 && s[i] == '1') continue;
            if (c == 1 && s[i] == '0') continue;

            for(int j = 0; j < n; ++ j) {
                (dp[nxt][go[j][c]] += dp[cur][j]) %= MOD;
            }
        }
    }

    cout << (dp[l & 1][1] + dp[l & 1][5]) % MOD << endl;


}

int main()
{
    solve();
    return 0;
}



Measured memory_bytes: 512
def prime_factorization(n):  # 素因数分解
    res = []
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            cnt = 0
            while n % i == 0:
                cnt += 1
                n //= i
            res.append((i, cnt))
    if n > 1:
        res.append((n, 1))
    return res


N = int(input())
pf = prime_factorization(N)

ans = 0
for _, f in pf:
    x = 1
    while f >= x:
        ans += 1
        f -= x
        x += 1

print(ans)

Measured memory_bytes: 9468
//Littleboy123 Template 1.1

#include <bits/stdc++.h>
using namespace std;

//pragmas
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define FOR(a,b,c) for(ll (a)=(b);(a)<(c);++(a))
#define FORE(a,b,c) for(ll (a)=(b);(a)<=(c);++(a))
#define FORN(a,b,c) for(ll (a)=(b);(a)>(c);--(a))
#define FORNE(a,b,c) for(ll (a)=(b);(a)>=(c);--(a))
#define COUT(a) cout << (a) << '\n'
#define MEM(a,b) memset((a), (b), sizeof((a)))
#define MAX(a,b) (a) = max((a), (b))
#define MIN(a,b) (a) = min((a), (b))
#define nl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)

void init(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

//End of template

int main(){
	init();

	//debug
	/*
	ifstream in("input.in");
	streambuf *cinbuf = std::cin.rdbuf();
	cin.rdbuf(in.rdbuf());

	ofstream out("out.txt");
	streambuf *coutbuf = std::cout.rdbuf();
	cout.rdbuf(out.rdbuf());
	*/
	//end debug

	int n;
	cin >> n;
	int arr[n];
	FOR(i, 0, n)
		cin >> arr[i];
	sort(arr, arr+n);
	int ans = 1;
	FORNE(i, n-2, 0){
		if(arr[i] < arr[i+1]){
			ans++;
		}
	}
	cout << ans << nl;
	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;

#define INF (1e17)

ll N, M, L;

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

    ll A, B, C;
    vvi d(N, vi(N, INF));
    for (int i = 0; i < N; i++) {
        d[i][i] = 0;
    }

    for (int i = 0; i < M; i++) {
        cin >> A >> B >> C;
        A--;
        B--;
        d[A][B] = C;
        d[B][A] = C;
    }

    // warshall_floyd
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    vvi d2(N, vi(N, INF));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (d[i][j] == 0)
                d2[i][j] = 0;
            else if (d[i][j] <= L)
                d2[i][j] = 1;
        }
    }

    // warshall_floyd
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);
            }
        }
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (d2[i][j] >= INF)
                d2[i][j] = -1;
            else
                d2[i][j] = max(ll(0), d2[i][j] - 1);
        }
    }

    //
    int Q, s, t;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        cin >> s >> t;
        cout << d2[s - 1][t - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 1920
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()
x = str(input())

S = x[:N]
T = x[N+1:]
c = str()
for i in range(N):
    c += S[i]
    c += T[i]

print(c)

Measured memory_bytes: 38400
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()

#define PI 3.14159265359

using namespace std;
typedef long long unsigned int ll;

int main() {
	int r;
	cin >> r;
	cout << r * r;
}

Measured memory_bytes: 256
n = int(raw_input())
s = raw_input()

def d(r):
	for i in range(1, n):
		if r[i] == "S":
			if s[i] == "o":
				r += r[i-1]
			else:
				r += "S" if r[i-1] == "W" else "W"
		else:
			if s[i] == "o":
				r += "S" if r[i-1] == "W" else "W"
			else:
				r += r[i-1]
	if r[0] != r[-1]:
		return False
	else:
		if r[0] == "S":
			if s[0] == "o":
				if r[1] != r[-2]:
					return False
			else:
				if r[1] == r[-2]:
					return False
		else:
			if s[0] == "o":
				if r[1] == r[-2]:
					return False
			else:
				if r[1] != r[-2]:
					return False

	return r[:-1]

def main():
	r1 = "SS"
	r2 = "SW"
	r3 = "WS"
	r4 = "WW"
	a = d(r1)
	if a:
		print a
		return
	a = d(r2)
	if a:
		print a
		return
	a = d(r3)
	if a:
		print a
		return
	a = d(r4)
	if a:
		print a
		return
	print -1

main()

Measured memory_bytes: 6132
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
ll mod=1e9+7;
ll inv(ll a){
    ll n=mod-2,ans=1;
    while(n>0){
        if(n%2) ans=ans*a%mod;
        n=n/2;
        a=a*a%mod;
    }
    return ans;
}
ll nCr(ll a,ll b){
    ll ans=1;
    rep(i,b) ans=ans*(a-i)%mod*inv(i+1)%mod;
    return ans;
}
int main(){
    long long n,m,ans=1,A[200000]={0},a=0;
    cin>>n>>m;
    rep(i,sqrt(m)-1){
        while(m%(i+2)==0) A[a]++,m=m/(i+2);
        a++;
    }
    if(m>1) A[a]++,a++;
    sort(A,A+a,greater<ll>());
    rep(i,n) ans=(ans*nCr(n+A[i]-1,A[i]))%mod;
    cout<<ans;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  int H[n];
  for (int i= 0; i<n; i++) {
  	cin >> H[i];
  }
  int count = 1;
  for (int i = 1; i<n; i++) {
    for (int j = 0; j<i; j++) {
    	if (H[j]>H[i]) break;
      	if (j == i-1) count++;
    }
  }
  cout << count << endl;
}

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

int mcxi2i(char mcxi){
  switch(mcxi){
  case 'm': return 1000;
  case 'c': return 100;
  case 'x': return 10;
  case 'i': return 1;
  }
  return 0;
}


int MCXI2i(string mcxi){
  int ans = 0;
  for(size_t i = 0; i < mcxi.size(); i++){
    if(0 <= mcxi[i] - '0'
       && mcxi[i] - '0' <= 9){
      ans += (mcxi[i] - '0') * mcxi2i(mcxi[i + 1]);
      ++i;
    }
    else{ ans += mcxi2i(mcxi[i]); }
  }
  return ans;
}

string i2MCXI(int n){
  string ans = "";
  string mcxi = "mcxi";
  int radix[4] = {1000, 100, 10, 1};
  
  for(int i = 0; i < 4; i++){
    int tmp = n / radix[i];
    if(tmp >= 2){ ans += to_string(tmp); }
    if(tmp >= 1){ ans += mcxi[i]; }
    n -= (n / radix[i]) * radix[i];
  }
  
  return ans;
}

int main(void){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    string a, b;
    cin >> a >> b;
    cout << i2MCXI(MCXI2i(a) + MCXI2i(b)) << endl;
  }
  return 0;
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back      
#define F first
#define S second
#define SS stringstream
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define CC(x) cout << (x) << endl
#define pw(x) (1ll<<(x))
#define buli(x) __builtin_popcountll(x)
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define M 1000000007
#define N 211111

#define TASK "1"

using namespace std;

int main(){
	#ifdef home
		freopen(TASK".in","r",stdin);	
		freopen(TASK".out","w",stdout);
	#endif		
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	long long ans = 0;

	for (int o = 0; o < pw(s.size() - 1); o++) {
		SS q;
		for (int i = 0; i < s.size(); i++) {
			q << s[i];
			if (o & pw(i)) q << " ";
		}
		long long x;
		while ((q >> x)) ans += x;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 764
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, m;
  cin >> n >> m;

  vll dist(n + m, INF);

  vvll to(n+m);

  rep(i, n){
    ll k;
    cin >> k;
    rep(j, k){
      ll l;
      cin >> l;
      l--;
      to[i].push_back(n + l);
      to[n + l].push_back(i);
    }
  }

  dist[0] = 0;
  queue<ll> que;
  que.push(0);

  while(!que.empty()){
    ll u = que.front();
    que.pop();
    for(ll v : to[u]){
      if(dist[v] != INF) continue;
      que.push(v);
      dist[v] = dist[u] + 1;
    }
  }

  string ans = "YES";
  rep(i, n){
    if(dist[i] == INF){
      ans = "NO";
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 14140
// Candies
#include <cmath>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

int main() {
    int N;
    cin >> N;
    int A[2][N];
    int sumA0[N] = {0};
    int sumA1[N] = {0};
    for (int i = 0; i < N; i++) {
        cin >> A[0][i];
        if (i == 0) sumA0[i] = A[0][i];
        else sumA0[i] = sumA0[i-1] + A[0][i];
    }
    for (int i = 0; i < N; i++) {
        cin >> A[1][i];
        if (i == 0) sumA1[i] = A[1][i];
        else sumA1[i] = sumA1[i-1] + A[1][i];
    }
    int max_ame = 0;
    for (int i = 0; i < N; i++) {
        int ame = 0;
        if (i == 0) ame = sumA0[i] + sumA1[N-1];
        else ame = sumA0[i] + sumA1[N-1] - sumA1[i-1];
        max_ame = max(max_ame, ame);
    }
    cout << max_ame << endl;
}

Measured memory_bytes: 256
n = int(input())
title = []
time = []
for i in range(n):
    s,t = input().split()
    t = int(t)
    title.append(s)
    time.append(t)
x = input()

tar = 0

for i in range(n):
    if x == title[i]:
        tar = i
        break
ans = 0
for i in range(tar+1, n):
    ans += time[i]

print(ans)

Measured memory_bytes: 3064
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx")
#include <bits/stdc++.h>

namespace {
    template<int n, typename T>
    void mult(const T *__restrict a, const T *__restrict b, T *__restrict res) {
        if (n <= 64) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    res[i + j] += a[i] * b[j];
                }
            }
        } else {
            const int mid = n / 2;
            alignas(64) T btmp[n], E[n] = {};
            auto atmp = btmp + mid;
            for (int i = 0; i < mid; i++) {
                atmp[i] = a[i] + a[i + mid];
                btmp[i] = b[i] + b[i + mid];
            }
            mult<mid>(atmp, btmp, E);
            mult<mid>(a + 0, b + 0, res);
            mult<mid>(a + mid, b + mid, res + n);
            for (int i = 0; i < mid; i++) {
                const auto tmp = res[i + mid];
                res[i + mid] += E[i] - res[i] - res[i + 2 * mid];
                res[i + 2 * mid] += E[i + mid] - tmp - res[i + 3 * mid];
            }
        }
    }
}

using ll = long long;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    const int NMAX = (1 << 11)*49;
    alignas(64) static ll a[NMAX], b[NMAX * 2];
    int n; ll k; std::cin >> n >> k;
    for (int i = 0, val; i < n; i++) {
        std::cin >> val;
        a[val]++;
    }
    mult<NMAX>(a,a,b);
    ll answ(0);
    for (int i = 2 * NMAX - 1; k > 0 && i >= 0; i--) {
        answ += std::min(k, b[i]) * i;
        k -= b[i];
    }
    std::cout << answ << std::endl;
    return 0;
}


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

void solve(long long K){
    if (K<=9) printf("%lld\n",K);
    else {
        int count = 9;
        vector<ll> cand{1,2,3,4,5,6,7,8,9};
        while(1){
            vector<ll> next;
            for (ll elem :cand){
                int tail = elem %10;
                for (int j = max(tail-1,0);j<10 && j <= tail+1;j++){
                    ll num = j + 10 * elem;
                    next.push_back(num);
                    //printf("%lld\n",num);
                    count++;
                    if (count == K) {printf("%lld\n",num);break;}
                }
                if (count >=K) break;
            }
            if (count >=K) break;
            cand = std::move(next);
        }

    }

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


Measured memory_bytes: 1072
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define MAX_N 40
#define INF 100000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;

int n, m, k;
vector<int> d;
map<int,int> rev;
int e[100][100];
int dp[(1<<16)];
queue<int> que;

int main(){
    cin >> n >> m >> k;
    rep(i,(1<<16)) dp[i] = INF;
    rep(i,m){
        int D;
        cin >> D;
        d.push_back(--D);
        rev[D] = i;
    }
    rep(i,n) rep(j,k){
        int v;
        cin >> v; v--;
        e[i][j] = v;
    }
    int st = 0;
    rep(i,d.size()){
        st += (1<<i);
    }
    dp[st] = 0;
    que.push(st);
    while(!que.empty()){
        int p = que.front();
        que.pop();
        rep(i,k){
            int nxt = 0;
            rep(j,d.size()){
                if(p&(1<<j)){
                    int to = e[d[j]][i];
                    if(rev.count(to)){
                        nxt |= (1<<rev[to]);
                    }
                }
            }
            if(dp[nxt] == INF){
                dp[nxt] = dp[p]+1;
                que.push(nxt);
            }
        }
    }
    cout << dp[0] << endl;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

int main() {
    ios_base::sync_with_stdio(0);
    ll t, i, j, k, p, q, r, x, y, u, v, n, m;
    cin>>u>>v>>n>>m;
    ll a,b;
    if(u>=0&&v>=0)
    {
       a= v;
       if(n>=0&&m>=0)
       {
          b=m;
       }
       else if(n<0&&m<0)
       {
          a=u;
          b=m;
       }
       else{
         b=m;
       }
    }
    else if(u<0&&v<0)
    {
       a=u;
       if(n>=0&&m>=0)
       {
          a=v;
          b=n;
       }
       else if(n<0&&m<0)
       {
          b=n;
       }
       else{
         b=n;
       }
       
    }
    else
    {
      a=v;
      if(n>=0&&m>=0)
       {
          b=m;
       }
       else if(n<0&&m<0)
       {
          a=u;
          b=n;
       }
       else{
        //  deb2(u,v);
        //  deb2(n,m);
         if(u*n>v*m)
         {
          //  cout<<"here"<<endl;
           a=u;
           b=n;
         }
         else
           b=m;
       }
    }
    // deb2(a,b);
    cout<<a*b<<endl;

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}




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

int main() {
  int n, k;
  cin>>n;
  vector<int> a(n);
  rep(i,n){
    cin>>k;
    a[i]=k;
  }
  sort(a.begin(), a.end());
  
  cout<<a[n/2]-a[n/2-1]<<endl;
  
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(vec) vec.begin(),vec.end()
#define rep(i,n) for(ll i = 0;i<n;++i)
#define repc(bit,k,n) for (ll bit = (1<<k)-1;bit < (1<<n); bit = next_combination(bit))
#define repi(itr,vec) for(auto itr = vec.begin();itr!=vec.end();++itr)
using namespace std;
vector<vector<int> >path(1001);
vector<int>X;
int dp[1001][2];
bool checked[1001];
int dp2[1001][1001];
bool checked2[1001][1001];
const int INF = 1000000007;

template<class T> inline bool chmin(T& a, T b) {
      if (a > b) {
                a = b;
                        return true;
                            }
          return false;
}
int solve(const int i, int cur,int s){
  if(checked2[cur][s])return dp2[cur][s];
  if(cur==-1)return 0;
  int ans = INF;
  rep(j,2){
    if(dp[path[i][cur]][j]<=s){
      int temp = solve(i,cur-1,s-dp[path[i][cur]][j]);
      if(temp<0)continue;
      chmin(ans,temp+dp[path[i][cur]][1-j]);
    }else continue;
  }
  if(ans==INF)ans = -1;
  checked2[cur][s] = true;
  return dp2[cur][s] = ans;

}

int check(int i){
  if(checked[i])return 1;
  repi(itr,path[i]){
    if(check(*itr)==-1) return -1;
  }
  fill((bool*)checked2, (bool*)checked2+sizeof(checked2)/sizeof(bool),false);
  int temp = solve(i, path[i].size()-1, X[i]);
  if(temp<0) return -1;
  dp[i][0] = X[i];
  dp[i][1] = temp;
  checked[i] = true;
  return 1;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;cin>>n;
  rep(i,n-1){
    int a; cin>>a;a--;
    path[a].push_back(i+1);
  }
  rep(i,n){
    int a;cin>>a;
    X.push_back(a);
  }
  if(check(0)==-1)cout<<"IMPOSSIBLE\n";
  else cout<<"POSSIBLE\n";

  return 0;
}

Measured memory_bytes: 8568
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

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

    int port = 1;
    int ans = 0;
    rep(i, 10000) {
        if (port >= b) break;
        port += a - 1;
        ans += 1;
    }
    print(ans);

    return 0;
}



Measured memory_bytes: 256
#import <stdio.h>
#define MAX(a,b) ((a)<(b)?(b):(a))
long CEIL(long x, long y){
    if(x%y==0) {
        return x/y;
    }else{
        return x/y+1;
    }
}
int main(){
    int n;
    scanf("%d",&n);
    long a=1,b=1;
    for(int i=0;i<n;i++){
        long c,d;
        scanf("%ld %ld",&c,&d);
        long k = MAX(CEIL(a,c),CEIL(b,d));
        a=c*k;
        b=d*k;
    }
    printf("%ld",a+b);
}


Measured memory_bytes: 2172
use std::collections::HashMap;
#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(non_snake_case)]
fn main() {
    input![N: usize, A: [i32; N]];
    let mut map = HashMap::new();
    for a in &A {
        *map.entry(a).or_insert(0) += 1;
    }
    let mut ans = 0;
    for (&k, &v) in &map {
        ans += if k <= &v { v - k } else { v };
    }
    println!("{}", ans);
}


Measured memory_bytes: 12540
#include<bits/stdc++.h>
#define rep(i, x) for (ll i = 0; i < (x); i++)
#define chmax(x, a)  do { x = max(x, a); } while(0)

template<typename T>
using reversed_priority_queue = \
    std::priority_queue<T, std::vector<T>, std::greater<T> >;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main(void) {
  ll N;
  cin >> N;
  vector<ll> a(N);
  rep(i, N)
    cin >> a[i];
  sort(begin(a), end(a));
  priority_queue<ll> q;
  ll i = N - 1, ans = 0;
  q.push(a[i--]);
  while (i >= 0) {
    ans += q.top();
    q.pop();
    q.push(a[i]);
    q.push(a[i]);
    i--;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6940
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			String[] str = scan.nextLine().split(",");
			double[] point = new double[str.length];
			for(int i = 0;i < str.length;i++){
				point[i] = Double.parseDouble(str[i]);
			}
			if(point[0] == point[2]){
				System.out.printf("%.5f %.5f\n",2.0*point[0]-point[4],point[5]);
				continue;
			}
			double a = (point[3]-point[1]) / (point[2]-point[0]);
			double b = ((point[1]*point[2]) - (point[0]*point[3])) / (point[2]-point[0]);
			if(a == 0){
				System.out.printf("%.5f %.5f\n",point[4],2.0*b-point[5]);
				continue;
			}
			double c = 1 + a*a;
			double x = (1.0 - a*a)*point[4] - 2*a*b + 2*a*point[5];
			double y = (a*a - 1.0)*point[5] + 2*a*point[4] + 2*b;
			System.out.printf("%.5f %.5f\n",x/c,y/c);
		}
	}
	
}

Measured memory_bytes: 17192
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <numeric>

using namespace std;

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

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

int n;

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

    cin >> n;
    vector<int> b(n);
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }

    vector<int> ans;
    while (!b.empty()) {
        int i;
        for (i = (int) b.size() - 1; i >= 0; --i) {
            if (b[i] == i + 1) {
                ans.emplace_back(b[i]);
                b.erase(b.begin() + i);
                break;
            }
        }
        if (i == -1) {
            cout << -1 << endl;
            return 0;
        }
    }
    reverse(ans.begin(), ans.end());
    for (auto &i : ans) cout << i << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {

    val n = readLine()!!.toInt()
    var x = readLine()!!.split(" ").map(String::toInt).toMutableList()
    val m = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map(String::toInt)

    val o = 2019

    for (i in 0..m-1) {

        if (a[i] >= n) {
            //一番右端のコマ確定
            if (x[a[i]-1] < o) {
                x[a[i]-1] = x[a[i]-1] + 1
            }
        } else {
            if (x[a[i]-1]+1 != x[a[i]]) {
                x[a[i]-1] = x[a[i]-1] + 1
            }    
        }
    }
    x.forEach {i ->  println(i)}
}


Measured memory_bytes: 32080
package main

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

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	as := make([]int, n)
	pm := make(map[int][2]int)
	pc := [19][19]int{}
	for i := 0; i < n; i++ {
		a := nextFloat()
		as[i] = int(math.Round(a * 1e9))

		p2 := 0
		for t := as[i]; t%2 == 0; t /= 2 {
			p2++
		}
		p5 := 0
		for t := as[i]; t%5 == 0; t /= 5 {
			p5++
		}
		p2 = min(18, p2)
		p5 = min(18, p5)

		pc[p2][p5]++
		pm[as[i]] = [2]int{p2, p5}
	}

	ans := 0
	for _, a := range as {
		a2, a5 := pm[a][0], pm[a][1]
		for b2 := 0; b2 <= 18; b2++ {
			for b5 := 0; b5 <= 18; b5++ {
				if a2+b2 >= 18 && a5+b5 >= 18 {
					ans += pc[b2][b5]
					if a2 == b2 && a5 == b5 {
						ans--
					}
				}
			}
		}
	}
	ans /= 2

	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat() float64 {
	sc.Scan()
	i, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return i
}


Measured memory_bytes: 19000
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

int[2][6] pt;

void main()
{
    foreach (i; 0..3) {
        auto ab = readln.split.to!(int[]);
        pt[i] = [ab[0], ab[1]];
        pt[3+i] = [ab[1], ab[0]];
    }

    foreach (i, a; pt) {
        foreach (j, b; pt) {
            foreach (k, c; pt) {
                if (i%3 == j%3 || j%3 == k%3 || k%3 == i%3) continue;
                if (a[1] == b[0] && b[1] == c[0]) {
                    writeln("YES");
                    return;
                }
            }
        }
    }
    writeln("NO");
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int,int> P;
int H,W;
int dx[4] = {-1,1,0,0},dy[4] = {0,0,-1,1};
int dist[1010][1010] = {};
char F[1010][1010];

bool in(int x,int y){
    return 1<=x && x<=H && 1<=y && y<=W;
}
int main(){
    cin >> H >> W;
    queue<P> Q;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            cin >> F[i][j];
            dist[i][j] = -1;
            if(F[i][j]=='#'){
                Q.push({i,j});
                dist[i][j] = 0;
            }
        }
    }
    while(!Q.empty()){
        P p = Q.front(); Q.pop();
        int x = p.first,y = p.second;
        for(int i=0;i<4;i++){
            int nx = x+dx[i],ny=y+dy[i];
            if(!in(nx,ny) || dist[nx][ny]!=-1) continue;
            dist[nx][ny] = dist[x][y]+1;
            Q.push({nx,ny});
        }
    }
    int ans = 0;
    for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) ans = max(ans,dist[i][j]);
    cout << ans << endl;
}

Measured memory_bytes: 13328
#include <iostream>

int main()
{
    int A, B, C, K;
    std::cin >> A >> B >> C >> K;
    int result = 0;
    if(A <= K) {
        result += A;
        K -= A;
    }
    else {
        std::cout << K << std::endl;
        return 0;
    }
    K -= B;
    if(K <= 0) {
        std::cout << result << std::endl;
        return 0;
    }
    std::cout << (result - K) << std::endl;
    return 0;
}

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


int main(){
  int a[50000];
  int d; // d[i] : a[i]ツ暗按降ツづ勲SS ツづ個催妥・ツ値
  int n;

  while( cin>>n && n ){
    for( int i=0;i<n;cin>>a[i++] );

    int mx = a[0];
    for( int i=0;i<n;i++ ){
      int sum =a[i];
      d=sum;
      for( int j=i+1;j<n;j++ ){
	sum+=a[j];
	d = max( d,sum );
      }
      mx = max( mx,d );
    }
    cout << mx << endl;
  }

  return 0;
}

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

int main()
{
    char mas[105][105];
    int H, W;

    fill_n(*mas, 105 * 105, '#');

    cin >> H >> W;

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

    for(int i = 0; i <= H + 1; i++) {
        for(int j = 0; j <= W + 1; j++) {
            cout << mas[i][j];
        }
        cout << endl;
    }

    return (0);
}


Measured memory_bytes: 256
#include<stdio.h>
char map[20][13][13];
int nya;
void a_land(char x,char y){
    if(map[nya][x][y-1]=='1'&&y!=0){
        map[nya][x][y-1]='0';
        a_land(x,y-1);
    }
    if(map[nya][x+1][y]=='1'&&x!=11){
        map[nya][x+1][y]='0';
        a_land(x+1,y);
    }
    if(map[nya][x][y+1]=='1'&&y!=11){
        map[nya][x][y+1]='0';
        a_land(x,y+1);
    }
    if(map[nya][x-1][y]=='1'&&x!=0){
        map[nya][x-1][y]='0';
        a_land(x-1,y);
    }
}
int main(void){
    int i,j,n=0;
    for(nya=0;;nya++){
        for(i=0;i<12;i++){
            if(scanf("%s",map[nya][i]) == EOF) {
                goto end;
            }
        }
        for(i=0;i<12;i++){
            for(j=0;j<12;j++){
                if(map[nya][i][j]=='1'){
                    map[nya][i][j]=='0';
                    a_land(i,j);
                    n++;
                }
            }
        }
    printf("%d\n",n);
    n=0;
    getchar();
    }
end:
return 0;
}

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

int main() {
  string N;
  cin >> N;
  for (int i = 0; i < N.size()/2; i++) {
    if (N[i] != N[N.size()-i-1]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <queue>
#include <set>
using namespace std;

int main(){
    int N, K;
    std::string S;
    std::cin >> N >> K;
    std::cin >> S;
    if(S.substr(K-1,1) == "A"){
        S.replace(K-1,1,"a");
    }else if(S.substr(K-1,1) == "B"){
        S.replace(K-1,1,"b");
    }else{
        S.replace(K-1,1,"c");
    }
    std::cout << S << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int X,A,B;
  scanf("%d %d %d",&X,&A,&B);

  if(X >= -A+B){
    if(A >= B){
      printf("delicious\n");
    } else {
      printf("safe\n");
    }
  } else {
    printf("dangerous\n");
  }
  return 0;
}

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

int main(){
	string s;
	cin>>s;
	bool f=true;
	for(int i=0;i<3;i++){
		if(s[i]==s[i+1])f=false;
	}
	if(f)cout<<"Good"<<endl;
	else cout<<"Bad"<<endl;
	return 0;
}

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

/*Starry Sky Tree*/
/*Range Add Min(Max) Query*/
/*区間加算、区間Min,区間Max*/

class RSUQ{
public: 
  
  //遅延用の型  
  struct T{
    int type; //0 - empty   , 1 - update
    int value;
    T():type(0),value(0){}
    T(int type,int value):type(type),value(value){}
  };

  //マージ可能な主データ型
  struct D{
    int value;
    D():value(0){} /*適切な値にする!!!!!!*/
    D(int value):value(value){}
    bool operator < (D a)const {return value < a.value;} //merge用
  };
  
  int n;
  vector<D> dat;
  vector<T> td;
  D returnD = D(0); // 範囲外の時に返す値。
  
  RSUQ(){n=-1;}
  RSUQ(int n_){
    n=1;
    while(n < n_) n *= 2;
    td.resize(2*n-1,T());
    dat.resize(2*n-1,D());
  }
  
  D merge(D a,D b){return a.value + b.value;}
  
  void delay(int k,int len){
    if(td[k].type==0) return;
    int v = td[k].value;
    td[k].type = 0;
    td[k].value = 0;
    
    len /= 2;
    int l = k*2+1,r = k*2+2;
    dat[l].value = v * len; td[l].type = 1; td[l].value = v;
    dat[r].value = v * len; td[r].type = 1; td[r].value = v;
  }

  D write(int k,int x, int len){
    dat[k].value = x * len;
    td[k].type = 1;
    td[k].value = x;
    return dat[k];
  }
  
  //[a,b)の値をx変更　query(a,b,x)
  D update(int a,int b,int x,bool flg=true,int k=0,int l=0,int r=-1){
    if(r==-1) r=n, assert(a <= n && b <= n);
    if(r <= a||b <= l) return flg? dat[k]:returnD;
    if(a <= l && r <= b) return flg? write(k, x, r - l):dat[k];
    
    delay(k, r - l);
    D vl = update(a,b,x,flg,k*2+1,l,(l+r)/2);
    D vr = update(a,b,x,flg,k*2+2,(l+r)/2,r);
    if(flg) dat[k] = merge(vl, vr);
    return merge(vl, vr);
  }
  
  //[a,b)の合計値を得る　find(a,b);
  int find(int a,int b){
    D res = update(a,b,0,false);
    return res.value;
  }
};


signed main(){
  int n,q;
  cin>>n>>q;
  
  RSUQ rsuq(n);

  while(q--){
    int cmd;
    cin>>cmd;
    if(cmd == 0){
      int s,t,x;
      cin>>s>>t>>x;
      rsuq.update(s,t+1,x);
    }
    if(cmd == 1){
      int s,t;
      cin>>s>>t;
      cout<<rsuq.find(s,t+1)<<endl;
    }
  }
  
  return 0;
}



Measured memory_bytes: 8832
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> x(N);
  for(int i=0; i<N; i++){
    cin >> x[i];
  }
  int ans=INFI;
  for(int i=0; i<N-K+1; i++){
    if(x[i]<0 && x[i+K-1]<=0){
      ans = min(ans,abs(x[i]));
    }else if(x[i]>=0 && x[i+K-1]>0){
      ans = min(ans,abs(x[i+K-1]));
    }else{
      if(abs(x[i]) < abs(x[i+K-1])){
        ans = min(ans,x[i+K-1]-x[i]+abs(x[i]));
      }else{
        ans = min(ans,x[i+K-1]-x[i]+x[i+K-1]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

vector < pair < pair <string, int>, int> > v;

bool comp(pair < pair <string, int>, int> a, pair < pair <string, int>, int> b)
{
    if(a.first.first == b.first.first)return a.first.second > b.first.second;
    else return a.first.first < b.first.first;
}

int main()
{
    int n;
    cin >> n;
    string city;
    int rate;
    for (int i = 0; i < n; i++)
    {
        cin >> city >> rate;
        v.push_back(make_pair(make_pair(city,rate), i+1));
    }
    sort(v.begin(), v.end(), comp);
    for (auto it : v)
    {
        cout << it.second << '\n';
    }
}


Measured memory_bytes: 256
# coding: utf-8
def format_building(building):
    return "\n".join(map(lambda floor: " " + " ".join(map(str, floor)),building))
    
line_number = int(input())
regidents_data = [list(map(int, input().split(" "))) for i in range(line_number)]
buildings = [[[0 for room in range(10)] for floor in range(3)] for building in range(4)]

for data in regidents_data:
    b, f, r, v = data
    buildings[b-1][f-1][r-1] += v

print("\n####################\n".join(map(format_building, buildings)))

Measured memory_bytes: 7680
import sys
sys.setrecursionlimit(10**7)

def culc(List):
    global Q
    global commands

    score=0
    for i in range(Q):
        if List[commands[i][1]-1]-List[commands[i][0]-1]==commands[i][2]:
            score+=commands[i][3]
    return score



def max_score(List,last_number):
    global M
    global N
    global Q

    Max_score=0
    temp_score=0
    for i in range(last_number,M+1):
        List.append(i)
        if len(List)==N:
            temp_score=culc(List)
            Max_score=max(Max_score,temp_score)
        else:
            temp_score=max_score(List,i)
            Max_score=max(Max_score,temp_score)
        List.pop(-1)    #backtrack
    
    return Max_score


N,M,Q=map(int,input().split())
commands=[list(map(int,input().split())) for _ in range(Q)]


ans=max_score([],1)
print(ans)

Measured memory_bytes: 9144
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        mut n: i64,
    };
    n -= 1;
    let mut ans: Vec<u8> = Vec::new();
    loop {
        let remainder = n % 26;
        ans.push(b'a' + remainder as u8);
        if n < 26 {
            break;
        }
        n = n / 26 - 1;
    }
    println!(
        "{}",
        ans.into_iter().rev().map(|c| c as char).collect::<String>()
    );
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
 
int main(){
  ll i,j,cnt;
  int n;
  ll t=1,a=1;
  cin>>n;
  ll T[n],A[n];
  for(i=0;i<n;i++)cin>>T[i]>>A[i];
  for(i=0;i<n;i++){
    j=max((t+T[i]-1)/T[i],(a+A[i]-1)/A[i]);
    while(a>A[i]*j || t>T[i]*j)j++;
    t=j*T[i];
    a=j*A[i];
  }
  cout<<t+a;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <math.h>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)

typedef long long ll;
typedef long long int lli;

int main() {
    int N; //m;
    ll f;
    vector<int> a;   
    cin >> N;
    for (int i = 0; i < N; i++) {
        int num;
        cin >> num;
        a.push_back(num);
    }

    for (int i = 0;i < N; i++) {
        f += a.at(i) - 1;
    }
    
    cout << f << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

#define int ll

int a,b,c,n,m,k,t,ans,cnt;

string s;

signed main(){
    cin>>a>>b;
    if(a*b%2==0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 764
n = input()
n1 = int(n[0])
n2 = int(n[1])
n3 = int(n[2])
n4 = int(n[3])
flag = False

for op1 in ['+', '-']:
    for op2 in ['+', '-']:
        for op3 in ['+', '-']:
            if op1 == '+':
                n12 = n1 + n2
            else:
                n12 = n1 - n2

            if op2 == '+':
                n23 = n12 + n3
            else:
                n23 = n12 - n3

            if op3 == '+':
                n34 = n23 + n4
            else:
                n34 = n23 - n4

            if n34 == 7:
                flag = True
                break
        if flag:
            break
    if flag:
        break

print(n1, op1, n2, op2, n3, op3, n4, '=7', sep='')

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

vector<pair<int, int>> knives;
int n, h, ans = 0;

int solve();

int main() {
  int i, a, b;
  cin >> n >> h;
  for(i = 0; i < n; ++i) {
    cin >> a >> b;
    knives.push_back(make_pair(a, 0));
    knives.push_back(make_pair(b, 1));
  }
  sort(knives.begin(), knives.end(),
       greater<pair<int, int>>());
  cout << solve() << endl;
  return 0;
}

int solve() {
  int i = 0, ans = 0;
  pair<int, int> now;
  while(h > 0) {
    now = knives[i];
    if(now.second) {
      ++ans;
      h -= now.first;
    }
    else {
      ans += (h + now.first - 1) / now.first;
      h = 0;
    }
    ++i;
  }
  return ans;
}

Measured memory_bytes: 2420
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int const inf = numeric_limits<int>::max();

// RMQ
template<class T>
struct SegmentTree {
    int n;
    vector<T> dat;
    SegmentTree(int n_ = 0) : n(n_){
        n = 1;
        while(n < n_) n <<= 1;
        dat.resize(n*2, inf);
    }
    T query(int v, int w, int l, int r){
        if(r <= l || w == 0) return inf;
        if(l + w == r) return dat[v];
        return min(query(v<<1, w/2, l, min(r, w/2)),
                   query(v<<1|1, w/2, max(0, l-w/2), r-w/2));
    }
    void update(int i, T x){
        i += n;
        dat[i] = x;
        for(; i!=1; i>>=1) dat[i>>1] = min(dat[i], dat[i^1]);
    }
    T query(int l, int r){
        return query(1,n,l,r);
    }
    size_t size() const {
        return n;
    }
};

int main(){
    // cin.tie(0);
    // ios::sync_with_stdio(0);
    int n, q;
    while(cin >> n >> q){
        SegmentTree<int> st(n);
        while(q--){
            char c;
            int x, y;
            cin >> c >> x >> y;
            if(c == '0'){
                st.update(x,y);
            } else {
                cout << st.query(x,y+1) << endl;
            }
        }
    }
}

Measured memory_bytes: 2052