akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <algorithm>
using namespace std;
 
int main(){
  int N, b;
  string a;
  cin >> N;
  vector<pair<string, pair<int, int>>> vec(N);
  
  for(int i = 0; i < N; i++){
    cin >> a >> b;
    vec.at(i) = make_pair(a, make_pair((-1)*b, i+1));
  }
  
  sort(vec.begin(), vec.end());
  
  for(int i = 0; i < N; i++){
    cout << vec.at(i).second.second << endl;
  }
  
}

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

using namespace std;

int BIT[300000];

int Sum(int I)
{
    long long S=0;
    I = 300000-I;
    I -= 2;
    I++;
    while (I > 0)
    {
        S += BIT[I];
        I -= I & (-I);
    }
    return S;
}

void Update(int I)
{
    I = 300000-I;
    I -= 2;
    I++;
    while (I < 300000)
    {
        BIT[I]++;
        I += I & (-I);
    }
}

int main()
{
    for (int i = 0; i < 300000; i++)
    {
        BIT[i] = 0;
    }
    int n, K, k=0;
    long long a, S=0, R=0;
    cin >> n >> K;
    long long A[n];
    set <long long> SL;
    set <long long> :: iterator it1;
    map <long long,int> Ma;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        a -= K;
        A[i] = a;
        if (i != 0)
        {
            S += a;
        }
        SL.insert(a-S);
    }
    for (set <long long> :: iterator it = SL.begin(); it != SL.end(); it++)
    {
        Ma[*it] = k;
        k++;
    }
    S = 0;
    for (int i = 0; i < n; i++)
    {
        a = A[i];
        if (i != 0)
        {
            S += a;
        }
        Update(Ma[a-S]);
        it1 = SL.lower_bound((-1)*S);
        if (it1 != SL.end())
        {
            R += Sum(Ma[*SL.lower_bound((-1)*S)]);
        }
    }
    cout << R;
    return 0;
}


Measured memory_bytes: 24832
x = gets.to_i
list5 = []
hash5 = {}
a = 1
while(true) do
  a5 = a**5
  hash5[a5] = a
  b5 = - (x - a5)
  if b5 == 0
    puts "#{a} 0"
    exit
  end
  if b = hash5[b5]
    puts "#{a} #{b}"
    exit
  end
  if b = hash5[-b5]
    puts "#{a} #{-b}"
    exit
  end
  a += 1
end

Measured memory_bytes: 14392
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    char s[n];
    cin >> s;
    int x = 0, max = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'I')
        {
            x++;
        }
        else
        {
            x--;
        }
        if (x >= max)
        {
            max = x;
        }
    }
    cout << max << endl;

    return 0;
}

Measured memory_bytes: 256
import bisect

n,k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9+7

ass = 0
for i in range(n):
    for j in range(i):
        if a[i] < a[j]:
            ass += 1

res = 0
b = sorted(a)
for e in b:
    kw = bisect.bisect_right(b,e)
    res += n-kw

print((k*ass%mod+( (k*(k-1)//2)%mod )*res%mod)%mod)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
bool a[300001];
vector<int> v;
inline void sm(){
    for(int i=0;i<300001;i++)a[i]=1;
    for(int i=2;i<300001;i++){
        if(i%7==1 || i%7==6){
            if(a[i]!=1)continue;
            v.push_back(i);
            int now=i*2;
            while(now<=300000){
                a[now]=0;
                now+=i;
            }
        }else{
            a[i]=0;
        }
    }
    a[1]=0;
    //for(int i=0;i<v.size();i++)cout<<v[i]<<" ";
    //cout<<endl;
}
int main(){
    sm();
    int n;
    while(cin>>n){
        vector<int> vv;
        if(n==1)return 0;
        if(a[n]==1){
            cout<<n<<": "<<n<<endl;
            continue;
        }
        for(int i=0;i<v.size();i++){
            if(n%v[i]==0)vv.push_back(v[i]);
        }
        //reverse(vv.begin(),vv.end());
        cout<<n<<":";
        for(int i=0;i<vv.size();i++){
            cout<<" "<<vv[i];
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 3492
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

// template version 2.0
using namespace std;
#include <bits/stdc++.h>

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); }
template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

ll calc(ll x, ll y){
    return cdiv(x, y) - 1;
}

int solve() {
    ll n,k;cin>>n>>k;
    vector<ll> a(n);
    rep(i, n) {
        cin>>a[i];
    }
    dump(a);

    ll left = 0, right = 1e9;
    auto isright = [&](ll y) {
        ll cnt = 0;
        rep(i, n){
            cnt += calc(a[i], y);
        }
        bool is_r = cnt <= k;
        return is_r;
    };
    while (right - left > 1) {/*{{{*/
        ll mid = (right + left) / 2;
        if (isright(mid)) right = mid;
        else left = mid;
    }/*}}}*/

    dump(right);
    cout << right << endl;

    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


Measured memory_bytes: 4692
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto N = readln.chomp.to!int;
    auto AS = readln.split.to!(int[]);
    auto BS = readln.split.to!(int[]);

    auto ns = new int[](N+1);
    auto cs = new int[][N+1];
    int d;
    int[] dis;
    foreach (i; 0..N) {
        auto a = AS[i];
        auto b = BS[i];
        ++ns[a];
        ++ns[b];
        if (a == b) {
            ++d;
            dis ~= i;
            cs[a] ~= i;
        }
    }
    foreach (i; 0..N) if (ns[i+1] > N) {
        writeln("No");
        return;
    }

    int max_cl, max_ci;
    foreach (i, c; cs) {
        auto cl = c.length.to!int;
        if (cl > max_cl) {
            max_cl = cl;
            max_ci = i.to!int;
        }
    }

    if (max_cl == d) {
        auto X = max_ci;
        int i;
        foreach (di; dis) {
            while (AS[i] == X || BS[i] == X) ++i;
            swap(BS[di], BS[i++]);
        }
        writeln("Yes");
        writeln(BS.to!(string[]).join(" "));
        return;
    } else if (max_cl > d/2) {
        bool[int] dim;
        foreach (di; dis) dim[di] = true;
        auto X = max_ci;
        int i, j;
        while (max_cl > d/2) {
            while (AS[i] == X || BS[i] == X) ++i;
            dim[cs[X][j]] = false;
            if (i in dim) {
                dim[i] = false;
                --d;
            }
            swap(BS[i++], BS[cs[X][j++]]);
            --max_cl;
            --d;
        }
        int[] ndis;
        foreach (k, v; dim) if (v) ndis ~= k;
        sort(ndis);
        dis = ndis;
    }

    auto ii = 0.iota(N).array;
    foreach (i, di; dis) {
        ii[di] = dis[(i+d/2)%d];
    }
    writeln("Yes");
    writeln(ii.map!(i => BS[i]).array.to!(string[]).join(" "));
}

Measured memory_bytes: 27140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
#define mk make_pair
#define pb push_back
#define pf push_front
typedef pair<int, int> pii;
#define INF (1 << 30)
#define INFL (1ll << 60ll);
#define mod 1000000007
#define se second
#define fi first

int N;
string s;
int sum[30];

signed main()
{
    cin >> N >> s;
    int ans = 1;
    for(int i = 0; i < N; i++){
        sum[s[i] - 'a']++;
    }
    for(int i = 0; i < 26; i++){
        ans *= sum[i] + 1ll;
        ans %= mod;
    }
    cout << (ans + mod - 1) % mod << endl;


    return 0;
}


Measured memory_bytes: 512
import sys

input = sys.stdin.readline
N = int(input())
S = sorted([sorted(input()) for _ in range(N)])
ans = 0
pre = '_'
precnt = 0
for s in S:
    if s == pre:
        precnt += 1
        ans += precnt
    else:
        pre = s
        precnt = 0
print(ans)


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

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

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll n,m;
    string s;
    cin>>n>>m;
    Yes(m>=n);
    return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//useful 
#define rep(i,n) for(int i = 0; i < (n); i++)
int long long gcd(int long long a, int long long b){
    return b?gcd(b,a%b):a;
} //最大公約数
int long long lcm(int long long a, int long long b){
    return a/gcd(a,b)*b;
} //最小公倍数
int long long GetDigit(int long long num){
    int long long digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
} //桁数
int long long GetDigitN(int long long num, int long long N){
    int long long digit=0;
    while(num!=0){
        num /= N;
        digit++;
    }
    return digit;
} //十進数でnumの際のN進数における桁数
int long long GetDigitSum(int long long n){
    if(n < 10){
       return n;
    }
    return GetDigitSum(n/10) + n%10;
} //十進数の桁和
unsigned int long long unsignedGetDigitSum(unsigned int long long n){
    if(n < 10){
       return n;
    }
    return unsignedGetDigitSum(n/10) + n%10;
} //十進数の桁和
int long long divisorcount(int long long n){
	int long long ans = 1;
	vector<int> x(n + 1);
	int long long num = n; // 素因数分解する変数num 
	for (int long long i = 2; i <= n; i++) {
		while (num%i == 0) { // 素数で割り切れなくなるまで割っていく
			x.at(i)++; //割った個数を配列に足す
			num /= i;
		}
	}
	for (int i = 2; i <= n; i++){
		ans *= x.at(i) + 1; //それぞれを+1して掛けていく
	}
    return ans;
} //約数カウント

int main(){
    string N;
    cin >> N;
    unsigned int long long A = 0;
    unsigned int long long B = N.size();
    for(unsigned int long long i = 0; i < B; i++){
        A = A + (N.at(i) - '0');
    }
    if(A % 9 == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

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

using i64 = int64_t;

int main(){
    i64 n, k;
    cin >> n >> k;
    vector<i64> v;
    for(int i=0;i<n;++i){
        i64 a;
        cin >> a;
        v.push_back(a-1);
    }
    vector<i64> cumsum(n+1);
    for(int i=1;i<=n;++i){
        cumsum[i] = (cumsum[i-1] + v[i-1]) % k;
    }

    int right = 1;
    i64 ans = 0;
    map<i64, i64> mp;
    mp[0] = 1;
    for(int left=0;left<n;++left){
        while(right <= n && right - left < k){
            ans += mp[cumsum[right]];
            mp[cumsum[right]]++;
            right++;
        }
        mp[cumsum[left]]--;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 15856
#include <stdio.h>

int main(void){

  int a,b;
  scanf("%d %d", &a, &b);

  if (a == b) {
    for (int i = 0; i < a; i++) {
      printf("%d", a);
    }
  } else {
    if (a < b) {
      for (int i = 0; i < b; i++) {
        printf("%d", a);
      }
    } else {
      for (int i = 0; i < a; i++) {
        printf("%d", b);
      }
    }
  }
  printf("\n");

  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

struct BIT{
  int n;
  vector<ll> bit;
  BIT(int size):n(size),bit(size+1,0){}

  ll sum(int i){
    if(i==-1)return 0;
    i++;
    ll s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }

  void add(int i,ll v){
    i++;
    while(i<=n){
      bit[i]+=v;
      i+=i&-i;
    }
  }

  ll lower_bound(ll w){
    if(w<=0)return 0;
    ll x=0,r=1;
    while(r<n)r<<=1;
    for(ll k=r;k>0;k>>=1){
      if(x+k<=n&&bit[x+k]<w){
        w-=bit[x+k];
        x+=k;
      }
    }
    return x;
  }
};

int Q,N=300010;
string A,B;
set<int> id0,id1;

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

  cin>>Q>>A>>B;
  reverse(all(A)); reverse(all(B));
  BIT bita(N),bitb(N);
  int totb=0;

  rep(i,A.size()){
    if(A[i]=='1')bita.add(i,1);
  }
  rep(i,B.size()){
    if(B[i]=='1'){
      bitb.add(i,1);
      totb++;
    }
  }
  rep(i,N){
    if(bita.sum(i)-bita.sum(i-1)==0&&bitb.sum(i)-bitb.sum(i-1)==0)id0.insert(-i);
    if(bita.sum(i)-bita.sum(i-1)==1&&bitb.sum(i)-bitb.sum(i-1)==1)id1.insert(-i);
  }

  while(Q--){
    char typ;
    cin>>typ;
    if(typ=='Q'){
      int r=bitb.lower_bound(totb);

      int idx0=-100000000,idx1=-100000000;
      if(id0.size()){
        auto it=id0.lower_bound(-r);
        idx0=-(*it);
      }

      if(id1.size()){
        auto it=id1.lower_bound(-r);
        idx1=-(*it);
      }

      if(idx1>idx0){
        cout<<bita.sum(N-1)-bita.sum(r)+r+1<<endl;
      }else{
        cout<<bita.sum(N-1)-bita.sum(r)+r<<endl;
      }
    }else{
      int i;
      cin>>i;
      int crta=bita.sum(i)-bita.sum(i-1);
      int crtb=bitb.sum(i)-bitb.sum(i-1);
      if(typ=='A'){
        if(crta==0){
          bita.add(i,1);
          if(crtb==0)id0.erase(-i);
          else id1.insert(-i);
        }else{
          bita.add(i,-1);
          if(crtb==1)id1.erase(-i);
          else id0.insert(-i);
        }
      }else{
        if(crtb==0){
          bitb.add(i,1);
          totb++;
          if(crta==0)id0.erase(-i);
          else id1.insert(-i);
        }else{
          bitb.add(i,-1);
          totb--;
          if(crta==1)id1.erase(-i);
          else id0.insert(-i);
        }
      }
    }
  }

  return 0;
}



Measured memory_bytes: 22100
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=2005;
vector<int>v[N];
int n,m,a,b,dist[N][N];//dist[i][j]=k点i到点j的最短路径为k 
inline bool cmp(vector<int>x,vector<int>y){return x.size()>y.size();}
void bfs()
{
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)dist[i][j]=1e9;
	queue<int>q;
	for(int i=0;i<n;i++)
	{
		q.push(0);
		q.push(i);
		q.push(i);
	}
	while(!q.empty())
	{
		int move=q.front();q.pop();
		int org=q.front();q.pop();
		int now=q.front();q.pop();
		if(dist[org][now]<=move)continue;
		dist[org][now]=move;
		for(int i=0;i<v[now].size();i++)
		{
			int to=v[now][i];
			q.push(move+1);
			q.push(org);
			q.push(to);
		}
	}
	
}
void solve()
{
	bfs();
	int pnt=0,ans=0;
	vector<int>e[N];
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			if(dist[i][j]>m)
				e[i].pb(j),pnt++;
	for(int i=0;i<n;i++)sort(e[i].begin(),e[i].end());
	while(pnt)
	{
		int MAX=0,num=-1;
		for(int i=0;i<n;i++)
		{
			if(MAX<e[i].size())
			{
				num=i;
				MAX=e[i].size();
			}
		}
		for(int i=0;i<e[num].size();i++)
		{
			int to=e[num][i];
			e[to].erase(lower_bound(e[to].begin(),e[to].end(),num));
		}
		ans++;
		pnt-=e[num].size()*2;
		e[num].clear();
	}
	cout<<ans<<endl;
	return;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n-1;i++)
	{
		cin>>a>>b;
		a--,b--;
		v[a].pb(b);
		v[b].pb(a);
	}
	solve();
	return 0;
}

Measured memory_bytes: 65924
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }



string s;

signed main()
{
	cin >> s;
	int len = s.length();

	int sum = 0;
	REP(i, len)
	{
		int n = s[i] - '0';
		sum += n;
	}
	
	YesNo(sum % 9 == 0);
}



Measured memory_bytes: 3348
import java.util.*;
import java.math.*;

class Main{
    public static void cout(String str)
    {
        System.out.println(str);
    };
    public static void main(String args[])
    {
        Scanner cin=new Scanner(System.in);
        String a="",b="",str;
        int n;
        n=cin.nextInt();
        cin.nextLine();
        str=cin.nextLine();
        for(int i=0;i<n/2;i++)
        {
            a=a+str.charAt(i);
        }
        if(str.equals(a+a))
            cout("Yes");
        else cout("No");
    }
};


Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int c[100001];
int d[100001];
int main()
{
int a,b,ans=0;
cin>>a>>b;
for(int i=0;i<a;i++)
cin>>c[i]>>d[i];
sort(c,c+a,greater<int>());
int mx=c[0];
sort(d,d+a,greater<int>());
for(int i=0;i<a;i++)
if(d[i]>mx && b>0){
b-=d[i];
ans++;}
if(b>0)
ans+=(b+mx-1)/c[0];
cout<<ans<<endl;
system("pause");
return 0;
}


Measured memory_bytes: 1272
X, Y = map(int, input().split())
first = 300000
second = 200000
third = 100000
ans = 0
if X == 1 and Y == 1:
    print(300000 + 300000 + 400000)
    exit()
if X == 1:
    ans += first
elif X == 2:
    ans += second
elif X == 3:
    ans += third
else:
    ans += 0

if Y == 1:
    ans += first
elif Y == 2:
    ans += second
elif Y == 3:
    ans += third
else:
    ans += 0

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<stdbool.h>
using namespace std;

int main(void) {
	string a, b, c;
	cin >> a >> b >> c;
	cout << a[0] << b[0] << c[0] << endl;
	return 0;
}

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

int main() {
  static const double pi = 3.141592653589793;
  double a, b, c;
  cin >> a >> b >> c;
  c = pi*c/180;
  cout << fixed << setprecision(10) << a * b * sin(c) / 2 << endl;
  cout << fixed << setprecision(10) << a + b + sqrt(a*a + b*b - 2*a*b*cos(c))<< endl;
  cout << fixed << setprecision(10) << b*sin(c) << endl;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (b >= a * c)cout << c << endl;
	else cout << b / a << endl;
	return 0;
}


Measured memory_bytes: 256
// Why am I so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int INF = 1e9;

bool took[6][30005];

int dp[6][30005];

int n;

void solve() {                   
	scanf("%d", &n);

	if (n == 3) {
		printf("2 5 63\n");
		return;
	}

	if (n == 4) {
		printf("2 5 20 63\n");
		return;
	}

	for (int i = 1; i <= 30000; ++i) {
		for (int j = 0; j < 6; ++j) {
			dp[j][i] = -INF;
			took[j][i] = 0;			
		}
	}    

	dp[2][2] = 1;
	dp[5][3] = 2;
	took[2][2] = 1;
	took[5][3] = 1;

	for (int i = 4; i <= 30000; ++i) {
		for (int cur = 0; cur < 6; ++cur) {
			dp[cur][i] = dp[cur][i - 1];
		}

		if (i % 2 && i % 3) {
			continue;
		}

		for (int cur = 0; cur < 6; ++cur) {
			if (dp[cur][i - 1] == -INF) {
				continue;
			}

			int val = dp[cur][i - 1] + 1;
			int nxt = (cur + i) % 6;

			if (val <= n && val > dp[nxt][i]) {
				dp[nxt][i] = val;
				took[nxt][i] = 1;
			}
		}
	}

	for (int i = 30000, s = 0; i > 1; --i) {
		if (took[s][i]) {
			printf("%d ", i);
			s = (s - (i % 6) + 6) % 6;
		}	
	}
}

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back

using namespace std;
typedef pair<ll,ll> pll;


string s;
ll n;
vector<ll> bd;
ll solve(ll x,ll y)
{
        if(x >= y) return 0;
        ll ret = 0;
        ll cnt = 0;
        for(ll i=y;i>=x;i--){
                if(s[i] == 'A') ret += cnt;
                else if(s[i] == 'B') cnt++;
        }
        return ret;
}
int main()
{
        cin >> s;
        n = s.length();
        s = "#" + s;
        s = s + "#";
        bd.pb(0);
        bd.pb(n+1);
        for(ll i=1;i<=n;i++) {
                if(s[i] == 'B' && s[i+1] != 'C') bd.pb(i);
                else if(s[i] == 'C' && s[i-1] != 'B') bd.pb(i);
        }
        sort(bd.begin(), bd.end());
        ll ans = 0;
        for(ll i=1;i<bd.size();i++) {
                ans += solve(bd[i-1]+1, bd[i]-1);
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 2804
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#define lli long long int
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 57;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;

void solve()
{
    lli n, m;
    cin>>n>>m;
    lli a[n];
    for(int i = 0; i < n; i ++)
        cin>>a[i];
    priority_queue<lli> pq;
    for(int i = 0; i < n; i++)
    {
        pq.push(a[i]);
    }
    while(m --)
    {
        lli  x = pq.top();
        pq.pop();
        x /= 2;
        pq.push(x);
    }
    lli ans = 0;
    while(!pq.empty())
    {
        lli x = pq.top();
//        cout<<x<<endl;
        pq.pop();
        ans += x;
    }
    cout<<ans;
    return ;
}
/*
7
6 7 4 1 2 11 6
5
1 2 10 4 5
*/

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

    lli t;
    t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 2168
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
//using Edge = Pair<long, int>;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var nm = Input.ar;
        var xyz = Input.arL2D(nm[0]);
        var res = long.MinValue;
        for (var i = 0; i < 8; i++)
        {
            var c = xyz.Select(ar =>  ar[0] * f((i & 1) == 1) + ar[1] * f((i & 2) == 2) + ar[2] * f((i & 4) == 4)).OrderByDescending(v=>v).Take(nm[1]).Sum();
            res = Max(res, c);
        }
        WriteLine(res);
    }
    static int f(bool b)
        => b ? 1 : -1;
}

public class Input
{
    public static string read => ReadLine().Trim();
    public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
    public static int num => ToInt32(read);
    public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
    public static long numL => ToInt64(read);
    public static char[][] gred(int h)
        => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray();
    public static int[] ar1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => num).ToArray();
    public static long[] arL1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => numL).ToArray();
    public static string[] strs(int n)
        => Enumerable.Repeat(0, n).Select(_ => read).ToArray();
    public static int[][] ar2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => ar).ToArray();
    public static long[][] arL2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => arL).ToArray();
    public static T getValue<T>(string g)
    {
        var t = typeof(T);
        if (t == typeof(int))
            return (T)(object)int.Parse(g);
        if (t == typeof(long))
            return (T)(object)long.Parse(g);
        if (t == typeof(string))
            return (T)(object)g;
        if (t == typeof(char))
            return (T)(object)char.Parse(g);
        if (t == typeof(double))
            return (T)(object)double.Parse(g);
        if (t == typeof(bool))
            return (T)(object)bool.Parse(g);
        return default(T);
    }
    public static string[] Make<T1, T2>(out T1 v1, out T2 v2)
    {
        var r = read.Split(' ');
        v1 = getValue<T1>(r[0]);
        v2 = getValue<T2>(r[1]);
        return r;
    }
    public static string[] Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3)
    {
        var r = Make(out v1, out v2);
        v3 = getValue<T3>(r[2]);
        return r;
    }
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public const int MOD = 1000000007;
}

Measured memory_bytes: 13664
#include<iostream>
using namespace std;
string x,y;
int q;

int lcs(){
  int c[1002][1002],ans=0;
  int  m=(int)x.size(),n=(int)y.size();
    x=' '+x,y=' '+y;
  for(int i=1;i<=m;i++)c[i][0]=0;
  for(int i=1;i<=n;i++)c[0][i]=0;
  for(int i=1;i<=m;i++)
    for(int j=1;j<=n;j++){
      if(x[i]==y[j])c[i][j]=c[i-1][j-1]+1;
      else if(c[i-1][j]>=c[i][j-1])c[i][j]=c[i-1][j];
      else c[i][j]=c[i][j-1];
      if(ans<=c[i][j])ans=c[i][j];
    }
  return ans;
}

int main(){
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>x>>y;
  cout<<lcs()<<endl;
  }
  return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  string N;
  cin>>N;
  int ans=0;
  for(auto it:N){
    ans=(ans+it-'0')%9;
  }
  if(ans==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 3788
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <climits>
using namespace std;
 
int N, Q;
struct Year {
  string name;
  int base, wy;
  Year() {}
  Year(string name, int base, int wy)
    : name(name), base(base), wy(wy) {}
  bool operator < (const Year &y) const {
    if(wy != y.wy) return wy < y.wy;
    if(base != y.base) return base < y.base;
    return name < y.name;
  }
};
 
vector<Year> v;
int main() {
  while(cin >> N >> Q && (N || Q)) {
    v.clear();
    for(int i = 0; i < N; ++i) {
      Year y;
      cin >> y.name >> y.base >> y.wy;
      y.wy = y.wy - y.base + 1;
      v.push_back(y);
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < Q; ++i) {
      int q;
      cin >> q;
      int p  = distance(v.begin(),lower_bound(v.begin(), v.end(), Year("",INT_MAX,q)));
      if(p == 0 || !(q < v[p-1].wy+v[p-1].base)) cout << "Unknown" << endl;
      else cout << v[p-1].name << " " << q-v[p-1].wy+1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1292
#include<algorithm>
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;

string s;

int main()
{
	cin>>s;
	
	if(s=="Sunny") puts("Cloudy");
	else if(s=="Cloudy") puts("Rainy");
	else puts("Sunny");
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

n_switches = []
switches = []
for i in range(M):
    ipt = list(map(int, input().split()))
    n_switches.append(int(ipt[0]))
    switches.append(ipt[1:])


p = list(map(int, input().split()))

ans = 0

# print(n_switches)
# print(switches)
# print(p)

# ランプの光り方のパターンだけ
for i in range(2 ** N):
    ptn = bin(i)[2:].rjust(N, '0')

    allLight = True  # 全ての電球が光っているかどうか（一つでも光っていなければそのパターンは無効）

    # 電球の数だけ
    for j in range(M):

        n_light = 0
        # 電球に対するスウィッチの数だけ
        for k in range(n_switches[j]):
            # スウィッチが光っていれば
            if ptn[switches[j][k] - 1] == '1':
                n_light += 1

        if n_light % 2 != p[j]:
            allLight = False
            break

    if allLight:
        ans += 1

print(ans)

    

Measured memory_bytes: 3064
#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;


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

	int n, m, c, i, j, k, ct, s;
	cin >> n >> m >> c;

	vector<int> b(m), a(m);
	for (i = 0; i < m; i++) cin >> b[i];
	ct = 0;
	while (n--) {
		s = c;
		for (i = 0; i < m; i++) {
			cin >> a[i];
			s += b[i] * a[i];
		}
		if (s > 0) ct++;
	}
	cout << ct << "\n";


	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define NIL -1
//#define DEBUG

typedef struct node{
  int left;
  int right;
  int parent;
}node;

int getSibling(int);
int getDegree(int);
int getDepth(int);
int getHeight(int);
void printTree(void);

node *tree;
int n;

int main(){
  int id,left,right,i;
  
  scanf("%d",&n);
  
  tree = (node *)malloc(sizeof(node)*n);
  for(i=0;i<n;i++){
    tree[i].parent = NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d %d %d",&id,&left,&right);
    tree[id].left = left;
    tree[id].right = right;
    tree[tree[id].left].parent = id;
    tree[tree[id].right].parent = id;
  }

  #ifdef DEBUG
  printf("debug\n");
  printf("n=%d\n",n);
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i,tree[i].left,tree[i].right);
  }
  #endif
  
  printTree();

  return 0;
}

int getSibling(int c){
  int left,right;
  if(tree[c].parent!=-1){
    left = tree[tree[c].parent].left;
    right = tree[tree[c].parent].right;

    if(left!=-1&&c!=left) return left;
    else if(right!=-1&&c!=right) return right;
  }
  return -1;
}

int getDegree(int c){
  int d=0;
  if(tree[c].left!=-1) d++;
  if(tree[c].right!=-1) d++;
 
  return d;
}

int getDepth(int c){
  int d=0;
  while(tree[c].parent!=-1){
    c=tree[c].parent;
    d++;
  }
  return d;
}

int getHeight(int c){
  int d=0;
  if(tree[c].left==-1&&tree[c].right==-1) return 0;
  if(tree[c].left==-1) return getHeight(tree[c].right)+1;
  if(tree[c].right==-1) return getHeight(tree[c].left)+1;
  if(getHeight(tree[c].left)<getHeight(tree[c].right))
    return getHeight(tree[c].right)+1;
  else return getHeight(tree[c].left)+1;
  return d;
}

void printTree(){
  int i,dep,h;
  for(i=0;i<n;i++){
    dep=getDepth(i);
    h=getHeight(i);
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,tree[i].parent,getSibling(i),getDegree(i),dep,h);
    if(dep==0) printf("root\n");
    else if(h==0) printf("leaf\n");
    else printf("internal node\n");
  }

  return;
}

Measured memory_bytes: 612
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

// - 移動できる条件
//   - 2点間の移動距離が時間以内であること
//   - 距離が偶数の場合は時間も偶数、奇数の場合は時間も奇数であること
int main() {
  int N;
  cin >> N;

  int prevT = 0;
  int prevX = 0;
  int prevY = 0;
  bool can = true;

  for (int i = 0; i < N; i++) {
    int t, x, y;
    cin >> t >> x >> y;

    int diffTime = t - prevT;
    int dist = abs(x - prevX) + abs(y - prevY); // 2点間の移動距離

    if (diffTime < dist || (diffTime % 2) != (dist % 2)) {
      can = false;
      break;
    }

    prevT = t;
    prevX = x;
    prevY = y;
  }

  if (can) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
/*
ABHIJEET BISWAS
CSE (2017-2021)
MNNIT ALLAHBAD
*/

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e15
#define ll long long
#define ld long double
#define int ll
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define MAX 1000009
#define pb push_back
#define mp map<int,int>
#define F first
#define S second
#define popi __builtin_popcount
#define popll __builtin_popcountll
#define grp vector<int> graph[MAX];
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

//////////////////////TEMPLATE ENDS///////////////////////////////////////////////////////////////////////
ll power(ll,ll);
ll mpower(ll,ll);
//////////////////////////////////////////////////////////////////////////////////////////////////////////
int n,k;
int dp[101][100008];
int pref[101][100008];
int arr[100003];




int32_t main() {
	fastIO


	cin >> n >> k;

	for(int i=1;i<=n;i++) cin >> arr[i];
	dp[0][0]=1;
	pref[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=k;j++)
		{
			if(j>arr[i])
				dp[i][j] = (pref[i-1][j] - pref[i-1][j-arr[i]-1]+MOD)%MOD; 
			else
				dp[i][j] = (pref[i-1][j]);
			if(j==0)
				pref[i][j] = dp[i][j];
			if(j>0)
			pref[i][j] = (dp[i][j]+pref[i][j-1])%MOD;
		}
	}
	

	cout << pref[n][k] << endl;

	return 0;
}







/*_________________________________________________Utility Functions HERE_______________________________*/

ll power(ll a,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b%2==1)
		res=res*a;
		a=a*a;
		b=b/2;
	}
	return res;
}
ll mpower(ll a ,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%MOD;
		}
		a=(a*a)%MOD;
		b=b/2;
	}
	return res;
}

Measured memory_bytes: 157312
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int N,M;
	cin>>N>>M;
	vector<vector<int> > A(N,vector<int>(M));
	vector<int> B(M);
	for(int i=0;i<N;++i){
		for(int j=0;j<M;++j){
			cin>>A[i][j];
		}
	}
	for(int i=0;i<M;++i){
		cin>>B[i];
	}
	for(int i=0;i<N;++i){
		int sum=0;
		for(int j=0;j<M;++j){
			sum+=A[i][j] * B[j];
		}
		cout<<sum<<endl;;
	}
	return 0;
}



Measured memory_bytes: 3168
import java.util.Scanner;

public class Main {
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        
        if(a > b) {
            System.out.println(a + (a-1));
        } else if(b > a) {
            System.out.println(b + (b-1));
        } else {
            System.out.println(a*2);
        }

    }
}

Measured memory_bytes: 23892
import sys

mod = 10 ** 9 + 7

N = int(input())
S = input()

if S[0] == 'W' or S[-1] == 'W':
    print(0)
    sys.exit()

d = {'L':'R', 'R':'L'}

T = 'L'
for i in range(2 * N-1):
    if S[i] == S[i+1]:
        T += d[T[-1]]
    else:
        T += T[-1]

if T.count('L') != N:
    print(0)
    sys.exit()

ans = 1
cnt = 0

for i in range(2 * N):
    if T[i] == 'L':
        cnt += 1
    else:
        ans *= cnt
        ans %= mod
        cnt -= 1

def factorial(n, mod):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
        fact %= mod
    return fact

ans *= factorial(N, mod)
ans %= mod

print(ans)

Measured memory_bytes: 9552
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

a, b = map(int, input().split())

if a > 0 and b > 0:
    print("Positive")
elif a * b <= 0:
    print("Zero")
elif (b - a) % 2 == 1:
    print("Positive")
else:
    print("Negative")


Measured memory_bytes: 9108
#include <iostream>
#include <cstdio>
#define N 105
#define M 1005
using namespace std;

int n, m, ans, a[M], b[M], c[M], d[N][N];
int main()
{
	int i, j, k;
	cin >> n >> m;
	for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) if (i != j) d[i][j] = 1e9;
	for (i = 0; i < m; i++) {
		scanf("%d %d %d", &a[i], &b[i], &c[i]);
		d[a[i]][b[i]] = min(d[a[i]][b[i]], c[i]);
		d[b[i]][a[i]] = min(d[b[i]][a[i]], c[i]);
	}
	for (k = 1; k <= n; k++)
		for (i = 1; i <= n; i++)
			for (j = 1; j <= n; j++)
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	for (i = 0; i < m; i++) if (d[a[i]][b[i]] < c[i]) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define N 200100

int n,k,sz,sf,tmp,tt;
int a[N],b[N],c[N];
int ans=1e15;

signed main()
{
	scanf("%lld%lld",&n,&k);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		if (a[i]==0) tmp++;
		if (a[i]<0) b[++sf]=-a[i];
		if (a[i]>0) c[++sz]=a[i];
	}
	reverse(b+1,b+sf+1);
	if (tmp>=k) {puts("0"); return 0;}
	
	k-=tmp;
	if (sz>=k) ans=min(ans,c[k]);
	if (sf>=k) ans=min(ans,b[k]);
	
	for (int i=1;i<k;i++)
	{
		if (i>sz || k-i>sf) continue;
		tt=min(c[i]*2+b[k-i],b[k-i]*2+c[i]);
		ans=min(ans,tt);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST freopen("in.txt","r",stdin);
#define ab(a) ((a < 0) ? (-(a)) : (a))
#define all(a) a.begin(), a.end()
#define ones(a) __builtin_popcount(a)

int main(){
  fastIO;
  int a,b,c;
  ll k;
  cin >> a >> b >> c >> k;
  if(k % 2 == 0)
    cout << a-b;
  else
    cout << b-a;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
numL = [0 for i in range(n)]

x = input()
for i in range(n):
    numL[i] = int(x.split()[i])

flag = 1
ctr = 0
while flag:
    flag -= 1
    for i in range(n-1,0,-1):
        if numL[i] < numL[i-1]:
            ctr += 1
            tmp = numL[i]
            numL[i] = numL[i-1]
            numL[i-1] = tmp
            flag = 1
print(*numL)
print(ctr)



Measured memory_bytes: 5612
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int x1 = sc.nextInt();
		int y1 = sc.nextInt();
		int x2 = sc.nextInt();
		int y2 = sc.nextInt();

		int x = x2 - x1;
		int y = y2 - y1;
		System.out.println((x2 - y) + " " + (y2 + x) + " " + (x1 - y) + " " + (y1 + x));
		sc.close();
	}
}

Measured memory_bytes: 21204
#include <iostream>
#include <map>
using namespace std;
	typedef long long int lli;
	const int MaxN=200005;
	map <lli,lli> mapi;
	lli arr[MaxN];
int main(){
	lli N,M,i,j,p,q,res=0;
	cin>>N;
	for(i=1;i<=N;i++){
		cin>>arr[i];
	}
	for(i=1;i<=N;i++){
		p=i-arr[i];	
		q=i+arr[i];
		res+=mapi[p];
		mapi[q]+=1;
	}
	cout<<res;
	
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int X;

bool isprime(ll v) {
	for(ll i=2;i*i<=v;i++) if(v%i==0) return false;
	return (v!=1);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	cin>>X;
	while(isprime(X)==0) X++;
	cout<<X<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
import math
n = int (input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))

l = list(range(1,n+1))
num = 0
for i in range(n):
     a = l.index(int(p[i]))
     l.remove(int(p[i]))

     num += a * math.factorial(n-i-1)

l1 = list(range(1,n+1))
num1 = 0
for i in range(n):
     a = l1.index(int(q[i]))
     l1.remove(int(q[i]))
     num1 += a * math.factorial(n-i-1)

print(abs(num -num1))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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 (a>b) { a = b; return 1; } return 0; }
void rcmb(ll *x,ll s,ll r,function<void(ll *)>f){if(r==0){f(x);}else{if(s<0)return;rcmb(x,s-1,r,f);x[r-1]=s;rcmb(x,s-1,r-1,f);}}
void cmb(ll n,ll k,function<void(ll *)>f){ll x[k];rcmb(x,n-1,k,f);}
void prm(ll n,function<void(ll *)>f){ll x[n];for(ll i=0;i<n;i++)x[i]=i;do{f(x);}while(next_permutation(x,x+n));}
void prm(ll n,ll k,function<void(ll *)>f){cmb(n,k,[&](ll *c){prm(k,[&](ll *p){ll x[k];for(ll i=0;i<k;i++){x[i]=c[p[i]];}f(x);});});}
// prm(4, 2, [](ll *x){ cout << x[0] << "," << x[1] << "\n"; });
 
int main(){
    ll X;
    cin >> X;
    string res = "NO";
    if (X==3) res = "YES";
    if (X==5) res = "YES";
    if (X==7) res = "YES";
    cout << res << "\n";
}


Measured memory_bytes: 256
def code_for_C(test=None):

    N = int(input())
    list_d = list(map(int, input().split()))

    list_d.sort()

    half_smaller = list_d[int(N/2)-1]
    half_larger = list_d[int(N/2)]

    print(half_larger - half_smaller)
    
code_for_C()

Measured memory_bytes: 14396
#include<iostream>
#include<cstdio>

using namespace std;

int main(){
	double x1,y1,x2,y2,x3,y3,x4,y4;
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
		x2-=x1; y2-=y1;
		x4-=x3; y4-=y3;
		if(x2*y4-y2*x4==0) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <math.h>

using namespace std;

int main () {
	int N, M, X;
	cin >> N >> M >> X;
	int left =0, right = 0;
	for (int i = 0; i < M; i++){
		int A;
		cin >> A;
		if ( A > X ) right++;
		else left ++;
	}
	cout << min(left,right) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
using ll = long long int;

int main(){
    int d, t, s;
    cin >> d >> t >> s;

    if(s*t >= d) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3620