akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

int N;
int a[40010];
int b[40010];
int main(){

  while(cin>>N&&N){
    for(int i=0;i<N;i++)cin>>a[i];
    for(int i=0;i<N;i++)cin>>b[i];
    sort(a,a+N,greater<int>());
    sort(b,b+N,greater<int>());
    int oPos=0;
    int ans=-1;
    for(int i=0;i<N;i++){
      // テヲツ鳴ーテ」ツ?療」ツ?湘・ツ?・テ」ツ?」テ」ツ?ヲテ」ツ?催」ツ?淌ィツヲツ?ァツエツ?」ツ?ィテヲツッツ氾ィツシツ?
      if(a[i]<=b[oPos])oPos++;
      int k=i+1;
      if(k/2<k-oPos){
        ans=i+1;
        break;
      }
    }
    if(ans==-1||ans==N)cout<<"NA"<<endl;
    else cout<<ans<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 1492
fun main(args: Array<String>) {
    val (n, a, b) = readLongList()

    val MOD = 1000000007L
    val all = pow(2, n.toLong(), MOD) - 1

    var nPa = calcNPermutationM(n, a, MOD)
    val nCa = nPa * inverse(calcFactorial(a, MOD), MOD)

    var nPb = calcNPermutationM(n, b, MOD)
    val nCb = nPb * inverse(calcFactorial(b, MOD), MOD)

    var tmp = if (all - nCa < 0) {
        val tmp2 = (all - nCa) % MOD
        (tmp2 + MOD) % MOD
    } else {
        (all - nCa) % MOD
    }
    tmp = if ((tmp - nCb) % MOD < 0) {
        val tmp2 = (tmp - nCb) % MOD
        (tmp2 + MOD) % MOD
    } else {
        (tmp - nCb) % MOD
    }
    println(tmp)
}

fun calcNPermutationM(n: Long, m: Long, MOD: Long): Long {
    var ret = 1L
    for (i in (n - m + 1)..n) {
        ret = (ret * i) % MOD
    }
    return ret
}

fun calcFactorial(x: Long, MOD: Long) = calcNPermutationM(x, x, MOD)

fun pow(n: Long, m: Long, MOD: Long): Long {
    var ret = 1L
    var x = n
    var k = m
    while (k > 0) {
        if ((k and 1L) == 1L) {
            ret = (ret * x) % MOD
        }
        x = (x * x) % MOD
        k = k shr 1
    }

    return ret
}

fun inverse(n: Long, MOD: Long) = pow(n, MOD - 2L, MOD)

//class Combination(n: Int, private val MOD: Long) {
//    val fact = Array(n + 1) { 0L }
//    val ifact = Array(n + 1) { 0L }
//
//    init {
//        fact[0] = 1
//        for (i in 1..n) {
//            fact[i] = (fact[i - 1] * i) % MOD
//        }
//        ifact[n] = pow(fact[n], MOD - 2, MOD)
//        for (i in n downTo 1) {
//            ifact[i - 1] = (ifact[i] * i) % MOD
//        }
//    }
//
//    fun value(n: Int, k: Int): Long {
//        if (k < 0 || k > n) {
//            return 0
//        }
//
//        val tmp = (fact[n] * ifact[k]) % MOD
//        return (tmp * ifact[n-k]) % MOD
//    }
//}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 36024
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

#define ff              first
#define ss              second
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pi              pair<int,int>
#define vi              vector<int>
#define mi              map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define MOD             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1N
#define loop(i,a,b)     for(int i=a;i<b;i++)

void c_p_c(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin) ;
    // freopen("output.txt","w",stdout) ;
    // #endif
}

int32_t main(){
    c_p_c();
    set<string> s;
    int n; cin >> n;
    while(n!=0){
        n--;
        string ss;
        cin >> ss;
        s.insert(ss);

    }

    cout << s.size() << '\n';

}

























































































Measured memory_bytes: 19232
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

void slove(int n){
	vector<int> v(86410);
	rep(i, 86410) v[i] = 0;//?????????
	rep(i, n){
		string s, e;
		cin >> s >> e;
		//?§???°?????????
		int start = 36000 * (s[0] - '0') + 3600 * (s[1] - '0') 
					+ 600 * (s[3] - '0') + 60 * (s[4] - '0')
					+ 10 * (s[6] - '0') + 1 * (s[7] - '0');
		int end = 36000 * (e[0] - '0') + 3600 * (e[1] - '0') 
					+ 600 * (e[3] - '0') + 60 * (e[4] - '0')
					+ 10 * (e[6] - '0') + 1 * (e[7] - '0');
		
		v[start]++;
		v[end]--;
	}
	int ans = 0;
	int now = 0;
	reps(i, 1, 86410){
		v[i] += v[i - 1];
		//now += v[i];
		ans = max(ans, v[i]);
	}
	printf("%d\n", ans);
}
int main(void){
	rep(i, 1000000){
		int n; scanf("%d", &n);
		if(n == 0) break;
		slove(n);
	}
	return 0;
}

Measured memory_bytes: 3668
fun main(args: Array<String>) {
  val (N, D) = readLine()!!.split(' ').map { it.toInt() }
  val points =  (1 .. N).map { readLine()!!.split(' ').map { it.toInt() } }

  val distances = (0 until N).map {i -> 
    (1 until N - i).map { j -> 
      Math.sqrt((0 until D).map { k -> 
        Math.pow(Math.abs(points[i][k] - points[i + j][k]).toDouble(), 2.0)
      }.sum())
    }
  }.flatMap { it }

  println(distances.filter { it.equals(Math.floor(it))}.size)
}

Measured memory_bytes: 38228
#include <iostream>
#include <sstream>
#include <vector>
#include <memory>
#include <algorithm>

using namespace std;


struct Node{
    int self;
    vector<shared_ptr<Node>> children;
    Node() : self(0) {}
};

int solve(shared_ptr<Node> n){
    if(n->children.size() == 0){
        return n->self / 2 + 1;
    }else{
        vector<int> chi;
        for(auto c : n->children){
            chi.push_back(solve(c));
        }
        int ret = 0;
        sort(chi.begin(),chi.end());
        for(int i=0;i<chi.size()/2+1;i++){
            ret += chi[i];
        }
        return ret;
    }
}

typedef string::const_iterator Cursor;

shared_ptr<Node> number(Cursor&);
shared_ptr<Node> parse(Cursor& c){
    if(*c == '['){
        vector<shared_ptr<Node>> children;
        c++;
        while(true){
            children.push_back(parse(c));
            if(*c == ']'){
                c++;
                shared_ptr<Node> n = make_shared<Node>();
                n->children = children;
                return n;
            }
        }
    }else{
        return number(c);
    }
}

shared_ptr<Node> number(Cursor& c){
    stringstream ss;
    while(isdigit(*c)){
        ss << *c;
        c++;
    }
    int ret;ss >> ret;
    shared_ptr<Node> n = make_shared<Node>();
    n->self = ret;
    return n;
}

int main(){
    int n;cin >> n;
    cin.ignore();
    for(int i=0;i<n;i++){
        string s;
        getline(cin,s);
        Cursor c = s.begin();
        shared_ptr<Node> n = parse(c);
        cout << solve(n) << endl;
    }
    return 0;
}

Measured memory_bytes: 2040
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int> Pii;
typedef pair<int,string> Pis;
typedef pair<Pii,Pis> P;
int n,m;
P t[10];
int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++){
      cin>>t[i].second.second;
      t[i].second.first=i;
      t[i].first.first=t[i].first.second=0;
      for(int j=0;j<n-1;j++){
	cin>>m;
	if(m==0)t[i].first.first--;
	else if(m==1)t[i].first.second++;
      }
    }
    sort(t,t+n);
    for(int i=0;i<n;i++)cout<<t[i].second.second<<endl; 
  }
    return 0;
}

Measured memory_bytes: 1204
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
long long n,c,x[100005],v[100005],sz[100005],nz[100005],sj[100005],nj[100005],ans;
int main()
{
	cin>>n>>c;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i]>>v[i];
	}
	for(int i=1;i<=n;i++)
	{
		sj[i]=sj[i-1]+v[i];
		sz[i]=max(sz[i-1],sj[i]-x[i]);
	}
	for(int i=n;i>=1;i--)
	{
		nj[i]=nj[i+1]+v[i];
		nz[i]=max(nz[i+1],nj[i]-(c-x[i]));
		
	}
	for(int i=1;i<=n;i++)
	{
		ans=max(ans,sz[i]);
		ans=max(ans,sj[i]+nz[i+1]-2*x[i]);
	}
	for(int i=n;i>=1;i--)
	{
		ans=max(ans,nz[i]);
		ans=max(ans,nj[i]+sz[i-1]-2*(c-x[i]));
	}
	cout<<ans;
	return 0;
	
} 


Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    string s;
    cin >> s;
    int ans = 0;
    rep(i, s.length()) {
        if ( s[i] == '1' ) ++ans;
    }
    cout << ans << endl;
    return 0;
}


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

#define dk23      ios_base :: sync_with_stdio(false);
#define inp       freopen("input.txt","r",stdin);
#define ll        long long

int main()
{
    ll n,i;
    cin>>n;
    map<ll,ll>mp;
    vector<ll>vec(n);
    for(i=0;i<n;i++){
        cin>>vec[i];;
        mp[vec[i]]++;
    }

    ll sum=0;

    for(auto it:mp){
        ll x=it.second;
        sum+=x*(x-1)/2;
    }
    for(i=0;i<n;i++){
        cout<<sum-(mp[vec[i]]-1)<<endl;
    }
    return 0;
}


Measured memory_bytes: 11008
N=int(input())
Ai=list(map(int,input().split()))
Bi=list(map(int,input().split()))
Ci=list(map(int,input().split()))

sf=0
for i in range(N):
    sf+=Bi[i]
for i in range(N-1):
    if Ai[i]+1==Ai[i+1]:
        sf+=Ci[Ai[i]-1]
print(sf)


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

int main() {
  long long int a,b,c,k,bb;
  cin>>a>>b>>c>>k;
  if(abs(a-b)>=1000000000000000000)cout<<"Unfair"<<endl;
  else if(k%2==0)cout<<a-b<<endl;
  else cout<<b-a<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}


int main(){
  int N,C;
  cin >> N >> C;
  int D[C][C];
  int c[N][N];

  rep(i,C)rep(j,C) cin >> D[i][j];
  rep(i,N)rep(j,N){
    cin >> c[i][j];
    c[i][j]--;
  }

  // rep(k,C)rep(i,C)rep(j,C){
  //   D[i][j] = min(D[i][j],D[i][k] + D[k][j]);
  // }
  vector< vector<int> > color(3,vector<int>(C,0));

  rep(i,N)rep(j,N){
    color[(i+j)%3][c[i][j]] ++;
  }

  long long ans = 1e9,cost;
  rep(c1,C)rep(c2,C)rep(c3,C){
    if(c1 == c2 || c2 == c3 || c3 == c1) continue;
    cost = 0;
    rep(i,3)rep(j,C){
      if(i == 0) cost += D[j][c1] * color[i][j];
      if(i == 1) cost += D[j][c2] * color[i][j];
      if(i == 2) cost += D[j][c3] * color[i][j];
    }
    //if(cost == 2) cout << c1 << ' ' << c2 << ' ' << c3 << endl;
    ans = min(cost,ans);
  }

  // rep(i,C){
  //   rep(j,C){
  //     cout << D[i][j] << ' ';
  //   }
  //   cout << endl;
  // }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int main(){
	int k, x;
	cin >> k >> x;
	for (int i = x-k+1; i <= x+k-1; i++){
		cout << i << " ";
	}
	cout << endl;
	return 0;
}



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

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


int main(void){
    ll N=0;
    cin >> N;
    ll count=0;;
    
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            for(int k=1;k<=N;k++){
                count+=gcd(i,gcd(j,k));
            }
        }
    }
    
    cout << count;

}

Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
long long n,S,w[100000],v[100000],F[101][100001];
using namespace std;
int main()
{
    //freopen("KNAPSACK1.INP","r",stdin);
    cin>>n>>S;
    for (long long i=1;i<=n;i++)
        cin>>w[i]>>v[i];
    for (long long i=1;i<=n;i++)
        for (long long j=1;j<=S;j++)
            if (w[i]<=j) F[i][j]=max(F[i-1][j-w[i]]+v[i],F[i-1][j]);
            else F[i][j]=F[i-1][j];
    cout<<F[n][S];
    return 0;
}


Measured memory_bytes: 79360
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<ll> &v) {
    std::for_each(v.begin(), v.end(), [](ll x) { std::cout << x << " "; });
    std::cout << std::endl;
}
//後ろからgreedyに決めていく
int main() {
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    REP(i, N) { cin >> A[i] >> B[i]; }
    //けつから適当にやっていくか
    ll add = 0;
    for(int i = N - 1; i >= 0; i--) {
        if((A[i] + add) % B[i] == 0) {
            continue;
        } else {
            ll resi = (A[i] + add) % B[i];
            add += B[i] - resi;
            // cout << resi << endl;
        }
    }
    cout << add << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#define L 100005
#define MAX 100002
typedef struct{
  char name[100];
  int time;
}Pro;

Pro Q[L];
int head,tail,tail,n;

void initialize(void);
Pro enq(Pro);
Pro deq(void);
int isEmpty(void);
int isFull(void);
int min(int,int);


int main(){
  int el=0,b,i,q;
  Pro a;
  initialize();
  scanf("%d%d",&n,&q);
  for(i=1;i<=n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].time);
  }
  head=1;
  tail=n+1;

  while(1){
    if(head==tail)break;
    a=deq();
    b=min(q, a.time);
    a.time -= b;
    el     += b;
    if( a.time > 0 )
      enq(a);
    else 
      printf("%s %d\n", a.name, el);
  }
  
  return 0;

}

void  initialize (){
  head= tail=0;
}
int isEmpty(){
  return head == tail;
}
int isFull(){
  return head == (tail+1)%MAX;
}
Pro enq(Pro x){
  if(isFull())
    printf("error!\n");
  Q[tail]=x;
  tail=(tail+1)%L;
  return x;
}
Pro deq(){
  Pro x;
  if(isEmpty())
    printf("error\n");
  x=Q[head];
  head=(head+1)%L;
  return x;
}
int min(int a,int b){
  if(a<b)return a;
  return b;
}
  


Measured memory_bytes: 11884
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	h := nextInt()
	a := nextInt()

	if h%a == 0 {
		fmt.Println(h / a)
	} else {
		fmt.Println(h/a + 1)
	}
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

int main() {
  string S;
  cin >> S;
   sort(S.begin(),S.end());
    vector<char>vec(26);
    vec={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  vector<int> Chr(26,0);
  
  for(int i=0; i<S.size(); i++) {
    for(int j=0; j<26; j++) {
      if(S.at(i) == vec.at(j)) { 
        Chr.at(j)++;
      }
    }
  }
    for(int i=0; i<26; i++) {
      if(Chr.at(i) == 0) {
        cout << vec.at(i) << endl;
        return 0;
      }
    }
    cout << "None" << endl;
  }

    
    
    
    
  


Measured memory_bytes: 3676
/// BISMILLAH
#include <bits/stdc++.h>
using namespace std;
#define end "\n"
int main(void) {
    ios_base::sync_with_stdio(0);

    int l, d, n;
    cin >> l >> d >> n;
    int count = 0;
    for(int i = l; i <= d; i++) {
        if(!(i % n))
            count++;
    }
    cout << count << end;

    return 0;
}

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

const int N=1e5+5,zqm=1e9+7;
int f[N],pre[N];

int sum(int l,int r) {return (pre[r]-(l<=0 ? 0 : pre[l-1])+zqm)%zqm;}

int main() {
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	
	int n,k; scanf("%d%d",&n,&k);
	f[0]=1,fill(pre,pre+k+1,1);
	for(int i=1,a;i<=n;++i) {
		scanf("%d",&a);
		for(int j=1;j<=k;++j) f[j]=sum(j-a,j);
		for(int j=1;j<=k;++j) pre[j]=(pre[j-1]+f[j])%zqm;
	}
	printf("%d\n",f[k]);
	
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
long long n;
long long count0 = 0;

vector<long long> counter(string s){
    vector<long long> v(3, 0);

    for(long long i = 0; i < s.size(); i++){
        if(s[i] == '3'){
            v[0]++;
        }
        else if(s[i] == '5'){
            v[1]++;
        }
        else if(s[i] == '7'){
            v[2]++;
        }
    }

    return v;
}

void dfs(string s){
    if(s.size() == to_string(n).size()+1){
        return;
    }
    

    if(stoll(s) <= n and counter(s)[0] != 0 and counter(s)[1] != 0 and counter(s)[2] != 0){
        count0++;
    }

    dfs(s+'3');
    dfs(s+'5');
    dfs(s+'7');
}

int main(){
    cin >> n;

    dfs("3");
    dfs("5");
    dfs("7");

    cout << count0 << endl;
    return 0;
}

Measured memory_bytes: 3688
import sys
sys.stdin.readline

def main():
    N, K = input(), int(input())
    S = "0"*(100-len(N))+N
    DP = [[[0] * 2 for _ in range(K+2)] for _ in range(101)]
    DP[0][0][0] = 1
    for i in range(100):
        for j in range(K+1):
            DP[i+1][j][0] += DP[i][j][0] * (S[i] == "0")
            DP[i+1][j+1][0] += DP[i][j][0] * (S[i] != "0")
            DP[i+1][j][1] += DP[i][j][1] + DP[i][j][0] * (int(S[i]) > 0)
            DP[i+1][j+1][1] += DP[i][j][1] * 9 + DP[i][j][0] * max(0, int(S[i])-1)
    print(sum(DP[-1][K]))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N, M, K;
  cin >> N >> M >> K;
  
  vector<int> A(N), B(M);
  
  vector<int> book(N + 1); //読める本の数 Aの本はN冊～0冊
  int64_t total = 0; //Aの本を〇冊読むのにかかる時間
  int64_t btotal = 0;
  int bbook = 0;
  int y = 0;
  int maxbook = 0;
  for(int i = 0; i < N; i++)
  {
    cin >> A.at(i);
    total += A.at(i);
  }
  for(int i = 0; i < M; i++) cin >> B.at(i);
 
  for(int i = N; i >= 0; i--)
  {
    if(i != N) total -= A.at(i);
    if(total > K) continue;
    book.at(i) += i;
    while(total + btotal < K && y < M)
    {
      if(total + btotal + B.at(y) <= K)
      {
        btotal += B.at(y);
        y++;
        bbook++;
      }
      else break;
    }
    book.at(i) += bbook;
  }
  for(int i = 0; i <= N; i++)
  {
    if(maxbook < book.at(i)) maxbook = book.at(i);
  }  

  cout << maxbook << endl;
}

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

using namespace std;

 

string lcs(string s,string t){
   
   int m = s.size();
   int n = t.size();
   int C[m+1][n+1];
   s = " " + s;
   t = " " + t;

   for(int i=0;i<=m;i++){
       C[i][0] =0;
   }
   for(int j=1;j<=n;j++){
       C[0][j] =0;
   }

   for(int i=1;i<=m;i++){
       for(int j=1;j<=n;j++){
           if(s[i]==t[j]){
               C[i][j] = C[i-1][j-1] +1;
           }
           else{
               C[i][j] = max(C[i-1][j],C[i][j-1]);
           }
       }
   }
  
string ans = "";

  while(C[m][n]){
      if(C[m][n]==C[m-1][n]){
          m--;

      }
      else if(C[m][n]==C[m][n-1]){
          n--;
      }

      else{
          ans = ans + s[m];
          m--; 
          n--; 
          
      }
  }
  reverse(ans.begin(),ans.end());
  
  
  return ans;

}

int main() {
  string s,t;
  cin >> s >> t;
  
  cout << lcs(s,t) << endl;
}

Measured memory_bytes: 35456
array = []

while true do
  num = gets.chomp.split(" ").map(&:to_i)
  if num[0] == 0 && num[1] == 0
    break
  else
    array << num
  end
end

array.each do |i|
  sorted =  i.sort
  print sorted[0]
  print " "
  print sorted[1]
  puts ""
end


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

long long int* sat(long long int*a,long long int *b,int n)
{
	for(int j=0;j<n;j++)
	{
		b[j]=a[j];
	} 
	for(int k=0;k<n;k++)
	{
		a[k]=b[n-1-k]; 
	}
	return a;
}

int main(void)
{
	int n = 0;
	cin>>n;
	long long int a[n]={0};
	long long int b[n] ={0};
	
	for(int k=0;k<n;k++){
		long long int h =0;
		cin>>h;
		a[k]=h;
	}

	if(n%2 == 0)
	{
		for(int i=0;i<n/2;i++)
		{
			b[i]=a[n-1-2*i];
		}
		for(int j=n/2;j<n;j++)
		{
			b[j]=a[2*(j-n/2)];
		}
	}else
	{
		for(int i=0;i<(n+1)/2;i++)
		{
			b[i]=a[n-1-2*i];
		}
		for(int j=(n+1)/2;j<n;j++)
		{
			b[j]=a[2*(j-(n+1)/2)+1];
		}
	}

	for (int o=0;o<n;o++)
	{
		cout<<b[o]<<" ";
	}
	

	return 0;
}





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

int main(){
  int n; cin>>n;
  int arr[n];
  for(int i = 0; i < n; i++) cin>>arr[i];
  //bool f = 1;

  for(auto i: arr){
      if(i % 2 == 0){
        if(i % 3 != 0 and i % 5 != 0){
            cout<<"DENIED";
            exit(0);
          }
      }
    }

 cout<<"APPROVED";
  return 0;
  }


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

const int MAX_Q = 51;
int n, m, q;
int a[MAX_Q], b[MAX_Q], c[MAX_Q], d[MAX_Q];

int ans = 0;
 
void all_search(vector <int> &v, int dep) {
  if ( dep > n ) {
    int sum = 0;
    for ( int k = 0; k < q; k++ ) {
      if ( v[b[k]] - v[a[k]] == c[k] ) { sum += d[k]; }
    }
    ans = ( sum > ans ) ? sum : ans;
    return;
  }

  for(int k = v[dep - 1]; k <= m; k++) {
    v[dep] = k;
    all_search(v, dep+1);
  }
}
 
int main() {
  cin >> n >> m >> q;
  for ( int i = 0; i < q; i++ ) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  vector <int> v(n+1, 1);
  all_search(v, 1);

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

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using pii = pair<int,int>;

int main(){
  int n; cin>>n;
  int x[101010];
  rep(i,100){
    rep(j,100){
      rep(k,100){
        i++;j++;k++;
        int y = i*i+j*j+k*k+i*j+j*k+k*i;
        //cout<<y<<endl;
        x[y]++;
        i--;j--;k--;
      }
    }
  }
  rep(i,n){
    cout<<x[i+1]<<endl;
  }
}


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

int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> s(H);
    for (int r = 0; r < H; r++)
    {
        cin >> s.at(r);
    }

    vector<vector<int>> dp(H, vector<int>(W, 0));
    if (s.at(0).at(0) == '#')
    {
        dp.at(0).at(0) = 1;
    }
    for (int r = 1; r < H; r++)
    {
        if (s.at(r).at(0) == '#')
        {
            if (s.at(r - 1).at(0) == '#')
                dp.at(r).at(0) = dp.at(r - 1).at(0);
            else
                dp.at(r).at(0) = dp.at(r - 1).at(0) + 1;
        }
        else
        {
            dp.at(r).at(0) = dp.at(r - 1).at(0);
        }
    }
    for (int c = 1; c < W; c++)
    {
        if (s.at(0).at(c) == '#')
        {
            if (s.at(0).at(c - 1) == '#')
                dp.at(0).at(c) = dp.at(0).at(c - 1);
            else
                dp.at(0).at(c) = dp.at(0).at(c - 1) + 1;
        }
        else
        {
            dp.at(0).at(c) = dp.at(0).at(c - 1);
        }
    }
    for (int r = 1; r < H; r++)
    {
        for (int c = 1; c < W; c++)
        {
            int cost_d, cost_r;
            if (s.at(r).at(c) == '#')
            {
                if (s.at(r - 1).at(c) == '#')
                    cost_d = dp.at(r - 1).at(c);
                else
                    cost_d = dp.at(r - 1).at(c) + 1;
                if (s.at(r).at(c - 1) == '#')
                    cost_r = dp.at(r).at(c - 1);
                else
                    cost_r = dp.at(r).at(c - 1) + 1;
            }
            else
            {
                cost_d = dp.at(r - 1).at(c);
                cost_r = dp.at(r).at(c - 1);
            }
            dp.at(r).at(c) = min(cost_d, cost_r);
        }
    }
    cout << dp.at(H - 1).at(W - 1) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

int main(){

    int sum_x, leg_y;
    cin >> sum_x >> leg_y;

    rep(i,sum_x + 1){
        if (2 * i + 4 * (sum_x - i) == leg_y){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
using namespace std;
int main() {
    int N;
    scanf("%d%*c", &N);
    double A, ans = 0.0;
    for (int i = 0; i < N; i++) {
        scanf("%lf%*c", &A);
        ans += 1.0 / A;
    }
    printf("%.10lf\n", 1.0 / ans);
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main{
	int x;
	
	public void solve(){
		Scanner sc = new Scanner(System.in);
		x = sc.nextInt();
		
		System.out.println(x*x*x);
		
	}
	
	public static void main(String[] args){
		Main obj = new Main();
		obj.solve();
	}
}

Measured memory_bytes: 17160
#include <bits/stdc++.h>
#define INF 100000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define chmax(x, y) x = max(x, y)
#define print(x) cout << x << "\n"
#define printv(vec) rep(i, vec.size()) cout << vec[i] << " "
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;
using vvs = vector<vector<string>>;

void solve(){
	
	ll H, W, ch, cw, dh, dw;
	cin >> H >> W;
	cin >> ch >> cw;
	cin >> dh >> dw;
	vs S(H);
	rep(i, H) cin >> S[i];
	ll dir[] = {1, 0, -1, 0, 1};
	
    deque<pair<ll, ll>> q;
    vector<vector<ll>> dp(H, vector<ll>(W, INF));
    dp[ch - 1][cw - 1] = 0;
    q.push_back(make_pair(ch - 1, cw - 1));
	ll x, y, nx, ny;
    
    while(!q.empty()){

		x = q.front().first;
		y = q.front().second;
        q.pop_front();
		
		rep(i, 4){
			ny = y + dir[i];
			nx = x + dir[i + 1];
			if (ny < 0 || nx < 0 || nx >= H || ny >= W)continue;
			if (S[nx][ny] == '#') continue;
			if (dp[nx][ny] > dp[x][y]) {
				dp[nx][ny] = dp[x][y];
				q.push_front(make_pair(nx, ny));
			}
		}
		
        rep2(i, -2, 3){
            rep2(j, -2, 3){
                nx = x + i;
                ny = y + j;
                if (ny < 0 || nx < 0 || nx >= H || ny >= W)continue;
				if (S[nx][ny] == '#') continue;
				if(dp[nx][ny] > dp[x][y] + 1){
					dp[nx][ny] = dp[x][y] + 1;
					q.push_back(make_pair(nx, ny));
				}
			}
		}
	}

	ll ans = dp[dh - 1][dw - 1];
	if(ans == INF) print(-1);
	else print(ans);	
}	

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


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

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

void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n + 1), b(m + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    b[i] += b[i - 1];
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (k < a[i]) break;
    int j = prev(upper_bound(all(b), k - a[i])) - b.begin();
    ans = max(ans, i + j);
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 6352
# coding: utf-8
# Your code here!
N=int(input())
l=[]
for _ in range(N):
    l.append(int(input()))

l.sort()
sl=sum(l)

if sl%10==0:
    for i in range(N):
        if l[i]%10!=0:
            print(sl-l[i])
            exit()
    print(0)
    exit()
else:
    print(sl)

Measured memory_bytes: 3060
#include<stdio.h>
int main(){
  int n,i;
  int data[100];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&data[i]);
  }
  for(i=n-1;i>=0;i--){
    printf("%d",data[i]);
    if(i!=0)printf(" ");
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 2728
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N; 
  cin >> N;

  string s;
  cin >> s;

  vector<int> R(N, 0), G(N, 0), B(N, 0);
  RREP(i, N){
    if(s[i] == 'R') R[i]++;
    if(s[i] == 'G') G[i]++;
    if(s[i] == 'B') B[i]++;
    if(i != 0) R[i-1] += R[i];
    if(i != 0) G[i-1] += G[i];
    if(i != 0) B[i-1] += B[i];
  }

  int ans = 0;
  REP(i, N) FOR(j, i+1, N-1){
    if(s[i] != 'R' || s[j] != 'G') continue;
    ans += B[j+1];
    if(j+(j-i) < N && s[j+(j-i)] == 'B') ans--;
  }
  REP(i, N) FOR(j, i+1, N-1){
    if(s[i] != 'R' || s[j] != 'B') continue;
    ans += G[j+1];
    if(j+(j-i) < N && s[j+(j-i)] == 'G') ans--;
  }
  REP(i, N) FOR(j, i+1, N-1){
    if(s[i] != 'G' || s[j] != 'B') continue;
    ans += R[j+1];
    if(j+(j-i) < N && s[j+(j-i)] == 'R') ans--;
  }
  REP(i, N) FOR(j, i+1, N-1){
    if(s[i] != 'G' || s[j] != 'R') continue;
    ans += B[j+1];
    if(j+(j-i) < N && s[j+(j-i)] == 'B') ans--;
  }
  REP(i, N) FOR(j, i+1, N-1){
    if(s[i] != 'B' || s[j] != 'R') continue;
    ans += G[j+1];
    if(j+(j-i) < N && s[j+(j-i)] == 'G') ans--;
  }
  REP(i, N) FOR(j, i+1, N-1){
    if(s[i] != 'B' || s[j] != 'G') continue;
    ans += R[j+1];
    if(j+(j-i) < N && s[j+(j-i)] == 'R') ans--;
  }
  cout << ans << "\n";

  return 0;
}

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


int main(){
  int a,b;
  stack<string> s;
  string str;
  cin >> str;
  do{
   if(str=="+" || str=="-" || str=="*"){
     a = stoi(s.top());s.pop();
     b = stoi(s.top());s.pop();
     if(str == "+"){
       s.push(to_string(b+a));
     }else if(str == "-"){
       s.push(to_string(b-a));
     }else{
       s.push(to_string(b*a));
     }
   }else{
     s.push(str);
   }
 }while(cin >> str);
  
  cout << s.top() << endl;
     
       
}


Measured memory_bytes: 3284
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Papers, C - Poll
            int N = int.Parse(Console.ReadLine());

            var words = new Dictionary<string, int>();
            int max = 1;

            for(int i = 0; i < N; i++)
            {
                var s = Console.ReadLine();

                if (words.ContainsKey(s))
                {
                    words[s]++;
                    max = Math.Max(max, words[s]);
                }
                else
                {
                    words.Add(s, 1);
                }
            }

            //int max = words.Max(x => x.Value);
            var ans = new List<string>();

            foreach(var w in words)
            {
                if (w.Value == max)
                {
                    ans.Add(w.Key);
                }
            }

            ans.Sort(StringComparer.Ordinal);

            foreach(var a in ans)
            {
                Console.WriteLine(a);
            }
        }
    }
}


Measured memory_bytes: 42844
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main(){
  string s;
  cin >> s;
  char a,b;
  a = s[0];
  REP(i,s.size()){
    if(i==0) continue;
    b = s[i];
    if(a==b){
      cout << "Bad" << endl;
      return 0;
    }
    a = b;
  }

  cout << "Good" << endl;

}


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

int main(){
  string str;
  bool flag;
  int s = 0;
  cin >> str;
  for (int i=0; i < str.length(); i++){
    s += int(str.at(i)) - '0';
  }
  if (stoi(str) % s == 0) {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
  return 0;
  
}

Measured memory_bytes: 256
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [-a for a in A]
heapq.heapify(A)

for i in range(M):
    most_expensive = -heapq.heappop(A)
    most_expensive //= 2
    heapq.heappush(A, -most_expensive)

print(-sum(A))




Measured memory_bytes: 20392
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def ep(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        ep(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, W, WV):
    vl = {}
    vl[WV[0][0]] = list()
    vl[WV[0][0]+1] = list()
    vl[WV[0][0]+2] = list()
    vl[WV[0][0]+3] = list()
    for w, v in WV:
        vl[w].append(v)

    for v in vl.values():
        v.sort(reverse=True)
        v.insert(0, 0)


    wi, wj, wk, wl = vl.keys()
    ans = 0
    vis = 0
    for i, vi in enumerate(vl[wi]):
        if wi * i > W:
            break
        vis += vi
        vjs = 0
        for j, vj in enumerate(vl[wj]):
            if wi * i + wj * j > W:
                break
            vjs += vj
            vks = 0
            for k, vk in enumerate(vl[wk]):
                if wi*i + wj*j + wk*k> W:
                    break
                vks += vk
                vls = 0
                for l, vll in enumerate(vl[wl]):
                    if wi*i + wj*j + wk*k + wl*l> W:
                        break
                    vls += vll
                ans = max(ans, vis+vjs+vks+vls)
    return ans





def main():
    N, W = read_int_n()
    WV = [read_int_n() for _ in range(N)]
    print(slv(N, W, WV))


if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

struct range { ll l, r; };

int main() {
  int N, M; cin >> N >> M;
  string S; cin >> S;
  int num0[N], num1[N]; rep(i,N) { num0[i] = S[i]=='1'; num1[i] = S[i]=='1'; }
  range r[M]; rep(i,M) { cin >> r[i].l >> r[i].r; r[i].l--; r[i].r--; }
  // rep(i,M) cout << r[i].l << " " << r[i].r << endl;

  rep(i,M) {
    sort(num0+r[i].l,num0+(r[i].r+1));
    sort(num1+r[i].l,num1+(r[i].r+1), greater<int>());
  }
  // debug(num0,num0+N); debug(num1,num1+N);
  
  int l1[N+1] = {}, r1[N+1] = {};
  rep(i,N) { l1[i+1] = l1[i]+num0[i]; r1[i+1] = r1[i]+num1[i]; }
  // debug(l1,l1+(N+1)); debug(r1,r1+(N+1));

  ll dp[N+1][N+1] = {}; dp[0][0] = 1;
  repr(i,1,N+1) {
    repr(j,l1[i],r1[i]+1) {
      if (j==0) dp[i][j] = dp[i-1][j];
      else dp[i][j] = (dp[i-1][j-1]+dp[i-1][j]) % MOD;
    }
  }
  // rep(i,N+1) debug(dp[i],dp[i]+(N+1));

  ll count = 0; rep(i,N) count += num1[i];
  ll result = dp[N][count];
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 70784
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
/* }}} */

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

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvvi = std::vector<vvi>;
using pii = std::pair<int, int>;
using D = double;
using P = std::complex<D>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T> void print(T x) {std::cout << x << '\n';}
template <typename T>
void print(std::vector<T>& v, std::string s = " ") {
  REP(i, v.size()) {
    if (i != 0) std::cout << s;
    std::cout << v[i];
  }
  std::cout << '\n';
}

/* }}} */

struct Node {
  int par; // parent node
  vi chi; // child nodes
  Node() { par = -1; }
};

int N;
vvi g;
vector<Node> node;
vector<bool> vis;

// make tree
void dfs(int a, int b)
{
  vis[a] = true;
  node[a].par = b;
  REP(i, N) {
    // no-path or visited
    if (g[a][i] == INF || vis[i]) continue;
    node[a].chi.pb(i);
    dfs(i, a);
  }
}

void parse(int c, int cost, int& sum)
{
  vis[c] = true;
  if (node[c].chi.empty()) return;
  for (int i : node[c].chi) {
    if (!vis[i]) parse(i, g[c][i], sum);
  }
  sum += cost * 2;
}

int getcost()
{
  vis = vector<bool>(N, false);
  int sum = 0, cur = 0;
  while (cur != -1) {
    parse(cur, 0, sum);
    if (node[cur].par != -1) sum += g[cur][node[cur].par];
    cur = node[cur].par;
  }
  return sum;
}

signed main()
{
  while (N = in(), N) {
    g = vvi(N, vi(N, INF));
    REP(i, N - 1) {
      int a = in() - 1, b = in() - 1, cost = in();
      g[a][b] = g[b][a] = cost;
    }
    int mini = INF;
    REP(i, N) {
      vis = vector<bool>(N, false);
      node = vector<Node>(N);
      dfs(i, -1);
      mini = min(mini, getcost());
    }
    print(mini);
  }

  return 0;
}

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

int main (){
    int a;
    cin >> a;
    int len;
    cin >> len;
    int b[a];
    int i,co=0;
    for(i=0;i<a;i++){
        cin >>b[a];
        if(b[a]>=len)
        co++;
    }
    cout << co;
    return 0;
}

Measured memory_bytes: 256
<?php
list($h, $w) = ints();
for ($i = 0; $i < $h; ++$i) {
    $s = strs();
    $j = array_search('snuke', $s);
    if ($j !== false) $ans = chr(65 + $j) . ($i + 1);
}
echo $ans . PHP_EOL;
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

int x,i,sum = 0;
int main() {
    scanf("%d", &x);
    for(i = 1;; i++){
        sum += i;
        if(sum >= x) break;
    }
    pout(i);

	return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
 
lst = ["." + input() + "." for _ in range(h)]
matrix = ["." * (w + 2)] + lst + ["." * (w + 2)]
 
 
ans = "Yes"
for i in range(1, h + 1):
    for j in range(1, w + 1):
        center = matrix[i][j]
        up = matrix[i - 1][j]
        down = matrix[i + 1][j]
        left = matrix[i][j - 1]
        right = matrix[i][j + 1]
        if center == "#" and up == down == left == right == ".":
            ans = "No"
print(ans)

Measured memory_bytes: 3064
n, m = gets.chomp.split.map(&:to_i)
balls = Array.new(n + 1, 1)
red = Array.new(n + 1, false)
red[1] = true

m.times do
  x, y = gets.chomp.split.map(&:to_i)
  if red[x]
    red[y] = true
    if balls[x] == 1
      red[x] = false
    end
  end
  balls[x] -= 1
  balls[y] += 1
end

ans = 0
red.each do |r|
  ans += 1 if r
end
puts ans

Measured memory_bytes: 3324