akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
const int INT_INF = 500000000;
const long long LONG_LONG_INF = (long long)pow(10, 18);
const int MOD = pow(10, 9) + 7;
/* contest template */
string s;
int K;
vector<string> v(5);

int main() {
  cin >> s >> K;
  char min = 'z';
  int cnt = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] < min) {
      cnt = 1;
      min = s[i];
    } else if (s[i] == min) {
      cnt++;
    }
  }
  int i = 0;
  int le = 2;
  v[0] = min;
  v[1] = "zzzzzz";
  v[2] = "zzzzzz";
  v[3] = "zzzzzz";
  v[4] = "zzzzzz";
  while (i < K - 1) {
    i++;
    for (int j = 0; j + le - 1 < s.length(); j++) {
      if (s[j] == v[i - 1][0]) {
        string t = s.substr(j, le);
        if (t < v[i]) {
          v[i] = t;
        }
      }
    }
    if (v[i] == "zzzzzz") {
      for (int j = 0; j < s.length(); j++) {
        string t(1, s[j]);
        if (t > v[i - 1] && t < v[i]) {
          v[i] = t;
        }
      }
      le = 2;
    } else {
      le++;
    }
  }
  cout << v[K - 1] << endl;
  return 0;
}


Measured memory_bytes: 256
const lines=readlines(open("/dev/fd/0"))
let
    state=0
    global input
    input()=lines[state+=1]
end
int(s::String)=parse(Int,s)
intSub(s::SubString{String})=parse(Int,s)
intLine(s::Array{SubString{String},1})=map(intSub,s)
function main()
    INF=2^60
    a,b,q=input()|>split|>intLine
    s=Array{Int}(a+2)
    s[1],s[a+2]=-INF,INF
    for i in 2:a+1
        s[i]=int(input())
    end
    t=Array{Int}(b+2)
    t[1],t[b+2]=-INF,INF
    for i in 2:b+1
        t[i]=int(input())
    end
    for _ in 1:q
        x=int(input())
        m=INF
        i=searchsortedlast(s,x)
        j=searchsortedlast(t,x)
        for v in view(s,i:i+1)
            for w in view(t,j:j+1)
                m=min(m,abs(x-v)+abs(v-w),abs(x-w)+abs(w-v))
            end
        end
        println(m)
    end
end
main()

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

int h,w;
char g[1005][1005];
queue<int> qx;
queue<int> qy;
int dx[]={-1,0,1,0},dy[]={0,1,0,-1};
int u[1005][1005];
int ans;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>h>>w;
    memset(u,-1,sizeof(u));
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>g[i][j];
            if(g[i][j]=='#'){
                qx.push(i);
                qy.push(j);
                u[i][j]=0;
            }
        }
    }
    while(!qx.empty()){
        int cx=qx.front();qx.pop();
        int cy=qy.front();qy.pop();
        ans=max(ans,u[cx][cy]);
        for(int d=0;d<4;d++){
            int nx=dx[d]+cx;
            int ny=dy[d]+cy;
            if(u[nx][ny]==-1&&nx>0&&ny>0&&nx<=h&&ny<=w){
                qx.push(nx);
                qy.push(ny);
                u[nx][ny]=u[cx][cy]+1;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 13440
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer a=sc.nextInt(),b=sc.nextInt();
		Set<String> set = new TreeSet<>();
		String A="",B="";

		for(int i=0;i<a;i++) {
			B+=b.toString();
		}
		for(int i=0;i<b;i++) {
			A+=a.toString();
		}
		set.add(A);
		set.add(B);
		for(String str : set) {
				System.out.println(str);
			return;
		}

	}
}

Measured memory_bytes: 27104
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)
#include <string>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < (n);++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0)

const ll INF = 1e9+7;

// 各桁の和
template<typename T>T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;}
template<typename T>T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

int main() {
  ll n,W;cin>>n>>W;
  vector<ll> w(n),v(n);rep(i,n)cin>>w[i]>>v[i];
  
  ll dp[110][100100];
  
  rep(i,n){
    rep(j,W+1){
      if(j >= w[i]){
        dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]]+v[i]);
      }else{
        dp[i+1][j] = dp[i][j];
      }
    }
  }
  print(dp[n][W]);
  return 0;
}

Measured memory_bytes: 80512
#include <stdio.h>

int search(int n) {
  int i, count = 0;
  while (n > 1) {
    count++;
    if (n % 3) {
      n /= 3;
      n++;
    } else {
      n /= 3;
    }
  }
  return count;
}

int main(void) {
  int n, ans;
  scanf("%d", &n);

  ans = search(n);
  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 596
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 head = fs.nextInt();
		int leg = fs.nextInt();
		
		for(int i = 0; i <= head; i++) {
			int kame = i;
			int tsuru = head - kame;
			
			if(kame * 4 + tsuru * 2 == leg) {
				System.out.println("Yes");
				return;
			}
		}
		
		System.out.println("No");
	}

	

	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: 32920
#include<iostream>

using namespace std;

int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if((a==5&&b==5&&c==7)||(a==5&&b==7&&c==5)||(a==7&&b==5&&c==5))
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
}
    

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

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

    int score = 0;
    for (int i = 0; i < N - 1; ++i){
        if(S[i] == S[i+1])
            score++;
    }
    int ans = min(score + 2 * K, N - 1);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

ll mp[62][222222];

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

	ll n, k;cin >> n >> k;
	REP(i, n)cin >> mp[0][i+1];

	for(ll i = 1;i < 62;i++){
		for(ll j = 1;j <= n;j++){
			mp[i][j] = mp[i-1][mp[i-1][j]];
		}
	}

	ll now = 1;
	REV(i, 62){
		if(k & (1LL << i))now = mp[i][now];
	}
	cout << now << endl;

	return 0;
}


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

int main() {
    std::string s;
    std::cin >> s;
    int count = 0;
    int ans = 0;
    for (auto c : s) {
        if (c == 'R') {
            ans = std::max(++count, ans);
        } else
            count = 0;
    }
    std::cout << ans;
}


Measured memory_bytes: 3592
import java.util.*;
public class Main {
	public static void main(String[] args){
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
      	
      	
		if(A%2==0){
        	System.out.println((A/2)*(A/2));
        }else{
        	System.out.println((A/2)*(A/2+1));
        }
      
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include <functional>
#include <queue>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;

int main() {

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

	if (a > b && c > b && c < a) {
		cout << "Yes" << endl;
	}
	else if (a < b && a < c && c < b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}








}

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

int main() {
  long N, K;
  cin >> N >> K;
  vector<long> X(N);
  for (long i = 0; i < N; i++) cin >> X.at(i);
  long ans = 2e18;
  for (long i = 0; i + K - 1 < N; i++) {
    long l = X.at(i);
    long r = X.at(i + K - 1);
    if (r < 0) ans = min(ans, -l);
    else if (l > 0) ans = min(ans, r);
    else ans = min(ans, r - l + min(-l, r));
  }
  cout << ans << "\n";
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

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

int main(){
	int a,b,c;
	while(~scanf("%d %d %d",&a,&b,&c)){
		if(a==b && b==c && c== -1) break;

		int remain1 = 120 * 60 - (a*60*60+b*60+c);
		int h = remain1 / 3600;
		int remain2 = remain1 % 3600;
		int m = remain2 / 60;
		int s = remain2 % 60;
		printf("%02d:%02d:%02d\n",h,m,s);


		remain1*=3;
		h = remain1 / 3600;
		remain2 = remain1 % 3600;
		m = remain2 / 60;
		s = remain2 % 60;
		printf("%02d:%02d:%02d\n",h,m,s);
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<cstring>
#include<cmath>
#define MAX 105
#define max(a,b) ((a) > (b) ? (a) : (b))
using namespace std;
int Cand[5][MAX],DP[5][MAX];

int main( )
{
	int n;
	memset(DP,0,sizeof(DP));
	cin >> n;
	for(int j = 1; j <= 2; j++)
		for(int i = 1; i <= n; i++)
			cin >> Cand[j][i];
	for(int i = 1; i <= 2; i++){
		for(int j = 1; j <= n; j++){
			DP[i][j] = max(DP[i - 1][j] + Cand[i][j],DP[i][j - 1] + Cand[i][j]);
		}
	}
	cout << DP[2][n] << endl;
}

 

Measured memory_bytes: 256
/*********************************
*include
*********************************/
#include <stdio.h>

/*********************************
*function prototype
*********************************/
int cuberaise( int x );

/*********************************
*function
*********************************/
int main( void )
{
	int num;

	scanf( "%d", &num );

	/* num???3????????¨????????? */
	printf( "%d\n", cuberaise( num ) );

	return ( 0 );
}

int cuberaise( int x )
{
	return ( x * x * x );
}

Measured memory_bytes: 596
open System

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f

    let readInts() =
        read string
        |> Seq.toArray
        |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<EntryPoint>]
let main _ =
    let s = read string

    let l = s.Substring(0, 4)
    let r = s.Substring(4)
    sprintf "%s %s" l r |> printfn "%s"
    0 // return an integer exit code


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

int main() {
  int N, A;
	int n;
  cin >> N >> A;
	n = N % 500;
	if (n > A){
		cout << "No" << endl;
	} 
  else if (n <= A) {
    cout << "Yes" << endl;
  }
}


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

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define ALL(s) (s).begin(),(s).end()
#define ALLn(s,n) s,s+n
#define F first
#define S second
#define pb push_back
#define tc(t) int t; cin >> t; while(t--)
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }

const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const ll INF = LONG_LONG_MAX;
#define PI 3.141592653589793
void solve() {
	int n;
	cin >> n;
	n %= 10;

	if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9) cout << "hon";
	else if(n == 0 || n == 1 || n == 6 || n == 8) cout << "pon";
	else cout << "bon";
}

int32_t main() {_
	//tc(t)
		solve();
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(n) for(int i=0;i<n;i++)
#define ll long long
ll mob=1000000007;
using namespace std;
int main()
{ 
int a,m;
cin>>a>>m;
int y=a*(a-1)/2;
int u=m*(m-1)/2;
cout<<y+u;






return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;



int main() {
	while(1) {
		int N; cin >> N;
		if (!N)break;
		vector<pair<string, long double>>pls;
		for (int i = 0; i < N; ++i) {
			string st;
			int p, a, b, c, d, e, f, s, m; cin >> st>>p >> a >> b >> c >> d >> e >> f >> s >> m;
			int initime = a + b + c;
			int rooptime = d + e;
			int money = m*s*f-p;
			long double eff = static_cast<long double>(money) / static_cast<long double>(initime + rooptime*(m));
			pls.push_back(make_pair(st, eff));
		}
		sort(pls.begin(), pls.end(), [](const pair<string, long double>&l, const pair<string, long double>&r) {return abs(l.second-r.second)<1e-12?l.first<r.first:l.second > r.second; });
		for (int i = 0; i < pls.size(); ++i) {
			cout << pls[i].first << endl;
		}
		cout << "#" << endl;
	}
	return 0;
}

Measured memory_bytes: 3032
N = int(input())
H = list(map(int, input().split()))
ans = []
cnt = 0

for i in range(N - 1):
  if H[i] < H[i + 1]:
    ans.append(cnt)
    cnt = 0
  else:
    cnt += 1
ans.append(cnt)
print(max(ans))

Measured memory_bytes: 14252
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>

using namespace std;

bool prime[100001];

void eratos(void)
{
	memset(prime, true, sizeof(prime));
	prime[1] = false;

	for (int i = 2; i <= 100000; i++)
	{
		if (prime[i] == true)
		{
			for (int j = 2 * i; j <= 100000; j += i)
			{
				prime[j] = false;
			}
		}
	}
}
int main(void)
{
	long long int dp[100001] = { 0, };
	int q, l, r;

	cin.tie(0);
	ios::sync_with_stdio(false);

	eratos();
	dp[0] = 0;

	for (int i = 1; i <= 100000; i++)
	{
		int a = i;
		int b = (i + 1) / 2;
		if (prime[a] == true && prime[b] == true)
		{
			dp[i] = dp[i - 1] + 1;
		}
		else
		{
			dp[i] = dp[i - 1];
		}
	}

	cin >> q;

	for (int i = 0; i < q; i++)
	{
		cin >> l >> r;
		cout << dp[r] - dp[l - 1] << '\n';
	}
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000009
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

vector<vector<ll>> dp(101, vector<ll>(100001, INF*2));
//dp.at(i).at(j)は始めのi個まで使って価値がj以上になる最小の重さ

int main(){
  ll N, W;
  cin >> N >> W;
  vector<ll> w(N), v(N);
  rep(i, N){
    cin >> w.at(i) >> v.at(i);
  }
  rep(i, N){
    rep(j, 100001){
      if(j > v.at(i)){
        dp.at(i+1).at(j) = min(dp.at(i).at(j), dp.at(i).at(j-v.at(i))+w.at(i));
      }
      else{
        dp.at(i+1).at(j) = min(dp.at(i).at(j), w.at(i));
      }
    }
  }
  ll ans = 0;
  rep(i, 100001){
    if(dp.at(N).at(i) <= W){
      ans = i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 80256
N = int(input())

ac = wa = tle = re = 0
for i in range(N):
    s = input()
    if s == "AC":
        ac += 1
    if s == "WA":
        wa += 1
    if s == "TLE":
        tle += 1
    if s == "RE":
        re += 1

print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))


Measured memory_bytes: 69864
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define a first
#define b second
using namespace std;
typedef pair<ll, ll> line;
const int N = 2e5 + 5;
ll n, c, h[N], dp[N];

ll val(line u, ll x) { return u.a * x + u.b; }
ld giaoX(line u, line v) { return (ld)(v.b - u.b) / (u.a - v.a); }
struct conVex
{
    deque<line> dq;
    void add(line u)
    {
        while (dq.size() >= 2 && giaoX(u, dq[dq.size() - 1]) <= giaoX(u, dq[dq.size() - 2]))
            dq.pop_back();
        dq.emplace_back(u);
    }
    ll query(ll x)
    {
        while (dq.size() >= 2 && giaoX(dq[0], dq[1]) < x)
            dq.pop_front();
        return val(dq[0], x);
    }
} T;

int main()
{
    //freopen("z.inp", "r", stdin);
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n >> c;
    for (int i = 1; i <= n; i++)
        cin >> h[i];
    //dp[i] = min(dpj + (hj - hi)^2 + c) = dpj + hj^2 - 2hjhi + hi^2 + c
    //dp[i] = min(-2hj*hi + dpj + hj^2) + hi^2 + c
    dp[1] = 0;
    T.add({-2 * h[1], h[1] * h[1]});
    for (int i = 2; i <= n; i++)
    {
        dp[i] = T.query(h[i]) + h[i] * h[i] + c;
        T.add({-2 * h[i], dp[i] + h[i] * h[i]});
    }
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 8460
#include<stdio.h>
int main(void){

int N=0;
  
scanf("%d",&N);
  
if(N>=64)
  printf("%d",64);
  if(N<64 && N>=32)
    printf("%d",32);
  	if(N<32 && N>=16)
      printf("%d",16);
  	  if(N<16 && N>=8)
        printf("%d",8);
  		if(N<8 && N>=4)
          printf("%d",4);
  		  if(N<4 && N>=2)
            printf("%d",2);
  			if(N==1)
              printf("%d",1);
  return 0;
}

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

vector<long long> divisors(long long n) {
  vector<long long> res;
  for (int i = 1; i < int(sqrt(n)) + 1; i++) {
    if (n % i == 0) res.push_back(i);
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  auto res = divisors(n);
  int i = res[res.size() - 1];
  int ans = max(to_string(i).size(), to_string(n / i).size());
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(a%b,b);
}

template<typename T>
vector<ll> countVector(vector< T >v,T guard=-1){
    ll size=v.size();
    //番兵を追加(初期値は-1)
    v.push_back(guard);
    vector<ll>ret;
    ll count=1;
    for(int i=0;i<size;i++){
        if(v[i]==v[i+1]){
            count++;
        }else{
            ret.push_back(count);
            count=1;
        }
    }
    return ret;
}

int main(){
  init();
  ll N;cin>>N;ll X;cin>>X;
  vector<ll>x(N);
  for(int i=0;i<N;i++)cin>>x[i];

  ll ans=0;
  for(int i=0;i<N;i++)ans=gcd(ans,abs(x[i]-X));
  cout<<ans<<endl;

}


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

using namespace std;
const int OO = 0x3f3f3f3f;
//const long long OO = (long long) 5e18+7;
//const unsigned long long UOO = (long long) 10e18+7;
#define lp(i,a,n) for(long long i = a ; i < n ; ++i)
#define lpr(i,a,n) for(long long i = a ; i >= n ; --i)
#define rep(i,vec) for(ll i = 0 ; i < vec.size() ; ++i)
#define reprv(i,vec) for(ll i = vec.size()-1; i >=0 ; --i)
#define eps (1e-5)
#define pb(i) push_back(i)
#define EPS 1e-9
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define debug(x) cout<<(#x)<<": \""<<x<<"\""<<endl
#define debugVec(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl

typedef vector<int> vi ;
typedef   long long ll;
typedef   unsigned long long ull;
typedef vector<ll> vll ;
typedef pair<int,int> pii ;
typedef vector< pair<int,int> >  vpii;
typedef vector<pair<long long,long long>> vpll;
typedef vector<vector<int> > vvi ;
typedef complex<double> point;
typedef pair<ll,ll> pll;

using namespace std;
ll  inv(ll a, ll b) {return 1 < a ? b - inv(b % a, a) * b / a : 1;}
ll  Pow(ll  B,ll  P){ll  R=1; while(P>0)  {if(P&1) R=(R*B);P/=2;B=(B*B);}return R;} //compute b^p
ll  GCD(ll  a,ll  b){ while(b){b ^= a ^=b ^= a %=b;}  return a;}
ll  LCM(ll  a,ll  b) { return (a / GCD(a,b)*b); }
ll  BigMod(ll  B,ll  P,ll  M){ ll  R=1; while(P>0)  {if(P&1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return (ll )R;} //compute b^p%m
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//int i=uniform_int_distribution<int>(1,n)(rng);


int N;
vi h;
int mem[100005];

int dp(int pos){
    if(pos > N) return 1000000000;
    if(pos == N) return 0;
    if(mem[pos]!=-1) return mem[pos];
    int a = 1000000000,b = 1000000000;
    if(pos+1 <= N) a = abs(h[pos]-h[pos+1])+ dp(pos+1);
    if(pos+2 <= N) b = abs(h[pos]-h[pos+2]) + dp(pos+2);
    return mem[pos]=min(a,b);
}




int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
//    cout.tie(0);
//#ifndef ONLINE_JUDGE
//   freopen( "output.txt" , "w" , stdout ) ;
//   freopen( "input.txt" , "r" , stdin ) ;
//#endif

    cin >> N;
    h.resize(N);
    lp(i,0,N) cin >> h[i];
    --N;
    memset(mem,-1,sizeof mem);
    cout << dp(0);


    return 0;
}


Measured memory_bytes: 8748
import collections

n,p=map(int,input().split())

a=[]
while p % 2 == 0:
  p //= 2
  a.append(2)
f = 3
while f * f <= p:
  if p % f == 0:
    a.append(f)
    p //= f
  else:
    f += 2
if p != 1:
  a.append(p)

dct=collections.Counter(a)

ans=1

li=dct.items()

for tt in li:
  if tt[1]//n>=1:
    ans*=tt[0]**(tt[1]//n)
print(ans)


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

int n1, n2, i1, i2;
int dp [3001][3001];
char s1 [3001];
char s2 [3001];
vector <char> out;

int main ()
    {
    scanf ("%s%s",s1+1,s2+1);
    n1 = strlen(s1+1);
    n2 = strlen(s2+1);
    for (i1=1; i1<=n1; i1++)
        for (i2=1; i2<=n2; i2++)
            {
            if (s1[i1]==s2[i2])
                dp[i1][i2]=dp[i1-1][i2-1]+1;
            else
                dp[i1][i2]=max(dp[i1][i2-1],dp[i1-1][i2]);
            }
    i1=n1;
    i2=n2;
    while (dp[i1][i2]>0)
        {
        if (s1[i1]==s2[i2])
            {
            out.push_back(s1[i1]);
            i1--;
            i2--;
            }
        else
            {
            if (dp[i1-1][i2]>=dp[i1][i2-1])
                i1--;
            else
                i2--;
            }
        }
    reverse (out.begin(),out.end());
    for (char c : out)
        printf ("%c", c);
    printf ("\n");
    return 0;
    }


Measured memory_bytes: 35456
#include <stdio.h> 
int main(){
    int n;
    scanf("%d", &n);
    int p[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &p[i]);
    }
    int flag = 0;
    int d = n+1;
    for(int i = 0; i < n; i++){
        if(p[i] < d){
            d = p[i];
            flag++;
        }
    }
    printf("%d", flag);
    
    return 0;
}

Measured memory_bytes: 896
#include <iostream>

using namespace std;

int main()
{
	long long a[3];
	cin>>a[0];
	cin>>a[1];
	cin>>a[2];
	for(int i=0;i<2;i++)//降序排列 
	{
		for(int j=i;j<3;j++)
		{
			if(a[i]<a[j])
			{
				swap(a[i],a[j]);
			}
		}
	}
    long long t1=a[0]-a[0]/2;
    long long t2=a[0]-t1;
    long long t=t1-t2;
    if(t<0)
    {
    	t=-t;
	}
	cout<<t*a[1]*a[2];
 } 

Measured memory_bytes: 256
N=int(input())

t_,x_,y_=(0,0,0)

ans = 'Yes'
for n in range(N):
    t,x,y = list(map(int,input().split()))
    T = t-t_
    manhattan_dist = abs(x-x_)+abs(y-y_)
#     print(T,manhattan_dist)
    if T >= manhattan_dist and manhattan_dist%2 == T%2:
        pass
    else:
        ans='No'
        
    t_,x_,y_ = t,x,y

print(ans)

Measured memory_bytes: 74728
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <array>
#include <cmath>

using namespace std;

using ll = long long int;

// GCDを計算します
template <typename NumType>
NumType calcGCD(NumType a, NumType b) {
    if (a < b) {
        NumType tmp = a;
        a = b;
        b = tmp;
    }

    NumType r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

// 約数を数えます
template <typename NumType>
NumType cntDivisor(const NumType & num) {
    NumType cnt = 0;
    for(NumType i = 1; i * i <= num; ++i) {
        if(num % i == 0) {
            cnt++;
            if(i * i != num) cnt++;
        }
    }

    return cnt;
}

// [beg, end)の範囲を，添え字indexでループするfor文に置換します
#define FOR_RANGE(index, beg, end)     for (ll index = beg; index < N; ++index)

#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

template<class T>
T min(T a, T b) {
    return (a < b) ? a : b;
}

template<class T>
T max(T a, T b) {
    return (a > b) ? a : b;
}

int main() {
    int N;
    int X[100];

    cin >> N;
    int sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> X[i];
        sum += X[i];
    }

    int min = 100000000;

    std::sort(X, X+N, std::less<int>());

    //int middle = sum/2;
    // for (int range = 0; range < sum/2; range++) {
    //     for (int way = 0; way < 2; way++) {
    //         int p;
    //         if (way == 0) {
    //             p = middle + range;
    //         } else {
    //             p = middle - range;
    //         }

    //         int ans = 0;
    //         for (int i = 0; i < N; i++) {
    //             ans += std::pow(X[i] - p, 2);
    //         }

    //         if (ans < min) {
    //             min = ans;
    //         } else if (ans > min) {
    //             //break;
    //         }
    //     }
    // }

    for (int p = 1; p <= 100; p++) {
        int ans = 0;
        for (int i = 0; i < N; i++) {
            ans += std::pow(X[i] - p, 2);
        }

        if (ans < min) {
            min = ans;
        }
    }

    cout << min;

    return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <math.h>
#include <string.h>

using std::endl;
using std::string;

#define ll long long int
#define LEP(a, n) for(int a = 0; a < n; ++a)
#define INF 1145141919810
#define OUT std::cout
#define IN std::cin
#define itn int
#define fro for
#define sdt std

ll N, M;
ll A, B, C;
ll ans = 0;

int main()
{
	IN >> N >> M;
	ans = N - M + 1;


	OUT << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
//const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
int main()
{

    fastread();

    ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r;


    cin>>n>>k;

    ll ara[n+2],dp[n+2]= {};

    dp[0]=dp[1]=0;



    for(i=1; i<=n; i++)
    {
        cin>>ara[i];



          if(i>1)
          {
              j=i-1;

              dp[i]=1e18;

              ll &ret=dp[i];

              while(j>=max(1ll,i-k))
              {
                  ret=min(ret,dp[j]+abs(ara[i]-ara[j]));
                  j--;
              }
          }
    }

    cout<<dp[n]<<endl;



}


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

int main() 
{
    string w, t;                                                        //一つの単語w, 文章に含まれる文章t
    bool judge;                                                         //YES, NOを判定する変数
    int count = 0;                                                      //一致した回数を数える
    int trans = 'a' - 'A';                                              //大文字、小文字の変換

    cin >> w;

    while( cin >> t )
    {
        if( t == "END_OF_TEXT" )
            break;
        if( t.size() != w.size() );
        
        else
        {
            for( int i = 0; i < w.size(); i++ )
            {
                if( t[i] != w[i] )
                {
                    if( t[i] != w[i] - trans )
                    {
                        judge = false;
                        break;
                    }
                    else
                        judge = true;
                }
                else
                    judge = true;
            }

            if( judge )
                count++;
        }
    } 
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3140
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
using namespace std;

int main()
{
	int nC[3][3];
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
			cin >> nC[i][j];
	}

	int nA[3] = {0,0,0};
	int nB[3] = {0,0,0};
	bool bNG = false;
	for (int x = 0; x < nC[0][0]; x++)
	{
		// 仮数
		nA[0] = nC[0][0] - x;
		nB[0] = nC[0][0] - nA[0];
		nB[1] = nC[0][1] - nA[0];
		nB[2] = nC[0][2] - nA[0];
		nA[1] = nC[1][0] - nB[0];
		nA[2] = nC[2][0] - nB[0];

		// 一致チェック
		try
		{
			for (int i = 0; i < 3; i++)
			{
				for (int j = 0; j < 3; j++)
				{
					if (nC[i][j] != nA[i] + nB[j])
					{
						bNG = true;
						throw 1;
					}
				}
			}
		}
		catch (...)
		{
			;
		}
		if (bNG == false)
			break;
	}
	if (bNG == false)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main (String args[]) throws Exception{
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt() * 2;
		int ans = 0;
		if(a > b) {
			ans = a - b;
		}
		System.out.println(ans);
	}
}

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

#define pb push_back 

ll const mod=1e9+7;





int main()
{

int n;
cin>>n;
ll a[n],p[n+1];
int i=1;
p[0]=0;
for(auto &x:a)
{
	cin>>x;
	p[i]=(p[i-1]+x+mod)%mod;
	i++;
}
ll ans=0;
for(int j=0;j<n;j++)
{
	ans+=(p[j]*a[j]+mod)%mod;
	ans=(ans+mod)%mod;
}

cout<<(ans+mod)%mod;

}

Measured memory_bytes: 6764
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
cnt = 0
for _ in range(N):
    S = C
    for i, a in enumerate(map(int, input().split())):
        S += a*B[i]
    if S>0:
        cnt += 1
print(cnt)

Measured memory_bytes: 62216
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

ans = 0
n.times do |i|
  if i.even? && a[i].odd?
    ans += 1
  end
end

puts ans


Measured memory_bytes: 14580
#include <stdio.h>
int main(){
    long N,M;
    long i,j;
    long L[100000],R[100000];
    long ret = 0;
    long min,max;
    min = 100001;
    max = 0;
    scanf("%ld %ld",&N,&M);
    for(i=0;i<M;i++){
        scanf("%ld %ld",&(L[i]),&(R[i]));
        if (L[i]>max){
            max = L[i];
        }
        if (R[i]<min){
            min = R[i];
        }
    }
    ret = min - max + 1;
    if(ret<1){ret = 0;}
    printf("%ld\n",ret);
    return 0;
}

Measured memory_bytes: 1664
from collections import defaultdict

N, P = map(int, input().split())
S = input()
if P == 2 or P == 5:
    ans = 0
    for i in range(N):
        d = int(S[i])
        if d % P == 0:
            ans += i + 1
    print(ans)
else:
    ans = 0
    count = defaultdict(int)
    count[0] = 1
    num = 0
    factor = 1
    for i in range(N)[::-1]:
        num = (num + int(S[i]) * factor) % P
        factor = factor * 10 % P
        ans += count[num]
        count[num] += 1
    print(ans)


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

using namespace std;

typedef long long int ll;
#define pb push_back
#define ALL(a) (a).begin() , a.end()

int mod = 1e9 + 7;
int add(int a, int b){
	if(a + b >= mod)return a+ b - mod;
	return a + b;
}
int mul(int a, int b){
	return 1LL * a * b  % mod;
}
int const N = 200 * 1010;

/********************i**********************************/
void solve(){
	string s, t;
	cin >> s >> t;
	int dp[s.length() + 1][t.length() + 1];
	int n = s.length(), m = t.length();
	for(int x =0; x<n+1; x++)for(int y =0; y<m+1; y++)dp[x][y] = 0;
	for(int x = 0; x<s.length(); x++){
		for(int y = 0; y<t.length(); y++){
			if(s[x] == t[y])
				dp[x+1][y+1] = dp[x][y] + 1;
			else{
				dp[x+1][y+1] = max(dp[x+1][y], dp[x][y+1]);
			}
		}
	}
	// for(int x =0; x<n+1; x++){
	// 	for(int y =0 ;y<m+1; y++)
	// 		cout << dp[x][y] << " ";
	// 	cout << endl;
	// }
	int l = dp[s.length()][t.length()];
	string  ans  = "";
	while(n != 0 && m != 0){
		if(s[n-1] == t[m-1])ans = s[n-1] + ans , n--, m--;
		else if(dp[n][m] == dp[n][m-1])m--;
		else n--;
	}
	// reverse(ALL(ans));
	cout << ans;
}


/******************************************************/
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int t;
	t = 1;
	// cin >> t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 35456
#include<bits/stdc++.h>
 
using namespace std;
 
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}init;
 
typedef long long LL;
 
template<typename T>void chmin(T &a,T b){a=min(a,b);}
template<typename T>void chmax(T &a,T b){a=max(a,b);}
template<typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
#define SZ 600000
#define fin "\n"
struct node{
    int all_num;
    int len;
    int nxt[27];
    int exist;
}trie[SZ];
 
int sz=0;
#define getpos(c) (c-'a'+1)
#define getbitid(i) (__builtin_ctz(i))
#define getbitcnt(i) (__builtin_popcount(i))
int p[27];
int res[SZ];
int main(){
    p[0]=0;
    for(int i=0;i<SZ;i++){
        trie[i].all_num=0;
        trie[i].len=0;
        trie[i].exist=0;
        for(int k=0;k<27;k++)trie[i].nxt[k]=-1;
    }
    sz++;
    int N,Q;
    cin>>N;
    vector<string> s(N);    
    for(int i=0;i<N;i++){
        cin>>s[i];s[i]+=(char)('a'-1);
        int len=s[i].size();
        int v=0;
        for(int j=0;j<len;j++){
            int u=getpos(s[i][j]);
            if(trie[v].nxt[u]==-1){
                trie[v].nxt[u]=sz++;
                trie[v].exist|=1<<u;
            }
            v=trie[v].nxt[u];
            trie[v].all_num++;
            trie[v].len=j+1;
        }
    }
    for(int i=sz-1;i>=0;i--){
        for(int j=0;j<27;j++){
            if(trie[i].nxt[j]!=-1){
                int nxt=trie[i].nxt[j];
                if(getbitcnt(trie[nxt].exist)==1){
                    int k=getbitid(trie[nxt].exist);
                    trie[i].nxt[j]=trie[nxt].nxt[k];
                }
            }
        }
    }
    cin>>Q;
    for(int tt=0;tt<Q;tt++){
        int id;
        string t;
        cin>>id>>t;id--;
        for(int i=0;i<26;i++)
            p[getpos(t[i])]=i+1;
        int len=s[id].size();
        int now=0;
        int v=0;
        int lower=0;
        while(now<len){
            int bit=trie[v].exist;
            int pos=getpos(s[id][now]);
            while(bit){
                int nowbit=getbitid(bit);
                if(p[nowbit]<p[pos])lower+=trie[trie[v].nxt[nowbit]].all_num;   
                bit-=1<<nowbit;
            }
            v=trie[v].nxt[pos];
            now=trie[v].len;
        }
        res[tt]=lower+1;
    }
    for(int t=0;t<Q;t++)cout<<res[t]<<fin;
    return 0;
}


Measured memory_bytes: 77056
target = input()

while len(target)>=5:
    if target[-7:] == "dreamer":
        target = target[:-7]
    elif target[-6:] == "eraser":
        target = target[:-6]
    elif target[-5:]=="dream" or target[-5:]=="erase":
        target = target[:-5]
    else:
      break
if len(target)==0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
const int maxn = 500050;
const int mod = 1e9+7;
using namespace std;
int main()
{
	int a;
	cin>>a;
	cout<<a+a*a+a*a*a<<endl;
	return 0;
}

Measured memory_bytes: 3564
import math
a,b=map(int,input().split())
ok=0
x=0
ans=0
while ok<1:
    aa=math.floor(x*0.08)
    bb=math.floor(x*0.1)
    #print(aa)
    #print(bb)
    if aa==a and bb==b:
        ans=x
        break
    x+=1
    if x==100000:
        ans=-1
        break
print(ans)

Measured memory_bytes: 40908
n=int(input())
taro=0
hanako=0
for i in range(n):
    a,b=map(str,input().split())
    if a>b:
        taro+=3
    elif a<b:
        hanako+=3
    else:
        taro+=1
        hanako+=1
        
print(taro,hanako)


Measured memory_bytes: 5596
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template< typename T > using matrix = vector< vector< T > >;

//FUNCTION  


void solve(void)
{
  int N,K;
  cin>>N>>K;
  K--;
  vector<int> vec(N);
  for (int i = 0; i < N; i++)
  {
    cin>>vec[i];
  }
  sort(ALL(vec));
  int ANS = INF;
  for (int i = 0; i < N-K; i++)
  {
    chmin(ANS,min(abs(min(vec[i],0LL)) + abs(max(vec[i+K],0LL)*2),abs(min(vec[i],0LL))*2 + abs(max(vec[i+K],0LL))));
  }
  cout<<ANS<<endl;
  
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 1024
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
x = a[0] * a[1] // gcd(a[0], a[1])
for i in range(2, n):
    x = x * a[i] // gcd(x, a[i])
c = 0
for i in range(n):
    c += (x - 1) % a[i]
print(c)


Measured memory_bytes: 5344
#include <iostream>

using namespace std;

typedef struct{
	int color;
	bool is_checked;
} building_t;

// いつも1次元配列を使う癖があるので
inline int xy(const int _x, const int _y, const int _W){ return _x + _y * (_W + 2); }

// 奇数行と偶数行での隣接の座標を一括で扱うための関数
// 斜め左の x座標を返す
inline int xLeftOblique(const int _x, const int _y){ return _x - (_y+1)%2; }
// 斜め右の x座標を返す
inline int xRightOblique(const int _x, const int _y){ return _x + _y%2; }

// 囲まれた白マスを調べる関数
bool isInside(building_t *_buildings, int *_index, int *_memo, const int _x, const int _y, const int _W){
	const int coordinate = xy(_x, _y, _W);
	building_t *tmp = &_buildings[coordinate];

	// 建物があるなら true を返す
	if((*tmp).color == 1) return true;

	// 地図外なら false を返す
	if((*tmp).color == -1) return false;

	// 既に調べていたら true を返す
	if((*tmp).is_checked) return true;

	// チェック済みであることをメモ
	(*tmp).is_checked = true;

	// 隣接マスを調べる（再帰呼び出し）
	// 奇数行と偶数行で隣接の座標の規則が異なるので注意
	const int xlo = xLeftOblique(_x, _y);
	const int xro = xRightOblique(_x, _y);

	// -> false が返ってきたら color を -1 にして false を返す
	// 同じような文を6つ書くのでマクロ関数使う
	#define IS_INSIDE(X, Y) if(!isInside(_buildings, _index, _memo, X,  Y, _W)){ (*tmp).color = -1; return false; }
	IS_INSIDE(xlo , _y-1);	// 左上
	IS_INSIDE(xro , _y-1);	// 右上
	IS_INSIDE(_x-1, _y  );	// 左
	IS_INSIDE(_x+1, _y  );	// 右
	IS_INSIDE(xlo , _y+1);	// 左下
	IS_INSIDE(xro , _y+1);	// 右下
	#undef IS_INSIDE

	// すべてをパスしたら囲まれている可能性があるので true を返し, color を 1 にする
	// 囲まれいない場合を考慮して調べたマスをメモしておく
	// -> 囲まれていなかったら後でまとめて color を -1 にする
	(*tmp).color = 1;
	_memo[*_index] = coordinate;
	(*_index)++;
	return true;
}

int main(){
	int W, H;
	cin >> W >> H;

	// 地図外のマスを余分に用意しておく
	// isInside を再帰的に呼び出すので地図の外を見る可能性があるため
	const int W2 = W + 2;
	const int H2 = H + 2;

	building_t *buildings = new building_t[W2 * H2];

	// 建物の配置を入力
	// 地図外 -> -1, 建物なし(白) -> 0, 建物あり(灰色) -> 1
	for(int y=0; y<H2; y++){
		for(int x=0; x<W2; x++){
			const int coordinate = xy(x, y, W);
			if(x == 0 || x == W2 - 1 || y == 0 || y == H2 - 1) buildings[coordinate].color = -1;
			else cin >> buildings[coordinate].color;
			buildings[coordinate].is_checked = false;
		}
	}

	// 囲まれている白マスを調べる
	// -> color を囲まれていたら 1, 囲まれていなかったら -1 に変える
	// isInside の再帰呼び出しの際に一時的に調べたマスをメモしておく
	// -> 囲まれていなかったらまとめて color を -1 にする
	int *memo = new int[W*H];	
	for(int y=1; y<=H; y++){
		for(int x=1; x<=W; x++){
			int index = 0;	// メモの引数
			if(!isInside(buildings, &index, memo, x, y, W)){
				for(int i=0; i<index; i++) buildings[memo[i]].color = -1;
			}
		}
	}

	// 壁面の長さを求める
	int answer = 0;
	for(int y=1; y<=H; y++){
		for(int x=1; x<=W; x++){
			// 建物がある場合は隣接を調べる
			if(buildings[xy(x, y, W)].color == 1){

			// -> 隣接の color が -1 なら長さ +1
				const int xlo = xLeftOblique(x, y);
				const int xro = xRightOblique(x, y);

				// 同じような文を6つ書くのでマクロ関数使う
				#define ADD_ANSWER(X, Y) if(buildings[xy(X, Y, W)].color == -1) answer++
				ADD_ANSWER(xlo, y-1);	//左上
				ADD_ANSWER(xro, y-1);	//右上
				ADD_ANSWER(x-1, y  );	//左
				ADD_ANSWER(x+1, y  );	//右
				ADD_ANSWER(xlo, y+1);	//左下
				ADD_ANSWER(xro, y+1);	//右下
				#undef ADD_ANSWER
			}
		}
	}

	cout << answer << endl;

	delete[] buildings;
	delete[] memo;
	return 0;
}

Measured memory_bytes: 1784
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdio>
#include <climits>
#include <set>
#include <map>
using namespace std;

typedef long long ll;



int main()
{
    ll n;
    cin >> n;
    int y = sqrt(n);
    ll ans = 1e13;

    for(int i = 1; i <= y; i++)
    {
        if((n % i) == 0)
        {
            ll x = n / i;
            ll wa = i + x - 2;
            ans = min(ans, wa);
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var n=Arr.shift()-0;
   if(n==0)break;
   var arr=(Arr.shift()).split(" ").map(Number);
   var ball=32;
   var i=0;
   while(true){
      ball-=(ball-1)%5;
      console.log(ball);
      if(ball==1){console.log(0);break;}
      ball-=arr[i%n];
      i++;
      console.log(ball);
   }
}

Measured memory_bytes: 10052
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		boolean[][] cards = new boolean[4][13];
		for(int i = 0; i < n; i++){
			int m = getMark(scan.next().charAt(0));
			int num = scan.nextInt() - 1;
			cards[m][num] = true;
		}
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 13; j++){
				if(!cards[i][j]){
					System.out.println(toMark(i) + " " + (j + 1));
				}
			}
		}
	}
	public static int getMark(char c){
		switch(c){
			case 'S' : return 0;
			case 'H' : return 1;
			case 'C' : return 2;
			default : return 3;
		}
	}
	public static String toMark(int c){
		switch(c){
			case 0 : return "S";
			case 1 : return "H";
			case 2 : return "C";
			default : return "D";
		}
	}

}

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

int main(){
  long long N,K,ans = 0;
  cin >> N >> K;
  vector<long long> H(N);
  for(int i = 0;i < N;i++){
    cin >> H[i];
  }
  sort(H.begin(),H.end());
  //でばっぐ
  //for(int i = 0;i <N;i++){
  //  cout << H[i];
  //}
  for(int i = 0;i < N-K;i++){
    ans += H[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
#include <time.h>
#include<stdlib.h>
#include<string.h>

int main(void) {
    long int a, b, c, a2, b2, c2, ans = 0;

    scanf("%ld %ld %ld", &a, &b, &c);

    while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
        if (a == b && b == c) {
            ans = -1;
            break;
        }
        a2 = a / 2;
        b2 = b / 2;
        c2 = c / 2;
        a = b2 + c2;
        b = a2 + c2;
        c = a2 + b2;
        ans++;
    }
    printf("%ld", ans);
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N; cin >> N;
  vector<int> MY(N);
  for(int i=0;i<N;i++){
    cin >> MY.at(i);
  }
  sort(MY.begin(), MY.end());
  if(MY.at(N/2-1)==MY.at(N/2)){
    cout << 0 << endl;
    return 0;
  }
  else cout << MY.at(N/2)-MY.at(N/2-1) << endl;
}
    

Measured memory_bytes: 640