akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
void debug(vector<vector<ll>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
void debug(vector<ll>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
vector<vector<ll>>vec(ll x, ll y, ll w){
  vector<vector<ll>>v(x,vector<ll>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}
//m.emplace(x,0).fi->se++;
 
ll MAX_V = 3000; //頂点数
struct edge {
    ll to;
    ll cost;
};
vector<vector<struct edge>> G(MAX_V); //隣接リスト
vector<ll> d(MAX_V); //各頂点への最短距離
vector<ll> neg(MAX_V,0);
ll n;
bool bellmanford(ll s){
  fill(ALL(d), INF);
  d[s]=0;
  for(ll i=0;i<2*MAX_V;i++){
    for(ll j=0;j<G.size();j++){
      for(ll k=0;k<G[j].size();k++){
        struct edge e=G[j][k];
        if(d[e.to]>d[j]+e.cost){
          d[e.to]=d[j]+e.cost;
          if(i>=MAX_V-1&&d[e.to]<=INF/5){
            d[e.to]=-INF;
            if(e.to==n)
            return false;
          }
        }
      }
    }
  }
  return true;
}
 
 
int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll m,p;cin>>n>>m>>p;
  vector<ll> u(m),v(m),a(m);
  for(ll i=0;i<m;i++){
    cin>>u[i]>>v[i]>>a[i];
    struct edge e ={v[i],p-a[i]};
    G[u[i]].push_back(e);
  }
  if(bellmanford(1)){
    cout<<max(0LL,-d[n])<<endl;
  }
  else{
    cout<<-1<<endl;
  }
  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
int p[200010];
signed main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    int cnt = 1;
    int minn = p[0];
    for (int i = 1; i < n; i++)
    {
        if(minn < p[i]){
        }
        else{
            minn = p[i];
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
int main() {
    int n, a = 0, b = 0;
    cin >> n;
    REP(i,n){
        string s,t;
        cin >> s >> t;
        if(s>t) a += 3;
        else if(s<t) b+=3;
        else a++,b++;
    }
    cout << a << " " << b << endl;
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    vector<pair<int, pair<int, int>>> v(n);
    for (int i = 0; i < n; i++)
    {
        cin>>v[i].second.first>>v[i].second.second>>v[i].first;
    }
    sort(ALL(v));
    map<int, int> mp;
    set<int> st;
    for (int i = 0; i < q; i++)
    {
        int d;
        cin >> d;
        mp[d] = i;
        st.insert(d);
    }
    vector<int> ans(q,-1);
    for (int i = 0; i < n; i++)
    {
        int l = v[i].second.first - v[i].first;
        int r = v[i].second.second - v[i].first;
        auto it1 = st.lower_bound(l);
        auto it2 = st.lower_bound(r);
        //cout << st << endl;
        vector<int> er;
        for (auto it = it1; it != it2; it++)
        {
           // cerr << l<<" " <<r<<" "<<*it << endl;
            //st.erase(st.find(*it));
            int id = mp[*it];
            ans[id] = v[i].first;
            er.push_back(*it);
        }
        for (int i = 0; i < er.size(); i++)
        {
            st.erase(er[i]);
        }

        /*for (auto it = it1; it != it2;it++){
            st.erase(st.find(*it));
        }*/
    }
    for (int i = 0; i < q; i++)
    {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 30604
import threading
import sys


def main():
    def solve(n):
        if n == 1:
            return 0
        else:
            if S[n - 2] == S[n - 1]:
                return solve(n - 1)
            else:
                return solve(n - 1) + 1

    S = input()
    first_s = S[0]
    S = [1 if first_s == s else 0 for s in S]

    print(solve(len(S)))


if __name__ == "__main__":

    sys.setrecursionlimit(1024 * 1024 * 2)
    threading.stack_size(128 * 1024 * 1024 * 2)
    threading.Thread(target=main).start()


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

const int mod = 1e9 + 7;

int main () {
  int n, m;
  cin >> n >> m;
  vector<int> x(n), y(m), sx(n+1, 0), sy(m+1, 0);

  rep(i,n) {
    cin >> x[i];
    sx[i+1] = (sx[i] + x[i]) % mod;
  }
  rep(i,m) {
    cin >> y[i];
    sy[i+1] = (sy[i] + y[i]) % mod;
  }

  ll xf = 0, yf = 0;
  rep(i,n) {
    xf += sx[n] - sx[i] - ll(n-i) * x[i] + mod;
    xf %= mod;
  }
  rep(i,m) {
    yf += sy[m] - sy[i] - ll(m-i) * y[i] + mod;
    yf %= mod;
  }
  printf("%d\n", (xf * yf) % mod);

  return 0;
}


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

int main(){
  int A, B, ans;
  cin >> A >> B;

  if(A>=0 && A<=5){
    ans = 0;
  } else if(A>=6 && A<=12){
    ans = B/2;
  } else {
    ans = B;
  }

  cout << ans << endl;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
 
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define form(i, n) for (size_t i = 0; i < size_t(n); ++i)
#define forn(i, n) for (size_t i = 1; i <= size_t(n); ++i)
template<class T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long mod(long long a, long long b) { return (a%b+b)%b; }
long long gcd(long long x, long long y) { return __gcd(x, y); }
long long lcm(long long x, long long y) { return x * 1ll * y / gcd(x, y); }
 
 
const long long MAXN = 1e9 + 9;
const long long SIZE = 3e5 + 5;
const long long MOD = 1e9 + 7;


int main() { speedhack()

	long long N, M, K;

	cin >> N >> M >> K;

	long long div = N / M;
	if (N % M) ++div;
	div = div * K;

	cout << div << endl;


	return 0;
}

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

void solve(){
    char c;
    cin >> c;
    if(islower(c)) c='a';
    else c='A';

    cout<<c<<endl;
}

int main(){
   // int t;  cin >> t;   while(t--)
    solve();

    return 0;
}


Measured memory_bytes: 3632
N = int(input())
T = list(map(int, input().split()))
M = int(input())
P = [0] * M
X = [0] * M
for i in range(M):
    P[i], X[i] = map(int, input().split())

time = sum(T)

for i in range(M):
    ans = time - T[P[i] - 1] + X[i]
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int N, A, B;
    cin >> N;
    if(N == 1){
        cout << "Hello World" << endl;
    }else{
        cin >> A >> B;
        cout << A + B << endl;
    }
    return 0;
}

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

ll pow(ll x,ll y){
  if(y == 0){
    return 1;
  }
  if(y == 1){
    return x;
  }
  if(y%2 == 0){
    return pow(x,y/2)*pow(x,y/2);
  }
  else{
    return x*pow(x,y/2)*pow(x,y/2);
  }
}
struct Sieve {
  int n;
  vector<int> mindivnum, primes;
  Sieve(int n=1):n(n), mindivnum(n+1) {
    mindivnum[0] = mindivnum[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (mindivnum[i]) continue;
      primes.push_back(i);
      mindivnum[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!mindivnum[j]) mindivnum[j] = i;
      }
    }
  }
  bool isPrime(int x) { return mindivnum[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(mindivnum[x]);
      x /= mindivnum[x];
    }
    return res;
  }
  vector<pair<int,int>> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<pair<int,int>> res(1, pair<int,int>(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vector<pair<ll,int>> factor(ll x) {
    vector<pair<ll,int>> res;
    for (int p : primes) {
      int y = 0;
      while (x%p == 0) x /= p, ++y;
      if (y != 0) res.emplace_back(p,y);
    }
    if (x != 1) res.emplace_back(x,1);
    return res;
  }
}; 

int main(){
    ll n;
    cin >> n;
    Sieve s(1000000);
    auto fs = s.factor(n);
    int ans = 0;
    for(auto p: fs){
        int a = p.second;
        int b = 1;
        while(a>=b){
            a-=b;
            b++;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 7852
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	//入力
	string S;
	cin >> S;

	//処理
	vector <string> divide = { "dream","dreamer","erase","eraser" };

	vector <bool> flag(S.size() + 1, 0);
	flag[0] = 1;

	for (int S_i = 0; S_i < S.size(); ++S_i) {
		if (flag[S_i] == 0) continue;
		for (string s : divide) {
			if (S.substr(S_i, s.size()) == s) {
				flag[S_i + s.size()] = 1;
			}
		}
	}

	//出力
	if (flag[S.size()]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
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;
}
///////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,x; cin >> N >> x;
    if (x == 1 || x == 2*N-1) cout << "No" << endl;
    else {
        cout << "Yes" << endl;
        vector<int> A(2*N-1);
        rep(i,2*N-1) A[i] = i+1;
        swap(A[x-1],A[N-1]);
        swap(A[0],A[N-2]);
        swap(A[2*N-2],A[N]);
        rep(i,2*N-1) cout << A[i] << endl;
    }
}

Measured memory_bytes: 2304
#include "bits/stdc++.h"
using namespace std;
const int N=100;
int n,a[N],ans;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];

	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
			ans+=a[i]*a[j];
	cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll SUB(ll x,ll y)
{
    return ((x-y)+MOD)%MOD;
}
int arr[MAX],last[MAX];
ll fact[1000005],inverse[1000005];
ll Bigmod(int a,int b)
{
    if(b==0)
        return 1%MOD;
    ll x=Bigmod(a,b/2);
    x=(x*x)%MOD;
    if(b%2==1)
        x=(x*a)%MOD;
    return x;
}
ll nCr(int x, int y)
{
    if(x<0 || y<0 || x<y)
        return 0;
    return fact[x] * (inverse[y] * inverse[x - y] % MOD) % MOD;
}
void pre_cal()
{

    fact[0]=1;
    for(int i=1; i<=1000000; i++)
        fact[i]=fact[i-1]*1LL*i%MOD;
    inverse[1000000]=Bigmod(fact[1000000],MOD-2);
    for(int i=1000000; i>0; i--)
    {
        inverse[i-1]=i* 1LL*inverse[i] % MOD;
    }
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    pre_cal();
    int n,en=-1,st;
    cin>>n;
    n++;
    for(int i=1; i<=n; i++)
    {
        cin>>arr[i];
        if(last[arr[i]])
        {
            st=last[arr[i]];
            en=i;
        }
        last[arr[i]]=i;
    }
    ll ans=0,d=(en-st)+1;
    st--;
    cout<<n-1<<endl;
    for(int i=2; i<=n; i++)
    {
        ans=nCr(n,i);
        ll temp=nCr(n-d,i-1);
        ans=SUB(ans,temp);
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 19940
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

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

	ll ans = 0;
	ll high = A[0];
	FOR(i, 1, N) {
		high = max(A[i], high);
		if (high - A[i] > 0) ans += high - A[i];
	}

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

Measured memory_bytes: 4832
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

char s[201];
bool ok1;

int main(){
	gets(s);
	for(int i = 0; i <= 105; i ++){
		if(s[i] == 'C'){
			ok1 = true;
		}
		if(ok1 == true && s[i] == 'F'){
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def floyd_warshall(dist):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

def is_bipartite(u):
    for v in range(N):
        if u == v or dist[u][v] != 1:
            continue
        if color[v] == -1:
            color[v] = 1 - color[u]
            if not is_bipartite(v):
                return False
        elif color[u] == color[v]:
            return False
    return True

N = int(input())
S = [input().rstrip() for _ in range(N)]
dist = [[1 if S[i][j] == '1' else (0 if i == j else float('inf')) for j in range(N)] for i in range(N)]
color = [-1] * N
color[0] = 0
ans = 0
if is_bipartite(0):
    floyd_warshall(dist)
    ans = max(max(d) for d in dist) + 1
else:
    ans = -1
print(ans)


Measured memory_bytes: 55772
#include <stdio.h>

#define N 100

int main(void){
  int c,n,i,j,max,index;
  char s[N];
  
  int Is_include_in_X[26];
  int Is_include_in_Y[26];
  
  for( i=0; i<26; i++){
    Is_include_in_X[i] = 0;
    Is_include_in_Y[i] = 0;
  }
  
  scanf("%d",&n);
  scanf("%s",s);
  
  for( i=0; i<n; i++){
    index = s[i] - 0x61;
    Is_include_in_Y[ index ]++;
  }
  
  for( max=0, i=0; i<n; i++){
    // Slide divide point 
    index = s[i] - 0x61;
    Is_include_in_Y[ index ]--;
    Is_include_in_X[ index ]++;
    
    // Check between list
    for( c=0, j=0; j<26; j++){
      if( Is_include_in_Y[j] > 0 &&
          Is_include_in_X[j] > 0) c++;
      
      if( max < c ) max = c;
    }
  }
  
  printf("%d\n",max);
  
  return 0;
}
  

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

using namespace std;
using ll = long long;

template<typename T>
T pown(T b, ll e) {
    if(e == 0) return 1;
    T p = pown(b, e / 2);
    if(e % 2 == 0) return p * p;
    return p * p * b;
}

template<const int mod>
struct Intmod {
    ll a;
    Intmod(ll a = 0): a(((a % mod) + mod) % mod) {}

    Intmod operator-() const {return Intmod(-a);}

    Intmod& operator+=(const Intmod b) {
        if((a += b.a) >= mod) a -= mod;
        return *this;
    }
    Intmod& operator+=(const ll b) {
        if((a += Intmod(b).a) >= mod) a -= mod;
        return *this;
    }
    Intmod& operator-=(const Intmod b) {
        if((a -= b.a) < 0) a += mod;
        return *this;
    }
    Intmod& operator-=(const ll b) {
        if((a -= Intmod(b).a) < 0) a += mod;
        return *this;
    }
    Intmod& operator*=(const Intmod b) {
        (a *= b.a) %= mod;
        return *this;
    }
    Intmod& operator*=(const ll b) {
        (a *= Intmod(b).a) %= mod;
        return *this;
    }

    template<typename T> Intmod operator+(const T b) const {return Intmod(*this) += b;}
    template<typename T> Intmod operator-(const T b) const {return Intmod(*this) -= b;}
    template<typename T> Intmod operator*(const T b) const {return Intmod(*this) *= b;}

    // Valid for prime mod. pown() needs to be included.
    int i = 0;
    Intmod inv() {
        if(a == 0) throw "Inverse of zero does not exist.";
        if(!i) i = pown(*this, mod - 2).a;
        return Intmod(i);
    }
    Intmod& operator/=(const Intmod b) {return *this *= b.inv();}
    Intmod& operator/=(const ll b) {return *this *= Intmod(b).inv();}
    template<typename T> Intmod operator/(const T b) const {return Intmod(*this) /= b;}
};
template<const int mod, typename T> Intmod<mod> operator+(const T b, Intmod<mod> a) {return a += b;}
template<const int mod, typename T> Intmod<mod> operator-(const T b, Intmod<mod> a) {return a -= b;}
template<const int mod, typename T> Intmod<mod> operator*(const T b, Intmod<mod> a) {return a *= b;}
template<const int mod, typename T> Intmod<mod> operator/(const T b, Intmod<mod> a) {return a /= b;} //Valid for prime mod.

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

    const int MOD = 1000000007;

    int n, m;
    cin >> n >> m;

    Intmod<MOD> ans = 0;
    vector<Intmod<MOD>> p(n + 1), c(n + 1);
    p[n] = 1;
    for(int i = n - 1; i >= 0; --i) p[i] = p[i + 1] * (m - i);
    c[0] = 1;
    for(int i = 1; i <= n; ++i) {
        c[i] = c[i - 1] * (n - i + 1);
        c[i] /= i;
    }

    for(int i = 0; i <= n; ++i) ans += (i&1 ? -1 : 1) * p[i] * c[i];
    ans *= p[0];

    printf("%lld\n", ans.a);

    return 0;
}

Measured memory_bytes: 18712
import sys
d=[0 for i in range(26)]
for line in sys.stdin:
    for c in line:
        x = ord(c)
        if ord('A')<=x and x<=ord('Z'):
            x -= (ord('A')-ord('a'))
        if ord('a')<=x and x<=ord('z'):
            d[x-ord('a')] += 1   

for i in range(26):
    print("%s : %d" % (chr(ord('a')+i),d[i]))

Measured memory_bytes: 7488
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;


const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

// _key[何番目のボタンを押したか][何回押したか]
/*
 * ex) k番目のボタンをn回押した時
 *     _key[k - 1][n % _key[k - 1].size()]
 *           ↑           ↑
 *  0が基準なので-1する　↑
 *                       ↑
 *                       ↑
 *       n % _key[k - 1].size() で結果何番目の文字になったかが分かる
 */
 
string _key[9] = {
	      ".,!? ",
	      "abc",
	      "def",
	      "ghi",
	      "jkl",
	      "mno",
	      "pqrs",
	      "tuv",
	      "wxyz"
};

int main(){
  int N;
  cin >> N;
  for(int _ = 0; _ < N; _++) {
    string s, message = "";
    cin >> s;
    int cnt = 0;
    char key = '0';
    
    for(int i = 0; i < s.size(); i++) {
      if(key == '0' && s[i] != '0') {
	cnt = 0;
	key = s[i];
      } else if(key == s[i]) {
	cnt++;
      } else if(s[i] == '0') {
	message += _key[key - '0' - 1][cnt % _key[key - '0' - 1].size()];
	key = '0';
      }
    }
    
    cout << message << endl;
  }
  return 0;
}





Measured memory_bytes: 3100
import java.io.*;
import java.util.*;
import java.lang.*;
public class Main {
	PrintWriter out;
    StringTokenizer st;
    BufferedReader br;
 	
 	class Pair implements Comparable<Pair>
	{
	    int f;
	    int s;
 
	    Pair(int t, int r) {
	       f = t;
	       s = r;
	    }
	    public int compareTo(Pair p)
	    {
	    	if(this.f!=p.f)
	    		return this.f-p.f;
 
	    	return this.s-p.s;
	    }
 	}
 // 	class Sort implements Comparator<String> 
	// { 
	//     public int compare(String a, String b) 
	//     { 
	//     	return (a+b).compareTo(b+a);
	//     } 
	// }
 
	String ns() {
        while (st == null || !st.hasMoreElements()) {
 
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }
 
    String nextLine() throws Exception {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            throw new Exception(e.toString());
        }
        return str;
    }
 
    int nextInt() {
        return Integer.parseInt(ns());
    }
 
    long nextLong() {
        return Long.parseLong(ns());
    }
 
    double nextDouble() {
        return Double.parseDouble(ns());
    }
	
	int upperBound(long a[],long key)
	{
		int l=0,r=a.length-1;
		int i=-1;
 
		while(l<=r)
		{
			int mid=(l+r)/2;
 
			if(a[mid]<key)
				l=mid+1;
 
			else{
				i=mid;	
				r=mid-1;
			}
			
		}
		return i;
	}
	int lowerBound(Pair[] a , long key)
	{
		int l = 0, r = a.length- 1;
		int i = -1;
 	
		while(l<=r)
		{
			int mid=(l+r)/2;
 
			if(a[mid].f<key)
			{
				i=mid;
				l=mid+1;	
			}
 
			else
				r=mid-1;
			
		}
		return i;
	}
 
	long power(long x,long y)
	{
	    long ans=1;
	    
	    while(y!=0)
	    {
	        if(y%2==1) ans=(ans*x)%mod;
	        x=(x*x)%mod;
	        y/=2;
	    }
	    return ans%mod;
	}
	
 
	int mod= 1000000007;
	long gcd(long x ,long y)
	{
		if(y==0)
			return x;
		return gcd(y,x%y);
	}
 
	// ArrayList<Integer> a[];
	// TreeMap<Integer, Long> map;
	// int vis[];
	// long d[];
	// void dfs(int ver, int m)
	// {
	// 	map.put(ver, d[m % 3]);
	// 	for(int v : a[ver])
	// 	{
	// 		if(vis[v] == 0){
	// 			vis[v] = vis[ver] + 1;
	// 			dfs(v, m + 1);
	// 		}
	// 	}
	// }
 
 	int countSetBits(long n) 
    { 
        int count = 0; 
        while (n > 0) { 
            n &= (n - 1); 
            count++; 
        } 
        return count; 
    }
 
	void solve() throws IOException{
		int n = nextInt();
		long amount = 1000, backup = 0;
		int a[] = new int[n];
		for(int i = 0; i < n; i++)
			a[i] = nextInt();
		
		
		for(int i = 0; i < n - 1; i++)
		{
			long m = 0;
			if(a[i] < a[i + 1])
			{
				m = amount / a[i];
				amount += m * (a[i + 1] - a[i]);
			}
		}	
		out.println(amount);
	}
	
    void run() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
		solve();
		out.flush();
 
		out.close();
	}
 
	public static void main(String args[]) throws IOException {
		new Main().run();
	}
}

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

int N, D;
vector<int> C[100];
int num[100];
int power[100];

bool isValid() {
  int mini, maxi;
  mini = maxi = power[0];
  for(int i = 1; i < N; ++i) {
    mini = min(mini, power[i]);
    maxi = max(maxi, power[i]);
  }
  return maxi - mini <= D;
}

bool iscomplete() {
  for(int i = 0; i < N; ++i) {
    if(num[i] != C[i].size()) return false;
  }
  return true;
}

bool solve() {
  fill(num, num+N, 0);
  fill(power, power+N, 0);
  while(!iscomplete()) {
    for(int i = 0; i <= N; ++i) {
      if(i == N) return false;
      if(num[i] == C[i].size()) continue;
      power[i] += C[i][num[i]++];
      if(isValid()) break;
      power[i] -= C[i][--num[i]];
    }
  }
  return true;
}

int main() {
  while(cin >> N >> D && (N | D)) {
    for(int i = 0; i < 100; ++i) C[i].clear();
    for(int i = 0; i < N; ++i) {
      int m;
      cin >> m;
      for(int j = 0; j < m; ++j) {
	int c;
	cin >> c;
	C[i].push_back(c);
      }
    }
    cout << (solve() ? "Yes" : "No") << endl;
  }
  return 0;
}

Measured memory_bytes: 1004
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,m;
    cin >> n >> m;
    vector<ll> a(n);
    ll s = 0;
    for(ll i=0; i<n; i++)
    {
        cin >> a[i];
        s+=a[i];
    }
    ll x = 4*m;
    ll cnt = 0;
    for(ll i=0; i<n; i++)
    {
        if(x*a[i]>=s)
            cnt++;
    }
    if(cnt>=m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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

int N,X;
int m[110];
int main(){
	cin >> N >> X;
	for(int i=0;i<N;i++){
		cin >> m[i];
		X -= m[i];
	}
	sort(m,m+N);
	cout << N + X/m[0] << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
long long a[1000007],b[1000007],c[1000007];
int main()
{
	int n,i;
	cin>>n;
	for(i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(i=1;i<=n;i++)
		scanf("%lld",&b[i]);
	for(i=1;i<=n;i++)
		scanf("%lld",&c[i]);	
	sort(a+1,a+n+1);sort(b+1,b+n+1);sort(c+1,c+n+1);
	long long j=0,j2=0;
	long long ans=0;
	for(i=1;i<=n;i++)
	{
		while(a[j+1]<b[i]&&j<n)
		{
			j++;
		}
		while(c[j2+1]<=b[i]&&j2<n)
		{
			j2++;
		}
		//cout<<j<<" "<<j2<<endl;
		ans+=j*(n-j2);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9216
N = gets.to_i
cards = gets.strip.split.map(&:to_i).sort{|a,b|b<=>a}
result = 0

i = 0
N.times do |i|
  if i == 0 || i.even?
    result += cards[i]
  else
    result -= cards[i]
  end
end

puts result

Measured memory_bytes: 1788
import java.io.*;
import java.util.StringTokenizer;

public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int N = Integer.parseInt(br.readLine());
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] v = new int[N];
        int[] c = new int[N];
        for(int i=0;i<N;++i)
        {
            v[i] = Integer.parseInt(st.nextToken());
        }
        st = new StringTokenizer(br.readLine());
        for(int i=0;i<N;++i)
        {
            c[i] = Integer.parseInt(st.nextToken());
        }
        int ans = 0;
        for(int i=0;i<N;++i)
        {
            ans+=v[i]>c[i]?v[i]-c[i]:0;
        }
        bw.write(ans+"");
        bw.close();

    }

}


Measured memory_bytes: 21332
#include <stdio.h>

typedef struct { int i, p, q, r; } candy;

int main(void)
{
    int n;

    while (scanf("%d", &n), n != 0){
        candy c[1024];
        int P, Q, R, C;
        int flag;
        int i;

        for (i = 0; i < n; i++) scanf("%d %d %d %d", &c[i].i, &c[i].p, &c[i].q, &c[i].r);
        scanf("%d %d %d %d", &P, &Q, &R, &C);
        for (i = flag = 0; i < n; i++){
            int tp = c[i].p * 4;
            int tq = c[i].q * 9;
            int tr = c[i].r * 4;

            if (c[i].p <= P && c[i].q <= Q && c[i].r <= R && tp + tq + tr <= C){
                printf("%d\n", c[i].i);
                flag = 1;
            }
        }
        if (flag == 0) puts("NA");
    }

    return 0;
}

Measured memory_bytes: 1056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int H,W;
    cin >> H >> W;
    vector<vector<string>> S(H,vector<string>(W));
    REP(i,H)REP(l,W)cin >> S[i][l];
    int a,b;
    REP(i,H){
        REP(l,W){
            if(S[i][l] == "snuke"){
                a = i+1;
                b = l;
            }
        }
    }
    cout << (char)('A' + b) << a << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <numeric> 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define int long long int
#define mod 1000000007
#define INT_BITS 16
#define inf 1000000099
#define watch(x) cout<<(#x)<<"="<<(x)<<"\n" 
//__builtin_popcount()

vector<int> decToBinary(int n,int digit) 
{ 
    // array to store binary number 
    int binaryNum[digit]={0}; 
    vector<int>v;
    // counter for binary array 
    int i = 0; 
    while (n > 0) { 
  
        // storing remainder in binary array 
        binaryNum[i] = n % 2; 
        n = n / 2; 
        i++; 
    } 
  
    // printing binary array in reverse order 
    for (int j = 0; j< digit; j++) 
        v.push_back(binaryNum[j]);
      return v; 
}


int32_t main()
{
    int n,m,x;
    cin>>n>>m>>x;
    int a[n][m+1];
    for (int i = 0; i < n; ++i)
    {
        for(int j=0;j<m+1;j++)
          cin>>a[i][j];
      /* code */
    }
    int ans=inf;
    for (int i = 0; i < pow(2,n); ++i)
    {
        vector<int>v=decToBinary(i,n);
        int sum[m+1]={0};
        int total=0;
        for(int j=0;j<n;j++)
        {
            if(v[j]==1)
            {
              for(int k=1;k<m+1;k++)
              {
                  sum[k]+=a[j][k];
              }
              total+=a[j][0];
            }
        }
        int flag=0;
        for (int j = 1; j <m+1 ; ++j)
        {
            if(sum[j]<x)
              flag=1;
          /* code */
        }
        if(flag==0)
          ans=min(ans,total);
    }
    if(ans<inf)
     cout<<ans<<endl;
   else
   {
      cout<<-1<<endl;
   }
    

    return 0;
}


Measured memory_bytes: 4108
#include<iostream>
using namespace std;
int main(){
  int floor[4][3][10]={{{}}},n,b,f,r,v;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> b >> f >> r >> v;
    floor[b-1][f-1][r-1] += v;
  }
  for(int i=0;i<4;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<10;k++){
    cout << " " << floor[i][j][k];
      }
      cout << endl;
    }
    if(i!=3)
    cout << "####################" << endl;
  }
}

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

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

    string tmp(S);
    for(int i=0; i<S.length(); i++){
        char lastch = tmp.back();
        tmp.pop_back();
        tmp.insert(0, 1, lastch); 
        if(tmp == T){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int a, b, c,d,e,ans;
int g=0;

scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	ans=a+b+c+d+e;
g=a%10;
if(g>0)
ans+=10-g;
if(b%10>0)
ans+=10-b%10;
if(c%10>0)
ans+=10-c%10;
if(d%10>0)
ans+=10-d%10;
if(e%10>0)
ans+=10-e%10;

if(g>b%10&&b%10>0)
g=b%10;

if(g>c%10&&c%10>0)
g=c%10;

if(g>d%10&&d%10>0)
g=d%10;

if(g>e%10&&e%10>0)
g=e%10;
if(g>0)
ans-=10-g;

  printf("%d\n",ans);
     
	return 0;
}

Measured memory_bytes: 128
def sieve_of_eratosthenes(N):
    prime_list = [True for _ in range(N + 1)]
    prime_list[0] = False
    prime_list[1] = False
    for p in range(2, int(N ** 0.5) + 1):
        if prime_list[p]:
            for i in range(2 * p, N + 1, p):
                prime_list[i] = False

    return prime_list


Q = int(input())
Max_ = 10**5
prime_list = sieve_of_eratosthenes(Max_)
count_list = [0]*(Max_+1)
count = 0
for i in range(Max_+1):
    if prime_list[i] and prime_list[(i + 1) // 2]:
        count += 1
    count_list[i] = count
for _ in range(Q):
    l, r = map(int, input().split())
    print(count_list[r] - count_list[l-1])

Measured memory_bytes: 51456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef complex <double> cp;
#define debug(a) cout<<#a<<":"<<a<<endl;
#define fr freopen("in.txt","r",stdin);
#define Fill(x,a) memset(x,a,sizeof(x))
#define cpy(a,b) memcpy(a,b,sizeof(a))
const double PI = acos(-1);
const int INF=0x3f3f3f3f;
const int N=1e6+7;
const int mod=1e9+7;
int maxn,minn;
int T,n,m,q;
int a[N], b[N], c[N];

int main(){
	cin >> n;
	for(int i = 1; i <= n; i ++ ){
		scanf("%d", a + i);
	}
	for(int i = 1;i <= n; i ++ ){
		scanf("%d", b + i);
	}
	reverse(b + 1, b + n + 1);
	int l, r, flag, num;
	l = r = flag = num = 0;
	for(int i = 1; i <= n; i ++ ){
		if(a[i] == b[i] && l == 0){
			l = i;
			r = i;
			flag = a[i];
		}
		else if(a[i] == b[i] && l){
			r = i;
		}		
	}
	if(l){
		for(int i = 1; i <= n && num <= r - l; i ++ ){
			if(b[i] != flag && a[i] != flag){
				b[l + num] = b[i];
				b[i] = flag;
				num ++ ;
			}
		} 
	}
	if(l == 0 || num == r - l + 1){
		puts("Yes");
		for(int i = 1;i <= n; i ++ ){
			cout << b[i] << " ";
		}
		cout << endl;
	}
	else{
		puts("No");
	}
	
	
	

	return 0;
}



Measured memory_bytes: 5252
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
const int mod = 1000000007;
#define ll long long
struct memo {
	char s;
	ll cnt;
};
vector<memo> X;
int main()
{
	string S; cin >> S;
	X.push_back({ S[0], 1 });
	int k = 0;
	for (int i = 1; i < S.size(); i++) {
		if (S[i] == X[k].s) {
			X[k].cnt++;
		}
		else {
			X.push_back({ S[i],1 });
			k++;
		}
	}
	ll ans = 0;
	ll num = 0;
	int i = 0;
	while (i < X.size()) {
		if (i == 0 && X[i].s == '<') {
			for (int j = 0; j < X[i].cnt; j++) {
				ans += j;
				num = j + 1;
			}
			i++;
		}
		else {
			ans += max(num, X[i].cnt);
			//cout << max(num, X[i].cnt)<<" ";
			for (int j = X[i].cnt - 1; j >= 0; j--) {
				ans += j;
				//cout << j << " ";
			}
			num = 0;
			if (i + 1 >= X.size()) {
				break;
			}
			for (int j = 1; j < X[i + 1].cnt; j++) {
				ans += j;
				num = j + 1;
				//cout << j << " ";
			}
			if (X[i + 1].cnt == 1) {
				num = 1;
			}
			i += 2;
		}
	}
	ans += num;
	cout << ans << endl;
}

Measured memory_bytes: 6904
#include<bits/stdc++.h>
using namespace std;
bool vis[100][100];
int fx[] = {0,0,1,-1};
int fy[] = {1,-1,0,0};
int dist[100][100];
int main()
{
    int n,m;
    cin >> n >> m ;
    char ara[n+10][m+10];

    int cnt = 0;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
        {
            cin >> ara[i][j] ;
         //   dist[i][j] = INT_MAX;
            if(ara[i][j]=='#')cnt++;
        }
    }
   // cout << cnt << " " << n*m << endl;

   // memset(dist,2,sizeof dist);


    queue <pair<int,int> > q;
    bool mrk = 0;
    if(ara[0][0]=='.' && ara[n-1][m-1]=='.')
    q.push(make_pair(0,0)),dist[0][0] = 0,vis[0][0]=0;
    else mrk = 1;

    //cout << dist[n-1][m-1] << endl;
    if(!mrk)
    while(!q.empty())
    {
        pair<int,int> prnt = q.front() ;
        q.pop();
        int px = prnt.first;
        int py = prnt.second;
        for(int i=0; i<4; i++)
        {

            int cx = px + fx[i];
            int cy = py + fy[i];

            if(cx>=0 && cx<n && cy>=0 && cy<m && ara[cx][cy]=='.'  && vis[cx][cy]==0)
            {
                vis[cx][cy] = 1;
    //            cout << px << " " << py << endl;
      //          cout << cx << " " << cy << endl;
                dist[cx][cy] = dist[px][py]+1 ;
                q.push(make_pair(cx,cy));
            }
        }

    }

     if(!vis[n-1][m-1])mrk = 1;
    int rasta = 0 ;
     rasta =  dist[n-1][m-1]+1 ;
      if(!mrk)
      cout << n*m - cnt - rasta << endl;
      else cout << "-1" << endl;
}


Measured memory_bytes: 3636
n,m =map(int, input().split())
s_list = [list(input().split()) for _ in range(m)]
num = ['x']*n
flag = 0
for s in s_list:
    if num[int(s[0])-1] == 'x' or num[int(s[0])-1] == s[1]:
        num[int(s[0])-1] = s[1]
    else:
        flag =1
        break
if flag:
    print(-1)
else:
    if num[0] == '0':
        if n == 1:
            print(0)
        else:
            print(-1)
    else:
        for i in range(len(num)):
            if num[i] == 'x':
                if i == 0 and n != 1:
                    num[i] = '1'
                else:
                    num[i] = '0'
        print(''.join(num))

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <bitset>

using namespace std;
using ll = long long int;

int main() {
  ll N, D;
  cin >> N >> D;

  ll ans = 0;
  for (ll i = 0; i < N; i++)
  {
    ll xi, yi;
    cin >> xi >> yi;
    if ((xi * xi) + (yi * yi) <= D * D) {
      ans += 1;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3628
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>

#define MY_SIZE_MAX 100001
#define MY_VALUE_MAX 100001

#define COUNTOF( a ) (sizeof(a)/sizeof(a[0]))
#define MIN(a,b) (((a)>(b))?(b):(a))
#define MAX(a,b) (((a)<(b))?(b):(a))

using namespace std;

int main()
{
	struct SData
	{
		double size;
		unsigned long long money;
	};
	SData list[] = 
	{
		{ 0.25f, 0 },
		{ 0.5f, 0 },
		{ 1.0f, 0 },
		{ 2.0f, 0 },
	};
	unsigned long long ne;
	cin >> list[0].money >> list[1].money >> list[2].money >> list[3].money;
	cin >> ne;

	list[1].money = MIN( list[0].money+list[0].money, list[1].money );
	list[2].money = MIN( list[1].money+list[1].money, list[2].money );
	list[3].money = MIN( list[2].money+list[2].money, list[3].money );

	double e = static_cast< double >( ne );
	unsigned long long result = 0;
	for( int i = COUNTOF( list ) - 1; i >= 0; --i ){
		unsigned long long count = static_cast< unsigned long long >( e / list[i].size );
		e -= list[i].size * count;
		result += list[i].money * count;
	}

	cout << result << endl;
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc089/tasks/abc089_d

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll H, W, D;
  cin >> H >> W >> D;

  VVL mat(H, VL(W));
  VL num_to_h(H * W + 1);
  VL num_to_w(H * W + 1);

  rep(h, H) rep(w, W) {
    ll val;
    cin >> val;

    mat[h][w] = val;
    num_to_h[val] = h;
    num_to_w[val] = w;
  }

  VVL rem_acc(D + 1, VL(0));

  rep1(first, D) {
    ll cur = first;
    ll acc = 0;

    rem_acc[first].emplace_back(acc);

    while (cur + D <= H * W) {
      ll next = cur + D;
      ll cost = abs(num_to_h[cur] - num_to_h[next]) +
                abs(num_to_w[cur] - num_to_w[next]);
      acc += cost;
      rem_acc[first].emplace_back(acc);
      cur = next;
    }
  }

  ll Q;
  cin >> Q;

  rep(i, Q) {
    ll L, R;
    cin >> L >> R;

    ll first = L % D == 0 ? D : L % D;
    ll l_index = (L - first) / D;
    ll r_index = (R - first) / D;

    ll res = rem_acc[first][r_index] - rem_acc[first][l_index];
    cout << res << endl;
  }
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    int ans = 0;
    if (S == "SUN") ans = 7;
    if (S == "MON") ans = 6;
    if (S == "TUE") ans = 5;
    if (S == "WED") ans = 4;
    if (S == "THU") ans = 3;
    if (S == "FRI") ans = 2;
    if (S == "SAT") ans = 1;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int x[10001];
  int a,n=0;
  while(1)
  {
    cin>>a;
    if(a==0)
      break;
    else
      {
        x[n]=a;
        n++;
      }
  }
    for(int i=0;i<n;i++)
    cout<<"Case "<<i+1<<": "<<x[i]<<endl;
    return 0;
}

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

typedef pair<int,int> P;
struct edge{int to, id;};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mod 1000000007



int main(){
    int n,w;
    cin >> n >> w;
    int v[n],weight[n];
    rep(i,n){
        int a,b;
        cin >> a >> b;
        v[i] = a;
        weight[i] = b;
    }
    int dp[n+1][w+1];
    for(int i = 0; i <= w; i++){
        dp[0][i] = 0;
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j <=w ; j++){
            if(weight[i] <= j){
                dp[i+1][j] = max(dp[i][j-weight[i]] + v[i],dp[i][j]);
            }
            else{
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    cout << dp[n][w] << endl;

}


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

int main() {
    long long l, r;
    cin >> l >> r;

    int mod = 2019;

    if (r % mod == 0 || l % mod == 0 || r - l > mod) {
        cout << 0 << endl;
        return 0;
    }

    long long ans = mod;
    for (int i = l; i < r; i++) {
        for (int j = i+1; j <= r; j++) {
            ans = min(ans, 1LL * i * j % mod);
        }
    }
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 256
from itertools import*
h,*m=open(0)
h,w,k=map(int,h.split())
s=0
for i in range(h+1):
    for a in combinations(range(h),i):
        a={*a}
        for j in range(w+1):
            for b in combinations(range(w),j):
                b={*b}
                c=0
                for y in range(h):
                    if y in a:continue
                    for x in range(w):
                        if x in b:continue
                        c+=m[y][x]=='#'
                s+=c==k
print(s)

Measured memory_bytes: 9040
#include <iostream>
#include <fstream>
#include <string>

using namespace std;


int main(){

  int n;
  cin >> n;

  int left = n / 100;

  int first = left*100 + left*10+ left;
  int second = (left+1)*100 + (left+1)*10 + (left+1);

  if(first < n ){
    cout << second;
  }else{
    cout << first;
  }
  cout << endl;
}


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);
	if(1<=A && A<=10000){
		if(1<=B && 	B<=10000){
			if(1<=C && C<=10000){
				if(1<=D && D<=10000){
					int z=max(A*B, C*D);
					printf("%d",z);
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256