akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	iv, _ := strconv.Atoi(readStr())
	return iv
}

func readStr() string {
	sc.Scan()
	return sc.Text()
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	h, w := readInt(), readInt()
	s := make([]string, h)
	for i := range s {
		s[i] = readStr()
	}

	type point struct{ x, y int }
	dx := []int{1, 0, -1, 0}
	dy := []int{0, -1, 0, 1}
	ans := 0
	for i, sh := range s {
		for j, v := range sh {
			if v == '#' {
				continue
			}

			qu := list.New()
			qu.PushBack(point{j, i})
			pas := make(map[point]int)
			pas[point{j, i}] = 0
			for {
				p := qu.Remove(qu.Front()).(point)
				for d := 0; d < 4; d++ {
					nx, ny := p.x+dx[d], p.y+dy[d]
					if nx < 0 || nx >= w || ny < 0 || ny >= h || s[ny][nx] == '#' {
						continue
					}
					if _, ok := pas[point{nx, ny}]; ok {
						continue
					}

					qu.PushBack(point{nx, ny})
					mv := pas[p] + 1
					ans = max(ans, mv)
					pas[point{nx, ny}] = mv
				}
				if qu.Len() == 0 {
					break
				}
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5504
#include<iostream>
int main()
{
  long long a,b,c,d;
  scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
  long long N = a*c;
  if(N < a*d)
    N = a*d;
  if(N < b*c)
    N = b*c;
  if(N < b*d)
    N = b*d;
  printf("%lld",N);
}


Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
#include<cstdio>
void ans(){
  int n,m;
  cin>>n>>m;
  
  vector<string> a(n),b(m);
  for(int i=0; i<n; i++)cin>>a.at(i);
  for(int i=0; i<m; i++)cin>>b.at(i);
  
 

  for(int j=0; j<=n-m; j++){//j<=n-m  =忘れ
    for(int k=0; k<=n-m; k++){
      for(int i=0; i<m; i++){
        string a_ =a.at(j+i).substr(k,m);
        if(b.at(i)!=a_)break; 
        if(b.at(i)==a_&&i==m-1) {
          cout<<"Yes";return;}
      }
     // cout<<"Yes";return;
    }
  }
  cout<<"No";return;
}
int main() {
  ans();
}








Measured memory_bytes: 256
N = int(input())
a_s = [int(x) for x in input().split()]

mean = sum(a_s) * 1.0 / N
d = min(map(lambda a: abs(a - mean), a_s))
ans = N
for i in range(N):
    if abs(a_s[i] - mean) == d:
        ans = i
        break

print(ans)


Measured memory_bytes: 3060
int main(void) {
	int n, i, j, k;
	int A[4][3][10] = {};
	int b, f, r, v;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d %d %d %d", &b, &f, &r, &v);

		A[b-1][f-1][r-1] += v;
	}

	for (i = 0; i < 4; i++) {
		for (j = 0; j < 3; j++) {
			for (k = 0; k < 10; k++) {
				printf(" %d", A[i][j][k]);
			}
			printf("\n");
		}

		if (i < 3) {
			for (j = 0; j < 20; j++) {
				printf("#");
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 600
from collections import deque

H,W=map(int,input().split())
count=0
S=[['#']*(W+1) for _ in range(H+1)]
for i in range(1,H+1):
    S_comp=list(str(input()))
    for j in range(1,W+1):
        if S_comp[j-1]=='.':
            count+=1
        S[i][j]=S_comp[j-1]


def sur(v):  #v is tuple
    vx=v[0]
    vy=v[1]
    preE=[(vx-1,vy),(vx+1,vy),(vx,vy-1),(vx,vy+1)]
    E=[]
    for nv in preE:
        if 1<=nv[0]<=H and 1<=nv[1]<=W:
            if S[nv[0]][nv[1]]=='.':
                E.append(nv)
    return E

q=deque()
s=(1,1)
g=(H,W)
q.append(s)
dist=[[-1]*(W+1) for k in range(H+1)]
dist[s[0]][s[1]]=0

while q:
    now=q.popleft()
    for next in sur(now):
        if dist[next[0]][next[1]]!=-1:
            continue
        q.append(next)
        dist[next[0]][next[1]]=dist[now[0]][now[1]]+1
        if next==g:
            ans=dist[g[0]][g[1]]
            print(count-1-ans)
            break
    else:
        continue
    break
else:
    print(-1)







Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

int main()
{
  string s,t;
  cin >> s >> t;
  cout << t << s << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0,1,0,-1 };
const ll dy[4] = { -1, 0, 1,0 };
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////


//最後にどの料理を注文するかを全探索する
//i番目の料理を最後に注文する場合i番目以外の料理でT-１分以内に完食できる美味しさの合計の最大値+Bi
//dp1[i][j]:1～i番目の料理でj分以内に完食できる美味しさの合計の最大値
//dp2[i][j]:i～N番目の料理でj分以内に完食できる美味しさの最大値
//としてi番目以外の料理でT-1分以内に完食できる美味しさの合計の最大値は
//(0<=j<=T-1)max(dp1[i-1][j]+dp2[i+1][T-j-1]+B[i])より求められる
int N, T; 
int A[3010], B[3010];
int dp1[3010][3010];
int dp2[3010][3010];
int main() {
	cin >> N >> T;
	REP(i,3010) {
		REP(j, 3010) {
			dp1[i][j] = 0;
		}
	}
	REP(i, N) {
		cin >> A[i] >> B[i];
	}
	REP(i, N) {
		REP(j, T) {
			if (j >= A[i]) {
				dp1[i+1][j] = max(dp1[i][j], dp1[i][j - A[i]] + B[i]);
			}
			else {
				dp1[i + 1][j] = dp1[i][j];
			}
			if (j >= A[N - 1 - i]) {
				dp2[N - i][j] = max(dp2[N +1- i][j], dp2[N+1 - i][j - A[N - 1 - i]] + B[N - 1 - i]);
			}
			else {
				dp2[N - i][j] = dp2[N+1-i][j];
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < T; ++j) {
			ans = max(ans, B[i] + dp1[i][j] + dp2[i + 2][T - j - 1]);
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main()
{
    long long A;
    cin >> A;
    string ans = "";
    vector<int> idx;
    while (A)
    {
        int rem = A % 26;
        if (rem == 0)
        {
            idx.push_back(26);
            A = (A - 26) / 26;
        }
        else
        {
            idx.push_back(rem);
            A = A / 26;
        }
    }
    int n = idx.size();
    for (int i = n - 1; i >= 0; i--)
    {
        ans += 'a' + (idx[i] - 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
/*
Author :: Shahadat Hossain Nirob
............SUST_MATH14..........
*/
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <vector>

#define Long long long
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define II() ( { int a ; read(a) ; a; } )
#define LL() ( { Long a ; read(a) ; a; } )
#define DD() ({double a; scanf("%lf", &a); a;})
#define DB if(0) 
#define D(x) cout << #x " is " << x << endl
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef vector<PII> VII;
typedef vector<string> VS;

const int INF = 2000000009;
const int MX = 200005;
const double EPS = 1e-9;
const int MOD = 1000000007;

template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

template<class T>inline bool read(T &x){
    int c=getchar();int sgn=1;
    while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}
    for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; 
    x*=sgn; return ~c;
}

#define nl puts ("")
#define sp printf ( " " )
#define phl printf ( "hello\n" )
#define ff first
#define ss second
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define MP make_pair
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define SQ(x) ((x)*(x))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define ALL(x) (x).begin(),(x).end()
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define SZ(x) ((vlong)(x).size())
#define NORM(x) if(x>=mod)x-=mod;
#define MOD(x,y) (((x)*(y))%mod)
#define ODD(x) (((x)&1)==0?(0):(1))

typedef string st;
typedef vector<st> vs;
#define rep(i, n) for(int i = 0; i < n; i++)
#define fogg(i,a,b) for(int i = (a); i <= (b); i++)
#define ford(i,a,b) for(int i = (a); i >= (b); i--)
#define test int t; cin >> t; while(t--)
#define endl '\n'
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main()
{
	/*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    
    int a=II(),b=II();
    if(a%b==0) cout << a%b << endl;
    else cout << "1\n";
	
	return 0;
}



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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

vector<ll> g[100005];

ll dfs(ll x){
	if(g[x].size() == 0) return 0;
	
	vector<ll> v;
	rep(i,g[x].size()){
		ll y = g[x][i];
		v.push_back(dfs(y));
	} 
	
	sort(v.begin(),v.end(),greater<ll>());

	ll mx = -1;
	rep(i,v.size()){
		ll z = v[i];
		mx = max(mx,z+i+1);
	}

	return mx;
}

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

	ll n;
	cin >> n;

	rep(i,n-1) {
		ll a;
		cin >> a;
		g[a-1].push_back(i+1);
	}

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

Measured memory_bytes: 13568
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip> // 文字幅の指定 setw(int), 詰めたい文字の指定 setfill(char)
#include <algorithm> // sort
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define p(x) cout << (x) << endl
#define FOR(i,r,n) for(ll i=(ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n); i>=r; i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) REP(i,0,n)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pb push_back

// 定義する？→左揃えで0埋め
// cout << setfill('0') << left << setw(4) << 12; // "0012"
// http://marycore.jp/prog/cpp/padding-left-right-zero/

const int inf = (int)1e9;
const ll INF = (ll)1e18;

// vectorの中身をcout << vs;で表示
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v)
{
    o << "{";
    for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i];
    o << "}";
    return o;
}

ll gcd (ll a, ll b) {
	while (b > 0) {
		ll t = a % b;
		a = b, b = t;
	}
	return a;
}

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

bool is_prime (ll n) {
		if (n < 2) return false;
		else if (n == 2) return true;
		else if (n % 2) return false;
		
		double sqrtn = sqrt(n);
		for (ll i = 3; i < sqrtn; i += 2) {
			if (n % i == 0) return false; 
		}
		return true;
}

ll ctoi(char c) {
	return (ll)(c - 48);
}

ll n, k, cnt=0, ans=0, sum=0;
string s,t;

// ==================== template ============================

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

	int d, x; cin >> n >> d >> x;
	REP(i, n) {
		int a; cin >> a;
		sum += (d-1)/a + 1;
	}
	cout << x + sum << endl;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException{
		Main mainObj = new Main();
		mainObj.solve();
	}
	
	public void solve() throws IOException{
		FastScanner fs = new FastScanner();
		int k = fs.nextInt();
		int n = fs.nextInt();
		int[] distArr = fs.nextIntArr(n);
		
		int beforeDist = distArr[0];
		
		int maxDist = k - distArr[n-1] + distArr[0]; 
		
		for(int i = 1; i < n; i++){
			maxDist = Math.max(maxDist, distArr[i] - beforeDist);
			beforeDist = distArr[i];
		}
		
		System.out.println(k - maxDist);
	}

	public class FastScanner {
		
		BufferedReader reader;
		private StringTokenizer st;
		
		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		
		public String next() throws IOException {
			if(st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}
		
		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}
		
		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}
		
		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
		
		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for(int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}
		
		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for(int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}
		
		public void close() throws IOException {
			reader.close();
		}
	}
}


Measured memory_bytes: 47824
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
using namespace std;
const int N = 1e5+5;
void fast(){std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
int main()
{
	fast();
	string s,t;
	cin>>s>>t;
	cout<<t<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

    int main()

    {
       int i,j,n,a[100000],z;

       scanf("%d",&n);

       if(n>0&&n<=9)
       {
          printf("%d\n",n);
       }

       else if(n>=10&&n<=99)
       {
          printf("9\n");
       }

       else if(n>=100&&n<=9999)
       {
          if(n<=999)
          {
             z = (n-100)+10;

             printf("%d\n",z);
          }

          else if(n>999)
          {
             printf("909\n");
          }
       }

       else if(n>=10000&&n<=100000)
       {
          if(n<=99999)
          {
             z = 910 + (n-10000);

             printf("%d\n",z);
          }

          else if(n==100000)
          {
             printf("90909\n");
          }
       }
    }


Measured memory_bytes: 1688
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define chmin(x, y) x = min(x, y)
#define ll long long
#define ld long double
#define int ll
#define INF LLONG_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

signed main() {
  string S; cin >> S;
  ll K; cin >> K;
  ll i = 0;
  // cout  << i << endl;
  // cout << S.size() << endl;
  
  while(S[i] == '1') {
    i++;
  }

  if (i >= K) {
    cout << 1 << endl;
    return 0;
  }

  i = 0;
  while (1) {
    if (i == (ll)S.size()) {
      cout << S[S.size()-1] << endl;
      return 0;
    } else if (S[i] != '1') {
      cout << S[i] << endl;
      return 0;
    } else if (i >= INF) {
      cout << 1 << endl;
      return 0;
    } else {
      i++;
    }
  }
}


Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()

cnt = [0 for _ in range(N)]
for i in range(1, N):
    cnt[i] = cnt[i-1]
    if S[i] == 'C' and S[i-1] == 'A':
        cnt[i] += 1

for i in range(Q):
    l, r = map(int, input().split())
    print(cnt[r-1] - cnt[l-1])

Measured memory_bytes: 11640
class Dice
    def initialize(n)
        @up = n[0]
        @front = n[1]
        @right = n[2]
        @left = n[3]
        @back = n[4]
        @down = n[5]
    end

    def move(direction)
        case direction
        when 'S'
            tmp = @up
            @up = @back
            @back = @down
            @down = @front
            @front = tmp
        when 'W'
            tmp = @up
            @up = @right
            @right = @down
            @down = @left
            @left = tmp
        when 'E'
            tmp = @up
            @up = @left
            @left = @down
            @down = @right
            @right = tmp
        when 'N'
            tmp = @up
            @up = @front
            @front = @down
            @down = @back
            @back = tmp
        end
    end
    def getUp
        @up
    end
    def getDown
        @down
    end
    def getFront
        @front
    end
    def getBack
        @back
    end
    def getRight
        @right
    end
    def getLeft
        @left
    end
    def displayUp
        puts @up
    end
    def rotation(up,front)
        if @right == front then
            move('W')
            move('S')
        elsif @left == front then
            move('E')
            move('S')
        else
            while @front != front do
                move('S')
            end
        end
        while @up != up do
            move('W')
        end
    end
    def problem1
        displayUp
    end
    def problem2(up,front)
        rotation(up,front)
        puts @right
    end
    def same?(other_dice)
        if @up == other_dice.getUp && @down == other_dice.getDown && @front == other_dice.getFront && @back == other_dice.getBack && @right == other_dice.getRight && @left == other_dice.getLeft then
            puts "Yes"
        else
            puts "No"
        end
    end
    def problem3(other_dice)
        rotation(other_dice.getUp,other_dice.getFront)
        same?(other_dice)
    end
end

x = gets.split.map(&:to_i)
y = gets.split.map(&:to_i)
dice = Dice.new(x)
dice2 = Dice.new(y)
dice.problem3(dice2)


Measured memory_bytes: 6884
#include <iostream>
#include <vector>
typedef long long ll ;
using namespace std;
int main(){
    ll n;
    cin>>n;
    ll capacity;
    cin>>capacity;
    ll a[n+1][capacity+1];
    vector<pair<int,int>> w;
    for(int i=0;i<n;i++){
        ll x,y;
        cin>>x>>y;
        w.push_back(make_pair(x,y));
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=capacity;j++){
            if(i==0 or j==0) a[i][j]=0;
            else if(w[i-1].first <= j){
                a[i][j]=max(w[i-1].second+a[i-1][j-w[i-1].first],a[i-1][j]);
            }
            else a[i][j]=a[i-1][j];
            //cout<<a[i][j]<<" ";
        }
        //cout<<endl;

    }
    cout<<a[n][capacity]<<endl;
    return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

void main_()
{
    ll N;
    cin >> N;
    ll ans = N * (N - 1) / 2;
    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ac=0,bc=0,cc=0;
  cin>>n;
  long long cnt=0;
  vector<int> a(n),b(n),c(n);
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n;i++) cin>>b[i];
  for(int i=0;i<n;i++) cin>>c[i];
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  for(int i=0;i<n;i++) 
    cnt+=(lower_bound(a.begin(),a.end(),b[i])-a.begin())*(c.size()-(upper_bound(c.begin(),c.end(),b[i])-c.begin()));
  cout<<cnt<<endl;
  return 0;
}

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

using namespace std;
typedef long long ll;

int main(void)
{
    int n;
    cin >> n;
    vector<int> a(100000);
    for (int i = 0; i < n;i++)
        cin >> a.at(i);

    map<int, int> mp;
    for (int i = 0; i < n;i++)
        //keyであるa.at(i)の数字に対するvalueを加算していく
        mp[a.at(i)]++;

    int ans = 0;
    //登録されたmpの数だけループして数える
    for(auto p: mp){
        int x = p.first;
        int y = p.second;
        //keyよりもvalueが小さいときは加算
        if(y<x)
            ans += y;
        //keyよりもvalueが大きいときは差分を加算
        else
            ans += y - x;
    }
    cout << ans << endl;
}

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

#define ll long long
#define ull unsigned long long
#define LL long long
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define sch(n) scanf(" %c", &n)
#define ss(n) scanf("%s", n)
#define pii pair <int, int>
#define pll pair <ll, ll>
#define plp pair <int, pll >
#define pb push_back
#define fr first
#define sc second
#define all(a)  a.begin(),a.end()
#define Unique(a)  sort(all(a)),a.erase(unique(all(a)),a.end())

#define inf (1LL<<50)
#define eps 1e-9

ll Set(ll n, ll pos)
{
    return n|(1LL<<pos);
}

bool Check(ll n, ll pos)
{
    return (bool) (n&(1LL<<pos));
}

vector <ll> ed[100050];

ll dp[100050][2];

#define mod 1000000007

ll solve(ll n, ll pcol, ll par)
{
    ll &ret = dp[n][pcol];
    if (ret != -1)
        return ret;

    ret = 0;
    ll x = 1;
    for (ll i = 0; i < ed[n].size(); i++)
    {
        if (par == ed[n][i]) continue;
        x = (x*solve(ed[n][i], 0, n))%mod;
    }

    ret = x;

 //   cout << n << " " << par << " " << pcol << " f " << ret << endl;

    if (pcol == 0)
    {
        x = 1;
        for (ll i = 0; i < ed[n].size(); i++)
        {
            if (par == ed[n][i]) continue;
            x = (x*solve(ed[n][i], 1, n))%mod;
        }
        ret = (ret + x)%mod;
    }

 //   cout << n << " " << pcol << " " << ret << endl;

    return ret;
}

int main ()
{
    //  freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    //  ios_base::sync_with_stdio(0); // no printf/scanf must be present
    ll cs, ts, i, j, k, x, y, z, q, m, n, cap;

    while(sl(n) != EOF)
    {
        memset(dp, -1, sizeof(dp));

        for (i = 1; i <= n; i++)
            ed[i].clear();

        for (i = 1; i <= n-1; i++)
        {
            sl(x);
            sl(y);
            ed[x].pb(y);
            ed[y].pb(x);
        }

        ll ans = solve(1, 0, 0);
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 14208
import sys
input = sys.stdin.readline

def main():
    S = input().strip()

    s = list(S)
    n = len(s)

    while n > 0:
        if "".join(s[n - 5:n]) == "dream":
            n -= 5
        elif "".join(s[n - 5:n]) == "erase":
            n -= 5
        elif "".join(s[n - 7:n]) == "dreamer":
            n -= 7
        elif "".join(s[n - 6:n]) == "eraser":
            n -= 6
        else:
            print("NO")
            return
    else:
        print("YES")


if __name__ == '__main__':
    main()




Measured memory_bytes: 3956
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <math.h>

using namespace std;

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);
	string ans[] = {"yes", "no"};

	while(1) {
		int flg = 0;
		string s;
		getline(cin, s);
		if( s == "." ) break;
		int paren = 0;
		int brack = 0;
		vector<int> type;
		for(int i = 0; i < s.length(); i++) {
			char ch;
			ch = s.at(i);
			switch(ch) {
				case '(':
					type.push_back(1);
					paren ++;
					break;
				case ')':
					if(type.size() == 0) {
						flg = 1;
					} else {
						if(type.back() != 1) flg = 1;
						else type.pop_back();
					}
					paren --;
					break;
				case '[':
					type.push_back(2);
					brack ++;
					break;
				case ']':
					if(type.size() == 0) {
						flg = 1;
					} else {
						if(type.back() != 2) flg = 1;
						else type.pop_back();
					}
					brack --;
					break;
				default:
					break;
			}
			if( paren < 0 || brack < 0 ) flg = 1;
		}
		if(paren != 0 || brack != 0) flg = 1;
		cout << ans[flg] << endl;

	}

	
	//while(1){}
	return 0;
}

Measured memory_bytes: 1204
N,M=map(int,input().split())
d=set()
k=1
while(k*k<=M):
    if M%k==0:
        d.add(k)
        d.add(M//k)
    k+=1
ans=1
for n in d:
    if n>=N:
        ans=max(ans,M//n)
print(ans)


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

int main() {
    int n; cin >> n;
    vector<int> v(n, 0);
    for(int i = 0; i < n; ++i)
        cin >> v[i];
    
    int64_t ans = 0, sum = 0;

    for(int i = n - 1; i >= 0; --i) {
        sum += v[i];
        if(v[i] == 0) {
            ans += sum / 2;
            sum = 0;
        }
    }

    ans += sum / 2;

    cout << ans << "\n";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

int binpow(int a, int b) {
    if (b == 0)
    {
        return 1;
    }
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
    {
        return res * a;
    }
    return res;
}

ll gcd(ll a,ll b)
{
    if (b==0) return a;
    return gcd(b,a%b);
}

string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    double n;
    cin>>n;
    n/=3;
    cout<<setprecision(19)<<n*n*n;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
     
     
    #define ll long long
    #define pb push_back
    #define mp make_pair
    #define loop(i, a, b) for(int i = (a); i < (b); i++)
    #define loopb(i, a, b) for(int i = (a); i > (b); --i)
     
    typedef pair <int,int> ii;
    typedef vector <int> vi;
    typedef vector <ii> vii;
    typedef vector <ll> vl;
     
    const int mod = 1e9+7;
    const ll inf = 2e18+5;
     
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);

        int n;
        cin>>n;
        vl a(n);
        loop(i,0,n) cin>>a[i];

        ll dp[3005][3005]; //dp[i][j] is the answer when interval of [i,j] is remaining. So our final answer will be [0,n-1]

        for(int i=n-1; i>=0; i--){
            for(int j=i; j<=n-1; j++){
                if(i==j)
                    dp[i][j] = a[i];
                else
                    dp[i][j] = max(a[i] - dp[i+1][j] , a[j] - dp[i][j-1]);    
            }
        }

        cout<<dp[0][n-1];

        return 0;

}

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

using namespace std;

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

  int n, l;
  cin >> n >> l;

  vector<string> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];

  sort(begin(v), end(v));
  
  string res;
  for (string s: v) res += s;
  cout << res << "\n";
}


Measured memory_bytes: 3680
import sys
import numpy as np
from numba import njit,i8,void

@njit(i8(i8,i8),cache=True)
def gcd(x,y):
    while y:
        x,y = y , x % y 
    return x

@njit(i8(i8[:]),cache=True)
def get_gcd(a):
    gcd_all = a[0]
    for i in range(1,a.size):
        gcd_all = gcd(gcd_all,a[i])
    return gcd_all

@njit(i8(i8[:]),cache=True)
def judge_setwise(a):
    amax = a.max()
    aflag = np.zeros(amax,np.int64)
    aflag[a-1] = 1

    for i in range(2,amax+1):
        index = (np.arange(amax//i)+1)*i - 1
        count = aflag[index].sum()
        if count>=2:
            print("setwise coprime")
            return 0
    else:
        print("pairwise coprime")
        return 0

        
n = int(input())
a = np.array(list(map(int,input().split())),np.int64)


if get_gcd(a)>1:
    print("not coprime")
else:
    judge_setwise(a)

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

using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}

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

    int N, T;
    cin >> N >> T;

    vector<pair<int, int>> AB(N);
    rep(i, N) cin >> AB[i].first >> AB[i].second;
    sort(all(AB));

    vector<vector<int>> dp(N+1, vector<int>(T+1, 0));    

    rep(i, N) {
        rep(j, T + 1) {
            chmax(dp[i + 1][j], dp[i][j]);
            if (j != T) {
                int t = min(j + AB[i].first, T);
                chmax(dp[i + 1][t], dp[i][j] + AB[i].second);
            }
        }
    }

    cout << dp[N][T] << endl;
}


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

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};

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

string S,T;

signed main(){
    cin>>S>>T;
    int ma=0;
    for(int i=0;i<S.size()-T.size()+1;++i){
        int cnt=0;
        for(int j=0;j<T.size();++j){
            if(S[i+j]==T[j])cnt++;
        }
        chmax(ma,cnt);
    }
    cout<<(int)(T.size())-ma<<endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>

using namespace std;

int main() {
	string S;
	int K;
	cin >> S >> K;

	priority_queue<string, vector<string>, greater<string>> q;
	unordered_map<string, bool> m;
	for(int i = 0; i < S.size(); i++) {
		for(int l = 1; l <= K && i + l <= S.size(); l++) {
			string s(S, i, l);
			if(m.find(s) == m.end()) {
				m.emplace(s, true);
				q.push(s);
			}
		}
	}

	for(int i = 0; i < K - 1; i++) q.pop();
	cout << q.top() << endl;
}


Measured memory_bytes: 1724
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int

#define P pair<ll,ll>
#define V vector<ll>
#define M map<int,int>
#define S set<int>
#define L list<int>

#define pb(a) push_back(a)
#define mp make_pair

int main(){

    ll n,a,b;cin>>n>>a>>b;
    V x(n);
    VECCIN(x);

    ll cost=0;
    REP(i,n-1)cost+=min((x[i+1]-x[i])*a,b);
    COUT(cost);

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
int dp[123456][15];
//main
signed main(){
  string s;cin>>s;
  reverse(s.begin(),s.end());
  memset(dp,0,sizeof(dp));
  dp[0][0]=1;
  int N=s.size();
  int t=1;
  for(int i=0;i<N;i++){
    if(s[i]=='?'){
      for(int j=0;j<13;j++){
        for(int k=0;k<=9;k++){
          dp[i+1][(j+k*t)%13]+=dp[i][j];
          dp[i+1][(j+k*t)%13]%=MOD;
        }
      }
    }
    else {
      for(int j=0;j<13;j++){
        dp[i+1][(j+(s[i]-'0')*t)%13]+=dp[i][j];
        dp[i+1][(j+(s[i]-'0')*t)%13]%=MOD;
      }
    }
    t*=10;t%=13;
  }
  cout<<dp[N][5]<<endl;
}


Measured memory_bytes: 14976
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << "\n"; }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}


#line 2 "tmp.cpp"

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

  string a;
  cin >> a;
  map<char, ll> mp;
  ll len = a.length();
  REP(i, len) { mp[a[i]]++; }

  ll ans = len * (len - 1) / 2;
  for (const auto val : mp) {
    ll s = val.second;
    if (s > 0) {
      ans -= s * (s - 1) / 2;
    }
  }
  cout << ans + 1 << endl;

  return 0;
}


Measured memory_bytes: 720
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = input()

    res = 0
    for i, j in zip(s, "CODEFESTIVAL2016"):
        if i != j:
            res += 1
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 2940
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const int N = 2e5;
const LL MOD = 1e9 + 7;
vector<int> lst;
LL dp[N + 5];
LL pref[N + 5];
LL psum[N + 5];

void hora(int tc) {
	int n;
	cin>>n;
	lst.PB(0);
	for(int i = 0;i < n;i++) {
		int x;
		cin>>x;
		if(lst.back() == x) continue;
		lst.PB(x);
	}
	dp[0] = pref[0] = 1;
	psum[lst[1]] = 1;
	n = lst.size();
	n--;
	for(int i = 1;i <= n;i++) {
		dp[i] = (dp[i] + psum[lst[i]]) % MOD;
		psum[lst[i + 1]] = (psum[lst[i + 1]] + dp[i]) % MOD;
	}
	cout<<dp[n]<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}




Measured memory_bytes: 5364
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
//g++ -std=c++11 

using namespace std;

long long N;

int main(){
	cin >> N;

	long long ans = LONG_MAX;
	for(long long i = 1; i * i <= N; i++) {
		if(N%i == 0) {
			ans = min(ans, i - 1 + N/i - 1);
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3624
#include <stdio.h>
int main(void){
int n,m,i,j;
int a,b; 
int A[100][100] = {0}; 
int B[100] = {0}; int c[100] = {0}; scanf("%d %d " ,&n,&m);
for(j=0; j<n; j++) { for(i=0; i < m; i++) { scanf("%d",&a); A[j][i] = a;
}
} 
for(j=0; j<m; j++) { scanf("%d",&b); B[j] = b;
}
for(j=0;j<n ; j++){ for(i = 0; i<m; i++){ c[j] = c[j] + A[j][i]*B[i]; 
    
}
} 
for(i=0;i<n;i++) { printf("%d\n",c[i]); 
    
}
return 0; 
    
}


Measured memory_bytes: 2140
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int n,sg[SZ]; Edg
inline void dfs(int x,int f=0)
{for esb(x,e,b) if(b!=f) dfs(b,x),sg[x]^=sg[b]+1;}
int main()
{
	scanf("%d",&n);
	for(int i=1,a,b;i<n;++i)
		scanf("%d%d",&a,&b),adde(a,b);
	dfs(1);
	if(sg[1]) puts("Alice");
	else puts("Bob");
}

Measured memory_bytes: 11648
X, K, D = [int(a) for a in list(input().split())]
X = abs(X) 
q = X//D
r = X%D
if q >= K:
    print(X - D*K)
    exit()
rem = K - q
if rem % 2 == 0:
    print(r)
else:
    print(abs(D-r))

Measured memory_bytes: 9180
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

const int inf=1e9+10;
const int maxn=2e5+10;

int n;
ll ans[15][15];

void get_ans(int x){
	string s;
	while(x>0){
		s+=char(x%10+'0');
		x/=10;
	}
	ans[s[0]-'0'][s[s.size()-1]-'0']++;
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		get_ans(i);
	ll cnt=0ll;
	for(int i=1;i<=9;i++) for(int j=1;j<=9;j++)
		cnt+=ans[i][j]*ans[j][i];
	printf("%lld\n",cnt);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,e) for(int i=s;i<e;i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(),(a).end()
typedef long long LL;

int main() {
  int n,k;
  cin>>n>>k;
  vector<int> p(n);
  REP(i,n) cin>>p[i];
  int ans=1000000000;
  for(int i=0;i+k-1<n; i++){
    int j=i+k-1;
    if(p[j]<=0) ans=min(ans,-p[i]);
    else if(p[i]>=0) ans=min(ans,p[j]);
    else ans=min(ans,-p[i]+p[j]+min(-p[i],p[j]));
    }
  cout<<ans<<endl;
}

Measured memory_bytes: 768
unittest
{
	assert( [ "3" ].solve == "ACLACLACL" );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto k = input.front.to!( long );
	
	return "ACL".repeat( k ).join;
}


Measured memory_bytes: 2740
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    cout << (1 + N) * N / 2 << endl;
}

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

int main(){
	string S;
	cin >> S;
	string::iterator itr = S.begin();
	int cnt = 0;
	int i = 0;
	while(i + 1< S.length()){
		if(*(itr + i) != *(itr + 1 + i)){
			S.erase(itr + i, itr + 2 + i);
			cnt = cnt + 2;
			itr = S.begin();
			if(i > 0){
				i--;
			}
		}
		else{
			i++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <boost/range/adaptors.hpp>


int main() {
    int N;
    int M;
    std::cin >> N >> M;

    std::cout << N * (N - 1) / 2 + M * (M - 1) / 2 << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
char c;
int h,w,i,j;
int a[105],b[105];
int s[105][105];
int main(){

 cin>>h>>w;
 for(int i=1;i<=h;i++)
   for(int j=1;j<=w;j++)
     
 {
   cin>>c;
   if(c=='.')s[i][j]=1;
   else s[i][j]=-1;     
 }
 for(int i=1;i<=h;i++)
 {
 
 	for(int j=1;j<=w;j++)
 	    if(s[i][j]==-1)a[i]=1,b[j]=1;
 
 }
  
  for(int i=1;i<=h;i++)
 {
 	if(a[i]==1)
 {
 		for(int j=1;j<=w;j++)
     
 {
  if(b[j]==1)
   if(s[i][j]==1)cout<<'.';
   else cout<<'#';     
 }
 cout<<endl;
   }  
   }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(ll i = 0; i < (n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,e) for (ll i = s; i < (ll)e; i++)
#define TEN(x) ((ll)1e##x)

int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);

	ll n, k; cin >> n >> k;
	vb d(10, false);
	REP(i, k) {
		ll dd; cin >> dd;
		d[dd] = true;
	}


	while (true) {
		ll m = n;
		bool dd = false;
		while (m != 0) {
			if (d[m % 10]) dd = true;
			m /= 10;
		}
		if (!dd) {
			cout << n << endl;
			break;
		}
		n++;
	}

	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split(' '))

A = [0, 1000000]
for i in range(M) :
    L, R = map(int, input().split(' '))
    A[0] = max(A[0], L)
    A[1] = min(A[1], R)

ans = max(A[1] - A[0] + 1, 0)
print(ans)



Measured memory_bytes: 3060
#include <iostream>
using namespace std ;
int main(){
    int m , f , r , x , y ;
    while ( 1 ){
        cin >> m >> f >> r ;
        if ( m == -1 && f == -1 && r == -1 ) break ;
        else if ( m == -1 || f == -1 )
            cout << "F" << endl ;
        else if ( m + f >= 80 )
            cout << "A" << endl ;
        else if ( m + f >= 65 && m + f < 80 )
            cout << "B" << endl ;
        else if ( m + f >= 50 && m + f < 65 )
            cout << "C" << endl ;
        else if ( m + f >= 30 && m + f < 50 && r >= 50 )
            cout << "C" << endl ;
        else if ( m + f >= 30 && m + f < 50 )
            cout << "D" << endl ;
        else if ( m + f < 30 )
            cout << "F" << endl ;
        }
 
 
}

Measured memory_bytes: 3084
N=int(input())
xyh=[list(map(int,input().split()[:3])) for _ in range(N)]

#hが0以外の要素をみつける
ax, ay, ah = list(filter(lambda x: x[2], xyh))[0]

for x in range(101):
    for y in range(101):
        H=ah+abs(ax-x)+abs(ay-y)
        if all(max(H-abs(t[0]-x)-abs(t[1]-y),0) == t[2] for t in xyh):
            print(x,y,H)

Measured memory_bytes: 3064
# Greedyを一ひねり
# 最初はGreedyに取る。それから種類を増やす。2個目以降を削除して、新たなネタの1個目を加える。
# あるネタの中でポイントが最高かどうかが重要。これを　True　/　False　で管理する
n, k = list(map(int, input().split()))

sushi = [list(map(int, input().split())) + [None] for _ in range(n)]
sushi.sort(key = lambda s: s[1] , reverse = True) #値段の降順

# あるネタの中でポイントが最高なら、 Trueそうでなければ、　False
neta_seen = set()
for i in range(n):
	if sushi[i][0] in neta_seen:
		sushi[i][2] = False
	else:
		sushi[i][2] = True
		neta_seen.add(sushi[i][0])

# n_kind = len([s[1] for s in sushi[:k] if s[1] == True ]) 
# なんかうまくいかないので、最初からk番目までのTrueの数を愚直に書こう

n_kind = 0
for i in range(k):
	if sushi[i][2]:
		n_kind += 1

ans = sum([s[1] for s in sushi[:k]]) + n_kind ** 2
#print(sushi, ans)

now = ans
adopt = k
trash = k-1

while(True):

	while(adopt < n and sushi[adopt][2] == False):
		adopt += 1
	while(trash >= 0 and sushi[trash][2] == True):
		trash -= 1
	if not(adopt < n and trash >= 0):
		break

	now = now + sushi[adopt][1] - sushi[trash][1]
	now = now - n_kind**2 + (n_kind+1) ** 2

#	print(adopt, trash, now)

	n_kind += 1
	adopt += 1
	trash -= 1

	if now > ans:
		ans = now

print(ans)


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

using namespace std;

const int MAXN=10010;

typedef vector<int> vec;
typedef vector<vec> Graph;

Graph G(MAXN);
vec d(MAXN);

int main()
{
	int n,e;
	scanf("%d%d",&n,&e);
	for(int i=0;i<e;i++)
	{
		int s,t;
		scanf("%d%d",&s,&t);
		G[s].push_back(t);
		d[t]++;
	}
	queue<int> que;
	for(int i=0;i<n;i++)
		if(d[i]==0)
			que.push(i);
	while(!que.empty())
	{
		int t=que.front();que.pop();
		printf("%d\n",t);
		d[t]=INT_MAX;
		for(int i=0;i<G[t].size();i++)
		{
			d[G[t][i]]--;
			if(d[G[t][i]]==0)
				que.push(G[t][i]);
		}
	}
	return 0;
}

Measured memory_bytes: 3528
N = int(input())
A = list()
x = list()
y = list()

for i in range(N):
    A_tmp = int(input())
    A.append(A_tmp)
    x_tmp = list()
    y_tmp = list()
    for k in range(A_tmp):
        tmp = [int(j) for j in input().split()]
        x_tmp.append(tmp[0])
        y_tmp.append(tmp[1])
    x.append(x_tmp)
    y.append(y_tmp)

def DFS(acc_list, depth):
    if depth < N:
        acc_list[depth] = 0
        result1 = DFS(acc_list, depth+1)
        acc_list[depth] = 1
        result2 = DFS(acc_list, depth+1)
        return max(result1, result2)

    acc_dict = dict()
    for i in range(N):
        acc_dict[i] = None

    for i in range(N):
        if acc_list[i] == 1:
            for j in range(A[i]):
                if acc_dict[x[i][j]-1] == None:
                    acc_dict[x[i][j]-1] = y[i][j]
                else: 
                    if acc_dict[x[i][j]-1] == y[i][j]:
                        pass
                    else: 
                        return 0

    flag = 1
    for i in range(N):
        if acc_dict[i] == acc_list[i]:
            pass
        else:
            if acc_dict[i] == None:
                pass
            else:
                flag = 0
    if flag == 1:
        return sum(acc_list)
    else:
        return 0

acc_list = [0]*N

result = DFS(acc_list, 0)
print(result)

Measured memory_bytes: 48604