akhauriyash/Code-Regression huggingface dataset:
import           Control.Monad
import qualified Data.Array.IO         as IO
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  [n, k] <- getIntList
  [r, s, p] <- getIntList
  t <- BS.getLine

  dp <- IO.newArray ((0,0),(n-1,2)) 0 :: IO (IO.IOUArray (Int, Int) Int)

  forM_ [0..(n-1)] $ \i ->
    if (i < k)
    then case BS.index t i of
           'r' -> IO.writeArray dp (i, 2) p
           's' -> IO.writeArray dp (i, 0) r
           'p' -> IO.writeArray dp (i, 1) s
    else do
      let (u, v, w) = case BS.index t i of
            'r' -> (0, 0, p)
            's' -> (r, 0, 0)
            'p' -> (0, s, 0)
      prev0 <- IO.readArray dp (i-k, 0)
      prev1 <- IO.readArray dp (i-k, 1)
      prev2 <- IO.readArray dp (i-k, 2)
      IO.writeArray dp (i, 0) (u + max prev1 prev2)
      IO.writeArray dp (i, 1) (v + max prev2 prev0)
      IO.writeArray dp (i, 2) (w + max prev0 prev1)

  let solve :: Int -> Int -> IO Int
      solve i res | i == k = return res
                  | otherwise = do x <- IO.readArray dp (n-1-i, 0)
                                   y <- IO.readArray dp (n-1-i, 1)
                                   z <- IO.readArray dp (n-1-i, 2)
                                   solve (i+1) ((max (max x y) z) + res)
  ans <- solve 0 0
  print ans

Measured memory_bytes: 11900
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string.h>
#include <cstring>
#include <math.h>
#include <cmath>
#include <iomanip>
#include <set>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <cassert>

using namespace std;
using ll = long long;

#define nl "\n"
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trav(x) for(auto& i: x)

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

	ll a;
	long double b;
	cin >> a >> b;
	ll c = a * b;
	cout << c;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  for(int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if(S == "Y") {
      cout << "Four" << endl;
      break;
    }
    else if (S != "Y" && i == N-1) {
      cout << "Three" << endl; 
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX	1000000
int main()
{
	int e;
	for (; cin >> e, e != 0;)
	{
		int m_min = MAX , y, z;
		for (y = 0; y <= 1000; y++)
		{
			for (z = 0; z <= 100; z++)
			{
				int x;
				x = e - y*y - z*z*z;
				if (x < 0)continue;
				if (m_min > x+y+z)m_min = x+y+z;
			}
		}
		cout << m_min << endl;
	}
	return 0;
}

Measured memory_bytes: 3068
#!/usr/bin/env ruby
n = STDIN.readline.strip.to_i
t, a = STDIN.readline.strip.split(' ').map(&:to_i)
h = STDIN.readline.strip.split(' ').map(&:to_i)
diff = h.map{|hi| ((t - hi * 0.006) - a).abs}
puts diff.each_with_index.min[1]+1


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
typedef pair<ll, ll> LP;
 
ll POW(ll m,ll n)
{
  if(n<0) return 0;
  if(n==0) return 1;
  return m*POW(m,n-1)%MOD;
}

ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}

ll CON(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return m*CON(m-1,n)/(m-n);
}
 
int main()
{
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  printf("%lld %lld %lld %lld",c+b-d,d+c-a,a+b-d,b+c-a);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll N,M,L,O,P,Q,R;
string S;

int main(){
    cin>>S;
    if(S[0]==S[1]&&S[2]==S[3]&&S[0]!=S[2]){
        cout<<"Yes"<<endl;
    }
    else if(S[0]==S[2]&&S[1]==S[3]&&S[0]!=S[1]){
        cout<<"Yes"<<endl;
    }
    else if(S[0]==S[3]&&S[1]==S[2]&&S[0]!=S[1]){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}

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

#define MAX 100002

char buf[MAX];
string s;
int main() {
	scanf("%s", buf);
	s = buf;
	int lef = 0;
	int rig = s.size() - 1;
	int ans = 0;
	while (lef <= rig) {
		if (s[lef] == s[rig]) {
			lef++;
			rig--;
			continue;
		}
		if (s[lef] == 'x') {
			lef++;
			ans++;
			continue;
		}
		if (s[rig] == 'x') {
			rig--;
			ans++;
			continue;
		}
		puts("-1");
		return 0;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	int W,H,x,y,r;
	cin >> W>>H>>x>>y>>r;
	if(r<=x&&x<=(W-r)&&r<=y&&y<=(H-r)){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

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

void fnInput(vector<int>& rvnSort)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  rvnSort.resize(nMaxSiz);
  for (int i = 0; i < nMaxSiz; i++)
    cin >> rvnSort[i];
} 

void fnTrace(const vector<int>& cnrvnSort)
{
  for (int i = 0; i < cnrvnSort.size(); i++)
  {
    if (i) cout << " ";
    cout << cnrvnSort[i];
  }
  cout << endl;
}

void fnInsertionSort(vector<int>& rvnSort)
{
  for (int nSorting = 1; nSorting < rvnSort.size(); nSorting++)
  {
    int nTrg = rvnSort[nSorting];
    int nSorted = nSorting - 1;

    while (nSorted >= 0          &&
           nTrg  < rvnSort[nSorted])
    {
      rvnSort[nSorted + 1] = rvnSort[nSorted];
      nSorted--;
    }
    rvnSort[nSorted + 1] = nTrg;
    fnTrace(rvnSort);
  }
}

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

  vector<int> vnSort;

  fnInput(vnSort);
  fnTrace(vnSort);
  fnInsertionSort(vnSort);

  return 0;
}

Measured memory_bytes: 3144
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = sc.next().split("");
        String[] t = sc.next().split("");

        int count = 0;
        for (int i = 0; i < s.length; i++) {
            if (!s[i].equals(t[i])) count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 57196
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD = 1e9+7;

int fast_power(int base, int power) {
    int result = 1;
    while(power > 0) {

        if(power&1) {
            result = (result*base) % MOD;
        }
        base = (base * base) % MOD;
        power = power / 2;
    }
    return result;
}

int find(int y, int k, int prev){
	int x = prev;
	while(y*fast_power(2,x)<k)	x++;
	return x;
}

int main(){
	int n,k;
	cin>>n>>k;
	int a[n+1] = {0};
	//a[i] gives x+1 for outcome i from die
	for(int y=1;y<=n;y++){
		a[y] = find(y,k,a[y-1]-1);
	}
	double ans = 0;
	if(n>=k)	ans += (n-k+1);	//for i>=k && i<=n
	for(int i=1;i<=n && i<k;i++){
		ans += 1/(double)fast_power(2,a[i]);
	}
	ans /= n;
	cout<<fixed<<setprecision(12)<<ans<<endl;
	return 0;
}

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

#define rep(i,k,n) for(int (i)=(k);(i)<(n);(i)++)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) ((a)>0 ?(a):-(a))
#define llong long long

int cmp_int(const void *a,const void *b){
	int *a0=(int*)a,*b0=(int*)b;
	return *b0-*a0;
}

int main(){
  int N; scanf("%d",&N);
  int A[N];
  rep(i,0,N) scanf("%d",&A[i]);
  qsort(A,N,sizeof(int),cmp_int);
  int p[1000001]={0};
  rep(i,0,N){
  	if( p[A[i]]==0 ){
  		if( i!=0 && A[i-1]==A[i] ) p[A[i]]=1;
  		int j=A[i]*2;
  		while(j<1000001){
  			p[j]=1;
  			j+=A[i];
  		}
  	}
  }
  int cnt=0;
  rep(i,0,N){
  	if( p[A[i]]==0 ) cnt++;
  }
  printf("%d",cnt);
  return 0;
}


Measured memory_bytes: 6384
i = gets.chomp.split(' ').map(&:to_i)
result = []

for p in 0..(i.length-1)
  for q in (p+1)..(i.length-1)
    result << (i[p]-i[q]).abs
  end
end

result.sort!{ |i, j| i <=> j }.reverse!
puts result[0]

Measured memory_bytes: 1788
n   = gets.chomp.to_i
ary = gets.split(" ").map(&:to_i)
i   = 1

puts ary.join(" ")

while i < n
  v = ary[i]
  j = i - 1
  while j >= 0 && ary[j] > v
    ary[j + 1] = ary[j]
    j          -= 1
  end
  ary[j + 1] = v
  puts ary.join(" ")
  i += 1
end

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

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

	for (int i = 0; i < N; i++) {
		b.at(a.at(i) - 1) = i + 1;
	}

	for (int i = 0; i < N; i++) {
		cout << b.at(i) << " ";
	}

}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define int long long int
#define mod 998244353 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output1.txt","w", stdout);
    #endif
    int n,x,t;
    cin>>n>>x>>t;
    if (n%x==0)
    {
        cout<<(n/x)*t;
    }
    else
    {
        cout<<(n/x)*(t)+t;
    }
    #ifndef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}       

Measured memory_bytes: 3760
import java.io.PrintWriter
import java.lang.Math.*
import java.util.*

val pw = PrintWriter(System.out)
val sc = Scanner(System.`in`)


fun main(args: Array<String>) {
    val (a, b) = nextListOfInt()
    println(a * b)
}

fun abc000a() {
}


fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextListOfString() = next().split(" ")
fun nextListOfInt() = nextListOfString().map { it.toInt() }
fun nextListOfLong() = nextListOfString().map { it.toLong() }
fun nextListOfDouble() = nextListOfString().map { it.toDouble() }

Measured memory_bytes: 38664
#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<iostream>
#define pb push_back
#define fi first
#define se second
#define sz(x)  x.size()
#define cl(x)  x.clear()
#define all(x)  x.begin() , x.end()
#define r(x)  scanf("%d", &x)
#define rr(x , y)  scanf("%d%d" , &x , &y)
#define rst(s)  scanf("%s" , s)
#define rl(x)  scanf("%lld" , &x)
#define rrl(x , y)  scanf("%lld%lld" , &x , &y)
#define w(x)  printf("%d" , x)
#define ww(x , y)  printf("%d %d" , x , y)
#define wl(x)  printf("%lld" , x)
#define wwl(x , y)  printf("%lld %lld" , x , y)
#define sp()  printf(" ")
#define en()  puts("")
#define rep(i , x , n)  for(int i = x ; i <= n ; i ++) 
#define per(i , n , x)  for(int i = n ; i >= x ; i --) 
#define mem0(x)  memset(x , 0 , sizeof(x))
#define mem_1(x)  memset(x , -1 , sizeof(x))
#define mem_inf(x)  memset(x , inf , sizeof(x))
#define mem__inf(x)  memset(x , -inf , sizeof(x))
#define p_queue priority_queue
#define debug(x)  cout << x << '\n'
#define ddebug(x , y)  cout << x << ' ' << y << '\n'
using namespace std ;
//mt19937  rnd(chrono::high_resolution_clock::now().time_since_epoch().count()) ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair<int , int> pii ;
typedef pair<ll , ll> pll ;
typedef pair<int , ll> pil ;
typedef pair<ll , int> pli ;
const int inf = 0x3f3f3f3f ;
const int maxn = 2005 ;
const int maxm = 30 ;
const ll mod = 1e9 + 7 ;
int n ;
ll dp[maxn][maxn] ;
struct node
{
	int num , x ;
	bool operator < (const node &s) const
	{
		if(num != s.num)  return num > s.num ;
		else  return x < s.x ; 
	}
} a[maxn] ;
int main()
{
	ll ans = 0 ;
	r(n) ;
	rep(i , 1 , n)  r(a[i].num) , a[i].x = i ;
	sort(a + 1 , a + n + 1) ;
	mem0(dp) ;
	rep(i , 0 , n - 1)
	  rep(j , 0 , i)
	  {
	  	int k = i - j ;
	  	int l = j , r = n - k + 1 ;
	  	int num = a[i + 1].num ;
	  	int x = a[i + 1].x ;
	  	dp[l + 1][r] = max(dp[l + 1][r] , dp[l][r] + (ll)num * abs(x - (l + 1))) ;
	  	dp[l][r - 1] = max(dp[l][r - 1] , dp[l][r] + (ll)num * abs(x - (r - 1))) ;
	  }
	rep(i , 0 , n)  ans = max(ans , dp[i][i + 1]) ;
	wl(ans) , en() ;
	return 0 ;
}

Measured memory_bytes: 35244
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

typedef double P_type; //座標(integer or real)
typedef double G_real; //実数の戻り値(float or double or long double)
typedef complex<P_type> P;
const G_real P_eps = 1e-8; //整数の時はゼロ

namespace std{
  template<class T> bool operator<(const complex<T> &a, const complex<T> &b){
    return abs(a.real() - b.real()) < P_eps ? a.imag() + P_eps < b.imag() : a.real() + P_eps < b.real();
  }
};

P rotate(P p, double theta){
  return p * P(cos(theta), sin(theta));
}

//内積
P_type dot(P a, P b) {
  return (a * conj(b)).real();
}

//外積
P_type cross(P a, P b) {
  return (conj(a) * b).imag();
}

//反時計回り
int ccw(P a, P b, P c){
  if(cross(b-a, c-a) > P_eps) return 1; //COUNTER_CLOCKWISE(center:a)
  if(cross(b-a, c-a) < -P_eps) return -1; //CLOCKWISE(center:a)
  if(dot(b-a, c-a) < -P_eps) return -2; //c -> a -> b
  if(dot(a-b, c-b) < -P_eps) return 2; //a -> b -> c
  return 0; //a -> c -> b
}

// a -> b -> c
P_type degree(P a, P b, P c) {
  c = c - b;
  a = b - a;
  return atan2(cross(c, a), dot(c, a)) / M_PI * 180;
}

int main(){
  int N, x[8], y[8];
  P points[11];

  cin >> N;

  for(int i=0; i<N; i++) {
    cin >> x[i] >> y[i];
    points[i+1] = P(x[i], y[i]);
  }

  int p[N+3];
  iota(p, p+N+3, 0);
  points[0] = P(0, 0);
  points[N+1] = P(0, 0);
  points[N+2] = P(-1, 0);

  double ans = 1e18;

  do{
    double sum = 0;

    for(int i=N+1; i>=1; i--) {
      sum += abs(degree(points[p[i+1]], points[p[i]], points[p[i-1]]));
    }

    ans = min(ans, sum);

  }while(next_permutation(p+1, p+N+1));

  printf("%.10lf\n", ans);

  return 0;
}



Measured memory_bytes: 3472
n=int(input())
l = list(map(int, input().split()))
m=sum(l)
ans=[]
for i in range(n):
    ans.append(l[i])
    if(sum(ans)>=(m/2)):
        ans3=min( abs(m-(2*sum(ans)) ) ,abs(m-2*sum(ans)+(2*l[i])) )
        break
    

print(ans3)

Measured memory_bytes: 3188
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));
//left + 1 < top

using namespace std;
using P = pair<long long, long long>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.141592653589793;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

//////////////////////////////////

vector<vector<int>> tree(100005);
int color[100005];
map<P, int>colorMap;
int m = 0;

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

struct People {
	int index;
	int town;
	int year;
	People(int i, int t, int y) {
		index = i;
		town = t;
		year = y;
	}
};

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

struct UnionFind {
	vector<int>uf;
	
	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i-1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

void dfs(int from) {
	int c = 1;
	for (auto t : tree[from]) {
		c = c != color[from] ? c : c + 1;
		color[t] = c;
		colorMap[make_pair(from, t)] = c;
		m = max(c, m);
		dfs(t);
		c++;
	}
}

int cnt;
int target;
void calc(int c) {
	cnt -= (target / c);
	target %= c;
}

int main() {
	int a1, a2, a3;
	cin >> a1 >> a2 >> a3;
	int sum = a1 + a2 + a3;
	string ans = 22 <= sum ? "bust" : "win";
	cout << ans << endl;
}

Measured memory_bytes: 3192
// inputに入力データ全体が入る

function Main(input) {
    input = input.split("\n")
    N = input[0]
    inputA = input[1].split('\r')[0].split(' ')
    inputB = input[2].split('\r')[0].split(' ')
    inputC = input[3].split('\r')[0].split(' ')
    var count = 0

    for(var i=0; i < N;i++){
//        console.log( " inputB[ inputA[i] - 1 ]:::" ,  inputB[ inputA[i] - 1 ]  )
        count += parseInt( inputB[ inputA[i] - 1 ] );
        if( i > 0   ){
         //   console.log( inputA[i-1]  ,inputA[i]  )

            if( inputA[i-1] == inputA[i] -1  ){
                count += parseInt( inputC[  inputA[i-1] -1  ])
//console.log("inputC[i-1]:::",inputC[  inputA[i-1] -1   ])
            }
        }
    }
    console.log(count)
}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）

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


Measured memory_bytes: 7372
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto s = readln.chomp;
  int cnt;
  foreach (i; 0..s.length/2) {
    if (s[i] != s[$-i-1]) {
      cnt++;
    }
  }
  cnt.writeln;
}


Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}]

int main(){
	ll n,a ;
	cin >> n >> a ;
	if(a==1||a==n*2-1) cout << "No\n" ;
	else {
		cout << "Yes\n" ;
		for(int i=1;i<=2*n-1;i++){
			if(i==n-1) cout << a-1 << endl ;
			if(i==n) cout << a << endl ;
			if(i==n+1) cout << a+1 << endl ;
			if(i<n-1) cout << i+3*(i>=a-1) << endl ;
			if(i>n+1) cout << i-3*(i<=a+1) << endl ;
		}
	}
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mx 4000007
#define mod 1000000007
ll dx[8]={1,1,0,-1,-1,-1,0,1};
ll dy[8]={0,1,1,1,0,-1,-1,-1};
int main()
{
    ll i,j,k,l,n,m,c;
    string s[100];
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        cin>>s[i];
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(s[i][j]=='.')
            {
                c=0;
                for(k=0;k<8;k++)
                {
                    ll adjx=i+dx[k];
                    ll adjy=j+dy[k];
                    if(adjx>=0&&adjx<n&&adjy>=0&&adjy<m&&s[adjx][adjy]=='#')
                    {
                        c++;
                    }
                }
                s[i][j]=c+'0';
            }
        }
    }
    for(i=0;i<n;i++)
    {
        cout<<s[i]<<endl;
    }
    return 0;
}


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

using namespace std;

#define FAST_IO ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
typedef long long ll;

int dp[3007][3007];
 
int main(){ 
	
	FAST_IO;
   
	string s,t;
	cin>>s>>t;
	int n = s.length();
	int m = t.length();

	for(int i=0; i<=n; i++){
		for(int j=0; j<=m; j++){
			if(i==0 || j==0)
				dp[i][j] = 0;
			else if(s[i-1]==t[j-1]){
				dp[i][j] = dp[i-1][j-1] + 1;
			}
			else{
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}

	/*
	for(int i=0; i<=n; i++){
		for(int j=0; j<=m; j++){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}
	*/

	int i = n; int j = m;

	string ans;

	while(i>0 && j>0){
		if(s[i-1]==t[j-1]){
			ans += s[i-1];
			i--;
			j--;
		}
		else if(dp[i-1][j]>dp[i][j-1])
			i--;
		else
			j--;
	}

	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
}
 

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100000
#define rint register int
inline int read(){int r;int s=0,c;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;}
int fa[MAXN+5], p[MAXN+5], n, m, Ans; inline int getf(int x){return x^fa[x]?fa[x]=getf(fa[x]):x;} inline void Union(int x, int y){(x=getf(x))^(y=getf(y))?fa[x]=y:0;}
unordered_set<int> G[MAXN+5];
int main()
{
	n = read(), m = read(); for(rint i = 1; i <= n; fa[i] = i, p[i] = read(), i++); for(rint i = 1; i <= m; Union(read(),read()), i++);
	for(rint i = 1; i <= n; G[getf(i)].insert(i), i++); for(rint i = 1; i <= n; Ans += G[getf(i)].count(p[i]), i++); printf("%d\n",Ans); return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const long long MOD = 1e9 + 7;

int main() {
    int N, a = 15;
    rep(i, 5) {
        cin >> N;
        a -= N;
    }
    cout << a << endl;
}

Measured memory_bytes: 3632
import queue
k = int(input())

q = queue.Queue()
for i in range(1, 10):
    q.put(i)

for i in range(k):
    x = q.get()
    if (x % 10) > 0:
        q.put((10 * x) + (x % 10) - 1)
    q.put(10 * x + (x % 10))
    if (x % 10) < 9:
        q.put((10 * x) + (x % 10) + 1)
print(x)

Measured memory_bytes: 12452
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back
#define fi first
#define be begin()
#define en end()
#define se second

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int N,A;
  cin>>N>>A;
  cout << N*N-A << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    int n,q;
    cin >> n >> q;
    vector<ll>a(n);
    rep(i,n) cin >> a[i];
    rep(i,q) {
        ll x;
        cin >> x;
        int right = 0;
        ll sum = 0;
        ll res = 0;
        rep(left,n) {
            while(right<n && sum+a[right]<=x) {
                sum += a[right];
                right++;
            }
            res += right-left;
            if(left==right) right++;
            else sum -= a[left];
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> p(n), c(n), g(n);
    vector<ll> d[n];
    rep(i, n)
    {
        cin >> p[i];
        p[i]--;
    }
    rep(i, n)
    {
        cin >> c[i];
    }

    rep(i, n)
    {
        g[i] = c[p[i]];
    }

    rep(i, n)
    {

        d[i].push_back(i);
        ll j = i;
        while (i != p[j])
        {
            d[i].push_back(p[j]);
            j = p[j];
        }
    }
    ll ans = -1000000000000000000;
    rep(i, n)
    {

        ll tot = 0;
        ll now = 0;
        rep(j, d[i].size())
        {
            tot += g[d[i][j]];
        }
        rep(j, min(k, (ll)d[i].size()))
        {
            now += g[d[i][j]];
            ll co = now;
            if (tot > 0)
            {
                co += (k - j - 1) / (ll)d[i].size() * tot;
            }
            ans = max(ans, co);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 219072
from bisect import bisect_left


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


def is_similar(n):
    pos = bisect_left(p, n)
    if pos < len(p) and p[pos] == n:
        return True
    else:
        return False


q = int(input())

p = primes(10 ** 5)
l = [0] * 10 ** 5
for i in range(3, 10 ** 5, 2):
    if is_similar(i) and is_similar((i+1)//2):
        l[i] += 1

sum_l = [0]
for v in l[1:]:
    sum_l.append(sum_l[-1] + v)

res = []
for _ in range(q):
    l, r = map(int, input().split())
    res.append(sum_l[r] - sum_l[l-1])

for v in res:
    print(v)

Measured memory_bytes: 83660
import math

q = int(input())
for i in range(q):
    a,b = map(int,input().split())
    x = min(a,b)
    y = max(a,b)
    
    if x <= y <= x+1:
        print((x-1)*2)
    else:
        xy = math.ceil((x*y)**0.5)
        l = xy
        r = xy
        if l*r < x*y:
            print((r-1)*2)
            continue
        r -= 1
        if l*r < x*y:
            print(r*2-1)
            continue
            
        print((r-1)*2)

Measured memory_bytes: 3188
/*****/

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

//#define int long long

using namespace std;
using ll = long long;
using ld = long double;
using vecll = vector<ll>;

#define nextline() (std::cerr << "\n")
#define debug(x) (#x " : " + (x))
#define debug_cout(x) (std::cerr << #x << " : " <<  (x) << "\n")
#define debug_tabcout(n, x) (std::cerr << strMulti("\t",n) << #x << " : " <<  (x) << "\n")
#define debug_headcout(h, x) (std::cerr << h << " : " <<  (x) << "\n")
#define debug_tabheadcout(n, h, x) (std::cerr << strMulti("\t",n) << h << " : " <<  (x) << "\n")

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<=i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b);
constexpr int INF = 2000000100;
constexpr ll DIV = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> T divup(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
std::string strMulti(std::string t, int n) { std::string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }
template<class T> T math_P(T m, T n) { T ret = 1; for (T i = m; i > m - n; i--) { ret *= i; } return ret; }
template<class T> T math_C(T m, T n) { T ret = mathP(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }
template<class T> bool compare_by_b(pair<T, T> a, pair<T, T> b) { if (a.second != b.second) { return a.second < b.second; } return a.first < b.first; }
template<class T> T math_gcd(T a, T b) { a = abs(a); b = abs(b); if (a < b) { std::swap(a, b); } T tmp; while (b != 0) { tmp = b; b = a % b; a = tmp; } return a; }
template<class T> T math_lcm(T a, T b) { a = abs(a); b = abs(b); if (a > b) { std::swap(a, b); } if (a == 1) { return b; } T i = a; while (i % b != 0) { i += a; } return i; }

/*****/

void Main()
{
	int n;
	cin >> n;

	if (n == 1)
		cout << 0;
	else if (n == 2)
		cout << 1;
	else
		cout << (divup(n, 2) - 1);
}

/*****/

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

	//std::cout << std::fixed << std::setprecision(10);


	/*
	while (true)
	{
		Main();
		cout << endl;
	}
	//*/


	Main();

	return 0;
}


Measured memory_bytes: 256
D = int(input())
C = list(map(int, input().split()))
S = [tuple(map(int, input().split())) for _ in range(D)]
Z = 26

last = [-1] * Z
ans = 0
T = []
for d in range(D):
    maxScore = 0
    cand = 0
    for i in range(26):
        tmp = last[i]
        last[i] = d
        up = S[d][i]
        down = sum(C[j] * (d - last[j]) for j in range(Z))
        score = up - down
        if maxScore < score:
            cand = i
            maxScore = score
        last[i] = tmp
    T.append(cand + 1)
print(*T, sep='\n')


Measured memory_bytes: 74600
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
int field[10][5]={};
int sum=0;
void game(int h){
	int newfield[11][5]={};
	for(int y=0;y<h;y++){
		newfield[y][0]=field[y][0];
		newfield[y][4]=field[y][4];
		for(int x=1;x<4;x++){
			if(field[y][x-1]==field[y][x]&&field[y][x+1]==field[y][x]){
				newfield[y][x-1]-=1000;
				newfield[y][x]-=1000;
				newfield[y][x+1]-=1000;
			}
			else{
				newfield[y][x]+=field[y][x];
			}
		}
		for(int i=0;i<5;i++){
			if(newfield[y][i]<0)	newfield[y][i]=0;
		}
	}
	for(int i=0;i<h;i++){
		for(int y=h-1;y>=0;y--){
			for(int x=0;x<5;x++){
				if(newfield[y][x]==0){
					for(int Y=y;Y>=0;Y--)
						if(Y==0)	newfield[Y][x]=0;
						else{
							newfield[Y][x]=newfield[Y-1][x];
						}
				}
			}
		}
	}
	//cout << endl;
	for(int y=0;y<h;y++){
		//cout << endl;
		for(int x=0;x<5;x++){
			field[y][x] = newfield[y][x];
			//cout << field[y][x] << ' ';
		}
	}
}
int main(void){
	while(1){
		int H,sum=0,sum2=0;
		cin >> H;
		if(!H)	break;
		for(int y=0;y<H;y++){
			for(int x=0;x<5;x++){
				cin >> field[y][x];
				sum+=field[y][x];
			}
		}
		for(int i=0;i<H;i++)	game(H);
		for(int i=0;i<H;i++){
			for(int j=0;j<5;j++)	sum2+=field[i][j];
		}
		cout << sum-sum2 << endl;
	}
	return 0;
}


Measured memory_bytes: 3060
using System;
using System.Linq;

public class HelloWorld
{
    static public void Main ()
    {
        var S = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var ans = 0L;
        if(S[0] < S[1]){
            ans += S[1];
            S[1]--;
        }else{
            ans += S[0];
            S[0]--;
        }
        
        if(S[0] < S[1]){
            ans += S[1];
            S[1]--;
        }else{
            ans += S[0];
            S[0]--;
        }
        
        Console.WriteLine (ans);
    }

}


Measured memory_bytes: 11348
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();

        long[] aa = sc.LongArray();
        long[] bb = sc.LongArray();

        long countA = 0;
        long countB = 0;

        for (int i = 0; i < n; i++)
        {
            long a = aa[i];
            long b = bb[i];
            if (a > b)
            {
                countB += a - b;
            }
            else if (b > a)
            {
                if ((b - a) % 2 == 0)
                {
                    countA += b - a;
                }
                else
                {
                    countA += b - a + 1;
                    countB++;
                }
            }
        }

        string answer = countA >= 2 * countB ? "Yes" : "No";

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 30464
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	var num int
	ans := false
	d1 := make([]int, n)
	d2 := make([]int, n)
	for i := range d1 {
		fmt.Scan(&d1[i], &d2[i])
		if d1[i] == d2[i] {
			num++
		}else{
			num = 0
		}
		if num >= 3 {
			ans = true
		}
	}
	if ans == true {
		fmt.Println("Yes")
	}else{
		fmt.Println("No")
	}
}


Measured memory_bytes: 1768
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, 0, n) {
        cin >> a[i];
    }
    vector<int> used(100, 0);
    sort(a.begin(), a.end());
    int Min = 2 * n;
    REP(i, 0, a[n - 1] + 1) {
        used[max(a[n - 1] - i, i)]++;
        chmin(Min, max(a[n - 1] - i, i));
    }
    if (a[0] < Min) {
        cout << "Impossible" << endl;
        return 0;
    }
    REP(i, 0, n) {
        used[a[i]]--;
    }
    if (used[Min] != 0) {
        cout << "Impossible" << endl;
        return 0;
    }
    REP(i, 0, 100) {
        if (used[i] > 0) {
            cout << "Impossible" << endl;
            return 0;
        }
    }
    cout << "Possible" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)
 
inline ll ii(){ ll x; cin >> x; return x; }
inline string is(){ string x; cin >> x; return x; }
inline ld id(){ ld x; cin >> x; return x; }
inline void oi(ll x){ cout << x; }
inline void od(ld x){ cout << fixed << setprecision(10) << x; }
inline void os(string x){ cout << x; }
inline void oe(){ cout << endl; }
inline void oie(ll x){ oi(x); oe(); }
inline void ode(ld x){ od(x); oe(); }
inline void ose(string x){ os(x); oe(); }
inline void maxin(ll &a, ll b){ a=max(a,b); }

ll m[1234][1234];
ll t[1234][1234];

int main(){
    ll H=ii(), W=ii();
    ll CH=ii()-1, CW=ii()-1;
    ll DH=ii()-1, DW=ii()-1;
    REP(y,0,H){
        string S=is();
        REP(x,0,W){
            if(S[x]=='#'){
                m[x][y]=0;
            }else{
                m[x][y]=1;
            }
            t[x][y]=LLONG_MAX;
        }
    }

    if(CH==DH&&CW==DW){
        oie(0);
        return 0;
    }

    deque<pii> q;
    q.push_front(make_pair(CW,CH));
    t[CW][CH]=0;
    while(!q.empty()){
        ll cx=q.front().first;
        ll cy=q.front().second;
        q.pop_front();
        for(ll x = max((ll)0,cx-2); x<=cx+2;x++){
            for(ll y = max((ll)0,cy-2); y<=cy+2;y++){
                ll cc=t[cx][cy];
                bool prit;

                if(abs(cx-x)==1&&abs(cy-y)==0){
                    prit=true;
                }else if(abs(cx-x)==0&&abs(cy-y)==1){
                    prit=true;
                }else if(cx==x&&cy==y){
                    continue;
                }else{
                    prit=false;
                    cc++;
                }

                if(m[x][y]==1){
                    if(cc < t[x][y]){
                        t[x][y]=cc;
                        if(prit){
                            q.push_front(make_pair(x,y));
                        }else{
                            q.push_back(make_pair(x,y));
                        }
                    }
                }
            }
        }
    }

    if(t[DW][DH]<LLONG_MAX){
        oie(t[DW][DH]);
        return 0;
    }

    oie(-1);
    return 0;
}

Measured memory_bytes: 23036
import java.util.*;
 
public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in); 

        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] x = new int[N];
        for(int i = 0; i < N; i++){
            x[i] = sc.nextInt();
        }
        sc.close();
        int min = Integer.MAX_VALUE;
        for(int i = 0; i <= N-K; i++){
            min = Math.min(min, Math.abs(x[i+K-1] - x[i])+Math.min(Math.abs(x[i+K-1]), Math.abs(x[i])));
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 50692
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define PI 3.14159265359

const int mod = 1e9 + 7;

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int K;
  cin >> K;

  vector<int> candidate;

  rep(i, 9) candidate.push_back(i+1);


  while(1){
    if(K <= candidate.size()){
      cout << candidate[K-1] << endl;
      return 0;
    }

    K -= candidate.size();

    vector<int> old;

    swap(old, candidate);

    for(int tmp: old){
      for(int d=-1; d<=1; d++){
        int next_digit = tmp % 10 + d;
        if(next_digit < 0 || 9 < next_digit) continue;

        int next = tmp * 10 + next_digit;
        candidate.push_back(next);
      }
    }
  }

  return 0;
}


Measured memory_bytes: 1712
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")

using namespace std;
using namespace __gnu_pbds;

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifdef HOME
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;
typedef complex < double > com;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 5, M = 1e3 + 5, LG = 20;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1 / db(1e6);
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

void test() {
    ll n;
    cin >> n;
    ll ans = LINF;
    for (ll i = 1; i <= sqrt(n); ++i) {
        if (n % i == 0) {
            ans = min(ans, i + n / i - 2);
        }
    }
    cout << ans << "\n";
}

int main() {
    fast_io();
    #ifdef HOME
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    cout << fixed << setprecision(15);
    test();
    #ifdef HOME
        cout << "Time: " << (int)(clock() * 1000. / CLOCKS_PER_SEC) << "ms";
    #endif
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

#define ll long long
#define MAX_N 100005

using namespace std;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  vector<pair<ll, ll>> P(M);
  priority_queue<ll> que;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  for (int i = 0; i < M; i++) {
    cin >> P[i].second >> P[i].first;
  }
  sort(P.begin(), P.end(), greater<pair<ll, ll>>());
  ll count = 0;
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < P[i].second; j++) {
      que.push(P[i].first);
      count++;
      if (count >= N)
        break;
    }
    if (count >= N)
      break;
  }
  for (int i = 0; i < N; i++) {
    que.push(A[i]);
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 4724
open System

// 受け取った番号を配列番号に変換
let toArr (x : int[])= 
    let l = x.Length - 1
    [| for i in 0 .. l -> x.[i] - 1 |]

let mutable  [|N; M|] = stdin.ReadLine().Split(' ') |> Array.map int |> toArr



let mutable parent = [| for i in 0 .. N -> i  |]
let mutable size = [| for i in 0 .. N -> 1 |]

let rec root a = if a = parent.[a] then a else root parent.[a]

let unit a b = 
        let ra = root a
        let rb = root b
        if ra <> rb then 
            if ra < rb then 
                parent.[rb] <- ra
                size.[ra] <- size.[ra] + size.[rb]
                parent.[b] <- ra
            else 
                parent.[ra] <- rb
                size.[rb] <- size.[rb] + size.[ra]
                parent.[a] <- rb

for i in 0 .. M do
    let [|A; B|] = stdin.ReadLine().Split(' ') |> Array.map int |> toArr

    unit A B

let mutable max = 0
for i in 0 .. N do
    max <- if max > size.[i] then max else size.[i]

max |> printf "%d"    

Measured memory_bytes: 47072
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, k;
    cin >> n >> k;

    vector<pair<ll, ll>> p(n);  // p[i] : (おいしさ, ネタの種類)
    rep(i, n) {
        ll t, d;
        cin >> t >> d;
        p[i] = make_pair(d, t);
    }
    sort(rall(p));

    map<ll, ll> mp;
    priority_queue<ll, vector<ll>, greater<ll>> prQ;  // 小さい要素から順に取り出す
    ll sumD = 0;
    rep(i, k) {
        sumD += p[i].first;
        mp[p[i].second]++;
        if(mp[p[i].second] >= 2) {
            prQ.push(p[i].first);
        }
    }
    ll x = mp.size();
    ll ans = sumD + x*x;

    exrep(i, k, n-1) {
        if(prQ.empty()) {
            break;   
        }
        mp[p[i].second]++;
        if(mp[p[i].second] >= 2) {
            mp[p[i].second]--;
            continue;
        }
        sumD += p[i].first - prQ.top();
        prQ.pop();
        x++;
        ll now = sumD + x*x;
        chmax(ans, now);
    }

    out(ans);
    re0;
}

Measured memory_bytes: 6140
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007

int main() {
  int N, D;
  cin >> N >> D;
  int X[N][D] = {};
  rep(i, N) {
    rep(j, D) {
      cin >> X[i][j];
    }
  }
  int ans = 0;
  rep(i, N) {
    for (int j = i + 1; j < N; j++) {
      int dist = 0;
      rep(k, D) dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);

      for (int l = 1; l * l <= dist; l++) {
        if (l * l == dist) {
          ans++;
          break;
        }
      }
    }
  }

  cout << ans << endl;


}


Measured memory_bytes: 256