akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
an = list(map(int, input().split()))

dict = {}
for a in an:
    if a in dict:
        dict[a] += 1
    else:
        dict[a] = 1

ans = 0
if len(dict) > K:
    for k, v in sorted(dict.items(), key=lambda x: x[1])[0:len(dict) - K]:
        ans += v

print(ans)


Measured memory_bytes: 39804
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll mod = 1000000007;
ll INF = 1000000009;


void solve(){
    int x;
    cin >> x;
    int a,b,c,d;
    d = x%10;
    c = (x/10)%10;
    b = (x/100)%10;
    a = (x/1000)%10;
    //結局8通りだし愚直にやる方が早い
    if(a+b+c+d==7) cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
    else if(a+b+c-d==7) cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
    else if(a+b-c+d==7) cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
    else if(a+b-c-d==7) cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
    else if(a-b+c+d==7) cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
    else if(a-b+c-d==7) cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
    else if(a-b-c+d==7) cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
    else if(a-b-c-d==7) cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
}

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


Measured memory_bytes: 256
//#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;

// ?????¬???????????¬??????
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), c.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<double> vd;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<long, long> pil;


// ??°?????????????????¬??????
typedef int Weight;

struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) {}
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight :
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;


int main() {
  double r;
  scanf("%lf", &r);
  printf("%f %f\n", r*r*M_PI, 2*r*M_PI);

  return 0;
}

Measured memory_bytes: 3172
# -*- coding: utf-8 -*-
 # 宇都宮涼
 # J5-170029

T = int(input())
for i in range(T):
    n,k = map(int, input().strip().split(' '))
    a = list(input().split(' '))
    if n <= k:
        print(0)
    else:
        for m in range(len(a)):
            a[m] = int(a[m])
        b = []
        for j in range(len(a)-1):
            c = a[j+1]-a[j]
            b.append(c)
        b.sort()
        answer = sum(b)
        for l in range(k-1):
            answer = answer - b[len(b)-l-1]
        print(answer)



Measured memory_bytes: 18720
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
// #define modd 2019

#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>

#include <cassert>
// #include <algorithm>
#include <functional>
using namespace std;

int euk(int a, int b){
    if(a<b){
    int tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  int r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
  /* 最大公約数を出力 */
//   printf("最大公約数 = %d\n", b);
 
  return b;

}

int main(){
    unsigned long int l, r;
    cin >> l >> r;
    // if((r*r - r) - (l*l + l))
    int res = 2019;
    for(int ind= l; ind < r; ind++){
        // show('a')
        int i = ind%2019;

        if(i == 0){
            cout << 0;
            return 0;
        }

        int fmod = (i*(i+1)) % 2019;//最小のjのmod

        unsigned long int kurikaesi = 2019/euk(2019, i);
        kurikaesi = min(kurikaesi, r-ind);
        // show(kurikaesi)
        int buf = 2019;
        for(unsigned long int j = 0; j < kurikaesi; j++){
            if(buf > ((fmod+(j*i))%2019)){
                buf = ((fmod+(j*i))%2019);
            }
        }



        // int buf;


        // int count = (2018-fmod)/i + 1;
        // shows(i) shows(fmod) show(kurikaesi)
        // if(count <= (r-ind-1)){
        //     buf = ((i+count+1)*i) % 2019;   
            // show(buf)
        // }
        // else{
        //     buf = fmod;
        // }
        // show(buf)
        if(res > buf) res = buf;
    }
    cout << res;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,w,v;
long long  dp[100001];
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    cin>>n>>m;
    for(int i = 1;i<=n;i++){
        cin>>w>>v;
        for(int j=m;j>=w;j--) dp[j]=max(dp[j],dp[j-w] + v);
    }
    cout<<dp[m];
}



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

#define rep(n)      for (int i = 0; i < n; ++i)
#define rep2(n)     for (int j = 0; j < n; ++j)
#define mp          make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;

int main() {    
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n, w;
    cin >> n >> w;
    
    cout << (w>=n?"unsafe":"safe") << "\n";
    
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main() {
	char s[55][105], a[105];
	int t[55];
	int n, ans;
	while (cin >> n) {
		ans = 0;
		int j;
		for (int i = 0; i < n; ++i) cin >> s[i] >> t[i];
		cin >> a;
		for (j = 0; j < n; ++j)if (strcmp(s[j], a) == 0)break;
		for (int i = j + 1; i < n; ++i)ans += t[i];
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n,m,c = map(int ,input().split())
l=[list(map(int ,input().split())) for x in range(n+1)]
cont=0
for i in range(n):
    k=0
    for h in range(m):
        k+=l[0][h]*l[i+1][h]
    k=k+c
    if k>0:
        cont+=1
print(cont)

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def calc_sum(v, n):
    a = [0] * (n)
    for i in range(n):
        if i == 0:
            a[i] = v[i]
            continue
        a[i] = a[i-1] + v[i]
    return a

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))

    a = calc_sum(v, n)
    b = list(reversed(calc_sum(list(reversed(v)), n)))

    ans = INF
    for i in range(n-1):
        ans = min(ans, abs(a[i] - b[i+1]))
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 87200
#include<stdio.h>
#include<stdlib.h>
int n;
int alllength;
int length;
int distance;
int maxmum=0;
int main(){
  scanf("%d",&alllength);
  scanf("%d",&n);
  int array[n];
  for(int i=0;i<n;i++){
    scanf("%d",&array[i]);
  }
   maxmum=alllength-array[n-1]+array[0];
    for(int i=0;i<(n-1);i++){
      distance=abs(array[i+1]-array[i]);
    	if(maxmum<distance){
          maxmum=distance;
        }
     }
   
  
  length=(alllength-maxmum);
  printf("%d",length);
}

Measured memory_bytes: 896
from itertools import combinations

n,m,x = map(int, input().split())

cl = []
al = []
for _ in range(n):
    xl = list(map(int, input().split()))
    cl.append(xl[0])
    al.append(xl[1:])

res = 10**9
for r in range(n+1):
    for c in combinations(range(n), r=r):
        s = 0
        xl = [0]*m
        for i in c:
            s += cl[i]
            xl = [xl[j]+al[i][j] for j in range(m)]
        if all([q>=x for q in xl]):
            res = min(res,s)

if res==10**9:
    print(-1)
else:
    print(res)

Measured memory_bytes: 9244
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cassert>
#define ll long long
#define MOD 1000000007
using namespace std;
inline ll read(){
	ll re=0,flag=1;char ch=getchar();
	while(ch>'9'||ch<'0'){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
ll A[4],B[4];
inline void mul1(){
	int t[4];
	t[0]=(A[0]*B[0]+A[1]*B[1])%MOD;
	t[1]=(A[0]*B[2]+A[1]*B[3])%MOD; 
	A[0]=t[0];
	A[1]=t[1];
} 
inline void mul2(){
	int t[4];
	t[0]=(B[0]*B[0]+B[2]*B[1])%MOD;
	t[1]=(B[1]*B[0]+B[3]*B[1])%MOD; 
	t[2]=(B[0]*B[2]+B[2]*B[3])%MOD;
	t[3]=(B[1]*B[2]+B[3]*B[3])%MOD;
	B[0]=t[0];
	B[1]=t[1];
	B[2]=t[2];
	B[3]=t[3];
}
void qpow(ll k){
	while(k){
		if(k&1) mul1();
		mul2();k>>=1;
	}
}
ll qqpow(ll a,ll b){
	ll re=1;
	while(b){
		if(b&1) re=re*a%MOD;
		a=a*a%MOD;b>>=1;
	}
	return re;
}
ll n,m,k;bool a[1010][1010];
int main(){
	n=read();m=read();k=read();char s[1010];ll i,j,v=0,ud=0,lr=0,tot=0,st=0;
	for(i=1;i<=n;i++){
		scanf("%s",s);
		for(j=0;j<m;j++) a[i][j+1]=(s[j]=='#'),v+=(s[j]=='#');
	}
	for(i=1;i<=n;i++) lr+=(a[i][1]&&a[i][m]);
	for(i=1;i<=m;i++) ud+=(a[1][i]&&a[n][i]);
	tot=qqpow(v,(k-1)%(MOD-1));
	if(lr&&ud||k==1){
		puts("1");return 0;
	} 
	if(!lr&&!ud){
		printf("%lld\n",tot);return 0;
	}
	if(lr) for(i=1;i<=n;i++) for(j=1;j<m;j++) st+=(a[i][j]&&a[i][j+1]);
	else for(i=1;i<n;i++) for(j=1;j<=m;j++) st+=(a[i+1][j]&&a[i][j]);
	if(lr) swap(lr,ud);
	
//	cout<<v<<' '<<st<<' '<<tot<<' '<<lr<<' '<<ud<<'\n';
	
	A[0]=st;A[1]=v;
	B[3]=v;B[0]=ud;B[1]=st;
	
	qpow(k-2);
	
	printf("%lld\n",(tot-A[0]+MOD)%MOD);
}

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

int deg[5];

int main(){
    int u, v;
    while(cin>>u>>v){
        deg[u]++;
        deg[v]++;
    }
    int cnt = 0;
    for(int i=1; i<=4; i++)
        if(deg[i] % 2)
            cnt++;
    if(cnt == 0 || cnt == 2)
        cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 2000003;
const int MOD = 1000000007;

//
int 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;
    }
}
     vector<pair<int,int>> hen[100001];
void solve(int a,bool *used, bool *ans,bool *q,bool &x){
        if(q[a])x=!x;
        for(int i=0;i<hen[a].size();i++){
                if(!used[hen[a][i].first]){
                        used[hen[a][i].first]=true;
                        if(x)ans[hen[a][i].second]=!ans[hen[a][i].second];
                        solve(hen[a][i].first,used,ans,q,x);
                        if(x)ans[hen[a][i].second]=!ans[hen[a][i].second];
                }
        }
}

// 二項係数計算
int 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;
}

        signed main() {
    cout<<fixed<<setprecision(15);
     int n,m,a,b;
     cin>>n>>m;

     pair<int,int> p[n];
     for(int i=0;i<n;i++){
             cin>>a>>b;
             p[i]=make_pair(a,b);
     }
     sort(p,p+n);
     bool q[n+1];
     q[0]=(false)^bool(p[0].second);
        q[n]=(false)^bool(p[n-1].second);
        for(int i=1;i<n;i++){
                q[i]=bool(p[i-1].second)^bool(p[i].second);
        }

      int ok,ng,mid,l,r;
      for(int i=0;i<m;i++){
              cin>>l>>r;
              if(l>p[n-1].first)continue;
              if(r<p[0].first)continue;
              ng=-1;ok=n-1;
              while(abs(ng-ok)>1){
                      mid=(ok+ng)/2;
                      if(l<=p[mid].first)ok=mid;
                      else ng=mid;
              }
              a=ok;
              ng=n;ok=0;
              while(abs(ok-ng)>1){
                      mid=(ok+ng)/2;
                      if(r>=p[mid].first)ok=mid;
                      else ng=mid;
              }
              b=ok+1;
       
              if(a==b)continue;
              hen[a].push_back(make_pair(b,i));
              hen[b].push_back(make_pair(a,i));
            
      }
     
      bool used[n+1]={},ans[m]={},x=false;
      queue<int> que;
      for(int i=0;i<=n;i++){
              if(used[i])continue;
              
              used[i]=true;
              bool x=false;
               solve(i,used,ans,q,x);
               if(x){
                       cout<<"-1";
                       return 0;
               }
      }
      int ans2=0;
      for(int i=0;i<m;i++)if(ans[i])ans2++;
      cout<<ans2<<endl;
      for(int i=0;i<m;i++)if(ans[i]){
              cout<<i+1<<' ';
      }
    
      }

        


Measured memory_bytes: 22656
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;


void Main(){
    string S;
    cin >> S;
    string ans="";
    for(ll i=0;i<3;i++){
        ans += S[i];
    }
    cout << ans <<endl;


}

int main(){
    Main();
}

Measured memory_bytes: 3132
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
from operator import mul
import pprint



sys.setrecursionlimit(2147483647)
INF = 100
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


x = LI()
for i in range(5):
    if x[i] == 0:
        print(i + 1)
        break


Measured memory_bytes: 76764
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
// const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
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; }



void solve(){
    ll n;
    ll k[200010],l[200010],r[200010],d[200010];
    typedef pair<ll,pll> P;
    vector<P> v,w;
    cin>>n;
    rep(i,n){
        cin>>k[i]>>l[i]>>r[i];
        d[i]=l[i]-r[i];
        if(d[i]>=0) v.pb(make_pair(k[i],pll(d[i],l[i])));
        else w.pb(make_pair(k[i],pll(-d[i],r[i])));
    }
    
    sort(v.begin(),v.end());
    sort(w.begin(),w.end());
    reverse(w.begin(),w.end());

    ll now=0,now2=0;
    ll ans=0;
    priority_queue<ll, vector<ll>, greater<ll> > que;
    rep2(i,1,n+1){
        rep2(j,now,(ll)v.size()){
            if(v[j].fi==i){
                que.push(v[j].sc.fi);
                ans+=v[j].sc.sc;
                now++;
            }
            else break;
        }
        while((ll)que.size()>i){
            ll a=que.top();
            que.pop();
            ans-=a;
            // cout<<i<<" "<<a<<endl;
        }
        // cout<<"case0 "<<i<<" "<<ans<<endl;
    }
    priority_queue<ll, vector<ll>, greater<ll> > que1;
    for(ll i=n ; i>=1 ; i--){
        
        rep2(j,now2,(ll)w.size()){
            if(w[j].fi==i){
                que1.push(w[j].sc.fi);
                ans+=w[j].sc.sc;
                now2++;
            }
            else break;
        }
        while((ll)que1.size()>(n-i)){
            ll a=que1.top();
            que1.pop();
            ans-=a;
            // cout<<i<<" "<<a<<endl;
        }
        // cout<<"case1 "<<i<<" "<<ans<<endl;
    }

    cout<<ans<<endl;

}



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);


    ll t;
    cin>>t;
    rep(i,t) solve(); 


    return 0;
}


Measured memory_bytes: 15232
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a;
    cin>>n>>a;
    string s[n];
    for(int i=0;i<n;i++)cin>>s[i];
    sort(s,s+n);
    for(int i=0;i<n;i++)cout<<s[i];
    cout<<endl;

return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define endl "\n"
#define pii pair<int,int>
#define pll pair<ll,ll>
typedef long long ll;
#define loop() for(int i=0; i<(); i++)
const int MOD=1e9+7;
int modpow(int x, int n, int m)
{
    if(n==0) return 1;
    ll ans=1;
    while(n>0)
    {
        if(n%2==1) ans=(ans*x)%m;
        x=(x*x)%m;
        n/=2;
    }
    return ans;
}

void solve()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    map<int,int>m;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        m[a[i]]++;
    } 
    sort(a,a+n);
    vector<int>dp(k+1,2);
    dp[0]=0;
    for(int i=1; i<=k; i++)
    {
        if(m.count(i))
        {
             dp[i]=0;
             continue;
        }
        for(int j=0; j<n && a[j]<=i; j++)
        {
            if(dp[i-a[j]]==1) 
            {
                dp[i]=0;
                break;
            }
        }
         if(dp[i]==2) dp[i]=1;
        
    }
    if(dp[k]==0) cout<<"First"<<endl;
    else cout<<"Second"<<endl;
    
}   

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

}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;
using pint = pair<int, int>;

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

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

int main()
{
  ll n, d, x, y;
  cin >> n >> d;
  int ans = 0;
  rep(i, n)
  {
    ll x, y;
    cin >> x >> y;
    if (x * x <= d * d - y * y)
      ans++;
  }

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

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
struct point{
	double x,y;
	point(){}
	point(double _x,double _y){
		x=_x;y=_y;
	}
	point operator +(const point &b) const{
		return point(x+b.x,y+b.y);
	}
	point operator -(const point &b) const{
		return point(x-b.x,y-b.y);
	}
	double operator ^(const point &b) const{
		return (x*b.x)+(y*b.y);
	}
	double operator *(const point &b) const{
		return x*b.y-y*b.x;
	}
	point operator *(const double &b) const{
		return point(x*b,y*b);
	}
};
struct matrix{
	int xmax,xmin,ymax,ymin;
}a[2];
double len(point p){
	return (p.x*p.x+p.y*p.y);
}
int main(){
	point p0,p1,p2,p3;
	int q;
	cin>>q;
	point vec;
	while(q--){
		cin>>p0.x>>p0.y>>p1.x>>p1.y>>p2.x>>p2.y>>p3.x>>p3.y;
		vec=(p1-p0)*(((p3-p2)*(p0-p2))/((p1-p0)*(p3-p2)));
		vec=vec+p0;
		if(fabs(vec.x)==0) vec.x=0;
		if(fabs(vec.y)==0) vec.y=0;
		printf("%.8lf %.8lf\n",vec.x,vec.y);
	}
	return 0;
}


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

// 絶対値の和の最小値
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        for(int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            B[i] = A[i] - i;
        }
        Arrays.sort(B);
        int x = B[N/2];

        long res = 0;
        for(int j = 0; j < N; j++) {
            res += Math.max(-x+B[j],x-B[j]);
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 64928
from bisect import bisect_left
p = 10**9+7
N = int(input())
C = [int(input()) for _ in range(N)]
A = [0 for _ in range(N)]
B = {i:[0,-1] for i in range(1,2*10**5+1)}
for i in range(N):
    c = C[i]
    if B[c][-1]==i-1:
        A[i] = 0
    else:
        A[i] = 1
    B[c].append(i)
dp = [0 for _ in range(N+1)]
dp[1] = 1
for i in range(1,N):
    if A[i]==1:
        ind = bisect_left(B[C[i]],i)
        j = B[C[i]][ind-1]
        dp[i+1] = (dp[i]+dp[j+1])%p
    else:
        dp[i+1] = dp[i]
print(dp[N])

Measured memory_bytes: 119844
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//C
int main(void) {
  int n, k, i, cou=0, tmp;
  int a, b, c, d, e, f;
  scanf(" %d %d %d", &n, &a, &b);

  for(i=1; i <= n; i++){
    tmp=0;
    e=i;
    for(k=0; k < 5; k++){
      tmp+=e % 10;
      e/=10;
    }
    if(tmp >= a && tmp <= b) cou+=i;
  }
  printf("%d", cou);
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	int LEN = (int)1e6 + 1;

	void doIt() {
		long N = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();
		long cnt = 0l;
		cnt += (N / (A + B)) * A;
		cnt += Math.min((N % (A + B)), A);
		System.out.println(cnt);
	}

	public static void main(String[] args) {
		new Main().doIt();
	}

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main(){
    cin>>N;
    ll have = 0;
    rep(i,N){
        cin>>A;
        if(A == have + 1){
            ++have;
        }
    }
    cout<<(have == 0 ? -1 : N - have)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1LL<<50
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll d[105][105];

void warshall_floyd(int n) {
	rep(k,n) {
		rep(i,n) {
			rep(j,n) {
				if(d[i][k] != INF && d[k][j] != INF) {
					d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
				}
			}
		}
	}
}

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

	rep(i, n) rep(j, n) d[i][j] = INF;
	rep(i, n) d[i][i] = 0;

	rep(i, m) {
		int s, t, c;
		cin >> s >> t >> c;

		d[s][t] = c;
	}

	warshall_floyd(n);

	bool flag = false;
	rep(i, n) {
		if(d[i][i] < 0) flag = true;
	}

	if(flag) {
		cout << "NEGATIVE CYCLE" << endl;
	} else {
		rep(i, n) {
			rep(j, n) {
				if(d[i][j] == INF) cout << "INF";
				else cout << d[i][j];

				if(j == n-1) cout << endl;
				else cout << " ";
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1236
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
import math
A, B, N = map(int, input().split())

def f(x):
    return math.floor(A*x/B) - A * math.floor(x/B)

def main():
    print(f(min(N, B-1)))

if __name__ == "__main__":
    main()



Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define rep(i,n) for (ll i=0; i<(n); i++)
#define INF 100000000
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
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; }


int main(){
    ll N; cin >> N;
    string S; cin >> S;
    
    int cntW=0;
    int cntE=0;
    rep(i,S.size()){
        if (S[i]=='W') cntW++;
        else cntE++;
    }
    
    vector <int> W(N,0);
    vector <int> E(N,0);
    rep(i,S.size()){
        if (i==0){
            if (S[i]=='W') W[0]=1;
            else E[0]=1;
        }else{
            if (S[i]=='W'){
                W[i]=W[i-1]+1;
                E[i]=E[i-1];
            }
            if (S[i]=='E'){
                E[i]=E[i-1]+1;
                W[i]=W[i-1];
            }
        }
    }
    
    ll ans=INF;
    rep(i,N){
        ll left=0;
        ll right=0;
        if (S[i]=='W'){
            if (i-1<0){
                left=0;
            }else{
                left=W[i-1];
            }
            right=cntE-E[i];//右にあるEの数
            ans=min(ans,left+right);
        }
            //cout << left <<" " << right << endl;
        if (S[i]=='E'){
            if (i-1<0){
                left=0;
            }else{
                left=W[i-1];
            }
            right=cntE-E[i];
            ans=min(ans,left+right);
            //cout << left <<" " << right << endl;
        }
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#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, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

vector<bool> IsPrime;

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

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

int main() {
  int n;
  cin >> n;
  sieve(n);
  vector<int> div(n+1, 1);
  FOR(i, 2, n+1) {
    int m = i;
    int j = 2;
    while (m != 1) {
      if (IsPrime[j] && m % j == 0) {
        div[j]++;
        m /= j;
      }
      else j++;
    }
  }
  int over75 = 0;
  int over25 = 0;
  int over15 = 0;
  int over5 = 0;
  int over3 = 0;
  rep(i, n+1) {
    if (!IsPrime[i]) continue;
    if (div[i] >= 75) over75++;
    if (div[i] >= 25) over25++;
    if (div[i] >= 15) over15++;
    if (div[i] >= 5) over5++;
    if (div[i] >= 3) over3++;
  }
  int ans = over75;
  ans += over25 * (over3-1);
  ans += over15 * (over5-1);
  ans += (over3-2) * over5 * (over5-1) / 2;
  cout << ans << endl;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// trueで初期化した配列pが必要です 遅め
vector<bool> p(100000 + 1, true);
void eratos(int n) {
  p[0] = p[1] = false;
  for (int i = 2; i <= sqrt(n); i++)
    if (p[i])
      for (int j = i * 2; j < n; j += i) p[j] = false;
}

// ====================================================================

int main() {
  int n;
  cin >> n;
  eratos(100000);
  int count = 0;
  for (int i = 0; i <= 55555; i++) {
    if (p[i] && (i - 1) % 5 == 0) {
      cout << i << " ";
      count++;
    }
    if (count >= n) {
      cout << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String a=sc.next();
		int[] stacks=new int[a.length()];
		int kaisu=0;
		int pointer=0;
		for(int i=0; i<a.length(); i++) {
			if(a.charAt(i)=='S') {
				stacks[pointer]=1;
				pointer++;
			}
			else if(a.charAt(i)=='T') {
				stacks[pointer]=2;
				pointer++;
			}

			if(pointer>=2) {
				if(stacks[pointer-2]==1 && stacks[pointer-1]==2) {
					stacks[pointer-2]=0;
					stacks[pointer-1]=0;
					pointer-=2;
					kaisu++;
				}
			}
		}
		System.out.println((a.length()-kaisu*2));
	}
}

Measured memory_bytes: 26108
///in the name of ALLAH
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin>>n;
    int a[n],c=0;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i+=2)
    {
        if(a[i]%2!=0)
            c++;
    }
    cout<<c<<endl;
}



Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>

int main(void) {
	int i,j,h,b;
	char r[8],a[8];
	while(scanf("%s%s",r,a),strcmp(r,"0")!=0){
		h=0;b=0;
		for(i=0;i<=3;i++){
			if(r[i]==a[i]) h++;
			for(j=0;j<=3;j++){
				if(r[i]==a[j]) b++;
			}
		}
		printf("%d %d\n",h,b-h);
	}
	return 0;
}

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

int main(){
  int n, W;
  cin >> n >> W;
  int w[n];
  long v[n];
  long dp[n+1][W+1];
  for(int i = 0;i < n;i++)
    cin >> w[i] >> v[i];
  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(w[i]>j){
        dp[i+1][j] = dp[i][j];
      } else {
        dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i]);
      }
    }
  }
  cout << dp[n][W] << endl;
}

Measured memory_bytes: 79104
fn input() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim().to_string()
}

fn main() {
    let _line = &input();
    let line = &input();
    let seg: Vec<i64> = line
        .split_whitespace()
        .map(|s| s.parse::<i64>().unwrap())
        // .map(|s| s.to_owned())
        .collect();
    min_max_sum(seg);
}

fn min_max_sum(v: Vec<i64>) {
    println!(
        "{} {} {}",
        v.iter().min().unwrap(),
        v.iter().max().unwrap(),
        v.iter().sum::<i64>()
    );
}


Measured memory_bytes: 5036
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}
ll LCM(ll x, ll y) { 
  return x / GCD(x, y) * y;
}

int main(){
  int n; cin >> n;
  vector<pair<int, int>> a(n);
  rep(i, n) {
    int b; cin >> b;
    a[i] = make_pair(b, i);
  }
  sort(all(a));
  rep(i, n) cout << a[i].second + 1 << ' ';
  cout << endl;
}

Measured memory_bytes: 1664
n, m = map(int, input().split(' '))

b = (n + 1)*(n**2 + 2*n + 6)
a = m*(2*m**2 - 3*m*(n + 2) + 3*n - 2)

ans = (a + b)//6+1
ans = ans % 1000000007
print(ans)

Measured memory_bytes: 9184
#!/usr/bin/env python
"""<https://github.com/cheran-senthil/PyRival>"""
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    _str = str
    str = lambda x=b"": x if type(x) is bytes else _str(x).encode()


def all_factors(n):
    """returns a sorted list of all distinct factors of n"""
    small, large = [], []
    for i in range(1, int(n**0.5) + 1, 2 if n & 1 else 1):
        if not n % i:
            small.append(i)
            large.append(n // i)
    if small[-1] == large[-1]:
        large.pop()
    large.reverse()
    small.extend(large)
    return small


def main():
    n = int(input())
    cnt = 0
    for f in all_factors(n)[1:]:
        if n // (f - 1) == n % (f - 1):
            cnt += f - 1
    print(cnt)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._buffer = BytesIO()
        self._fd = file.fileno()
        self._writable = "x" in file.mode or "r" not in file.mode
        self.write = self._buffer.write if self._writable else None

    def read(self):
        if self._buffer.tell():
            return self._buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()

    def flush(self):
        if self._writable:
            os.write(self._fd, self._buffer.getvalue())
            self._buffer.truncate(0), self._buffer.seek(0)


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 30956
// https://atcoder.jp/contests/abc106/tasks/abc106_b
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int_fast32_t i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int_fast32_t i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

// 約数の個数 (１の倍数＋２の倍数＋３の倍数＋...)
template <int N> struct calc_approx {
    int cnt[N + 1];

    constexpr calc_approx() : cnt() {
        for (int_fast64_t i = 1; i <= N; ++i) {
            for (int_fast64_t j = i; j <= N; j += i)
                cnt[j]++;
        }
    }
};
calc_approx<200000> approx;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 105; i <= N; i += 2) {
        ans += (approx.cnt[i] == 8);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4396
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
    int n;
    cin>>n;
    int ans[100005];
    long long result = 0;
    int k = 0;
    for (int i = 0 ; i < n; i ++){
        scanf("%d",&ans[i]);
        result += abs(ans[i]-k);
        k = ans[i];
    }
    result += abs(ans[n-1]);
    
    cout<<result-abs(ans[0]-ans[1])-abs(ans[0])+abs(ans[1])<<endl;
    for (int i = 1;i < n-1;i++){
        cout<<result - abs(ans[i]-ans[i-1])-abs(ans[i+1]-ans[i])+abs(ans[i+1]-ans[i-1])<<endl;
    }
    cout<<result - abs(ans[n-1]-ans[n-2])-abs(ans[n-1])+abs(ans[n-2])<<endl;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

template<unsigned P> struct ModInt {
  using M = ModInt;
  unsigned v;
  ModInt() : v(0) {}
  template<class Z> ModInt(Z x) : v(x >= 0 ? x % P : (P - -x % P) % P) {}
  constexpr ModInt(unsigned v, int) : v(v) {}
  static constexpr unsigned p() { return P; }
  M operator+() const { return *this; }
  M operator-() const { return {v ? P - v : 0, 0}; }
  explicit operator bool() const noexcept { return v; }
  bool operator!() const noexcept { return !(bool) *this; }
  M operator*(M r) const { return M(*this) *= r; }
  M operator/(M r) const { return M(*this) /= r; }
  M operator+(M r) const { return M(*this) += r; }
  M operator-(M r) const { return M(*this) -= r; }
  bool operator==(M r) const { return v == r.v; }
  bool operator!=(M r) const { return !(*this == r); }
  M& operator*=(M r) { v = (uint64_t) v * r.v % P; return *this; }
  M& operator/=(M r) { return *this *= r.inv(); }
  M& operator+=(M r) { if ((v += r.v) >= P) v -= P; return *this; }
  M& operator-=(M r) { if ((v += P - r.v) >= P) v -= P; return *this; }
  M inv() const {
    int a = v, b = P, x = 1, u = 0;
    while (b) {
      int q = a / b;
      swap(a -= q * b, b);
      swap(x -= q * u, u);
    }
    assert(a == 1);
    return x;
  }
  template<class Z> M pow(Z n) const {
    if (n < 0) return pow(-n).inv();
    M res = 1;
    for (M a = *this; n; a *= a, n >>= 1) if (n & 1) res *= a;
    return res;
  }
  template<class Z> friend M operator*(Z l, M r) { return M(l) *= r; }
  template<class Z> friend M operator/(Z l, M r) { return M(l) /= r; }
  template<class Z> friend M operator+(Z l, M r) { return M(l) += r; }
  template<class Z> friend M operator-(Z l, M r) { return M(l) -= r; }
  friend ostream& operator<<(ostream& os, M r) { return os << r.v; }
  friend istream& operator>>(istream& is, M& r) { lint x; is >> x; r = x; return is; }
  template<class Z> friend bool operator==(Z l, M r) { return M(l) == r; }
  template<class Z> friend bool operator!=(Z l, M r) { return !(l == r); }
};
using Mint = ModInt<(unsigned) 1e9 + 7>;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  constexpr int N = 1e5;
  int n, X; cin >> n >> X;
  V<> s(n); for (auto&& e : s) cin >> e;
  sort(begin(s), end(s));
  V<Mint> dp(N + 1);
  for (int i = 1; i <= N; ++i) dp[i] = i;
  for (int i = 0; i < n; ++i) {
    V<Mint> ndp(N + 1);
    for (int x = 0; x <= N; ++x) {
      ndp[x] = i * dp[x] + dp[x % s[i]];
    }
    swap(dp, ndp);
  }
  cout << dp[X] << '\n';
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
//INF = 1 061 109 567 ; INF + INF = 2 122 219 134 ;
//LINF = 4 557 430 888 798 830 399 ; LINF + LINF = 9 114 861 777 597 660 798 ;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9+7;
const int maxn = (int)1e3+7;

//浮点型运算
const db eps = 1e-6;
bool eq(const db &a, db const &b) { return fabs(a - b) < eps; }
bool ls(const db &a, db const &b) { return a + eps < b; }
bool le(const db &a, db const &b) { return eq(a, b) || ls(a, b); }

struct Floyd {

    int n;
    int d[maxn][maxn];

    void Init(int n) {
        this->n = n;
        memset(d,0x3f,sizeof(d));
        rep(i,0,n) d[i][i] = 0;
    }

    void AddEdge(int from, int to, int dist) {
        d[from][to] = dist;
    }

    void floyd() {
        rep(k,0,n) rep(i,0,n) rep(j,0,n)
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }

    int length(int S, int T) {
        return d[S][T];
    }

    void connect() {
        rep(k,0,n) rep(i,0,n) rep(j,0,n)
            d[i][j] = d[i][j] || (d[i][k] && d[k][j]);
    }
};

void Init() {
}

Floyd ans;
int a[maxn][maxn];

int main ()
{
    int H, W;
    scanf("%d%d", &H, &W);
    ans.Init(10);
    rep(i, 0, 10) rep(j, 0, 10) {
        scanf("%d", &a[i][j]);
        ans.AddEdge(i, j, a[i][j]);
    }
    ans.floyd();

    ll tot = 0;
    rep(i, 0, H) {
        rep(j, 0, W) {
            int t;
            scanf("%d", &t);
            if (t != -1) {
                tot += ans.length(t, 1);
            }
        }
    }
    printf("%lld\n", tot);




    return 0;
}


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

int main() {
    int a;
    string s;
    cin >> a >> s;
    cout << (a >= 3200 ? s : "red") << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      long a = sc.nextLong();
      long b = sc.nextLong();
      long x = sc.nextLong();
      long countA = 0;
      if(a==0)countA = 0;
      else countA = (a-1)/x+1;
      long countB = b/x+1;
      System.out.println(countB-countA);
    }
}


Measured memory_bytes: 21844
prices = [int(input()) for _ in range(int(input()))]

max_profit = -2000000000
min_price = prices[0]

for price in prices[1:]:
    cur_profit = price - min_price
    max_profit = max(cur_profit, max_profit)
    min_price = min(min_price, price)

print(max_profit)



Measured memory_bytes: 15096
N,M,K=map(int, input().split())
#最初しろ
#行、列ごとに反転
L=[0]*(10**7)
if K==0 or K==N*M:
    print("Yes")
else:
    for h in range(N+1):
        for w in range(M+1):
            now=h*w+(N-h)*(M-w)
            L[now]+=1
    if L[K]>0:
        print("Yes")
    else:
        print("No")




Measured memory_bytes: 81140
import java.util.Scanner
import kotlin.system.exitProcess

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val a = scn.nextLong()
	val b = scn.nextLong()
	val c = scn.nextLong()
	if (a+b>=c) no()
	val dC = c*c
	val dAB = (a+b)*(a+b)
	println(
			if (4*a*b+2*c*(a+b)<dC+dAB) "Yes" else "No"
	)
}

fun no(){
	println("No")
	exitProcess(0)
}

Measured memory_bytes: 31392
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s,t;
  cin >> s >> t;
  ll l = s.size();
  vector<vector<ll>> v(26);
  for(ll i = 0; i < l; ++i){
    v[s[i]-'a'].push_back(i);
  }
  ll ans = 0,pos = -1;
  for(char c : t){
    ll idx = c-'a';
    if(v[idx].empty()){
      cout << -1;
      return 0;
    }
    auto it = lower_bound(begin(v[idx]),end(v[idx]),pos+1);
    if(it == end(v[idx])){
      ans += l;
      pos = v[idx][0];
    }
    else pos = *it;
  }
  cout << ans+pos+1;
  return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <fstream>
#include <set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int main(int argc, const char * argv[]) {
    
    int K, S;
    cin >> K >> S;
    
    int cnt = 0;
    for (int x = 0; x <= K; x++) {
        for (int y = 0; y <= K; y++) {
            if (S - x - y >= 0 && S - x - y <= K) cnt++;
        }
    }
    
    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <set>
#include <bitset>
#include <limits>

using namespace std;

#define ll long long

int main(void){
    double r;
    cin >> r;

    printf("%.9lf", 2*M_PI*r);

    return 0;
}

Measured memory_bytes: 3788
#include <cstdio>
#include <algorithm>
#define maxn 200010
int a[maxn],head[maxn],tot,n,d[maxn],ans,mx[maxn];
using namespace std;
struct node{
	int to,next;
}e[maxn<<1];
void add_edge(int u,int v){
	tot++,e[tot].to=v,e[tot].next=head[u],head[u]=tot;
}
void dfs(int u,int fa){
	int b,v,save,flag,l,r,mid;;
	for(b=head[u];b;b=e[b].next){
		v=e[b].to;
		if(v==fa)continue;
		save=ans,flag=0;//回溯
		if(d[ans]<a[v])d[++ans]=a[v];
		else{
			l=0,r=ans;
			while(l+1<r){
				mid=(l+r)/2;
				if(d[mid]<a[v])l=mid;
				else r=mid;//a[st[mid]]>=a[v]
			}
			flag=d[r],d[r]=a[v];
		}
		mx[v]=ans;
		dfs(v,u);
		ans=save;//回溯
		if(flag)d[r]=flag;//回溯
	}
}
void init(){
	int i,u,v;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	for(i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		add_edge(u,v),add_edge(v,u);//无向图
	}
}
int main(){
	init();
	ans=1,d[1]=a[1],mx[1]=1;
	dfs(1,0);
	for(int i=1;i<=n;i++)printf("%d\n",mx[i]);
	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long

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

int minCost(vector<int> a, int k)
{
    int n = a.size();
    vector<int> dp(n, INF);
    dp[0] = 0;
    for(int i = 0; i < n; i++)
        for(int j = i + 1; j <= min(i + k, n); j++)
            dp[j] = min(dp[j], dp[i] + abs(a[j] - a[i]));
    return dp[n - 1];
}

            
int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k; cin >> n >> k;
    vector<int> h(n);
    for(auto &it: h)
        cin >> it;
    cout << minCost(h, k) << endl;
}

Measured memory_bytes: 4512
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll a, b, b_digit = 0, tmp;
  scanf("%lld%lld", &a, &b);
  ll bb = b;
  while (1)
  {
    bb /= 10;
    b_digit++;
    if (bb == 0)
      break;
  }
  tmp = a * pow(10, b_digit) + b;
  for (int i = 1; i <= sqrt(100100); i++)
  {
    if (i * i == tmp)
    {
      puts("Yes");
      return 0;
    }
  }
  puts("No");
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <utility>

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
#define mp make_pair
#define x first
#define y second

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


return 0;
}



Measured memory_bytes: 3632
#include<iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>

using namespace std;

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


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

int main ()
{
    int n;
    cin>>n;
    vector<pair<string,pair<int,int>>> rest(n);
    for (int i=0;i<n;i++)
    {
        cin>> rest.at(i).first;
        cin>> rest.at(i).second.first;
        rest.at(i).second.first = -rest.at(i).second.first;
        rest.at(i).second.second = i;
    }

    sort(rest.begin(),rest.end());
    
    for (int i=0;i<n;i++)
    {
        cout<<rest.at(i).second.second+1<<endl;
    }
}

Measured memory_bytes: 256