akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main()
{
        int i, j;
        int h, w, time[100][100], count;
        char cloud[100][100];

        scanf("%d%d", &h, &w);
        for(i=0;i<h;i++)scanf("%s", cloud[i]);
        //for(i=0;i<h;i++)for(j=0;j<w;j++)time[i][j] = -1;

        for(i=0;i<h;i++){
                count = -1;
                for(j=0;j<w;j++){
                        if(cloud[i][j] == 'c')count = 0;
                        time[i][j] = count;
                        if(count != -1)count ++;
                }
        }
        
        for(i=0;i<h;i++){
                for(j=0;j<w;j++){
                        printf("%d%s", time[i][j], (j==w-1)?"\n":" ");
                }
        }
        return 0;
}

Measured memory_bytes: 648
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

#[allow(unused_imports)]
fn main() {
    use std::cmp::max;
    use std::cmp::min;
    use std::collections::HashMap;

    input!{
        a: chars,
        b: chars,
    }

    let ans = if a[0] < b[0] {
        '<'
    } else if a[0] == b[0] {
        '='
    } else {
        '>'
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
void main()
{
    int n = readln.chomp.to!int;
    int[] a = readln.split.to!(int[]);

    auto cnt4 = a.count!(x => x % 4 == 0);
    auto cnt2 = a.count!(x => x % 4 != 0 && x % 2 == 0);

    if (cnt4 >= n / 2) "Yes".writeln;
    else if (cnt4 >= (n - cnt2 + 1) / 2) "Yes".writeln;
    else "No".writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 4404
#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iomanip>
using namespace std;
int main(){
	int N,M,rank,dis,distance;
	cin >> N >> M;
	int a[N],b[N];
	int c[M],d[M];
	for(int i=0;i<N;i++){
		cin >> a[i] >> b[i];
	}
	for(int j=0;j<M;j++){
		cin >> c[j] >> d[j];
	}

	for(int g=0;g<N;g++){
		rank = 0;
		dis = 1000000000;
		for(int h=0;h<M;h++){
			distance = abs(a[g]-c[h])+abs(b[g]-d[h]);
			if(dis > distance){
				dis = distance;
				rank = h+1;
			}
		}
		cout << rank << endl;
	}
	return 0;
}

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


int main()
{
int N;
cin>>N;
int answer=0;
int kijun=0;
while(kijun==0&&answer<50000)
{
if(answer+answer*8/100==N){cout<<answer<<endl;kijun++;}
answer++;
}
if(kijun==0){cout<<":("<<endl;}
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <utility>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <stdio.h>
#include <deque>

using namespace std;

#define REP(i,n,m) for( long long int i = (n); i < (m); i++ )
#define REV(v) for (auto itr = v.rbegin(); itr != v.rend(); itr++)
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define SORT(v) sort( ALL(v) );
#define LAST(v) v[v.size()-1]
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,-1,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pi pair<int, int>
#define MP make_pair
#define PB push_back
#define IIN(a) int a; cin >> a;
#define LIN(a) ll a; cin >> a;
#define SIN(a) string a; cin >> a;
#define Vl(v,n) vector<ll> v(n);
#define Read_vll(v,n) vector<ll> v(n);REP(i,0,n)cin>>v[i];
#define sumV(v,n) Vl(acm,n) REP(i,0,n) acm[i] = v[i] + ( i == 0 ? 0 : acm[i - 1]);
#define EPS (1e-10)
#define INF 1000000000000LL

void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}


template<class T=ll>struct Graph{
	int n;
	vector<vector<tuple<ll,T>>>edge;
	Graph(int N=1):n(N){edge.resize(n);}
	void add(ll f,ll t,T c,bool d=false){
		edge[f].emplace_back(t,c);
		if(!d)edge[t].emplace_back(f,c);
	}
	void view(){
		REP(i,0,n)for(auto&e:edge[i])
			puta(i,"=>",get<0>(e),", cost :",get<1>(e));
	}
};

const ll maxv = 1e5 + 10;

int MOD=1000000007;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
//I ASCII code: '0' = 48; 'A' = 65; 'a' = 97

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    LIN(n) LIN(m)
    std::vector<ll> v(n);
    REP(i,0,m){
      LIN(a) LIN(b)
      v[a - 1] ^= 1;
      v[b - 1] ^= 1;
    }
    REP(i,0,n){
      if( v[i] ){
        cout << "NO" << endl;
        return 0;
      }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <map>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-9

const int coin[] = {1,5,10,50,100,500};
const int inf = 999999999;
int c[6],p;

int oturi(int x){
	int ret = 0;
	for(int i=5; i>=0 && x>0; i--){
		ret += (x/coin[i]);
		x -= (x/coin[i])*coin[i];
	}
	return ret;
}
int pay(int x){
	int ret = 0;
	for(int i=5; i>=0 && x>0; i--){
		ret += min(x/coin[i], c[i]);
		x -= min(x/coin[i],c[i]) * coin[i];
	}
	return x==0 ? ret : -1;
}
int main(){
	while(scanf("%d",&p),p){
		scanf("%d%d%d%d%d%d",c,c+1,c+2,c+3,c+4,c+5);
		int sum = 0;
		int ret = INT_MAX;
		
		rep(i,6)sum += coin[i]*c[i];
		
		for(int i=p; i<=p+500; i++){
			int t = pay(i);
			if( t!=-1 ){
				ret = min(ret, t+oturi(i-p));
			}
		}
		printf("%d\n",ret);
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  long long ans =0;
  for(int i=1;i<N;i++){
    int count = 0;
    count = (N-1)/i;
    ans = ans + count;
  }
  
  cout << ans << endl;
    
}


Measured memory_bytes: 3620
#!/usr/bin/env python3
import sys


def solve(N: int, R: int):
    print(100*(10-N)+R if N<10 else R)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    solve(N, R)

if __name__ == '__main__':
    main()


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

int main() {
int n;
cin >> n;
vector<int>vec(n);

for (int i=0;i<n;i++){
    cin >> vec.at(i);
}
sort(vec.begin(),vec.end());
int p,q;
p=vec.at((n/2)-1);
q=vec.at(n/2);
cout << q-p <<endl;

}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

int main() {
    long long int a;
    cin>>a;
    if(a%2==1){
		 cout<<0<<endl;
		return 0;
	}
	long long int sum=0;
	long long int val= 5;
	a/=2;
	while(val<=a){
		sum += a/val;
		val *= 5;
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int mod = 1000000007;
int main()
{
  int n,m;
  cin>>n>>m;
  int i,j,s[n],t[m];
  for(i=0;i<n;i++) cin>>s[i];
  for(i=0;i<m;i++) cin>>t[i];
  
  int dp[n+1][m+1];
  memset(dp, 0, sizeof(dp));
  
  for(i=1;i<=n;i++)
  {
    for(j=1;j<=m;j++)
    {
   		dp[i][j]=(dp[i-1][j]+ dp[i][j-1])%mod;
      	dp[i][j]= (dp[i][j]-dp[i-1][j-1]+mod)%mod;
      	if(s[i-1]==t[j-1])
        {
          dp[i][j]=(dp[i][j]+1+dp[i-1][j-1])%mod;
        }
    }
  }
  cout<<(dp[n][m]+1)%mod;
  return 0;
}

Measured memory_bytes: 15872
#include<iostream>
using namespace std;
int main() {
  int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  cout << a[K-1] << endl;
}

Measured memory_bytes: 256
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int main(void){
	int l, r, i, j;
	scanf("%d%d", &l, &r);
	if(r>l+2019){
		puts("0");
	}else{
		int k=l/2019*2019;
		l-=k; r-=k;
		int ans=2019;
		for(i=l; i<=r; i++){
			for(j=l; j<i; j++){
				int now=i*j%2019;
				if(now<ans) ans=now;
			}
		}
		printf("%d\n", ans);
	}
}


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

int a[200000];
int main(){
	int n,t;
	long long ans = 0;
	
	cin >> n >> t;
	for(int i = 0;i < n;i++){
		cin >> a[i];
	}
	for(int i = 0;i < n-1;i++){
		ans+=min(a[i+1]-a[i],t);
	}
	ans+=t;
	cout << ans << endl;
}

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

long long N;
static vector<pair<int, int> > V[100000];
static long long Dist[100000] = {};
static bool visited[100000] = {};

void DFS(int S) {
	visited[S] = true;
	for (pair<int, int> NS : V[S]) {
		if (!visited[NS.first]) {
			Dist[NS.first] = (Dist[S] + NS.second) % 2;
			DFS(NS.first);
		}
	}
}

int main() {
	cin >> N;
	for (int i = 0; i < N - 1; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		w = w % 2;
		u--, v--;
		V[u].push_back({ v, w });
		V[v].push_back({ u, w });
	}
	DFS(0);
	for (int i = 0; i < N; i++) {
		cout << Dist[i] << endl;
	}
}

Measured memory_bytes: 8064
#include <stdio.h>

int main(void){
    int n,k;
    scanf("%d%d",&n,&k);
    int d[k];
    scanf("%d",&d[0]);
    int a[k][100];
    int count[n];
    int ans=0;
    for(int i=0; i<n; i++){
        count[i]=0;
    }
    for(int i=0; i<k; i++){
        for(int j=0; j<d[i]; j++){
            scanf("%d",&a[i][j]);
            count[a[i][j]-1]++;
        }
        if(i==k-1){
            break;
        }
        scanf("%d",&d[i+1]);
    }
    for(int i=0; i<n; i++){
        if(count[i]==0){
            ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vec;
typedef vector<P> pvec;
typedef vector<vector<int>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<int> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<int,vector<int>,greater<int>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> DX = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> DY = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const ll INF = (1LL << 60); // 1152921504606846976
const double PI = (3.141592653589794);
const double EPS = (0.0000000001); // 10^(-10)

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }



//----------------------------------------------------------------
int nmax=200000; // 2*(10^5)
vvec G(nmax);


int n,m;
vec ans(nmax);
vector<bool> seen;

void solve4ts()
{
    
    cin>>n>>m;
    seen.resize(n,false);
    rep(i,m){
        int a,b;
        cin>>a>>b;a--;b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    

    queue<int> p;
    p.push(0);
    seen[0]=true;
    while(!p.empty()){
        int now=p.front(); p.pop();
        for(auto next:G[now]){
            if(seen[next]) continue;
            else{
                p.push(next);
                ans[next]=now;
                seen[next]=true;
            }
        }
    }

    int ng=0;
    rep(i,n) if(seen[i]==false) ng++;
    if(ng==0){
        cout<<"Yes"<<endl;
        rep(i,n-1){
            cout<<ans[i+1]+1<<endl;
        }
    }
    else{
        cout<<"No"<<endl;
    }
}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
    int repeat = 1;
    // cin >> repeat;
    while(repeat--) solve4ts();
}

Measured memory_bytes: 16220
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll inf = 1e18;
int main() {
    int a, b, q;
    cin >> a >> b >> q;
    vector<ll> s(a+2), t(b+2);
    s[0] = t[0] = -inf;
    rep(i, a) cin >> s[i+1];
    rep(i, b) cin >> t[i+1];
    s[a+1] = t[b+1] = inf;
    rep(i, q) {
        ll res = inf;
        ll x; cin >> x;
        auto it1 = lower_bound(s.begin(),s.end(),x);
        it1--;
        auto it2 = lower_bound(t.begin(),t.end(),*it1);
        it2--;
        res = min(res, abs(*it1-x)+min(abs(*it2-*it1),abs(*(it2+1)-*it1)));
        it1++;
        it2 = lower_bound(t.begin(),t.end(),*it1);
        it2--;
        res = min(res, abs(*it1-x)+min(abs(*it2-*it1),abs(*(it2+1)-*it1)));
        it1 = lower_bound(t.begin(),t.end(),x);
        it1--;
        it2 = lower_bound(s.begin(),s.end(),*it1);
        it2--;
        res = min(res, abs(*it1-x)+min(abs(*it2-*it1),abs(*(it2+1)-*it1)));
        it1++;
        it2 = lower_bound(s.begin(),s.end(),*it1);
        it2--;
        res = min(res, abs(*it1-x)+min(abs(*it2-*it1),abs(*(it2+1)-*it1)));
        cout << res << endl;
    }
}


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

/*ll gcd(ll a, ll b){
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll LCM(ll a,ll b)
{
    return (a*b)/gcd(a, b);
}*/

int main()
{
    /*
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
            cin>>a[i];

        cout<<endl;
    }*/
    char c;
    cin>>c;
    if(c>=65 && c<=90)
        cout<<"A"<<endl;
    else
        cout<<"a"<<endl;
  return 0;
}


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

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

    int n, l;
    cin >> n >> l;
    vector<int> a(n);
    int s = 0;
    rep(i, n)
    {
        a[i] = l + i;
        s += a[i];
    }
    if (a[0] * a[n - 1] <= 0)
        cout << s << endl;
    else if (a[0] > 0)
        cout << s - a[0] << endl;
    else
        cout << s - a[n - 1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

void solve(lli n, lli m, vector<tuple<lli,lli>> const &tasks) {
  priority_queue<lli> que;
  lli ans = 0;
  for (lli idx = 0, day = m - 1; day >= 0; --day) {
    while (idx < n && day + get<0>(tasks[idx]) <= m) {
      // cerr << "push " << get<0>(tasks[idx]) << "/" << get<1>(tasks[idx]) << "\n";
      que.push(get<1>(tasks[idx]));
      ++idx;
    }
    if (que.empty()) { continue; }
    // cerr << "pop " << que.top() << "\n";
    ans += que.top();
    que.pop();
  }

  cout << ans << "\n";
}

int main() {
  // cout << fixed << setprecision(10);

  lli N, M; cin >> N >> M;
  vector<tuple<lli,lli>> tasks;
  REP(i, N) {
    int A, B; cin >> A >> B;
    tasks.emplace_back(A, B);
  }
  sort(begin(tasks), end(tasks));
  solve(N, M, tasks);
  return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <string>
#include <queue>

using namespace std;

struct Tag {
    int to;
    string str;

    Tag() {}
    Tag(int to, const string &str) : to(to), str(str) {}
};

int main() {
    while(true) {
        int N, A, S, G;
        cin >> N >> A >> S >> G;
        if(!N && !A && !S && !G) break;

        vector<vector<Tag> > v(N);
        for(int i = 0; i < A; ++i) {
            Tag t;
            int x;
            cin >> x >> t.to >> t.str;
            v[x].push_back(t);
        }

        vector<string> best(N, "\xFF");
        vector<int> goalable(N, 0);
        bool noans = false;
        best[G] = "";
        goalable[G] = 1;
        for(int TURN = 0; TURN < N; ++TURN) {
            vector<string> next = best;
            for(int i = 0; i < N; ++i) {
                for(int j = 0; j < v[i].size(); ++j) {
                    const Tag &tag = v[i][j];
                    const string str = tag.str + best[tag.to];
                    if(goalable[tag.to] && str < next[i]) {
                        next[i] = str;
                        goalable[i] = 1;
                    }
                }
            }
            best = next;
        }

        bool hasloop = false;
        for(int TURN = 0; TURN < 6*N; ++TURN) {
            vector<string> next = best;
            for(int i = 0; i < N; ++i) {
                for(int j = 0; j < v[i].size(); ++j) {
                    const Tag &tag = v[i][j];
                    const string str = tag.str + best[tag.to];
                    if(goalable[tag.to] && str < next[i]) {
                        next[i] = str;
                        goalable[i] = 1;
                        if(i == S) hasloop = true;
                    }
                }
            }
            best = next;
        }       

        if(hasloop || best[S] == "\xFF") cout << "NO" << endl;
        else cout << best[S] << endl;
    }
    return 0;
}

Measured memory_bytes: 1032
n, m = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(m)]
SortedPY = sorted(PY, key=lambda x: x[1])

from collections import defaultdict
d = defaultdict(int)
memo = [1]*(n+1)
for py in SortedPY:
    p, y = py
    d[(p, y)] = memo[p]
    memo[p] += 1

for py in PY:
    p, y = py
    print(str(p).zfill(6)+str(d[(p, y)]).zfill(6))

Measured memory_bytes: 46844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

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

    ll n, m, k; cin >> n >> m >> k;
    vector<ll> a(n+1), b(m+1, 0);
    for (int i = 0; i < n; i++) cin >> a[i+1];
    for (int i = 0; i < m; i++) cin >> b[i+1];

    vector<ll> pa(n+1), pb(m+1);
    for (int i = 1; i <= n; i++) pa[i] = pa[i-1] + a[i];
    for (int i = 1; i <= m; i++) pb[i] = pb[i-1] + b[i];

    ll ans = 0;
    for (ll i = 0; i <= n; i++) {
        if (pa[i] > k) break;
        if (pa[i] == k) {
            ans = max(ans, i); continue;
        }
        auto x = upper_bound(pb.begin(), pb.end(), k-pa[i]);
        if (x == pb.begin()) ans = max(ans, i);
        else {
            --x;
            ans = max(ans, i + (x-pb.begin()));
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9540
#include <cmath>
#include <cstring>
#include <iostream>
#include <stack>
#include <stdio.h>
#include <string>
#include <map>
#include <vector>

using namespace std;

map<string,int> dict;
int getCharValue(char c){
    if(c=='A'){
        return 4;
    }else if(c=='C'){
        return 1;
    }else if(c=='G'){
        return 2;
    }else if(c=='T'){
        return 3;
    }else{
        return 0;
    }
}

int getValue(string key){
    int sum = 0;
    for(int i = 1;key[i]!='\0' ; i++){
        sum += 5*i * getCharValue(key[i]) ;
    }
    return sum;
}


void insert(string key){
    dict.insert(make_pair(key,getValue(key)));
}

void find(string key){
    map<string,int>::iterator itr = dict.find(key);
    if(itr!=dict.end()){
        printf("yes\n");
    }else{
        printf("no\n");
    }
}

int main(){
    int n;
    string command,key;
    scanf("%d",&n); 
    for(int i = 0; i < n ; i++){
        cin >> command >> key;
        if(command[0]=='i'){
            insert(key);
        }else if(command[0]=='f'){
            find(key);
        } 
    }
}




Measured memory_bytes: 36952
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    s=int(input())
    x0=10**9
    y1=(s-1)//x0+1
    x1=1
    y0=x0*y1-s
    print(0,0,x0,y0,x1,y1)
resolve()

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

using namespace std;

int main(){
  int i, n, m, x, sum;
  vector<int> data;
  vector<int>::iterator j;

  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;

    sum = 0;
    for(i=0; i<n; ++i){
      cin >> x;
      data.push_back(x);
    }

    for(i=0; i<m; ++i){
      cin >> x;
      sum += x;
      j = find(data.begin(), data.end(), x);
      if(j != data.end()) data.erase(j);
    }

    for(i=0; i<data.size(); ++i) sum += data[i];
    cout << sum << endl;
    data.clear();
  }
  return 0;
}

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

Measured memory_bytes: 600
if __name__ == "__main__":
    a , b , c = map(int,input().split())
    k = int(input())
    cnt = 0
    while b<=a:
        cnt += 1
        b *= 2
    while c<=b:
        cnt += 1
        c *= 2

    if cnt >k:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 9112
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
--import Data.Array
--import Data.Array.Unboxed
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe

-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
-- templete

f l [] = l
f l [e,p,q] = ins l (e,p*q)
  where
    ins [] w = [w]
    ins (t@(i,x):ls) t'@(i',x')
      | i==i' = (i,x+x') : ls
      | otherwise = t : ins ls t'

main = do
    n <- getInt
    when (n/=0) $ do
        map fst . filter ((>=1000000) . snd) . foldl f [] <$> replicateM n getInts >>= \res -> if null res then putStrLn "NA" else mapM_ print res
        main


Measured memory_bytes: 5668
N = int(input())
A, B = map(int, input().split())
P = list(map(int, input().split()))


def main():
    count1 = len([p for p in P if p <= A])
    count2 = len([p for p in P if p > A and p <= B])
    count3 = len([p for p in P if p > B])

    print(min([count1, count2, count3]))

if __name__ == '__main__':
    main()


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

vector<int> xs[101010], ys[101010];
bool vx[101010], vy[101010];

bool possible(int x, int y) {
    return xs[y].size() >= 2 && ys[x].size() >= 2;
}

int cntx, cnty;

void dfsy(int y);

void dfsx(int x) {
    cntx++;
    vx[x] = true;
    for (int y : ys[x]) {
        if (!vy[y]) dfsy(y);
    }
}

void dfsy(int y) {
    cnty++;
    vy[y] = true;
    for (int x : xs[y]) {
        if (!vx[x]) dfsx(x);
    }
}

long long cnt(int X, int Y) {
    cntx = 0;
    cnty = 0;
    if (!vx[X]) dfsx(X);
    if (!vy[Y]) dfsy(Y);
    return 1ll * cntx * cnty;
}

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

    int n;
    cin >> n;
    vector<int> X(n), Y(n);
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        xs[y].push_back(x);
        ys[x].push_back(y);
        X[i] = x, Y[i] = y;
    }

    long long ans = 0;
    for (int i = 0; i < n; i++) {
        if (possible(X[i], Y[i])) {
            if (!vx[X[i]]) {
                assert(!vy[Y[i]]);
                ans += cnt(X[i], Y[i]);
            }
        }
    }

    for (int i = 0; i < n; i++) {
        if (vx[X[i]] && vy[Y[i]]) ans--;
    }

    cout << ans << endl;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1LL << 60;
const int MOD = 1'000'000'007;

template <typename T>
void print(const T &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

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;
}

set<int> cand;
map<int, int> mp;

vector<pair<int, int>> factorization(int num)
{
    map<int, int> mp;

    int tmp = num;
    for (int i = 2; i * i <= num; i++)
    {
        while (tmp % i == 0)
        {
            mp[i]++;
            tmp /= i;
        }
    }
    if (tmp != 1)
    {
        mp[tmp]++;
    }
    vector<pair<int, int>> ret;
    for (auto m : mp)
    {
        ret.push_back(make_pair(m.first, m.second));
    }
    return ret;
}

void f(int a)
{
    vector<int> el;
    for (auto c : cand)
    {
        if (a % c == 0)
        {
            ++mp[c];
        }
        else
        {
            el.push_back(c);
        }
    }
    for (int e : el)
    {
        cand.erase(e);
    }
    return;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    bool flag = false;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        if (!flag)
        {
            auto fac = factorization(a);
            for (auto f : fac)
            {
                ++mp[f.first];
                if (mp[f.first] > 1)
                {
                    flag = true;
                    continue;
                }
                cand.insert(f.first);
            }
        }
        else
        {
            f(a);
        }
    }
    bool pw_flag = true;
    for (auto m : mp)
    {
        if (m.second == n)
        {
            cout << "not coprime" << endl;
            return 0;
        }
        if (m.second > 1)
        {
            pw_flag = false;
        }
    }
    if (pw_flag)
    {
        cout << "pairwise coprime" << endl;
    }
    else
    {
        cout << "setwise coprime" << endl;
    }
    return 0;
}


Measured memory_bytes: 10924
#codng utf-8
O=[i for i in input()]
E=[i for i in input()]
m=len(O)
n=len(E)
ans=''
for i in range(len(O)-1):
    ans+=O[i]
    ans+=E[i]
if len(O)-len(E)==0:
    ans+=O[n-1]
    ans+=E[n-1]
    print(ans)
else:
    ans+=O[m-1]
    print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<map>

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

const ll MAX = 1e6;

long long fac[MAX], finv[MAX], inv[MAX];
 
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//binary_libraryを貼る

ll H(ll a, ll b){
  return COM( a + b - 1, b - 1);}

int main(){
  ll N,M; cin >> N >> M; COMinit();
    if( M == 1){ cout << 1 << endl; return 0;} //全て１しかない
map<ll,ll> power;  power.clear();
    ll c = sqrt((double) M); bool flag = true; ll k = M;
    for(ll j = 2; j <= c + 1; j++){ //Mの素因数分解
      while( k % j == 0){  flag = false;k /= j; power[j]++;}}
    if( k != 1){ power[k]++;}
    if(flag){  cout << N << endl; return 0;} //M自身が素数だった
    
    ll ans = 1;
     for( auto p : power){
       if(p.second != 0){
        ans *= H(p.second,N); ans %= MOD;}
      } //map全探索を行う
    
    cout << ans << endl; return 0;}
      
  

Measured memory_bytes: 23808
#author: raghav_0901
from math import *

mod = (10**9) + 7


def _in():
    return [int(x) - 1 for x in input().split(' ')]


def main():
    n, k = [int(x) for x in input().split(' ')]
    arr, dp = _in(), [0, ]
    vis = [False] * (n)
    vis[0], nxt = True, arr[0]
    while(not vis[nxt] and len(dp) <= k):
        dp.append(nxt)
        vis[nxt] = True
        nxt = arr[nxt]
    if(len(dp) == k + 1):
        print(dp[-1] + 1)
    else:
        i = 0
        while(dp[i] != nxt):
            k, i = k - 1, i + 1
        rem = k % (len(dp) - i)
        print(dp[rem + i] + 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 33552
N, K = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in range(N):
	s = 0
	for j in range(i, N):
		s = s + a[j]
		b.append(s)
max_b = len(bin(max(b))) - 2
#print(b, max_b)
ans = 0
for i in range(max_b):
	p = 0
	c = 2 ** (max_b - 1 - i)
	#print("i=",i, "c=",c)
	for j in b:
		if (ans + c) & j == ans + c:
			#print("j=",j)
			p = p + 1
	if p >= K:
		ans = ans + 2 ** (max_b - 1 - i)
		#print("ans=",ans)
print(ans)

Measured memory_bytes: 66300
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int power(int x,int y){
	if(y == 0) return 1;
	int res = power(x * x % MOD,y / 2);
	if(y & 1) res = res * x % MOD;
	return res;
}

signed main(){
	int s,ans = 0;
	cin >> s;
	for(int i = 1;i < s;i++){
		int a = s / i,b = s % i;
		if(a >= 8){
			if(!b) ans = (ans + 9 * power(10,a - 1) % MOD - i + 1 + MOD) % MOD;
			else ans = (ans + 1) % MOD;
		}
	}
	for(int i = 1;i <= 7;i++){
		for(int j = i;j <= 8;j++){
			if(i == j){
				if(s % i == 0 && s / i <= 9 * power(10,i - 1)) ans = (ans + 9 * power(10,i - 1) % MOD - s / i + 1 + MOD) % MOD;
			}
			else{
				int cnt = 0;
				for(int k = i + 1;k < j;k++) cnt += k * 9 * power(10,k - 1);
				for(int k = 1;k * i < s - cnt && k <= 9 * power(10,i - 1);k++){
					if((s - cnt - k * i) % j == 0 && (s - cnt - k * i) / j <= 9 * power(10,j - 1)){
						ans = (ans + 1) % MOD;
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import collections

def main():
    s = list(str(input()))
    l = collections.Counter(s)
    if len(l) == 2:
        print("Second")
    else:
        if s[0] == s[-1]:
            if len(s)%2 == 0:
                print("First")
            else:
                print("Second")
        else:
            if len(s)%2 == 0:
                print("Second")
            else:
                print("First")

if __name__ == "__main__":
    main()

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

int main() {
  double n;
  cin >> n;
  double ans = n / 2;
  if (int(n)%2 != 0) ans += 0.5;
  ans /= n;
  printf("%.8lf", ans);
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


class Main
{	
	
	
	public static void main(String args[]) throws IOException
	{
		FastScanner fs = new FastScanner();
		int N = fs.nextInt()/100;
		
		switch (N)
		{
			case 4:
			case 5: System.out.println(8);
			break;
			case 6:
			case 7: System.out.println(7);
			break;
			case 8:
			case 9: System.out.println(6);
			break;
			case 10:
			case 11: System.out.println(5);
			break;
			case 12:
			case 13: System.out.println(4);
			break;
			case 14:
			case 15: System.out.println(3);
			break;
			case 16:
			case 17: System.out.println(2);
			break;
			case 18:
			case 19: System.out.println(1);
			break;
		}

			
	}


	
}
class FastScanner
{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer str = new StringTokenizer("");
	
	String next() throws IOException
	{
		while(!str.hasMoreTokens())
			str = new StringTokenizer(br.readLine());
		
		return str.nextToken();
	}
	
	int nextInt() throws IOException
	{
		return Integer.parseInt(next());
	}
	
	float nextfloat() throws IOException
	{
		return Float.parseFloat(next());
	}
	
	double nextDouble() throws IOException
	{
		return Double.parseDouble(next());
	}
	long nextLong() throws IOException
	{
		return Long.parseLong(next());
	}
	int[] arrayIn(int n) throws IOException
	{
		int arr[] = new int[n];
		for(int i=0; i<n; i++)
		{
			arr[i] = nextInt();
		}
		return arr;
	}
}



	

Measured memory_bytes: 32712
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
 private:
  vector<ll> parents;

 public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) { return root(x) == root(y); }

  bool merge(ll x, ll y) {
    if (issame(x, y)) return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry]) swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) { return -parents[root(x)]; }

 private:
  ll root(ll x) {
    if (parents[x] < 0) return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

// 配るDP
ll dp1(const vector<ll> &values, const vector<ll> &weights,
       vector<vector<ll>> &dp, ll N, ll W) {
  for (ll i = 0; i < N; i++) {
    for (ll w = 0; w < W + 1; w++) {
      if (w + weights[i] <= W) {
        dp[i + 1][w + weights[i]] =
            max(dp[i][w] + values[i], dp[i][w + weights[i]]);
      }

      dp[i + 1][w] = max(dp[i][w], dp[i + 1][w]);
    }
  }

  ll ans = 0;
  for (auto d : dp[N]) {
    ans = max(ans, d);
  }

  return ans;
}

ll dp2(const vector<ll> &values, const vector<ll> &weights,
       vector<vector<ll>> &dp, ll N, ll W) {
  for (ll i = 0; i < N; i++) {
    for (ll w = 0; w < W + 1; w++) {
      if (w - weights[i] >= 0) {
        dp[i + 1][w] = max(dp[i][w - weights[i]] + values[i], dp[i][w]);
      } else {
        dp[i + 1][w] = max(dp[i][w], dp[i + 1][w]);
      }
    }
  }

  ll ans = 0;
  for (auto d : dp[N]) {
    ans = max(ans, d);
  }

  return ans;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  ll N, W;
  cin >> N >> W;

  vector<ll> values(N);
  vector<ll> weights(N);

  for (ll i = 0; i < N; i++) {
    cin >> weights[i] >> values[i];
  }

  vector<vector<ll>> dp(N + 1, vector<ll>(W + 1, 0));

  // for (ll i = 0; i < N + 1; i++) {
  //   for (ll w = 0; w < W + 1; w++) {
  //     cout << dp[i][w] << " ";
  //   }
  //   cout << endl;
  // }

  cout << dp2(values, weights, dp, N, W) << endl;

  return 0;
}


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

typedef long long LL;
typedef pair<int, int> pii;

#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxm = 4e6 + 10;
const int maxn = 2000 + 10;

template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

LL f[maxn][maxn];
LL fac[maxm], ifac[maxm];

LL fpm(LL base, LL exp) {
    LL ans = 1;
    for(; exp > 0; exp >>= 1) {
        if(exp & 1) 
            ans = ans * base % mod;
        base = base * base % mod;
    }
    return ans;
}

LL C(int n, int m) {
    return fac[n] * ifac[m] % mod * ifac[n-m] % mod;
}
void init() {
    fac[0] = ifac[0] = 1;
    for(int i = 1; i < maxm; i++) {
        fac[i] = fac[i-1] * i % mod;
        ifac[i] = fpm(fac[i], mod-2);
    }
}

int n, k;
int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif

    n = read<int>(); k = read<int>();
    if(k == 1) return puts("1"), 0;

    init();
    f[n][n] = 1;
    for(int i = n; i >= 0; i--) {
        for(int j = n; j >= 0; j--) if(f[i][j]) {
            if(i > j) (f[i-1][j] += f[i][j]) %= mod;
            if(j > 0) (f[i][j-1] += f[i][j] * C(n-i + (n-j)*(k-1) + k-2, k-2)) %= mod;
        }
    }
    printf("%lld\n", f[0][0] * fac[n] % mod);
    return 0;
}


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m, n;
    cin >> n >> m;
    int nn = n*(n-1)/2;
    int mm = m*(m-1)/2;
    //cout << nn << " " << mm << endl;
    cout << nn + mm << endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string u;
    cin>>u;
    if(u==s) cout<<a-1<<" "<<b<<endl;
    else cout<<a<<" "<<b-1<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using std::cout ;
using std::endl ;
using std::cin ;
using std::string ;
using std::vector ;
using std::set ;
using std::map ;
using std::pair ;
#define rep(i,n) for(int i=0, i##_end=(n); i<i##_end; i++)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
template<class T>bool updateMax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool updateMin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(c) c.begin(),c.end()
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    
    int ans =
        (A >= K ? K :(A+B >= K ? A : A - (K-A-B)));
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3624
import collections
def com(x,y):
    y=min(y,x-y)
    a=1
    for i in range(x,x-y,-1):
        a*=i
    b=1
    for i in range(1,y+1):
        b*=i
    return a//b
n,m=map(int,input().split())
y=[]
i=2
z=m
while(i*i<=m):
    if m%i:
        i+=1
    else:
        m//=i
        y.append(i)
if m>1:
    y.append(m)
c=collections.Counter(y).values()
ans=1
mod=10**9+7
for t in c:
    ans*=com(t+n-1,t)
    ans%=mod
print(ans)

Measured memory_bytes: 3316
nn = int(input())
ss = str(input())
stones = list(map(str, str(ss)))
#print(stones)


numW = sum(x == 'W' for x in stones)
numR = sum(x == 'R' for x in stones)
if numW == 0:
    print('0')
elif numR == 0:
    print('0')
else:
    addrW = [0]*numW
    addrR = [0]*numR
    countW = 0
    countR = 0

    for i in range(nn):
        if stones[i] == 'W':
            addrW[countW] = i
            countW += 1
        else:
            addrR[countR] = i
            countR +=1

    ind_leftmostW = 0
    ind_rightmostR = len(stones)

    ind = 0

    while ind < min(numR,numW):
        if addrW[ind] < addrR[numR-1-ind]:
    #        stones[addrW[ind]] = 'R'
    #        stones[addrR[numR-1-ind]] = 'W'
    #        print(stones)
            ind += 1
        else:
            break

    print(ind)

Measured memory_bytes: 87884
a = int(input())
half = int(a ** .5)
for num in range(half, 0, -1):
  if a / num == int(a/num):
    if num == 1 or a/num == 1:
      print(max(a//num, num) - 1)
      break
    else:
      print(a//num + num - 2)
      break


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

using namespace std;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1000000007;

using ll = long long;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}

int main(){

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


    int n, m;
    cin >> n >> m;
    bool redexist[n];
    fill_n(redexist, n, false);
    redexist[0] = true;
    int num[n];
    fill_n(num, n, 1);

    rep(i, m){
        int x, y;
        cin >> x >> y;
        --x; --y;
        if(redexist[x]) redexist[y] = true;
        --num[x]; ++num[y];
        if(num[x] == 0) redexist[x] = false;
    }

    int cnt = 0;
    rep(i, n){
        if(redexist[i]) ++cnt;
    }

    ppp(cnt);

    return 0;
}


Measured memory_bytes: 768
S=input()
s_count = len(S)
ans = 0
for i in range(2**(s_count-1)):
  calc_str=""
  for j in range(s_count):
    calc_str = calc_str + S[j]
    if (i>>j) & 1:
      calc_str = calc_str + "+"
  ans = ans + eval(calc_str)
print(ans)

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

constexpr int SIZE = 'z' - 'a' + 1;

int main()
{
	std::string w;
	int count[SIZE];
	for (int i = 0; i < SIZE; i++)
		count[i] = 0;

	std::cin >> w;

	for (size_t i = 0; i < w.size(); i++)
		++count[w[i] - 'a'];

	bool check = true;
	for (int i = 0; i < SIZE; i++)
		if (count[i] % 2 != 0) {
			check = false;
			break;
		}

	if (check)
		std::cout << "Yes\n";
	else
		std::cout << "No\n";

	return 0;
}

Measured memory_bytes: 256