akhauriyash/Code-Regression huggingface dataset:
package main

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

func solve(sc *scanner, wr *bufio.Writer) {
	n, m := sc.getInt2()
	pq := newIntPriorityQueue(n)
	for i := 0; i < n; i++ {
		a := sc.getInt()
		pq.push(a)
	}

	for i := 0; i < m; i++ {
		pq.fix(0, pq.head()/2)
	}

	ans := sum(*pq.h...)
	fmt.Fprintln(wr, ans)
}

type intPriorityQueue struct {
	h *intHeap
}

func newIntPriorityQueue(cap int) *intPriorityQueue {
	pq := new(intPriorityQueue)
	ih := make(intHeap, 0, cap)
	pq.h = &ih
	heap.Init(pq.h)
	return pq
}
func (pq *intPriorityQueue) push(x int) { heap.Push(pq.h, x) }
func (pq *intPriorityQueue) pop() int   { return heap.Pop(pq.h).(int) }
func (pq *intPriorityQueue) fix(i, x int) {
	(*pq.h)[i] = x
	heap.Fix(pq.h, i)
}
func (pq *intPriorityQueue) head() int {
	return (*pq.h)[0]
}

type intHeap []int

func (h *intHeap) Len() int           { return len(*h) }
func (h *intHeap) Less(i, j int) bool { return (*h)[i] > (*h)[j] }
func (h *intHeap) Swap(i, j int)      { (*h)[i], (*h)[j] = (*h)[j], (*h)[i] }
func (h *intHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}
func (h *intHeap) Pop() interface{} {
	old := *h
	n := len(old)
	ret := old[n-1]
	*h = old[0 : n-1]
	return ret
}

func main() {
	sc := newScanner()
	wr := bufio.NewWriter(os.Stdout)
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)

	solve(sc, wr)
	wr.Flush()
}

// input ------------------------
type scanner struct {
	*bufio.Scanner
}

func newScanner() *scanner {
	sc := bufio.NewScanner(os.Stdin)
	return &scanner{sc}
}
func (sc *scanner) getInt() int {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getInt2() (int, int) {
	return sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt3() (int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt4() (int, int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInts(n int) []int {
	ret := make([]int, n)
	for i := range ret {
		ret[i] = sc.getInt()
	}
	return ret
}
func (sc *scanner) getString() string {
	sc.Scan()
	return sc.Text()
}
func (sc *scanner) getRunes() []rune {
	return []rune(sc.getString())
}
func (sc *scanner) getFloat() float64 {
	sc.Scan()
	ret, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := range ret {
		ret[i] = sc.getFloat()
	}
	return ret
}

// math ----------------------------
func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

func pow(a, b int) int {
	ret := 1
	for b > 0 {
		if b&1 > 0 {
			ret = ret * a
		}
		a = a * a
		b >>= 1
	}
	return ret
}


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

using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<double>;
using VVI = vector<VI>;
using VVL = vector<VL>;
using PI = pair<int, int>;
using PL = pair<ll, ll>;
using VPI = vector<PI>;
using VPL = vector<PL>;
using VS = vector<string>;

#define ln '\n'
#define REP(t, n) for (int t = 0; t < (n); ++t)
#define FOR(t, a, b) for (int t = (a); t <= (b); ++t)
#define FORR(t, a, b) for (int t = (a); t >= (b); --t)
#define ALL(c) (c).begin(), (c).end()

int main() {
    int n;
    cin >> n;
    VI store(n);
    VS city(n);
    VI point(n);
    REP(i, n) {
        store[i] = i;
        cin >> city[i] >> point[i];
    }
    sort(ALL(store), [&city, &point](const int &a, const int &b) {
        if (city[a] == city[b])
            return point[a] > point[b];
        else
            return city[a] < city[b];
    });
    REP(i, n) {
        cout << store[i] + 1 << ln;
    }

    return 0;
}


Measured memory_bytes: 256
/**
 *  author:   TakeruOkuyama
 *  created:  2020-04-15 11:17:28
**/
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1000000007;
const int INF = 999999999;

int main(){
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> A(Q);
    vector<int> P(N, 0);
    rep(i, Q){
        cin >> A[i];
        P[A[i]-1]++;
    }
    rep(i, N){
        //P[i] = abs(K - P[i]);
        //cout << P[i] << endl;
        if(K <= Q - P[i]){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }
    
return 0;}
/**
 * g++ code.cpp
 * ./a.out
 * shift + ctrl + i
**/ 

Measured memory_bytes: 1408
using System;
using System.Collections.Generic;

namespace _0075
{
    class Program
    {
        static void Main(string[] args)
        {
            var studentList = new List<int>();
            while (true)
            {
                var input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    break;
                }
                var inputs = input.Split(',');
                var bmi = (double.Parse(inputs[1])) /(double.Parse(inputs[2])*double.Parse(inputs[2]));

                if( bmi >= 25.0 )
                {
                    studentList.Add(int.Parse(inputs[0]));
                }
            }
            studentList.Sort();

            foreach(var i in studentList)
            {
                Console.WriteLine(i);
            }
        }
    }
}

Measured memory_bytes: 5832
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef queue<int, int> qii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;

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

//int型を受け取ってその桁数を返す
int check_digits(int n) {
	int digits = 0;
	while (n != 0) {
		n /= 10;
		digits++;
	}
	return digits;
}

//int型を受け取ってその各桁の和を返す
int sum_digits(int n) {
	int sum=0;
	int N = n;
	while (N) {
		sum += N % 10;
		N /= 10;
	}
	return sum;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}

void yes() {
	cout << "Yes" << endl;
}

void no() {
	cout << "No" << endl;
}

int main() {
	string s;
	cin >> s;
	int n = s.size();
	rept(i, n)cout << 'x';
	cout << endl;

	

	system("pause");
	return 0;
}


Measured memory_bytes: 504
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn = 10005;
int main(void) {
    int a,b,c,count = 0;
    scanf("%d%d%d",&a,&b,&c);
    for(int i = a; i <= b; i++)
        if(c % i == 0)
            count ++;
    cout << count << endl;
    return 0;
}



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

std::string s;
int res;

int is_palindrome( std::string s ) {
    std::string t = s;
    std::reverse(t.begin(), t.end());
    return t == s;
}

int main() {
    while (std::cin >> s) {
        res += is_palindrome( s );
    }
    std::cout << res << std::endl;
    return 0;
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long A, B, K;
  cin >> A>>B>>K;
  if(A>=K){
    A-=K;
  }
  else{
    K-=A;
    A=0;
    B-=K;
    if(B<0) B=0;
  }
  cout << A <<" "<<B<<endl;
}


Measured memory_bytes: 256
console.log((args=>{
  const [[N,k],x] = args.trim().split`\n`.map(r=>r.split` `.map(v=>v|0));
  const K = k-1;
  let min = Infinity;
  for ( let i = 0; i+K < N; i++ ) {
    if ( x[i] < 0 && 0 < x[i+K] ) {
      min = Math.min( min, x[i+K] - x[i] + Math.min(x[i+K],-x[i]) );
    } else if ( x[i] >= 0 ) min = Math.min( min, x[i+K] );
    else if ( x[i+K] <= 0 ) min = Math.min( min, -x[i] );
  }
  return `${min}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 40072
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
using namespace std;

signed main() {
    int x, y;
    cin >> x >> y;
    cout << x + y / 2 << endl;
    return 0;
}


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

using namespace std;

typedef long long int ll;

float calc_sd(ll n) {
    string temp = std::to_string(n);
    int sn = 0;
    for(int i = 0;i < temp.length();i++) {
        char tt[2];
        tt[0] = temp[i];
        tt[1] = NULL;
        sn = sn + atoi(tt);
    }
    float retval = 0;
    retval = (float)n / (float)sn;
    return retval;
}

bool if_sunuke(int sunuke) {
    for(int i = sunuke + 1;i < sunuke * 10;i++) {
        if(calc_sd(sunuke) > calc_sd(i))
            return false;
    }
    return true;
}

int main(void) {
    ll res = 1;
    ll pls = 1;
    int count = 1;
    int k;
    cin >> k;
    cout << 1 << endl;
    while(count < k) {
        while(calc_sd(res + pls + pls) < calc_sd(res + pls))
            pls = pls * 10;
        res = res + pls;
        cout << res << endl;
        count++;
    }
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		int count5 = 0, count7 = 0;
		for (int i = 0; i < 3; i++) {
			int a = sc.nextInt();
			if (a == 5) count5++;
			else if (a == 7) count7++;
		}
		
		if (count5 == 2 && count7 == 1) {
			out.println("YES");
		} else {
			out.println("NO");
		}
		out.flush();
	}
	
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	
	private byte readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	
	private boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}
	
	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}
	
	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}
	
	public int nextInt() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

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

//#define getchar getchar_unlocked
//#define putchar putchar_unlocked
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define ff first
#define ss second
#define err stderr
#define out stdout

typedef long long int ll;
typedef long double ld;
typedef short int sh;

inline void readI(int *i)
{
	register int t=0;
	register char z=getchar();
	int znak=1;
	if (z=='-')
	{
		znak=-1;
	}
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
		if (z=='-')
		{
			znak=-1;
		}
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*i=(t*znak);
}
inline void readUI(int *i)
{
	register int t=0;
	register char z=getchar();
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*i=t;
}
inline void readL(ll *l)
{
	register ll t=0;
	register char z=getchar();
	int znak=1;
	if (z=='-')
	{
		znak*=-1;
	}
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
		if (z=='-')
		{
			znak=-1;
		}
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*l=(t*znak);
}
inline void readUL(ll *l)
{
	register ll t=0;
	register char z=getchar();
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*l=t;
}
inline void writeL(ll l)
{
	if (l==0)
	{
		putchar(48);
	}
	else
	{
		if (l<0)
		{
		   l*=-1;
		   putchar(45);
		}
		int _tab[21];
		int wsk=0;
		while (l>0)
		{
			++wsk;
			_tab[wsk]=(l%10)+48;
			l/=10;
		}
		for (int j=wsk; j>=1; --j)
		{
			putchar(_tab[j]);
		}
	}
}
inline void writeS(string s)
{
	int l=s.length();
	for (int i=0; i<l; ++i)
	{
		putchar(s[i]);
	}
}
inline void space()
{
	putchar(32);
}
inline void endl()
{
	putchar(10);
}

#define debug if(1)
#define debug2 if(1)
#define debug3 if(1)
#define debug4 if(1)
#define MAXN (int)(1e5)+5

int n, a, b, c;
int dp[2][3];

int main()
{
	readUI(&n);
	for (int i=1; i<=n; ++i)
	{
		readUI(&a);
		readUI(&b);
		readUI(&c);
		dp[i&1][0]=max(dp[i&1^1][1], dp[i&1^1][2])+a;
		dp[i&1][1]=max(dp[i&1^1][0], dp[i&1^1][2])+b;
		dp[i&1][2]=max(dp[i&1^1][0], dp[i&1^1][1])+c;
	}
	fprintf (out, "%d\n", max(dp[n&1][0], max(dp[n&1][1], dp[n&1][2])));
	return 0;
}
/*
*/




Measured memory_bytes: 256
D = int(input())
c = list(map(int, input().split()))
s = []
for k in range(D):
    s.append(list(map(int, input().split())))

ch = s.index(max(s))+1


p = 0

ch = c.index(min(c))
chli = [[] for k in range(D)]
for k in range(D):
    for j in range(len(c)):
        chli[k].append([s[k][j] - (D-k)*c[j], j])
    chli[k].sort(key = lambda x: x[0])
#print(chli)
ans = [chli[k][-1][1] +1 for k in range(D)]
#print(ans)

scheduled = [0 for _ in range(26)]

for k in range(D):
    t = ans[k]
    scheduled[t-1] = -1
    for j in range(26):
        scheduled[j] +=1
        p -= c[j]*scheduled[j]
    p += s[k][t-1]

np = p

for n in range(D):
    op = 0+ np
    oa = 0 + ans[n]
    ans[n] = ch
    for k in range(D):
        t = ans[k]
        scheduled[t-1] = -1
        for j in range(26):
            scheduled[j] +=1
            np -= c[j]*scheduled[j]
        np += s[k][t-1]
    if np < op:
        ans[n] = 0 + oa
        np = 0 + op
        op = 0+ np

#print(np)

for k in range(D):
    print(ans[k])

Measured memory_bytes: 10576
#include<cstdio>
#include<vector>
#include<iostream>

using namespace std;

int main(void) {
    while(1) {
        int n,k,m;
        cin >> n >> k >> m;
        if(!n) break;

        vector<int> v;
        for(int i=0; i<n; i++)
            v.push_back(i);
        for(int now=m-1; v.size() != 1; now=(now-1+k)%v.size())
            v.erase(v.begin() + now);
        cout << v.front()+1 << endl;
    }
    return 0;
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int d = 3 * max({a, b, c}) - a - b - c;
    cout << (d + d % 2 * 3) / 2 << endl;
    return 0;
}

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



Measured memory_bytes: 2048
//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) ((a + b - 1) / b)
#define tomax(a, b) (a = max(a, b))
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

//#define TEST

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

int main(){
    StarBurstStream

    string s;
    cin >> s;
    int n = s.size();
    int sum = 0;
    for(int i = 0; i < n; i++){
        sum += s[i] - '0';
    }
    if(sum % 9) cout << "No\n";
    else cout << "Yes\n";

    return 0;
}

Measured memory_bytes: 3780
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-8
#define inf INT_MAX
#define mod 1000000009
using namespace std;

int main() {
	speed;
	int r, d, x;
	cin >> r >> d >> x;
	for (int i = 0; i < 10; ++i){
		x = r * x - d;
		cout << x << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
const ll N=998244353;
bool isPal(string s)
{
    string t=s;
    reverse(all(t));
    return t==s;
}
void solve()
{
    string s;
    cin>>s;
    ll n=s.length();
    bool val= isPal(s.substr(0,(n-1)/2));
    //cout<<val;
    val=val&&isPal(s.substr((n+3)/2-1, n+1-(n+1)/2));
    val=val&&isPal(s);
    if(val)
    cout<<"Yes";
    else
    cout<<"No";
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

Measured memory_bytes: 256
kingaku, n = input().split()
no_num = input().split()
result = []
ok_num = []
kuriage_num = [-1, 0]

def kuriage(l):
    for i in ok_num:
        if result[l] < i:
            kuriage_num = [l, i]
            return
    if l <= 0:
        return
    return kuriage(l-1)

#使える数字のリストを作成
for i in range(10):
    if not str(i) in no_num:
        ok_num.append(str(i))

set_flg = False
for i in kingaku:
    set_flg = True
    for j in ok_num:
        if i == j:
            set_flg = False
            result.append(j)
            break
        elif i < j:
            result.append(j)
            print("".join(result).ljust(len(kingaku), ok_num[0]))
            exit()
            break
    
    if set_flg:
        n = 0
        if ok_num[0] == '0':
            n = 1
        print(ok_num[n].ljust(len(kingaku)+1, ok_num[0]))
        exit()

print(''.join(result))


Measured memory_bytes: 9108
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, m;
  cin >> n >> m;
  vector<vi> ms(m);
  rep(i, n) {
    int x;
    cin >> x;
    ms[x % m].push_back(x);
  }
  rep(i, m) sort(all(ms[i]));
  int ans = 0;
  rep(i, m / 2 + 1) {
    if(i == 0 || i == m - i) {
      ans += ms[i].size() / 2;
    } else {
      vi s = ms[i];
      vi t = ms[m - i];
      if(s.size() < t.size()) swap(s, t);
      int now = 0;
      rep(j, s.size() - 1) {
        if(s.size() - now * 2 < t.size() + 2) break;
        if(s[j] == s[j + 1]) {
          now++;
          j++;
        }
      }
      ans += now + t.size();
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <numeric>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    for(int i = 0;i < N;i++){
        cin >> A[i];
        B[i] = A[i] - i;
    }

    sort(B.begin(),B.end());

    long ans = 0;

    for(int i = 0;i < N;i++){
        ans = ans + abs(B[i] - B[(N - 1) / 2]);
    }

    cout << ans << endl;
}

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

typedef pair<int, int> Pair;

const int MAXN = 100005;
const int INF = 1<<28;
int N;
int p[MAXN];
int to[MAXN];

int main() {
  while(cin >> N) {
    for(int i = 0; i < N; ++i) cin >> p[i];
    memset(to, -1, sizeof(to));
    for(int i = 0; i < N; ++i) {
      if(to[i] != -1) continue;
      int v = i;
      vector<int> vs;
      while(to[v] == -1) {
        if(p[v] == 0) {
          to[v] = v;
          break;
        }
        to[v] = INF;
        vs.push_back(v);
        v += p[v];
      }
      if(to[v] != INF) {
        for(int j = 0; j < vs.size(); ++j) to[vs[j]] = to[v];
      }
    }

    vector<int> cost(N, INF);
    priority_queue<Pair, vector<Pair>, greater<Pair> > que;
    cost[0] = 0;
    que.push(Pair(0, 0));
    while(que.size()) {
      const Pair s = que.top();
      que.pop();
      if(s.first > cost[s.second]) continue;
      for(int i = 1; i <= 6; ++i) {
        const Pair t(s.first + 1, to[min(N-1, s.second+i)]);
        if(t.second == INF) continue;
        if(t.first >= cost[t.second]) continue;
        cost[t.second] = t.first;
        que.push(t);
      }
    }
    cout << cost[N-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 2460
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define mod 1000000007ll
#define mod1 998244353ll
#define endl '\n'
#define inf ((ll)1e18+1)
#include<chrono>
using namespace chrono;
mt19937_64 rng(high_resolution_clock::now().time_since_epoch().count());
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define debr(x,y) {cout<<"-->  "<<#x<<" to "<<#y<<" :  "; auto itr=x; while(itr!=y) cout<<(*itr++)<<' '; cout<<endl; }
#define deba(x) {cout<<"-->  "<<#x<<" :  "; for(auto ele:(x)) cout<<ele<<"  "; cout<<endl; }
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s);istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a <<"  ,  ";
    err(++it, args...);
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t=1;
    // cin>>t;
    while(t--){
        ll n,k;
        cin>>n>>k;
        vector<ll> per(n+1),c(n+1);
        for(ll x=1;x<=n;x++){
            cin>>per[x];
        }
        for(ll x=1;x<=n;x++){
            cin>>c[x];
        }
        ll ans=-inf;
        for(ll x=1;x<=n;x++){
            ll count=0;
            ll tmp=0;
            ll curr=x;
            ll cycle=0;
            while(tmp<k){
                curr=per[curr];
                cycle+=c[curr];
                ans=max(ans,cycle);
                tmp++;
                if(curr==x)break;
            }
            if(tmp==k){
                ans=max(ans,cycle);
            }else{
                ll tmpK=k;
                ll how=k/tmp;
                if(k%tmp==0){
                    how--;
                }
                ll sum=how*cycle;
                if(how!=0){
                    ans=max(ans,sum);
                }
                k-=how*tmp;
                curr=x;
                while(k--){
                    curr=per[curr];
                    sum+=c[curr];
                    ans=max(ans,sum);
                }
                ans=max(ans,sum);
                k=tmpK;
            }
        }
        cout<<ans<<endl;
    }
    return 0;

}


Measured memory_bytes: 3716
def dfs(i, A):
    global res
    global ans
    if len(A) == n:
        res = 0
        for j in range(q):
            if A[l[j][1]] - A[l[j][0]] == l[j][2]:
                res += l[j][3]
        ans = max(ans, res)
        return ans
    lim = 1
    lim = 1 if i == 0 else A[i-1]
    for k in range(lim, m+1):
        A.append(k)
        dfs(i+1, A)
        A.pop()
        
n, m, q = map(int, input().split())
A = []
l = []
ans = 0

for i in range(q):
    a, b, c, d = map(int, input().split())
    l.append([a-1, b-1, c, d])
dfs(0, A)
print(ans)

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

int x[100];

int main( void )
{
	int N,K;
	cin >> N >> K;
	
	rep(i,N)
		cin >> x[i];
	
	ll sum = 0;
	
	rep(i,N)
		sum += min(2*x[i],2*(K-x[i]));
	
	cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n, r;
    cin >> n >> r;

    int ans = r;
    if (n < 10) ans += 100 * (10 - n);

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

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a.at(i);
    }
    vector<int> b(n);
    for(int i = 0; i < n; i++){
        b.at(i) = a.at(i);
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    for(int i = 0; i < n; i++){
        if(b.at(i) == a.at(0)){
            cout << a.at(1) << endl;
        } else {
            cout << a.at(0) << endl;
        }
    }
}

Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

const ll MAX_N = 1e5;
int N;
ll A, B;
ll h[MAX_N];
#define MAX_V 1000000

bool check(ll T) {
	ll total = 0;
	rep(i, 0, N) {
		if(h[i] - T * B <= 0) continue;
		if((h[i] - T * B) % (A - B) == 0) {
			total += (h[i] - T * B) / (A - B);
		} else {
			total += ((h[i] - T * B) / (A - B)) + 1;
		}
	}

	return total <= T;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> A >> B;
	rep(i, 0, N) cin >> h[i];

	ll left = 1, right = 10000000000;

	while(right - left > 1) {
		ll mid = (left + right) / 2;
		if(check(mid)) {
			right = mid;
		} else {
			left = mid;
		}
	}
	if(check(left)) cout << left << endl;
	else cout << right << endl;

}


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

int main(){
    std::string s;
    std::cin >> s;
    auto p = s.front();

  int n1 = 0;
  for(int i=0;i<s.size();i+=2){
  	if(s[i] != '0'){
      	n1 ++;
    }
  }
  int n2 = 0;
  for(int i=1;i<s.size();i+=2){
  	if(s[i] != '0'){
      	n2++;
    }
  }
  auto n1b = s.size() / 2 - n2;
  auto n2b = (s.size() + 1) / 2 - n1;
  auto n11 = n1 + n1b;
  auto n22 = n2 + n2b;
  
  std::cout << std::min(n11,n22) << std::endl;
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >>n;
  int v[n],c[n];
  for(int i=0; i<n;i++)cin >> v[i];
  for(int i=0; i<n ; i++) cin >> c[i];
  int cost = 0;
  for(int i = 0; i < n ; i++){
    if(v[i] - c[i] > 0) cost += v[i]-c[i];
  }
  cout << cost <<endl;
  return 0;
}


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

int main(){
    
    
    long long a,b,c,d,e,f,g,h,i,j,k;
    cin>>a>>b>>c>>d;
    e=a*d;
    f=a*c;
    g=b*d;
    h=b*c;
    i=max(e,f);
    j=max(g,h);
    k=max(i,j);
    cout<<k<<endl;
    
}



Measured memory_bytes: 3632
#include    <bits/stdc++.h>
#define     ll long long
#define     ull unsigned long long
#define     ld long double
#define     prec(k) fixed << setprecision(k)
#define     up(i, k, n) for (int i = k ; i < n ; i ++)
#define     down(i, k, n) for (int i = k ; i >= n ; i --)
#define     ii pair<int, int>
#define     pll pair <ll, ll>
#define     X first
#define     Y second
#define     str basic_string <int>
#define     QuanPham
const int maxN = (int) 1e4 + 7;
const int maxM = (int) 1e5 + 7;
const int maxT = (int) 1e6 + 7;
const int INF = 2e9;

using namespace std;

int n, a[57], maxa = -INF, mina = INF, argmaxa = -1, argmina = -1;

void enter()
{
	cin >> n;
	up(i, 0, n)
	{
		cin >> a[i];
		if (a[i] > maxa)
		{
			maxa = max(maxa, a[i]);
			argmaxa = i;
		}
		if (a[i] < mina)
		{
			mina = min(mina, a[i]);
			argmina = i;
		}
	}
}

void solve()
{
	if (mina >= 0)
	{
		cout << n - 1 << '\n';
		up(i, 0, n - 1) cout << i + 1 << ' ' << i + 2 << '\n';
	}
	else if (maxa <= 0)
	{
		cout << n - 1 << '\n';
		down(i, n, 2) cout << i << ' ' << i - 1 << '\n';
	}
	else if (abs(maxa) >= abs(mina))
	{
		cout << 2 * n - 1 << '\n';
		up(i, 1, n + 1) cout << argmaxa + 1 << ' ' << i << '\n';
		up(i, 0, n - 1) cout << i + 1 << ' ' << i + 2 << '\n';
	}
	else
	{
		cout << 2 * n - 1 << '\n';
		up(i, 1, n + 1) cout << argmina + 1 << ' ' << i << '\n';
		down(i, n, 2) cout << i << ' ' << i - 1 << '\n';
	}
}

int main()
{
    #ifdef QuanPham
    auto start = chrono::steady_clock::now();
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen ("A.INP", "r", stdin);
    //freopen ("A.OUT", "w", stdout);

    enter();
    solve();

    #ifdef QuanPham
    auto end = chrono::steady_clock::now();
    cerr << "In milliseconds : "
         << chrono::duration_cast<chrono::milliseconds>(end - start).count();
    cerr << '\n' << "In seconds : "
         << chrono::duration_cast<chrono::seconds>(end - start).count() << '\n';
    #endif
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    set<string> ss;
    while(n--){
        string s;
        cin >> s;
        ss.insert(s);
    }
    cout << ss.size() << endl;
}

Measured memory_bytes: 19244
#include<bits/stdc++.h>
using namespace std;
long long n,m,k;
int main()
{
    cin>>n>>m>>k;
    if(n<=m)
    {
        cout<<"1"<<endl;
        return 0;
    }
    if(m<=k)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    cout<<((n-m)%(m-k)==0?(n-m)/(m-k):(n-m)/(m-k)+1)*2+1<<endl;
	return 0;
}


Measured memory_bytes: 256
s = input()
k = int(input())
if len(set(s)) == 1 and s[0] == '1':
    print(1)
else:
    i = 0
    while i < len(s) and s[i] == '1':
        i += 1
    if k <= i:
        print(1)
    else:
        print(s[i])


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


int main() {

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

  string s; cin >> s;
  
  int ans = 700;
  for (int i = 0; i < 3; i++) {
    if (s[i] == 'o') ans += 100;
  }

  cout << ans << endl;


  return 0;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ll cnts[51][51][51][51] = {};


void solve() {
    ll N, K;
    cin >> N >> K;
    vector<Pll> ps(N);
    Vl xs(N), ys(N);
    for (ll i = 0; i < N; i++) {
        ll x, y;
        cin >> x >> y;
        ps[i] = {x, y};
        xs[i] = x;
        ys[i] = y;
    }
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    sort(ys.begin(), ys.end());
    ys.erase(unique(ys.begin(), ys.end()), ys.end());

    ll nx = (ll)xs.size();
    ll ny = (ll)ys.size();

    for (ll i = 0; i < nx; i++) {
        for (ll j = 0; j < ny; j++) {
            for (ll k = i; k < nx; k++) {
                for (ll l = j; l < ny; l++) {
                    for (ll m = 0; m < N; m++) {
                        auto [a, b] = ps[m];
                        if (xs[i] <= a && a <= xs[k] && ys[j] <= b && b <= ys[l]) {
                            ++cnts[i][j][k][l];
                        }
                    }
                }
            }
        }
    }

    ll ans = L_INF;
    for (ll i = 0; i < nx; i++) {
        for (ll j = 0; j < ny; j++) {
            for (ll k = 0; k < nx; k++) {
                for (ll l = 0; l < ny; l++) {
                    if (cnts[i][j][k][l] >= K) {
                        ans = min(ans, (xs[k] - xs[i]) * (ys[l] - ys[j]));
                    }
                }
            }
        }
    }

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

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 34928
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;

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

  int32_t N, K;
  cin >> N >> K;
  vector<double> P(1000, 0);
  double sum = 0;
  for (int i = 1; i <= 1000; i++) {
    sum += i;
    double p = sum / (double)i;
    P[i-1] = p;
  }
  vector<double> kitai(N, 0);
  for (int i = 0; i < N; i++) {
    int tmp = 0;
    cin >> tmp;
    kitai[i] = P[tmp - 1];
  }
  double max_val = 0;
  for (int i = 0; i < K; i++) {
    max_val += kitai[i];
  }
  double cur_val = max_val;
  for (int i = 1; i + K <= N; i++) {
    cur_val = cur_val - kitai[i-1] + kitai[i+K-1];
    max_val = max(max_val, cur_val);
  }
  cout << setprecision(12);
  cout << max_val << endl;
  
  return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
int main()
{
    int k;
    string s;
    cin >> k >> s;
    if (s.size() <= k)
    {
        cout << s << endl;
    }
    else
    {
        cout << s.substr(0, k) << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3612
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, _) = get!(usize, usize);
    let mut ss: Vec<String> = Vec::new();
    for _ in 0..n {
        ss.push(get!(String));
    }
    ss.sort();
    println!("{}", ss.iter().cloned().collect::<String>());
}

Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int c[4][4];
int main()
{
	for(int i=1;i<=3;i++)
	for(int j=1;j<=3;j++)
	cin>>c[i][j];
	if
	(
	c[1][3]==c[3][3]-c[3][1]+c[1][1]&&
	c[1][2]==c[2][2]-c[2][1]+c[1][1]&&
	c[2][3]==c[3][3]-c[3][1]+c[2][1]&&
	c[3][2]==c[3][1]-c[2][1]+c[2][2]
	)
	cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, K;
    cin >> N >> K;
    vector<int> x(N, 0);
    vector<int> L, R;
    R.push_back(0);
    REP(i, N) {
        cin >> x.at(i);
        if (x[i] >= 0) {
            R.push_back(x[i]);
        } else {
            L.push_back(abs(x[i]));
        }
    }
    L.push_back(0);
    reverse(ALL(L));

    int ans = INF;
    REP(i, K + 1) {
        if (R.size() <= i || L.size() <= K - i) {
            continue;
        } else {
            // cout << "i:" << i << " K - i:" << K - i << endl;
            // cout << " ans:" << ans << endl;
            chmin(ans, R[i] + L[K - i] * 2);
            chmin(ans, R[i] * 2 + L[K - i]);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1404
#include <bits/stdc++.h>
#include <math.h>  
#include <string>
#include <cstdio>
#include <iostream>
#include <algorithm> 

using namespace std;

typedef signed long long ll;
typedef unsigned long long ull;
typedef vector< pair<int, int> > vec_int_pairs;
typedef vector<int>  vecint;
typedef vector< vector<int> > vecint2;
typedef vecint2 graph;
typedef map<int, int> int_int_map;

int main() {
	int n, k;
	cin >> n;
	cin >> k;
	
	vecint a(n);
	
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	
	vecint dp(n, numeric_limits<int>::max());
	
	dp[0] = 0;
	for (int i = 1; i < n; ++i) {
		for (int j = i - 1; j >= i - k; --j) {
			if (j >= 0) {
				dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
			}
		}
	}
	
	cout << dp[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
typedef long long LL;
int main()
{
    LL n,a,b;
    scanf("%lld%lld%lld",&n,&a,&b);
        if(a>b )
            printf("0\n");
        else if(n == 1 && a != b)
            printf("0\n");
        else
            printf("%lld\n",(b-a)*(n-2)+1);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<60;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;

int ans_sugar_water=0;
int ans_sugar=0;
double max_concentration=0.0;

int main(){

    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    vector<int> waters;
    for(int i = 0; i <= F/100; i++){
        for (int j = 0; j <= F/100; j++){
            int water = i*A*100 + j*B*100;
            if (water <= F){
                waters.push_back(water);
            }
        }
    }

    vector<int> sugars;
    for (int i = 0; i <= F; i++){
        for(int j = 0; j <= F; j++){
            int sugar = i*C + j*D;
            if (sugar <= F){
                sugars.push_back(sugar);
            }
        }
    }

    int ans_sugar_water = 0;
    int ans_sugar = 0;
    double max_concentration = -1.0;
    for(int i = 0; i < waters.size(); i++){
        for (int j = 0; j < sugars.size(); j++){
            int water_sugar = waters[i] + sugars[j];
            if (water_sugar <= F){
                int dissolve_amount = waters[i] / 100 * E;
                if (dissolve_amount >= sugars[j]){
                    double concentration = 100.0*sugars[j]/(water_sugar);
                    if (max_concentration < concentration){
                        max_concentration = concentration;
                        ans_sugar_water = water_sugar;
                        ans_sugar = sugars[j];
                    }
                }
            }
        }
    }

    cout << ans_sugar_water << " " << ans_sugar << endl;
}

Measured memory_bytes: 4216
# 速くなるかどうか実験
n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
a0 = a[0]
d = 1
while a0 % 2 == 0 do
  a0 /= 2
  d *= 2
end
if a.any? {|v| v % d != 0 || (v / d) % 2 == 0}
  puts 0
else
  half_lcm = a.inject(:lcm) / 2
  puts (m / half_lcm + 1) / 2
end


Measured memory_bytes: 12676
#include<stdio.h>

#define N 4

void Nshinsu(int);

int main(){
  while(1){
    int n;
    scanf("%d",&n);
    if(n==-1)break;
    Nshinsu(n);
  }
  return 0;
}

void Nshinsu(int n){

  long long i,y=0,b=1;

  for(i=0;i<100;i++){    
    y+=(n%N)*b;
    n/=N;
    b*=10;
  }

  printf("%lld\n",y);
}

Measured memory_bytes: 1028
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,s,n) for(int i=s; i<n; i++)
#define ALL(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
	int b, r, g, c, s, t;
	while(cin >> b >> r >> g >> c >> s >> t, b||r||g||c||s||t) {
		int coin = 100;
		t -= (s + b*5 + r*3);
		coin -= t*3;
		coin += 15*b + 15*r + 7*g + 2*c;
		coin += 13*(5*b + 3*r);
		cout << coin << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
inline void normal(ll &a)
{
    a %= MOD;
    (a < 0) && (a += MOD);
}
inline ll modMul(ll a, ll b)
{
    a %= MOD, b %= MOD;
    normal(a), normal(b);
    return (a*b)%MOD;
}
inline ll modAdd(ll a, ll b)
{
    a %= MOD, b %= MOD;
    normal(a), normal(b);
    return (a+b)%MOD;
}
main()
{
    int t=1;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        ll ans=0;
        for(int i=k; i<=n+1; i++)
        {

            ans=modAdd((modAdd((modMul((n-i+1),i)),1)),ans);


        }
        cout<<ans<<endl;
    }

}


Measured memory_bytes: 3532
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    map<int, int> m;
    for (auto &&i : v) {
        scanf("%d", &i);
        m[i]++;
    }
    sort(v.begin(), v.end(), greater<>());

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if(!m[v[i]]) continue;
        m[v[i]]--;
        int k = 1;
        while (k <= v[i]) k <<= 1;
        int y = k-v[i];
        if(m[y]) {
            ans++;
            m[y]--;
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 19712
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
using namespace std;
using ll = long long;
ll MOD = 1e9+7;


int main(int argc, const char * argv[]) {    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a,b) << " " << (a+b-n < 0 ? 0 : a+b-n) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define MOD_Q 998244353
#define PI 3.14159265358979
#define ll long long
using namespace std;

int main()
{
	int n;
	cin >> n;
	int bill = 0;
	while (bill * 1000 < n) {
		bill++;
	}

	printf("%d", bill * 1000 - n);

	return 0;
}


Measured memory_bytes: 3748
from operator import itemgetter
Q, H, S, D = map(int, input().split())
p = sorted([(1,Q,Q*8),(2,H,H*4),(4,S,S*2),(8,D,D)], key=itemgetter(2))
N = int(input()) * 4
ans = 0
for i in range(4):
    ans += N // p[i][0] * p[i][1]
    N -= N // p[i][0] * p[i][0]
print(ans)


Measured memory_bytes: 62096