akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool up_min(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool up_max(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }

    ll operator"" _64(unsigned long long x){ return ll(x); }
    ull operator"" _64u(unsigned long long x){ return ull(x); }

    template<class T>
    vector<T> make_mdvector(int n, T t){
        return vector<T>(n, t);
    }
    template<class ...Ts>
    auto make_mdvector(int n, Ts ... ts){
        return vector<decltype(make_mdvector(ts...))>(n, make_mdvector(ts...));
    }

    inline ll bit(int x){
        return 1ll << x;
    }

    template<class T>
    istream& operator>>(istream& is, vector<T>& v){
        for (auto &&x : v) { is >> x; } return is;
    }

    template<class T>
    ostream& operator<<(ostream& os, const vector<T>& v){
        for (auto &&x : v) { os << x << ' '; } cout << endl; return os ;
    }
}
using namespace utils;

class solver{
    istream& is;
    ostream& os;

public:
    solver(istream& I, ostream& O) :is(I), os(O) {}
    ll N;
    void run();
};

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef XELMH
    string test_cases = "test_A.txt";
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int loop = 0;
    while(fs) {
        loop++;
        cout << '#' << loop << "#------\n";
        solver(fs, cout).run();
    }
    if(loop <= 1) {
        cout << "===" << endl;
        while(cin) solver(cin, cout).run();
    }
#else
    solver(cin, cout).run();
#endif
    return 0;
}


void solver::run(){
    is >> N;
    if(!is) return;
    os << N*N << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define REP(i,a) for(int i=0;i<(a);i++)
#define REPR(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
// using ll = long long;
// using vi = vector<int>;
// using vvi = vector<vi>;
// using vl = vector<long long>;
// using vvl = vector<vl>;
// using vs = vector<string>;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

int main () {
  int s;
  string o;
  cin >> s;
  int a = s/100;
  int b = s%100;
  if(0 < a && a < 13) {
    if(0 < b && b < 13) {
      o = "AMBIGUOUS";
    } else {
      o = "MMYY";
    }
  }
  else {
    if(0 < b && b < 13) {
      o = "YYMM";
    } else {
      o = "NA";
    }
  }
  cout << o << endl;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define inv(n, a) for(int i = 0; i < n; i++) cin >> a[i]
#define MOD 1000000007
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25

int main() {
    int n, h; cin >> n >> h;
    vector<pair<int, int>> P(n);
    pair<int, int> ma = make_pair(0, 0);
    rep(i, n){
        int a, b; cin >> a >> b;
        P[i] = make_pair(a, b);
        if(ma.first < a) ma = make_pair(a, b);
    }
    sort(P.begin(), P.end(), [](const auto& a, const auto& b){return a.second > b.second;});

    int dm = 0;
    bool f = false;
    int ans = 0;
    rep(i, n){
        if(P[i].second < ma.first){
            break;
            // 斬りつけに使う刀の斬りつけダメージより投擲ダメージが小さい刀は使用しない
        }
        h -= P[i].second;
        ans++;
        if(h <= 0){
            cout << ans << endl;
            return 0;
        }
    }
    ans += ceil((double)h / (double)ma.first);
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <utility>
#include <cstdio>

using namespace std;

int N, M, L;
int A[100][100], B[100][100];

int main(void) {

    cin >> N >> M >> L;

    for (int n = 0; n < N; ++n) {
        for (int m = 0; m < M; ++m) {
            cin >> A[n][m];
        }
    }

    for (int m = 0; m < M; ++m) {
        for (int l = 0; l < L; ++l) {
            cin >> B[m][l];
        }
    }

    for (int n = 0; n < N; ++n) {
        for (int l = 0; l < L; ++l) {
            long long total = 0;
            for (int m = 0; m < M; ++m) {
                total += A[n][m] * B[m][l];
            }
            if (l != L-1)
                printf("%lld ", total);
            else
                printf("%lld", total);
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 1232
#include <cstdio>
#include <ctype.h>
const int bufSize = 1e6;
inline char nc()
{
    #ifdef DEBUG
    return getchar();
    #endif
    static char buf[bufSize],*p1 = buf,*p2 = buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,bufSize,stdin),p1==p2)?EOF:*p1++;
}
template<typename T>
inline T read(T &r)
{
    static char c;
    r=0;
    for(c = nc();!isdigit(c);) c = nc();
    for(;isdigit(c);c=nc()) r = r * 10 + c - 48;
    return r;
}
int L,R,d;
int main()
{
    read(L),read(R),read(d);
    int ans = 0;
    for(int i = L;i<=R;++i) ans += !(i%d);
    printf("%d\n",ans);
    return 0;
}

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

#define ll long long
using namespace std;

#define MAXN 200000
#define MAXC 200000
#define MOD 1000000007
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int N, A[MAXN], B[MAXN],C[MAXC], D[MAXN+1];
	cin>>N;
	
	for(int i=0; i<N; ++i)
	{
		cin>>A[i];
		if(i>0 && A[i]==A[i-1])
		{
			--N;
			--i;
		}
	}
	for(int i=0; i<MAXC; ++i)
	{
		C[i]=-1;
	}
	for(int i=N-1; i>=0; --i)
	{
		B[i]=C[A[i]-1];
		C[A[i]-1]=i;
	}
	for(int i=0; i<=N; ++i)
		D[i]=0;
	D[0]=1;
	for(int i=0; i<N; ++i)
	{
		D[i+1]=(D[i]+D[i+1])%MOD;
		if(B[i]!=-1)
		{
			D[B[i]]+=D[i];
			D[B[i]]%=MOD;
		}
		
	}
	cout<<D[N]<<endl;
	return 0;
}


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

int main(){
  int N,Y;
  cin >> N >> Y;
  int res10000 = -1, res5000 = -1, res1000 = -1;
  for(int x=0;x<=N;x++){
    for(int y=0;x+y<=N;y++){
      int z = N-x-y;
      int total = 10000*x+5000*y+1000*z;
      if(total==Y){
        res10000 = x;
        res5000 = y;
        res1000 = z;
      }
    }
  }
  cout << res10000 << " " << res5000 << " "<< res1000;
}


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

int main() {
  int n;
  cin >> n;
  for(int i = 1; i <= 9; ++i) {
    if(n % i == 0) {
      int pos = n / i;
      if(pos >= 1 && pos <= 9) {
        puts("Yes");
        return 0;
      }
    }
  }
  puts("No");
  return 0;
}

Measured memory_bytes: 256
a,b = list(map(int, input().split()))

if a >= b:
    max = a
    min = b
else:
    min = a
    max = b

ans = int((max-min) / 2)
if abs(max - ans) == abs(min + ans):
    print(abs(max-ans))
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 3060
# coding: utf-8
import sys
from bisect import bisect_left, bisect_right, insort

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

""" 
石数最大の中で右の山から取り除く
次の数までまとめて石を取り除く
"""
N = ir()
A = lr()
A = [(x, i+1) for i, x in enumerate(A)] + [(0, 0)]
A.sort(reverse=True)
answer = [0] * (N+1)  # 1-indexed
mi = 10 ** 10
mi_index = 10 ** 10
for i, (x, pre_index) in enumerate(A[:-1]):
    diff = A[i][0] - A[i+1][0]
    if pre_index < mi_index:
        mi_index = pre_index
    answer[mi_index] += diff * (i+1)

print('\n'.join(map(str, answer[1:])))


Measured memory_bytes: 35068
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] tako = new int[N];
   for(int i =0;i<N;i++) 
   {
     tako[i] = sc.nextInt();
   }
   int sum = 0;
   for(int i = 0;i<N;i++){
     for(int k = i+1;k<N;k++){
       sum+= tako[i]*tako[k];
     }
   }
   System.out.println(sum);
 }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H,W;
  cin>>H>>W;
  vector<vector<char>> p(H,vector<char>(W));
  vector<int> t(H);
  vector<int> y(W);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>p[i][j];
      if(p[i][j]=='#'){
        t[i]++;
        y[j]++;
      }
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(t[i]&&y[j]){
        cout<<p[i][j];
      }
    }
    cout<<endl;
  }
}

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

int main()
{

    string s;
    int cnt = 0;

    cin>>s;

    if(s[0] == '1')
    {
        cnt++;
    }

    if(s[1] == '1')
    {
        cnt++;
    }

    if(s[2] == '1')
    {
        cnt++;
    }

    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var inputs = ReadLongs();
            var A = inputs[0];
            var B = inputs[1];
            var C = inputs[2];

            return C <= A + B + 1 ? C + B : B + (A + B + 1);
        }

        #region Console

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 13268
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

template <class Tp, class BinaryOperation1, class BinaryOperation2>
class segment_tree {
public:
  using binary_operation1 = BinaryOperation1;
  using binary_operation2 = BinaryOperation2;
  using value_type = Tp;

private:
  std::vector<value_type> c;
  size_t m = 1;
  binary_operation1 op1;  // aggregate
  binary_operation2 op2;  // update

  void init_resize(size_t n) {
    m = 2*n;
    c.resize(m);
  }

  void init_aggregate() {
    for (size_t i = m/2; i-- > 1;)
      c[i] = op1(c[i<<1], c[i<<1|1]);
  }

public:
  segment_tree(size_t n,
               BinaryOperation1 op1 = BinaryOperation1(),
               BinaryOperation2 op2 = BinaryOperation2()): op1(op1), op2(op2) {

    init_resize(n);
    c.assign(m, op1.identity);
  }

  segment_tree(size_t n, const Tp& e,
               BinaryOperation1 op1 = BinaryOperation1(),
               BinaryOperation2 op2 = BinaryOperation2()): op1(op1), op2(op2) {

    init_resize(n);
    for (size_t i = m/2; i < m; ++i) c[i] = e;
    init_aggregate();
  }

  template <class ForwardIt>
  segment_tree(ForwardIt first, ForwardIt last,
               BinaryOperation1 op1 = BinaryOperation1(),
               BinaryOperation2 op2 = BinaryOperation2()): op1(op1), op2(op2) {

    static_assert(std::is_same<Tp, typename ForwardIt::value_type>::value, "");
    init_resize(std::distance(first, last));
    for (size_t i = m/2; first != last; ++i) c[i] = *first++;
    init_aggregate();
  }

  void update(size_t i, Tp x) {
    i += m/2;
    c[i] = op2(c[i], x);
    while (i > 1) {
      i >>= 1;
      c[i] = op1(c[i<<1], c[i<<1|1]);
    }
  }

  value_type aggregate(size_t l, size_t r) const {
    value_type resl = op1.identity;
    value_type resr = op1.identity;
    l += m/2;
    r += m/2;
    while (l < r) {
      if (l & 1) resl = op1(resl, c[l++]);
      if (r & 1) resr = op1(c[--r], resr);
      size_t j = __builtin_ctzll(l | r);
      l >>= j;
      r >>= j;
    }
    return op1(resl, resr);
  }

  value_type operator [](size_t k) const { return c[k+m/2]; }
};

template <class Tp>
struct max {
  Tp identity = 0;
  Tp operator ()(const Tp& x, const Tp& y) const { return std::max(x, y); }
};

template <class Tp>
struct update {
  Tp operator ()(const Tp&, const Tp& y) const { return y; }
};

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<intmax_t> h(N), a(N);
  for (auto& hi: h) scanf("%jd", &hi);
  for (auto& ai: a) scanf("%jd", &ai);

  segment_tree<intmax_t, max<intmax_t>, update<intmax_t>> sg(N);
  for (size_t i = 0; i < N; ++i) {
    size_t j = h[i];
    sg.update(j-1, sg.aggregate(0, j) + a[i]);
  }

  printf("%jd\n", sg.aggregate(0, N));
}


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

int main() {
  int N, sum;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    sum += y - x + 1;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility> 
#include <unordered_set>
#include <vector>
#include <list> 
#include <string>
#include <iterator> 
#include <deque>
#include <array>
#include <forward_list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <bitset>
#include <numeric>
using namespace std;


const long double PI = 3.14159265358979323846264338327950;
const int N = 1e5+5;

template <class T>
T gcd(T a, T b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n, ans;
	string s, cpr = "ABC";
	cin >> n >> s;
	ans = 0;

	for (int i = 0; i < s.length(); ++i) {
		if (s.substr(i, cpr.length()) == cpr) {
			++ans;
			i += cpr.length() - 1;
		}
	}

	cout << ans << '\n';
}
		

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using II = pair<int, int>; using VII = vector<II>; using VVII = vector<VII>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, const pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, const map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
constexpr int MOD = 1e9 + 7;

signed main() {
  string s, t; cin >> s >> t;
  int n = s.size();
  int m = t.size();
  VVII dp(n + 1, VII(m + 1, {0, -1}));
  II ma = {-1, -1};
  REP (i, n) {
    REP (j, m) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = {dp[i][j].fi + 1, i * m + j};
      } else {
        dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
        // if (dp[i + 1][j].fi > dp[i][j + 1].fi) {
        //   dp[i + 1][j + 1] = {dp[i + 1][j].fi, (i + 1) * m + j};
        // } else {
        //   dp[i + 1][j + 1] = {dp[i][j + 1].fi, i * m + (j + 1)};
        // }
      }
      ma = max(ma, dp[i + 1][j + 1]);
    }
  }
  string ans = "";
  while (ma.fi > 0) {
    int i = ma.se / m;
    int j = ma.se % m;
    assert(s[i] == t[j]);
    ans = s[i] + ans;
    ma = dp[i][j];
  }
  cout << ans << endl;
}


Measured memory_bytes: 141184
#include <iostream>
#include <vector>
#include <limits>
#include <algorithm>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    uint N, K;
    cin >> N >> K;
    vector<uint> v;
    for (auto &&i: irange(0U, N)){
        uint l;
        cin >> l;
        v.emplace_back(l);
    }
    sort(v.begin(), v.end(), greater<>());
    uint ret{0};
    for (auto &&i: irange(0U, K)){
        ret+=v.at(i);
    }
    cout << ret;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

ll n;
ll aa[100010],*a=aa+1;
ll ans;
int main(){
	scanf("%lld",&n);
	rep(i,0,n){
		ll t;
		scanf("%lld",&t);
		a[t-1]++;
		a[t]++;
		a[t+1]++;
	}
	rep(i,0,100000)ans=max(ans,a[i]);
	printf("%lld\n",ans);
}

Measured memory_bytes: 896
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
    public static void main(String[] args) {
        FastReader read = new FastReader();
        int n = read.nextInt();
        int r = read.nextInt();
        int ans = 0;
        if(n == 1){
            ans+=300000;
        }
        else if(n==2){
            ans+=200000;
        }
        else if(n==3){
            ans+=100000;
        }
        if(r == 1){
            ans+=300000;
        }
        else if(r==2){
            ans+=200000;
        }
        else if(r==3){
            ans+=100000;
        }
        if(n == 1 && r == 1){
            ans +=400000;
        }
        System.out.println(ans);
    }
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
}


Measured memory_bytes: 21204
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B, N;
    cin >> A >> B >> N;
    if (N >= B) {
        N = B - 1;
    }
    ll ans = (A * N) / B - A * (N / B);
    cout << ans << endl;
}


Measured memory_bytes: 3652
s = input()
S = ['AKIHABARA', 'KIHABARA', 'AKIHBARA', 'AKIHABRA', 'AKIHABAR',
     'KIHBARA', 'KIHABRA', 'KIHABAR', 'AKIHBRA', 'AKIHBAR', 'AKIHABR',
     'AKIHBR', 'KIHABR', 'KIHBAR', 'KIHBRA', 'KIHBR',
     ]

if s in S:
    ans = 'YES'
else:
    ans = 'NO'

print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int MAXN = 100005;

struct bitree{
	int tree[MAXN];
	void add(int x, int v){
		while(x < MAXN){
			tree[x] += v;
			x += x & -x;
		}
	}
	int query(int x){
		int ret = 0;
		while(x){
			ret += tree[x];
			x -= x & -x;
		}
		return ret;
	}
};

struct seg{
	bitree bit;
	void add(int s, int e, int x){
		bit.add(s, x);
		bit.add(e + 1, (26 - x) % 26);
	}
	int query(int x){
		return bit.query(x);
	}
}seg;

struct disj{
	int pa[MAXN];
	void init(int n){
		iota(pa, pa + n + 1, 0);
	}
	int find(int x){
		return pa[x] = (pa[x] == x ? x : find(pa[x]));
	}
	bool uni(int p, int q){
		p = find(p);
		q = find(q);
		if(p == q) return 0;
		pa[q] = p; return 1;
	}
}disj;

string s;
int q;
vector<int> pos[MAXN];
int nxt[MAXN], dx[MAXN];

int main(){
	cin >> s >> q;
	int n = s.size();
	int h = n / 2;
	disj.init(h);
	for(int i=0; i<q; i++){
		int s, e;
		scanf("%d %d",&s,&e);
		if(s + e > n) tie(s, e) = pi(n+1-e, n+1-s);
		if(e > n - e) e = n - e;
		disj.uni(s - 1, e);
	}
	for(int i=0; i<=h; i++){
		pos[disj.find(i)].push_back(i);
	}
	memset(nxt, -1, sizeof(nxt));
	for(int i=0; i<=h; i++){
		if(pos[i].size() > 1){
			for(int j=1; j<pos[i].size(); j++){
				nxt[pos[i][j-1] + 1] = pos[i][j];
			}
		}
	}
	for(int i=0; i<h; i++){
		dx[i+1] = s[i] - s[n-1-i];
		dx[i+1] += 26;
		dx[i+1] %= 26;
		seg.add(i+1, i+1, dx[i+1]);
	}
	for(int i=1; i<=h; i++){
		if(nxt[i] != -1){
			seg.add(i, nxt[i], 26 - seg.query(i) % 26);
		}
		int q = seg.query(i) % 26;
		if(q){
			puts("NO");
			return 0;
		}
	}
	puts("YES");
}



Measured memory_bytes: 5248
import sys
input=sys.stdin.readline

def shak(n,k):

	a=[int(input()) for _ in range(n)]


	l,r=0,k
	res=0
	cnt=sum(a[l:r])
	while r<n:
		res=max(res,cnt)

		cnt=cnt+a[r]-a[l]
		r+=1
		l+=1
	print(res)

for i in range(5):
	n,k=map(int,input().split())
	if n==k==0:exit()
	shak(n,k)


Measured memory_bytes: 9880
#include <stdio.h>

int main() {
	int N;
	int A[100001] = {};
	scanf("%d",&N);
	int ans = N;
	for (int i = 0; i < N+1; i++) {
		A[i] = getchar();
	}
	for (int i = 1; i < N+1; i++) {
	}
	for (int i =1 ; i < N;i++) {
		if (A[i] == A[i + 1]) {
			ans--;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#define MAX 101

int main() {
  int n, i, u, j, k, v, adj[MAX][MAX];
  
  scanf( "%d" , &n );
  for ( i=1; i<=n; i++ ) for ( j=1; j<=n; j++ ) adj[i][j] = 0;
  
  for ( i=1; i<=n; i++ ) {
    scanf( "%d %d" , &u , &k );
    for ( j=1; j<=k; j++ ) {
      scanf( "%d" , &v );
      adj[u][v] = 1;
    }
  }

  for ( i=1; i<=n; i++ ) {
    for ( j=1; j<n; j++ ) printf( "%d " , adj[i][j] );
    printf( "%d\n" , adj[i][n] );
  }
  
  return 0;
}



Measured memory_bytes: 2108
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  input! {
    n: usize,
  }
  let mut k = 1usize;
  while k * (k - 1) / 2 < n {
    k += 1;
  }
  if k * (k - 1) / 2 != n {
    println!("No");
    return;
  }
  println!("Yes\n{}", k);
  let mut s = vec![vec![]; k];
  let mut index: i32 = 1;
  for i in 0 .. k {
    for j in 0 .. i {
      s[i].push(index);
      s[j].push(index);
      index += 1;
    }
  }
  for g in s.iter() {
    print!("{}", k - 1);
    for &x in g.iter() {
      print!(" {}", x);
    }
    println!("");
  }
}


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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> b=a;
    sort(b.rbegin(),b.rend());
    rep(i,n){
        ll ans=b[0];
        if(b[0]==a[i]) ans=b[1];
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 6408
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <list>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define LL long long
#define eps 1e-6
using namespace std;
const double pi = 3.1415926535;
/*
https://codeforces.com/contest/1106/problems
https://codeforces.com/contest/1106/submit
*/

struct A{
	int x,y,a;
}a[1000];
int main(){
	int w,h,n;
	s(w) s(h) s(n)
		int x,y,a;
	int x_mini = 0,y_mini = 0,x_maxi = w,y_maxi = h;
	for(int i = 0; i < n; i ++){
		s(x) s(y ) s(a)
		if(a == 1){
			if(x > x_mini && x < x_maxi){
				x_mini = x;
			}else if(x <= x_mini){
				
			} else if(x >= x_maxi){
				x_mini = x_maxi;
			}
		}else if(a == 2){
			if(x > x_mini && x < x_maxi){
				x_maxi = x;
			}else if(x <= x_mini){
				x_mini = x_maxi;
			} else if(x >= x_maxi){
				
			}
		}else if(a == 3){
			if(y > y_mini && y < y_maxi){
				y_mini = y;
			} else if(y <= y_mini){
				
			} else if(y >= y_maxi){
				y_mini = y_maxi;
			}
		}else if(a == 4){
			if(y > y_mini && y < y_maxi){
				y_maxi = y;
			}else if(y <= y_mini){
				y_mini = y_maxi;
			} else if(y >= y_maxi){
				
			}
		}
		


	}
	p((x_maxi-x_mini)*(y_maxi-y_mini)) pn


    return 0;

}



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

#define Inf ll(1e18)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=100005;
int n,x,k;
pair<ll,int>a[maxn]; 
ll sum[maxn];
int l[maxn],r[maxn],b[maxn];
bool vis[maxn];
ll ans,base,dlt;

int main(){
	ans=Inf;
	scanf("%d%d",&n,&x);
	REP(i,n){
		scanf("%d%d%d",&b[i],&l[i],&r[i]);
		base+=1LL*l[i]*b[i];
		a[i]=mp(1LL*r[i]*(x-b[i])+1LL*l[i]*b[i],i);
	}
	sort(a+1,a+1+n);
	reverse(a+1,a+1+n);
	REP(i,n)sum[i]=sum[i-1]+a[i].fst;
	REP(i,n){
		if(base-sum[i]<=0){
			k=i-1;
			break;
		}
		vis[a[i].snd]=true;
	}
	REP(i,n){
		ll cur;
		if(!vis[i])cur=base-sum[k];
		else cur=base-sum[k+1]+1LL*r[i]*(x-b[i])+1LL*l[i]*b[i];
		ll tmp=(cur+l[i]-1)/l[i];
		if(tmp<=b[i])ans=min(ans,1LL*k*x+tmp);
		if(cur-1LL*b[i]*l[i]>=0){
			tmp=(cur-1LL*b[i]*l[i]+r[i]-1)/r[i];
			ans=min(ans,1LL*k*x+b[i]+tmp);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3840
#include<stdio.h>

int main(void)
{
  int a,b,i,j,d=0,f,g,h;
  scanf("%d",&a);
  int x[a];
  char c[12];
  for(i=0;i<a;i++)
  {
    scanf("%s %d",c,&b);
    if(c[0]=='i')
    {
      x[i]=b;
    }
    else if(c[6]=='F')
    {
      i-=2;a-=2;
    }
    else if(c[6]=='L'){
      i--;a--;d++;
    }
    else{
      i--;a--;
      f=0;
      for(j=i;j>=0;j--){
        if(f>0)break;
        if(b==x[j]){
          g=i-j;
          h=0;
          f++;
          while(g!=h++)x[j+h-1]=x[j+1+h-1];
          i--;a--;
        }
      }
    }
  }
  for(i=0;i<a-d;i++){
        if(i==a-d-1)printf("%d\n",x[a-1-i]);
    else printf("%d ",x[a-1-i]);
  }
    return 0;
}

Measured memory_bytes: 6176
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
/* #pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
typedef long long ll;
const ll MAXN = 1e5 + 2;
const ll MAXK = 5e2 + 2;
const ll MOD = 1e9 + 7;
const ll MODH = 1e9 + 9;
const int MAXLG = 20;
const long double PI = acos(-1);
const ll p = 41;
const long double EPS = 1e-4;
#define x first
#define y second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll rand(ll a, ll b) {ll c = rng(); return a+((ll)abs(c))%(b-a+1);}
ll binpow(ll a, ll b, ll m) {a %= m;ll res = 1;while (b > 0) {if (b & 1){res = res * a % m;}a = a * a % m;b >>= 1;
}return res;}



int main() {
  
 
 ios::sync_with_stdio(0);
 cin.tie(0);
 cout.tie(0);
  int n,x,t;
  string s;
  cin >> s;
  ll ans = 0;
  for(char c : s){
   ans+=(c - '0');
   ans%=9;
  }
  
  cout << (ans > 0 ? "No" : "Yes");
  

  }

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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

const int N = 100005, M = 1000000007;
ll fact[N], infact[N];
int a[N];

ll power(int x, int y) {
	if (y == 0) return 1;
	ll temp = power(x, y >> 1);
	temp *= temp;
	temp %= M;
	if (y & 1) {
		temp *= x;
		temp %= M;
	}
	return temp;
}

void init() {
	fact[0] = infact[0] = 1;
	for (int i = 1; i < N; i++) {
		fact[i] = (fact[i-1] * i) % M;
		infact[i] = power(fact[i], M - 2);
	}
}

ll C(int n, int r) {
	if (r > n) return 0;
	ll ret = fact[n];
	ret *= infact[n-r];
	ret %= M;
	ret *= infact[r];
	ret %= M;
	return ret;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	init();
	int n, k;
	cin >> n >> k;
	map <int, int> mp;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	ll res = 0;
	for (int i = 0; i < n; i++) {
		res += (C(i, k - 1) * a[i]) % M;
		res %= M;
	}
	for (int i = n - 1; i >= 0; i--) {
		res -= (C(n - i - 1, k - 1) * a[i]) % M;
		res += M;
		res %= M;
	}
	cout << res;
	return 0;
	/*for (auto it = mp.begin(); it != mp.end(); it++) {
		sum += it->se;
		res += (C(sum - 1, k - 1) * it->fi) % M;
		res %= M;
	}
	sum = 0;
	auto it = --mp.end();
	while (it != mp.begin()) {
		sum += it->se;
		res -= (C(sum - 1, k - 1) * it->fi) % M;
		res += M;
		res %= M;
		it--;
	}
	sum += it->se;
	res -= (C(sum - 1, k - 1) * it->fi) % M;
	res += M;
	res %= M;
	/*
	for (auto it = mp.rbegin(); it != mp.rend(); it++) {
		sum += it->se;
		res -= (C(sum - 1, k - 1) * it->fi) % M;
		res += M;
		res %= M;
	}
	cout << res;
	return 0;*/
}


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

int main(){
	char *s;
	s=(char*)malloc(sizeof(char)*100000);
	if(s == NULL) exit(0);

	scanf("%s",s);
	int n = strlen(s);
	int i;
	int par=0;
	for(i=0;i<n;i++){
		if(s[i]=='p')
			par++;
	}
	printf("%d\n",n/2-par);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int cnt[100000];
int ans[100000];

int main()
{
  int N,M;
  int x,y;

  scanf("%d%d",&N,&M);
  for(int i=0;i<N;i++)
    cnt[i]=1;
  ans[0]=1;
  int i;
  for(i=0;i<M;i++){
    scanf("%d%d",&x,&y);
    x--;
    y--;
    cnt[x]--;
    cnt[y]++;
    ans[y]|=ans[x];
    if(cnt[x]==0) ans[x]=0;
  }
  int sum=0;
  for(i=0;i<N;i++){
    sum+=ans[i];
  }
  printf("%d\n",sum);
  return 0;
}


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

using namespace std;

int main() {
    int a, b, n;
    cin >> a >> b >> n;
    pair<int, int> new_record = {a, b};
    vector<int> temp(1001, 0);
    for(int i = 0; i < n; i++)
    {
        int s, f;
        cin >> s >> f;
        for(int j = s; j < f; j++)
        {
            temp[j] = 1;
        }
    }
    bool flag = true;
    for(int i = a; i < b; i++)
    {
        if(temp[i] == 1)
        {
            flag = false;
        }
    }
    if(flag)
    {
        cout << 0 << endl;
    }else{
        cout << 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3092
import java.io.*;
import java.util.StringTokenizer;

import static java.lang.Math.*;

public class Main {
  public static void main(String[] args) {
    new Main().solve();
  }

  private void solve() {
    try(InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out)) {

      long a = in.nextLong();
      long b = in.nextLong();
      long c = in.nextLong();
      long d = in.nextLong();

      final long lcm = c * d / gcd(c ,d);

      a--;
      long x = (b / c) - (a / c);
      long y = (b / d) - (a / d);
      long z = (b / lcm) - (a / lcm);

      final long ans = (b - a) - x - y + z;
      out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }

  // def gcd(a:Long, b:Long):Long = {
  //   if(b == 0) a
  //   else gcd(b, a%b)
  // }

  long gcd(long a, long b) {
    if(b == 0) return a;
    return gcd(b, a % b);
  }

  int atoi(String s) { return Integer.parseInt(s); }
  long atol(String s) { return Long.parseLong(s); }

  static class InputReader implements AutoCloseable {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream), 32768);
      st = null;
    }
    public String next() {
      if (st == null || !st.hasMoreTokens()) {
        try { st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          throw new UncheckedIOException(e);
        }
      }
      return st.nextToken();
    }
    public int nextInt() { return Integer.parseInt(next()); }
    public long nextLong() { return Long.parseLong(next()); }
    int[] mapInt(int len) {
      int[] ret = new int[len];
      for (int i = 0; i < len; i++) ret[i] = Integer.parseInt(next());
      return ret;
    }
    long[] mapLong(int len) {
      long[] ret = new long[len];
      for (int i = 0; i < len; i++) ret[i] = Long.parseLong(next());
      return ret;
    }
    @Override public void close() throws IOException { br.close(); }
  }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) (int i=0; i<n; i++)
int main(){
  int X;
  cin >> X;
  
  int cnt;
  int x = X;
  while(true){
    if(x%10 == 0) break;
    cnt += x%10;
    x = x/10;
  }
  X % cnt == 0 ? cout << "Yes" << endl : cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

import scala.annotation.tailrec

/**
  * Created by ui on 2016/02/07.
  */
object ReverseNumber {
  def run: Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    var l = List.fill(n)(sc.nextInt)
    l = l.reverse
    fact(l)

  }
  @tailrec
  def fact (l:List[Int]): Unit = {
    if (l.size == 1) println(l.head)
    else {print(s"${l.head} ")
      fact (l.tail)
    }

  }
}

/**
  * Created by ui on 2016/02/04.
  */
object Main {
  def main(args: Array[String]): Unit = {
    ReverseNumber.run
  }
}

Measured memory_bytes: 45268
import sys
from collections import Counter

import numpy as np

sys.setrecursionlimit(2147483647)
INF = float('inf')

MOD = 10 ** 9 + 7
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))


def mod_invs(max, mod):
    invs = [1] * (max + 1)
    for x in range(2, max + 1):
        invs[x] = (-(mod // x) * invs[mod % x]) % mod
    return invs


def get_ncrs(n):
    invs = mod_invs(N + 1, MOD)
    ret = [1]
    ncr = 1
    for i in range(1, n + 1):
        ncr = ((ncr * (n - i + 1) % MOD) * invs[i]) % MOD
        ret.append(ncr)
    return ret


# どことどこが一緒？
A = np.array(A)
dup, _ = Counter(A).most_common(1)[0]
L, r = np.where(A == dup)[0]

# dup より端から i 個選ぶ組み合わせ
side_ncrs = get_ncrs(L + N - r)
while len(side_ncrs) < N + 2:
    side_ncrs.append(0)

# 全部選んで選びすぎを引く
# dup を 1 つ選び、その他を dup より端から選ぶ組み合わせが重複する
ans_ncrs = get_ncrs(N + 1)
while len(ans_ncrs) < N + 2:
    ans_ncrs.append(0)
ans = [(ans_ncrs[k] - side_ncrs[k - 1]) % MOD for k in range(1, N + 2)]

print('\n'.join(map(str, ans)))


Measured memory_bytes: 42468
import java.util.Scanner;

public class Main {
	 public static void main(String[] args){
	        Scanner scan = new Scanner(System.in);
	        
	    	Dice dice = new Dice();
	    	
	    	int n;
	    	String dir;
	    	
	    	while (true) {
	    		for (int i = 0; i < 6; i++) {
	        		dice.setDice(i, i + 1);
	        	}
	    		
	        	dice.left();
	        	dice.left();
	    		
	    		n = scan.nextInt();
	    		if (n == 0) break;
	    		
	    		for (int i = 0; i < n; i++) {
	    			dir = scan.next();
	    			if (dir.equals("north")) dice.noth();
	    			else if (dir.equals("east")) dice.east();
	    			else if (dir.equals("west")) dice.west();
	    			else if (dir.equals("south")) dice.south();
	    		}
	    	System.out.println(dice.getDice(0));
	    	}
	    }
}
class Dice {
    private int[] dice = new int[6];

    Dice() {
    	
    };

    Dice(int[] val) {
    	for (int i = 0; i < this.dice.length; i++) {
			this.dice[i] = val[i];
		}
    }

    void setDice(int i, int val) {
    	this.dice[i] = val;
    }

    int getDice(int i) {
    	return this.dice[i];
    }

    int[] getDice() {
    	return this.dice;
    }

	int[] noth() {
		swap(0, 1, 5, 4);
		return this.dice;
	}

	int[] east() {
		swap(0, 3, 5, 2);
		return this.dice;
	}

	int[] west() {
		swap(0, 2, 5, 3);
		return this.dice;
	}

	int[] south() {
		swap(0, 4, 5, 1);
		return this.dice;
	}

	int[] right() {
		swap(1, 2, 4, 3);
		return this.dice;
	}

	int[] left() {
		swap(1, 3, 4, 2);
		return this.dice;
	}

	void swap(int n1, int n2, int n3, int n4) {
		int swap = this.dice[n1];
		this.dice[n1] = this.dice[n2];
		this.dice[n2] = this.dice[n3];
		this.dice[n3] = this.dice[n4];
		this.dice[n4] = swap;
	}

	void dicePrint() {
		int i;
		for (i = 0; i < this.dice.length - 1; i++) {
			System.out.print(this.dice[i] + ", ");
		}
	}
}

Measured memory_bytes: 29280
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int W = sc.nextInt();
        int[] w = new int[N];
        int[] v = new int[N];

        long[][] dp = new long[N+1][100_001];
        for (int i = 0; i < N; i++) {
            w[i] = sc.nextInt();
            v[i] = sc.nextInt();
        }

        for (int i = 0; i < N; i++) {//
            for (int j = 1; j < 100_001 ; j++) {
                dp[i][j] = (long)Integer.MAX_VALUE;
            }
        }

        for (int i = 1; i <= N ; i++) {//item
            for (int j = 1; j <=100_000 ; ++j) {// sum(v)
                if(j-v[i-1] >=0){
                    long w1 = dp[i-1][j-v[i-1]]+w[i-1];
                    long w2 = dp[i-1][j];
                    dp[i][j] = Math.min(w1,w2);
                }else{
                    dp[i][j] =  dp[i-1][j];
                }
            }
        }

        int ans = -1;
        for (int i = 0; i <=100_000; i++) {
            if(dp[N][i] <= W){
                ans = i;
            }
        }

        System.out.println(ans);
    }

}

Measured memory_bytes: 126932
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int N;
	scanf("%d",&N);

	int ans = 0;
	for(int i = 1; i <= N; i++){
		if(i <= 9)ans++;
		if(100 <= i && i <= 999)ans++;
		if(10000 <= i && i <= 99999)ans++;
	}

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

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define INF 1 << 29

int min(int a,int b){
  if(a < b){
    return a;
  }
  return b;
}

int main(void){
  int D,G;
  scanf("%d%d",&D,&G);

  int p[D],c[D];
  for (int i = 0; i < D; i++) {
    scanf("%d%d",&p[i],&c[i]);
  }

  int ans = INF;
  for (int i = 0; i < 1<<D; i++) {
    int maxnum = -1;
    int point = 0;
    int cnt = 0;
    for (int j = 0; j < D; j++) {
      if((i>>j)&1){
        point += (j+1)*100*p[j]+c[j];
        cnt += p[j];
      } else maxnum = j;
    }
    if(point >= G) ans = min(ans,cnt);
    else{
      if(maxnum == -1) continue;
      int plus = (G-point+(maxnum+1)*100-1)/((maxnum+1)*100);
      if(plus >= p[maxnum]) continue;
      ans = min(ans,cnt+plus);
    }
  }

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

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


int main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n){
		cin >> a[i];
	}
	int ans = 0;
	rep(i, k) {
		sort(a.begin(), a.end());
		ans += a[n-1-i];
		a.pop_back();
	}
	cout << ans;
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main(){
    char s[200000]={},t[200000]={};
    int ans=0;
    cin>>s>>t;
    for(int i=0;i<200000;i++){
        if(s[i]==t[i]){

        }
        else{
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3980
import java.util.*;

public class Main {
 	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long x = sc.nextLong();
	    System.out.println(new Barger(n).getCount(x));
   }
   
   static class Barger {
       Barger under;
       int level;
       long size;
       long value;
       
       public Barger(int level) {
           this.level = level;
           if (level == 0) {
               size = 1;
               value = 1;
           } else {
               under = new Barger(level - 1);
               size = under.size * 2 + 3;
               value = under.value * 2 + 1;
           }
       }
       
       public long getCount(long idx) {
           if (level == 0) {
               return 1;
           }
           if (idx < 2) {
               return 0;
           }
           idx--;
           long ans = 0;
           if (idx <= under.size) {
               return under.getCount(idx);
           }
           idx -= under.size;
           ans += under.value;
           if (idx <= 1) {
               return ans + 1;
           }
           idx--;
           ans++;
           if (idx <= under.size) {
               return ans + under.getCount(idx);
           }
           return value;
       }
   }
}




Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int main()
{
	int n;
	while(cin>>n){
		int sum=0;
		int f=n;
		if(n>1000000000||n<1){
			break;
		}
		while(n){
			sum+=n%10;
			n/=10;
		}
		//cout<<sum<<endl;
		if(f%sum==0){
			cout<<"Yes"<<endl; 
		}
		else {
			cout<<"No"<<endl;
		}
	}
	return 0;
}

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

int a, b, c, x, y, z;

int main() {
  int i, ans;
  cin >> a >> b >> c;
  x = abs(a - b);
  y = abs(b - c);
  z = abs(a - c);
  i = max(x, max(y, z));
  if(i == x)
    ans = y + z;
  else if(i == y)
    ans = z + x;
  else
    ans = y + x;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int q;
  cin >> s >> q;
  int i,x=1;
  deque<char> que;
  for(i=0;i<s.size();i++){
    que.push_back(s[i]);
  }
  for(i=0;i<q;i++){
    int a,b;
    char c;
    cin >> a;
    if(a==1){
      x*=-1;
      continue;
    }
    cin >> b >> c;
    if((b==1 && x==1) || (b==2 && x==-1)){
      que.push_front(c);
    }
    else{
      que.push_back(c);
    }
  }
  if(x==1){
    while(!que.empty()){
      cout << que.front();
      que.pop_front();
    }
  }
  else{
    while(!que.empty()){
      cout << que.back();
      que.pop_back();
    }
  }
  cout << endl;
}

Measured memory_bytes: 3976