akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;

int main(void)
{
    //string a,b;
    int a,b,c,d;
    int i=0;
    //char a,b='.';
    cin>>a>>b>>c>>d;
    cout<<(min(a,b)+min(c,d));
    return 0;
}



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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n;
    cin >> n;
    if (n == 3) {
        cout << "2 5 63" << '\n';
    } else if (n == 4) {
        cout << "2 5 20 63" << '\n';
    } else if (n == 5) {
        cout << "2 5 20 30 63" << '\n';
    } else {
        vector<int> res;
        ll sum = 0;
        int i = 2;
        for ( ; i<=30000 && (int)res.size()<n; ++i) {
            if (i%2 == 0 || i%3 == 0) {
                sum += i;
                res.push_back(i);
            }
        }
        int del = -1;
        if (sum%6 == 2) {
            del = 8;
            while (i%6 != 0) ++i;
            res.push_back(i);
        } else if (sum%6 == 3) {
            del = 9;
            while (i%6 != 0) ++i;
            res.push_back(i);
        } else if (sum%6 == 5) {
            del = 9;
            while (i%6 != 4) ++i;
            res.push_back(i);
        }
        for (int j=0; j<(int)res.size(); ++j) {
            if (res.at(j) != del) {
                cout << res.at(j);
            }
            if (j == (int)res.size()-1) cout << '\n';
            else cout << ' ';
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  string s,in;
  int co=0;
  cin>>s;
  rep(i,s.size())s[i]=tolower(s[i]);
  while(cin>>in,in!="END_OF_TEXT"){
    rep(i,in.size())in[i]=tolower(in[i]);
    if(in==s)co++;
  }
  cout<<co<<endl;
}

Measured memory_bytes: 1192
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
ans = 0
p = 0
for i in range(N):
    ans = 0
    ans += C
    A = list(map(int,input().split()))
    for j in range(M):
        ans += (A[j]*B[j])
    if ans>0:
        p += 1
print(p)

Measured memory_bytes: 3064
n = gets.chomp.to_i
pi = gets.chomp.split(' ').map(&:to_i)
pi.unshift(nil)
pa = Array.new(pi.size, false)
ans = 0

pi.each_with_index do |a, i|
  next if a.nil?
  pa[i] = true if a != i
end

for i in 1..(pa.size-1) do
  if pa[i] == false
    t = pi[i]
    pi[i] = pi[i+1]
    pi[i+1] = t
    pa[i] = true
    if pi[i+1] == i+1
      pa[i+1] = false
    else
      pa[i+1] = true
    end
    ans += 1
  end
end

puts ans


Measured memory_bytes: 11916
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n, k;
	cin >> n >> k;
	vector<int>a(n);
	for(int i=0; i<n; i++)
		cin >> a[i];
	multiset<int> st;
	for(int i=0; i<k; i++){
		st.insert(a[i]);
	}
	int left = 0;
	for(int i=k; i<n; i++){
		int prev = a[left++];
		int cur = a[i];
		if(cur > prev)
			cout << "Yes\n";
		else
			cout << "No\n";
		auto itr = st.find(prev);
		st.erase(itr);
		st.insert(cur);
	}
	return 0;
}

Measured memory_bytes: 13492
#include<bits/stdc++.h>
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    char s[3];
    int a=0,b=0,c=0;
    scanf("%s",s);
    if(s[0]=='o')
    {
        a=100;

    }
    if(s[1]=='o')
    {
        b=100;

    }
    if(s[2]=='o')
    {
        c=100;

    }

    cout<<700+a+b+c<<endl;

    return 0;
}



Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var n=arr.shift()-0;
while(n--){
   var xy=[0,0];
   var max=[0,0,0];
   while(true){
      var str=arr.shift();
      if(str=="0 0")break;
      var ary=str.split(" ").map(Number);
      xy[0]+=ary[0];
      xy[1]+=ary[1];
      var d=Math.sqrt(xy[0]*xy[0]+xy[1]*xy[1]);
      if(max[0]<d)max=[d,xy[0],xy[1]];
      else if(max[0]==d && max[1]<xy[0])max=[d,xy[0],xy[1]];
      }
   max.shift();
   console.log(max.join(" "));
}

Measured memory_bytes: 17656
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  if(s[n-1] == 's') {
    s.push_back('e');
    s.push_back('s');
  } else s.push_back('s');
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl

using namespace std;
typedef long long  ll;

const long long MOD = 1e9+7;

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

    int ans_0, ans_1;
    if(n == 0 or n == 1){
        ans_0 = 0;
    } else {
        ans_0 = n*(n-1)/2;
    }

    if(m == 0 or m == 1){
        ans_1 = 0;
    } else {
        ans_1 = m*(m-1)/2;
    }

    p(ans_0+ans_1);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C& _a4, C _b4) { _a4 = min(_a4, _b4); }
template<class C> void maxi(C& _a4, C _b4) { _a4 = max(_a4, _b4); }

template<class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
	while (*sdbg != ',')cerr << *sdbg++; cerr << '=' << h << ','; _dbg(sdbg + 1, a...);
}

template<class T> ostream& operator<<(ostream& os, vector<T> V) {
	os << "["; for (auto& vv : V) os << vv << ","; os << "]";
	return os;
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
	return os << "(" << P.st << "," << P.nd << ")";
}


#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#endif

int32_t main(int32_t argc, char ** argv) {
	ios_base::sync_with_stdio(0);
	int q, h, s, d;
	cin >> q >> h >> s >> d;
	s = min({ s, q * 4, h * 2});
	d = min({ d, 2 * s });
	int n;
	cin >> n;
	int res = (n / 2) * d + (n & 1) * s;
	cout << res << "\n";

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
if(a<=5){
  cout<<0<<endl;
}else if(6<=a&&a<=12){
	cout<<b/2<<endl;
	}
  else if(a>=13){
    cout<<b<<endl;
  }
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N, R; cin >> N >> R;
    if(N < 10) R += 100 * (10 - N);
    Out(R);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;


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

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

  for(i=1;i<n-1;i++){
    a[i] = min(b[i-1],b[i]);
  }
  a[n-1] = b[n-2];

  int sum = 0;
  for(i=0;i<n;i++){
    sum += a[i];
  }
  cout << sum << endl;


}


Measured memory_bytes: 256
n, k = map(int,input().split())
f = [int(x)-1 for x in input().split()]

def tortoise_and_hare(s,f):
    tortoise = f[s]
    hare = f[f[s]]

    while tortoise != hare:
        tortoise = f[tortoise]
        hare = f[f[hare]]

    rho = 0
    tortoise = s
    while tortoise != hare:
        tortoise = f[tortoise]
        hare = f[hare]
        rho += 1

    lamb = 1
    hare = f[hare]

    while tortoise != hare:
        hare = f[hare]
        lamb += 1

    return rho,lamb

rho, lamb = tortoise_and_hare(0,f)

if k <= rho:
    s = 0
    for i in range(k):
        s = f[s]
else:
    s = 0
    for i in range(rho):
        s = f[s]
    k = (k-rho)%lamb
    for i in range(k):
        s = f[s]

print(s+1)


Measured memory_bytes: 100236
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>

using namespace std;
 
typedef long long i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	i64 from, to, cost;
	edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
	edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

//-----end of template-----//

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	i64 n;
	cin >> n;
	vector<i64> a(n), b(n);
	for(int i = 0; i < n; ++i) cin >> a[i];
	for(int i = 0; i < n; ++i) cin >> b[i];
	vector<i64> sorted(n);
	for(int i = 0; i < n; ++i){
		sorted[i] = a[i] - b[i];
	}
	sort(sorted.begin(), sorted.end());
	i64 cnt, sum;
	cnt = sum = 0;
	for(int i = 0; i < n; ++i){
		if(sorted[i] >= 0) break;
		else{
			cnt++;
			sum += sorted[i];
		}
	}
	bool flag = false;
	for(int i = n - 1; i >= 0; --i){
		if(sum >= 0){
			flag = true;
			break;
		}
		if(sorted[i] < 0) break;
		else{
			cnt++;
			sum += sorted[i];
		}
	}
	if(flag){
		cout << cnt << endl;
	}else{
		cout << -1 << endl;
	}
}

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

using namespace std;

void fast();

/*
*
* Watch out! Another Buggy Code From Muhammad_Mamdouh, Happy Coding;
*
*/

int main()
{
    fast();
    string s, x; cin >> s >> x;

    int cnt = 0;
    for (int i = 0; i < s.size(); ++i)
    {
        if (s[i] != x[i])
            ++cnt;
    }

    cout << cnt;

    return 0;
}

void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

Measured memory_bytes: 3788
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    vector<int> s[301];
    int t[101] = {};
    int ans[101] = {};
    int n; scanf("%d", &n);

    for (int i = 0; i < n * (n - 1) / 2; ++i) {
        int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);
        if (c > d)
            t[a] += 3;
        else if (d > c)
            t[b] += 3;
        else
            t[a] += 1, t[b] += 1;
    }

    for (int i = n; i >= 0; --i) s[t[i]].push_back(i);

    int r = 1;

    for (int i = 300; i >= 0; --i) {
        int cnt = 0;
        while (s[i].size()) {
            ans[s[i].back()] = r;
            s[i].pop_back();
            cnt++;
        }
        r += cnt;
    }

    for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
}

Measured memory_bytes: 1060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    ll N;cin>>N;
    ll ans=0;
    for(ll i=1;i*(i+2)<=N;i++){
        if(N%i==0)ans+=N/i-1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		double N=stdIn.nextDouble();
		int A=(int)N;
		if(N%2==0)
			System.out.println(0.5);
		else
			System.out.println((A/2+1)/N);
	}
}


Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <stdio.h>
#include <ctype.h>
#include <algorithm>
#include <stdlib.h>
#include <stack>
#include <queue>
#include <bitset>
#include <memory.h>

using namespace std;



int sosuu(int x){
    for(int i=2; i<=sqrt(x); i++){
        if(x%i==0)return 0;
    }
    return 1;
}


int main() {
    
    int x, y;
    int sum=0;
    int all=0;
    int cou=0;
    while(scanf("%d,%d",&x,&y)!=EOF){
        sum+=x*y;
        all+=y;
        cou++;
    }
    cout<<sum<<endl;
    cout<<(int)(((double)all)/cou+0.9)<<endl;
    return 0;
}

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

long long n;
vector<long long> a;

long long solve(int x);

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x; //項の一つ一つ
    a.push_back(x);
  }
  cout << min(solve(0), solve(1)) << endl;
  return 0;
}

long long solve(int x) { //引数は0か1
  long long ans = 0, now = 0;

  for(long long i = 0; i < n; ++i) {
    now += a[i]; //累積和

    if((i % 2 == x) && (now >= 0)) {
      ans += now + 1;
      now = -1;
    }
    if(!(i % 2 == x) && (now <= 0)) {
      ans -= now - 1;
      now = 1;
    }
  }
  return ans;
}


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

int main(){
  int n, x, y; cin >> n >> x >> y;
  vector<vector<int> > v(n + 1);
  for(int i = 1; i < n; i++){
    v[i].push_back(i + 1);
    v[i + 1].push_back(i);
    if(i == x){
      v[i].push_back(y);
      v[y].push_back(i);
    }
  }

  /*for(int i = 1; i <= n; i++){
    for(int j = 0; j < v[i].size(); j++){
      cout << v[i][j] << " ";
    }
    cout << endl;
  }*/

  vector<vector<int> > dis(n + 1, vector<int>(n + 1, 2000));
  for(int i = 1; i <= n; i++){
    queue<int> q;
    q.push(i);
    vector<bool> visted(n + 1, false);
    visted[i] = true;
    dis[i][i] = 0;
    while(q.size() > 0){
      int f = q.front(); q.pop();
      for(int j = 0; j < v[f].size(); j++){
        if(visted[v[f][j]] == false){
          q.push(v[f][j]);
          visted[v[f][j]] = true;
          dis[i][v[f][j]] = min(dis[i][v[f][j]], dis[i][f] + 1);
        }
      }
    }
  }
  vector<int> ans(n + 1, 0);
  for(int i = 1; i <= n; i++){
    //cout << i << "->";
    for(int j = i + 1; j <= n; j++){
      //cout << dis[i][j] << " ";
      ans[dis[i][j]]++;
    }
    //cout << endl;
  }
  for(int i = 1; i < n; i++) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 16128
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<set>
#include<iomanip>
using namespace std;
int main()
{
	int n,m,d,ans;cin>>n>>m;
	pair<int,int> a[55],c[55];
	for(int i=1;i<=n;i++)cin>>a[i].first>>a[i].second;
	for(int i=1;i<=m;i++)cin>>c[i].first>>c[i].second;
	for(int i=1;i<=n;i++)
	{
		ans=0;
		d=1<<30;
		for(int j=m;j>=1;j--)
		{
			if(d>=abs(a[i].first-c[j].first)+abs(a[i].second-c[j].second))
			{
				ans=j;
				d=abs(a[i].first-c[j].first)+abs(a[i].second-c[j].second);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 632
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

constexpr int MOD = 1000000007;

template <int MAX_N>
class UnionFind {
public:
    int parent[MAX_N];
    int rank[MAX_N];
    int size[MAX_N];

    UnionFind(int n) {
        for (int j = 0; j < n; ++j) {
            parent[j] = j; rank[j] = 0;
            size[j] = 1;
        }
    }

    int find(int x) {
        if (parent[x] == x) { return x; }
        return parent[x] = find(parent[x]);
    }

    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) { return false; }

        if (rank[x] < rank[y]) {
            parent[x] = y;
            size[y] += size[x];
        } else {
            parent[y] = x;
            if (rank[x] == rank[y]) {
                ++rank[x];
            }
            size[x] += size[y];
        }

        return true;
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int N, M;

vector<int> speaker[100000];
UnionFind<100001> uf(100000);

int main() {
    cin >> N >> M;
    for (int j = 0; j < N; ++j) {
        int k;
        cin >> k;
        for (int l = 0; l < k; ++l) {
            int v;
            cin >> v;
            speaker[--v].push_back(j);
        }
    }

    for (int j = 0; j < M; ++j) {
        for (int k = 0; k < (int)speaker[j].size()-1; ++k) {
            uf.unite(speaker[j][k], speaker[j][k+1]);
        }
    }

    if (uf.size[uf.find(0)] == N) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }


    return 0;
}


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

using namespace std;
  
int main() {
  int N;
  map<int, long, greater<long>> m;

  cin >> N;
  
  for(int i=0; i<N; i++){
    int h;
    cin >> h;
    m[h] = i+1; 
  }
  
  for(int i=0; i<N; i++){
    cout << m[i+1] << " ";
  }
  
  
 }

Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
int digit(int n,int k)
{
  int ret = 1;
  while(n/k!=0){
    n /= k;
    ret++;
  }
  return ret;
}


int main(){
  int n,k;cin>>n>>k;
  cout << digit(n,k) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>

#define ll long long int

using namespace std;

const int INF = (1<<30) - 1;

class Edge{
public:
    int to, dis, e;
    
    Edge(int to, int dis, int e): to(to), dis(dis), e(e){};
};

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

    int N, M, L;
    while(cin>>N>>M>>L, N|M|L){
        vector<vector<Edge>> edges(N);
        for(int i=0; i<M; i++){
            int a, b, d, e;
            cin >> a >> b >> d >> e;
            a--; b--;
            edges[a].push_back(Edge(b, d, e));
            edges[b].push_back(Edge(a, d, e));
        }
        
        vector<vector<int>> dp(N, vector<int>(L+1, INF));
        priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> q;
        
        dp[0][L] = 0;
        q.push(make_pair(dp[0][L], make_pair(0, L)));
        
        while (!q.empty()) {
            auto p = q.top(); q.pop();
            int e = p.first;
            int v = p.second.first;
            int l = p.second.second;
            if(dp[v][l] < e)
                continue;
            
            for(auto edge: edges[v]){
                if(edge.dis <= l && dp[edge.to][l-edge.dis] > e){
                    dp[edge.to][l-edge.dis] = e;
                    q.push(make_pair(e, make_pair(edge.to, l-edge.dis)));
                }
                if(dp[edge.to][l] > e+edge.e){
                    dp[edge.to][l] = e+edge.e;
                    q.push(make_pair(e+edge.e, make_pair(edge.to, l)));
                }
            }
        }
        int ans = INF;
        for(int i=0; i<=L; i++)
            ans = min(ans, dp[N-1][i]);
        cout << ans << endl;
    }
    
    return 0;
}

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

int main(){
  int N,d,ans=0;
  int p[1000];

  cin>>N>>d;
  for(int i=0;i<N;i++){
    cin>>p[i];
    ans+=max(0,p[i]-d);
  }

  if(ans>0)
    cout<<ans<<endl;
  else
    cout<<"kusoge"<<endl;
  
  return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
 
 
//答えは必ず2の累乗
int main() {
    int N; 
	cin >>N;
  	int p = N;
    int answer = 0;
    
//for文書いてiカウントしてiの数だけ2をかけるとかやるのがかっこいいんだろうけど
//力技
    if(p==1){
    answer+=1;
    }	//1は0回割れるから1が最大ってことね
  
  	else if(p>=2,p<=3){
    answer+=2;
    }
  
  	else if(p>=4,p<=7){
    answer+=4;
    }
  
  	else if(p>=8,p<=15){
    answer+=8;
    }  
  
  	else if(p>=16,p<=31){
    answer+=16;
    } 
  
  	else if(p>=32,p<=63){
    answer+=32;
    }   
  
  	else{
    answer+=64;
    }        
 
    cout << answer << endl;
    }


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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18 + 1;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N, K;

signed main() {
    cin >> N >> K;
    ll sup = (N - 1) * (N - 2) / 2;
    if(K > sup) eputs(-1);
    ll dif = sup - K;
    ll M = N - 1 + dif;
    cout << M << "\n";
    REP(i, N - 1) { cout << 1 << " " << i + 2 << "\n"; }
    ll cnt = 0;
    bool ok = false;
    if(dif > 0) {
        FOR(i, 1, N) {
            FOR(j, i + 1, N) {
                cout << i + 1 << " " << j + 1 << "\n";
                if(++cnt == dif) {
                    ok = true;
                    break;
                }
            }
            if(ok) break;
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if((x - r) < 0 | (x + r) > W){
		printf("No\n");
	} else if((y - r) < 0 | (y + r) > H){
		printf("No\n");
	} else {
		printf("Yes\n");
	}
	return 0;
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int ans = 0;
    char c[3];
    for(int i = 0;i < 3;i++){
        cin >> c[i];
        if(c[i] == 'R'){
            if(ans == 0){
                ans++;
            }
            else{
                if(c[i - 1] == 'R'){
                    ans++;
                }
            }
        }
    }
    
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 3636
//============================================================================
// Author       : Sun YaoFeng
//============================================================================

//#pragma 	comment(linker, "/STACK:100240000,100240000")
//#include	<cstdio>
//#include	<cstdlib>
//#include	<cstring>
//#include	<algorithm>

#include	<bits/stdc++.h>

using	namespace	std;

#define DB		double
#define	lf		else if
#define I64		long long
#define	Rd()	(rand()<<15|rand())
#define For(i,a,b)	for(int i=a,lim=b;i<=lim;i++)
#define Rep(i,a,b)	for(int i=a,lim=b;i>=lim;i--)

#define	fi	first
#define se	second
#define MK	make_pair
#define PA	pair<int, int>

//#define	min(a,b)	((a)<(b)?(a):(b))
//#define	max(a,b)	((a)<(b)?(b):(a))

#define	CH	(ch=getchar())
int		IN()	{
		int x= 0, f= 0, ch;
		for	(; CH < '0' || ch > '9';)	f= (ch == '-');
		for	(; ch >= '0' && ch <= '9'; CH)	x= x*10 + ch -'0';
		return	f? -x : x;
}

#define n	100005

int		N, D, C, st[n], ID[n], Dep[n];

struct	Lin{
		int v, next;
}E[n];

void	Link(int u, int v)	{
		E[++ D]= (Lin){v, st[u]};	st[u]= D;
}

bool	Cmp(int a, int b)	{
		return	Dep[a] > Dep[b];
}

void	DFS(int u)	{
		for (int i= st[u]; i; i= E[i].next)	DFS(E[i].v);
		
		C= 0;
		for (int i= st[u]; i; i= E[i].next)	ID[++ C]= E[i].v;
		sort(ID+1, ID+C+1, Cmp);
		
		For(i, 1, C)	Dep[u]= max(Dep[u], Dep[ID[i]] + i);
}

int		main(int argc, char* argv[]){
		N= IN();
		For(i, 2, N)	Link(IN(), i);
		
		DFS(1);
		printf("%d\n", Dep[1]);
		
		return	0;
}

Measured memory_bytes: 4992
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;
const int N = 205, X = 1e5+10;

int n, x;
int s[N];
alignas(32) int dp[2][X]; // dp[i][j] = # of ways to end with j, last mod i

void add(int& a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s, s + n, greater<int>());
  dp[0][x] = 1;
  for (int i = 0; i < n; i++) {
    memset(dp[1], 0, sizeof dp[1]);
    // take self
    for (int j = 0, rem = 0; j <= x; j++) {
      add(dp[1][rem], dp[0][j]);
      if (++rem == s[i]) {
        rem = 0;
      }
    }
    // don't take self
    for (int j = 0; j <= x; j++) {
      dp[1][j] = (dp[1][j] + (ll) dp[0][j] * (n - i - 1)) % MOD;
    }
    swap(dp[0], dp[1]);
  }
  int ans = 0;
  for (int i = 0; i < s[n-1]; i++) {
    ans = (ans + (ll) i * dp[0][i]) % MOD;
  }
  cout << ans << nl;
  return 0;
}


Measured memory_bytes: 1152
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    const ll MOD = 1e9 + 7;
    int N; cin >> N;
    vi A(N); REP(i, N) cin >> A[i];

    sort(A.begin(), A.end());
    bool ok = true;
    if (N%2==1) {
        if (A[0] != 0) ok = false;
        for(int i=1; i<N; i+=2) {
            if (A[i] != A[i + 1]) ok = false;
        }
    } else {
        for(int i=0; i<N; i+=2) {
            if (A[i] != A[i + 1]) ok = false;
        }
    }
    if (!ok) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    if (N%2==1) {
        for(int i=1; i<N; i+=2) {
            ans *= 2;
            ans %= MOD;
        }
    } else {
        for(int i=0; i<N; i+=2) {
            ans *= 2;
            ans %= MOD;
        }
    }

    cout <<  ans << endl;

    return 0;
}

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

using namespace std;

typedef long long LL;
#define FAST ios::sync_with_stdio(false);
const int MaxN = 105;

int main()
{
	char c;
	cin >> c;
	if(c == 'a' || c == 'e' || c == 'i' || c == 'o'|| c == 'u')
		cout << "vowel" << endl;
	else 
		cout << "consonant" << endl;
	return 0;
	}

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

using ll = long long;

void solve(long long N, std::vector<long long> a){
    vector<bitset<64>> ans(N);
    vector<vector<bool>> diff(64, vector<bool>(N));
    for(int i = 0;i < N - 1;i++){
        bitset<64> x, y;
        x = bitset<64>(a.front());
        y = bitset<64>(a[i]);
        for(int j = 0;j < 64;j++){
            diff[j][i] = x[j] == y[j];
        }
    }
    bitset<64> x = bitset<64>(a.back());
    for(int i = 0;i < 64;i++){
        int cnt = count(diff[i].begin(), diff[i].end(), true);
        if(x[i] == 1){
            if(cnt % 2 == 0){
                for(int j = 0;j < N - 1;j++){
                    if(diff[i][j] == false)ans[j][i] = 1;
                }
            }else{
                for(int j = 0;j < N - 1;j++){
                    if(diff[i][j] == true)ans[j][i] = 1;
                }
            }
        }else{
            if(cnt % 2 == 1){
                for(int j = 0;j < N - 1;j++){
                    if(diff[i][j] == false)ans[j][i] = 1;
                }
            }else{
                for(int j = 0;j < N - 1;j++){
                    if(diff[i][j] == true)ans[j][i] = 1;
                }
            }
        }
    }
    bitset<64> xo = 0;
    for(int i = 1;i < N - 1;i++){
        xo ^= ans[i];
    }
    bitset<64> y(a.front());
    for(int i = 0;i < 64;i++){
        if(y[i] != xo[i]){
            ans.back()[i] = 1;
        }else{
            ans.back()[i] = 0;
        }
    }
    for(int i = 0;i < N;i++){
        cout<<ans[i].to_ulong()<<(i != N - 1 ? " " : "");
    }
    cout<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


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

int main(){
  	int n,memo = 0;
  	cin >> n;
  
  	int a[2*n];
  	
  	rep(i,0,2*n){
      cin >> a[i];
    }
  
  	sort(a,a+2*n);
  
  	rep(i,0,n){
      memo += a[2*i];
    }
  
  	cout << memo << endl;
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef pair<int,int> PP;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define MM <<" "<<
#define Endl endl

const int maxV=314514;
struct edge{int end;int cost;};
typedef pair<int,int> P;
int V;
vector<int> d;
vector<edge> G[maxV];

void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P>> que;
    for(int i=0;i<maxV;i++){d.push_back(INF);}
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<G[v].size();i++){
            edge e = G[v][i];
            if(d[e.end]>d[v]+e.cost){
                d[e.end] = d[v]+e.cost;
                que.push(P(d[e.end],e.end));
            }
        }
    }
}


signed main(void){
    int N,M;
    int u[114514],v[114514];
    int S,T;
    
    cin >> N >> M;
    REP(i,M){
        cin >> u[i] >> v[i];
        u[i]--;v[i]--;
    }
    cin >> S >> T;
    S--;T--;
    edge h;
    REP(i,M){
        h.cost=1;
        h.end=v[i]+N;
        G[u[i]].push_back(h);
        h.end=v[i]+2*N;
        G[u[i]+N].push_back(h);
        h.end=v[i];
        G[u[i]+2*N].push_back(h);
    }
    dijkstra(S);
    if(d[T]==INF){
        cout << -1 << endl;
    }else{
        cout << d[T]/3 << endl;
    }
    return 0;
}



Measured memory_bytes: 24180
list = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ans = list.dup * 2
idx = 0
h = list.chars.inject({}) { |acc, c| acc[c] = idx; idx += 1; acc; }

n = gets.to_i
s = gets.chop.chars
a = ''
s.each do |k|
  a += ans[h[k] + n]
end

puts a

Measured memory_bytes: 28028
open Batteries
open BatPrintf

let scan fmt f =
  Scanf.sscanf (read_line ()) fmt f

let scan_list cnv =
  read_line ()
  |> String.split_on_char ' '
  |> List.map cnv

let scan_listn n cnv =
  (0 --^ n) |> Enum.map (fun _ -> (cnv % read_line) ())

let bsearch_ge arr a =
  let l = Array.length arr in
  match Array.bsearch Int.ord arr a with
  | `All_lower -> l
  | `All_bigger -> 0
  | `Just_after n -> l - n -1
  | `At n -> l - n
  | `Empty -> 0

let rec zip xs ys =
  match xs, ys with
  | [], _ -> []
  | _, [] -> []
  | x::xs, y::ys ->
    (x, y) :: zip xs ys

let square x = x * x

let dbg n =
  Printf.printf "%s\n" @@ dump n; n

module CombMemo = struct
  let prime = 1_000_000_000+7
  let size = 2*1_00_000

  let memo = let arr = Array.make size None in
    arr.(0) <- Some 1;
    arr

  let ( * ) a b = a * b mod prime
  let (-) a b = (a+prime - b) mod prime

  let rec pow n m =
    if m = 0 then 1
    else if m mod 2 = 0 then pow (n*n) (m/2)
    else n * pow (n*n) (m/2)

  let rec fact n =
    match memo.(n) with
    | None ->
      let m = n * fact (n-1) in
      memo.(n) <- Some m;
      m
    | Some a -> a

  let comb n k =
    fact n * (pow (fact k) (prime-2)) * (pow (fact (n - k)) (prime-2))
end

module Comb = struct
  let prime = 1_000_000_000+7

  let ( * ) a b = a * b mod prime
  let (-) a b = (a+prime - b) mod prime

  let rec pow n m =
    if m = 0 then 1
    else if m mod 2 = 0 then pow (n*n mod prime) (m/2)
    else n * pow (n*n mod prime) (m/2) mod prime

  let fact n =
    let rec aux m ret =
      if m = 0 then ret
      else aux (m-1) @@ (m*ret) mod prime in
    aux n 1

  let comb n k =
    let x = Enum.fold ( * ) 1 (n-k+1 -- n) in
    x * (pow (fact k) (prime - 2))
end

let (n, a, b) = scan "%d %d %d" Tuple.Tuple3.make


let () =
  let open Comb in
  pow 2 n
  |> (fun x -> (-) x 1)
  |> (fun x -> (-) x @@ comb n a)
  |> (fun x -> (-) x @@ comb n b)
  |> printf "%d\n"


Measured memory_bytes: 4608
import java.util.Scanner

fun main(args:Array<String>){

    val cin = Scanner(System.`in`)
    val r = cin.nextInt()
    val c = cin.nextInt()
    var table = Array(r+1,{ Array(c+1,{0}) })

    for(i in 0..r-1){
	    for(j in 0..c-1){
	        table[i][j] = cin.nextInt()
	        table[i][c] += table[i][j]
	        table[r][j] += table[i][j]
	        table[r][c] += table[i][j]
	    }
    }

    for(i in 0..r){
	    for(j in 0..c){
	        if(j > 0) print(" ")
	        print(table[i][j])
	    }
	    println()
    }
}


Measured memory_bytes: 41288
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

void solve(int step, int n, string s, string s1, string s2, map<pair<string, string>, long long>& ct) {
	if (step == n) ct[{s1, s2}]++;
	else {
		solve(step + 1, n, s, s1 + s[step], s2, ct);
		solve(step + 1, n, s, s1, s2 + s[step], ct);
	}
}

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

	long long n, i, j, k, ans;
	string s, s1, s2;

	cin >> n >> s;
	s1 = s.substr(0, n);
	s2 = s.substr(n);
	reverse(s2.begin(), s2.end());

	map<pair<string, string>, long long> c1, c2;

	solve(0, n, s1, "", "", c1);
	solve(0, n, s2, "", "", c2);

	ans = 0;
	for (auto p : c1) ans += p.second * c2[p.first];
	cout << ans << "\n";

	return 0;
}


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

#define int long long int 

int32_t main()
{

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

	int val1=abs(a-c)+abs(b-c);
	int val2=abs(a-b)+abs(c-b);
	int val3=abs(c-a)+abs(b-a);

	cout<<min(val1,min(val2,val3))<<endl;
}

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

long long p_num(int l){
    if(l == 0) return 1;
    return p_num(l-1) * 2 + 1;
}
long long pb_num(int l){
    if(l == 0) return 1;
    return pb_num(l-1) * 2 + 3;
}

long long p[51], pb[51];
long long countp(int l, long long x){
    if(l == 0) return 1;
    if(x == 1) return 0;
    if(1 < x && x <= 1 + pb[l-1]) return countp(l-1, x-1);
    if(x == 2 + pb[l-1]) return p[l-1] + 1;
    if(2 + pb[l-1] < x && x <= 2 + pb[l-1] * 2) return p[l-1] + 1 + countp(l-1, x-2-pb[l-1]);
    else return 1 + p[l-1] * 2;
}

int main(){
    for(int i = 0; i <= 50; i++){
        p[i] = p_num(i);
        pb[i] = pb_num(i);
    }

    int n;
    long long x;
    cin >> n >> x;
    cout << countp(n, x) << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#define vi vector<int>
#define vll vector<long long>
#define ll long long
#define ull unsigned long long
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define nl cout<<'\n'
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#define pll pair<long long,long long>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<ll,ll> >
#define si set<int>
#define sll set<long long>
#define all(v) (v).begin(),(v).end()
#define Unique(x)           (x).erase(unique(all(x)), x.end())
#define v_present(vec, x)  (find(all(vec),x)!=(vec).end())
#define present(myset, x)    ((myset).find(x)!=(myset).end())
#define Cprint(c)  for(auto i:(c)) { cout<<i<<" "; } nl
#define trace2(x, y) cout<<x<<" "<<y<<endl;
#define trace3(x, y, z) cout<<x<<" "<<y<<" "<<z<<endl;
#define trace4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<endl;
ll mod = 1e9 + 7;
const int MAX = 1e5 + 5;

using namespace std;

ll dp[405][405];  // dp[i][j] represents ways to divide j candies among 1st i students
ll pre[405];

ll solve(int i, int j){
    if(i==j)
        return 0;

    ll &ans=dp[i][j];
    if(ans!=-1)
        return ans;
    ans=1e15;
    for(int k=i;k<=j-1;k++){
        ans=min(ans,solve(i,k)+solve(k+1,j)+pre[j]-pre[i-1]);
    }
    return ans;
}


int main() {
    FAST_IO;
    int n;
    cin >> n ;
    vll a(n+1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        pre[i]=pre[i-1]+a[i];
    }
    memset(dp,-1,sizeof(dp));
    ll ans=solve(1,n);
    cout<<ans;


    return 0;

}

Measured memory_bytes: 1536
#include <iostream>

int main() {
  int a = 0, b = 0, c = 0, d = 0;
  std::cin >> a >> b >> c >> d;
  if (a+b > c+d) std::cout << "Left" << std::endl;
  else if (a+b == c+d) std::cout << "Balanced" << std::endl;
  else std::cout << "Right" << std::endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

/*class Rcontest101C{
  public static long dk(int[] x,int point,int cost,int n,int k,int index){
    int i  = index;
    int i2 = index;
    long r = 1000000001;
    long s = 1000000001;
    int[] nx = new int[x.length];
    if(n < k){
      if(i < x.length){
        for(;i < x.length;i++){
          if(x[i] != 100000001){
            int f = x[i];
            x[i] = 100000001;
            System.arraycopy(x,0,nx,0,x.length);
            r = dk(nx,point+f,cost+Math.abs(f)-point,n + 1,k,i + 1);
        }
      }
  }
  if(i2 > 0){
    i2 = i2 - 1;
    for(;i2 >  -1;i2--){
      if(x[i2] != 100000001){
        int f = x[i2];
        x[i2] = 100000001;
        System.arraycopy(x,0,nx,0,x.length);
        s = dk(nx,point+f,cost+Math.abs(f),n + 1,k,i2 - 1);
    }
  }
  }
  return  r>s?s:r;
}
return cost;
}
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int k = scan.nextInt();
    int[] x = new int[n];
    int index = 100001;
    for(int i = 0;i < n;i++){
      x[i] = scan.nextInt();
      if(index == 100001 && x[i] >= 0){
        index = i;
      }
    }
    long result = dk(x,0,0,0,k,index);
    System.out.println(result);
  }
}*/

class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int k = scan.nextInt();
    int[] x = new int[n];
    long a = 0;
    long b = 0;
    for(int i = 0;i < x.length;i++){
      x[i] = scan.nextInt();
    }
    for(int i = 0; i < x.length-k+1;i++){
      if(i == 0){
        b = Math.abs(x[i]) + Math.abs(x[i]-x[i+k-1]);
        b = (Math.abs(x[i+k-1])+ Math.abs(x[i]-x[i+k-1])) > b?b:(Math.abs(x[i+k-1])+ Math.abs(x[i]-x[i+k-1]));
        continue;
      }
      a = Math.abs(x[i]) + Math.abs(x[i]-x[i+k-1]);
      a = (Math.abs(x[i+k-1])+ Math.abs(x[i]-x[i+k-1])) > a?a:(Math.abs(x[i+k-1])+ Math.abs(x[i]-x[i+k-1]));
      b = b < a?b:a;
    }
    System.out.println(b);
  }
}


Measured memory_bytes: 49432
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323

ll f(ll n)
{
       ll p = (n+1)/2;      // 0..1 2..3
       if(n==0) return 0;
       if(n%2==0)    // n rem
       {
              if(p&1) return n^1;
              return n^0;
       }
       else
       {
              if(p&1) return 1;
              else return 0;
       }
}

void solve()
{
       ll a, b;
       cin>>a>>b;
       //cout<<f(a-1)<<endl;
       //cout<<f(b)<<endl;
       cout<<(f(a-1)^f(b))<<endl;
       //cout<<(1^2^3)<<endl;
}

int main() {
	ll T = 1;
	speed_up
	//cin>>T;
	while(T--)
	    solve();
	return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int A, B, C;

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

  std::cin >> A >> B >> C;

  int x = std::min(A - B, C), res = C - x;
  std::cout << res << std::endl;
}


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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N, K; cin >> N >> K;
  vector<int> P(N);
  for (int i = 0; i < N; i++) cin >> P.at(i);

  vector<bool> incK(N);
  {
    int i = 1;
    int cont = 1;
    while (i < N) {
      if (P.at(i-1) < P.at(i)) {
	cont++;
	if (cont >= K) incK.at(i+1-K) = true;
      }else cont = 1;
      i++;
    }
  }

  int count = 0;
  bool seeInc = false;
  set<int> cset;
  for (int i = 0; i < K; i++) cset.insert(P.at(i));
  count = 1;
  if (incK.at(0)) seeInc = true;
  for (int i = 1; i < N-K+1; i++) {
    auto itSmall = cset.begin();
    auto itBig = cset.rbegin();
    if (incK.at(i)) {
      if (!seeInc) {
	count ++;
	seeInc = true;
      }
    }else if (*itSmall == P.at(i-1) && *itBig < P.at(i+K-1)) {
      // do nothing
    }else {
      count ++;
    }
    cset.erase(P.at(i-1));
    cset.insert(P.at(i+K-1));
  }
  cout << count << endl;

  return 0;
}



Measured memory_bytes: 10496