akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int k = Integer.parseInt(str[1]);

		double ans = 0.0;
		for (int i = 1; i <= n; i++) {
			double d = (double) 1 / n;
			int point = i;
			while (point < k) {
				d *= (double) 1 / 2;
				point *= 2;
			}
			ans += d;
		}

		System.out.println(ans);
	}
}

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

using namespace std;

#define MOD 1000000007
#define N 100005
#define M 102
#define ll long long 
#define ld long double
#define pb push_back
#define ff first
#define ss second

ll dp[M][N];

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ll n, W, i, w, wi, vi;
	cin>>n>>W;
	for(i=0; i<n; i++){
		cin>>wi>>vi;
		if(i == 0){
			for(w=wi; w<=W; w++){
				dp[i][w] = vi;
			}
		}
		else{
			for(w=0; w<=W; w++){
				dp[i][w] = max(dp[i][w], dp[i-1][w]);
				if(w >= wi) dp[i][w] = max(dp[i][w], dp[i-1][w-wi] + vi);
			}
		}
	}
	ll ans = 0;
	for(w=0; w<=W; w++){
		ans = max(ans, dp[n-1][w]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 78336
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int N; cin >> N;
  double cnt = 0;
  for (int i = 1; i <= N; ++i) {
    if (i % 2 == 1) ++cnt;
  }
  printf("%.8f\n", cnt / N);
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1001001001;


int main() {
  ll n,k;
  cin>>n>>k;
  ll cnt=0;
  if (k==0){
    cout<<ll(n*n);
    return 0;
  }
  for(ll i=k+1;i<=n;i++){//bの候補
    ll q=n/i;
    cnt+=q*(i-k);
  //  cout<<i<<'i'<<cnt<<endl;

    if ((q*i+k)<=n)cnt+=n-(q*i+k-1);
  //  cout<<cnt<<endl;
  }

cout<<cnt;
}


Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
B = []
for i in A:
  if i%2 == 0:
    B.append(i)
count = 0
for j in B:
  if j%3 == 0 or j%5 == 0:
    count = count + 1
if count >= len(B):
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 3060
// inputに入力データ全体が入る
function Main(input) {
    var x = input[0]-0;
    var a = input[1]-0;
    var b = input[2]-0;
    
    console.log((x-a)%b)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").split("\n"));

Measured memory_bytes: 7624
#include<iostream>
#include<algorithm>

using namespace std;

int n, m;
int a[20];

bool solve(int i, int sum){
  if(i == n) return false;
  if(sum + a[i] == m) return true;

  return solve(i + 1, sum) || solve(i + 1, sum + a[i]);
}

int main(){

  int q;

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

  cin >> q;
  for(int i = 0;i < q;i++){
    cin >> m;
    if(solve(0, 0)) cout << "yes" << endl;
    else cout << "no" << endl;
  }

  return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double INF = 1e18;
const int inf = 1e9;
double pi = 3.14159265359;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    int n;
    cin >> n;
    ll a[n];
    rep (i, 0, n) {
        cin >> a[i];
        if (a[i] == 0) {
            cout << 0 << "\n";
            return 0;
        }
    }
    ll ans = 1;
    rep (i, 0, n) {
        if (a[i] > 1000000000000000000 / ans) {
            cout << -1 << "\n";
            return 0;
        }
        ans *= a[i];
    }
    cout << ans << "\n";
}


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

int main() {
    int H, W;
    cin >> H >> W;
    vector< vector< char > > field(H, vector< char >(W));
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> field.at(i).at(j);
        }
    }

    vector< vector< int > > path(H, vector< int >(W));
    const int INF = 10e8;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            path.at(i).at(j) = INF;
        }
    }

    queue< pair< int, int > > q;
    q.push(pair< int, int >(0, 0));
    path.at(0).at(0) = 0;
    while (q.size() > 0) {
        pair< int, int > cij = q.front();
        q.pop();
        int ci = cij.first;
        int cj = cij.second;
        vector< int > di = {0, 0, 1, -1};
        vector< int > dj = {1, -1, 0, 0};
        for (int k = 0; k < 4; ++k) {
            int ni = ci + di.at(k);
            int nj = cj + dj.at(k);
            int next = path.at(ci).at(cj) + 1;
            if (ni < 0 || H <= ni || nj < 0 || W <= nj) {
                continue;
            }
            if (field.at(ni).at(nj) == '.' && next < path.at(ni).at(nj)) {
                path.at(ni).at(nj) = next;
                q.push(pair< int, int >(ni, nj));
            }
        }
    }

    int ci = H - 1;
    int cj = W - 1;
    int step = path.at(ci).at(cj);

    if (step == INF) {
        cout << -1 << endl;
        return 0;
    }

    while (step != 0) {
        field.at(ci).at(cj) = 'x';
        vector< int > di = {0, 0, 1, -1};
        vector< int > dj = {1, -1, 0, 0};
        for (int k = 0; k < 4; ++k) {
            int ni = ci + di.at(k);
            int nj = cj + dj.at(k);
            if (ni < 0 || H <= ni || nj < 0 || W <= nj) {
                continue;
            }
            if (path.at(ni).at(nj) == step - 1) {
                ci = ni;
                cj = nj;
                --step;
                break;
            }
        }
    }
    field.at(0).at(0) = 'x';

    int ans = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (field.at(i).at(j) == '.') {
                ++ans;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(s: String, t: String);

    let s_v: Vec<char> = s.chars().collect();
    let t_v: Vec<char> = t.chars().collect();
    let mut count = 0;
    for i in 0..s.len() {
        if s_v[i] == t_v[i] {
            count += 1;
        }
    }
    println!("{}", count);
}


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

int main(){
	//int n = 3;
	int i;
	int n;
	cin >> n;
	for (i = 1; i <= n; i++){
		int x = i;
		if (x % 3 == 0){
			cout << " " << i;
		}
		else {
			while (x) {
				if (x % 10 == 3){
					cout << " " << i;
					break;
				}
				else {
					x /= 10;
				}
			}
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  string a,b;
  cin >> a >> b;
  int c = a.size(),d=b.size();
  if(c==d){
    rep(i,c){
      cout << a.at(i) << b.at(i);
    }
    cout << endl;
  }
  else{
    rep(i,d){
      cout << a.at(i) << b.at(i);
    }
    cout << a.at(c-1) << endl;
  }
}


Measured memory_bytes: 3576
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static int minCost(int stones[]) {
		int cost[] = new int[stones.length];
		cost[0] = 0;
		cost[1] = Math.abs(stones[1] - stones[0]);
		for (int i = 2; i < stones.length; i++) {
			cost[i] = Math.min(Math.abs(stones[i - 1] - stones[i]) + cost[i - 1],
					Math.abs(stones[i] - stones[i - 2]) + cost[i - 2]);
		}
		return cost[stones.length - 1];
	}

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.valueOf(br.readLine());
		int stones[] = new int[n];
		String array[] = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			stones[i] = Integer.valueOf(array[i]);
		}
		System.out.println("" + minCost(stones));

	}

}

Measured memory_bytes: 34188
#include <cstdio>
#include <numeric>
#include <algorithm>

#define REP(i,n) for(int i=0;i<n;i++)

int N;
int L[10];

int main() {
  scanf("%d\n", &N);
  REP(i, N) scanf("%d", &L[i]);

  int max = *std::max_element(L, L+N);
  int sum = std::accumulate(L, L+N, 0);
  if (sum - max > max) printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 128
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
p = [0]*M
S = [0]*M
cnt_penalty = [0]*N
cnt_ac = [0]*N

for i in range(M):
  p[i], S[i] = input().split()
  p[i] = int(p[i])
  
for i in range(M):
  if cnt_ac[p[i]-1] == 0:
    if S[i] == "WA":
      cnt_penalty[p[i]-1] += 1
    elif S[i] == "AC":
      cnt_ac[p[i]-1] = 1
      
for i in range(N):
  if cnt_ac[i] == 0:
    cnt_penalty[i] = 0

print(sum(cnt_ac), sum(cnt_penalty))



Measured memory_bytes: 16956
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;

class primes {
    public:
    vector<int> pr;
    primes(int n) {
        vector<int> t(n+1);
        for (int i=2*2; i <= n; i += 2) {
            t[i] = 2;
        }
        pr.push_back(2);
        for (int j=3; j <= n ; j += 2) {
            if (t[j] == 0) pr.push_back(j);
            for (int i=j*2; i <= n; i += j) {
                t[i] = j;
            }
        }
    }
    vector<int> const& get() { return pr; }
    vector<pair<ll,int>> factor(ll x) {
        vector<pair<ll,int>> fs;
        if (x == 1) {
            fs.push_back({1,1});
            return fs;
        }
        if (x <= 0)
            return fs;
        if (x > (ll)pr.back()*pr.back())
            return fs;
        ll maximum = sqrt(x)+1;
        for (int p : pr) {
            if (p > maximum) {
                if (x != 1)
                    fs.push_back({x,1});
                break;
            }
            int c = 0;
            while (x % p == 0) {
                x /= p;
                ++c;
            }
            if (c)
                fs.push_back({p,c});
            if (x == 1)
                break;
        }
        return fs;
    }
};

int main() {
    ll N;
    cin >> N;
    vector<int> a(N);
    primes p(1e6);
    rep(i,N) cin >> a[i];
    set<int> s;
    bool pw = true;
    rep(i,N) {
        for (auto x : p.factor(a[i])) {
            if (s.count(x.first)) {
                pw = false;
                break;
            }
            if (a[i] != 1)
                s.insert(x.first);
        }
        if (!pw)
            break;
    }
    if (pw) {
        cout << "pairwise coprime" << endl;
        return 0;
    }
    int d = a[0];
    rep(i,N-1) {
        d = gcd(d, a[i+1]);
        if (d == 1)
            break;
    }
    string ans = (d == 1) ? "setwise coprime" : "not coprime";
    cout << ans << endl;
}


Measured memory_bytes: 11644
#include <algorithm>
#include <iostream>

using namespace std;
typedef long long ll;

const int MAX_N = 500'010;

int n, k;
int _rank[MAX_N + 1];
int lcp[MAX_N + 1];
int tmp[MAX_N + 1];

string rotate(string str) {
  return str.substr(1) + str[0];
}

bool compare_sa(int i, int j) {
  if (_rank[i] != _rank[j]) {
    return _rank[i] < _rank[j];
  } else {
    int ri = i + k <= n ? _rank[i + k] : -1;
    int rj = j + k <= n ? _rank[j + k] : -1;

    return ri < rj;
  }
}

void construct_sa(string S, int *sa) {
  n = S.size();

  for (int i = 0; i <= n; ++i) {
    sa[i] = i;
    _rank[i] = i < n ? S[i] : -1;
  }

  for (k = 1; k <= n; k *= 2) {
    sort(sa, sa + n + 1, compare_sa);

    tmp[sa[0]] = 0;
    for (int i = 1; i <= n; ++i) {
      tmp[sa[i]] = tmp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
    }
    for (int i = 0; i <= n; ++i) {
      _rank[i] = tmp[i];
    }
  }
}

bool contain(string S, int *sa, string T) {
  int a = 0;
  int b = S.size();

  while (b - a > 0) {
    int c = (a + b) / 2;

    if (S.compare(sa[c], T.size(), T) < 0) {
      a = c;
    } else {
      b = c;
    }
  }

  return S.compare(sa[b], T.length(), T) == 0;
}

void construct_lcp(string S, int *sa, int *lcp) {
  int n = S.size();
  for (int i = 0; i <= n; ++i) {
    _rank[sa[i]] = i;
  }

  int h = 0;
  lcp[0] = 0;
  for (int i = 0; i < n; ++i) {
    int j = sa[_rank[i] - 1];

    if (h > 0) --h;
    for (; j + h < n && i + h < n; ++h) {
      if (S[j + h] != S[i + h]) break;
    }

    lcp[_rank[i] - 1] = h;
  }
}

int main() {
  string S;
  cin >> S;
  int N = S.size();
  int sa[N + 1];

  construct_sa(S, sa);
  construct_lcp(S, sa, lcp);
  ll ans = 1LL * N * (1 + N) / 2;

  for (int i = 0; i < N; ++i) {
    ll x = lcp[i];
    ans -= x;
  }

  cout << ans << endl;
  return 0;
}


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

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int a,b,c;
    cin>>a>>b>>c;
    set<int> x;
    x.insert(a);x.insert(b);x.insert(c);
    cout<<x.size()<<endl;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")

#define fi first
#define se second

const int N = 100010;

using namespace std;

int C(int n, int k)
{
        if((n & k) == k) return 1;
        return 0;
}

int solve(string s)
{
        int res = 0, n = s.size();
        for(int i = 0; i < n; i++){
                if(s[i] & 1) res ^= C(n - 1, i);
        }
        return res;
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        ios_base::sync_with_stdio(0);

        int n;
        string s;
        cin >> n >> s;
        for(auto &c: s) c -= '1';
        int res = solve(s);
        if(res == 1){
                cout << res << '\n';
                return 0;
        }
        bool shit = false;
        for(int i = 0; i < n; i++){
                if(s[i] == 1) shit = true;
                else if(s[i] == 2) s[i] = 1;
        }
        if(shit) cout << 0 << "\n";
        else cout << 2 * solve(s) << "\n";
}


Measured memory_bytes: 2332
import java.util.Scanner;

 class Main {
	public static void main(String[] a){
		Scanner scan = new Scanner(System.in);

		int[] x, y, z;
		int n = scan.nextInt();;
		x = new int[n];
		y = new int[n];
		z = new int[n];
		
		for(int i = 0; i < n; i++){
			x[i] = scan.nextInt();
			y[i] = scan.nextInt();
			z[i] = scan.nextInt();
		}
		for(int i = 0; i < n; i++){
			if(x[i]*x[i] + y[i]*y[i] == z[i]*z[i] ||
			   x[i]*x[i] + z[i]*z[i] == y[i]*y[i] ||
			   z[i]*z[i] + y[i]*y[i] == x[i]*x[i]) System.out.println("YES");
			else System.out.println("NO");
		}
	}
}

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

int main(){
  string s; cin >> s;
  if(s == "RRR") cout << 3 << endl;
  else if(s == "RRS" || s== "SRR") cout << 2 << endl;
  else if(s == "RSR" || s == "SRS" || s == "SSR" || s == "RSS") cout << 1 << endl;
  else if(s == "SSS") cout << 0 << endl;
  return 0;
}  

Measured memory_bytes: 3624
A,B,C,D = map(int,input().split())

def gcd(m,n):
	while n!=0:
		m,n = n,m % n
	return m

def lcm(m,n):
	return m * n // gcd(m,n)

CD = lcm(C,D)

supC = B // C
supD = B // D
supCD = B // (CD)

infC = (A-1) // C
infD = (A-1) // D
infCD = (A-1) // (CD)

num = B - A + 1
num = num - supC - supD + supCD + infC + infD - infCD
print(num)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll sum;
int main() {
    ll n,k;
    scanf("%lld%lld",&n,&k);
    if(k==0) {
        printf("%lld\n",n*n);
        return 0;
    }
    for(int i=k+1; i<=n; i++) {
        sum+=(n/i)*(i-k);
        if(n%i>=k)
            sum+=(n%i-k+1);
    }
    printf("%lld\n",sum);
    return 0;
}


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

int main(){
	long long int N;
  	cin >> N;
  	long long int ans = N;
  	for(long long int i = 1; i*i<=N;i++){
    	if (N%i == 0){
        	ans = min(ans,max(i,N/i));
        }
    }
    string a = to_string(ans);
  	cout << a.size() << endl;
  
  
}


Measured memory_bytes: 256
use std::str::*;
use std::io::*;

fn read<T: FromStr>() -> Option<T> {
    let s = stdin().bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    if s.is_empty() {
        None
    } else {
        s.parse::<T>().ok()
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

use std::collections::*;

fn solve() {
    while let Some(s) = read::<String>() {
        let a = s.bytes().map(|c| c - b'a').collect::<Vec<u8>>();
        let n = s.len();
        let mut pos = vec![vec![]; 26];
        for i in 0..n {
            pos[a[i] as usize].push(i);
        }
        for i in 0..26 {
            pos[i].push(n);
        }

        let mut s = BTreeSet::<u8>::new();
        let mut len = vec![0; n];
        for i in (0..n).rev() {
            s.insert(a[i]);
            if s.len() == 26 {
                len[i] = len[i + 1] + 1;
                s.clear();
            } else if i != n - 1 {
                len[i] = len[i + 1];
            } else {
                len[i] = 1;
            }
        }

        let stdout = stdout();
        let mut buf = BufWriter::new(stdout.lock());
        let mut cur = 0;
        for k in (0..len[0]).rev() {
            for c in 0..26 {
                let ipos = pos[c as usize].binary_search(&cur).unwrap_or_else(|e| e);
                let i = pos[c as usize][ipos];
                let l = if i + 1 < n { len[i + 1] } else { 0 };
                if l == k {
                    write!(&mut buf, "{}", (c + b'a') as char).ok();
                    cur = i + 1;
                    break;
                }
            }
        }
        writeln!(&mut buf, "").ok();
    }
}


Measured memory_bytes: 12668
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int main() {
    string s;
    std::cin >> s;
    // 白黒と黒白
    ll a=0;
    ll b=0;
    for (int i = 0; i < s.length(); i++) {
        if(i%2==0){
            // aは0がいや
            // bは1がいや
            if(s[i]=='0'){
                // std::cout << 1 << std::endl;
                a++;
            }else{
                // std::cout << 2 << std::endl;
                b++;
            }
        }else{
            if(s[i]=='1'){
                // std::cout << 3 << std::endl;
                a++;
            }else{
                // std::cout << 4<< std::endl;
                b++;
            }
        }
    }
    // std::cout << a<<" "<<b << std::endl;
    std::cout << min(a,b) << std::endl;
}
// 10010010
// 10101010
// 01010101


Measured memory_bytes: 512
#include<stdio.h>
#include<sstream>
#include<iostream>
#include<cstdlib>
#include<string.h>

using namespace std;

#define BUF_SIZE 1024

int count = 0;

void insertionSort(int array[], int n, int g) {
    int v, j;
    for(int i = g; i < n; i++) {
        v = array[i];
        j = i - g; //j = 0, 1, 2,....
        while(j >= 0 && array[j] > v) {
            array[j + g] = array[j];
            j = j - g;
            count++;
        }
        array[j + g] = v;
    }
}

void shellSort(int array[], int n) {
    int m = 0;
    int s = 1;
    
    while((n / s) > 0) {
        s *= 2;
        m++;
    }
    
    int G[20];
    
    for(int k = 0, t = 1; k < m; k++) {
        G[k] = n / t;
        t *= 2;
    }
    
    for(int i = 0; i < m; i++) {
        insertionSort(array, n, G[i]);
    }
    
    printf("%d\n", m);
    for(int i = 0; i < m; i++) {
        if(i != m - 1) {
            printf("%d ", G[i]);
        }else {
            printf("%d\n", G[i]);
        }
    }
    
    printf("%d\n", count);
    for(int i = 0; i < n; i++) {
        printf("%d\n", array[i]);
    }
}

int main(int argc, char* argv[]) {
    char buf[BUF_SIZE];
    int n = atoi(fgets(buf, BUF_SIZE, stdin));
    int array[1000000];
    
    for(int i = 0; i < n; i++) {
        cin >> array[i];
    }
    
    shellSort(array, n);
}


Measured memory_bytes: 7104
n,k=map(int,input().split())
s=input()
s="x"+s+"x"
lr,rl=0,0
ans=0
for i in range(1,n+1):
  if s[i]=="L":
    if s[i-1]=="L":
      ans+=1
    if s[i+1]=="R":
      lr+=1
  else:
    if s[i+1]=="R":
      ans+=1
    elif s[i+1]=="L":
      rl+=1
if k<=min(lr,rl):
  ans+=2*k
else:
  ans+=2*min(lr,rl)
  k-=min(lr,rl)
  if k>=abs(lr-rl):
    ans+=abs(lr-rl)
  else:
    ans+=k
print(ans)

Measured memory_bytes: 3316
n = int(input())
v = list(map(int,input().split()))
dic_odd = {}
dic_even = {}

for i in range(0,n,2):
    if v[i] in dic_odd:
        dic_odd[v[i]] += 1
    else:
        dic_odd[v[i]] = 1

for i in range(1,n,2):
    if v[i] in dic_even:
        dic_even[v[i]] += 1
    else:
        dic_even[v[i]] = 1

odd_sorted = sorted(dic_odd.items(), key=lambda x:x[1])
even_sorted = sorted(dic_even.items(), key=lambda x:x[1])

if odd_sorted[len(odd_sorted)-1][0] == even_sorted[len(even_sorted)-1][0]:
    if len(odd_sorted) == 1 and len(even_sorted) == 1:
        print(n//2)
    elif len(odd_sorted) == 1:
        print(n//2-even_sorted[len(even_sorted)-2][1])
    elif len(even_sorted) == 1:
        print(n//2-odd_sorted[len(odd_sorted)-2][1])
    else:
        if odd_sorted[len(odd_sorted)-1][1] < even_sorted[len(even_sorted)-1][1]:
            print(n - (odd_sorted[len(odd_sorted)-2][1] + even_sorted[len(even_sorted)-1][1]))
        elif  odd_sorted[len(odd_sorted)-1][1] > even_sorted[len(even_sorted)-1][1]:
            print(n - (odd_sorted[len(odd_sorted)-1][1] + even_sorted[len(even_sorted)-2][1]))
        else:
            if odd_sorted[len(odd_sorted)-2][1] < even_sorted[len(even_sorted)-2][1]:
                print(n - (odd_sorted[len(odd_sorted)-1][1] + even_sorted[len(even_sorted)-2][1]))
            else:
                print(n - (odd_sorted[len(odd_sorted)-2][1] + even_sorted[len(even_sorted)-1][1]))
else:
    print(n-(odd_sorted[len(odd_sorted)-1][1]+even_sorted[len(even_sorted)-1][1]))

Measured memory_bytes: 22752
#include <cstdio>
#include <cctype>
#include <algorithm>
using namespace std;
long long N,x;
long long A[200005],Ans=1e18;
inline void read(long long &Res){
	char ch=getchar();
	for (Res=0;!isdigit(ch);ch=getchar());
	for (;isdigit(ch);ch=getchar()) Res=(Res<<3)+(Res<<1)+ch-48;
}
inline long long check(long long a,long long b,long long c,long long d){
	return max(max(a,b),max(c,d))-min(min(a,b),min(c,d));
}
int main(){
	read(N);
	for (int i=1;i<=N;++i) read(x),A[i]=A[i-1]+x;
	for (int i=2;i<N-1;++i){
		long long LL=std::upper_bound(A+1,A+i,A[i]/2.0)-A;
		long long RR=std::upper_bound(A+i+1,A+N+1,(A[i]+A[N])/2.0)-A;
		for (int L=LL-1;L<=LL;++L)
			for (int R=RR-1;R<=RR;++R){
				if (0<L&&L<i&&i<R&&R<N) Ans=min(Ans,check(A[i]-A[L],A[L],A[N]-A[R],A[R]-A[i]));
			}
	}
	printf("%lld\n",Ans);
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  string s;
  ll k;
  cin >> s >> k;
  ll n = s.size();
  for(ll i = 0; i < min(n, k); ++i) {
    if(s[i] != '1') {
      cout << s[i] << endl;
      return 0;
    }
  }
  cout << 1 << endl;
}


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

int main(){
    int n;
    cin >> n;
    int a[n],b[n];
    for (int i = 0; i < n; i++){
        cin >> a[i];
        b[a[i]-1] = i+1;

    }
    for (int i = 0; i < n; i++){
        cout << b[i] << " ";
    }

    return 0;
}

Measured memory_bytes: 1536
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int r = stdIn.nextInt();
			int c = stdIn.nextInt();
			if(r == 0 && c == 0)
			{
				break;
			}
			if((r * c) % 2 == 0)
			{
				System.out.println("yes");
			}
			else
			{
				System.out.println("no");
			}
		}
	}
}

Measured memory_bytes: 12000
fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(' ').map { it.toLong() }

    fun f(x: Long): Set<Long> {
        val set = mutableSetOf(1L)
        var t = x
        var i = 2L

        while (t > 1 && i * i < x) {
            if (t % i == 0L) {
                set.add(i)
                t /= i
                continue
            }
            i++
        }
        set.add(t)

        return set
    }

    println(f(a).intersect(f(b)).size)
}


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

struct TreeNode{
  int value;
  TreeNode* left, *right, *parent;
};

TreeNode* makeNode(int v, TreeNode* l, TreeNode* r, TreeNode* p){
  TreeNode* newNode = new TreeNode;
  newNode->left = l;
  newNode->right = r;
  newNode->parent = p;
  newNode->value = v;
  return newNode;
}


struct Tree{
  TreeNode* root;
  TreeNode* nil;
  Tree(void){
    nil = makeNode(0, nullptr, nullptr, nullptr);
    root = nil;
  }
};

TreeNode* newNode(int v, Tree* T){
  return makeNode(v, T->nil, T->nil, T->nil);
}

void insert(Tree* T, TreeNode* z){
  TreeNode* y = T->nil;
  TreeNode* x = T->root;
  while ( x != T->nil ){
   y = x;
   if ( z->value < x->value )
     x = x->left;
   else
     x = x->right;
  }
  z->parent = y;


  if ( y == T->nil )
    T->root = z;
  else if ( z->value < y->value )
    y->left = z;
  else 
    y->right = z;
}

void printInorder(Tree& T,TreeNode* root){
  if (root == T.nil) return;
  printInorder(T, root->left);
  printf(" %d", root->value);
  printInorder(T, root->right);
}

void printPreorder(Tree& T, TreeNode* root){
  if (root == T.nil) return;
  printf(" %d", root->value);
  printPreorder(T, root->left);
  printPreorder(T, root->right);
}

void print(Tree tree){
  printInorder(tree, tree.root);
  printf("\n");
  printPreorder(tree, tree.root);
  printf("\n");
}

int main(){
  Tree tree;
  string str;
  int n;
  cin >> n;
  for (int i=0;i<n;i++){
    cin >> str;
    if (str == "insert"){
      int value;
      cin >> value;
      insert(&tree, newNode(value, &tree));
    }
    else if (str == "print")
      print(tree);
  }
  return 0;
}




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

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;

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


int main() {
	int n;
	cin >> n;
	int ans = 0, h_max = -1;
	rep(i, n) {
	    int h;
	    cin >> h;
	    if(h >= h_max) {
	        ans += 1;
	        h_max = h;
	    }
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

char opp(char x) {
  return (tolower(x) == x) ? toupper(x) : tolower(x);
}

vi mul(const vi& a, const vi& b) {
  vi c(a.size());
  for (int i = 0; i < a.size(); ++i) c[i] = b[a[i]];
  return c;
}

vi id(int n) {
  vi v(n);
  for (int i = 0; i < n; ++i) v[i] = i;
  return v;
}

vi inv(const vi& v) {
  vi a(v.size());
  for (int i = 0; i < v.size(); ++i) {
    a[v[i]] = i;
  }
  return a;
}

vi mpow(vi x, ll n) {
  vi res = id(x.size());
  while (n) {
    if (n & 1) res = mul(res, x);
    x = mul(x, x);
    n /= 2;
  } 
  return res;
}

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n, k;
  cin >> n >> k;
  --k;
  vi p(n), q(n), P(n), Q(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i]; --p[i];
    P[p[i]] = i;
  }
  for (int i = 0; i < n; ++i) {
    cin >> q[i]; --q[i];
    Q[q[i]] = i;
  }
  vvi mid(6);
  mid[0] = p;
  mid[1] = q;
  mid[2] = mul(P, q);
  mid[3] = P;
  mid[4] = Q;
  mid[5] = mul(p, Q);
  vvi per(5, id(n));
  per[1] = Q;
  per[2] = mul(per[1], p);
  per[3] = mul(per[2], q);
  per[4] = mul(per[3], P);
  int l = (k < 3) ? 0 : (k - 1) / 3 * 2 + (k % 3 == 0);
  vi pref = mul(mpow(per[4], l / 4), per[l % 4]);
  vi res = mul(mul(pref, mid[k % 6]), inv(pref));
  for (int i = 0; i < res.size(); ++i) cout << res[i] + 1 << ' ';
  cout << endl;
/*  vs s(40);
  s[0] = "p", s[1] = "q";
  string pat = "QpqP";
  for (int i = 2; i < s.size(); ++i) {
    string& a = s[i];
    a = s[i - 2];
    reverse(a.begin(), a.end());
    for (char& x : a) {
      x = opp(x);
    }
    for (char x : s[i - 1]) {
      if (a.empty() || tolower(a.back()) != tolower(x) || islower(a.back()) == islower(x)) {
        a += x;
      } else {
        a.pop_back();
      }
    }
    for (int j = 0; j < (int)s[i].size() / 2 - 1; ++j) assert(s[i][j] == pat[j % 4] && s[i][s[i].size() - 1 - j] == opp(pat[j % 4]));
    cerr << s[i] << endl;
  }*/

  return 0;
}


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

#define MAXN 100010
using namespace std;

int N, M;

vector<int> neigh[MAXN];
bool reached[MAXN];
int sig[MAXN];
int A, B;

int main()
{
	cin>>N>>M;
	for(int i = 0; i < M; ++i)
	{
		cin>>A>>B;
		neigh[A].push_back(B);
		neigh[B].push_back(A);
	}
	for(int i = 1; i <= N; ++i)
	{
		reached[i] = false;
	}
	deque<pair<int, int> > q;
	q.push_back(make_pair(1, 0));
	reached[1] = true;
	while(!q.empty())
	{
		int u = q.front().first;
		int step = q.front().second;
		for(int v: neigh[u])
		{
			if(!reached[v])
			{
				sig[v] = u;
				q.push_back(make_pair(v, step+1));
				reached[v] = true;
			}
		}
		q.pop_front();
	}
	cout<<"Yes"<<endl;
	for(int i = 2; i <= N; ++i)
		cout<<sig[i]<<endl;
	
	
	
}


Measured memory_bytes: 10788
#include "bits/stdc++.h"

#define REP(i, a, b) for (int i = (a); i <= (b); ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define FORV(a, A) for (auto &a : A)

using namespace std;

using ll = long long;

void Main()
{
   string S;
   cin >> S;
   if (S[0] == S[1])
   {
      if (S[2] == S[3] && S[0] != S[2])
      {
         cout << "Yes" << endl;
         return;
      }
   }
   if (S[0] == S[2])
   {
      if (S[1] == S[3] && S[0] != S[1])
      {
         cout << "Yes" << endl;
         return;
      }
   }
   if (S[0] == S[3])
   {
      if (S[1] == S[2] && S[0] != S[2])
      {
         cout << "Yes" << endl;
         return;
      }
   }
   cout << "No" << endl;
   return;
}

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


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000.0
#define MOD 1000000009
#define EPS 1E-9

double x;
double mn =  INF;
double mx = -INF;

int main()
{
  while(cin >> x){
    maxup(mx, x);
    minup(mn, x);
  }

  printf("%.10f\n", mx - mn);

  return 0;
}

Measured memory_bytes: 1240
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
h = LIST()

dp = [INF]*N
dp[0] = 0
for i in range(N):
	if i < N-1:
		dp[i+1] = min(dp[i+1], dp[i]+abs(h[i+1]-h[i]))
	if i < N-2:
		dp[i+2] = min(dp[i+2], dp[i]+abs(h[i+2]-h[i]))
# print(dp)
print(dp[-1])

Measured memory_bytes: 14872
s = input()
K = int(input())
alphabet = list("abcdefghijklmnopqrstuvwxyz")
result = []

for u in alphabet:
    for i in range(len(s)):
        if s[i] == u:
            for j in range(i + 1, min(i + K + 1, len(s) + 1)):
                result.append(s[i:j])
    result = list(set(result))
    if len(result) > K:
        break

result.sort()
print(result[K - 1])


Measured memory_bytes: 4340
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // ??????????????????????????????.
        // ???????????????????????´??°??? 1 ?????\???????????????.
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.printf("%d %d %7.5f", a / b, a % b, (double)a / (double)b);
    }
}

Measured memory_bytes: 26416
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
  static InputReader in;
  static PrintWriter out;

  static class Solution {
    void solve() throws IOException {
      while (true) {
        String x = in.next();
        if (x.equals("0")) {
          break;
        }
        
        long sum = 0;
        
        for (int i = 0; i < x.length(); i++) {          
          sum += Integer.parseInt(x.substring(i, i+1));
        }
       
       out.println(sum);
      }
      
//      End solve()
    }
//    End Solution
}

  public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
}

  static class InputReader {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }

    public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    }

    public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken());
    }

    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    }

    public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    }


  }

}

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

int main() {

int x;cin>>x;
rep(a,120)
{
  for (int b = -120; b <= 119; b++)
  {
    if(a*a*a*a*a-b*b*b*b*b==x)
    {cout << a<<" "<<b<<endl;return 0;}
  }
  
}

}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#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()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;

int main(void) {
  ll n,k;
  cin >> n >> k;
  ll ans = 0;
  rep2(i,1,n+1){
    if(k==0) ans -= 1LL;
    ans += n/i*(max(i-k,0LL)) + max(n%i-k+1,0LL);
    //cout << i << " " << n/i*(max(i-k,0LL)) + max(n%i-k+1,0LL) << endl;
  }
  cout << ans << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <array>
#include <stack>
#include <queue>
#include <chrono>
#include <numeric>
#include <memory.h>
#include <map>
#include <math.h>
#include <utility>
#include <set>

#pragma warning(disable:4996)
using namespace std;
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
typedef long long Int;
const double PI = 3.141592653589793238;
const Int INF = 999999999999;
typedef pair<int, int> P;


int aa[10];
int bb[10];

int main()
{
	int a[4];
	int b[4];

	int n;
	while (cin >> n){
		a[0] = n;
		REP(i, 3){
			cin >> a[i+1];
		}

		REP(i, 4){
			cin >> b[i];
		}

		REP(i, 10){
			aa[i] = bb[i] = -1;
		}


		REP(i, 4){
			aa[a[i]] = i;
			bb[b[i]] = i;
		}

		int blow = 0;
		int hit = 0;

		REP(i, 10){
			if (aa[i] >= 0){
				if (bb[i] >= 0){
					if (aa[i] == bb[i])
						++hit;
					else
						++blow;
				}
			}
		}

		cout << hit << " " << blow << endl;
	}
	return 0;

}

Measured memory_bytes: 1160
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	ns := make([]int, 3)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d %d", &ns[0], &ns[1], &ns[2])

	sort.Sort(sort.Reverse(sort.IntSlice(ns)))

	ns[1] = ns[0] - ns[1]
	ns[2] = ns[0] - ns[2]

	remaining := ns[1] + ns[2]
	if remaining%2 == 0 {
		fmt.Println(remaining / 2)
	} else {
		fmt.Println(remaining/2 + 2)
	}
}


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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9

using namespace std;

int main(){
  int n, m; cin >> n >> m;
  vector<vector<double> > cs;
  REP(i, n){
    vector<double> c(3);
    REP(i, 3) cin >> c[i];
    cs.push_back(c);
  }
  double res = 0;
  REP(i, 1 << n){
    bitset<20> bs(i);
    if(bs.count() != m) continue;
    double dist = 0;
    REP(i, n) REP(j, i){
      if(bs[i] and bs[j]) REP(k, 3) dist += (cs[i][k] - cs[j][k]) * (cs[i][k] - cs[j][k]);
    }
    res = max(res, dist);
  }
  cout << setprecision(10) << fixed << res << endl;
  return 0;
}

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

int main(){
  int a,b;
  string alp="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  cin>>a>>b;
  vector<vector<string>> s(a,vector<string> (b));
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
      cin>>s[i][j];
      if(s[i][j]=="snuke"){
        cout<<alp.at(j)<<i+1<<endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,m,p,sum,ai,bi;
vector<long long> a,b,fa,fb;
long long bns(long long find){
	if(find+fb[m-1]<=p)return m-1;
	if(find+fb[0]>p)return (long long)-1;
	long long l=0,r=m-1;
	while(r>l){
		long long mid=(l+r)/2+1;
		if(p>=find+fb[mid])l=mid;
		else r=mid-1;
	}
	return l;
}
int main(){
	cin>>n>>m>>p;
	for(long long i=0;i<n;i++){
		long long x;cin>>x;a.push_back(x);fa.push_back(x+(i>0?fa[i-1]:0));
	}
	for(long long i=0;i<m;i++){
		long long y;cin>>y;b.push_back(y);fb.push_back(y+(i>0?fb[i-1]:0));
	}
	for(long long i=0;i<n;i++){
		long long o=bns(fa[i]);if(o<0){
			if(fa[i]<=p)sum=max(sum,i+1);
			continue;
		}
		sum=max(sum,o+i+1+1);
	}
	for(long long i=1;i<m;i++){
		if(fb[i]>p && fb[i-1]<=p)sum=max(sum,i);
		if(i==m-1 && fb[i]<=p)sum=max(sum,m);
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 11280
n,m = (int(num) for num in input().split())

ls = []

for i in range(m):
    s = [int(num)-1 for num in input().split()]
    s.pop(0)
    ls.append(s)
    
#print(ls)
    
p = [int(num) for num in input().split()]
    
def isOK(k,s,p):
    r = 0
    for i in range (n):
        if (k >> i)%2 == 1 and i in s:
            r += 1
    #print(r,p)
    if r%2 == p:
        return True
    else:
        return False
    
ans = 0
    
for k in range(2**n):
    for i in range(m):
        f = True
        s = ls[i]
        if not isOK(k,s,p[i]):
            f = False
            break
    if f:
        ans += 1
        

print(ans)

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

int main()
{
    int N;
    cin >> N;
    int K;
    cin >> K;
    int sum = 0;
    vector<int> l(N);
    vector<bool>ok(N,false);
    for (int i = 0; i < N;i++)
    {
        cin >> l[i];
    }
    sort(l.begin(), l.end());
    for (int j = N - 1; j >= N -K; j--)
    {
        sum += l[j];
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int tmp[100005]={0},a[100005];
long long sum=0;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		tmp[a[i]]++;
		sum+=a[i];
	}
	int q;
	cin>>q;
	while(q--){
		int b,c;
		cin>>b>>c;
		long long x=tmp[b]*(c-b);
		tmp[c]+=tmp[b];
		tmp[b]=0;
		sum+=x;
		cout<<sum<<endl;
	}
	return 0;
} 


Measured memory_bytes: 4400
n, w = map(int, input().split())
W = [0 for i in range(n)]
V = [0 for i in range(n)]
for i in range(n):
    W[i], V[i] = map(int, input().split())

DP = [[0 for j in range(w + 1)] for i in range(n)]
for j in range(W[0], w + 1):
    DP[0][j] = V[0]

for i in range(1, n):
    for j in range(w + 1):
        if j - W[i] >= 0:
            DP[i][j] = max(DP[i - 1][j], DP[i - 1][j - W[i]] + V[i])
        else:
            DP[i][j] = DP[i - 1][j]

print(DP[n - 1][w])

Measured memory_bytes: 218112
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<limits.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int IINF=INT32_MAX;
static const ll LINF=INT64_MAX;
static const ll mod=1e9+7;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};

int N,M;

bool f[200005];
bool usem[200005];

int main(){
    cin>>N>>M;
    if(N%2==1){
        for(int i=1;i<=M;++i){
            cout<<i<<" "<<N-i+1<<endl;
        }
    }
    else{
        for(int i=1;i<=M;++i){
            if(N-2*i+1>2*i-1)cout<<i<<" "<<N-i+1<<endl;
            else cout<<i<<" "<<N-i<<endl;
        }
    }
}

Measured memory_bytes: 3628
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(m)]
class unionfind:
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
    def find(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def count(self, x):
        return -self.root[self.find(x)]
uf=unionfind(n)
ans=n*(n-1)//2
for i in range(1,m+1):
    a,b=ab[-i]
    ab[-i]=ans
    if(uf.same(a,b)):
        continue
    else:
        ans-=uf.count(a)*uf.count(b)
        uf.unite(a,b)
for i in ab:
    print(i)

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

int main() {
  int N, M; cin >> N >> M;
  vector<int> p(M);
  vector<string> S(M);
  vector<bool> solved(N, false);
  vector<int> wa(N, 0);
  for(int i = 0; i < M; i++) {
    cin >> p[i] >> S[i];
    p[i]--;
  }
  int total_ac = 0, total_wa = 0;
  for(int i = 0; i < M; i++) {
    if(solved[p[i]]) {
    } else {
      if(S[i] == "AC") total_ac++, solved[p[i]] = true, total_wa += wa[p[i]];
      else {
        wa[p[i]]++;
      }
    }
  }
  cout << total_ac << " " << total_wa << endl;
  return 0;
}


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

X = [0,0,0]
Y = [0,0,0]

for i in range(3):
    Y[i] = C[0][i] - X[0]
for i in range(3):
    X[i] = C[i][0] - Y[0]

for i in range(3):
    for j in range(3):
        if (C[i][j] != X[i] + Y[j]):
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3064