akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
using namespace std;
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
#define inI1(x) scanf("%d",&x);
#define inI2(x,y) scanf("%d %d",&x,&y);
#define inI3(x,y,z) scanf("%d %d %d",&x,&y,&z);
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
int n,dp[100005],k,mm,go[100],r;
int main()
{
    for(int i=0;i<100005;i++)dp[i]=imx;
    inI1(n);
    dp[0]=0;
    go[0]=1;
    k=6;
    mm=6;
    while(k<100005)
    {
        ++r;
        go[r]=k;
        k*=mm;
    }
    k=9;
    mm=9;
    while(k<100005)
    {
        ++r;
        go[r]=k;
        k*=mm;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=r;j++)
        {
            if(i-go[j]>=0)
            {
                dp[i]=min(dp[i-go[j]]+1,dp[i]);
            }
        }
    }
    printf("%d",dp[n]);
}


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

using namespace std;

typedef long long ll;

const ll mod = 1e9+7;

ll K[101010], S[101010], T[101010];
ll dp[101010][2];
ll n, a, b, s;

void add(ll l, ll r, ll v)
{
	if(l <= r){
		T[l] += v;
		T[r+1] -= v;
	}
}

int main()
{
	ll i, j;
	
	scanf("%lld%lld%lld", &n, &a, &b);
	
	if(a < b) swap(a, b);
	
	for(i=1;i<=n;i++) scanf("%lld", S+i);
	
	if(n == 1){
		printf("2\n");
		return 0;
	}
	
	for(i=n;i>=1;i--){
		if(i == n || S[i+1] - S[i] < b) K[i] = i;
		else K[i] = K[i+1];
	}
	
	add(1, K[1]+1, 1);
	
	for(i=j=1;i<=n;i++){
		for(;j<=n && S[j] - S[i] < a;j++);
		
		s = (s + T[i] + mod) % mod;
		
		if(i == 1){
			add(max(i+2, j), K[i+1]+1, 1);
		}
		else if(i == 2){
			dp[2][0] = (S[2] - S[1] >= a);
			dp[2][1] = 1;
			
			add(max(i+2, j), K[i+1]+1, dp[i][0]);
			if(i < n && S[i+1] - S[i-1] >= b) add(max(i+2, j), K[i+1]+1, dp[i][1]);
		}
		else{
			dp[i][0] = (dp[i-1][0] + dp[i-1][1]) * (S[i] - S[i-1] >= a) % mod;
			dp[i][1] = s;
			
			add(max(i+2, j), K[i+1]+1, dp[i][0]);
			if(i < n && S[i+1] - S[i-1] >= b) add(max(i+2, j), K[i+1]+1, dp[i][1]);
		}
	}
	
	printf("%lld\n",((s + T[i] + dp[n][0] + dp[n][1]) % mod + mod) % mod);
	
	return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long 
#define trace(x) cerr<<#x<<" : "<<x<<"\n"; 
int main() 
{ 
    ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    string a,b,u; 
    ll x,y; 
    cin>>a>>b; 
    cin>>x>>y; 
    cin>>u; 
    if(u==a) x-=1; 
    else y-=1; 
    cout<<x<<" "<<y;
    return 0; 
} 

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
long long arr[100005] , dp[100005];
int main(){
	int n ;
	cin>>n;
	for(int i = 0; i< n;  i++){
		cin>>arr[i];
		dp[i] = 1e13;
	}
	dp[0] = 0;
	for(int i = 0; i < n ; i++){
		if(i + 2 < n)dp[i + 2] = min(dp[i + 2] , dp[i] + abs(arr[i + 2] - arr[i]));
		if(i + 1 < n)dp[i + 1] = min(dp[i + 1] , dp[i] + abs(arr[i + 1] - arr[i])); 
	}
	cout<<dp[n-1];
	return 0;
}  


Measured memory_bytes: 1792
#include<iostream>
#include<string>
int main(){
  std::string in;
  int cnt;
  while(1){
    cnt = 0;
    std::cin >> in;
    if(in[0] == '0') break;
    for(int i=0; i<in.length(); i++) cnt += in[i] - '0';
    std::cout << cnt << std::endl;
  }
  return 0;
}

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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Mll = M<ll, ll>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin(),ie=(c).rend();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n;
string s;

int main() {
    cin >> n >> s;
    Vi r(n+1), g(n+1), b(n+1);
    r[n] = 0; g[n] = 0; b[n] = 0;
    RREP(i, n-1, 0) {
        r[i] = r[i+1];
        g[i] = g[i+1];
        b[i] = b[i+1];
        switch (s[i]) {
            case 'R':
                r[i]++;
                break;
            case 'G':
                g[i]++;
                break;
            case 'B':
                b[i]++;
                break;
        }
    }

    ll res = 0;
    REP(i, n) REP2(j, i+1, n) {
        if (s[i] == s[j]) continue;
        int x = j + abs(j-i);
        V<char> c = {s[i], s[j]};
        sort(ALL(c));
        if (c[0] == 'B' && c[1] == 'G') {
            res += r[j+1];
            if (x < n && s[x] == 'R') res--;
        } else if (c[0] == 'B' && c[1] == 'R') {
            res += g[j+1];
            if (x < n && s[x] == 'G') res--;
        } else {
            res += b[j+1];
            if (x < n && s[x] == 'B') res--;
        }
    }
    cout << res << '\n';

    return 0;
}


Measured memory_bytes: 3676
///B - Tap Dance

#include<bits/stdc++.h>
using namespace std;
#define ll long long

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

 /* char odd[3]={'R','U','D'};
  char even[3]={'L','U','D'};

  string str;

  cin>>str;

  int flag_odd=0,flag_even=0;

  for(int i=0;i<str.size();i++)
  {
      if(i%2==0)
      {
          for(int j=0;j<3;j++)
          {
              if(str[i]==odd[j])
              {
                  flag_odd++;
              }
          }

      }
      else if(i%2==1)
      {
          for(int j=0;j<3;j++)
          {
              if(str[i]==even[j])
              {
                  flag_even++;
              }
          }

      }
  }

  if(flag_even+flag_odd==str.size())
  {
       cout<<"Yes"<<"\n";

  }
  else
  {
      cout<<"No"<<"\n";
  }
  */

  ///duplicate

  string str;
  cin>>str;

  set<char>odd;
  odd.insert('R');
    odd.insert('U');
      odd.insert('D');

  set<char>even;
  even.insert('L');
  even.insert('U');
  even.insert('D');

  for(int i=0;i<str.size();i++)
  {
      if(i%2==0)
      {
          if(odd.count(str[i])==0)
          {
              cout<<"No"<<"\n";
              return 0;
          }

      }
      else if(i%2==1)
      {
         if(even.count(str[i])==0)
          {
              cout<<"No"<<"\n";
              return 0;
          }
      }
  }

  cout<<"Yes"<<"\n";

  return 0;
}



Measured memory_bytes: 256
def examA():
    X = I()
    X -= 400
    ans = 8 - X//200
    print(ans)
    return

def examB():
    A, B, C = LI()
    K = I()
    cnt = 0
    while(A>=B):
        B *= 2
        cnt += 1
    while(B>=C):
        C *= 2
        cnt += 1

    if cnt<=K:
        print("Yes")
    else:
        print("No")
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examB()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 10544
import java.io.PrintWriter

val pw = PrintWriter(System.out)
fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    var (n,k) = listOfInt()
    var ans = 0
    while(n>0){
        ans++
        n /= k
    }
    println(ans)
}

// 入力取得
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

// 約数のList
fun divisor(value : Long) : List<Long> {
    val max = Math.sqrt(value.toDouble()).toLong()
    return (1..max)
        .filter { value % it == 0L }
        .map { listOf(it, value / it) }
        .flatten()
        .sorted()
}

// 範囲内の素数を取得
// fromだけ指定すると戻り値の個数で素数判定ができる
fun prime(from : Long, to : Long = from) : List<Long> {
    return (from..to).filter { i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all { j ->  i % j != 0L }
    }
}

// 素因数分解
fun decom(value : Long) : List<Long>{
    if (value == 1L) return listOf(1)
    val max = Math.sqrt(value.toDouble()).toLong()
    return prime(2, max).filter { value % it == 0L }
}

// 最大公約数
fun gcd(a : Long, b : Long) : Long {
    return if (a % b == 0L) b else gcd(b, a % b)
}

// 文字列を入れ替え
fun swap(base : String, a : String, b : String) : String {
    return base.map {
        when (it) {
            a.toCharArray()[0] -> b
            b.toCharArray()[0] -> a
            else -> it.toString()
        }
    }.joinToString()
}

fun println(value : Any) {
    pw.println(value)
}

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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;
typedef pair<lli, int> pii;


int main()
{
    lli s;
    cin >> s;
    lli x = 1e9;
    cout << "0 0 " << x << " 1 ";

    lli c = (s+x-1)/x;
    lli m = s%x;
    cout << (x*c)-s << " " << c << "\n";

    return 0;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

int main()
{
  pair<pair<int, int> , int> p[100001];
  int n,m;
  cin >> n >> m;
  REP(i,m) {
    int x, y;
    cin >> x >> y;
    p[i] = make_pair(make_pair(y, x), i);
  }

  sort(p, p+m);
  pair<int,int> result[100001];
  int c[100001] = {};
  REP(i ,m) {
    result[p[i].second] = make_pair(p[i].first.second, c[p[i].first.second] + 1);
    c[p[i].first.second]++;
  }

  REP(i,m) {
    printf("%06d%06d\n", result[i].first, result[i].second);
  }
}


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

        int N = sc.nextInt();
        int[] a = new int[N];
        Map<Integer, Integer> map = new HashMap<>();
        for(int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
            map.put(i+1, a[i]);
        }
        sc.close();

        int[] b = new int[N];

        int key = 1;
        int count = 0;
        while(true){
            if(b[key-1] != 1)
                b[key-1] = 1;
            else
                break;
            key = map.get(key);
            count++;
            if(key == 2){
                System.out.println(count);
                return;
            }
        }
        System.out.println(-1);
    }
}

Measured memory_bytes: 67980
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional>
using namespace std;
#define ll long long
#define ull unsigned ll
const int N=500005;
int n;
char s[N];
int nxt[N];
int dp[N];
int main() {
	cin>>n>>s;
	for(int i=1; i<=n; i++) dp[i]=N;
	dp[0]=0;
	int cnt=0;
	for(int i=n-1; i>=0; i--) {
		if(s[i]=='1') cnt++;
		if(s[i]=='0') nxt[i]=i;
		else if (i<n-1) nxt[i]=nxt[i+1];
		else nxt[i]=n;
	}
	for(int i=0; i<n; i++) {
		if(s[i]=='0')
			dp[i+1]=min(dp[i+1], dp[i]);
		else {
			dp[i+1]=min(dp[i+1], dp[i]+1);
			if(nxt[i]==i+1) {
				for(int j=i+2; j<n&&s[j]=='1'; j++)
					dp[j+1]=min(dp[j+1], dp[i]+1);
			} else if (nxt[i]+1<n&&s[nxt[i]+1]=='1')
				dp[nxt[i]+2]=min(dp[nxt[i]+2], dp[i]+1);
		}
	}
	printf("%d\n", cnt-dp[n]);
	return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
#define N 500010

// fenwick tree
int f[N];
void init(){for(int i=0;i<=N;i++)f[i]=0;}

void add(int i, int x){for(;i<=N;i+=i&-i)f[i]+=x;}

int sum(int i)
{
    int ret=0;
    for(;i>0;i-=i&-i)ret+=f[i];
    return ret;
}

int rangesum(int l, int r){return sum(r)-sum(l-1);}
// fenwick tree

int c[N];
vector<int> ql[N],qid[N];

int ans[N];

int a[N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n,q;
    cin>>n>>q;

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

    for(int i=0;i<q;i++)
    {
        int l,r;
        cin>>l>>r;

        ql[r].push_back(l);
        qid[r].push_back(i);
    }

    for(int i=1;i<=n;i++)
    {
        if(a[c[i-1]]>0)add(a[c[i-1]],-1);
        add(i,1);
        a[c[i-1]]=i;

        for(int j=0;j<ql[i].size();j++)
        {
            ans[qid[i][j]]=rangesum(ql[i][j],i);
        }
    }

    for(int i=0;i<q;i++)cout<<ans[i]<<endl;

    return 0;
}



Measured memory_bytes: 52996
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i=1; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define rreps(i, n) for (int i=((int)(n)-1); i>0; i--)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
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 L, R;
const int mod = 2019;
vector<int> flag(mod);
int main() {
  scanf("%d%d", &L, &R);
  for (int i = 0; i < mod && L+i <= R; i++) {
    int index = (L+i) % mod;

    flag.at(index) = 1;
  }

  int ans = 1e9;
  for (int i = 0; i < mod; i++) {
    for (int j = i+1; j < mod; j++) {
      if (flag.at(i)==1 && flag.at(j)==1) {
  
        int temp = (i * j) % mod;
        chmin(ans, temp);
      }
    }
  }
  
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;


/**
 *
 * @author
 *
 *
 *
 */

public class Main {
    public static void main(String[] args) throws IOException {
        MyScanner scanner = new MyScanner();
        PrintStream out = System.out;

        Integer[] data = scanner.nextIntegerArray();

        Set<Integer> set = new HashSet<Integer>();
        set.addAll(Arrays.asList(data));

        out.println(set.size());

        scanner.reader.close();
        out.close();
    }

    // -----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader reader;

        public MyScanner() {
            this.reader = new BufferedReader(new InputStreamReader(System.in));
        }

        public void close() throws IOException {
            this.reader.close();
        }

        int nextInt() {
            return Integer.parseInt(this.next());
        }

        long nextLong() {
            return Long.parseLong(this.next());
        }

        double nextDouble() {
            return Double.parseDouble(this.next());
        }

        String next() {
            String str = "";
            try {
                str = this.reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        String[] nextStringArray() {
            String[] str = null;
            try {
                str = this.reader.readLine().trim().split(" ");
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int[] nextIntArray() {
            String[] data  = nextStringArray();
            int[] a  = new int[data.length];

            for (int i = 0; i < a.length; i++) {
                a[i] = Integer.parseInt(data[i]);
            }

            return a;
        }

        Integer[] nextIntegerArray() {
            String[] data  = nextStringArray();
            Integer[] a  = new Integer[data.length];

            for (int i = 0; i < a.length; i++) {
                a[i] = Integer.parseInt(data[i]);
            }

            return a;
        }

        long[] nextLongArray() {
            String[] data  = nextStringArray();
            long[] a  = new long[data.length];

            for (int i = 0; i < a.length; i++) {
                a[i] = Long.parseLong(data[i]);
            }

            return a;
        }
    }
}



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

char incrementChar(char x){
    return static_cast<char>(x + 1);
}

int weekToInt(string x){
    int num;
    if(x == "SUN"){
        num = 1;
    }else if(x == "MON"){
        num = 2;
    }else if(x == "TUE"){
        num = 3;
    }else if(x == "WED"){
        num = 4;
    }else if(x == "THU"){
        num = 5;
    }else if(x == "FRI"){
        num = 6;
    }else if(x == "SAT"){
        num = 7;
    }else{
        num = 0;
    }

    return num;
}

int main(){
    int A, B;
    cin >> A >> B;

    vector<int> v;
    auto it = v.begin();

    it = v.insert(it, A + B);
    it = v.insert(it, A - B);
    it = v.insert(it, A * B);

    int max = *max_element(v.begin(), v.end());
    cout << max << endl;

    return 0;
}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
l = [*1..n]
ps = 0
pe = n-1
flg = false
m.times do
  if n.even? && !flg && pe - ps <= n / 2
    pe -= 1
    flg = true
  end
  puts [l[ps], l[pe]].join(' ')
  ps += 1
  pe -= 1
end

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

int main(){
    int n, k, x, y, sum=0;
    cin >> n >> k >> x >> y;

    for(int i=1; i<=n; i++){
        if(i <= k) sum += x;
        else sum += y;
    }
    cout << sum;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
    int n,x;
    
    while(std::cin >> n >> x){
        if(!n&&!x) break;
        
        int cnt = 0;
        for(int i = 1 ; i <= n ; i++){
            for(int j = i+1 ; j <= n ; j++){
                for(int k = j+1 ; k <= n ; k++){
                    if(i+j+k == x) cnt++;
                }
            }
        }
        std::cout << cnt << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1160
import java.io.*;
import java.util.*;

/**
 * @author baito
 */
class UnionFindTree
{
    int[] par;
    int[] rank;
    int[] sizes;

    UnionFindTree(int n)
    {
        par = new int[n];
        rank = new int[n];
        sizes = new int[n];
        for (int i = 0; i < n; i++)
        {
            par[i] = i;
            sizes[i] = 1;
        }
    }

    int root(int x)
    {
        if (par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {
        x = root(x);
        y = root(y);

        if (x == y) return;
        if (rank[x] < rank[y])
        {
            par[x] = y;
            sizes[y] += sizes[x];
        }
        else
        {
            par[y] = x;
            sizes[x] += sizes[y];
            if (rank[x] == rank[y]) rank[x]++;
        }
    }

    boolean isSame(int x, int y)
    {
        return root(x) == root(y);
    }

    int size(int x)
    {
        return sizes[par[x]];
    }
}

public class Main
{
    static StringBuilder sb = new StringBuilder();
    static Scanner sc = new Scanner(System.in);
    static int INF = 12345678;
    static long LINF = 123456789123456789L;
    static long MINF = -123456789123456789L;
    static long MOD = 1000000007;
    static int[] y4 = {0, 1, 0, -1};
    static int[] x4 = {1, 0, -1, 0};
    static int[] y8 = {0, 0, 1, 0, -1, -1, 1, 1, -1};
    static int[] x8 = {0, 1, 0, -1, 0, 1, -1, 1, -1};
    static long[] F;//factorial
    static boolean[] isPrime;
    static int[] primes;
    static char[][] map;

    static int N, K, L;
    static int[] A;


    public static void main(String[] args)
    {
        N = sc.nextInt();
        K = sc.nextInt();
        L = sc.nextInt();
        UnionFindTree u1 = new UnionFindTree(N);
        UnionFindTree u2 = new UnionFindTree(N);
        for (int i = 0; i < K; i++)
            u1.unite(sc.nextInt() - 1, sc.nextInt() - 1);
        for (int i = 0; i < L; i++)
            u2.unite(sc.nextInt() - 1, sc.nextInt() - 1);

        Map<Long, Integer> map = new HashMap<>();

        for (int i = 0; i < N; i++)
        {
            int r1 = u1.root(i);
            int r2 = u2.root(i);
            Long key = getHashKey(r1, r2);
            Integer v = map.get(key);
            map.put(key, v == null ? 1 : v + 1);
        }
        int[] cous = new int[N];
        for (int i = 0; i < N; i++)
        {
            int r1 = u1.root(i);
            int r2 = u2.root(i);
            Long key = getHashKey(r1, r2);
            System.out.println(map.get(key));
        }
    }

    public static long getHashKey(int a, int b)
    {
        return (long) a << 32 | b;
    }


}


Measured memory_bytes: 151236
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A=0, B=0, C=0;
  cin >> A >> B >> C;
  bool flg=false;
  
  for(int i=1;i<=B;i++){
    int x=A*i;
    if(x%B==C){
      flg=true;
      break;
    }
  }
  
  if(flg){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#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>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

ll x;
ll solve(){
    ll n=100;
    ll cnt=0;
    while(n<x){
        n=n*1.01;
        cnt++;
    }
    return cnt;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>x;
    cout<<solve()<<endl;
    return 0;
}

Measured memory_bytes: 3652
n,m = [int(x) for x in input().split()]
a = []
for _ in range(m):
    a.append([int(x) for x in input().split()])
a.sort(key=lambda x: x[1])
ans = 0
r = 0
for i in range(m):
    if r<=a[i][0]:
        r = a[i][1]
        ans+=1
print(ans)

Measured memory_bytes: 64556
n, m = map(int, input().split())
c = [1] * n
dp = [False] * n
dp[0] = True
for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    if dp[x]:
        dp[y] = True
        if c[x] == 1:
            dp[x] = False
    c[x] -= 1
    c[y] += 1
print(dp.count(True))

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

int main() {
    string s; cin >> s;
    switch(s.size()) {
        case 2:
            cout << s << endl;
            return 0;
        case 3:
            reverse(s.begin(), s.end());
            cout << s << endl;
            return 0;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define mod 1000000007 
#define check exit(0)
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace __gnu_pbds;
using namespace std;

int main()
{
    jaldi
    int n,m;
    cin>>n>>m;
    ll ans=(n*(n-1))/2 + (m*(m-1))/2;
    cout<<ans;
    return 0;
}


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

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	sort(a.begin(), a.end(), greater<ll>());
	ll tate = 0;
	ll yoko = 0;
	ll idx_tate = 0;
	bool flag_tate = false;
	rep(i,n-1) {
		if (a[i] == a[i+1]) {
			if (!flag_tate) {
				tate = a[i];
				i++;
				flag_tate = true;
			}
			else {
				yoko = a[i];
				break;
			}
		}
	}
	cout << tate*yoko << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(ll i = 0; i < (ll )(n); i++)
#define repi(i,a,b) for(ll i=ll (a);i<ll (b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

ll mo[6]={1,10,9,12,3,4};
ll mod=1e9+7;
int  main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin>>s;
  ll cnt=0;
  vector<ll > dp(13);
  rep(i,13)dp[i]=0;
  reverse(all(s));

  for(auto c:s)
  {
    ll di=c-'0';
    vector<ll >ndp(13);
    if(cnt==0)
    {
      if(c=='?')
      {
        rep(i,10)dp[i]++;
      }
      else
      {
        dp[di]++;
      }
      cnt++;
      continue;
    }
    if(c=='?')
    {
      rep(i,10)
      {
        ll ni=i*mo[cnt%6];
        rep(j,13)
        {
          ndp[(ni+j)%13]+=dp[j];
          ndp[(ni+j)%13]%=mod;
        }
      }
    }
    else
    {
      ll i=di;
      rep(j,13)
      {
        ll ni=i*mo[cnt%6];
        ndp[(ni+j)%13]+=dp[j];
        ndp[(ni+j)%13]%=mod;
      }
    }
    dp=ndp;
    cnt++;
  }
  cout<<dp[5]<<endl;

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;

int main()
{
    int N, K;
    std::cin >> N >> K;
    if (K == 1) {
        std::cout << 1 << std::endl;
        return 0;
    }

    double sum = 0.0;
    for (int i = 1; i <= N; i++) {
        int j = i;
        int toss_num = 0;
        while (true) {
            if (j >= K) {
                break;
            }
            toss_num++;
            j *= 2;
        }
        sum += std::pow(0.5, toss_num);
    }
    std::cout << std::setprecision(12) << sum / N << std::endl;
    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
int n,a[200020];
bool check(int w)
{
	map<int,int>s;
	int len=0;
	for(int i=1;i<=n;++i)
	{
		if(a[i]>a[i-1])len=a[i];
		else
		{
			while(s.size()&&s.rbegin()->first>a[i])s.erase(s.rbegin()->first);
			len=a[i];++s[len];
			int x=len;
			while(s[x]==w)
			{
				if(x==1)return 0;
				s[x]-=w;
				++s[x-1];
				--x;
			}
		}
	}
	return 1;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	bool flag=0;
	for(int i=1;i<n;++i)if(a[i]>=a[i+1])flag=1;
	if(!flag)return printf("1"),0;
	int l=2,r=n,mid;
	while(l<r)
	{
		mid=l+r>>1;
		if(check(mid))r=mid;
		else l=mid+1;
	}
	printf("%d",l);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
double  r;
    cin >> r;

    cout << fixed << setprecision(8) <<(M_PI*r*r) << " "
         << fixed << setprecision(8) << (M_PI*2*r) << endl;

}

Measured memory_bytes: 3276
n, k = map(int, input().split())

# ①nCrの各項のmod(10^9+7)を事前計算
p = 10 ** 9 + 7
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, 2*n):
  fact.append((fact[-1] * i) % p)
  inv.append((-inv[p % i] * (p // i)) % p)
  factinv.append((factinv[-1] * inv[-1]) % p)

# ②事前計算した項を掛け合わせ
def cmb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fact[n] * factinv[r] * factinv[n-r] % p

rlt = 0
m = min(n,k+1)
for i in range(m):
  rlt += cmb(n-1,n-1-i,p)*cmb(n,i,p) % p
  rlt %= p
  
print(rlt)

Measured memory_bytes: 162568
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    string S;
    cin >> S;
    rep(i,3){
        cout << S[i];
    }
    cout << endl;
}

Measured memory_bytes: 3588
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Contest.B
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			int n = cin.NextInt();
			int m = cin.NextInt();
			int c = cin.NextInt();
			var b = cin.ArrayInt(m);
			int ans = 0;
            for (int i = 0; i < n; i++)
            {
				var a = cin.ArrayInt(m);
				int hoge = c;
                for (int j = 0; j < m; j++)
                {
					hoge += a[j] * b[j];
                }
				if (hoge > 0) ans++;
            }
            Console.WriteLine(ans);

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 11092
import math

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n = int(input())

if n == 1 or n == 2:
    print(0)
    exit()

root_n = int(math.sqrt(n))

ans = 0
for mod in range(1, root_n+1):
    if (n - mod) % mod == 0:
        a = (n - mod) // mod
        #if a != 1 and a < n:
        if n % a == mod:
            #print(a)
            ans += a

print(ans)


Measured memory_bytes: 40300
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }
fn main() {
    input!(k: u64);

    let mut m7 = 7 % k;
    for i in 0..k {
        if m7 == 0 {
            println!("{}", i + 1);
            return ();
        }
        m7 = (m7 * 10 + 7) % k;
    }

    println!("-1");
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline 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 h,w; cin >> h >> w;
  vector<string> s(h); rep(i,h) cin >> s[i];
  vector<vi> l(h,vi(w)), r(h,vi(w)), u(h,vi(w)), d(h,vi(w));
  rep(i,h){
    rep(j,w){
      if(s[i][j] == '#') l[i][j] = 0;
      else{
        if(!j) l[i][j] = 1;
        else l[i][j] = l[i][j-1]+1;
      }
    }
  }
  rep(i,h){
    for(int j = w-1; 0 <= j; j--){
      if(s[i][j] == '#') r[i][j] = 0;
      else{
        if(j == w-1) r[i][j] = 1;
        else r[i][j] = r[i][j+1]+1;
      }
    }
  }
  rep(j,w){
    rep(i,h){
      if(s[i][j] == '#') u[i][j] = 0;
      else{
        if(!i) u[i][j] = 1;
        else u[i][j] = u[i-1][j]+1;
      }
    }
  }
  rep(j,w){
    for(int i = h-1; 0 <= i; i--){
      if(s[i][j] == '#') d[i][j] = 0;
      else{
        if(i == h-1) d[i][j] = 1;
        else d[i][j] = d[i+1][j]+1;
      }
    }
  }
  int ans = 0;
  rep(i,h) rep(j,w) chmax(ans,l[i][j]+r[i][j]+d[i][j]+u[i][j]-3);
  cout << ans;
  cout << "\n";
  return 0;
}


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

using namespace std;
 
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000000000
#define MAXN        100005
#define mod         998244353  
 
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll k,i;
    string s;
    cin>>k>>s;
    if(s.size()<=k){
        cout<<s;
    }
    else{
        for(i=0;i<k;i++){
            cout<<s[i];
        }
        cout<<"...";
    }
}

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

#define ll long long
#define pi pair<int,int>
#define ppi pair<pi,pi>
#define mp make_pair
#define fr first
#define sc second

using namespace std;
int  k;
ll P[11];
ll Ans = 0;
bool solve(int i,int pre){
    if(i < 0){
        k--;
        return (k == 0);
    }
    for(int j = max(0 , pre - 1);j <= min(9 , pre + 1);j++ ){
        if(solve(i - 1, j))
        {
           Ans += P[i] * j;
           return 1;
        }
    }
    return 0;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0) , cout.tie(0);
    P[0] = 1;
    for(int i = 1;i < 11;i++)P[i] = P[i - 1] * 10;
    cin >> k;

    for(int Len = 0;;Len++){
        for(int j = 1;j < 10;j++){
            if(solve(Len - 1 , j)){
                Ans += P[Len] * j;
                cout << Ans << '\n';
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            int r = sc.nextInt();
            if ((n|r) == 0) {
                break;
            }
            ArrayList<Integer> list = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                list.add(0, i + 1);

            }
            for (int i = 0; i < r; i++) {
                // for (int j = 0; j < list.size(); j++) {
                //     System.out.print(list.get(j) + " ");
                // }
                // System.out.println();
                int p = sc.nextInt() - 1;
                int c = sc.nextInt();
                for (int j = 0; j < c; j++) {
                    int k = list.remove(j + p);
                    list.add(j, k);
                }
            }
            System.out.println(list.get(0));
        }
    }
}

Measured memory_bytes: 37728
#include<bits/stdc++.h>
using namespace std;int n,k;typedef long long ll;ll ans;
ll sqr3(ll x){return x*x*x;}
int main()
{
    cin>>n>>k;ans=sqr3(n/k);
    if(k%2==0&&n>=k/2){
        ans+=sqr3((n-k/2)/k+1);
    }cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define fr(i,n,m) for(ll i=n;i<m;i++)
int compare_int(const void *a, const void *b)
{
    return *(int*)a-*(int*)b;
}
int main()
{
    ll n,ans=0;
    scanf("%lli",&n);
    ll l[n];
    fr(i,0,n) {
        scanf("%lli",&l[i]);
    }
    qsort(l, n, sizeof(ll),compare_int);
    fr(i,0,n){
        fr(j,i,n) {
            if (l[i]<l[j]) {
                fr(k,j,n){
                    if(l[j]<l[k] && l[k]<l[i]+l[j]) {
                        ans++;
                    }
                }
            }
        }
    }
    printf("%lli",ans); 
    return 0;
}

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

using namespace std;

long long n, a[100005], sum = 0, b[100005];

int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    if(sum %( n * (n + 1) / 2) != 0){
        cout << "NO\n";
        return 0;
    }
    long long num = sum / (n * (n + 1) / 2);
    for(int i = 0; i < n; i++){
        b[i] = -a[(i + 1)%n] + a[i] + num;
        if(b[i] >= 0 && b[i] % n == 0){

        }
        else{
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //


int main() {
	in(ll, N, K);
	vector<ll> minus, plus;
	loop(i, N) {
		ll tmp;
		cin >> tmp;
		if (tmp == 0)
			--K;
		else if (tmp < 0)
			minus.push_back(-tmp);
		else if (tmp > 0)
			plus.push_back(tmp);
	}
	if(!minus.empty()) sort_v(minus);
	if (!plus.empty()) sort_v(plus);
	ll ans = INF;
	auto check = [&](ll l, ll r) {
		return 0 <= l && l <= minus.size() && 0 <= r && r <= plus.size();
	};
	auto sub = [&](ll r) {
		ans = std::min(ans, r);
	};
	if (minus.empty() && plus.empty())
		ans = 0;
	if (0 <= K && K <= plus.size() && K)
		sub(plus[K-1]);
	if (0 <= K && K <= minus.size() && K)
		sub(minus[K-1]);
	loop(i, K + 1) {
		if (i && K - i) {
			if (check(i, K - i)) {
				sub(minus[i - 1] + plus[K - i - 1] * 2);
				sub(minus[i - 1] * 2 + plus[K - i - 1]);
			}
		}
	}
	out(ans);
	return 0;
}


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

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb emplace_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
ll dx[4] = {1,0,-1,0};
ll dy[4] = {0,1,0,-1};

int main(){
    ll n,k,ans=0;cin>>n>>k;
    vll v(n);
    rep(i,n) cin>>v[i];
    ll r=min(n,k);
    rep(p,r+1){
        for (int q = 0; p + q <= r; ++q){
            ll cur=0;
            vll x;
            rep(i,p) x.pb(v[i]), cur+=v[i];
            //cout<<cur<<endl;
            rep(i,q) x.pb(v[n-1-i]), cur+=v[n-1-i];
            //cout<<cur<<endl;
            sort(all(x));
            //for(auto z:x)cout<<z<<" ";
            //puts("");
            rep(i,min((ll)x.size(),k-p-q)) if(x[i]<0)cur-=x[i];
            ans=max(ans,cur);
            //cout<<"p:q:ans -> "<<p<<" "<<q<<" "<<cur<<endl;
        }
    }
    cout<<ans<<endl;
}  


Measured memory_bytes: 256
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var p = o.r(n);
  return p.reduce((a,b)=>a+b) - Math.max(...p) / 2;
}

Measured memory_bytes: 21064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  bool flag=true;
  rep(i,n){
    if(a[i]%2==0){
      if(a[i]%3==0||a[i]%5==0){
        continue;
      }
      flag=false;
    }
  }
  if(flag)cout<<"APPROVED"<<endl;
  else cout<<"DENIED"<<endl;
  return 0;
}


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

class C
{
    static void Main()
    {
        Console.ReadLine();
        var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var b = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        var x = 0L;
        for (var i = 0; i < b.Length; i++)
        {
            var m = Math.Min(a[i], b[i]);
            x += m;
            b[i] -= m;
            var n = Math.Min(a[i + 1], b[i]);
            x += n;
            a[i + 1] -= n;
        }
        Console.WriteLine(x);
    }
}


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


int main(){
    string a,b,c;
    cin>>a>>b>>c;

    cout<<(char)(a[0] - 'a' + 'A')<<(char)(b[0] - 'a' + 'A')<<(char)(c[0] - 'a' + 'A')<<endl;

    return 0;
}


Measured memory_bytes: 256