akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::string s;

  std::cin >> s;

  bool used[333] = {0};

  for (const auto& c : s)
    used[c] = true;

  for (char c = 'a'; c <= 'z'; c ++)
    if (! used[c]) {
      std::cout << s << c << std::endl;
      
      return 0;
    }

  int size = s.size();

  assert(size == 26);

  bool found[333] = {0};

  for (int i = size - 1; i >= 0; i --) {
    char c = s[i];

    found[c] = true;

    if (c == 'z')
      continue;

    for (c ++; c <= 'z'; c ++)
      if (std::count(std::begin(s), std::begin(s) + i, c) == 0) {
        std::cout << s.substr(0, i) << c << std::endl;
        
        return 0;
      }
  }
  
  std::cout << -1 << std::endl;
    
  return 0;
}


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

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	
	
	int x,y,z;
	x=abs(a-b);
	y=abs(b-c);
	z=abs(c-a);
	
	int k=max(x,max(y,z));


	cout<<x+y+z-k<<endl;
	
	
	return 0;
}		

Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<map>
using namespace std;
int main(){
	int id,d;
	map<int,int> lastm,currm;
	string s;
	while(getline(cin,s)&&s.size()>0){
		sscanf(s.c_str(),"%d,%d",&id,&d);
		lastm[id]++;
	}
	while(getline(cin,s)&&s.size()>0){
		sscanf(s.c_str(),"%d,%d",&id,&d);
		currm[id]++;
	}
	for(__typeof(lastm.begin()) i=lastm.begin(); i!=lastm.end(); i++){
		if(currm[i->first]>0)cout<<i->first<<" "<<(i->second+currm[i->first])<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef pair<int, int> P;
int main(void){
    int n, a, b;
    long long h, w, c[10];
    map<P, int> m, z;
    vector<P> v;
    cin >> h >> w >> n;
    for(int i=0;i<n;i++){
        cin >> a >> b;
        m[P(a, b)]++;
        v.push_back(P(a, b));
    }
    fill(c, c+10, 0);
    for(int i=0;i<v.size();i++){
        for(int j=0;j<=8;j++){
            int nx=v[i].first+j/3-1, ny=v[i].second+j%3-1;
            if(nx>1&&nx<h&&ny>1&&ny<w){
                if(z[P(nx, ny)]==0){
                    int u=0;
                    for(int k=0;k<=8;k++){
                        int kx=nx+k/3-1, ky=ny+k%3-1;
                        if(m[P(kx, ky)]==1)u++;
                    }
                    c[u]++;
                    z[P(nx, ny)]++;
                }
            }
        }
    }
    c[0] = (h-2)*(w-2);
    for(int i=1;i<=9;i++){
        c[0]-=c[i];
    }
    for(int i=0;i<=9;i++){
        cout << c[i] << endl;
    }
    
}


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

int main(){
    ll n,d,x,y,ans=0;
    cin>>n>>d;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        if(sqrt(x*x + y*y)<=d) ans++;
    }
    cout<<ans;
return 0;
}

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

template <typename T>
struct queueElm
{
  std::string name;
  T value;

  queueElm<T> *nextPtr = nullptr;
};

template <typename T>
struct queue
{
  queueElm<T> *head =  nullptr;
  queueElm<T> *tail = nullptr;

  bool isEmpty()
  {

    if ((head == nullptr) && (tail == nullptr))
      return true;
    else
      return false;
  };

  void enqueue(std::string name, T value)
  {
    queueElm<T> *newPtr;
    if (!isEmpty())
      {
        newPtr = tail;
      }
    else
      {
        newPtr = new queueElm<T>;
        head = newPtr;
      }

    newPtr->name = name;
    newPtr->value = value;
    queueElm<T> *nextPtr = new queueElm<T>;
    newPtr->nextPtr = nextPtr;
    tail = nextPtr;
  };

  queueElm<T> dequeue()
  {
    auto tmpPtr = head;
    auto retVal = *tmpPtr;
    head = tmpPtr->nextPtr;
    delete tmpPtr;

    if (head == tail)
      {
        head = nullptr;
        tail = nullptr;
      }

    return retVal;
  };

  void print()
  {
    auto tmpPtr = head;
    while (tmpPtr != tail)
      {
        std::cout << tmpPtr->name << " " << tmpPtr->value << std::endl;
        tmpPtr = tmpPtr->nextPtr;
      }
  }

};

int main()
{
  int n, q;
  std::cin >> n >> q;

  queue<int> processes;

  for (int i=0; i<n; i++)
    {
      std::string name;
      int time;
      std::cin >> name >> time;

      processes.enqueue(name, time);
      //process.print();
    }

  auto total_time = 0;
  while (!processes.isEmpty())
    {
      auto process = processes.dequeue();
      if (process.value <= q)
        {
          total_time += process.value;
          std::cout << process.name << " " << total_time << std::endl;
        }
      else
        {
          total_time += q;
          process.value -= q;
          processes.enqueue(process.name, process.value);
        }
    }
}



Measured memory_bytes: 7088
#include <stdio.h>

struct Node {
  int parent;
  int left;
  int right;
};

void setup(struct Node node[], int n) {
  for (int i = 0; i < n; i++) {
    node[i].parent = -1;
    node[i].left = -1;
    node[i].right = -1;
  }
}

void input(struct Node node[], int n) {
  int id, cleft , cright;
  for (int i = 0; i < n; i++) {
    scanf("%d", &id);
    scanf("%d", &cleft);
    scanf("%d", &cright);
    
    node[id].left = cleft;
    node[id].right = cright;
    node[cleft].parent = id;
    node[cright].parent = id;
  }
}

int root_search(struct Node node[], int n) {
  for (int i = 0; i < n; i++) {
    if (node[i].parent == -1)
      return i;
  }
}

void preorder_tree_walk(struct Node node[], int id) {
  printf(" %d", id);
  if (node[id].left != -1)
    preorder_tree_walk(node, node[id].left);
  if (node[id].right != -1)
    preorder_tree_walk(node, node[id].right);
}

void inorder_tree_walk(struct Node node[], int id) {
  if (node[id].left == -1 && node[id].right == -1)
    printf(" %d", id);
  else {
    if (node[id].left != -1)
      inorder_tree_walk(node, node[id].left);
    printf(" %d", id);
    if (node[id].right != -1)
      inorder_tree_walk(node, node[id].right);
  }
}

void postorder_tree_walk(struct Node node[], int id) {
  if (node[id].left != -1)
    postorder_tree_walk(node, node[id].left);
  if (node[id].right != -1)
    postorder_tree_walk(node, node[id].right);
  printf(" %d", id);
}

int main(void) {
  int n, root;
  struct Node node[25]; 

  scanf("%d", &n);

  setup(node, n);
  input(node, n);

  root = root_search(node, n);

  printf("Preorder\n");
  preorder_tree_walk(node, root);

  printf("\nInorder\n");
  inorder_tree_walk(node, root);

  printf("\nPostorder\n");
  postorder_tree_walk(node, root);
  printf("\n");

  return 0;
}



Measured memory_bytes: 2108
#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;

void solve(ll N, std::vector<ll> a) {
  ll sum = 0;
  for (auto v : a) {
    sum += v;
  }

  ll ans = 2e18;
  ll x = 0;
  for (int i = 0; i < N - 1; i++) {
    x += a.at(i);
    ans = min(ans, abs(sum - 2 * x));
  }

  cout << ans << endl;

  return;
}

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


Measured memory_bytes: 1792
#include <bits/stdc++.h>
//Remove below header file if c++ version greater than 14
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
using namespace std;
#define ll long long int
#define pb push_back
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
//#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)

const int inf = -1000;
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a /gcd(a, b) *b;
}
typedef pair<int,int> pii;
const int mod = 1e9+7;
int main() {

   int n,q;

   cin>>n>>q;
   string s;
   cin>>s;

   int countt = 0;
   int ct[n];
   ct[0] = 0;
   for(int i=1;i<=n-1;++i){
       if(s[i-1]=='A'&&s[i]=='C'){
           countt++;

       }
       ct[i] = countt;
   }

   while(q--){

    int l,r;
    cin>>l>>r;
    l-=1;
    r-=1;
    cout<<ct[r]-ct[l]<<endl;

   }





























    return 0;

      }


Measured memory_bytes: 1408
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    MOD = 1000000007
    N, *A = map(int, read().split())
    C = [0] * (N + 1)
    C[0] = 3
    ans = 1
    for a in A:
        ans = ans * C[a] % MOD
        if ans == 0:
            print(0)
            return
        C[a] -= 1
        C[a + 1] += 1

    print(ans)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 14068
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A;
  cin >> N >> A;
  
  if(N < 1 || N > 100) {
    cout << "N(first input) must be between 1 and 100.";    
    return 0;
  }
  
  if(A < 0 || A > std::pow(N, 2.0)) {
  	cout << "A(second input) must be between 0 and the square of N(first input).";
    return 0;
  }

  cout << std::pow(N, 2.0) - A << endl;
}

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

using namespace std;

int solve(const vector<int>&cs,const vector<vector<int> >& cover,int bit,vector<char>& memo)
{
	if(memo[bit]!=-1)
		return memo[bit];
	int n=cs.size();
	int res=0;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++){
			if(cs[i]!=cs[j])
				continue;
			if((bit&1<<i) || (bit&1<<j))
				continue;
			bool ok=true;
			for(int k=0;k<i;k++)
				ok&=(bit&1<<k) || cover[i][k]==0;
			for(int k=0;k<j;k++)
				ok&=(bit&1<<k) || cover[j][k]==0;
			if(!ok)
				continue;
			res=max(res,2+solve(cs,cover,bit|1<<i|1<<j,memo));
		}
	return memo[bit]=res;
}

int main()
{
	for(int n;cin>>n,n;){
		vector<int> xs(n),ys(n),rs(n),cs(n);
		for(int i=0;i<n;i++)
			cin>>xs[i]>>ys[i]>>rs[i]>>cs[i];
		vector<vector<int> > cover(n,vector<int>(n));
		for(int i=0;i<n;i++){
			for(int j=0;j<i;j++){
				int x=xs[j]-xs[i],y=ys[j]-ys[i],r=rs[i]+rs[j];
				if(x*x+y*y<r*r)
					cover[i][j]=1;
			}
		}
		vector<char> memo(1<<n,-1);
		int res=solve(cs,cover,0,memo);
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 16000
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    if(a == 1){a = 14;}
    if(b == 1){b = 14;}
    if(a == b){cout << "Draw";}
    else if(a > b){cout << "Alice";}else{cout << "Bob";}

    return 0;
}


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

int main() {
    long long N, A, B;
    cin>>N>>A>>B;
    long long ans;
    if((A-B)%2==0){
        ans = abs(A-B)/2;
    }
    else {
        if(max(N-A, N-B) < max(A-1, B-1)){
            ans = min(N-A, N-B)+1;
            ans += (max(N-A, N-B) - min(N-A, N-B) - 1)/2;
        }
        else{
            ans = min(A-1, B-1)+1;
            ans += (max(A-1, B-1) - min(A-1, B-1) - 1)/2;
        }
    }
    cout<<ans<<endl;
}


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

int main()
{
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> dat(n);

  for (int i = 0; i < n; i++){
    int a, b;
    cin >> a >> b;
    dat[i] = make_pair(a, b);
  }

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

  long long ans = 0;

  for (int i = 0; m > 0; i++){
    int price = dat[i].first;
    int num = min(m, dat[i].second);
    ans += price * (long long) num;
    m -= num;
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define fgx cerr<<"-------------"<<endl
#define N 1000000
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<ll,int> pii;
void dbg(){cerr<<endl;}
template<typename A,typename... B>void dbg(A x,B... y){cerr<<x<<" ";dbg(y...);}
#define debug(...) cerr<<#__VA_ARGS__<<"=",dbg(__VA_ARGS__)
int n,x,b[N],l[N],r[N],tag[N]; pii a[N];
inline ll gao(int i,int v){return (ll)min(v,b[i])*l[i]+(ll)max(0,v-b[i])*r[i];}
inline ll check(ll s)
{	int k=s/x,res=s%x; ll sum=0,ans=0;
	for(rint i=1;i<=n;i++) a[i]=mp(gao(i,x),i),tag[i]=0;
	sort(a+1,a+n+1,greater<pii>()); for(rint i=1;i<=k;i++) tag[a[i].second]=1,sum+=a[i].first;
	if(!res) return sum;
	for(rint i=1;i<=n;i++)
	if(tag[i]) ans=max(ans,sum-gao(i,x)+gao(i,res)+a[k+1].first);
	else ans=max(ans,sum+gao(i,res));
	return ans;
}
int main()
{	ll v=0; cin>>n>>x;
	for(rint i=1;i<=n;i++) scanf("%d%d%d",&b[i],&l[i],&r[i]),v+=(ll)l[i]*b[i];
	ll l=0,r=(ll)n*x,ans=-1;
	while(l<=r)
	{	ll mid=(l+r)>>1;
		if(check(mid)>=v) ans=mid,r=mid-1;
		else l=mid+1;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 9984
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long;
using pll = pair<ll,ll>;

#define reps(i,s,n) for(int (i) = (s) ;(i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)

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

    vector<int> ans;
    rep(i,n+1){
        rep(j,m+1){
            ans.push_back(m*i + n*j - 2*(i*j));
        }
    }
bool f = false;
/*
    for(auto e: ans){
        cout << e << endl;
    }
cout << endl;
*/
    rep(i,ans.size()){
        if(ans[i] == k){ 
            f=true;
            break;
        }
    }

    if(f){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}



Measured memory_bytes: 6384
function main()
    N = parse(Int, readline())
    a = map(x -> parse(Int, x), split(readline()))

    sort!(a, rev=true)

    alice = 0
    bob = 0
    for i = 1:N 
        if i % 2 == 1
            alice += a[i]
        else
            bob += a[i]
        end
    end

    println(alice - bob)
end

main()

Measured memory_bytes: 112300
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans=0;
	for(int i=0;i<1000;i++){
		string t;
		if(i>=0 && i<10){
			t+="00";
		}else if(i>=10 && i<100){
			t+='0';
		}
		t+=to_string(i);
		int now=0;
		for(int j=0;j<n;j++){
			if(t[now]==s[j]){
				now++;
				if(now==3){
					ans++;
					break;
				}
			}
		}
	}
	cout << ans << endl;		
	return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int h, w, k;
  cin >> h >> w >> k;
  string c[6];
  for(int i = 0; i < h; ++i)
  {
    cin >> c[i];
  }

  int all_blacks = 0;
  vector<int> h_num(h, 0);
  vector<int> w_num(w, 0);
  for(int i = 0; i < h; ++i)
  {
    for(int j = 0; j < w; ++j)
    {
      if (c[i][j] == '#') 
      {
        h_num[i]++;
        all_blacks++;
      }
    }
  }

  for(int i = 0; i < w; ++i)
  {
    for(int j = 0; j < h; ++j)
    {
      if (c[j][i] == '#') w_num[i]++;
    }
  }

  int ans = 0;
  int mask = 1 << (h + w);
  while(mask--, mask >= 0)
  {
    int h_mask = mask >> w;
    int w_mask = (mask & 0b111111);

    int h_hidden_num = 0;
    int w_hidden_num = 0;
    for(int i = 0; i < h; ++i)
    {
      if (( h_mask & (1 << i) ) > 0) h_hidden_num += h_num[i];
    }

    for(int i = 0; i < w; ++i)
    {
      if (( w_mask & (1 << i) ) > 0) w_hidden_num += w_num[i];
    }

    int rest_num = all_blacks - h_hidden_num - w_hidden_num;
    for(int i = 0; i < h; ++i)
    {
      if ( (h_mask & (1 << i) ) == 0) continue;
      for(int j = 0; j < w; ++j)
      {
        if ( (w_mask &  (1 << j) ) == 0) continue;
        rest_num += (c[i][j] == '#');
      }
    }
    ans += (rest_num == k);
  }

  cout << ans;

}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3652
#pragma region
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define vi vector<int>
#define vd vector<double>
#define vs vector<string>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define dump(x) cerr << #x << " = " << x << endl
#define gcd __gcd
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);
int dig(int n){return (int)(log10(n) + 1);}
int abc(char x){return (int)(x)-(int)('a');} // 0~25
char abc(int x){return (char)(x+(int)('a'));} 
int ABC(char x){return (int)(x)-(int)('A');}
char ABC(int x){return (char)(x+(int)('A'));}
void solve();
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	solve();
}
#pragma endregion

void solve() {
	int N;
	cin >> N;
	int sum = 0;
	repi(i, 1, N + 1) {
		if (i % 3 != 0 && i % 5 != 0) {
			sum += i;
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 3704
from collections import deque

n,m = map(int,input().split())
e = [[] for i in range(n+1)]
for i in range(m):
    a,b = map(int,input().split())
    e[a].append(b)
    e[b].append(a)

l = deque([1])
s = set([1])
while True:
    check = True
    for nex in e[l[-1]]:
        if nex in s:
            continue
        l.append(nex)
        s.add(nex)
        check = False
        break
    if check:
        break
while True:
    check = True
    for nex in e[l[0]]:
        if nex in s:
            continue
        l.appendleft(nex)
        s.add(nex)
        check = False
        break
    if check:
        print(len(l))
        print(*l)
        exit()

Measured memory_bytes: 32416
#include<stdio.h>

#define N 100

int bubbleSort(int *, int );

int main(){

  int A[N],i,n,cunt;

  scanf("%d",&n);

  for(i=0;i<n;i++)scanf("%d",&A[i]);

  cunt =  bubbleSort(A,n);

  for(i=0;i<n-1;i++)printf("%d ",A[i]);
  printf("%d\n",A[i]);
  printf("%d\n",cunt);
  
  return 0;
}

int bubbleSort(int A[], int n){
  int i,j, flag = 1 ,key ,cunt = 0;
  for(j = 0;flag ;j++){
    flag = 0;
    for(i=n-1;i>= j+1;i--){
      if(A[i]<A[i-1]){
	key = A[i];
	A[i]=A[i-1];
	A[i-1]=key;
	flag = 1;
	cunt++;
      }	
    }
  }
  return cunt;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<min(a,b)+min(c,d)<<endl;
}

Measured memory_bytes: 3604
function Main(input) {

	input = input.split(" ");
  var A = input[0];
  var B = input[1];  
  if(A-B*2<0){
    console.log("0");
  }else{
  console.log(A-B*2);
}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;


int main(){
  int n,m;
  cin >> n >>m;
  cout << (n-1)*(m-1) << endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int a[1000];
int main () {
  int n;
  cin >> n;
  for (int i =0; i < n; i++) {
    cin >>a[i];
  }
  sort(a, a + n);
  cout << a[n - 1] - a[0] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
char s[N],t[N];
int a[27],b[27];
int main(){
  cin>>s>>t;
  int n=strlen(s);
  for(int i=0;i<n;i++){
  	a[s[i]-97]++;
  	b[t[i]-97]++;
  }
  int flag=0;
/* for(int i=0;i<26;i++){
 	if(a[i]&&!b[i])flag=1;
 	 else if(!a[i]&&b[i])flag=1;
 }*/
 sort(a,a+26);
 sort(b,b+26);
 for(int i=0;i<26;i++){
 	if(a[i]!=b[i]){
 		flag=1;
 		break;
	 }
 }
/* for(int i=0;i<26;){
 	int temp=a[i],num=1,t=i+1;
 	while(t<26&&a[t]==temp)t++,num++;
 	if(num%2){
 		flag=1;break;
	 }
	 i=t;
 }*/
 if(flag)cout<<"No";
  else cout<<"Yes";
  return 0;
}

Measured memory_bytes: 640
import math

n,m = list(map(int, input().split()))
a = []
b = []
c = []
for i in range(m):
    u,v = list(map(int, input().split()))
    a.append(u)
    b.append(v)
    clist = list(map(int, input().split()))
    temp = 0
    for i in range(len(clist)):
        temp += 2**(clist[i]-1)
    c.append(temp)

#print(a)
#print(b)
#print(c)

dp = [[10**9 for i in range(2**n)] for j in range(m)]

dp[0][c[0]] = a[0]

for i in range(m):
    dp[i][0]=0
    
for i in range(m-1):
    for j in range(2**n):
        dp[i+1][j] = min(dp[i][j],dp[i+1][j])
        dp[i+1][j|c[i+1]] = min(dp[i+1][j|c[i+1]],dp[i][j]+a[i+1])
        #print(j,j|c[i+1])
    #print("i:",i+1)
    #print(dp[i])
    #print(dp[i+1])

#print()
#print(dp[m-1])



if(dp[-1][-1]==10**9):
    print(-1)
else:
    print(dp[-1][-1])

Measured memory_bytes: 80344
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;

template<class T>
T gcd(T a,T b){
	a = abs(a), b = abs(b);
	if(b==0) return a;
	return gcd(b,a%b);
}
template<class T, class U>
T pow_mod(T x, U p, T mod){
	assert(p>=0);
	x %= mod;
	T a = 1 % mod;
	while(p){
		if(p&1) a = a*x%mod;
		x = x*x%mod;
		p >>= 1;
	}
	return a;
}
using ll = long long;
bool isprime(ll n){
	if(n<=1) return 0;
	if(n==2) return 1;
	if(n%2==0) return 0;
	ll d = n-1;
	while(d%2==0) d/=2;
	static const vector<ll> alist{2,3,5,7,11,13,17,19,23,29,31,37};
	for(ll a: alist){
		if(n<=a) break;
		ll t = d;
		ll y = pow_mod<__int128>(a,t,n);
		while(t!=n-1 && y!=1 && y!=n-1){
			y = __int128(y)*y%n;
			t<<=1;
		}
		if(y!=n-1 && t%2==0) return 0;
	}
	return 1;
}

ll f(ll x,ll n){ return (__int128(x)*x+1)%n;}
ll pollard_single(ll n){
	if(isprime(n)) return n;
	if(!(n&1)) return 2;
	ll i,x,y,p;
	for(i=1;;i++){
		x=i; y=f(x,n); p=gcd(y-x,n);
		while(p==1){
			x=f(x,n); y=f(f(y,n),n); p=gcd((y-x+n)%n,n)%n;
		}
		if(p==0 || p==n) continue;
		return p;
	}
	assert(0);
}

vector<ll> pollard(ll n){
	if(n==1) return {};
	ll x = pollard_single(n);
	if(x==n) return {x};
	vector<ll> le = pollard(x);
	vector<ll> ri = pollard(n/x);
	for(ll d: ri) le.push_back(d);
	return le;
}

int main(){
	int N;
	ll X;
	cin>>N>>X;
	vector<ll> ps = pollard(X);
	map<ll,int> mp;
	for(ll p: ps) mp[p]++;
	ll a = 1;
	for(auto it: mp){
		int K = it.sc/N;
		rep(i,K) a*=it.fs;
	}
	cout<<a<<endl;
}

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

using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

int main() {
  ll n, m, a, b, c;
  cin >> n >> m;
  vector<pair<ll, ll>> abc(m + n);
  for (int i = 0; i < n; i++) {
    cin >> a;
    abc[i] = make_pair(a, 1);
  }
  for (int i = n; i < m + n; i++) {
    cin >> b >> c;
    abc[i] = make_pair(c, b);
  }
  sort(abc.begin(), abc.end());
  ll sum = 0;
  ll cnt = n;
  for (int i = 0; i < m + n; i++) {
    if (abc[m + n - i - 1].second >= cnt) {
      sum += abc[m + n - i - 1].first * cnt;
      break;
    } else {
      sum += abc[m + n - i - 1].first * abc[m + n - i - 1].second;
      cnt -= abc[m + n - i - 1].second;
    }
  }
  cout << sum << endl;

  return 0;
}


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

using namespace std;

using pii = pair<int, int>;
using pll = pair<long long, long long>;

int main() {
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double deg_b = m * 6;
    double deg_a = 30.0 * h + 0.5 * m;
    double deg_need = min(abs(deg_a - deg_b), 360.0 - abs(deg_a - deg_b));
    cout.precision(20);
    cout << sqrt(a*a + b*b - 2 * a * b * cos(deg_need * M_PI / 180.0)) << endl;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
	int n, k;
	cin >> n >> k;
	int x[n];
	rep (i, n) cin >> x[i];

	ll sum = 0;
	rep (i, n) sum += min(x[i] * 2, abs(x[i] - k) * 2);

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long x,y;
  cin >> x >> y;
 
  long long ans=0;
  for (long long i = x; i <= y; i*=2)
  {
    ans++;
  }
  cout << ans << endl;
}
#include <bits/stdc++.h>

Measured memory_bytes: 256
while True:
    count=0
    n,x=map(int,input().split())
    if n==x==0:
        break
    for i in range(1,n+1):
        for j in range(i,n+1):
            for k in range(j,n+1):
                if i+j+k==x and (i!=j and i!=k and k!=j):
                    count+=1
    print(count)


Measured memory_bytes: 5592
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 100000001;
ll t[100010][50];
const ll mod = 1000000007;
void SnukeFestival() {
	ll n;
	cin >> n;
	ll a[100010], b[100010], c[100010];
	for (size_t i = 0; i < n; i++) cin >> a[i];
	for (size_t i = 0; i < n; i++) cin >> b[i];
	for (size_t i = 0; i < n; i++) cin >> c[i];
	sort(a, a + n);
	sort(b, b + n);
	sort(c, c + n);
	ll count = 0;
	for (size_t m = 0; m < n; m++)
	{
		ll bm = b[m];
		ll ai = lower_bound(a, a + n, bm) - a;

		ll cp =  n - (upper_bound(c, c + n, bm) - c);
		count += ai * cp;
	}
	cout << to_string(count) << endl;
}

int main() {
	SnukeFestival();

	return 0;
}



Measured memory_bytes: 2560
#include<iostream>
#include<sstream>
#include<cstring>
#include<math.h>
using namespace std;

int main(){
    char str[4];
    int n[4];
    int sum;
    int op[3];
    static int ans = 7;
    static int opNum = 3;

    scanf("%s", str);

    for(int i = 0; i < 4; i++){
        n[i] = str[i] - '0';
    }

    for(int i = 0; i < (int)pow(2, opNum); i++){

        sum = n[0];
        for(int j = 0; j < opNum; j++){
            if((1&(i>>j)) == 1){
                sum += n[j+1];
                op[j] = 1;
            }else{
                sum -= n[j+1];
                op[j] = 0;
            }
        }
        if(sum == ans){

            for(int j = 0; j < opNum; j++){
                printf("%d",n[j]);
                if(op[j]==1){
                    printf("%c",'+');
                }else{
                    printf("%c", '-');
                }
            }
            printf("%d=%d\n", n[3], sum);
            break;
        }
    }

    return 0;
}

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

using namespace std;

template <typename Type> class RMQ
{
private:

	int size;

	vector<Type> maxvalue;

	Type _query(int a, int b, int k, int l, int r)
	{
		if (r <= a || b <= l) { return INF; }
		if (a <= l && r <= b) { return maxvalue[k]; }

		Type vl = _query(a, b, 2 * k, l, (l + r) / 2);
		Type vr = _query(a, b, 2 * k + 1, (l + r) / 2, r);

		return max(vl, vr);
	}

public:

	Type INF;

	RMQ(int size_)
	{
		INF = numeric_limits<Type>::min() / 2;

		for (size = 1; size < size_;) { size <<= 1; }

		maxvalue = vector<Type>(size * 2, INF);
	}

	void update(int i, const Type& x)
	{
		i += size;

		maxvalue[i] = x;

		while (i > 1)
		{
			i = i / 2;

			maxvalue[i] = max(maxvalue[2 * i], maxvalue[2 * i + 1]);
		}
	}

	Type query(int s, int t)
	{
		return _query(s, t, 1, 0, size);
	}
};


#include <cstdio>

int main()
{
	int power[16]; power[0] = 1;

	for (int i = 1; i < 16; i++)
	{
		power[i] = power[i - 1] * 3;
	}

	int N; long long D;

	scanf("%d", &N);
	scanf("%lld", &D);

	int mid = N / 2;

	int power1 = power[mid];
	int power2 = power[N - mid];

	vector<long long> X(N);
	vector<long long> Y(N);

	for (int i = 0; i < N; i++)
	{
		scanf("%lld", &X[i]);
		scanf("%lld", &Y[i]);
	}

	vector<long long> D1X, D1Y;

	vector<pair<long long, long long> > D2;

	long long X3, Y3;

	for (int i = 0; i < power1; i++)
	{
		X3 = 0LL;
		Y3 = 0LL;

		for (int j = 0; j < mid; j++)
		{
			switch ((i / power[j]) % 3)
			{
			case 0: X3 -= X[j]; Y3 -= Y[j]; break; // Anna
			case 1: X3 += X[j]; Y3 += Y[j]; break; // Bruno
			}
		}

		D1X.push_back(X3);
		D1Y.push_back(Y3);
	}

	for (int i = 0; i < power2; i++)
	{
		X3 = 0LL;
		Y3 = 0LL;

		for (int j = mid; j < N; j++)
		{
			switch ((i / power[j - mid]) % 3)
			{
			case 0: X3 -= X[j]; Y3 -= Y[j]; break; // Anna
			case 1: X3 += X[j]; Y3 += Y[j]; break; // Bruno
			}
		}

		D2.push_back(make_pair(X3, Y3));
	}

	sort(D2.begin(), D2.end(), [](pair<long long, long long> x, pair<long long, long long> y) { return x.first < y.first; });

	int D1_size = D1X.size();
	int D2_size = D2.size();

	vector<long long> X1;

	RMQ<long long> rmq(N != 30 ? D2_size : 0);

	if (N != 30)
	{
		for (int i = 0; i < D2_size; i++)
		{
			X1.push_back(D2[i].first);

			rmq.update(i, D2[i].second);
		}
	}
	else
	{
		for (int i = 0; i < D2_size; i++)
		{
			X1.push_back(D2[i].first);
		}
	}

	long long Ans = numeric_limits<long long>::min() / 2;

	int ptr1, ptr2;

	if (N != 30)
	{
		for (int i = 0; i < D1_size; i++)
		{
			long long _D1X = -D1X[i];

			ptr1 = distance(X1.begin(), lower_bound(X1.begin(), X1.end(), _D1X - D));
			ptr2 = distance(X1.begin(), upper_bound(X1.begin(), X1.end(), _D1X + D));

			if (ptr1 != ptr2)
			{
				Ans = max(D1Y[i] + rmq.query(ptr1, ptr2), Ans);
			}
		}
	}
	else
	{
		for (int i = 0; i < D1_size; i++)
		{
			long long _D1X = -D1X[i];

			ptr1 = distance(X1.begin(), lower_bound(X1.begin(), X1.end(), _D1X - D));
			ptr2 = distance(X1.begin(), upper_bound(X1.begin(), X1.end(), _D1X + D));

			for (int j = ptr1; j < ptr2; j++)
			{
				Ans = max(D1Y[i] + D2[j].second, Ans);
			}
		}
	}

	printf("%lld\n", Ans);

	return 0;
}

Measured memory_bytes: 694608
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int K = sc.nextInt();
		Set<String> S = new HashSet<>();
		for(int i = 0; i < K; i++){
			for(int j = 0; j < s.length()-i; j++)
				S.add(s.substring(j, j + i + 1));
		}
		List<String> list = new ArrayList<>(S);
		Collections.sort(list);
		System.out.println(list.get(K-1));
	}

}

Measured memory_bytes: 24644
#include <cstdio>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
int main(){
	while(true){
		int e,mn=1e9;
		scanf("%d",&e);
		if(!e) break;
		for(int z=0;z*z*z<=e;z++){
			for(int y=0;y*y+z*z*z<=e;y++){
				mn=min(mn,y+z+(e-y*y-z*z*z));
			}
		}
		printf("%d\n",mn);
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
    int n,k,ans = 0;
    cin>>n>>k;
    int d,a;
    vector<int> treat(n,0);

    rep(i,n){
        cin>>d;
        rep(j,d){
            cin>>a;
            treat[a-1]++;
        }
    }
    rep(i,n){
        if(treat[i] == 0) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
    int h,w;
    cin>>h>>w;
    vector<string> s(h);
    for(int i=0; i<h; i++){
        cin>>s[i];
    }
    vector<vector<int>> dp(h,vector<int>(w,1e5));
    if(s[0][0]=='#') dp[0][0]=1;
    else dp[0][0]=0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(i+1<h && s[i+1][j]=='#' && s[i][j]=='.') dp[i+1][j]=min(dp[i+1][j],dp[i][j]+1);
            else if(i+1<h) dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
            if(j+1<w && s[i][j+1]=='#' && s[i][j]=='.') dp[i][j+1]=min(dp[i][j+1],dp[i][j]+1);
            else if(j+1<w) dp[i][j+1]=min(dp[i][j+1],dp[i][j]);
        }
    }
    cout<<dp[h-1][w-1]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
#define pb push_back
int main(void){
    ll n,m;
    cin>>n>>m;
    if(n==1&&m==0){
        cout<<0<<endl;
        return 0;
    }
    string ans="";
    rep(0,i,n)ans+=" ";
    vector<pair<ll,char>>p(m);
    rep(0,i,m){
        cin>>p[i].first>>p[i].second;
        --p[i].first;
    }
    sort(p.begin(),p.end());
    rep(0,i,m){
        ll s=p[i].first;
        char c=p[i].second;
        if(s==0&&c=='0'&&n!=1){
            cout<<-1<<endl;
            return 0;
        }
        if(ans[s]==' ')ans[s]=c;
        else if(ans[s]!=c){
            cout<<-1<<endl;
            return 0;
        }
    }
    rep(0,i,n){
        if(ans[i]==' '){
            if(i==0){
                ans[i]='1';
            }else{
                ans[i]='0';
            }
        }
    }
    rep(0,i,n)cout<<ans[i];
}

Measured memory_bytes: 3616
/*hello! guys~*/
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	long long t=100,a,i;
	cin>>a;
	for(i=1;i<=3761;i++)
	{
		t=t+t*0.01;
		if(t>=a)
		break;
	}
	printf("%lld",i);
	return 0;
}

Measured memory_bytes: 3764
N = int(input())
p = [int(i) for i in input().split()]


c = 0
is_ok = True
for i in range(N):
    if (i+1 != p[i]) :
        c += 1
    
    if (c > 2) :
        is_ok = False
        break

if (is_ok) :
    print("YES")
else :
    print("NO")

Measured memory_bytes: 3060
/* "It's okay if you hate me. I hate me too." */

#include <bits/stdc++.h>

using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	int i, res;
	for (i = 1; i <= n; i <<= 1)
		res = i;
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

const int N = 15;
const int INF = 1 << 25;
int dist[N][N];
void chmin(int &a, int b) {
    a = std::min(a, b);
}

int main() {
    while(1) {
        int M; scanf("%d", &M);
        if(M == 0) break;

        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                if(i != j) dist[i][j] = INF;
            }
        }

        int T = 0;
        for(int i=0; i<M; i++) {
            int a, b, c; scanf("%d%d%d", &a, &b, &c);
            chmin(dist[a][b], c);
            chmin(dist[b][a], c);
            T = std::max({T, a+1, b+1});
        }

        for(int k=0; k<T; k++) {
            for(int i=0; i<T; i++) {
                for(int j=0; j<T; j++) {
                    chmin(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }

        int ans = INF, idx = 0;
        for(int i=0; i<T; i++) {
            int sum = 0;
            for(int k=0; k<T; k++) {
                sum += dist[i][k];
            }
            if(ans > sum) {
                ans = sum;
                idx = i;
            }
        }
        printf("%d %d\n", idx, ans);
    }
    return 0;
}


Measured memory_bytes: 2584
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
using namespace std;

int main() {

	int N;
	int Y;
	cin >> N >> Y;

	int sum = 0;
	int cnt[3] = { 0, 0, 0 };

	while (Y >= sum) {
		sum += 10000;
		cnt[0] += 1;
	}

	sum -= 10000;
	cnt[0] -= 1;

	while (Y >= sum) {
		sum += 5000;
		cnt[1] += 1;
	}

	sum -= 5000;
	cnt[1] -= 1;

	while (Y != sum) {
		sum += 1000;
		cnt[2] += 1;
	}

	if (cnt[0] + cnt[1] + cnt[2] == N) {
		cout << cnt[0] << " " << cnt[1] << " " << cnt[2] << endl;
	}
	else if (cnt[0] + cnt[1] + cnt[2] < N) {
		bool frag = false;
		int ans[3] = { 0, 0, cnt[2] };
		int val = 0;
		for (int j = 0; j <= cnt[0]; j++) {
			for (int i = 0; i <= cnt[1] + 2 * j; i++) {
				val = cnt[2] + cnt[1] + 2 * j + cnt[0] - j - i + 5 * i;
				if (val == N) {
					ans[0] = cnt[0] - j;
					ans[1] = cnt[1] + 2 * j - i;
					ans[2] = cnt[2] + 5 * i;
					cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
					return 0;
				}
			}
		}
		cout << -1 << " " << -1 << " " << -1 << endl;
	}
	else {
		cout << -1 << " " << -1 << " " << -1 << endl;
	}



	return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
using namespace std;
int main (){
  string S;
  int ans =0;
  cin >> S;
for(int i=0;i<4;i++){
  if(S[i]==*"+"){
    ans++;
}else{
  ans--;
}}
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n, m;
	cin >> n >> m;
	vector<ll> a(m), b(m);
	vector<vector<ll>> p(n, vector<ll>(0));
	rep(i, m)
	{
		cin >> a[i] >> b[i];
		p[a[i] - 1].push_back(b[i] - 1);
		p[b[i] - 1].push_back(a[i] - 1);
	}

	queue<pair<ll, ll>> q;
	vector<ll> poi(n, 0);
	vector<ll> ans(n, -1);

	poi[0] = 1;
	rep(i, p[0].size())
	{
		q.emplace(p[0][i], 0);
	}

	while(!q.empty())
	{
		pair<ll, ll> tmp = q.front();
		q.pop();
		if (poi[tmp.first])
			continue;
		ans[tmp.first] = tmp.second;
		poi[tmp.first] = 1;
		rep(i, p[tmp.first].size())
		{
			q.emplace(p[tmp.first][i], tmp.first);
		}

	}

	for (int i = 1; i < n; i++)
	{
		if (ans[i] == -1)
		{
			cout << "No" << endl;
			ret;
		}
	}
	cout << "Yes" << endl;
	for (int i = 1; i < n; i++)
	{
		cout << ans[i] + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 20980
import java.util.*;
import java.io.*;
import java.lang.*; 
public class Main {
	public static void main(String[] args)  throws Exception{
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int k = sc.nextInt();
		if(B <= A){
		    while(k > 0 && B <= A){
		        B=B*2;
		        k--;
		    }
		}
		if(C <= B){
		    while(k >0 && C<=B){
		        C=C*2;
		        k--;
		    }
		}
		if(B>A && C >B){
		    System.out.println("Yes");
		}else{
		    System.out.println("No");
		}
    }
}

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

int main() {
    // input
    string S;
    cin >> S;

    // solve & output
    if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) {
        cout << "Bad" << endl;
    } else {
        cout << "Good" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  string str;
  string str1;
  cin>>str;
  str1=str;
  int a;
  a=str.size();
  a--;
  char str2;
  str2=str.at(a);
  if(str2=='s'){
    cout<<str1+"es"<<endl;
  }else{
    cout<<str1+'s'<<endl;
  }
  
  
 
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
	int k, s;
	cin >> k >> s;
	int ans = 0;
	for (int z = k; z >= 0; --z) {
		for (int y = k; y >= 0; --y) {
			if (s - z - y <= k&& s - z - y >=0) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>

int main(void){
    int N;
    char c;
    std::string ans="Yes";
    std::cin >> N;
    std::set<std::string> words;

    for (int i=0; i<N; ++i){
        std::string W;
        std::cin >> W;
        if (i == 0){
            words.insert(W);
            c = W.at(W.size() - 1);
        } else {
            if (c != W.at(0)){
                ans = "No";
                break;
            } else if (words.find(W) != words.end()){
                ans = "No";
                break;
            } else {
                words.insert(W);
                c = W.at(W.size() - 1);
            }
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


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

using namespace std;

#define REP(i,m) for(ll i=0; i<m; i++)
#define FOR(i,n,m) for(ll i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int ans[600][600];

void solve(int a, int b, int c){
	if((b-a)==1){
		ans[a][b] = c;
		return;
	}
	if(a == b) return;
	int m = a + (b-a)/2;
	FOR(i, a, m+1){
		FOR(j, m+1, b+1){
			ans[i][j] = c;
		}
	}
	solve(a, m, c+1);
	solve(m+1, b, c+1);
	return;
}

int main(){
	int n;
	cin >> n;
	if(n==2){
		cout << 1 << endl;
		return 0;
	}
	solve(0, n-1, 1);
	REP(i, n){
		FOR(j, i+1, n){
			cout << ans[i][j];
			if(j == n-1) cout << endl;
			else cout << " ";
		}
	}
	return 0;
} 


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

using namespace std;

const int MOD = 1e9 + 7;

long long dp[2005];

long long solve(int v) {
    if (v == 0) return 1;
    if (v < 3) return 0;
    if (dp[v] != -1) return dp[v];

    long long tot = 0;

    for (int i = 3; i <= v; i++) {
        tot += solve(v - i);
        tot %= MOD;
    }

    return dp[v] = tot;
}

int main() {
    int s;
    scanf("%d", &s);

    memset(dp, -1, sizeof(dp));

    printf("%lld\n", solve(s));
}


Measured memory_bytes: 3852
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };



int main() {
	ll x;
	cin >> x;
	ll s = 100;
	ll ans = 0;
	while (s < x) {
		ans++;
		s += (s / 100);
	}
	cout << ans << endl;
	return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long

void solve(){
	ll a;
	cin >> a;
	cout << a + (a * a) + (a * a * a); 
}

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

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int H,N;
  cin>>H>>N;
  while(N--)
  {
    int X;
    cin>>X;
    H-=X;
  }
  if(H>0)
    puts("No");
  else	puts("Yes");
  return 0;
} 

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

int n, a[100000], b[100001];

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

	int ans = 0;
	for (int i = 0; i <= 100000; i++) {
		ans = max(ans, b[i]);
	}

	cout << ans << endl;
}

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

inline double squ_minus(double a, double b){
	double x = a - b;
	return x * x;
}

inline double squ_plus(double a, double b){
	double x = a + b;
	return x * x;
}

int main(){
	int n; // the number of datasets
	std::cin >> n;
	
	for(int i = 0; i < n; ++i){
		std::array<double, 6> cir; // 0:xa, 1:ya, 2:ra, 3:xb, 4:yb, 5:rb
		std::cin >> cir[0] >> cir[1] >> cir[2] >> cir[3] >> cir[4] >> cir[5];

		double dis = squ_minus(cir[0], cir[3]) + squ_minus(cir[1], cir[4]);
		
		if(dis > squ_plus(cir[2], cir[5])){
			std::cout << "0" << std::endl;
		}else if(dis < squ_minus(cir[2], cir[5])){
			std::cout << (cir[2] >= cir[5] ? "2" : "-2") << std::endl;
		}else{
			std::cout << "1" << std::endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
#define  m_k make_pair
#define   P  pair<int,int>
#define  V vector
typedef long long LL;
typedef unsigned long long ULL;
void solve_B()
{
    int n,m;
    while(cin>>n>>m)
    {
        vector<int> a(n+1);
        double sum=0;
        for(int i=1;i<=n;i++)
            cin>>a[i],sum+=a[i];
        sum/=(4*m);
        int cnt=0;
        for(int i=1;i<=n;i++)
            if(a[i]>=sum) cnt++;
        if(cnt>=m) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }

}
void solve_C()
{
    ULL n,k;
    while(cin>>n>>k)
    {
        if(n==0){
            cout<<0<<endl;
            continue;
        }
    ULL ans=min(n%k,k-n%k);
    cout<<ans<<endl;
    }
}
int main()
{
    //freopen("D:\\CODE\\code_contest\\in.txt","w",stdout);
    //freopen("D:\\CODE\\code_contest\\in.txt","r",stdin);  
    solve_C();
    return 0;
}

Measured memory_bytes: 256