akhauriyash/Code-Regression huggingface dataset:
N=int(input())
S=input()

def cumsum_arr(s, w):
  arr=[]
  cnt=0
  for s_ in s:
    if s_==w: cnt+=1
    arr.append(cnt)
  return arr

w=cumsum_arr(S,      'W')
e=cumsum_arr(S[::-1],'E')
e=e[::-1]
ans=[w[i]+e[i]-1 for i in range(N)]
print(min(ans))

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

int main(){
	int N, K;
  	cin >> N >> K;
    
  	vector<int> A(N);
  	for(int i = 0;i < N;i++){
    	cin >> A.at(i);
 	    A[i]++;
    }
	
  	int mx = 0;
  	int s = 0;
  	queue<int> q;
  for(int i = 0;i < N;i++){
  	s += A[i];
    q.push(A[i]);
    if(q.size() > K){
    	s -= q.front();
      	q.pop();
    }
    if(q.size() == K){
    	mx = max(mx, s);
    }
  }
  
  double ans = mx;
  ans /= 2;
  
  printf("%.10f\n",ans);
}

Measured memory_bytes: 1792
#include<iostream>
int n,m,i,d,p,z;
main(){
  while(std::cin>>n>>m,n){
    int x[11]={};
    for(z=i=0;i++<n;x[p]+=d,z+=d*p)std::cin>>d>>p;
    for(i=10;i>=0;--i)
      if(x[i]<m)z-=x[i]*i,m-=x[i];
      else if(x[i])z-=i*m,m=0;
    std::cout<<z<<'\n';
  }
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll a[1000000];
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        

fast();
//ll t;cin>>t;while(t--)
{
  ll n,m,pen=0,crc=0;
  cin>>n>>m;

 
  for(int i=0;i<1000000;i++)
  {
    a[i]=0;
  }
  
  for(int i=1;i<=m;i++)
  {
    string s;
    ll p;
    cin>>p>>s;

    if(a[p]==1&&(s=="AC"||s=="WA"))
    {
      continue;
    }
    else if(a[p]<=0&&s=="WA")
    {
         a[p]--;
    }
    else if(a[p]<=0&&s=="AC")
    {
      pen+=(abs(a[p]));
      a[p]=1;
      crc++;
    }

  }
  cout<<crc<<" "<<pen<<endl;
    
}
return 0;
}

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

using namespace std;

int main() {
	int a, b,c,ans=0;
	cin >> a>>b>>c;
	if (a != b)ans++;
	if (b != c)ans++;
	if (a != c)ans++;
  if(a==b&&b==c)ans++;
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	while(a>0&&c>0)
	{
		c=c-b;
		if(c<=0)
		break;
		a=a-d;
		if(a<=0)
		break;
	}
	if(a<=0)
	printf("No");
	if(c<=0)
	printf("Yes");
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


const int MAX = 510000;
const int MOD = 1000000007;

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

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

  COMinit();

  int tate = h - a - 1;
  LL ans = 0;
  REP (i, w - b) {
    int yoko = b + i;
    ans = (ans + COM(tate + yoko, tate) * COM(a - 1 + w - b - i - 1, a - 1) % MOD) % MOD;
  }
  cout << ans << endl;
}


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

int main(){
    long long n;
    cin >> n;
    vector<long long> A(n);
    REP(i, n) cin >> A[i];

    map<long long, long long> mp;

    vector<long long> B(n + 1);
    B[0] = 0; mp[0]++;
    long long tmp = 0;
    REP(i, n){
        B[i + 1] = A[i] + tmp;
        tmp = B[i + 1];
        mp[B[i + 1]]++;
    }

    long long cnt = 0;
    for(auto x : mp){
        cnt += x.second * (x.second - 1) / 2;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (ll (i) = (s); (i) < (e); ++(i))
#define per(i, s, e) for (ll (i) = (s); (i) >= (e); --(i))
#define all(x) x.begin(),x.end()

bool update_right(vector<ll> &c, ll i, ll h, ll w, vector<ll> &que) {
  if ((i+1) % w == 0) return false;
  if (c[i+1] != 0) return false;
  c[i+1] = c[i] + 1;
  que.push_back(i+1);
  return true;
}

bool update_left(vector<ll> &c, ll i, ll h, ll w, vector<ll> &que) {
  if (i % w == 0) return false;
  if (c[i-1] != 0) return false;
  c[i-1] = c[i] + 1;
  que.push_back(i-1);
  return true;
}

bool update_bottom(vector<ll> &c, ll i, ll h, ll w, vector<ll> &que) {
  if (i >= (h-1)*w) return false;
  if (c[i+w] != 0) return false;
  c[i+w] = c[i] + 1;
  que.push_back(i+w);
  return true;
}

bool update_upper(vector<ll> &c, ll i, ll h, ll w, vector<ll> &que) {
  if (i < w) return false;
  if (c[i-w] != 0) return false;
  c[i-w] = c[i] + 1;
  que.push_back(i-w);
  return true;
}

ll eval(vector<ll> &c, ll i, ll h, ll w, vector<ll> &que) {
  bool flag = update_right(c, i, h, w, que) | update_left(c, i, h, w, que) |
              update_bottom(c, i, h, w, que) | update_upper(c, i, h, w, que);
  if (!flag) {
    return c[i]; 
  }
  ll res = c[i];
  while(que.size() > 0) {
    //cout << "que = " << que[0] << endl;
  	ll index = que[0];
  	que.erase(que.begin());
  	res = max(res, eval(c, index, h, w, que));
  }
  return res;
}


int main(void) {
  ll h, w;
  cin >> h >> w;
  vector<char> s(h*w);
  vector<ll> cost(h*w), cost_tmp(h*w);
  rep(i, 0, h*w) {
    cin >> s[i];
    if (s[i] == '.')      cost[i] = 0;
    else if (s[i] == '#') cost[i] = -1;
  }

  ll ans = 0;
  vector<ll> que;
  rep(i, 0, h*w) {
    if (s[i] != '#') {
      cost_tmp = cost;
      cost_tmp[i] = 1;
      ans = max(ans, eval(cost_tmp, i, h, w, que));
      //cout << "ans = " << ans << endl;
      que.clear();
    }
  }
  cout << ans-1 << endl;

}

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

const 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 main(){
  int k;
  cin >> k;
  cout << a[k-1] << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int gcd(int a, int b)
{
	return b == 0 ? a : gcd(b, a % b);
}
int main()
{
	int a, b, k;
	cin >> a >> b >> k;
	int up = gcd(a, b);
	int i;
	for(i = up; ; i--)
	{
		//cout << i << endl;
		if(k == 0) break;
		if(a % i == 0 && b % i ==0)
		{
		//	cout << i << endl;
			k--;
		//	cout << k << endl;
		}
	}
	cout << i+1 << endl;
	return 0;
}

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


// int N = 6;
// string s = "abcabc";

int N;
string s;

int main() {
    cin >> N >> s;
    if (N % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }

    int middle = N / 2;
    rep(i, N / 2) {
        if (s[i] == s[middle + i]) {
            continue;
        }

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

    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string.h>

using namespace std;

int main() {
	int K;
	string S;

	cin >> K >> S;

	if (S.size() <= K) {
		cout << S << endl;
	}
	else {
		cout << S.substr(0, K) << "..." << endl;
	}

	return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;

int main(){
    int N,M;
    cin>>N>>M;

    vector<int>oks(N+1,true);
    for(int i=0;i<M;++i){
        int a;cin>>a;
        oks[a]=false; 
    }

    vector<long long int>dp(N+1);
    dp[0]=1;
    for(int now=0;now<N;++now){
        for(int next=now+1;next<=min(N,now+2);++next){
            if(oks[next]){
                dp[next]+=dp[now];
                dp[next]%=mod; 
            }
        }
    }

    cout<<dp[N]<<endl;
    return 0;
}

Measured memory_bytes: 1408
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define F first
#define S second
#define pb push_back
#define bit __builtin_popcount
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define mkp make_pair
#define ffs fflush(stdout)

using namespace std;
using namespace __gnu_pbds;

//order_of_key(k) : Number of items strictly smaller than k
//find_by_order(k) : K-th element in a set (counting from 0)

template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef vector <int> lnum;
typedef pair <int, int> pii;

const int N = (int)1e6 + 5;
const int MOD = (int)1e9 + 7;
const int inf = (int)1e18;
const int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
const ld eps = 1e9 - 7;
const int pp[] = {29, 31, 53, 67, 71};
const double pi = acos(-1.0);

mt19937 gen(chrono::system_clock::now().time_since_epoch().count());

signed main() {
  ios_base :: sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int x, y;
  cin >> x >> y;
  int res = 0;
  if (x == 1 && y == 1)
    res += 400000;
  if (x == 1)
    res += 300000;
  if (x == 2)
    res += 200000;
  if (x == 3)
    res += 100000;
  if (y == 1)
    res += 300000;
  if (y == 2)
    res += 200000;
  if (y == 3)
    res += 100000;
  cout << res;
  return 0;
}


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved

int main(){
    int n;
    cin>>n;

    vector<pair<int,int>>d(n);
    for(int i=0;i<n;i++){
        int d1,d2;
        cin>>d1>>d2;
        d[i]=make_pair(d1,d2);
    }
    bool ans=false;
    rep(i,n-2){
        bool zoro=true;
        rep(k,3){
            if(d[i+k].first!=d[i+k].second)zoro=false;
        }
        if(zoro)ans=true;
    }

    if(ans){
        cout<<"Yes\n";
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;

}
/*


*/


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

using namespace std;

int n , m;
string s[505];
string a[505];
string b[505];
int main()
{
  cin >> n >> m;
  for(int i = 1; i <= n; i++) {
	  cin >> s[i];
	  a[i] = b[i] = s[i];
  }
  for(int i = 1; i <= n; i++) {
 	  a[i][0] = '#';
	  b[i][m - 1] = '#';
  }
  for (int i = 2; i < n; i += 2) {
	  for (int j = 1; j < m - 1; j++)
	    a[i][j] = '#';
  }
  for(int i = 3; i < n; i += 2) {
    for(int j = 1; j < m - 1; j++)
	    b[i][j] = '#';
  }
  for (int i = 1; i <= n; i++)
	  cout << a[i] << "\n";
  cout << "\n";
  for (int i = 1; i <= n; i++)
	  cout << b[i] << "\n";
  return 0;
}




Measured memory_bytes: 1536
N, K = map(int, input().split())
count = 0
count2 = 0
ans = 0
f = False
if K % 2 == 0:
    f = True
for n in range(1,N+1):
    if n % K == 0:
        count += 1
    if f and n % K == K//2:
        count2 += 1 
if f:
    ans = count2 ** 3 + count ** 3
else:
    ans = count ** 3
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    string s;
    cin>>s;
    int cnt[26]={};
    for(char c:s)cnt[c-'a']++;
    bool yes=true;
    for(int i=0;i<26;i++){
        if(cnt[i]&1)yes=false;
    }
    cout<<(yes?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
 
int main(){
    u_int n, m;
    while(std::cin >> n >> m){
        //n??????m???0????????°??????
        if(n == 0 && m == 0){
            return 0;
        }
         
        std::vector<u_int> p(n);
        for(int i = 0; i < n; ++i){
            std::cin >> p[i];
        }
         
        std::sort(p.begin(), p.end(), std::greater<u_int>());
        //(m????????°) ????????????????????????
        for(int i = m; i <= n; i += m){
            p[i-1] = 0;
        }
         
        std::cout << std::accumulate(p.begin(), p.end(), 0) << std::endl;
    }
     
    return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int y,n,a,b,c,f=1;
map<string,int> ma;
string s;
int main() {
	cin>>n;
	while(n--){
        cin>>s;
        ma[s]++;
	}
	int cm=0;
	map<string, int>::iterator it=ma.begin();
	while(it!=ma.end()){
        cm=max(cm,it->second);
        it++;
	}
	it=ma.begin();
	while(it!=ma.end()){
        if(it->second==cm)
            cout<<it->first<<endl;
        it++;
	}
	return 0;
}


Measured memory_bytes: 26624
#include<map>
#include<cmath>
#include<stack>
#include<cstdio>
#include<queue>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
struct BigNum {
	static const int BASE=100000000;
	static const int WIDTH=8;
	vector<int>s;
	BigNum(ll num=0){
		*this=num;
	}
	BigNum operator = (ll num){
		s.clear();
		do{
			s.push_back(num%BASE);
			num/=BASE; 
		}while(num>0);
		return *this;
	}
	BigNum operator = (const string& str){
		s.clear();
		int x,len=(str.length()-1)/WIDTH+1;
		for(int i=0;i<len;i++){
			int end=str.length()-i*WIDTH;
			int start=max(0,end-WIDTH);
			sscanf(str.substr(start,end-start).c_str(),"%d",&x);
			s.push_back(x); 
		}
		return *this;
	}
	BigNum operator + (const BigNum& b) const {
		BigNum c;
		c.s.clear();
		for(int i=0,g=0;;i++){
			if(g==0&&i>=s.size()&&i>=b.s.size())break;
			int x=g;
			if(i<s.size())x+=s[i];
			if(i<b.s.size())x+=b.s[i];
			c.s.push_back(x%BASE);
			g=x/BASE;
		}
		return c;
	}
	BigNum operator += (const BigNum& b) {
		*this=*this+b;
		return *this;
	}
	bool operator < (const BigNum& b) const {
		if(s.size()!=b.s.size())return s.size()<b.s.size();
		for(int i=s.size()-1;i>=0;i--)if(s[i]!=b.s[i])return s[i]<b.s[i];
		return false;
	}
	bool operator > (const BigNum& b) const {
		return b<*this;
	}
	bool operator <= (const BigNum& b) const {
		return !(b<*this);
	}
	bool operator >= (const BigNum& b) const {
		return !(*this<b);
	}
	bool operator != (const BigNum& b) const {
		return b<*this||*this<b;
	}
	bool operator == (const BigNum& b) const {
		return !(b<*this)&&!(*this<b);
	}
};
ostream& operator << (ostream &out,const BigNum& x){
	out << x.s.back();
	for(int i=x.s.size()-2;i>=0;i--){
		char buf[20];
		sprintf(buf,"%08d",x.s[i]);
		for(int j=0;j<strlen(buf);j++)out << buf[j];
	}
	return out;
}
istream& operator >> (istream &in,BigNum& x){
	string s;
	if(!(in >> s))return in;
	x=s;
	return in;
}
int n; 
int main(){
	BigNum a=2,b=1,c;
	cin>>n;
	if(n==0){
		puts("2");
		return 0;
	}
	if(n==1){
		puts("1");
		return 0;
	}
	for(int i=2;i<=n;i++){
		c=a+b;
		a=b;b=c;
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String op = sc.next();
        int b = sc.nextInt();

        int ans = 0;
        switch (op){
            case "-":
                ans = a - b;
                break;
            case "+":
                ans = a+b;
                break;
        }
        System.out.println(ans);
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, q;
	cin >>n >>q;
	vector<VI> r(n);
	rep(i, n-1){
		int a, b; cin >>a >>b;
		r[a-1].emplace_back(b-1);
		r[b-1].emplace_back(a-1);
	}
	VL sum(n);
	rep(i, q){
		int p, x; cin >>p >>x;
		sum[p-1] += x;
	}
	auto f=[&](auto f, int c, int p)->void{
		for(auto z: r[c]) if(z != p){
			sum[z] += sum[c]; f(f, z, c);
		}
	};
	
	f(f, 0,-1);
	for(auto x: sum) cout <<x <<" "; cout<<"\n";
	return 0;
	
}


Measured memory_bytes: 21888
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	int n, m, lmax=0,rmin=100001;
	cin >> n >> m;
	vector<int> l(m), r(m);
	for (int i = 0; i < m; ++i){
		cin >> l[i] >> r[i];
		lmax = max(lmax, l[i]);
		rmin = min(rmin, r[i]);
	}
	cout << ((rmin - lmax + 1 > 0) ? (rmin - lmax + 1) : 0) << endl;
	return 0;
}

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

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
	int n;
	while(cin >> n, n){
		int ret = 0;
		for(int i=0; i < n; i++){
			int a, b, c, w;
			cin >> a >> b >> c >> w;
			int h = a + b + c;
			if(h <= 60 && w <= 2) ret += 600;
			else if(h <= 80 && w <= 5) ret += 800;
			else if(h <= 100 && w <= 10) ret += 1000;
			else if(h <= 120 && w <= 15) ret += 1200;
			else if(h <= 140 && w <= 20) ret += 1400;
			else if(h <= 160 && w <= 25) ret += 1600;
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
????????????????????????????????? ??§?????§  
??????????????? ??§?????§ ???????´<_??? ?????? Welcome to My Coding Space!
???????????? ??? ?´_???`??????/??? ???i     
?????????????????????????????? ???  |???|     
????????? /?????? /??£??£??£??£/??????|  
??? ???_(__??????/???    ???/ .| .|????????????  
??? ????????????/????????????/??????u??????  
---------------------------------------------------------------------------------------------------*/






int N; string S;
//--------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> S;

    int ans = N;
    rep(i, 0, N - 1) {
        if (S[i] == 'x' && S[i + 1] == 'x') {
            ans = i + 1;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3352
#include <cstdio>
#include <algorithm>

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

using namespace std;

int n, d, x;
int p[10][10];
int a[10];
int b[10];
int dp[11][100001];

int solve(){
	fill_n(dp[0], x + 1, 0);
	rep(i, n){
		rep(j, x + 1){
			if(j < a[i]){
				dp[i + 1][j] = dp[i][j];
			}
			else{
				dp[i + 1][j] = max(dp[i + 1][j - a[i]] + b[i], dp[i][j]);
			}
		}
	}
	return dp[n][x];
}

int main(){
	scanf("%d%d%d", &n, &d, &x);
	rep(i, d){
		rep(j, n){
			scanf("%d", &p[i][j]);
		}
	}
	rep(i, d - 1){
		rep(j, n){
			a[j] = p[i][j];
			b[j] = p[i + 1][j] - p[i][j];
		}
		x += solve();
	}
	printf("%d\n", x);
}

Measured memory_bytes: 3728
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int S,h,m,s,x;
    cin >> S;
    h=S/3600;
    x=S%3600;
    m=x/60;
    s=x%60;
    cout << h;
    cout << ":";
    cout << m;
    cout << ":";
    cout << s;
    cout << endl;
}



Measured memory_bytes: 3092
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        sc.close();

        if(str.equals("RRR")){
            System.out.println("3");
        }
        else if(str.contains("RR")){
            System.out.println("2");
        }
        else if(str.contains("R")){
            System.out.println("1");
        }
        else{
            System.out.println("0");
        }
    }
}

Measured memory_bytes: 35516
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000001;
constexpr ll INF= 1e18;
constexpr ll MOD = 998244353;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int X;
    cin >> X;
    cout << X / 500 * 1000 + (X - X / 500 * 500) / 5 * 5 << endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

type SortName []int

func (x SortName) Len() int           { return len(x) }
func (x SortName) Less(i, j int) bool { return x[i] > x[j] }
func (x SortName) Swap(i, j int)      { x[i], x[j] = x[j], x[i] }

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(stringLineScan())
	}
	sort.Sort(SortName(a))
	b := make([]int, 2)
	c := 0
	for i := 0; i < n-1; i++ {
		if a[i] == a[i+1] {
			b[c] = a[i]
			c++
			i++
		}
		if c == 2 {
			break
		}
	}
	fmt.Println(b[0] * b[1])
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B, C, D, E;
  cin >> A >> B >> C >> D >> E;
  int a,b,c,d,e;
  a = A%10;
  b = B%10;
  c = C%10;
  d = D%10;
  e = E%10;
  int f,g,h,i,j,k;
  f = A+B+C+D+E+40-a-b-c-d-e;
  if(a == 0){
    f -= 10;
    a = 100;
  }
  if(b == 0){
    f -= 10;
    b = 100;
  }
  if(c == 0){
    f -= 10;
    c = 100;
  }
  if(d == 0){
    f -= 10;
    d = 100;
  }
  if(e == 0){
    f -= 10;
    e = 100;
  }
  if(a+b+c+d+e ==500){
    a = 0;
    b = 0;
    c = 0;
    d = 0;
    e = 0;
    f += 10;
  }
   cout << min(f+a,min(f+b,min(f+c,min(f+d,f+e)))) <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     ll n,k;
     cin>>n>>k;
     ll count=0;
     while(n!=0){
         n=n/k;
         count++;
     }
     cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef pair<double,double> P;
typedef complex<double> CP;
typedef long long ll;


double x,h;

int main(){
	while(cin>>x>>h,!(x==0&&h==0)){
		printf("%.6f\n",x*x+x*2.0*sqrt(h*h+x*x/4.0));
	}
	return 0;
}

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

#include <iostream>

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define FOR(i, a, b) for(int i = a;i < b;++i)
#define FORR(i, a, b) for(int i = b;i >= a;--i)
#define ALL(x) (x).begin(),(x).end()
#define INF 999999999
using namespace std;
#define lint long long

int main()
{
  int N; cin >> N;
  char s[N],t[N];
  char st[N*2];
  REP(i,N){
    cin >> s[i];
  }
  REP(i,N){
    cin >> t[i];
  }
  int count = 0;
  REP(i,N){
    st[count] = s[i];
    ++count;
    st[count] = t[i];
    ++count;
  }
  REP(i,N*2) cout << st[i];
  return 0;
}



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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, k;
  cin >> n >> k;

  unordered_map<char, ll> ngl;
  rep(i, k){
    char d;
    cin >> d;
    ngl[d]++;
  }

  repLRE(i, n, 99999){
    string str = to_string(i);
    bool ok = true;
    for(char c : str){
      if(ngl.count(c)) {
        ok = false;
        break;
      }
    }
    if(ok){
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int N= gi();
	    int M= gi();
	    int[] L = new int[M];
	    int[] R = new int[M];


	    for (int i=0; i<M;i++) {
	    	L[i]=gi();
	    	R[i]=gi();
	    }

	    int minr=Integer.MAX_VALUE;
	    int maxl=0;

	    for (int i=0; i<M;i++) {
	    	if(maxl < L[i]) {
	    		maxl=L[i];
	    	}
	    	if(minr>R[i]) {
	    		minr=R[i];
	    	}
	    }


        System.out.print(Math.max(minr-maxl+1,0));
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
}

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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		//入力表示
		int N = sc.nextInt();

		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < N; i++) {
			list.add(sc.nextInt());
		}
		int count = 0;
		int min = Collections.max(list);

		for (int i = 0; i < N; i++) {
			if (list.get(i) <= min) {
				min = list.get(i);
				count++;
			}

		}
		System.out.println(count);
		}
}

Measured memory_bytes: 55456
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
 
using namespace std;
using ll = long long;
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


int main()
{
    int n, a[100005], k = 0, i, ans = 1;

    cin >> n;
    for(i = 0; i < n; i++){
        cin >> a[i];
    }

    for(i = 1; i < n; i++){
        if(k == 0){
            if(a[i - 1] < a[i]){
                k = 1;
            }
            else if(a[i - 1] > a[i]){
                k = 2;
            }
        }
        else{
            if(k == 1){
                if(a[i - 1] > a[i]){
                    ans++;
                    k = 0;
                }
            }
            else{
                if(a[i - 1] < a[i]){
                    ans++;
                    k = 0;
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void){
	int N,i;
	int max=0;
	int ans=0;
	int temp;
	int p[10000]={};
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d",&temp);
		ans += temp;
		if(max < temp){
			max = temp;
		}
	}
	printf("%d",ans-(max)/2);
	return 0;
}

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

int main() {
    string S;
    cin >> S;
    long long ans = 0;
    for(int s=0; s < (1 << (S.size()-1)); s++){
        string now = "";
        now += S[0];
        for(int i=0; i<S.size()-1; i++){
            // S[i] と S[i+1] の間に + を入れるか
            if(s & (1<<i)) now += "+";
            now += S[i+1];
        }
        long long sum=0;
        int pos=0;
        while(now.find("+", pos) != string::npos){
            sum += stoll( now.substr(pos, now.find("+", pos)-pos) );
            pos = now.find("+", pos)+1;
        }
        sum += stoll( now.substr(pos) );
        ans += sum;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	//予備
	n := iScan()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	now := a[0]
	ans := 0
	for i := 0; i < n; i++ {
		if now < a[i] {
			now = a[i]
		} else {
			ans = ans + now - a[i]
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5852
import numpy as np

S = input()
N = len(S)
s = np.array([int(i) for i in list(S)])
s1 = np.array([i % 2 for i in range(N)])
s2 = abs(s1 - np.array([1] * N))

print(min(np.sum(np.abs(s - s1)), np.sum(np.abs(s - s2))))

Measured memory_bytes: 21020
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
static const int mod = 1e9 + 7;
vector<bool> IsPrime;

void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true); 
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i)
        if(IsPrime[i])
            for(size_t j=2; i*j<=max; ++j)
                IsPrime[i*j] = false;
}

ll cnt(int n){
    ll ans = 1;
    int tmp, cnt;
    for (int i = 2; i <= n; i++){
        cnt = 1;
        for (int j = i; j <= n; j++){
            if (!IsPrime[i]) continue;
            tmp = j;
            while (tmp % i == 0){
                tmp /= i;
                cnt += 1;
            }
        }
        ans = ans * cnt % mod;
    }
    return ans;
}

int main(){
    int n;
    sc(n)
    sieve(1000);
    cout << cnt(n) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mr make_pair
#define pb emplace_back
#define N 100010
#define fi first
#define se second
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
int n,v[300010],w[300010],dp[520][N],q,u,l;
vector<pair<int,int> > s;
int main(){
	read(n);for (int i=1;i<=n;i++)read(v[i]),read(w[i]);
	for (int i=1;i<min(n+1,1<<9);i++){
		for (int j=0;j<=100000;j++)dp[i][j]=dp[i/2][j];
		for (int j=0;j<=100000-w[i];j++)dp[i][j+w[i]]=max(dp[i/2][j+w[i]],dp[i/2][j]+v[i]);
	}
	read(q);
	while (q--){
		read(u);read(l);
		s.clear();s.pb(mr(l,0));
		while (u>=(1<<9)){
			int g=s.size();
			for (int i=0;i<g;i++)if (s[i].fi>=w[u])s.pb(mr(s[i].fi-w[u],s[i].se+v[u]));
			u/=2;
		}
		int g=s.size(),an=0;
		for (int i=0;i<g;i++)an=max(an,s[i].se+dp[u][s[i].fi]);
		printf("%d\n",an);
	}
	return 0;
}

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

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  
    int t;
    t=1;

    while(t--){
 		int n;
 		cin>>n;

 		vector<ll> data(n);
 		for(int i=0;i<n;i++)
 			cin>>data[i];

 		sort(data.begin(),data.end());
 		
 		int ans=0;
 		for(int i=0;i<n;i++){
 			for(int j=i+1;j<n;j++){
 				if(data[i]!=data[j]){
 					for(int k=j+1;k<n;k++){
 						if(data[j]!=data[k]){
 							if(data[i]+data[j]>data[k])
 								ans++;
 							else
 								break;
 						}
 					}
 				}
 			}
 		}
 		cout<<ans<<endl;
    }
}

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

int main() {
   int N,K;
   cin >> N >> K;
   long long total=1;
   for (int i=0; i<N; i++) {
       if (i==0) total*=K;
       else total*=(K-1);
   }
   cout << total << endl;
}

Measured memory_bytes: 256
rooms = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
N = int(input())
for i in range(N):
    b, f, r, v = map(int, input().split())
    b -= 1
    f -= 1
    r -= 1
    rooms[b][f][r] += v

for bi, b in enumerate(rooms):
    for f in b:
        print('', *f)
    if 0 <= bi < 3:
        print('#'*20)




Measured memory_bytes: 5624
#include "bits/stdc++.h"

#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 namespace std;
const long long INF = 1LL << 61;

int main() {
	int N; cin >> N;
	int count = 0;
	rep(i, N) {
		int num; cin >> num;
		if ((i + 1) != num)count++;
	}
	if (count > 2)cout << "NO";
	else cout << "YES";
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		int K=nextInt();
		int X=nextInt();

		System.out.println(500*K>=X?"Yes":"No");

	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 20564
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	s := make([]int, n+1)
	for i := 0; i < n; i++ {
		s[i+1] = s[i] + a[i]
	}

	sort.Sort(sort.IntSlice(s))

	ans := 0
	count := 0
	for i := 0; i < n; i++ {
		if s[i] == s[i+1] {
			count++
		} else if count > 0 {
			ans += combi(count+1, 2)
			count = 0
		}
	}
	if count > 0 {
		ans += combi(count+1, 2)
	}

	fmt.Println(ans)
}

func combi(n, r int) int {
	c := 1
	for i := 1; i <= r; i++ {
		c = c * (n - i + 1) / i
	}
	return c
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int add(int x, int y) {
	x += y;
	if (x >= mod) x -= mod;
	return x;
}
int sub(int x, int y) {
	x -= y;
	if (x < 0) x += mod;
	return x;
}
int mul(int x, int y) {
	return (x * 1LL * y) % mod;
}

int n;
int arr[500005];
int sum[500005];

pair<int, int> tree[1 << 21];
int doneUpdates[1 << 21];
int updates;

void propagate(int ind) {
	int toDo = updates - doneUpdates[ind];
	doneUpdates[ind] = updates;
	tree[ind].first = add(tree[ind].first, mul(tree[ind].second, toDo));
}

void update(int ind, int val) {
	propagate(ind);
	tree[ind].second = add(tree[ind].second, val);
}

void apply() {
	updates++;
}

int get(int ind) {
	propagate(ind);
	return tree[ind].first;
}

int main() {
	ios::sync_with_stdio(false);

	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", arr + i), sum[i] = arr[i];
	for (int i = 1; i < n; i++) sum[i] ^= sum[i - 1];

	int ans = 0;
	int z = 0;
	for (int i = n - 1; i >= 0; i--) {
		int val = sum[i];
		if (val == 0) {
			apply();
			if (sum[n - 1] == 0) {
				int tmp = z; if (i == n - 1) tmp = 1;
				z = add(tmp, z);
				ans = add(ans, tmp);
			}
		}
		else {
			int tmp = get(val);
			if (sum[n - 1] == 0) tmp = add(tmp, 1);
			else if (i == n - 1) tmp = 1;
			ans = add(ans, tmp);
			update(val, tmp);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 20608
m,d=map(int,input().split())
ans=0
for i in range(1,d+1):
    for j in range(1,m+1):
    # print(i//10,i%10,m)
        if (i//10)*(i%10)==j and i//10>=2 and i%10>=2:
            # print(i,j)
            ans+=1
print(ans) 

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

using namespace std;
#define int long long
int n,a,b,c,d;
unordered_map <int,int> u;
int slv(int x)
{
    if(x==0)
    {
        u[x]=0;
        return 0;
    }
    if(u.count(x))
    {
        return u[x];
    }
    int ans=1e18;
    if((1e18)/d>=x)
    {
        ans=(d*x);
    }
    for(int i=(-1);i<=1;++i)
    {
        if((x+i)%2==0 && (x+i)>=0 && (x+i)/2<x)
        {
            ans=min(ans,slv((x+i)/2)+abs(i)*d+a);
        }
    }
    for(int i=(-2);i<=2;++i)
    {
        if((x+i)%3==0 && (x+i)>=0 && (x+i)/3<x)
        {
            ans=min(ans,slv((x+i)/3)+abs(i)*d+b);
        }
    }
    for(int i=(-4);i<=4;++i)
    {
        if((x+i)%5==0 && (x+i)>=0 && (x+i)/5<x)
        {
            ans=min(ans,slv((x+i)/5)+abs(i)*d+c);
        }
    }
    u[x]=ans;
    //cout<<x<<" x "<<ans<<" ans "<<endl;
    return ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    u.clear();
    cin>>n>>a>>b>>c>>d;
    cout<<slv(n)<<endl;
    }
    return 0;
}


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

#define rep(i,a,b) for(auto i=(a); i<(b); ++i)
#define trav(a,x) for(auto& a: x)
#define all(x) begin(x),end(x)
#define sz(x) (int)size(x)
#define PB push_back
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using vi = vector<int>;

struct edge{int to;};
using graph = vector<vector<edge>>;

int main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);

  string s;
  cin >> s;
  if (s.back() == 's') s += "es";
  else s += "s";
  cout << s << '\n';
}


Measured memory_bytes: 3636
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

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

n, k = na()
a = na()

def nu(h, a):
    ret = 0
    for v in a:
        ret += (v-1) // h
    return ret

if sum(a) - n <= k:
    print(1)
else:
    low = 0
    high = 1000000007
    while high - low > 1:
        h = (high+low)//2
        if nu(h, a) <= k:
            high = h
        else:
            low = h
    print(high)


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

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

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

constexpr int MAX = 3010000;
constexpr int MOD = 1000000007;

//Please set MAX and MOD!!========================================

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

ll COM(int n, int k) {
	if (n < k || n < 0 || k < 0) return (0);
	return (fac[n] * (finv[k] * finv[n - k] % MOD) % MOD);
}

ll PERM(int n, int k) {
	if (n < k || n < 0 || k < 0) return (0);
	return (fac[n] * finv[n - k] % MOD);
}


void Main() {
	ll N, M; cin >> N >> M;
	COMinit();
	ll sum = 0;
	ll sign = 1;
	for (int k = 0; k <= N; k++) {
		ll val = (mod + sign * PERM(M, k)) % mod;
		(val *= PERM(M-k, N-k)) %= mod;	
		(val *= PERM(M-k, N-k)) %= mod;
		(val *= COM(N, k)) %= mod;
		(sum += val) %= mod;
		sign = -sign;
	}
	cout << sum << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 74192
#include <bits/stdc++.h>
using namespace std;
int main(){	
	int flag=0,i,j,k,l,m,n;
  	vector<int> b(110);
  	vector<int> a(110);
  	vector<int> c(110);
  	cin>>n;
  	for(i=0;i<n;i++){
		cin>>a.at(i);
      	
      	if(a.at(i)>i+1){
			flag=1;
          break;
        }
    }
  
  
  	if(flag==0){
      	for(i=n;i>0;i-=1){
          for(j=i-1;j>=0;j-=1){
         	if(a.at(j)==j+1){
              
              	c.at(i)=a.at(j);
              	
              
              for(l=j;l<i-1;l++){
						a.at(l)=a.at(l+1);
              }
              break;
            }
            
          }
        }
        for(k=1;k<n+1;k++){
			cout<<c.at(k)<<endl;
        }
    }else{
			cout<<-1<<endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int solve(int n) {
    vector<int>keep(n);
    vector<int>ans(n-1);
    int a;
    for(int i=0;i<n;i++){
        cin>>a;
        keep[i]=a;
    }
    // for(int i:keep)cout<<i<<" ";
    sort(keep.begin(),keep.end());
    for(int i=0;i<n-1;i++){
        ans[i]=abs(keep[i]-keep[i+1]);
    }
    // for(int i:ans)cout<<i<<" ";
    sort(ans.begin(),ans.end());
    // int sa = ans[0];
    return ans[0];
}

int main(int argc, char const *argv[]) {
    int n;
    vector<int>ans;
    while (1) {
        cin >> n;
        if (n == 0) break;
        ans.push_back(solve(n));
    }
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
}



Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<pair<ll,ll> > v;
    ll a,b;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        v.pb(make_pair(a+b,a-b));
    }
    sort(be(v));
    ll ans=1,num=v[0].first;
    for(int i=1;i<n;i++){
        if(v[i].second<num){
            continue;
        }else{
            ans++;
            num=v[i].first;
        }
    }
    cout << ans<<endl;
    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> CS(N + 1, 0);
  for (int i = 0; i < M; i++) {
    int l, r;
    cin >> l >> r;
    CS[l - 1]++, CS[r]--;
  }
  for (int i = 0; i < N; i++) {
    CS[i + 1] += CS[i];
  }
  int res = 0;
  for (int i = 0; i < N; i++) {
    if (CS[i] == M) res++;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 640
#include <cassert>
#include <iostream>
#include <vector>

using namespace std;

typedef long long LL;

LL dp[5000+10];
LL dp2[5000*5000+10];

int main() {
  int n;
  cin >> n;
  vector<int> la, lb;
  for (int i = 0; i < 3; ++i) {
    int a;
    cin >> a;
    la.push_back(a);
  }
  for (int i = 0; i < 3; ++i) {
    int b;
    cin >> b;
    lb.push_back(b);
  }

  for (int i = 0; i <= n; ++i) dp[i] = 0;
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j < 3; ++j) {
      if (i+la[j] > n) continue;
      dp[i+la[j]] = max(dp[i+la[j]], dp[i]+lb[j]);
    }
    dp[i+1] = max(dp[i+1], dp[i]+1);
  }

  LL m = dp[n];
  for (int i = 0; i <= m; ++i) dp2[i] = 0;
  for (int i = 0; i <= m; ++i) {
    for (int j = 0; j < 3; ++j) {
      if (i+lb[j] > m) continue;
      dp2[i+lb[j]] = max(dp2[i+lb[j]], dp2[i]+la[j]);
    }
    dp2[i+1] = max(dp2[i+1], dp2[i]+1);
  }

  cout << dp2[m] << endl;
}


Measured memory_bytes: 195584