akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;


int main(){
    string s;
    cin>>s;
   int count=0;
   for(int i=0;i<s.length()-1;i++){
    if(s[i]!=s[i+1]){
        ++count;
    }
   }
   cout<<count<<endl;
  return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <algorithm>
int n, k;

int min(int a, int b) {
    return a > b ? b : a;
}
int max(int a, int b) {
    return a > b ? a : b;
}

using namespace std;
int main(void){
    // Your code here!
    cin >> n >> k;
    char S[n];
    cin >> S;
    
    int now = 1;
    int cnt = 0;
    vector <int> V;


    for(int i = 0; i < n; i++){
        if(S[i] == '0' + now){
            cnt += 1;
        } else{
            V.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    
    if(cnt != 0) V.push_back(cnt);
    if(S[n] == '0'){
        V.push_back(0);
    }
    
    int add = 2 * k + 1;
    int ans = 0;
    int left = 0;
    int right = 0;
    int tmp = 0;
    
    for(int i = 0; i < V.size(); i+=2){
        int nextLeft = i;
        int nextRight = min(i + add, V.size());
        while(left < nextLeft){
            tmp -= V[left];
            left += 1;
        }
        
        while(right < nextRight){
            tmp += V[right];
            right += 1;
        }
        
        ans = max(ans, tmp);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 1020
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        if (A >= 13) {
            System.out.println(B);
        } else if (A >= 6) {
            System.out.println(B / 2);
        } else {
            System.out.println(0);

        }
    }

}


Measured memory_bytes: 25044
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,t;
  cin>>n>>t;
  int c=0;
  for(int i=0;i<n;i++){
    int ci,ti;
    cin>>ci>>ti;
    if(ti<=t)
      c=(c==0?ci:min(c,ci));
  }
  if(c==0)
    cout<<"TLE"<<endl;
  else
    cout<<c<<endl;
}

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

#define int long long

signed main() {
	int n; cin >> n;
	map<int,int> m;
	vector<int> v;
	for(int i = 0; i < n; i++) {
		int t; cin >> t;
		v.push_back(t);
		m.insert({t,0});
	}
	for(int i = 1; i <= n; i++) {
		int t; cin >> t;
		m[i] = t;
	}
	map<int,int> d;
	for(int i = 1; i < n; i++) {
		int t; cin >> t;
		d.insert({i,t});
	}
	int ans = 0;
	for(int i = 0; i < n; i++) {
		ans += m[v[i]];
		if(i+1 < n && v[i+1] == v[i]+1) ans += d[v[i]];
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	int i,ans=0;
	string s,s1;
	cin>>s;
	s1="CODEFESTIVAL2016";
	for(i=0;i<16;i++){
		if(s[i]!=s1[i]){
			ans++;
		}
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (_n, m) = {
        let nums = get_line()
            .split_whitespace()
            .map(|n| n.parse().unwrap())
            .collect::<Vec<u64>>();
        (nums[0], nums[1])
    };
    let scores = get_line()
        .split_whitespace()
        .map(|n| n.parse().unwrap())
        .collect::<Vec<u64>>();

    let total = scores.iter().fold(0, |sum, x| sum + x);
    let threshold: f64 = (total as f64) / ((4 * m) as f64);

    let count = scores
        .iter()
        .map(|&x| x as f64)
        .filter(|&x| x >= threshold)
        .count();

    if count >= m as usize {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <cstdio>
#include <set>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)

const int N_MAX = 100000;
const int M_MAX = 100000;

int N, M;
int x[M_MAX];
int y[M_MAX];

int c[N_MAX + 1];
set<int> st;

void solve() {
  FOR(i, 1, N) c[i] = 1;
  st.insert(1);
  REP(i, M) {
    if (st.count(x[i]) > 0) {
      st.insert(y[i]);
    }
    if(--c[x[i]] == 0) {
      st.erase(x[i]);
    }
    c[y[i]]++;
  }
  printf("%d\n", st.size());
}

void input() {
  scanf("%d%d", &N, &M);
  REP(i, M) scanf("%d%d", x + i, y + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 6144
#include<stdio.h>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>

using namespace std;
typedef long long ll;
 
#define REP(i,n) for(int i=0;i<(int)(n);i++)
 
int main()
{
    int ans,w,h;
    int c[55][55];
    queue<pair<int,int> > que;
    int dx[8]={1,1,1,0,-1,-1,-1,0};
    int dy[8]={-1,0,1,1,1,0,-1,-1};
    while(1==1)
    {
        ans=0;
        REP(i,55)REP(j,55)c[i][j]=10000;
        scanf("%d %d\n",&w,&h);
        if(w==0&&h==0)return 0;
        REP(i,h)REP(j,w)scanf("%d",&c[i+1][j+1]);
        for(int i=1;i<=h;i++)
        {
            for(int j=1;j<=w;j++)
            {
                if(c[i][j]==1)
                {
                    ans++;
                    c[i][j]=0;
                    while(!que.empty())que.pop();
                    que.push(pair<int,int>(i,j));
                    pair<int,int> p;
                    while(!que.empty())
                    {
                        p=que.front();
                        que.pop();
                        REP(k,8)
                        {
                            if(c[p.first+dy[k]][p.second+dx[k]]==1)
                            {
                                que.push(pair<int,int>(p.first+dy[k],p.second+dx[k]));
                                c[p.first+dy[k]][p.second+dx[k]]=0;
                            }
                        }
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 3292
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int count=0;
        for(int i=1;i<N;i++){
            count += N/i;
            if(N%i==0)count--;
        }
        System.out.println(count);
    }
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t,u;
    data_type a,b;
    cin>>s;
   for(auto i:s)
   {
      cout<<'x';
   }

cout<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <math.h>
using namespace std;
int main(){
	string a,s("0123456789");
	int t;
	cin>>a>>t;
	int len=a.size();
	int a1[(len+1)/2];
	string a2[(len-1)/2];
	for(int i=0;i<(len+1)/2;i++){
		for(int j=0;j<10;j++){
			if(s[j]==a[2*i]){
				a1[i]=j;
				break;
			}
		}
	}
	for(int i=0;i<(len-1)/2;i++){
		a2[i]=a[2*i+1];
	}
	//L
	int lt=a1[0];
	for(int i=1;i<(len+1)/2;i++){
		if(a2[i-1]=="+"){
			lt=lt+a1[i];
		}
		else{
			lt=lt*a1[i];
		}
	}
	//M
	int mt=0;
	for(int i=0;i<(len-1)/2;i++){
		if(a2[i]=="*"){
			a1[i+1]=a1[i+1]*a1[i];
			a1[i]=0;
		}
	}
	for(int i=0;i<(len+1)/2;i++){
		mt=mt+a1[i];
	}
	if(t==mt){
		if(t==lt){
			cout<<"U"<<endl;
		}
		else{
			cout<<"M"<<endl;
		}
	}
	else{
		if(t==lt){
			cout<<"L"<<endl;
		}
		else{
			cout<<"I"<<endl;
		}
	}
    return 0;
}

Measured memory_bytes: 1204
#include <stdio.h>
int main(){
    int a,b,c,d=0;
    scanf("%d %d %d",&a,&b,&c);
    for(int i=a;i<b+1;i++){
        if(c%i==0){
            d+=1;
        }
    }
    printf("%d\n",d);
}


Measured memory_bytes: 2704
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class ASheepAndWolves {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int S, W;
        cin >> S >> W;
        if (W >= S) {
            cout << "unsafe" << endl;
        } else {
            cout << "safe" << endl;
        }

    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    ASheepAndWolves solver;
    solver.solve(in, out);
    return 0;
}


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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define endl "\n"
#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
//グリッドグラフの範囲チェック
bool range_validation(int y,int x,int h,int w){
    return y>=0 && y<h && x>=0 && x < w;
}
//ビットカウント
int popcount(long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int gcd(ll a, ll b){
  if(b == 0){
    return a;
  }else{
    return gcd(b,a%b);
  }
}

vector<ll> sieve(ll n){
  vector<bool> is_prime(n+1,true);
  vector<ll> res;
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      res.push_back(i);
      for(int j=2*i;j<=n;j+=i){
        is_prime[j] = false;
      }
    }
  }
  return res;
}

vector<ll> divisor(ll n){
  vector<ll> list;
  for(int i=1;i*i<=n;i++){
    if(n%i==0){
      list.push_back(i);
      if(n/i != i){
        list.push_back(n/i);
      }
    }
  }
  return list;
}

umap<int,int> prime_factor(ll n){
  umap<int,int> fac;
  for(int i=2;i*i<=n;i+=2){
    if(n%i == 0){
      int count = 0;
      while(n%i == 0){
        count++;
        n /= i;
      }
      fac[i] = count;
    }
  }
  if(n!=1)fac[n] = 1;
  return fac;
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n;
  cin >> n;
  int a[n+1];
  REP(i,n){
    cin >> a[i];
  }
  a[n] = 0;
  ll sum[n+1] = {0LL};
  
  for(int i=n-1;i>=0;i--){
    sum[i] = sum[i+1] + abs(a[i]-a[i+1]);
  }
  ll dist = 0LL;
  int now = 0;
  REP(i,n){
    cout << dist + sum[i+1] + abs(now-a[i+1])<< endl;
    dist += abs(now-a[i]);
    now = a[i];
  }
  
  
  return 0;
}


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

using namespace std;

int main(void) {
	vector<int> A;
	vector<int> B;
	int N, T, count = 0;
	cin >> N >> T;
	for(int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		A.push_back(tmp);
	}

	int min = 0;
	for(int i = 0; i < N; i++) {
		if(i == 0) {
			min = A[i];
		} else {
			B.push_back(A[i] - min);
			if(A[i] < min)min = A[i];
		}
	}

	sort(begin(B), end(B), greater<int>());

	int tmp = 0;
	for(int i = 0; i < N; i++) {
		if(i == 0) {
			tmp = B[0];
		}
		if(tmp == B[i]) {
			count ++;
		}
	}

	cout << count << endl;
}


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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<long> A(N);
    copy_n(istream_iterator<long>(cin), N, A.begin());
    vector<long> ans(N);
    for(unsigned long i = 1; i < N; ++i){
        ans[i] += A[i - 1];
        A[i] -= A[i - 1];
        A[i - 1] = 0;
    }
    for(unsigned long i = 0; i < N; ++i)(ans[i] += (i & 1 ? -1 : 1) * A.back() / 2) *= 2;
    copy(ans.begin(), ans.end(), ostream_iterator<long>(cout, " "));
    return 0;
}

Measured memory_bytes: 2944
import java.util.*;
public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] arr = new int[n + 1];
        arr[0] = 1;
        for(int i = 1; i <= n; i++){
            arr[i] = sc.nextInt();
            if(i > k) {
                if (arr[i] > arr[i - k])
                    System.out.println("Yes");
                else
                    System.out.println("No");
            }
        }
    }
}

Measured memory_bytes: 60272
def main():
    h, w = map(int, input().strip().split())
    S = set(i for i in range(w))
    A = []

    for i in range(h):
        a = input()
        s = set()
        for i in range(w):
            if a[i] == ".":
                s.add(i)
        S = S & s
        if len(s) != w:
            A.append(a)
    
    for word in A:
        print_w = ""
        for i in range(w):
            if not(i in S):
              print_w += word[i]
        print(print_w)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
k,t=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
a.sort(reverse=True)
if len(a) ==1 :
    print(k-1)
else:
    m = 0
    for i in a:
        if(m<i):
            m = i - m
        else:
            m = m - i
    print(max(m-1,0))





Measured memory_bytes: 3064
#include <iostream>
using namespace std;
string a;
int dp[200005];
int bag[200005];
int nxt[200005][280];
bool cmp(string a,string b)
{
    if(a.empty())return 0;
    if(a.size()!=b.size())return a.size()<b.size();
    return a<=b;
}
int main()
{
    cin>>a;a=" "+a;
    for(int i='a';i<='z';i++)nxt[a.size()-1][i]=a.size();
    for(int i=a.size()-2;i>=0;i--){for(int c='a';c<='z';c++)nxt[i][c]=nxt[i+1][c];nxt[i][a[i+1]]=i+1;}
    for(int i=a.size()-1;i>=0;i--)
    {
        bag[i]=0;
        dp[i]=1<<30;
        for(int j='a';j<='z';j++)
            if(dp[i]>1+dp[nxt[i][j]])
                dp[i]=1+dp[nxt[i][j]],bag[i]=j;

    }
    int ind=0;
    while(ind!=a.size())
    {
        cout<<(char)bag[ind];
        ind=nxt[ind][bag[ind]];
    }
    return 0;
}


Measured memory_bytes: 220864
#include<stdio.h>

int main()
{
    int A,B,C;
    scanf("%d %d %d", &A,&B,&C);
    if(A==B && A!=C && B!=C){
        printf("Yes\n");
    }
    else if(A==C && A!=B && C!=B){
        printf("Yes\n");
    }
    else if(B == C && B != A && C != A){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
n, p = map(int, input().split())
enum_p = {}
for i in range(2, int(p**0.5) + 1):
    if p % i == 0:
        enum_p[i] = 1
        p //= i
        while p % i == 0:
            p //= i
            enum_p[i] += 1
if p != 0:
    enum_p[p] = 1
ans = 1
for k, v in enum_p.items():
    if v >= n:
        ans *= k**(v // n)
print(ans)

Measured memory_bytes: 9412
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]
dp = [[0, 0, 0] for _ in range(n+1)]
for i in range(n):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i+1][k] = max(dp[i+1][k], dp[i][j]+a[i][k])
print(max(dp[n]))

Measured memory_bytes: 76248
#include<stdio.h>

int main(){
  int n;
  long tt,t,pt,cnt=0;
  scanf("%d %ld",&n,&tt);
  scanf("%ld",&pt);
  cnt+=tt;
  for(int i=1;i<n;i++){
    scanf("%ld",&t);
    cnt+=tt;
    if(t-pt<tt)
      cnt-=tt-(t-pt);
    pt=t;
  }
  printf("%ld\n",cnt);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
long long MOD = 1e9 + 7;
int main() {
	long long n;
	cin >> n;
	long long k;

	cin >> k;
	n++;
	long long ans = 0;
	for (int i = k;i <= n ;i++) {
		ans = ans + (i * (n - i) + 1) % MOD;

	}
	cout << ans%MOD;
}

Measured memory_bytes: 3540
#include <stdio.h>
#include <math.h>

//???????????°x??????p<=???x?????????????´???????p??????????????¨????????§???????????¨???????´???°???????????????
int isPrime(int x){
    int i;
    double rx = sqrt(x); //???x
    if(x<2) return 0; //2???????°?????????????????´???°??§?????????
    else if(x==2) return 1; //2????´???°
    else if(x%2==0) return 0; //??¶??°????´???°??§?????????
    for(i=3;i<=rx;i+=2) //?\???°????????????????????????????????¨???????´???°??????
        if(x%i==0) return 0;
    return 1;
}

int main(void){
    int i,n,c;
    for(;;){
        scanf("%d", &n);
        if(n==0) break;
        c=0; //?????????
        for(i=n+1;i<=2*n;i++)
            if(isPrime(i)) c++;
        printf("%d\n", c);
    }
    return 0;
}

Measured memory_bytes: 600
open Batteries
open Printf

let ($) g f x = g (f x)

module MyList = struct
  include List
  let foldl = fold_left
  let foldli = fold_lefti
  let foldr = fold_right
  let foldri = fold_righti
  
  let flatmap = concat_map

  let zipf = map2
  let zipfi = map2i
end

module L = MyList

let swap = Tuple2.swap

let atoi = int_of_string
let itoa = string_of_int
let atof = float_of_string
let ftoa = string_of_float
let ctoi = int_of_char
let itoc = char_of_int

let ctos = String.of_char
let stocl = String.to_list
let cltos = String.of_list

module MyString = struct
  include String

  let map_to_list f s = L.map f (stocl s)
  let mapi_to_list f s = L.map f (stocl s)

  let zipf f a b = L.zipf f (stocl a) (stocl b)
  let zipfi f a b = L.zipfi f (stocl a) (stocl b)

  let mkstr f sep ls =
    L.foldl (fun acc x -> acc ^ sep ^ (f x)) (f @@ L.hd ls) (List.tl ls)
end

module S = MyString

let spoc = S.split_on_char
let spsp s = spoc ' ' s

module MySet = struct
  include Set

  let fold' f s z = fold f z s
end

module St = MySet

module MyMap = struct
  include Map

  let apply = find
  let apply_or = find_default
end

module Mp = MyMap


let rds () = read_line ()

let rdi () = atoi @@ rds ()

let rdhs () = spsp @@ rds ()
let rdhi () = rdhs () |> L.map atoi

let rdi2 () = match rdhi () with
  | a::b::_ -> (a, b)
  | _ -> (0, 0)

let rdi3 () = match rdhi () with
| a::b::c::_ -> (a, b, c)
| _ -> (0, 0, 0)

let rdi4 () = match rdhi () with
| a::b::c::d::_ -> (a, b, c, d)
| _ -> (0, 0, 0, 0)

let rdi5 () = match rdhi () with
| a::b::c::d::e::_ -> (a, b, c, d, e)
| _ -> (0, 0, 0, 0, 0)

let rdv n rdf =
  let rec rdv' n =
    if n <= 0 then []
    else (
      let s = rdf () in
      s::(rdv' (n - 1))
    )
  in rdv' n

let rdvi n = rdv n rdi
let rdvi2 n = rdv n rdi2
let rdvi3 n = rdv n rdi3
let rdvi4 n = rdv n rdi4

let puts s = print_endline s
let putyn b = puts (if b then "Yes" else "No")
let puti i = puts @@ itoa i

let set_power ls =
  let rec set_power' ls pls =
    match ls with
    | [] -> pls
    | hd::tl -> set_power' tl (L.flatmap (fun p -> [p; hd::p]) pls)
  in set_power' ls [[]]


let rdhf () = rdhs () |> L.map atof
let rdf4 () = match rdhf () with
| a::b::c::d::_ -> (a, b, c, d)
| _ -> (0., 0., 0., 0.)


module Graph = struct

  type 'a t = { nb : (int, int St.t) Mp.t; vdt : (int, 'a) Mp.t }

  let nothing = { nb = Mp.empty; vdt = Mp.empty }

  let add_edge (e : int * int) g =
    let (v1, v2) = e in
    let nbvs = g.nb |> Mp.apply_or St.empty v1 in
    let nb1 = g.nb |> Mp.add v1 (nbvs |> St.add v2) in
    { g with nb = nb1 }

  let add_uedge e g =
    add_edge e (add_edge (swap e) g)

  let from_edges es =
    es |> L.foldl (fun g e -> add_edge e g) nothing

  let from_uedges es =
    es |> L.foldl (fun g e -> add_uedge e g) nothing


end

module G = Graph


let _ =
  let n = rdi () in
  let xs = rdhi () in
  let rec mul r = function
  | [] -> if r > 1000000000000000000 then -1 else r
  | h::t -> if log10 (float h) +. log10 (float r) > 18. then -1
      else mul (h * r) t in
  puti (if L.mem 0 xs then 0 else (mul 1 xs))
;;


Measured memory_bytes: 17336
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, B;// N hr プラン１時間当たりA円　プラン2定額B円
  cin >> N >> A >> B;
  if (N * A <= B) {
    cout << N * A << endl;
  }
  else cout << B << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;

int K,S;
int main (){
    cin >> K >> S;
    int cnt = 0;
    for(int x=0; x<K+1; x++){
        for(int y=0; y<K+1; y++){
            int z = S - ( x + y ) ;
            if( x + y + z == S && ( z >= 0 && z < K + 1 )) cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
from heapq import *

def main():
	x, y, z, k, *L = map(int, open(0).read().split())
	s = sorted
	ans = []
	a = s(L[:x])[::-1]
	b = s(L[x:x + y])[::-1]
	c = s(L[x + y:])[::-1]
	h = [(-(a[0] + b[0] + c[0]), 0, 0, 0)]
	done = {(0, 0, 0)}
	for _ in range(k):
		v, i, j, k = heappop(h)
		ans += [-v]
		for ni, nj, nk in ((i + 1, j, k), (i, j + 1, k), (i, j, k + 1)):
			if ni == x or nj == y or nk == z:
				continue
			if (ni, nj, nk) not in done:
				heappush(h,(-(a[ni] + b[nj] + c[nk]), ni, nj, nk))
				done.add((ni, nj, nk))
	print(*ans)

if __name__=="__main__":
	main()

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

using namespace std;
typedef long long ll;

const int N = int(1e6) + 7;
int A[N];
int LOG[N];
int st[N][25];
int n;

void init(){
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d", &A[i]);
    for(int i = 0; i < n; i++){
        st[i][0] = A[i];
    }
    LOG[1] = 0;
    for(int i = 2; i < N; i++){
        LOG[i] = LOG[i/2] + 1;
    }
    for(int j = 1; j < 25; j++){
        for(int i = 0; i + (1 << j) <= n; i++){
            st[i][j] = max(st[i][j-1], st[i+(1 << (j-1))][j-1]);
        }
    }
}

int query(int l, int r){
    int j = LOG[r-l+1];
    return max(st[l][j], st[r - (1<<j) + 1][j]);
}

void solve(){
    init();
    printf("%d\n", query(1, n-1));
    for(int i = 1; i < n-1; i++){
        printf("%d\n", max(query(0, i-1), query(i+1, n-1)));
    }
    printf("%d\n", query(0, n-2));
}

const bool mtc = false;

int main(){
    int t;
    if(mtc){
        scanf("%d", &t);
        while(t--) solve();
    }
    else solve();
}


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


using namespace std;


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

    long long ans = 0;

    for (int s = 0; s < (1 << S.size() - 1); s++) {
        string now = " ";
        now += S[0];

        for (int i = 0; i < S.size() - 1; i++) {
            if (s & (1 << i)) {
                now += "+";
            }
            now += S[i + 1];
        }

        long long sum = 0;
        int pos = 0;
        while (now.find("+", pos) != string::npos) {
            int nextpos = now.find("+", pos);
            sum += stoll(now.substr(pos, nextpos - pos + 1));
            pos = nextpos + 1;
        }

        sum += stoll(now.substr(pos));
        ans += sum;
    }
    cout << ans;
    
    return 0;
} 


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n, m, l;
    int i, j, k;
    int a[100][100], b[100][100];
    long long int c[100][100]={};
    
    scanf("%d %d %d", &n, &m, &l);
    
    for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            scanf("%d", &a[i][j]);
        }
    }
    for(i=0; i<m; i++){
        for(j=0; j<l; j++){
            scanf("%d", &b[i][j]);
        }
    }
    
    for(i=0; i<n; i++){
        for(j=0; j<l; j++){
            for(k=0; k<m; k++){
                c[i][j]+=a[i][k]*b[k][j];
            }
        }
    }
    
    for(i=0; i<n; i++){
        for(j=0; j<l; j++){
            if(j==l-1){
                printf("%lld\n", c[i][j]);
            }
            else{
                printf("%lld ", c[i][j]);
            }
        
        }
    }
    
    return 0;
}

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

int main() {
   int a,b,c;
  string s;
  cin>>a;
  c=0;
  bool t=1;
  vector<int> vecA(a);
  vector<int> vecB(a);
  vector<int> vecC(a-1);
  for(int i=0;i<a;i++){
  	cin>>vecA.at(i);
  }
  for(int i=0;i<a;i++){
  	cin>>vecB.at(i);
  }
  for(int i=0;i<a-1;i++){
  	cin>>vecC.at(i);
  }
  
  for(int i=0;i<a;i++){
  	c += vecB.at(i);
  }  
  
  for(int i=0;i<a-1;i++){
  	if(vecA.at(i)==vecA.at(i+1)-1){
    	c += vecC.at(vecA.at(i)-1);
    }
  }
  
  cout<<c<<endl;
  
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int inf = 10e17;
#define mod 1000000007
int findLowerBound(
    vector<pair<int, int>> &arr,
    pair<int, int> &p)
{

    auto low = lower_bound(arr.begin(),
                           arr.end(), p);

    return low - arr.begin();
}
int findUpperBound(
    vector<pair<int, int>> &arr,
    pair<int, int> &p)
{
    auto up = upper_bound(arr.begin(),
                          arr.end(), p);

    return up - arr.begin();
}
bool vis[200005];
vector<int> vec[2000005];
int child[2000005];
int parent[2000005];
int div1[100005];
void dfs(int node)
{
    vis[node] = 1;
    for (int i = 0; i < vec[node].size(); i++)
    {
        if (!vis[vec[node][i]])
        {
            parent[vec[node][i]] = node;
            dfs(vec[node][i]);
            //   child[node] += child[vec[node][i]];
        }
    }
}
void bfs(int node)
{
    queue<int> qu;
    qu.push(node);
    vis[1] = 1;
    while (!qu.empty())
    {
        int top = qu.front();
        //cout << qu.front() << "\n";
        qu.pop();
        vis[top] = 1;
        for (int i = 0; i < vec[top].size(); i++)
        {
            if (!vis[vec[top][i]])
            {
                parent[vec[top][i]] = top;
                qu.push(vec[top][i]);
                vis[vec[top][i]] = 1;
            }
        }
    }
}
void belman(int n, int m, vector<pair<int, pair<int, int>>> vec, int dis[])
{
    for (int i = 0; i <= n + m - 1; i++)
    {
        for (int j = 0; j < vec.size(); j++)
        {
            int u = vec[j].second.first;
            int v = vec[j].second.second;
            int w = vec[j].first;

            if (dis[u] + w < dis[v])
            {
                dis[v] = dis[u] + w;
            }
        }
    }
}
int fun(int a, int b)
{
    if (a > b)
        return 0;
    if (a == b)
        return 1;
    else
    {
        return fun(a + 1, b) + fun(a, b - a);
    }
}
int32_t main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);

    int n;
    cin >> n;
    vector<int> vec;
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        if (temp > n)
        {
            ans++;
        }
        else
        {
            vec.push_back(temp);
        }
    }
    map<int, int> mp;
    for (auto itr : vec)
        mp[itr]++;
    for (auto itr : mp)
    {
        if (itr.first > itr.second)
        {
            ans += (itr.second);
        }
        else
        {
            ans += (itr.second - itr.first);
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 51128
#include <iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<math.h>
using namespace std;
int main(){
    int n,m;
    long x;
    long a[20][20];
    cin>>n>>m>>x;
    for(int i=0;i<n;i++){
        for(int j=0;j<m+1;j++){
            cin>>a[i][j];
        }
    }
    long b[20];
    /*for(int i=0;i<n;i++)
        cout<<a[i][0]<<" ";
    cout<<endl;*/
    long money=99999999;
    for(int i=0;i<(1<<n);i++){
            long now=0;
            for(int i=0;i<=m;i++)
                b[i]=0;
        for(int j=0;j<n;j++){
            if(i&(1<<j)){
                //cout<<j<<" ";
                now+=a[j][0];
                for(int k=1;k<=m;k++)
                    b[k]+=a[j][k];
            }

        }
        int flag=0;
        for(int i=1;i<m+1;i++)
            if(b[i]>=x)
                flag++;
        if(flag==m&&now!=0)
            money=money>now?now:money;
    }
    if(money==99999999)
        money=-1;
    cout<<money;

    return 0;
}


Measured memory_bytes: 3644
import numpy as np
from bisect import bisect

N,M,K = map(int,input().split())
A = np.array(input().split(),dtype=int)
B = np.array(input().split(),dtype=int)

AA = np.insert(A,0,0)
BB = np.insert(B,0,0)
AAA = np.cumsum(AA)
BBB = np.cumsum(BB)
max_books = 0
for a in enumerate(AAA):
    if a[1] > K:
        break
    books = a[0]
    ind = bisect(BBB,K - a[1])
    books += (ind-1)
    max_books = max(books,max_books)
print(max_books)        
    
    


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

int n,m,q,s,t;
int tree[100002];
int sn[100002];
list<int>l[100002];

int slv(int x,int id);

int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>s>>t;
    l[s].push_back(t);
    l[t].push_back(s);
  }

  for(int i=0;i<n;i++){
    tree[i]=-1;
    sn[i]=0;
  }
  int id=1;
  for(int i=0;i<n;i++){
    if(tree[i]==-1){
      slv(i,id);
      id++;
    }
  }

  cin>>q;
  for(int i=0;i<q;i++){
    cin>>s>>t;
    if(tree[s]==tree[t])cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }

  return(0);
}

int slv(int x,int id){
  tree[x]=id;
  sn[x]=1;
  for(int i=0;i<l[x].size();i++){
    int y=l[x].front();
    l[x].pop_front();
    l[x].push_back(y);
    if(sn[y]==0){
      slv(y,id);
    }
  }
  return(0);
}

Measured memory_bytes: 14460
#include"bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()

using namespace std;
typedef unsigned long long ll;

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

template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}


int main(void) {
	int n, k, b;
	cin >> n >> k;
	vector<bool> s(n,true);
	rep(i, k) {
		cin >> b;
		int q;
		rep(i, b) {
			cin >> q;
			s[q-1] = false;
		}
	}
	int ans = 0;
	rep(i, n) {
		if (s[i]) {
			++ans;
		}
	}
	cout << ans;
}

/*

*/


Measured memory_bytes: 3600
import java.util.*;


public class Main{

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		Long x=sc.nextLong();
		Long k=sc.nextLong();
		Long d=sc.nextLong();
		
		if(x<0)x*=-1;
		
		Long div=x/d;
		if(div>k) {
			System.out.println(x-d*k);
			return;
		}
		
		k-=div;
		x=x%d;
		
		long ans1=x;
		long ans2=Math.abs(x-d);
		
		if(k%2==0)System.out.println(ans1);
		else System.out.println(ans2);
		
		
	}

	
}


Measured memory_bytes: 35664
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	//	"strings"
	"sort"
)

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	mp := map[int]int{}
	for i := 0; i < n; i++ {
		tmp := sc.NextInt()
		mp[tmp]++
	}
	arr := []int{}
	sq := []int{}
	for k, v := range mp {
		if v >= 2 {
			arr = append(arr, k)
		}
		if v >= 4 {
			sq = append(sq, k)
		}
	}
	if len(arr) < 2 && len(sq) < 1 {
		fmt.Printf("%+v\n", 0) // output for debug
		return
	}
	ans := 0
	ans2 := 0
	if len(arr) >= 2 {
		sort.Ints(arr)
		ans = arr[len(arr)-1] * arr[len(arr)-2]
	}
	if len(sq) >= 1 {
		sort.Ints(sq)
		ans2 = sq[len(sq)-1] * sq[len(sq)-1]
	}
	if ans2 > ans {
		ans = ans2
	}
	fmt.Printf("%v\n", ans)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<vector<int>> A(2, vector<int>(N));
  REP(i, N) cin >> A[0][i];
  REP(i, N) cin >> A[1][i];
  int ans = -1;
  for(int i = 0; i < N; i++) {
    int sum = 0;
    for(int j = 0; j <= i; j++) {
      sum += A[0][j];
    }
    for(int k = i; k < N; k++) {
      sum += A[1][k];
    }
    ans = max(sum, ans);
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
    int n;
    bool flag = false;
    cin >> n;
    for (int i = 1; i <= 9; ++i) {
        for (int j = 1; j <= 9; ++j) {
            if (i * j == n)
                flag = true;
        }
        if (flag)
            break;
    }
    cout << ((flag) ? "Yes" : "No") << endl;
}

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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)

template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class F, class S> istream& operator >> (istream& s, pair<F, S>& p)
{ s >> p.first >> p.second; return s;}

int main()
{
    int A, B, C; cin >> A >> B >> C;
    int K; cin >> K;

    while (K > 0 && B <= A) {
        B *= 2;
        K--;
    }

    while (K > 0 && C <= B) {
        C *= 2;
        K--;
    }

    cout << ((A < B && B < C) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3592
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
#define ll long long
const ll INF=1e15+10;
#define MAX 100005
typedef pair<ll,ll> p;
struct Edge{
    ll to;
    ll cost;
    Edge(ll to,ll cost):to(to),cost(cost){}
};
vector<Edge> edge[MAX*100];
ll dis[MAX];
ll u,v,w;
ll n,q,x;
void Dijkstra(int s)
{
    priority_queue<p,vector<p>,greater<p> > que;
    fill(dis+1,dis+n+1,INF);
    dis[s]=0;
    que.push(p(0,s));
    while(!que.empty())
    {
        p P=que.top();
        que.pop();
        v=P.second;
        if(dis[v]<P.first)
            continue;
        for(ll i=0;i<edge[v].size();i++)
        {
            Edge e=edge[v][i];
        if(dis[e.to]>dis[v]+e.cost)
        {
            dis[e.to]=dis[v]+e.cost;
            que.push(p(dis[e.to],e.to));
        }
        }
    }
}
int main()
{
    scanf("%lld",&n);
    for(ll i=1;i<=n-1;i++)
    {
        scanf("%lld%lld%lld",&u,&v,&w);
        edge[u].push_back(Edge(v,w));
        edge[v].push_back(Edge(u,w));
    }
    scanf("%lld%lld",&q,&x);
    Dijkstra(x);
    for(int i=0;i<q;i++)
    {
        scanf("%lld%lld",&u,&v);
        printf("%lld\n",dis[u]+dis[v]);
    }
    return 0;
}


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

const int M = 1e9+7;
const int N = 1005;

int dp[N][N];

int main(){
	int h , w;	
	cin >> h >> w;

	vector<string> s(h);
	memset(dp , 0 , sizeof(dp));

	for(int i = 0 ; i < h ; i++){
		cin >> s[i];
	}

	dp[0][0] = 1;

	for(int i = 0 ; i < h ; i++){
		for(int j = 0 ; j < w ; j++){
			if (s[i][j] == '#'){
				dp[i][j] = 0;
				continue;
			}
			if (i >= 1){
				dp[i][j] += dp[i-1][j];
				dp[i][j] %= M;
			}
			if (j >= 1){
				dp[i][j] += dp[i][j-1];
				dp[i][j] %= M;
			}
		}
	}

	cout << dp[h-1][w-1] << endl;

	return 0;
}


Measured memory_bytes: 9420
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
import java.util.AbstractMap.SimpleEntry;

public class Main {

    // static final int modnum = 1e9 + 7;
    static int N;
    static int M;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();

        ArrayList<ArrayList<Integer>> light = new ArrayList<ArrayList<Integer>>();

        for(int m=0;m<M;m++){
            int k = sc.nextInt();
            ArrayList<Integer> switches = new ArrayList<Integer>();
            light.add(switches);
            for(int s=0;s<k;s++){
                int swi = sc.nextInt();
                switches.add(swi);
            }
        }

        int[] P = new int[M];
        for(int i = 0;i<M;i++){
            P[i]=sc.nextInt();
        }

        System.out.println(checker(new int[N], P, light));
    }

    private static int checker(int[] list,int[] P,ArrayList<ArrayList<Integer>> light){

        int[] nex = list.clone();
        for(int i=0;i<nex.length;i++){
            if(nex[i]==0){
                int ret = 0;
                nex[i]=1;
                ret += checker(nex,P,light);
                nex[i]=-1;
                ret += checker(nex,P,light);
                return ret;
            }
        }
        int ret = 0;
        for(int i=0;i<M;i++){
            ArrayList<Integer> needs = light.get(i);
            int sum = 0;
            for(int l:needs){
                if(list[l-1]==1)
                    sum++;
            }
            if(sum%2 == P[i]){
                ret++;
            }
        }
        if(ret == M)
            ret = 1;
        else 
            ret = 0;
        // System.out.println(Arrays.toString(list)+"  "+ret);
        return ret;
    }
}

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

int main() {
  int H,W;
  cin >> H >> W;
  for (int i =0;i<H+2;i++){
    if (i==0||i==H+1){
      for (int j=0;j<W+2;j++){
        cout << "#";
      }
    }
    else{
      string a;
      cin >> a;
      cout << "#" << a << "#";
    }
    cout << endl;
  }
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e3 + 5;

ll dp[MAXN];
ll c[MAXN][MAXN];
ll dp_v[MAXN][MAXN];
ll st2[MAXN];

set<ll> st;

ll brute_force(int n, int k){
	deque<int> dq;
	st.clear();
	REP(i, 0, 1 << (n - 1)){
		dq.clear();
		dq.pb(1);
		REP(j, 0, n - 1){
			if (i & (1 << j)){
				dq.pb(j + 2);
			} else {
				dq.push_front(j + 2);
			}
		}
		
		REP(i1, 0, 1 << (n - 1)){
			ll vv = 0;
			deque<int> dq1 = dq;
			int flag = 0;
			REP(j, 0, n){
				int a;
				if (i1 & (1 << j)){
					a = dq1.front();
					dq1.pop_front();
				} else {
					a = dq1.back();
					dq1.pop_back();
				}
				if (a == 1 && j + k == n){
					flag = 1;
				}
				vv = vv * (n + 1) + a;
			}
			if (flag){
				st.insert(vv);
			}
		}
	}
	
	return SZ(st);
}

void solve(int n, int k){
	st2[0] = 1;
	REPN(i, 1, n){
		st2[i] = (st2[i - 1] * 2) % MOD;
	}
	
	c[0][0] = 1;
	REPN(i, 1, n){
		c[i][0] = 1;
		REPN(j, 1, i){
			c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;
		}
	}
	
	dp[0] = 1;
	REPN(i, 1, n){
		dp[i] = 0;
		REP(j, 0, i){
			//dp[i] = (dp[i] + c[i - 1][j] * dp[j]) % MOD;
			dp[i] = (dp[i] + dp[j] * dp[i - 1 - j]) % MOD;
		}
	}
	
	dp_v[0][0] = 1;
	REPN(sum, 1, n){
		ll dp_sum = 0ll;
		REPN(i, 0, sum){
			int j = sum - i;
			if (j){
				dp_sum = (dp_sum + dp_v[i][j - 1]) % MOD;
			}
			dp_v[i][j] = dp_sum;
		}
	}
	
	/*REPN(i, 1, n){
		printf("%d %lld\n", i, dp[i]);
	}*/
	
	if (k == 1){
		printf("%lld\n", dp[n - 1]);
		//printf("%lld\n", brute_force(n, k));
		return;
	}
	
	ll ans = (st2[k - 2] * dp[n - k]) % MOD;
	
	//printf("#1: %lld\n", ans);
	
	REPN(i, k + 1, n){
		ll mul = (c[i - 2][k - 2] * st2[k - 2]) % MOD;
		ll sum = dp_v[n - i][i - k];
		/*ll sum = 0ll;
		REPN(j, i, n){
			ll cur = (dp[n - j] * c[j - k - 1][i - k - 1]) % MOD;
			printf("## %lld\n", cur);
			sum = (sum + cur) % MOD;
		}*/
		ans = (ans + mul * sum) % MOD;
		
		//printf("# %d %lld %lld\n", i, mul, sum);
	}
	
	printf("%lld\n", ans);
	
	//printf("%lld\n", brute_force(n, k));
}

void solve(){
	int n, k;
	scanf("%d%d", &n, &k);
	k = n - k + 1;
	solve(n, k);
	/*for(int n = 1; n <= 7; n++){
		for(int k = 1; k <= n; k++){
			printf("%d %d\n", n, k);
			solve(n, k);
		}
	}*/
}

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

int main(){
  int n;
  cin >> n;
  if(n>=105) {
    if(n>=135){
      if(n>=165){
        if(n>=189){
          if(n>=195){
            cout << "5" << endl;
          }
          else{
            cout << "4" << endl;
          }
        }
        else{
          cout << "3" << endl;
        }
      }
      else{
        cout << "2" << endl;
      }
    }
    else{
      cout << "1" << endl;
    }
  }
  else{
    cout << "0" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
	int A, B, C, D;
  	cin >> A >> B >> C >> D;
  	int DivA, DivC;
  	if ( A % D == 0 ) DivA = A / D;
  	else DivA = A / D + 1;
   	if ( C % B == 0 ) DivC = C / B;
  	else DivC = C / B + 1;
	//cout << DivA << " " << DivC << endl;
  	if ( DivC <= DivA ) cout << "Yes" << endl;
  	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main(){
  int n; cin>>n;
  map<string,int>mp;
  rep(i,n){
    string s; cin>>s;
    mp[s]++;
  }
  int mx = 0;
  for (auto p:mp) mx = max(p.second, mx);
  for (auto p:mp) if (p.second==mx) cout << p.first<< endl;
}


Measured memory_bytes: 19236
#include <bits/stdc++.h>
#include <algorithm>
#include<string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    if ((a[1]-a[0]) == (a[2]-a[1])) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int n;cin >> n;
    vector<ll> A(n), abs_A(n);
    ll min_abs_A = 1e10;
    int minus_cnt = 0;
    for (int i = 0; i < n; i++){
        cin >> A[i];
        abs_A[i] = abs(A[i]);
        min_abs_A = min(min_abs_A, abs_A[i]);
        if (A[i] < 0) minus_cnt++;
    }
    ll ans = accumulate(abs_A.begin(), abs_A.end(), 0LL);
    if (minus_cnt % 2) {
        ans -= min_abs_A * 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4792
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

d = [v[i] - c[i] for i in range(n)]
res = 0
for i in range(n):
  if d[i] > 0:
    res += d[i]
    
print(res)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
#define MAX 2000000

int H, A[MAX+1];

void maxHeapify(int i) {
  int l, r, largest;
  l = 2 * i;
  r = 2 * i + 1;

  // 左の子、自分、右の子で値が最大のノードを選ぶ
  if ( l <= H && A[l] > A[i] ) largest = l;
  else largest = i;
  if ( r <= H && A[r] > A[largest] ) largest = r;

  if ( largest != i ) {
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }
}

int main() {
  cin >> H;

  for ( int i = 1; i <= H; i++ ) cin >> A[i];

  for ( int i = H / 2; i >= 1; i-- ) maxHeapify(i);

  for ( int i = 1; i <= H; i++ )
    cout << " " << A[i];
  cout << endl;

  return 0;
}


Measured memory_bytes: 5032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k;
ll a[200010];
int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]++;
    }
    ll sum = 0;
    ll ans = 0;
    for (int i = 0; i < k; i++) {
        sum += a[i];
    }
    ans = max(ans, sum);
    for (int i = k; i < n; i++) {
        sum += a[i] - a[i - k];
        ans = max(ans, sum);
    }
    cout << setprecision(20) << (double)ans / 2.0 << endl;
    return 0;
}

Measured memory_bytes: 1792
S = input()
T = input()

q = int(input())

SA = [0]
SB = [0]
TA = [0]
TB = [0]

sa=0
sb=0
ta=0
tb=0

for i in range(len(S)):
    if S[i]=="A":
        sa+=1
    elif S[i]=="B":
        sb+=1
    SA.append(sa)
    SB.append(sb)
    

for i in range(len(T)):
    if T[i]=="A":
        ta+=1
    elif T[i]=="B":
        tb+=1
    TA.append(ta)
    TB.append(tb)

for i in range(q):
    a,b,c,d = list(map(int,input().split()))
    sa_num=SA[b]-SA[a-1]
    sb_num=SB[b]-SB[a-1]
    ta_num=TA[d]-TA[c-1]
    tb_num=TB[d]-TB[c-1]
    if (sa_num+2*sb_num)%3==(ta_num+2*tb_num)%3:
        print("YES")
    else:
        print("NO")
        

Measured memory_bytes: 13360
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
  int64_t h,w;
  cin >> h >> w;
  cin.ignore();
  vector<string> mtx(h);
  rep(i,h){
    cin >> mtx[i];
  }
  int64_t result = 0;
  vector<vector<bool>> isused(h,vector<bool>(w));
  rep(inity,h){
    rep(initx,w){
      if(!isused[inity][initx] && mtx[inity][initx] == '.'){
        queue<pair<int64_t,int64_t>> que;
        que.push(make_pair(inity,initx));
        int64_t blackcnt=0, whitecnt=0;
        vector<vector<int64_t>> dr{{1,0},{-1,0},{0,1},{0,-1}};
        bool white = true;
        while(!que.empty()){
          pair<int64_t,int64_t> p = que.front();
          //printf("(%ld,%ld)\n",p.first,p.second);
          if(isused[p.first][p.second]){
            que.pop();
            continue;
          }
          isused[p.first][p.second] = true;
          white = (mtx[p.first][p.second] == '.');
          if(mtx[p.first][p.second] == '.'){
            whitecnt++;
          }else{
            blackcnt++;
          }
          rep(j,4){
            int64_t ydy = p.first+dr[j][0];
            int64_t xdx = p.second+dr[j][1];
            if(0 <= ydy && ydy <= h-1 && 0 <= xdx && xdx <= w-1 
               && !isused[ydy][xdx])
              if((mtx[ydy][xdx] == '#' && white) || (mtx[ydy][xdx] == '.' && !white)){
                que.push(make_pair(ydy,xdx));
              }
          }
          que.pop();
          /*rep(iy,h){
            rep(ix,w){
              cout << isused[iy][ix];
            }
            cout << endl;
          }
          cout << endl;*/
        }
        //cout << result << endl;
        result += whitecnt*blackcnt;
      }
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 512