akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;

typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main(void){
    int n, m;
    cin >> n >> m;
    
    pair<int, bool> results[MAXR+1];
    REP(i, MAXR+1) {
        results[i] = make_pair(0, false);
    }
    
    REP(i, m) {
        int p;
        string s;
        cin >> p >> s;
        
        if(results[p].second) continue;
        if(s == "WA") {
            results[p].first++;
        }else {
            results[p].second = true;
        }
    }
    int ac=0, penalty=0;
    REP(i, MAXR+1) {
        if(results[i].second) {
            ac++;
            penalty += results[i].first;
        }
    }
    cout << ac << " " << penalty << endl;
    return 0;
}

Measured memory_bytes: 1024
from bisect import bisect

a, b, q = map(int, input().split())

s = [float("-inf")] + [int(input()) for _ in range(a)] + [float("inf")]
t = [float("-inf")] + [int(input()) for _ in range(b)] + [float("inf")]
xn = [int(input()) for _ in range(q)]

for x in xn:
    min_d = 0

    sx = bisect(s, x)
    tx = bisect(t, x)

    min_d = min(x - min(s[sx-1], t[tx-1]),
                max(s[sx], t[tx]) - x,
                2 * (x - s[sx-1]) + t[tx] - x,
                2 * (x - t[tx-1]) + s[sx] - x,
                2 * (t[tx] - x) + x - s[sx-1],
                2 * (s[sx] - x) + x - t[tx-1])

    print(min_d)


Measured memory_bytes: 16144
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] fluitArray = new int[n];
        for (int i = 0; i < n; i++) {
            fluitArray[i] = sc.nextInt();
        }
        Arrays.sort(fluitArray);
        int result = 0;
        for(int i = 0; i<k; i++) {
            result += fluitArray[i];
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 39064
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define M 1000000007
#define M 998244353
const int inf=4e18;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	string s;cin>>s;
	int i,n=s.length();
	if(n&1)
	{
		cout<<"No\n";
		return 0;
	}
	for(i=0;i<n;i+=2)
	{
		if(s[i]!='h'||s[i+1]!='i')
		{
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

s = input()
t = input()
ct = 0
for i in range(3):
    if s[i] == t[i]:
        ct += 1
print(ct)

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

int main(void){
  string a, b, c;
  cin >> a >> b >> c;
  if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

long long H, W, D, Q;
long long L, R;
long long d[90001];
long long px[90001];
long long py[90001];

int main(){
	cin >> H >> W >> D;
	for(long long i = 0; i < H; i++){
		for(long long j = 0; j < W; j++){
			long long tmp;
			cin >> tmp;
			//py[tmp] = i;
			//px[tmp] = j;
			py[tmp] = j;
			px[tmp] = i;
		}
	}

	//for(long long i = D + 1; i <= H*D; i++){
	//	d[i] = d[i-D] + abs(py[i] - py[i-D]) + abs(px[i] - px[i-D]);
	//}

	//cin >> Q;
	//for(long long i = 0; i < Q; i++){
	//	cin >> L >> R;
	//	cout << d[R] - d[L] << endl;
	//}

	for(int i=D+1;i<=H*W;i++)
		d[i]=d[i-D]+abs(px[i]-px[i-D])+ abs(py[i]-py[i-D]);
	scanf ("%d",&Q);
	while(Q--){
scanf ("%d%d",&L,&R);
printf ("%d\n",d[R]-d[L]);
	}
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll a, b;
  cin >> a >> b;
  if((a * b) % 2) cout << "Odd";
  else cout << "Even";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9;

int n, m;
pii A[MX];

int U[MX];
int find(int x){ return x==U[x] ? x : U[x]=find(U[x]); }
void unite(int x, int y){ U[find(y)]=find(x); }

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    iota(U, U+n, 0);
    for(int i=0; i<n; i++) cin>>A[i].first, A[i].second=i;
    for(int i=1; i<=m; i++){
        int u,v; cin>>u>>v;
        unite(u,v);
    }
    set<int> S;
    for(int i=0; i<n; i++) S.insert(find(i));
    int sz=S.size(), tot=2*sz-2, cnt[MX]={};
    ll ans=0;
    sort(A, A+n);

    if(sz==1){ cout<<"0\n"; return 0; }
    
    for(int i=0; i<n; i++){
        int x=find(A[i].second);
        if(cnt[x]==0){ ans+=A[i].first, tot--, cnt[x]++, A[i].second=-1; }
    }

    for(int i=0; i<n; i++){
        if(tot==0) break;
        int val, idx; tie(val, idx)=A[i];
        if(idx<0) continue;
        idx=find(idx);
        if(cnt[idx]>=sz-1) continue;
        ans+=val, cnt[idx]++, tot--;
    }
    if(tot>0) cout<<"Impossible\n";
    else cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>

using namespace std;

#define MAX 256

vector<int> Count(string s, int n)
{
	vector<int> cnt(MAX);

	for (int i = 0; i < n; i++)
	{
		cnt[s[i] - 'a']++;
	}

	return cnt;
}

unordered_map<int, int> CountCommon(vector<int> cnt)
{
	unordered_map<int, int> um;
	for (int i = 0; i < MAX; i++)
	{
		if (cnt[i] > 0)
		{
			um[cnt[i]]++;
		}
	}

	return um;
}

int main()
{
	string s, t;
	cin >> s >> t;

	int len = s.length();

	vector<int> cnt1 = Count(s, len);
	vector<int> cnt2 = Count(t, len);

	unordered_map<int, int> um1 = CountCommon(cnt1);
	unordered_map<int, int> um2 = CountCommon(cnt2);

	bool isPossible = true;
	for (auto it : um1)
	{
		if (um2[it.first] != it.second)
		{
			isPossible = false;
			break;
		}
	}

	if (isPossible)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 904
#include <stdio.h>

int main(){
  int n;
  while(scanf("%d",&n) != EOF){
    int i,j,k,l,count;
    count = 0;
    for(i=0;i<10;i++){
      for(j=0;j<10;j++){
        for(k=0;k<10;k++){
          for(l=0;l<10;l++){
            if(n == i+j+k+l) count++;
            }
        }
      }
    }

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

  return 0;
}
    

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>

using namespace std;

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

    char c1 = s[0];
    char c2 = s[s.size()-1];
    bool gusu = (s.size() % 2 == 0);
    cout << (gusu ^ (c1 == c2) ? "Second" : "First") << endl;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
	int a[4], b[4];
	while(cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]){
		int hit = 0, blow = 0;
		for(int i=0;i<4;++i){
			for(int j=0;j<4;++j){
				if(a[i]==b[j]){
					if(i==j) hit++;
					else blow++;
				}
			}
		}
		cout << hit << " " << blow << "\n";
	}
	return 0;
}

Measured memory_bytes: 0
using System;

namespace SmallLargeEqual
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');

            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);

            if (a > b)
            {
                Console.WriteLine("a > b");
            }
            else if (b > a)
            {
                Console.WriteLine("a < b");
            }
            else
            {
                Console.WriteLine("a == b");
            }
        }
    }
}

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

int main(){
  int a,b,c;
  cin >>a>>b>>c;
  if(a>b)
    swap(a,b);
  if(b>c)
    swap(b,c);
  if(a>b)
    swap(a,b);
  cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}



Measured memory_bytes: 3116
/* author   : mpily :-()
title : Competing.cpp
time :Sat Jan 11 09:24:52 2020

*/
#include<bits/stdc++.h>
using namespace std;
int factorial(int N){
	int ans = 1;
	while(N){
		ans*=N;
		N--;
	}
	return ans;
}	
int main(){
	int N;
	cin>>N;
	vector<int>arr(N);
	for(int i = 0; i < N; i++){
		cin>>arr[i];
	}
	map<int,int>avail;
	int pos = 0;
	for(int i = 0; i < N; i++){
		int count = 0;
		for(int j = 1; j < arr[i]; j++){
			if(!avail[j]){
				count +=1;
			}
		}
		avail[arr[i]]= 1;
		int tofact = N-(i+1);
		pos = pos + count*factorial(tofact);
	}
	vector<int>arr2(N);
	for(int i = 0; i < N; i++){
		cin>>arr2[i];
	}
	map<int,int>avail2;
	int pos2 = 0;
	for(int i = 0; i < N; i++){
		int count = 0;
		for(int j = 1; j < arr2[i]; j++){
			if(!avail2[j]){
				count +=1;
			}
		}
		avail2[arr2[i]]= 1;
		int tofact = N-(i+1);
		pos2 = pos2 + count*factorial(tofact);
	}
	cout<<abs(pos2-pos)<<"\n";
	return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d', $target);
$limit = ceil(sqrt($target));
$divs = [];
for ($i=1; $i <= $limit; $i++) { 
    if ($target % $i === 0) {
        $divs[] = $i;
    }
}
$maxDiv = max($divs);
$maxPair = $target / $maxDiv;

$ans = --$maxDiv + --$maxPair;
echo $ans."\n";

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


int main() {
    int s,w;
    cin>>s>>w;
    if(w>=s){
        cout<<"unsafe"<<endl;
    }
    else{
        cout<<"safe"<<endl;
    }
}

Measured memory_bytes: 3636
t=int(input())
nabcd=[list(map(int,input().split())) for _ in range(t)]

import sys
sys.setrecursionlimit(10**7)
import math
for n,a,b,c,d in nabcd:
  memo={0:0,1:d}
  def func(i):
    if i in memo:
      return memo[i]
    ret=math.inf
    ret=min(ret,func(i//2)+a+d*(i%2))
    ret=min(ret,func((i+2-1)//2)+a+d*((2-i%2)%2))
    ret=min(ret,func(i//3)+b+d*(i%3))
    ret=min(ret,func((i+3-1)//3)+b+d*((3-i%3)%3))
    ret=min(ret,func(i//5)+c+d*(i%5))
    ret=min(ret,func((i+5-1)//5)+c+d*((5-i%5)%5))
    ret=min(ret,d*i)
    memo[i]=ret
    return ret
  print(func(n))

Measured memory_bytes: 10944
var
  a:array[1..100000]of longint;
  b:array[1..2,1..100000]of longint;
  n,m,k,i,p,q,o,f,t:longint;
begin
  readln(n);
  for i:=1 to n do 
  begin
     read(a[i]);
	 inc(b[((i-1)mod 2)+1,a[i]]);
	 if a[i]>k then k:=a[i];
  end;
  for i:=1 to k do
  begin
     if b[1,i]>p then begin p:=b[1,i]; o:=i; end;
     if b[2,i]>q then begin q:=b[2,i]; m:=i; end;
  end;
  if o=m then 
  begin 
    if p>q then
	begin
    for i:=1 to k do
	begin
       if (i<>o)and(b[2,i]>=f) then f:=b[2,i];
    end;
	f:=f+p;
	end else
    if p<q then
	begin
    for i:=1 to k do
	begin
       if (i<>o)and(b[1,i]>=f) then f:=b[1,i];
    end;
	f:=f+q;
	end else
	begin
    for i:=1 to k do
	begin
       if (i<>o)and(b[1,i]>=f) then f:=b[1,i];
       if (i<>o)and(b[2,i]>=t) then t:=b[2,i];
    end;
	if t>f then f:=t+p
	else f:=f+p;
	end;
  end else f:=p+q;
  writeln(n-f);
end.


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

int main() {
    int q;
    cin >> q;
    int n = 100001;
    bool eratos[n];
    rep(i,n) eratos[i] = true;
    eratos[0] = false;
    eratos[1] = false;
    int j;
    rep(i,n) {
        if (eratos[i]) {
            j = i + i;
            while (j < n) {
                eratos[j] = false;
                j += i;
            }
        }
    }

    int dp[n+1];
    dp[0] = 0;
    rep(i,n) {
        dp[i+1] = dp[i];
        if (eratos[i] && eratos[(i+1)/2]) dp[i+1]++;
    }

    int l, r;
    vector<int> ans(q);
    rep(i,q) {
        cin >> l >> r;
        ans[i] = dp[r+1] - dp[l];
    }
    rep(i,q) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    vector<vector<int>> g(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> ans(n,-1);
    queue<int> que;
    que.push(0);
    while(!que.empty()){
        int v=que.front();
        que.pop();
        for(auto to:g[v]){
            if(ans[to]!=-1) continue;
            ans[to]=v;
            que.push(to);
        }
    }
    bool flag=true;
    FOR(i,1,n) if(ans[i]==-1) flag=false;
    if(flag){
        cout<<"Yes"<<endl;
        FOR(i,1,n) cout<<ans[i]+1<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 10176
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0 ; i < N ; i++) A[i] = sc.nextInt();
		Arrays.sort(A);
		long ans = 1;
		int cnt = 0;
		for(int i = N - 1 ; i > 0 ; i--) {
			if(A[i] == A[i - 1]) {
				ans *= A[i];
				i--;
				cnt++;
			}
			if(cnt >= 2) {
				System.out.println(ans);
				return;
			}
		}
		System.out.println(0);
	}
}

Measured memory_bytes: 50804
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(const auto& x : c )cout << x << " "; cout << "\n";
#define ol(c, s, e) for(int pos=s; pos<e; pos++)cout << c[pos] << " ";cout <<"\n";
#define PI acos(-1LL)

const int M = 1000000007;
const int N = 2e5 + 5;
const long long INF = 1e9 + 12;

vector<vector<int>> v;
int n, weight;
int dp[105][N];

//fun returns the minimum weight of items with total value exactly i;
int fun(int i, int val){
    if(val == 0 )
        return 0;
    if(val < 0 || i <= 0)
        return INF;
    if(dp[i][val]!=-1)
        return dp[i][val];
    return dp[i][val] = min(fun(i-1,val), fun(i-1, val-v[i][1])+v[i][0]);
}
void solve() {
    cin >> n >> weight;
    v.resize(n+1, vector<int>(2));
    memset(dp, -1, sizeof dp);
    int sum = 0;

    for(int i=1; i<=n; i++) {
        cin >> v[i][0] >> v[i][1];
        sum+=v[i][1];
    }
    int ans = 0;
    for(int i=1; i<=sum; i++){
        int minWt = fun(n,i);
        if(minWt <= weight)
            ans = i;
    }
    cout << ans << endl;
}

signed main(){
    FAST
    int tc = 1;
//    TODO: check for tc
//    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        solve();
    }
}


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

int main(){
  vector<int>a(10000);
  for(int i = 0; i<10000; i++){
    cin >> a.at(i);
    if(a.at(i)==0) break;
  }
  for(int i = 0; i<a.size(); i++){
    if(a.at(i) == 0) break;
    cout << "Case " << i+1 << ": " << a.at(i) << endl;
  }
}


Measured memory_bytes: 3044
##ABC 058
o = list(input())
e = list(input())

ans=[]

for i in range(min(len(o),len(e))):
    ans.append(o[0])
    o.pop(0)
    ans.append(e[0])
    e.pop(0)
               
print(''.join(ans)) if((o+e) == []) else print(''.join(ans+o+e))

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

int main() {
  int N;
  cin>>N;
  if(N%1000==0||N%1000==111||N%1000==222||N%1000==333||N%1000==444||N%1000==555||N%1000==666||N%1000==777||N%1000==888||N%1000==999){
  cout<<"Yes"<<endl;
  }
  else if((N-N%10)/10==111||(N-N%10)/10==222||(N-N%10)/10==333||(N-N%10)/10==444||(N-N%10)/10==555||(N-N%10)/10==666||(N-N%10)/10==777||(N-N%10)/10==888||(N-N%10)/10==999){
  cout<<"Yes"<<endl;
  }
  else {
  cout<<"No"<<endl;
  }
  }

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int h,w,i,j;
    while(1)
        {
    scanf("%d %d",&h,&w);
    if(h==0 && w==0)
    {break;}
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            printf("#");
        }
        printf("\n");
    }
        printf("\n");
    }
}



Measured memory_bytes: 2084
s=input()
if len(s)==1:
  if s in {"R","U","D"}:
    print("Yes")
  else:
    print("No")
  exit()
o=set(s[::2])
e=set(s[1::2])
for n in o:
  if n not in {"R","U","D"}:
    print("No")
    exit()
for f in e:
  if f not in {"L","U","D"}:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 3064
from operator import itemgetter

N = int(input())
AB = []
for i in range(N):
  list_ = list(map(int, input().split()))
  AB.append(list_)

AB.sort(key=itemgetter(1))

ans = "Yes"
a = 0
b = 0
for i in range(N):
  a += AB[i][0]
  if a > AB[i][1]:
    ans = "No"
    break
    
print(ans)

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

int main()
{
  int n;
  cin>>n;
  if(n%1000==0){
    cout<<0<<"\n";
    return 0;
  }
  int no = 1000-(n)%1000;
  cout<<no<<"\n";
  return 0;
}
  


Measured memory_bytes: 3672
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#include<chrono>
#include<random>
#include<iostream>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
#define VI vector<int>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=5005;
const int mod=1e9+7;
int pow_mod(int a,int b)
{
	int ret=1;
	for(;b;b>>=1,a=1LL*a*a%mod)if(b&1)ret=1LL*ret*a%mod;
	return ret;
}
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
void dl(int &x,int y){x-=y;if(x<0)x+=mod;}
int rt[MAXN],sz[MAXN],n,p[MAXN],flg[MAXN];
int findrt(int x){return rt[x]==x?rt[x]:rt[x]=findrt(rt[x]);}
void merge(int x,int y)
{
	if((x=findrt(x))==(y=findrt(y)))return ;
	rt[x]=y;sz[y]+=sz[x];
}
vector<int> vec;
int f[MAXN][MAXN],suf[MAXN];
int main()
{
	#ifdef Rose
		double BeginJudgeTime=clock();
	#endif
	n=read();
	for(int i=1;i<=n;i++)rt[i]=i,sz[i]=1;
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		p[i]=read();
		if(p[i]!=-1)merge(i,p[i]);
		else ++cnt;
	}
	int ans=1LL*n*pow_mod(n-1,cnt)%mod;vec.emplace_back(0);
	for(int i=1;i<=n;i++)if(p[i]==-1)vec.emplace_back(sz[findrt(i)]),flg[findrt(i)]=1;
	suf[SZ(vec)]=1;for(int i=SZ(vec)-1;i>=1;i--)suf[i]=1LL*suf[i+1]*(n-1)%mod;
	for(int i=1;i<=n;i++)if(rt[i]==i&&!flg[i])
		dl(ans,suf[1]);
	f[0][0]=1;
	for(int i=1;i<SZ(vec);i++)
		for(int j=0;j<i;j++)if(f[i-1][j])
		{
			ad(f[i][j],1LL*f[i-1][j]*(n-1)%mod);
			ad(f[i][j+1],1LL*f[i-1][j]*vec[i]%mod);
			if(j)ad(f[i][j],1LL*f[i-1][j]*(2*j*vec[i])%mod);
			if(j-1>0)ad(f[i][j-1],1LL*f[i-1][j]*(j*(j-1)*vec[i])%mod);
			if(j==1)
			{
				int coef=1LL*f[i-1][j]*vec[i]%mod;
				dl(ans,1LL*coef*suf[i+1]%mod);
			}
		}
	for(int i=1;i<SZ(vec);i++)dl(ans,1LL*suf[2]*(vec[i]-1)%mod);
	pr2(ans);
	#ifdef Rose
		double EndJudgeTime=clock();
		cerr<<"JudgeTime is"<<" ";
		cerr<<(EndJudgeTime-BeginJudgeTime)/CLOCKS_PER_SEC<<endl;
	#endif
	return 0;
}


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

int n, w;
int vi[105];
long long wi[105];
long long dp[105][100005];

void solve(){
	for (int i = 0; i <= n; i++) for (int j = 0; j <= 100000; j++) dp[i][j] = 1e15;
	dp[0][0] = 0;
	for (int i = 1; i <= n; i++){
		dp[i][0] = 0;
		for (int j = 1; j <= 100000; j++){
			dp[i][j] = min(dp[i][j],dp[i-1][j]);
			if (j >= vi[i])
				dp[i][j] = min(dp[i][j], dp[i-1][j - vi[i]] + wi[i]);
		}
	}
	for (int i = 0; i <= 100000; i++){
		if (dp[n][100000-i] <= w){
			cout << 100000-i << '\n';
			return;
		}
	}
}
int main(){
	cin >> n >> w;
	for (int i = 1; i <= n; i++)
		cin >> wi[i] >> vi[i];
	solve();
	return 0;
}


Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
template <class T> T input() {T t; cin>>t; return t;}
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define CHMAX(a,b) a = max(a,b)
#define CHMIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define newline putchar('\n')
#define cspace ' '
#define sspace " "
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;
const VI dx = {1, 0, -1, 0};
const VI dy = {0, 1, 0, -1};

class UnionFindTree {
public:
    int size;
    vector<int> rank, p;

    UnionFindTree() {}

    UnionFindTree(int num) {
        size = num;
        rank.resize(size, 0);
        p.resize(size, 0);
        for (int i = 0; i < size; ++i) {
            makeSet(i);
        }
    }

    void makeSet(int x)
    {
        p[x] = x;
        rank[x] = 0;
    }

    bool same(int x, int y)
    {
        return findSet(x) == findSet(y);
    }

    void unite(int x, int y)
    {
        link(findSet(x), findSet(y));
    }

    void link(int x, int y)
    {
        if (rank[x] > rank[y]) {
            p[y] = x;
        } else {
            p[x] = y;
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
    }

    int findSet(int x)
    {
        if (x != p[x]) {
            p[x] = findSet(p[x]);
        }
        return p[x];
    }

    int maxUnion()
    {
        int r = 0;
        map<int, int> mp;
        REP(i,size) {
            mp[findSet(i)]++;
        }
        REPITR(itr,mp) {
            r = CHMAX(r, itr->e2);
        }
        return r;
    }
};

int main()
{
    int n, m, ans = 0;
    cin>>n>>m;
    VI a(m), b(m);
    REP(i,m) cin>>a[i]>>b[i];
    REP(i,m) {
        UnionFindTree uf(n);
        REP(j,m) {
            if (i != j) {
                uf.unite(a[j]-1, b[j]-1);
            }
        }
        if (uf.maxUnion() != n) {
            ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 int main(){
   int N;cin>>N;
   string S;cin>>S;
   for(int i=0;i<S.size();i++){
       S[i]+=N;
       if(S[i]>('A'+25))S[i]-=26;

   }
   cout<<S<<endl;

    }
        






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

int main() {
  int n, k, d = 0;
  string s;
  cin >> n >> k >> s;
  for(int i = 1; i < n; i++){
    if(s.at(i-1)!= s.at(i))
      d++;
  }
  if(k >= (d+1)/2)
    cout << n-1 << endl;
  else
    cout << n-d-1+2*k << endl;
}


Measured memory_bytes: 512
import sys
h, w = list(map(int, input().split()))

if h == 1 or w == 1:
    print(1)
    exit()
tmp = h * w
if (tmp % 2) == 0:
    a = tmp // 2
    print(a)
else:
    a = tmp // 2
    b = a + 1
    print(b)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define Toggle(n,i) (n^(1<<i))
#define Check(n,i) (n&(1<<i))
#define Set(n,i) (n|(1<<i))
#define Reset(n,i) (n&(~(1<<i)))
#define fo(a,x,y) for(int i=(x);i<=(y);++i){cout<<a[i]<<" ";}cout<<endl;
#define me(arr,val) memset(arr,val,sizeof arr)
#define inf 10e8
#define infd DBL_MAX
#define infl 10e17
#define mod 1000000007ll
#define f first
#define s second
#define  g(t,a)  (get<a>(t))
#define pra(a) for(auto i:a){cout<<i<<endl;}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
//int dx[]={+1,-1,0,0};//vertical horizontal
//int dy[]={0,0,+1,-1};//vertical horizontal
//int dx[]={+1,+1,-1,-1,+2,-2,+2,-2};//knights move
//int dy[]={+2,-2,+2,-2,+1,+1,-1,-1};//knights move
//int dx[]={+1,-1,0,0,+1,+1,-1,-1};//vertical horizontal diagonal
//int dy[]={0,0,+1,-1,-1,+1,+1,-1};//vertical horizontal diagonal
using namespace std;
using namespace __gnu_pbds;
/*typedef tree<int, null_type,less<int>, rb_tree_tag,
             tree_order_statistics_node_update>indexed_set;
for set use above*/
typedef tree<pair<int,int>, null_type,less<pair<int, int>>, rb_tree_tag,
tree_order_statistics_node_update> indexed_multiset;
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}
template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
    os << "[";
    typename multiset< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}
template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}
#define pr(x) cerr << #x << " = " << x << endl;

int main()
{
    ll n,ans=0;
    cin>>n;
    for(ll i=1;i<=n-1;++i)
    {
        ans+=(n-1)/i;
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int  main(){
 int a;
 cin >> a;
 vector<string> s(a);
 int d = 0;
 int flag = 0;
 int yon = 0;
 rep(i,a){
   cin >> s[i];
 }
 sort(s.begin(),s.end());
 rep(i,a){
  if(s[i]!=s[i+1]){
     yon ++;
  }
 }
 cout << yon << endl;
return 0;
}

Measured memory_bytes: 9604
#include <stdio.h>
int main()
{
  int a,b,c,sa;
  int i,j=0;
  scanf("%d%d%d",&a,&b,&c);
 

  for(i=b;i>=a;i--){
    if(c%i==0)j++;
  }
  printf("%d\n",j);
  return 0;
}

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

#define int long long int
#define float long double
#define pb push_back
#define fi first
#define se second
#define vii vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define pq priority_queue<int>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) int a[n+f];for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define prdec(k) cout<<fixed<<setprecision(k);
#define mem(a,k) memset(a,k,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define mii map<int,int>
#define all(v) v.begin(),v.end()
#define inf LLONG_MAX
int exp(int x,int y,int mod){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x,int mod){return exp(x,mod-2,mod);}


signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int aa=a*c;
	int bb=a*d;
	int cc=b*c;
	int dd=b*d;
	cout<<max({aa,bb,cc,dd});
	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 10000000000

#define rep(i,n) for(i=0,i<n,i++)
typedef pair<int,int> pii;
int i,j;

int main() {
  int n;
  cin>>n;
  if(n==0)
    cout<<"1"<<endl;
  else if(n==1)
    cout<<"2"<<endl;
  else if(n==2)
    cout<<"1"<<endl;
  else
    cout<<"0"<<endl;
  return 0;
}

Measured memory_bytes: 3048
/*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog oi.ender-zzm.pro
*/
#include <bits/stdc++.h>
using namespace std;

template<class T>
inline void read(T &a) {
    register T x = 0, flag = 1;
    register char ch;
    while (!isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), isdigit(ch = getchar()));
    a = x * flag;
}

template <class T>
inline void write(T x) {
    if (x < 0)
        putchar('-'), x = -x;
    if(x >= 10) write(x / 10); 
    putchar(x % 10 + '0');
}

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define For(i, a, b) for (int i = (a); i <= (b); i++) 
#define Rep(i, a, b) for (int i = (a); i >= (b); i--) 
#define For_edge(x) for (int i = head[x]; i; i = net[i])
#define mem0(a) memset(a, 0, sizeof a)

string a, b;
int main() {
	cin >> a >> b;
	int n = a.size(), m = b.size();
	if (n >= m) {
		printf("No"); return 0;
	}
	For (i, 0, n - 1) {
		if (a[i] != b[i]) {
			printf("No\n"); return 0;
		}
	}
	printf("Yes");
	return 0;
}


Measured memory_bytes: 3684
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val s = sc.nextLine()
    var ans = 0
    var streak = 0
    for (i in 0 until 3) {
        if (s[i] == 'R') {
            streak++
        } else {
            ans = maxOf(ans, streak)
            streak = 0
        }
    }
    ans = maxOf(ans, streak)
    println(ans)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 34308
#include <stdio.h>

int main(void)
{
	int a,b,r;
	char o;
	while(1){
		scanf("%d %c %d",&a,&o,&b);
		if(o=='?') break;
		if(o=='+') r=a+b;
		if(o=='-') r=a-b;
		if(o=='*') r=a*b;
		if(o=='/') r=a/b;
		printf("%d\n",r);
	}
	return 0;
}

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

typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define debug(x) cerr << #x << ": " << x << '\n'

int main()
{
    ll N;
    cin >> N;
    vector<string> S(N);
    vector<ll> t(N);
    string X;
    for (int i = 0; i < N; ++i)
    {
        cin >> S[i] >> t[i];
    }
    cin >> X;
    bool add = false;
    ll ans = 0;

    for (int i = 0; i < N; ++i)
    {
        if (add)
        {
            ans += t[i];
        }
        if (S[i] == X)
        {
            add = true;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>

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

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<int, int> pi;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    int digit = n % 10;
    if(digit == 3){
        cout << "bon" << endl;
    }else if(digit == 0 or digit == 1 or digit == 6 or digit == 8){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }
    return 0;
}


Measured memory_bytes: 3660
use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();

    let s = input.trim().parse::<i32>().unwrap();
    let (m, s) = (s / 60, s % 60);
    let (h, m) = (m / 60, m % 60);
    println!("{}:{}:{}", h, m, s);
}



Measured memory_bytes: 5032
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b,c = INTM()
    if a<=c and c<= b:
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    do()

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

int main(){
  long long T1, T2, A1, A2, B1, B2;
  cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
  long long v1 = A1-B1, v2 = A2-B2;
  long long ans;
  if(v1 > 0 && v2 > 0) ans = 0;
  else if(v1 < 0 && v2 < 0) ans = 0;
  else if(v1*T1 == -v2*T2) ans = -1;
  else{
    if(v1 < 0) v1 *= -1, v2 *= -1;
    if(v1*T1 > -v2*T2) ans = 0;
    else{
      long long posFirst = v1*T1;
      long long dif = v1*T1 + v2*T2;
      if(dif < 0) dif *= -1;
      ans = posFirst/dif*2 + 1;
      if(posFirst % dif == 0) ans -= 1;
    }
  }
  if(ans == -1) cout << "infinity" << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 256
#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>;

template <class _T> inline bool chmax (_T& a,_T b){if(a<b){a=b;return true;}return false;}
template <class _T> inline bool chmin (_T& a,_T b){if(a>b){a=b;return true;}return false;}

const long long INF = 1LL << 60;


int main(void){
	int n,m;
	cin >> n >> m;
	vector<int> a(n);
	int sum=0;
	for(int i=0;i<n;i++){
		int b;cin >> b;
		sum += b;
		a.push_back(b);
	}
	sort(a.rbegin(),a.rend());
	bool flag = true;
	for(int i=0;i<m;i++){
		if(a[i]*4*m<sum){
			flag = false;
		} 
	}
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		List<Integer> l = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			l.add(scanner.nextInt());
		}

		Collections.sort(l);
		Collections.reverse(l);

		int ans = 0;
		for (int i = 0; i < k; i++) {
			ans += l.get(i);
		}

		System.out.println(ans);
	}
}


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

const int64_t MOD = 1e9+11;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
        A[i] = min(A[i], K);
    }
    static int64_t dp[10000];
    dp[0] = 1;
    for(int i=0; i<N; i++) for(int j=2*K-1-A[i]; j>=0; j--) add(dp[j+A[i]], dp[j]);
    int ans = 0;
    for(int i=0; i<N; i++){
        for(int j=0; j<=2*K-1-A[i]; j++) add(dp[j+A[i]], MOD-dp[j]);
        bool noneed = true;
        for(int j=K-A[i]; j<K; j++) if(dp[j]) noneed = false;
        if(noneed) ans++;
        for(int j=2*K-1-A[i]; j>=0; j--) add(dp[j+A[i]], dp[j]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
N = input()
K = int(input())

# dp[is未満][K][桁]
dp = [[[0] * len(N) for _ in range(K+1)] for _ in range(2)]
dp[0][0][0] = 0
dp[1][0][0] = 1
dp[0][1][0] = 1
dp[1][1][0] = max(0,int(N[0])-1)

man_k = 1
for i in range(1, len(N)):
    n = N[i]
    is_nonzero = 1 if n != '0' else 0
    man_k += is_nonzero
    if man_k <= K:
        dp[0][man_k][i] = dp[0][man_k-is_nonzero][i-1]

    dp[1][0][i] = dp[1][0][i-1]
    for k in range(1,K+1):
        dp[1][k][i] = dp[1][k][i-1] + dp[1][k-1][i-1] * 9 # n==0のパターンとn!=0のパターン
        if n != "0":
            dp[1][k][i] += dp[0][k-1][i-1] * (int(n)-1) + dp[0][k][i-1] 

print(dp[0][K][-1] + dp[1][K][-1]) 

Measured memory_bytes: 9224
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int a[200005];
int main()
{
    ll n,m,i,j,t;
    while(cin>>n)
    {
        for(i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        ll ans=0;
        for(i=1;i<n;i++)
        {
            if(a[i]>a[i+1])
            {
                ans+=a[i]-a[i+1];
                a[i+1]=a[i];
            }

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


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

int main(){
int a[30];
int b[28];
int c;
c=0;
while(c<28){
cin >> b[c];
c=c+1;}
c=0;
while(c<30){
a[c]=0;
c=c+1;}
c=0;
while(c<28){
a[b[c]-1]=1;
c=c+1;}
c=0;
while(c<30){
if(a[c]==0){cout << c+1 <<endl;}
c=c+1;
}
}

Measured memory_bytes: 1160
(*
ocamlfind ocamlopt -package batteries -linkpkg main.ml -o a.out
*)
open Batteries

let lst =
        Scanf.sscanf (read_line ()) "%d" (
                fun _ -> 
                        Str.split (Str.regexp " ") (read_line ())
                        |> List.map int_of_string
                        |> List.sort (fun a b -> - compare a b)
        )

let rec f lst =
        match lst with
                [] -> 0
                | first :: second :: rest -> 
                        (first - second) + f rest
                | first :: rest -> 
                        first + f rest

let () = 
        abs (f lst)
      |> Printf.printf "%d\n"


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


int main() {
    int N;
    cin >> N;
    vector<pair<ld,string>> V(N);
    rep(i,N) {
        cin >> V[i].first >> V[i].second;
    }
    ld ans = 0;
    rep(j,N) {
        if (V[j].second == "BTC") {
            ans += V[j].first*380000.0;
        }
        else {
            ans += V[j].first;
        }
    }
    cout << fixed << setprecision(10);
    cout << ans << endl;
}


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

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

int h, w;
vector<string> s;
vector<vector<bool>> visited;

void dfs(int y, int x, char c) {
  if(y < 0 || y >= h || x < 0 || x >= w || visited[y][x] || c != s[y][x]) return;
  visited[y][x] = true;

  for(int i = 0; i < 4; ++i) dfs(y + dy[i], x + dx[i], c);
}

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

  while(cin >> h >> w, h != 0 && w != 0) {
    s = vector<string>(h);
    visited = vector<vector<bool>>(h, vector<bool>(w, false));
    for(int i = 0; i < h; ++i) cin >> s[i];

    int cnt = 0;
    for(int i = 0; i < h; ++i) {
      for(int j = 0; j < w; ++j) {
        if(!visited[i][j]) {
          dfs(i, j, s[i][j]);
          cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
}


Measured memory_bytes: 3900
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC081_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int count = S.Count(s => s.Equals('1'));

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 26180
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>
#include <queue>
using namespace std;
typedef long long LL;
const LL N = 1000000007;

LL n;
LL a[200005];
LL pre[200005] = {0};
LL fac[200005],inv[200005];
LL pls[200005] = {0};
LL ans = 0;

LL kpw(LL x,LL y){
	LL ans = 1,tmp = x;
	while(y){
		if(y & 1) ans = (ans * tmp) % N;
		tmp = (tmp * tmp) % N;
		y >>= 1;
	}
	return ans;
}

LL comb(LL x,LL y){
	return (((fac[x] * inv[y]) % N) * (inv[x - y]) % N);
}

int main(){
	ios::sync_with_stdio(false);
	fac[0] = 1;
	for(LL i = 1;i <= 200000;i ++) fac[i] = (fac[i - 1] * i) % N;
	for(LL i = 0;i <= 200000;i ++) inv[i] = kpw(fac[i],N - 2);
	
	cin >> n;
	for(LL i = 1;i <= n;i ++) cin >> a[i];
	sort(a + 1,a + 1 + n);
	for(LL i = 1;i <= n;i ++) pre[i] = (pre[i - 1] + a[i]) % N;
	
	LL tot = 0;
	
	for(LL i = 1;i <= n;i ++){
		ans += ((((pre[n] * comb(n,i)) % N) * i) % N) * kpw(n,N - 2);
		ans %= N;
	}
	
	pls[1] = 1; pls[0] = 0;
	for(LL i = 2;i <= n;i ++){
		pls[i] = pls[i - 1] * 2 + kpw(2LL,i - 1);
		pls[i] %= N;
	}
	
	for(LL i = 1;i <= n;i ++){
		ans += ((pls[n - i] * a[i]) % N) * kpw(2LL,i - 1);
		ans %= N;
	}
	ans *= kpw(2LL,n); ans %= N;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8064
#include<stdio.h>
int main(void)
{
	int s;
	int count=2;
	int i,j,k;

	scanf("%d",&s);

	if(s==1){
		count=4;
	}else if(s==2){
		count=4;
		s=1;
	}
	

	for(i=0;s!=1;i++){
		count++;
		if(s%2==0){
			s=s/2;
			/*printf("%d\n",s);*/
		}else{
			s=3*s+1;
         /*   printf("%d\n",s);*/
  		}
	}

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

	return 0;
}

Measured memory_bytes: 128
/*Code by Codercjh*/
#include<bits/stdc++.h>
#define fr(i,a,b) for(int i=(a);i<=(b);++i)
#define rf(i,a,b) for(int i=(a);i>=(b);--i)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
using namespace std;
typedef long long ll;
template<typename T>
inline void read(T &x){
	char c=getchar();T fh=0;bool f=false;
	while(!isdigit(c))f|=(c=='-'),c=getchar();
	while(isdigit(c))fh=(fh<<1)+(fh<<3)+(c^48),c=getchar();
	x=f?-fh:fh;
	return;
}
char s[100005];
const int mod=1e9+7;
ll p3[100005];
int main(){
    scanf("%s",s+1);
    int n=strlen(s+1);
    p3[0]=1;
    fr(i,1,n)p3[i]=(p3[i-1]*3)%mod;
    ll ans=p3[n],tmp=1;
    fr(i,1,n)
    	if(s[i]=='0')
    		ans=((ans-tmp*2*p3[n-i])%mod+mod)%mod;
		else
		    tmp=(tmp*2)%mod;
	printf("%lld\n",ans%mod);
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

ll dp[105][100005];

int main(void){
  ll N, W;
  cin >> N >> W;
  vector<ll> w(N), v(N);
  REP(i, N) cin >> w[i] >> v[i];
  REP(i, N){
    REP(j, W){
      chmax(dp[i+1][j], dp[i][j]);
      if(j+w[i] <= W)chmax(dp[i+1][j+w[i]], dp[i][j]+v[i]);
    }
  }
  ll ans = 0;
  REP(i, W+1) chmax(ans, dp[N][i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 81616
#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(){
  
  int N, K;
  cin >> N >> K;
  
  vector<ll>A(200010);
  
  rep(i,N)cin >> A[i];
  
  ll ans = A[0];
  
  for(int i = 1; i < K; i++){
    ans += A[i];
  }
  
  //ここまでで初期値がきまった
  
  //K+1学期からの評点を比較
  
  ll now = 0;
  
  for(int i = K; i <N; i++){
    now = ans;
    ans -= A[i - K];
    ans += A[i];
    
    if(ans > now)cout << "Yes" << endl;
    else cout << "No" << endl;
    
    
  }
  return 0;
  
}

Measured memory_bytes: 4768
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-10;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
char in[110];
int main(){
	scanf("%s",in);
	int ret=99999;
	for(int i=0;i<26;i++){
		char c='a'+i;
		int tmp=0;
		int con=0;
		for(int j=0;in[j];j++){
			if(in[j]==c)con=0;
			else con++;
			tmp=max(tmp,con);
		}
		ret=min(ret,tmp);
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
  int n,s,m,i;
  while(scanf("%d",&n),n){
    for(i=s=0;i<n*(n-1)/2;i++){
      scanf("%d",&m);
      s+=m;
    }
    printf("%d\n",s/(n-1));
  }
  return 0;
}

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

using Graph = vector<vector<int>>;

int main(){
  int n;
  cin>>n;
  Graph G(n);
  for(int i=0;i<n-1;++i){
    int a;
    cin>>a;
    --a;
    G[a].push_back(i+1);
  }

  for(int i=0;i<n;++i) cout<<G[i].size()<<endl;
}

Measured memory_bytes: 14344
import heapq
N,M=map(int,input().split())
A=list(map(lambda x: int(x)*(-1),input().split()))
heapq.heapify(A)
for x in range(M):
  t=(-1)*heapq.heappop(A)
  heapq.heappush(A,(-1)*(t//2))
print(-1*sum(A))

Measured memory_bytes: 20452