akhauriyash/Code-Regression huggingface dataset:
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
    int x = Integer.parseInt(sc.next());
    List<Book> books = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      Book book = new Book(
        i,
        Integer.parseInt(sc.next())
      );
      int a[] = new int[m];
      for (int j = 0; j < m; j++) {
        a[j] = Integer.parseInt(sc.next());
      }
      book.a = a;
      books.add(book);
    }
    int ans = dfs(books, 0, 0, new Understand(x, m));
    pw.println(ans);
  }

  static int dfs(List<Book> books, int index, int price, Understand understand) {
    if (understand.isOk()) {
      return price;
    }
    boolean found = false;
    int ans = Integer.MAX_VALUE;
    for (int i = index; i < books.size(); i++) {
      Understand copy = new Understand(understand);
      copy.read(books.get(i));
      int childAns = dfs(books, i + 1, price + books.get(i).c, copy);
      if (childAns < 0) {
        continue;
      }
      found = true;
      ans = Math.min(ans, childAns);
    }
    if (found) {
      return ans;
    } else {
      return -1;
    }
  }

  static class Understand {

    int x;
    int current[];
    List<Book> read = new ArrayList<>();

    public Understand(int x, int m) {
      this.x = x;
      current = new int[m];
    }

    public Understand(Understand u) {
      this.x = u.x;
      this.current = Arrays.copyOf(u.current, u.current.length);
      this.read = new ArrayList<>(u.read);
    }

    void read(Book b) {
      read.add(b);
      for (int i = 0; i < b.a.length; i++) {
        current[i] += b.a[i];
      }
    }

    boolean isOk() {
      return Arrays.stream(current).allMatch(i -> i >= x);
    }

    @Override
    public String toString() {
      return
        read.stream().map(b -> String.valueOf(b.index)).collect(Collectors.joining(", ")) + ":"
          + Arrays.toString(current);
    }
  }

  static class Book {

    int index;
    int c;
    int a[];

    public Book(int index, int c) {
      this.index = index;
      this.c = c;
    }
  }
}


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

using namespace std;

int main() {
#ifdef _DEBUG
	freopen("_in" , "r", stdin );
	freopen("_out", "w", stdout);
#endif
	int n, k; cin >> n >> k;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int t; cin >> t;
		if (t >= k) ans++;
	}
	cout << ans << '\n';
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a), q(b), r(c);
    cin >> p >> q >> r;
    sort(p.begin(), p.end(), greater<int>());
    sort(q.begin(), q.end(), greater<int>());
    while(p.size() > x) p.pop_back();
    while(q.size() > y) q.pop_back();
    r.insert(r.end(), p.begin(), p.end());
    r.insert(r.end(), q.begin(), q.end());
    sort(r.begin(), r.end(), greater<int>());
    cout << accumulate(r.begin(), r.begin() + x + y, 0ll) << endl;
    return 0;
}


Measured memory_bytes: 2936
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
using namespace std;
typedef pair <int, int> pii;
int main()
{

	//int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, ans = 0;
	//cout << LONG_MAX << endl;
	string s, t;
	//long long n, A[1000000000];
	int n, m, q;
	//int   y[100001], z[100001], x[10001] = {};
	//pii y[100001];
	//pair<int, float> pii[100001];
	int A[501][501] = {};
	int B[501][501] = {};
	cin >> n;
	cin >> m;
	cin >> q;
	for (a = 1; a <= m; a++)
	{
		cin >> b;
		cin >> c;
		A[b][c]++;

	}
	int r;
	for (a = 1; a <= q; a++)
	{

		scanf("%d", &l);
		scanf("%d", &r);
		if (B[l][r] != 0)
		{
			printf("%d\n", B[l][r]);

		}
		else
		{

			d = 0;
			for (b = l; b <= r; b++)
			{
				for (c = b; c <= r; c++)
				{
					d += A[b][c];
				}
			}
			printf("%d\n", d);
			B[l][r] = d;
			//cout << d << endl;
		}

	}
	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << 1 << endl;


	return 0;
}

Measured memory_bytes: 2944
#include <iostream>

using std::cout;
using std::endl;

typedef enum {PRE, MEIJI, TAISHO, SHOWA, HEISEI} Gengou_t;

Gengou_t getGengou(int year_west, int month, int day);

int main()
{
    int year_west, month, day;
    while (std::cin >> year_west >> month >> day) {
        Gengou_t gengou = getGengou(year_west, month, day);
        int year_ja;

        switch (gengou) {
            case PRE:
                cout << "pre-meiji" << endl;
                break;
            case MEIJI:
                cout << "meiji ";
                year_ja = year_west - 1868 + 1;
                break;
            case TAISHO:
                cout << "taisho ";
                year_ja = year_west - 1912 + 1;
                break;
            case SHOWA:
                cout << "showa ";
                year_ja = year_west - 1926 + 1;
                break;
            case HEISEI:
                cout << "heisei ";
                year_ja = year_west - 1989 + 1;
                break;
        }

        if (gengou != PRE) {
            cout << year_ja << " " << month << " " << day << endl;
        }
    }

    return 0;
}

Gengou_t getGengou(int year_west, int month, int day)
{
    long yyyymmdd = 10000 * year_west + 100 * month + day;

    if (yyyymmdd < 18680908) {
        return PRE;
    } else if (yyyymmdd < 19120730) {
        return MEIJI;
    } else if (yyyymmdd < 19261225) {
        return TAISHO;
    } else if (yyyymmdd < 19890108) {
        return SHOWA;
    } else {
        return HEISEI;
    }
}

Measured memory_bytes: 1160
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    ll a = in(), b = in();
    ll cnt = 0;
    REP(i, 2) {
        if (a > b) {
            cnt += a;
            --a;
        } else {
            cnt += b;
            --b;
        }
    }
    cout << cnt << endl;
}

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

using namespace std;

int main(void)
{
	int k; cin>>k;
	int w[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	
	cout<<w[k-1]<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define deb(x) cout << #x << " = "<< x << "\n";

signed main() {
	//freopen("in.txt", "r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	string s, t;
	cin >> s >> t;
	int ans = 0;
	for(int i = 0; i < s.length(); i++) {
		ans += (s[i] != t[i]);
	}
	cout << ans << "\n";
}


Measured memory_bytes: 3756
import java.util.Scanner;

class Main {
  public static void main(String args[]) {
	  	Scanner scanner = new Scanner(System.in);
	  	int  x = scanner.nextInt();			//入力
	  	int  y = scanner.nextInt();
	  	int J;
	  	if(x == y)			//比較
	  		J = 1;
	  	else{
	  		if(x > y)
	  			J = 2;
	  		else
	  			J = 3;
	  	}
	  	
	  	switch(J){
	  	case 1:
	  		System.out.println("a == b");
	  		break;
	  	case 2:
	  		System.out.println("a > b");
	  		break;
	  	case 3:
	  		System.out.println("a < b");
	  	}
	  	
        scanner.close();
  }
}


Measured memory_bytes: 26268
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){

  int x[3000], y[3000];
  int i;

  for(i = 0; i < 3000; i++){
    scanf("%d %d", &x[i], &y[i]);
    if(x[i] == 0 && y[i] == 0){
      break;
    }else if(x[i] > y[i]){
      printf("%d %d\n", y[i], x[i]);
    }else{
      printf("%d %d\n", x[i], y[i]);
    }
  }
    
  return 0;
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
 
using namespace std;
 
int main() {
    string str;
    cin >> str;
    int beg = str.find_first_of('S');
    int end = str.find_last_of('T');
    if( beg == string::npos || end == string::npos ) {
        printf("%d\n",(int)str.size());
        return 0;
    }
    int ans = (int)str.size();
    int scnt = 0, tcnt = 0;
    for(int i = beg; i<=end; ++i) {
        if( str[i] == 'S' ) ++scnt;
        else ++tcnt;
        if( tcnt ) {
            int mn = min(scnt,tcnt);
            ans -= mn*2;
            scnt -= mn;
            tcnt -= mn;
            if( !scnt ) tcnt = 0;
        }

    }
    printf("%d\n",ans);
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define min(a, b) (a > b ? b : a)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll nck(int n, int k) { ll ret = 1; rep(i, k) {ret *= n - i; ret /= i + 1; } return ret; } // n <= 60
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


int n, k;

void solve() {
    
    double sum = 0;
    rep3(i, 1, n + 1) {
        
        double tmp = 1.0;
        int j = i;
        while (1) {
            if (j >= k) break;
            tmp *= 1.0 / 2;
            j *= 2;
        }
        sum += 1.0 / n * tmp;
    }
    out(FIX(10) << sum);
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n >> k;
    
    
    solve();
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <stack>

typedef long long ll;
typedef std::vector< int > VI;

const double EPS = 1e-10;
const double PI  = acos(-1);
const ll     INF = LLONG_MAX /10;

ll gcd(ll a, ll b)
{
  while (b > 0) {
    a = a % b;
    std::swap(a, b);
  }
  return a;
}

ll lcm(ll a, ll b) {
  ll gcd_val = gcd(a, b);
  return a / gcd_val * b;   // over flow 防止のため、割り算を先にする
}

ll extgcd(ll a, ll b, ll& x, ll& y)
{
  ll d = a;
  if (b != 0) {
    ll x_dash;
    ll y_dash;
    d = extgcd(b, a % b, x_dash, y_dash);
    x = y_dash;
    y = x_dash - (a / b) * y_dash;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}

int main(int argc, char* argv[])
{
  ll n;
  std::cin >> n;

  std::vector< ll > va(n, 0);
  std::vector< ll >::iterator it;

  for (ll i = 0; i < n; i++) {
    std::cin >> va[i];
  }

  ll min_elem = *std::min_element(va.begin(), va.end());
  ll max_elem = *std::max_element(va.begin(), va.end());
  ll max_x = std::max((ll)std::fabs(min_elem), (ll)std::fabs(max_elem));

  ll ans = +INF;
  for (int x = -max_x; x <= max_x; x++) {
    ll calc = 0;
    for (it = va.begin(); it != va.end(); it++) {
      calc += std::pow((*it - x), 2);
    }
    ans = std::min(ans, calc);
  }

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

  return 0;
}


Measured memory_bytes: 256
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var M = one[1];
  var mod = 1000000007;
  var output = 1;
  if(Math.abs(N - M) >= 2){
    myout(0);
  }else{
    for(var i = 1; i <= N; i++){
      output *= i;
      output %= mod;
    }
    for(var i = 1; i <= M; i++){
      output *= i;
      output %= mod;
    }
    if(M == N){
      output *= 2;
      output %= mod;
    }
    myout(output);
  }
}

Measured memory_bytes: 33492
#include<stdio.h>
int main(){
char s[15],t[15];
  int i,j,k;

scanf("%s",s);
  scanf("%s",t);
  
  for(i=0; s[i]!='\0'; ++i);
  for(j=0; t[j]!='\0'; ++j);

  if(i==j-1){
    for(k=0;k<i;k++){
      if(s[k]!=t[k]){
        printf("No\n");
        return 0;
      }
    }
  }
    if(i!=j-1){
              printf("No\n");
        return 0;
    }
      
    printf("Yes\n");
    return 0;
    

}


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

using namespace std;

struct s{
    int x, y, n;
};

bool cmp(s a, s b){
    if(a.x < b.x){
        return true;
    }
    else if(a.x == b.x){
        return a.y < b.y;
    }
    else{
        return false;
    }
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector 
 a(n), b(m);
    for(int i = 0; i < n; i++){
        cin >> a[i].x >> a[i].y;
        a[i].n = i;
    }
    for(int i = 0; i < m; i++){
        cin >> b[i].x >> b[i].y;
        b[i].n = i;
    }

    sort(b.begin(), b.end(), cmp);

    for(int i = 0; i < n; i++){
        int id = 0, len = INT_MAX;
        for(int j = 0; j < m; j++){
            if(len > (abs(a[i].x - b[j].x) + (abs(a[i].y - b[j].y)))){
                len = abs(a[i].x - b[j].x) + abs(a[i].y - b[j].y);
                id = b[j].n;
            }
        }
        cout << id + 1 << endl;
    }
    return 0;
}


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

using namespace std;
 
int main() {
    int n; cin>>n;
    int count = 0;
    vector<int> p(n), a(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    for(int i = 0; i < n; i++) a[i] = p[i];

    sort(p.begin(), p.end());
    for(int i = 0; i < n; i++){
        if(a[i] != p[i]) count++;
    }

    if(count <= 2) cout << "YES"<<endl;
    else cout << "NO" <<endl;
    return 0;
}

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

 
int main() {

  int N;
  cin >> N;

  vector<int> P(N);
  for (int i = 0; i < N; i++) {
    cin >> P[i];
  } 

  vector<int> Q(N);
  for (int i = 0; i < N; i++) {
    cin >> Q[i];
  }

  vector<int> v;
  for (int i = 0; i < N; i++) {
    v.push_back(i+1);
  }

  map<vector<int>, int> mp;
  do {
    mp[v] = mp.size();
  } while (next_permutation(v.begin(), v.end()));

  int a = mp[P];
  int b = mp[Q];

  cout << abs(a - b) << endl;

}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  int n;
  cin>>n;
  vecint dp(3, 0);
  for(auto&& i:irange(0,n)) {
    int d[3];
    for(auto&& j:irange(0,3)) {
      cin>>d[j];
    }
    vecint tmp(3, 0);
    for(auto&& j:irange(0,3)) {
      for(auto&& k:irange(0,3)) {
        if(j==k) continue;
        tmp[j] = max(tmp[j], dp[k] + d[j]);
      }
    }
    swap(dp, tmp);
  }
  cout<<*boost::max_element(dp)<<endl;
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int N, K; cin >> N >> K;
  string s; cin >> s;
  vi32 cnt;
  {
    char prev = '1';
    int c = 0;
    rep(i, N) {
      if (s[i] != prev) {
        cnt.push_back(c);
        c = 1;
        prev = s[i];
      } else {
        c++;
      }
    }
    cnt.push_back(c);
    if (prev != '1') cnt.push_back(0);
  }
  int n = cnt.size();
  int r = 2 * K + 1;
  int ans = 0;
  vi32 acc(n + 1);
  rep(i, n) acc[i + 1] = acc[i] + cnt[i];
  for (int i = 0; i < n; i += 2) {
    amax(ans, acc[min(n, i + r)] - acc[i]);
  }
  cout << ans << '\n';
}


Measured memory_bytes: 1272
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-04 20:54:26
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  int x, y, z; cin >> x >> y >> z;
  swap(x, y); swap(x, z);

  cout << x << " " << y << " " << z << endl;

  return 0;
}

Measured memory_bytes: 896
// https://tenka1-2019-beginner.contest.atcoder.jp/tasks/tenka1_2019_a

#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <regex>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define EPS (1e-7)
#define INF (1e9)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// long gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// long lcm(long a, long b) { return a * b / gcd(a, b); }
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, bl1 = 0, bl2 = 0, wh1 = 0, wh2 = 0, ans = INF;
    string s;
    cin >> n >> s;
    // 黒を数える
    for (int i = 0; i < (int)s.length(); i++) {
        if (s[i] == '.') {
            wh1++;
        } else {
            bl1++;
        }
    }

    // 左にある黒い石の個数とそれより右にある白い石の個数の和
    ans = min(ans, bl2 + wh1 - wh2);
    for (int i = 0; i < (int)s.length(); i++) {
        if (s[i] == '.') {
            wh2++;
        } else {
            bl2++;
        }
        // 左にある黒い石の個数とそれより右にある白い石の個数の和
        ans = min(ans, bl2 + wh1 - wh2);
    }

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


Measured memory_bytes: 720
n = int(raw_input())
  
d = [0 for i in range(n)]
f = [0 for i in range(n)]
a = [[0 for i in range(n)] for j in range(n)]
st = [0 for i in range(n)]
time = [0]
g = [0 for i in range(n)]
  
  
def dfs_visit(s):
    st[s] = 1
    time[0] += 1
    d[s] = time[0]
      
    for k in range(n):  
      if a[s][k] == 1 and st[k] == 0:
          dfs_visit(k)
    st[s] ==2
    time[0] += 1
    f[s] = time[0]
  
def main():
    for s in range(n):
        if st[s] == 0:
            dfs_visit(s)
    for s in range(n):
        print '%d %d %d' %(s+1, d[s], f[s])
  
for i in range(n):
    g = map(int, raw_input().split())
    for j in range(g[1]):
        a[g[0]-1][g[2+j]-1] = 1
  
main()

Measured memory_bytes: 6476
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	static const ULL M = 1000000007;
	ULL A[100000];

	ULL inv[100001];
	ULL fac[100001];
	ULL ifac[100001];
	ULL C[100001] = {};

	void Solve() {
		ULL N, K; cin >> N >> K;
		rep(i, N) {
			LL a; cin >> a;
			A[i] = M + a;
		}
		sort(A, A + N);

		inv[0] = inv[1] = 1; for (UL i = 2; i <= N; i++) inv[i] = (M - (inv[M%i] * (M / i) % M)) % M;
		fac[0] = 1; for (UL i = 1; i <= N; i++) fac[i] = fac[i - 1] * i % M;
		ifac[0] = 1; for (UL i = 1; i <= N; i++) ifac[i] = ifac[i - 1] * inv[i] % M;

		for (UL i = K; i <= N; i++) {
			ULL c = fac[i];
			c = c * ifac[K] % M;
			c = c * ifac[i - K] % M;
			C[i] = c;
		}

		ULL ans = 0;
		rep(i, N) {
			if (i >= K - 1) {
				ULL d = (M + C[i + 1] - C[i]) % M;
				ans += d * A[i];
			}
			if (i <= N - K) {
				UL l = N - i;
				ULL d = (M + C[l] - C[l - 1]) % M;
				ans += M - A[i] * d % M;
			}

			ans %= M;
		}
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }


main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    int cnt = min(k, a);
    ans += cnt;
    k -= cnt;
    cnt = min(k, b);
    k -= cnt;
    cnt = min(k, c);
    ans -= cnt;
    cout << ans << '\n';
}


Measured memory_bytes: 3644
#include <iostream>
#include <string.h>

using namespace std;

int main()
{
    
    int a;
    string str;
    string first="es";
    string second="s";
    cin>>str;
    a=str.size();
     if(str[a-1]=='s')
        {
           cout<<str.append(first); 
        }
        else
        {
            cout<<str.append(second);
        }
    
    
}

Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>


#define mod 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

using namespace std;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    int N,M;
    int a[100001];
    cin>>N>>M;
    int dp[100001][2]={};
    rep(i,0,M){
        cin>>a[i];
        dp[a[i]][1]=1;
    }
    dp[0][0]=1;
    if(dp[1][1]!=1)dp[1][0]=1;
    else dp[1][0]=0;

    rep(i,2,N+1){
        if(dp[i][1]!=1){
            dp[i][0]=dp[i-1][0]+dp[i-2][0];
        }
        else dp[i][0]=0;
        dp[i][0]%=mod;
    }

    cout<<dp[N][0];
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;
typedef vector<long long int> vll;

int main() {
	int n;
	cin >> n;
	set<int> st;
	rep(i, 0, n) {
		int a;
		cin >> a;
		st.insert(a);
	}
	if (st.size() % 2 == 1) cout << st.size() << endl;
	else cout << st.size() - 1 << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define lli long long int
#define ld long double
#define fop(i,m,n) for (int i=(m);i<(n);i++)
#define FOP(i,m,n) for (int i=(m)-1;i>=(n);--i)
#define test(x) cout << #x << ' ' << x << endl;
#define printv(a) {\
    for (auto y : a) cout << y << ' ';\
    cout << '\n';\
}
#define eb emplace_back
#define pb push_back
#define mp make_pair 
#define mt make_tuple
#define pii pair<int,int> 
#define pll pair<lli,lli>
#define tiii tuple<int,int,int>
#define all(a) a.begin(), a.end()
#define X first
#define Y second
#define oset tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update>
#define readfile freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 
auto SEED = chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(SEED);
const int mod = 998244353, x = 864197532, N = 20, logN = 18, K = 350, all = (1 << N) - 1;

int main () {
	int c;
	cin >> c;
	cout << (c >= 30 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> logs;
  int l = 0, r = 0;
  for (int i = 0; i < n; ++i) {    int a;
    cin >> a;
    r = max(r, a);
    logs.emplace_back(a);
  }
  while (r - l > 1) {
    int mid = (l + r) / 2;
    int tryNum = 0;
    for (const auto& log : logs) {
      tryNum += (log - 1) / mid;
      if (tryNum > k) {
        break;
      }
    }
    if (tryNum > k) {
      l = mid;
    } else {
      r = mid;
    }
  }
  cout << r << endl;
  return 0;
}

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

using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define rep(i, n) for (int i = 0; i < n; i++)

int N;
Graph G;

vector<int> res;

void dfs(int v, int p, int c)
{
    res[v] = c;
    for (auto e : G[v])
    {
        if (e.first == p)
            continue; // 木の枝刈りの書き方
        if (e.second & 1)
            dfs(e.first, v, 1 - c);
        else
            dfs(e.first, v, c);
    }
}

int main()
{
    cin >> N;
    G.assign(N, vector<Edge>());
    for (int i = 0; i < N - 1; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        --u, --v;
        G[u].push_back(Edge(v, w));
        G[v].push_back(Edge(u, w));
    }
    res.assign(N, 0);
    dfs(0, -1, 1); // parent は -1にしておく
    for (auto v : res)
        cout << v << endl;
}


Measured memory_bytes: 8960
n=gets.to_i
a=Array.new(n)
a=gets.chomp.split(" ").map(&:to_i)
=begin
for i in 0..a.length-1
    a[i]=a[i].to_i
end
=end

b=a.sort

maxcnt=0
maenopib=0

for i in 0..n-1
    cnt=0
    pib=b[i]
    if i!=0 && pib==b[i-1]
        next
    end

    for j in i..n-1
        if b[j]==pib || b[j]==pib+1 || b[j]==pib+2
            cnt+=1
        else
            break
        end
    end
    if cnt>maxcnt
        maxcnt=cnt
    end
end
print maxcnt





Measured memory_bytes: 12792
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}





int main() {
	

	ll N,K,an=0;
	cin >> N>>K;
	
	vector<ll> ve(N);

	rep(i, N) {
		
		cin >> ve.at(i);
		
	}
	sort(ve.begin(), ve.end());
	reverse(ve.begin(), ve.end());
	rep(i, N) {
		if (K > 0) {
	
			K--;
		}
		else {
			an += ve.at(i);
		}
	}
	
	cout << an << endl;


}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define fi first
#define se second
#define max3(a, b, c) max(a, max(b, c))

using namespace std;

typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
const int maxn = 6e5+10;
const int MOD = 1e9+7;
int n, k;
ll res, a[maxn], Tu;
ll Mul(ll A, ll B)
{
    A %= MOD;
    B %= MOD;
    return (A*B)%MOD;
}
ll fastPow(ll n, int k)
{
    ll tmp = 1;
    while (k)
    {
        if (k&1) tmp = Mul(tmp, n);
        n = Mul(n, n);
        k >>= 1;
    }
    return tmp;
}
int main()
{
    cin >> n >> k;
    for (int i = 0 ; i < n ; i++)
        cin >> a[i];
    /**************************************/
    sort(a, a+n);
    Tu = 1;
    res += a[k-1];
    for (int i = k ; i < n ; i++)
    res = res + Mul(a[i], Tu = Mul(Tu*i, fastPow(i-k+1, MOD-2))), res %= MOD;
    /**************************************/
    reverse(a, a+n);
    Tu = 1;
    res -= a[k-1];
    for (int i = k ; i < n ; i++)
    res = res - Mul(a[i], Tu = Mul(Tu*i, fastPow(i-k+1, MOD-2))), res %= MOD;
    cout << res%MOD;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, x[200100], y[200100], i, ans=-1, distx, disty;
    cin >> n;
    for(i=0;i<n;i++){
        long long tmpx, tmpy;
        cin >> x[i] >> y[i];
        tmpx=x[i];tmpy=y[i];
        x[i]-=tmpy;
        y[i]+=tmpx;
    }
    sort(x, x+n);
    sort(y, y+n);
    distx=x[n-1]-x[0];
    disty=y[n-1]-y[0];
    ans=max(distx, disty);
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 6712
x,y,h,w,T;main(n){for(;scanf("%d",&n)*n;T=!printf("%d\n",T))for(;n--;T+=x>8?0:x*200)scanf("%d%d%d%d",&x,&y,&h,&w),x=(x+y+h+19)/20,w=w<3?3:(w+19)/5,x=x>w?x:w;}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int n, m, a[N];
int seg[N * 4];
void update(int k, int x, int i = 1, int l = 1, int r = n) {
	if (l == r) {
		seg[i] = x;
		return;
	}
	int mid = (l + r) >> 1;
	if (k <= mid)
		update(k, x, i << 1, l, mid);
	else
		update(k, x, i << 1 | 1, mid + 1, r);
	seg[i] = max(seg[i << 1], seg[i << 1 | 1]);
}
int query(int lf, int rg, int i = 1, int l = 1, int r = n) {
	if (lf > rg) return 0;
	if (lf <= l && r <= rg)
		return seg[i];
	int res = 0;
	int mid = (l + r) >> 1;
	if (lf <= mid)
		res = max(res, query(lf, rg, i << 1, l, mid));
	if (rg > mid)
		res = max(res, query(lf, rg, i << 1 | 1, mid + 1, r));
	return res;
}
int ind[N], lst[N], ans[N];
vector<int> G[N];
priority_queue<int> que;
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		int x;
		scanf("%d", &x);
		a[x] = i;
	}
	for (int i = 1; i <= n; i++) {
		int j;
		j = query(max(1, a[i] - m + 1), a[i] - 1);
		if (j) G[a[i]].push_back(a[j]), ind[a[j]]++;
		j = query(a[i] + 1, min(n, a[i] + m - 1));
		if (j) G[a[i]].push_back(a[j]), ind[a[j]]++;
		update(a[i], i);
	}
	for (int u = 1; u <= n; u++)
		if (!ind[u])
			que.push(u);
	int cnt = 0;
	while (!que.empty()) {
		int u = que.top();
		lst[++cnt] = u;
		que.pop();
		for (int i = 0; i < (int)G[u].size(); i++) {
			int v = G[u][i];
			ind[v]--;
			if (!ind[v])
				que.push(v);
		}
	}
	reverse(lst + 1, lst + 1 + n);
	for (int i = 1; i <= n; i++)
		ans[lst[i]] = i;
	for (int i = 1; i <= n; i++)
		printf("%d\n", ans[i]);
	return 0;
}

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

int main(){
    for(int i=0;i<500000;i++){
        int h,w;
        cin>>h>>w;
        if(h==0&&w==0) break;
        else{
            for(int i=0;i<h;i++){
                for(int k=0;k<w;k++){
                    cout<<'#';
                }
            cout<<endl;
            }
        cout<<endl;
        }
    }
}


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

int main(){
    int N,M;
    cin >> N >> M;
    int c[M+1];

    for(int i=1;i<=M;i++){
        c[i]=0;
    }

    int k,v;
    for(int i=0;i<N;i++){
        cin >> k;
        for(int j=0;j<k;j++){
            cin >> v;
            c[v]++;
        }
    }

    int ans=0;
    for(int i=1;i<=M;i++){
        if(c[i]==N) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n,m,x;cin>>n>>m>>x;
  vector<int> a(n);
  rep(i,m)cin>>a[i];
  int l=0,r=0;
  rep(i,m){
    if(a[i]<x)l++;
    else r++;
  }
  cout<<min(l,r)<<endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    VEC(int) D(N);
    READVEC(D);
    int ret = 0;
    FOR(i, 0, N)
        FOR(j, 0, i)
        ret += D[i] * D[j];
    cout << ret << endl;
    return 0;
};


Measured memory_bytes: 384
use proconio::{input, fastout};
use std::cmp::max;

#[fastout]
fn main() {
    input! {
        n: i64,
        m: i64,
        aaa: [i64; m],
    }
    let homework: i64 = aaa.iter().sum();
    println!("{}", max(-1, n - homework));
}


Measured memory_bytes: 2276
#include <iostream>

using ll = long long;
using namespace std;

int main() {
  int bill_num;
  int sum;

  cin >> bill_num >> sum;

  int large_ans, midddle_ans, small_ans;
  large_ans = midddle_ans = small_ans = -1;
  for(int large_num = 0; large_num <= bill_num; large_num++) {
    for(int middle_num = 0; middle_num + large_num <= bill_num; middle_num++) {
      int small_num = bill_num - large_num - middle_num;

      ll candidate_sum = 10000 * large_num + 5000 * middle_num + 1000 * small_num;
      if(candidate_sum == sum) {
        large_ans = large_num;
        midddle_ans = middle_num;
        small_ans = small_num;
      }
    }

  }

  cout << large_ans << ' ' << midddle_ans << ' ' << small_ans << endl;
}

Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1LL<<60)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())
#define MOD 1000000007


int n, m;
int s, t;

vector<pair<int, int>> edge[100000];

long long d1[100000];
long long cnt1[100000];
long long d2[100000];
long long cnt2[100000];

void calc1(int s, long long d[]) {
	fill_n(d, n, INF);
	priority_queue<pair<long long, int>> pq;
	pq.emplace(0, s);
	d[s] = 0;

	while (!pq.empty()) {
		auto p = pq.top();
		pq.pop();
		int u = p.second;
		if (d[u] < -p.first)continue;
		for (auto e : edge[p.second]) {
			long long c = -p.first + e.second;
			int v = e.first;
			if (d[v] == INF || c < d[v]) {
				d[v] = c;
				pq.emplace(-c, v);
			}
		}
	}
}

void calc2(int s, long long d2[], long long cnt[],long long mind) {
	fill_n(cnt, n, 0LL);
	cnt[s] = 1;
	priority_queue<pair<long long, int>> pq;
	pq.emplace(0, s);
	vector<bool> in(n, false);
	in[s] = true;

	while (!pq.empty()) {
		auto p = pq.top();
		pq.pop();
		int u = p.second;
		for (auto e : edge[p.second]) {
			long long c = -p.first + e.second;
			int v = e.first;
			if (c + d2[v] == mind) {
				if (!in[v]) {
					pq.emplace(-c, v);
					in[v] = true;
				}
				cnt[v] += cnt[u];
				cnt[v] %= MOD;
			}
		}
	}
}



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

	cin >> n >> m >> s >> t;
	s--; t--;
	rep(i,m) {
		int u, v, d;
		cin >> u >> v >> d;
		u--; v--;
		edge[u].emplace_back(v, d);
		edge[v].emplace_back(u, d);
	}

	calc1(s, d1);
	calc1(t, d2);
	long long mind = d1[t];

	calc2(s, d2, cnt1, mind);
	calc2(t, d1, cnt2, mind);

	long long ans = cnt1[t] * cnt2[s] % MOD;
	rep(u, n)for(auto p : edge[u]) {
		int v = p.first;
		int c = p.second;
		if (d1[u]+c==d1[v] && d2[v]+c==d2[u] 
			&& max(d1[u],d2[v]) < min(d1[u],d2[v]) + c ) {

			//ans -= cnt1[u] * cnt2[v];
			ans -= cnt1[u] * cnt1[u] % MOD * cnt2[v] % MOD * cnt2[v];
			ans %= MOD;
		}
	}
	rep(u, n) if(d1[u]+d2[u]==mind && d1[u]==d2[u]){
		//ans -= cnt1[u] * cnt2[u];
		ans -= cnt1[u] *cnt1[u] % MOD * cnt2[u] % MOD * cnt2[u];
		ans %= MOD;
	}
	ans += MOD;
	ans %= MOD;
	cout << ans << endl;



	return 0;
}

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

int main() {
    ll n;
    std::cin >> n;
    string s;
    std::cin >> s;
    vector<vector<vector<bool>>> done(10,vector<vector<bool>>(10,vector<bool>(10)));
    ll res = 0;
    
    vector<ll> dp1(10,0);
    vector<vector<ll>> dp2(10,vector<ll>(10,0));
    
    for (int i = 0; i < n; i++) {
        int x = s[i]-'0';
        for (int j = 0; j < 10; j++) {
            for (int k = 0; k < 10; k++) {
                if(done[j][k][x]==1){
                    continue;
                }
                if(dp2[j][k]){
                    res++;
                    done[j][k][x]=1;
                }
            }
            if(dp1[j]==1){
                dp2[j][x] = 1;   
            }
        }
        dp1[x] = 1;
    }
    std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<int> sz(n + 1);
	for (int i = 1; i <= n; ++i) {
		cin >> sz[i];
	}

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

	vector<long long> pre_sum(n + 1);
	for (int i = 1; i <= n; ++i) {
		pre_sum[i] = (long long) sz[i] + pre_sum[i - 1];
	}

	int curr_creature = 1, curr_idx = 1;
	while (curr_creature <= n) {
		long long can_eat = 2 * pre_sum[curr_idx];
		vector<int>::iterator low = lower_bound(sz.begin(), sz.end(), can_eat);
		if (low == sz.end()) {
			cout << n - curr_creature + 1 << "\n";
			return 0;
		}

		int i = low - sz.begin();
		if (*low > can_eat) {
			--i;
		}

		if (i == curr_idx) {
			++curr_creature;
			curr_idx = curr_creature;
		} else {
			curr_idx = i;
		}
	}

	cout << "0\n";

	return 0;

}

Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int deg[60];

signed main() {
    int n, m; cin >> n >> m;
    memset(deg, 0, sizeof(deg));
    rep(i,0,m) {
        int a, b; cin >> a >> b;
        a--; b--;
        deg[a]++;
        deg[b]++;
    }
    rep(i,0,n) {
        cout << deg[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256