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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second
const int N = 2e5+5;

ll pre[N] , suf[N] , n , a[N] , ans=0;


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

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

    ans = pre[n];
    for(int i=n; i>0; i--)
    {
        suf[i] = __gcd(suf[i+1] , a[i]);
    }

    for(int i=1; i<=n; i++)
    {
        ll tmp = __gcd(suf[i+1] , pre[i-1]);
        ans = max(ans , tmp);
    }
    cout << ans << '\n';
//
    return 0;
}

Measured memory_bytes: 5972
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
  
#define mp make_pair
#define f first
#define s second
#define ll long long
#define pb push_back
#define popb pop_back
#define popf pop_front

using namespace std;

using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int inf = 2e9+7, mod=1e9+7;
const int N = 1e6+321, E=14e5;

ll xx[8]={1, 1, -1, -1, 1, -1, 0, 0};
ll yy[8]={1, -1, 1, -1, 0, 0, 1, -1};

string s[10];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	for(int i=0; i<5; i++){
		cin >> s[i];
		if (s[i]=="0")
			cout << i+1;
	}
    return 0;
}

Measured memory_bytes: 3604
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

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() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

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

func main() {
	defer stdout.Flush()

	H := readInt()
	_ = readInt()
	a := make([][]byte, H)
	for i := range a {
		a[i] = []byte(readString())
	}
	b := make([][]byte, 0, H)
	for _, x := range a {
		flag := false
		for _, r := range x {
			if r == '#' {
				flag = true
			}
		}
		if flag {
			b = append(b, x)
		}
	}
	c := make([][]byte, len(b))
	for j := 0; j < len(b[0]); j++ {
		flag := false
		for i := 0; i < len(c); i++ {
			if b[i][j] == '#' {
				flag = true
			}
		}
		if flag {
			for i := 0; i < len(c); i++ {
				c[i] = append(c[i], b[i][j])
			}
		}
	}

	for i := range c {
		println(string(c[i]))
	}

}

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


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for(int i=0;i<N;i++){
            a[i]=sc.nextInt();
        }
        Arrays.sort(a);
        int Alice = 0;
        int Bob = 0;
        for(int i=N-1;i>=0;i--){
            if(((N-i)&1)==1) Alice += a[i];
            else Bob += a[i];
        }
        
        System.out.println(Alice-Bob);


    }
}

Measured memory_bytes: 21844
#include <iostream>
#include<time.h>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1<<30
#define INFTY 1000000000000000001LL
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
int main(){
    int n;cin>>n;
    int h[101];rep(i,n)cin>>h[i];
    h[n]=0;
    int ans=h[0];
    for(int i=1;i<n;i++){
        int tmp=h[i]-h[i-1];
        if(tmp>0)ans+=tmp;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
#define forn(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define FORR(i,a,b) for(int i = a; i >= b; i--)
#define MAXN 100001

using namespace std;

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;

vpi g[MAXN];
int vis[MAXN];
bool color[MAXN];

void dfs(int u){
    vis[u] = 1;
    for(int i = 0; i < g[u].size(); i++){
        pi v = g[u][i];
        if(v.S&1)
            color[v.F] = !color[u];
        else
            color[v.F] = color[u];

        if(!vis[v.F])
            dfs(v.F);
    }
    vis[u] = 2;
}

void solve(){
    memset(vis, 0 , sizeof(vis));
    memset(color, 0, sizeof(color));
    for(int i = 0; i < MAXN; i++)
        g[i].clear();
    int n; cin >> n;
    for(int i = 0; i < n-1; i++){
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        g[u].PB(MP(v,w));
        g[v].PB(MP(u,w));
    }
    for(int i = 0; i < n; i ++){
        if(!vis[i])
            dfs(i);
    }

    for(int i = 0; i < n; i++){
        printf("%d\n", color[i]);
    }
}

int main(){
    //int t; cin >> t;
    //while(t--) solve();

    solve();
    return 0;
}


Measured memory_bytes: 8448
import sys

H,W,N = map(int,input().split())

ans = H
XY = []
now = 0

for i in range(N):

    X,Y = map(int,input().split())
    XY.append([X,Y])

XY.sort()

for i in range(N):

    X = XY[i][0]
    Y = XY[i][1]
    
    if Y < X - now:
        print (X-1)
        sys.exit()

    elif Y == X - now:
        now += 1

print (H)
    


Measured memory_bytes: 76308
while True:
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    else:
        if n>=m:
            x,y=n,m
        else:
            x,y=m,n
        s=0
        while True:
            if y!=0:
                x=x%y
                x,y=y,x
                s+=1
            else:
                break
    print(x,s)


Measured memory_bytes: 5604
package main

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

const maxN = 2e6 + 10
const inf = 1e11

var (
	a   = make([]int, maxN)
	ans = make([]int, maxN)
	dp  = make([]int, maxN)
	to  = make([][]int, maxN)
)

var (
	scanner = bufio.NewScanner(os.Stdin)
	w       = bufio.NewWriter(os.Stdout)
)

func readInt() (read int) {
	scanner.Scan()
	read, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return
}

func dfs(v int, p int) {
	i := sort.Search(maxN-1, func(i int) bool { return dp[i] >= a[v] })
	old := dp[i]
	dp[i] = a[v]
	ans[v] = i
	if p != -1 {
		ans[v] = int(math.Max(float64(ans[v]), float64(ans[p])))
	}
	for _, u := range to[v] {
		if u == p {
			continue
		}
		dfs(u, v)
	}
	dp[i] = old
}

func main() {
	scanner.Split(bufio.ScanWords)
	defer w.Flush()

	n := readInt()
	a = make([]int, maxN)
	ans = make([]int, maxN)

	for i := 0; i < n; i++ {
		a[i] = readInt()
	}

	for i := 0; i < n-1; i++ {
		u := readInt()
		v := readInt()
		u--
		v--
		to[v] = append(to[v], u)
		to[u] = append(to[u], v)
	}

	for i := 0; i < maxN; i++ {
		dp[i] = inf
	}
	dp[0] = -inf
	dfs(0, -1)
	for i := 0; i < n; i++ {
		fmt.Fprintln(w, ans[i])
	}
}


Measured memory_bytes: 88576
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n, k;
llint p[5005], c[5005];
llint s[5005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> p[i];
	for(int i = 1; i <= n; i++) cin >> c[i];
	
	llint ans = -inf;
	for(int i = 1; i <= n; i++){
		llint pos = 0, v = i;
		do{
			v = p[v];
			pos++;
			s[pos] = s[pos-1] + c[v];
		}while(v != i);
		
		llint tmp = 0, mx = -inf;
		if(s[pos] >= 0){
			tmp = k / pos * s[pos];
			for(int j = 0; j <= k % pos; j++) mx = max(mx, s[j]);
			tmp += mx;
			
			ans = max(ans, tmp);
			
			if(k / pos >= 1){
				tmp = (k / pos - 1) * s[pos];
				mx = 0;
				for(int j = 0; j <= pos; j++) mx = max(mx, s[j]);
				tmp += mx;
			}
		}
		else{
			for(int j = 1; j <= min(k, pos); j++) mx = max(mx, s[j]);
			tmp += mx;
		}
		ans = max(ans, tmp);
		//cout << i << " " << tmp << endl;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64
#define n_max 300

int main(){
    int n;
    cin >> n;
    int A[n_max][n_max];
    int kyori[n_max][n_max];
    REP(i,n){
        REP(j,n){
            scanf("%d",&A[i][j]);
            kyori[i][j]=A[i][j];
        }
    }

    REP(i,n){
        REP(j,n){
            REP(k,n){
                if(kyori[j][k] > kyori[j][i] + kyori[i][k]){
                    cout << -1 << endl;
                    return 0;
                }
                else if(kyori[j][k]==kyori[j][i] + kyori[i][k] and i!=k and i!=j){
                    A[j][k]=0;
                    A[k][j]=0;
                }
            }
        }
    }

    llong ans=0;
    REP(i,n) REP(j,n) ans+=A[i][j];
    cout << ans/2 << endl;

}

Measured memory_bytes: 896
import * as fs from 'fs'

const input = (fs.readFileSync('/dev/stdin', 'utf8') as string).split('\n')
const n = +input[0]
// const [n] = input[0].split(" ").map((x: string): number => +x);
const a = []
for (let i = 0; i < n; i++) {
    a.push(input[i + 1].split(' ').map((x: string): number => +x))
}

input[0] === 'ABC' ? console.log('ARC') : console.log('ABC')



Measured memory_bytes: 29620
#include<cstdio>
#include<iostream>
#include<algorithm>
#include <cmath>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int a[n+2],b[n+2];
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
	}
	for(int i=0;i<n;i++)
	{
		b[i] = a[i];
	}
	sort(b,b+n);
	int sum=0;
	for(int i=0;i<n;i++)
	{
		if(b[i] != a[i])sum++;
	}
	if(sum>2)printf("NO\n");
	else printf("YES\n");
}

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


using namespace std;

#define fastio() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()


void go(){
   int l,r,D;cin>>l>>r>>D;
   int ans=0;
   for(int i=l;i<=r;i++) if(i%D==0) ans++; 
   cout << ans;
}
int main(){
   
   fastio();
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}




Measured memory_bytes: 3620
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 2010
using namespace std;
int n,a[maxn],k,z,w;
int main()
{
	scanf("%d%d%d",&n,&z,&w);
	for(int i=1;i<=n;++i)
	scanf("%d",&a[i]);
	if(n==1) {
		cout<<abs(a[1]-w);
		return 0;
	}
	cout<<max(abs(a[n]-a[n-1]),abs(a[n]-w));
	return 0;
}
 

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=1e3+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
  }
   


void solve() {  
	string s;
	cin>>s;
	int len=sz(s);
	int sum=0;
	rep(i,0,len) {
		  sum+=(s[i]-'0');
		}
	if(sum%3==0) cout<<"Yes\n";
	else cout<<"No\n"; 
	               
}

    
int32_t main() {
	cool;
	int t=1;	

	//cin>>t;
	while(t--)
	  solve();

  return 0;	   
}



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


int main()

{
long long n;
cin>>n;
long long  d=sqrt(n);
long long  flag=0;
long long  sum=0;
if(n<=3)
    cout<<n-1;
else {
for(long long i=d;i>=2;i--)
{
    if(n%i==0)
    {
        flag=1;
        sum+=i;
        sum+=(n/i);
        break;
    }



}
if(flag==0)
    cout<<n-1<<endl;
else 
    cout<<sum-2<<endl;

}

    return 0;
}

Measured memory_bytes: 256
/*
 * Created by Dipta Das on 
 * Title: 
 * Problem Link: 
 * Editorial: 
 * Source Code: 
 * Comments: 
*/
#include <bits/stdc++.h>
#define fin freopen("input", "r", stdin);
#define fout freopen("output", "w", stdout);
#define wt(x) cerr << #x << ": " << x << " ";
#define whatis(x) {cerr << #x << ": " << x << endl;}
#define whatis2(x, y) {wt(x); wt(y); cerr << endl;}
#define whatis3(x, y, z) {wt(x); wt(y); wt(z); cerr << endl;}
#define whatis4(x, y, z, a) {wt(x); wt(y); wt(z); wt(a); cerr << endl;}
using namespace std;

typedef long long ll; typedef unsigned long long ull; typedef long double ld;
const ll MOD = 1000000007; const ld PI = acos(-1.0);

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

    
    ll a, b;
    cin >> a >> b;
    cout << a * b << endl;


    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll n;
	cin>>n;
	ll a[n],b[n],c[n],x,y,z;
	for(ll i=0;i<n;i++){
	    cin>>a[i]>>b[i]>>c[i];
	    if(i==0)
	        continue;
	    a[i]+=max(b[i-1],c[i-1]);
	    b[i]+=max(c[i-1],a[i-1]);
	    c[i]+=max(a[i-1],b[i-1]);
	}
	cout<<max({a[n-1],b[n-1],c[n-1]});
	return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

struct calc_bridge_and_articulation{
    const int size;
    vector<vector<int>> graph;
    vector<bool> used_v;
    vector<vector<bool>> used_e;
    vector<int> ord,lowlink,articulations;
    vector<pair<int,int>> bridges;

    calc_bridge_and_articulation(const vector<vector<int>> &graph):graph(graph),size(graph.size()){
        used_v.resize(size);
        used_e.resize(size);
        rep(i,0,size) used_e[i].resize(size);
        ord.resize(size);
        lowlink.resize(size);
        int k;
        rep(i,0,size) if(!used_v[i]) dfs(i,-1,k);
    }

    void dfs(int v,int p,int &k){ //v???????????¨???p=-1
        used_v[v]=true;
        ord[v]=lowlink[v]=k++;

        bool is_articulation=false;
        int count=0;
        for(int u:graph[v]){
            if(!used_v[u]){
                ++count;
                used_e[v][u]=true;
                dfs(u,v,k);
                lowlink[v]=min(lowlink[v],lowlink[u]);

                if(ord[v]<lowlink[u]) bridges.push_back(make_pair(min(v,u),max(v,u)));
                if(p!=-1 and ord[v]<=lowlink[u]) is_articulation=true;
            }else if(!used_e[u][v]) lowlink[v]=min(lowlink[v],ord[u]);
        }

        if(p==-1 and count>1) is_articulation=true;
        if(is_articulation) articulations.push_back(v);
    }
};

void solve(){
    int size_v,size_e;
    cin >> size_v >> size_e;
    vector<vector<int>> graph(size_v);
    rep(i,0,size_e){
        int s,t;
        cin >> s >> t;
        graph[s].push_back(t);
        graph[t].push_back(s);
    }
    calc_bridge_and_articulation cba(graph);
    auto ans=cba.bridges;
    sort(ans.begin(),ans.end());
    rep(i,0,ans.size()) cout << ans[i].first << " " << ans[i].second << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

Measured memory_bytes: 17780
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string s;cin >> s;
  char pre = s[0];
  int count = 0;
  rep(i,s.length()){
    if(s[i] != pre)++count;
    pre = s[i];
  }
  cout << count << endl;
  return 0;
}


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

class DisjointSet{
public:
    vector<int> height, p;
    DisjointSet() {}
    DisjointSet(int n) {
        height.resize(n,0);
        p.resize(n,0);
        for(int i=0;i<n;++i){
            makeset(i);
        }
    }
    void makeset(int i){
        p[i] = i;
        height[i] = 0;
    }
    void unionset(int x, int y){
        link(findset(x),findset(y));
    }
    void link(int x, int y){
        if(height[x]>height[y]){
            p[y] = x;
        }
        else{
            p[x] = y;
            if(height[x]==height[y]) height[y]++;
        }
    }
    int sameset(int x, int y){
        if(findset(x)==findset(y)) return 0;
        else return 1;
    }
    int findset(int x){
        if(x!=p[x]){
            p[x] = findset(p[x]);
        }
        return p[x];
    }
};


int main()
{
    int n, q, comd, x, y;
    cin >> n >>q;
    DisjointSet ds = DisjointSet(n);
    for(int i=0;i<q;++i){
        scanf("%d %d %d",&comd,&x,&y);
        if(comd==0){
            ds.unionset(x,y);
        }
        if(comd==1){
            if(ds.sameset(x,y)==0) cout<<1<<endl;
            else cout<<0<<endl;
        }

    }



    return 0;
}



Measured memory_bytes: 3320
#include <iostream>
#include <string>

using namespace std;

int main() {
	int N;
	int H[100];
	int max = 0;
	int ans = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
		if (H[i] >= max) {
			ans++;
			max = H[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool condition( int *a , int n)
{
    for(int i=0;i<n;i++)
    {
        if( a[i] >0)
            return false;
    }
    return true;
}
int main()
{
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    ll ans =0;
    while( !condition( h,n)  )
    {
        int l =0 ,r =0 ;
        bool ltaken = false;
        int lowest=INT_MAX;
        for(int i=0;i<n;i++)
        {
            if( !ltaken  && h[i] >0 )
            {
                l = i;
                ltaken = true;
            }
            if( ltaken && (h[i] ==0 ) )
            {
                r  = i-1;
                for( int i= l ;i<=r;i++)
                {
                    lowest = min( lowest ,h[i]);
                }
                ans+= lowest;
                for(int i=l;i<=r;i++)
                {
                    h[i] -= lowest;
                }
                ltaken= false;
            }
            if( ltaken && i== n-1)
            {
                r = n-1;
                for( int i= l ;i<=r;i++)
                {
                    lowest = min( lowest ,h[i]);
                }
                ans+= lowest;
                for(int i=l;i<=r;i++)
                {
                    h[i] -= lowest;
                }
                ltaken= false;
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3472
#include<stdio.h>
main()
{
    int i,j,x[10000],y[10000],a=0;
     for(a=0;a<10000;a++)
     {
         scanf("%d%d",&x[a],&y[a]);

         if(x[a]==0&&y[a]==0){
            break;
         }
     }
    for(a=0;a<10000;a++)
    {
        if(x[a]==0&&y[a]==0)
        {
            break;
        }
        i=(x[a]>y[a])?y[a]:x[a];
        j=(x[a]>y[a])?x[a]:y[a];
        printf("%d %d\n",i,j);

    }
    return 0;
}



Measured memory_bytes: 2020
n,m=map(int,input().split())
P=[]
for i in range(m):
    p,y=map(int, input().split())
    P.append([p,y,i])
nums=[0]*n
ans=[""]*m
P.sort(key=lambda x:x[1])

for p,y,i in P:
    nums[p-1]+=1
    ans[i]=(6-len(str(p)))*"0"+str(p)+(6-len(str(nums[p-1])))*"0"+str(nums[p-1])
for an in ans:
    print(an)

Measured memory_bytes: 32172
#include <iostream>
#include<string>
#include<vector>

using namespace std;


int main()
{
	int n, x;
	vector<int> ls;
	cin >> n >> x;

	for (int i = 0; i < n; i++) {
		int wk;
		cin >> wk;

		ls.push_back(wk);
	}

	int ans = 1;
	int now = 0;
	for (int i = 0; i < ls.size(); i++) {

		now += ls[i];

		if (now > x)break;

		ans++;
	}

	cout << ans << endl;



}



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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

const int INF = 1e9;

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

    int n, k, s;
    cin >> n >> k >> s;
    for (int i=0; i<n; i++)
        cout << (i < k ? s : s == INF ? 1 : s + 1) << " ";
    cout << "\n";

    return 0;
}


Measured memory_bytes: 3656
import numpy as np
N, M = [int(i) for i in input().split()]

a = np.ones(N)
b = np.ones(N)

c = np.ones(M)
d = np.ones(M)

for i in range(N):
    a[i],b[i] = [int(i) for i in input().split()]
    
for i in range(M):
    c[i],d[i] = [int(i) for i in input().split()]
    
    
for i in range(N):
    ans = 1
    min_sofar = abs(a[i]-c[0]) + abs(b[i] - d[0])
    for j in range(M):
        candid = abs(a[i]-c[j]) + abs(b[i] - d[j])
        if min_sofar > candid:
            ans = j+1
            min_sofar = candid
        
    print(int(ans))

Measured memory_bytes: 13100
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(a*b,c*d) << endl;
}

Measured memory_bytes: 256
defmodule Main do
  def main do
      x =
      IO.read(:line)
      |> String.trim
      |> String.to_integer
	  a =
      IO.read(:line)
      |> String.trim
      |> String.to_integer
      b =
      IO.read(:line)
      |> String.trim
      |> String.to_integer
      IO.puts(rem((x - a), b))
  end
end


Measured memory_bytes: 30624
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            Exec(args);
            // Console.WriteLine("============ Retry ============");
            Console.Out.Flush();
        }

        private static void Exec(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            var s = Console.ReadLine();

            var money = int.Parse(s);

            int result = 0;
            
            for (;;)
            {
                if (money > 1000)
                {
                    money -= 1000;
                }
                else
                {
                    result = 1000 - money;
                    break;
                }
            }
            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27476
#include <iostream>
#include <vector>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;
 
int main() {
	uint N, K, R, S, P;
	cin >> N >> K >> R >> S >> P;
	
	string T;
	cin >> T;
	
	ull ans = 0;
	
	for(uint i=0; i<K; i++) {
		vector<ull> dpR(2, 0);
		vector<ull> dpS(2, 0);
		vector<ull> dpP(2, 0);
		
		ull tmp = 0;
		uint prv = 0;
		uint cur = 1;
		
		for(uint j=i; j<N; j+=K) {
			char c = T[j];
			
			uint r = (c == 's') ? R : 0;
			uint s = (c == 'p') ? S : 0;
			uint p = (c == 'r') ? P : 0;
			
			dpR[cur] = max(dpP[prv], dpS[prv]) + r; 
			dpS[cur] = max(dpR[prv], dpP[prv]) + s;
			dpP[cur] = max(dpR[prv], dpS[prv]) + p;
			
			//cout << j << " " << dpR[cur] << " " << dpS[cur] << " " << dpP[cur] << endl;
			
			tmp = max(tmp, max(dpR[cur], max(dpS[cur], dpP[cur])));
			prv = cur;
			cur = (cur + 1) % 2;
		}
		
		ans += tmp;
	}
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void){
   int n,gram,i,min,minP,addDon;
   scanf("%d%d",&n,&gram);
   int m[n];

   for(i=0;i<n;i++)
      scanf("%d",&m[i]);

   min = m[0]; minP=0;
   for(i=1;i<n;i++)
      if(m[i]<min){min=m[i]; minP=i;}

   for(i=0;i<n;i++)
      gram-=m[i];

   addDon=gram/min;
   printf("%d\n",n+addDon);
   return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

    public static void main(String[] argv) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");

        int w = Integer.parseInt(str[0]);
        int h = Integer.parseInt(str[1]);
        int n = Integer.parseInt(str[2]);

        int[][] map = new int[h][w];
        for(int i=0; i<h; i++) Arrays.fill(map[i], 1);
        for(int i=0; i<n; i++){
            str = br.readLine().split(" ");
            int x = Integer.parseInt(str[0]);
            int y = Integer.parseInt(str[1]);
            int a = Integer.parseInt(str[2]);
            switch (a){
                case 1:
                    for(int j=0; j<h; j++) Arrays.fill(map[j], 0, x, 0);
                    break;
                case 2:
                    for(int j=0; j<h; j++) Arrays.fill(map[j], x, w,0);
                    break;
                case 3:
                    for(int j=0; j<y; j++) Arrays.fill(map[j], 0, w, 0);
                    break;
                case 4:
                    for(int j=y; j<h; j++) Arrays.fill(map[j], 0, w, 0);
                    break;
            }
        }

        int cnt = 0;
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                cnt += map[i][j];
            }
        }

        System.out.println(cnt);
    }
}


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

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;

int main() {
	
   	int n,m;cin>>n>>m;
	priority_queue<int> pq;
	rep(i, n){
		int t;cin>>t;
		pq.push(t);
	}
	rep(i, m){
		int ma = pq.top();
		ma /= 2;
		pq.pop();
		pq.push(ma);
	}
	ll ans = 0;
	while(!pq.empty()){
		ans += pq.top();
		pq.pop();
	}
	cout << ans << endl;

	return 0;
}


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

int main(){
  int N;
  cin >>N;
  vector<int> A(N);
  int mod =1000000007;
  long long sum = 0;
  for (int i=0; i<N; i++)
  {
    cin >> A[i];
    sum += A[i];
    sum %= mod;
  }
  long ans = 0;
  
  for (int i=0; i<N; i++)
  {
    sum -= A[i];
    if (sum < 0)
    sum += mod;
    ans += A[i]*sum;
    ans %=mod;
  }
  
  cout << ans;
}


Measured memory_bytes: 4036
A, B, C, D, E, F = map(int, input().split())
ans = [100 * A, 0]
c = 0

for i in range(1, F // (100 * A) + 1):
    for j in range(F // (100 * B) + 1):
        a = 100 * A * i + 100 * B * j
        if a > F:
            break
        for k in range((F - a) // C + 1):
            for l in range((F - a) // D + 1):
                b = k * C + l * D
                concentration = 100 * b / (a + b)
                if (A * i + B * j) * E >= b and a + b <= F:
                    if concentration > c:
                        c = concentration
                        ans = [a + b, b]
                else:
                    break

print(' '.join(map(str, ans)))

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys
from operator import itemgetter
from heapq import heappop,heappush

def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    kyuujinn = [[] for _ in range(M+1)]
    
    for i in range(N):
        if A[i] <= M:
            kyuujinn[A[i]].append(B[i])

    answer =0
    heapque = []
    for k in kyuujinn:
        if k:
            for kk in k:
                heappush(heapque,-kk)
        
        if heapque:
            work = heappop(heapque)
            answer-= work
    print(answer)
    
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 23124
#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 main() {
  int n;
  cin >> n;
  int odd = 0, even = 0;
  rep(i, n) {
    int64_t a;
    cin >> a;
    if (a%2 == 0) {
      even++;
    } else {
      odd++;
    }
  }
  if (odd%2 != 0) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
}

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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//Write From this Line

int main()
{
	string s ;
	cin >> s ;
	int n = s.size();
	rep(i,n){
		if(s[i]=='h'){
			//ok
			i++;
			if(s[i]=='i'){
				//ok
			} else {
				puts("No");
				return 0 ;
			}
		} else {
			puts("No");
			return 0 ;
		}
	}
	puts("Yes");
}


Measured memory_bytes: 256
#define pb push_back
#define ll long long
#include<bits/stdc++.h>
using namespace std;
int n, q;
string cmd;
struct node{
	node *l, *r;
	int key = 0;
	node(int k){
		key = k;
		l = r = NULL;
	}
};
node* insert(node* r, int key){
	if(r == NULL || r->key == key) return new node(key);
	if(r->key > key){
		r->l = insert(r->l, key);
	}else r->r = insert(r->r, key);
	return r;
}
void pre(node* r){
	if(!r) return;
//	if(ff) cout << " ";
	printf(" %d", r->key); 
	pre(r->l);
	pre(r->r);
}
void in(node* r){
	if(!r) return;
	in(r->l);
	printf(" %d", r->key); 
	in(r->r);
}
int cc = 0;
node* root = NULL;
void solve(){
	root = NULL;
	cc = 0;
	cin >> q;
	while(q--){
		cin >> cmd;
		if(cmd[0] == 'i'){
			int x; cin >> x;
		//	cout << cmd << " " << x << endl;
			root = insert(root, x);
		}else{
			in(root); 
			cout << endl;
			pre(root);
			cout << endl;
//			bool ok = false;
//			if(cc != 0) cout << endl, ok = true;
//			cc++;
//			if(q == 0 && ok == false) cout << endl;
		}
	}
	//cout << "root: " << root->key << endl;
}
int main(){
	solve();
	return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    vector<ll> A(N), B(N);
    rep(i, N){cin >> A.at(i) >> B.at(i);}
    ll A_ind = max_element(A.begin(), A.end()) - A.begin();
    cout << A.at(A_ind) + B.at(A_ind) << endl;
}

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


Measured memory_bytes: 4764
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] Vi = new int[N];
        int[] Ci = new int[N];

        for (int i= 0; i<N; i++) {
            Vi[i] = sc.nextInt();
        }
        for (int i= 0; i<N; i++) {
            Ci[i] = sc.nextInt();
        }
        int X = 0;
        int Y = 0;
        for (int i= 0; i<N; i++) {
            if (Vi[i] <= Ci[i]) continue;

            X += Vi[i];
            Y += Ci[i];
        }


        System.out.println(X - Y);
    }
}

Measured memory_bytes: 22996
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;

template <typename T>
T gcd(T a, T b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}

template <typename T>
T lcm(T a, T b) {
    T g = gcd(a, b);
    return a / g * b;
}

int main(){

    int x, y;
    cin >> x >> y;

    vector<int> group = {0, 1, 2, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1};

    if(group[x] == group[y]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<end
#define cout(n) cout<<fixed<<setprecision(n)
ll disitSum(ll x){
  ll res=0;
  while(x>0){
    res+=x%10;
    x/=10;
  }
  return res;
}

int main(){
  ll N;
  cin>>N;
  if(N%disitSum(N)!=0) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}


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

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
    ifstream t("/proc/self/status");
    cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum = 0, fg = 1;
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef pair<int, int> pii;

const int MAXN = (int) 1e5;

int n, k;

int a[MAXN + 5];

inline void input()
{
	n = read<int>(), k = read<int>();
	for(int i = 1; i <= n; ++i) a[i] = read<int>();
}

inline void solve()
{
	int ans = INT_MAX;
	for(int i = 1; i + k - 1 <= n; ++i) chkmin(ans, a[i + k - 1] - a[i] + min(abs(a[i]), abs(a[i + k - 1])));
	printf("%d\n", ans);
}

int main()
{
	input();
	solve();

	return 0;
}



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

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

Measured memory_bytes: 256
#include <iostream>
#include <string>

int main() {
  std::string str;
  std::cin >> str;
  if (str[0] != str[1] || str[1] != str[2])
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;
  return 0;
}

Measured memory_bytes: 256
package main
import (
    "fmt"
    "sort"
)

func solveMeFirst(a uint32,b uint32) uint32{
    if (a < b) {
        return 0
    } else {
        return a - b
    }
}

func main() {
    var n int
    fmt.Scanf("%v\n", &n)
    var v []int
    for i := 0; i < n; i++ {
        var a int
        fmt.Scanf("%v\n", &a)
        v = append(v, a)
    }
    sort.Ints(v)
//    for i := 0; i < n; i++ {
//        fmt.Println(v[i])
//    }
    var c int = 0
    var r int = 0
    var d int = 0
    for i := 0; i < n; i++ {
        if v[i] != c {
            r += d % 2
            c = v[i]
            d = 0
        }
        d += 1
    }
    r += d % 2
    fmt.Println(r)
}



Measured memory_bytes: 6656
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<algorithm>

#define X first
#define Y second
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define rep(i,n) for(ll i = 0; i < n; ++i)

using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
const ll INF = 1000000000000000000LL;

vector<PII> edges[2000];
vector<PII> e[2000];
int n,m;

vector<ll> dist;

bool bellman_ford(){
  dist = vector<ll>(n,INF);

  dist[0] = 0;
  rep(i,n){
    rep(v,n){
      rep(k, edges[v].size()){
        PLL pi = edges[v][k];
        if( dist[v] != INF && dist[pi.X] > dist[v] + pi.Y){
          dist[pi.X] = dist[v] + pi.Y;
          if(i == n-1){
            dist[n-1] = INF;
            return true;
          }
        }
      }
    }
  }
  return false;
}

void f(){
  queue<int> q;
  q.push(n-1);
  bool r[2000];
  rep(i,2000) r[i] = false;
  while(!q.empty()){
    int pos = q.front();q.pop();
    r[pos] = true;
    rep(j,e[pos].size()){
      PII pi = e[pos][j];
      if(r[pi.X])continue;
      q.push(pi.X);
    }
  }

  rep(i,n){
    rep(j,e[i].size()){
      PII pi = e[i][j];
      if(r[i] && r[pi.X]){
        edges[pi.X].eb(i, pi.Y);
//         cout << pi.X << " -> " << i << endl;
      }
    }
  }
}




int main(void){
  ll a,b,c;

  cin >> n >> m;
  rep(i,m){
    cin >> a >> b >> c;
    a--;b--;
    c *= -1;
     e[b].eb(a,c);
  }

  f();
  bellman_ford();
  if(dist[n-1] == INF){
    cout << "inf" << endl;
  }else{
    cout << -1*dist[n-1] << endl;
  }

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int N,M;

struct edge{
  int to;
  i64 s;
};

vector<edge> G[101010];

int main(){
  cin >> N >> M;
  rep(i,0,M - 1){
    int u,v;
    i64 s;
    cin >> u >> v >> s;
    G[u].push_back({v,s});
    G[v].push_back({u,s});
  }

  vector<i64> aop(101010,0);
  vector<i64> C(101010,0);

  aop[1] = 1;
  C[1] = 0;

  i64 A;
  bool defined = false;

  i64 MIN = 1LL << 62;
  i64 MAX = 0;

  queue<int> que;
  que.push(1);
  while(!que.empty()){
    int v = que.front();
    que.pop();
    //cout << v << " " << aop[v] << "=" << C[v] << endl;
    for(auto e : G[v]){
      if(aop[e.to] == 0){
        aop[e.to] = aop[v] * -1;
        C[e.to] = e.s - C[v];
        if(aop[e.to] == -1){
          MIN = min(MIN,C[e.to]);
        }
        else{
          MAX = max(MAX , -C[e.to]);
        }
        que.push(e.to);
      }
      else if(aop[e.to] == aop[v]){
        //2A + C[v] + C[to] == s
        if(abs(e.s - C[v] - C[e.to]) % 2 == 1){
          cout << 0 << endl;
          return 0;
        }
        i64 a = aop[v] * (e.s - C[v] - C[e.to]) / 2;


        if(a <= 0){
          cout << 0 << endl;
          return 0;
        }
        if(!defined){
          A = a;
          defined = true;
        }
        else if(A != a){
          cout << 0 << endl;
          return 0;
        }
      }
      else if(C[e.to] + C[v] != e.s){
        cout << 0 << endl;
        return 0;
      }
    }
  }

  if(defined){
    if(MAX < A && A < MIN)
      cout << 1 << endl;
    else{
      cout << 0 << endl;
    }
  }
  else{
    cout << max(0LL,MIN - MAX - 1) << endl;
  }
}


Measured memory_bytes: 9728