akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    double waters_cumulative_sum[N + 1];
    waters_cumulative_sum[0] = 0;
    for(int i = 1; i <= N; i++){
        double water;
        cin >> water;
        waters_cumulative_sum[i] = waters_cumulative_sum[i - 1] + water;
    }
    double dp[N + 1][N], dp_next[N + 1][N];
    for(int i = 1; i <= N; i++){
        for(int j = 0; j < N; j++){
            dp[i][j] = (i > M) * -1e12 + (waters_cumulative_sum[N] - waters_cumulative_sum[j]) / (N - j);
        }
    }
    for(int i = N - 1; i >= 1; i--){
        for(int j = 1; j <= N; j++){
            for(int k = 0; k < i; k++){
                dp_next[j][k] = max(dp[j][k], dp[j + 1][i] + (waters_cumulative_sum[i] - waters_cumulative_sum[k]) / (i - k));
            }
            for(int k = i; k < N; k++){
                dp_next[j][k] = -1e12;
            }
        }
        for(int j = 1; j <= N; j++){
            for(int k = 0; k < N; k++){
                dp[j][k] = dp_next[j][k];
            }
        }
    }
    cout << fixed << setprecision(10) << dp[1][0] << endl;
}


Measured memory_bytes: 7200
# すぬけくんはトレーニングが好きなので
# N 回だけトレーニングすることにしました。
# すぬけくんのトレーニング開始前のパワーは 1 です。
# すぬけくんが i 回目のトレーニングを終えるとパワーが i 倍されます。
# すぬけくんが N 回トレーニングをしたあとのパワーを求めなさい。
# ただし、答えの値は非常に大きな値になることがあるので 
# 10^9+7 で割ったあまりを出力してください。

# トレーニングの回数を取得
n = gets.chomp.to_i

# すぬけくんのパワーの初期値は1
power = 1

# トレーニングを実施
n.times do |i|
  power *= (i + 1)
  power %= (10 ** 9 + 7)
end

# 結果を出力
puts power

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define REP(i,n) for(long long i = 0;i < n;++i)
#define FOR(i,a,b) for(long long i = a;i < b;++i)
using namespace std;
using ll = long long;
using point = pair< int,int >;

int main(){
    int x, a, b;
    cin >> x >> a >> b;
    if (abs(x - a) < abs(x - b)) printf("A\n");
    else printf("B\n");
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
typedef pair<int, int> P;
struct edge{
    int to;
    int cap;
    int cost;
    int rev;
};
struct PDijk{
    int V;
    int INF;
    vector<int> pote, prevv, preve;
    vector<vector<edge>> G;
    PDijk(int N){
        V = N;
        INF = 1e9;
        G.resize(V);
        prevv.resize(V);
        preve.resize(V);
    }
    void add(int s, int t, int cap, int cost){
        edge e1 = {t, cap, cost, (int)G[t].size()};
        G[s].push_back(e1);
        edge e2 = {s, 0, -cost, (int)G[s].size() - 1};
        G[t].push_back(e2);
    }
    int solve(int s, int t, int f){
        int ans = 0;
        pote.resize(V, 0);
        while(f > 0){
            priority_queue<P, vector<P>, greater<P>> q;
            vector<int> d(V, INF);
            d[s] = 0;
            q.push(P(0, s));
            while(!q.empty()){
                P v = q.top();
                q.pop();
                if(d[v.second] < v.first) continue;
                int u = v.second;
                for(int i = 0; i < (int)G[u].size(); i++){
                    edge e = G[u][i];
                    if(e.cap > 0 && d[e.to] > d[u] - pote[e.to] + pote[u] + e.cost){
                        d[e.to] = d[u] - pote[e.to] + pote[u] + e.cost;
                        prevv[e.to] = u;
                        preve[e.to] = i;
                        q.push(P(d[e.to], e.to));
                    }
                }
            }
            if(d[t] == INF) return -1;
            for(int i = 0; i < V; i++) pote[i] += d[i];
            int temp = f;
            for(int i = t; i != s; i = prevv[i]){
                temp = min(temp, G[prevv[i]][preve[i]].cap);
            }
            f -= temp;
            ans += temp * pote[t];
            for(int i = t; i != s; i = prevv[i]){
                edge &e = G[prevv[i]][preve[i]];
                e.cap -= temp;
                G[i][e.rev].cap += temp;
            }
        }
        return ans;
    }
};
int main(){
    int N, E, F;
    cin >> N >> E >> F;
    PDijk pd(N);
    for(int i = 0; i < E; i++){
        int u, v, c, d;
        cin >> u >> v >> c >> d;
        pd.add(u, v, c, d);
    }
    int ans = pd.solve(0, N - 1, F);
    cout << ans << endl;
}


Measured memory_bytes: 3212
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n), c(n);
    for(int i=0; i<n; ++i)
        cin >> v[i];
    for(int i=0; i<n; ++i)
        cin >> c[i];

    int ans = 0;
    for(int i=0; i<n; ++i)
        ans += max(0, v[i] - c[i]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;

int a[100010];
ll dp[110][100010];
ll rec(int i,int j){

  if(j==0)return 1;
  if(j<0)return 0;
  if(i==-1)return 0;
  if(dp[i][j]!=-1)return dp[i][j];

  ll res=0;
  return dp[i][j]=(rec(i,j-1)+rec(i-1,j)-rec(i-1,j-a[i]-1)+2*mod)%mod;
}

int main(){
  int n,k;
  cin >>n >>k;
  rep(i,n)cin >> a[i];
  rep(i,n+1){
    rep(j,k+1)dp[i][j]=-1;
  }
  cout << rec(n-1,k) << endl;
}

Measured memory_bytes: 86784
x = []
n = int(input())
for i in range(n):
    x.append(sorted(list(input())))
x = sorted(x)
s = 0
su = 0

for i in range(0,n-1):
    if(x[i] == x[i+1]):
        s=s+1
        continue
    else:
        su += s*(s+1)//2
        s=0
su += s*(s+1)//2
print(su)

    

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

int main(){
    int n;cin>>n;int A[n];for(int i=0;i<n;i++)cin>>A[i];
    bool flg=1;
    int cnt=0;
    while(flg){
        flg=0;
        for(int j=n-1;j>0;j--){
            if(A[j]<A[j-1]){
                int tmp=A[j];
                A[j]=A[j-1];
                A[j-1]=tmp;
                flg=1;
                cnt+=1;
            }
        }
    }
    for(int i=0;i<n;i++){if(i==n-1)cout<<A[i]<<endl;else{cout<<A[i]<<' ';}}
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <vector>
#include <bitset>
#include <stack>
#include <iomanip>
#include <set>
#include <queue>
#include <map>


typedef long long ll;
typedef unsigned long long ull;
#define mk make_pair
#define mkt make_tuple
#define fi first
#define se second


using namespace std;
ll const MOD = 1e9 + 7;

ll binPow(ll a, ll n) {
	if (n == 1) return a;
	if (n % 2) return (a * (binPow(a, n - 1ll)%MOD)) % MOD;
	ll c = binPow(a, n / 2ll)%MOD;
	return (c * c) % MOD;
}

ll ans(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	ll num = 1ll;
	for (ll j = 1ll; j <= n; j++) {
		num *= j;
		num %= MOD;
	}

	ll den = 1ll;
	for (ll j = 1ll; j <= n - k; j++) {
		den *= j;
		den %= MOD;
	}
	for (ll j = 1ll; j <= k; j++) {
		den *= j;
		den %= MOD;
	}
	return (num * (binPow(den, MOD - 2ll) % MOD)) % MOD;
}

int main()
{
	ll n, k;
	cin >> n >> k;
	for (int i = 1; i <= k; i++) {
		ll curans = ans(n - k + 1ll, i);
		curans %= MOD;
		curans *= ans(k - 1ll, i - 1ll);
		curans %= MOD;
		cout << curans << endl;
	}
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
const int N = (int)(1*1e6+10);
int fen[N];
typedef long long ss;
int main()
{
    int i;
    char s;
    cin>>s;
    if(s>='A' && s<='Z')
        cout<<"A"<<endl;
    else cout<<"a"<<endl;
    return 0;
}


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

int min(int a,int b){
  if(a < b){
    return a;
  }
  return b;
}

int main(void){
  char s[100];
  scanf("%s", s);

  int N = strlen(s);
  int t[N];
  for (int i = 0; i < N; i++) {
    t[i] = s[i]-'a';
  }

  if(N == 1){
    printf("0\n");
    return 0;
  }
  for (int i = 0; i < N-1; i++) {
    if(t[i] != t[i+1]) break;
    if(i == N-2){
      printf("0\n");
      return 0;
    }
  }

  int ans = N+1;
  int past[N], next[N];
  for (int i = 0; i < 26; i++) {
    int cnt = 1;
    for (int j = 0; j < N; j++) {
      past[j] = t[j];
    }
    while(1){
      for (int j = 0; j < N-cnt; j++) {
        if(past[j] == i || (j+1 < N && past[j+1] == i)){
          next[j] = i;
        }else {
          next[j] = past[j];
        }
      }

      for (int j = 0; j < N-cnt; j++) {
        if(next[j] != i) break;
        if(j == N-cnt-1) ans = min(ans, cnt);
      }

      for (int j = 0; j < N-cnt; j++) {
        past[j] = next[j];
      }
      cnt++;
      if(N == cnt) break;
    }
  }

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

  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  int n; std::cin >> n;
  std::vector<int> p(n);
  for(auto& v: p) std::cin >> v;
  int ans = 0;
  for(int i = 1; i < n-1; ++i) {
    if((p[i] < p[i-1]) != (p[i] < p[i+1])) ++ans;
  }
  fin(ans);
  return 0;
}


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

int main() {
  int n, m, X, Y;
  cin >> n >> m >> X >> Y;
  int xs[n], ys[m];
  for (auto &x : xs) {
    cin >> x;
  }
  for (auto &y : ys) {
    cin >> y;
  }
  int l = *max_element(xs, xs + n);
  int r = *min_element(ys, ys + m);
  cout << ((l < r && X <= l && r <= Y) ? "No War" : "War") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
#include <map>
using namespace std;

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

	if (S.length() <= K) {
		cout << S << endl;
	}
	else {
		string ans = "";
		for (int i = 0; i < K; i++)
		{
			ans += S[i];
		}
		ans += "...";
		cout << ans << endl;
	}
}


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

int main() {
  int N;
  cin >> N;
  int i = 0;
  int sum = 0, l, r;
  while(i < N) {
    cin >> l >> r;
    sum += (r - l + 1);
    i++;
  }
  
  cout << sum << endl;
    
}

Measured memory_bytes: 256
n=int(input())
d={}

for i in range(n):
  s=input()
  if s in d:
    d[s]=d[s]+1
  else:
    d[s]=1
    
maxno=0
z=[]
for k,v in d.items():
  if maxno<v:
    maxno=v
    z=[k,]
  elif maxno==v:
    z.append(k)
z.sort()
for i in z:
  print(i)

 

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

using namespace std;

typedef long long ll;

int main(){
	int n;
	cin >> n;
	int a[n + 1];
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	int sol = 0;
	for(int i = 1; i <= n; i += 2){
		if(a[i] % 2)sol++;
	}
	cout << sol <<'\n';
}


Measured memory_bytes: 3596
def main():
    N = int(input())
    A = list(map(int,input().split()))
    #B = set(A)
    #C = len(B)
    if N == len(set(A)):
        print("YES")
    else:
        print("NO")
    # Uniqueにする
    # 　Aとlennを比較数
    # countsu

main()

Measured memory_bytes: 26808
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
#define all(x) (x).begin(),(x).end()


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

  string s;
  if(R < 1200) s = "ABC";
  else if(R < 2800) s = "ARC";
  else s = "AGC";

  cout << s << ln;
 }


Measured memory_bytes: 256
#pragma comment (linker, "/STACK:256000000")
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long a = 0;a < b;++a)
#define ALL(x) (x).begin(),(x).end()
void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}
unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
#define int ll
void solve() {
    int n;
    cin >> n;
    vector<pair<double, double>> inputs;
    REP(i, n) {
        double a, b;
        cin >> a >> b;
        inputs.pb(mp(a, b));
    }
    sort(ALL(inputs));
    long double ans = 0;
    long double cnt = 0;
    do {
        for (int i = 1; i < inputs.size(); ++i) {
            ans += sqrt(pow(inputs[i].first - inputs[i - 1].first, 2) + pow(inputs[i].second - inputs[i - 1].second, 2));
        }
        cnt++;
    } while (next_permutation(ALL(inputs)));
    cout << ans / cnt << endl;
}
#undef int
int main() {
    init();
    solve();
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
     
     int S,h,m,s;
     cin >> S;
     
     h = S/3600;
     m = (S % 3600) / 60;
     s = S % 60;
     
     cout << h << ":" << m << ":" <<s << endl;
     
     return 0;
    
}



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

int main(){
  int a[5],b[5],c[5];

  for(int i=0; i<5; i++){
    cin>>a[i];
    b[i]=a[i]%10;
    if(b[i]==0){
      c[i]=a[i]/10;
      b[i]=9;
    }else c[i]=a[i]/10+1;
  }

  int ans=0;
  if(min({b[0], b[1], b[2], b[3], b[4]})==b[0])ans=a[0]+(c[1]+c[2]+c[3]+c[4])*10;
  else if(min({b[0], b[1], b[2], b[3], b[4]})==b[1])ans=a[1]+(c[0]+c[2]+c[3]+c[4])*10;
  else if(min({b[0], b[1], b[2], b[3], b[4]})==b[2])ans=a[2]+(c[1]+c[0]+c[3]+c[4])*10;
  else if(min({b[0], b[1], b[2], b[3], b[4]})==b[3])ans=a[3]+(c[1]+c[2]+c[0]+c[4])*10;
  else if(min({b[0], b[1], b[2], b[3], b[4]})==b[4])ans=a[4]+(c[1]+c[2]+c[3]+c[0])*10;
  
  cout<<ans<<endl;
  
      
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();

		// 出力
    if(a>=30){
		System.out.println("Yes");
  }else{
    System.out.println("No");
  }
	}
}



Measured memory_bytes: 35652
class dice:
    def __init__(self,dice):
        self.dice = dice

    def roll_n(self):
        d = self.dice
        self.dice = [d[1],d[5],d[2],d[3],d[0],d[4]]

    def roll_e(self):
        d = self.dice
        self.dice = [d[3],d[1],d[0],d[5],d[4],d[2]]

    def roll_s(self):
        d = self.dice
        self.dice = [d[4],d[0],d[2],d[3],d[5],d[1]]
    
    def roll_w(self):
        d = self.dice
        self.dice = [d[2],d[1],d[5],d[0],d[4],d[3]]

    def top(self):
        return self.dice[0]

    def roll(self,command):
        if command=='N':self.roll_n()
        if command=='E':self.roll_e()
        if command=='S':self.roll_s()
        if command=='W':self.roll_w()

    def same(self,b):
        com1 = 'SSSWSSSE'
        com2 = 'WWWW'
        for c in com1:
            if self.dice[1]==b.dice[1]:break
            if c=='E':return False
            b.roll(c)
        for c in com2:
            if self.dice==b.dice:return True
            b.roll(c)
        return False

def main():
    a = dice(list(map(int,input().split())))
    b = dice(list(map(int,input().split())))
    if a.same(b):print('Yes')
    else        :print('No')

if __name__ == '__main__':
    main()




Measured memory_bytes: 5608
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int D;
	cin >> D;
	
	cout << "Christmas";
	for(int i=0; i<25-D; i++){
		cout << " Eve";
	}
	cout << endl;
	return 0;
}


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




int n;


void solve()
{
	bool ok=false;
	long long  total[4000];
	bool check[4000];
	memset(check,false,sizeof(check));
	memset(total,0,sizeof(total));
	for(int i=0;i<n;i++){
		long long  num,a,b;
		cin>>num>>a>>b;
		total[num]+=a*b;
		if(total[num]>=1000000 && !check[num]){
			cout<<num<<endl;
			check[num]=true;
			ok=true;
		}
	}
	if(!ok) cout<<"NA"<<endl;
}

int main()
{
	while(cin>>n){
		if(n==0) break;
		solve();
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();     
        int N = r.i();
        int people = 0;
        for(int i = 0; i < N; i++){
            int[] a = r.ii();
            people += a[1]-a[0]+1;
        }
        println(people);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 23764
import math

n = int(input())
limit = int(math.sqrt(n))
ansi = 0
exp = [1]
i = 2
beki = 1
while i <= limit:
    temp = i**beki
    if temp <= n:
        exp.append(temp)
        beki += 1
    else:
        beki = 1
        i += 1

exp.sort()
print(str(exp[-1]))

Measured memory_bytes: 3188
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector <int> a(n);
    for(int i=0;i<n;++i) cin >> a[i];
    
    int cnt=0;
    
    for(int i=0;i<n-1;++i){
        for(int j=0;j<n-i-1;++j){
            if(a[j]>a[j+1]){
                a[j]^=a[j+1]^=a[j]^=a[j+1];
                cnt++;
            }
        }
    }
    
    cout << a[0];
    for(int i=1;i<n;++i) cout <<" " << a[i];
    cout << endl;
    cout << cnt << endl;
}


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

int main()
{
	int N;
	string S;

	cin >> N >> S;

	int ans = 1;

	for (int i = 1; i < N; i++)
	{
		if (S[i] != S[i - 1])
		{
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


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

int32_t main() {
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    while(k--){
        
        if(b<=a){
            b=b*2;
        }
        else if(c<=b){
            c=c*2;
        }
    }
   
    if(c>b && b>a){
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
   
    string a,b,c;
    cin>>a>>b>>c;
    
    if(a[a.length()-1]==b[0] && b[b.length()-1]==c[0]){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    
    
    
    return 0;
}






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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

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

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	
	ll n,d;
	cin >> n >> d;

	vector<ll> x(n),y(n);
	rep(i,n){
		cin >> x[i] >> y[i];
	}

	int ans = 0;
	rep(i,n){
		if(x[i] * x[i] + y[i] * y[i] <= d * d) ans++;
	}

	cout << ans << endl;

}

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

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

#define MAXN 200007

int n ;
int a[ MAXN ] ;

void input ( ) {
    cin >> n ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        cin >> a[ i ] ;
        a[ i ] = - a[ i ] ;
    }
    sort ( a + 1 , a + n + 1 ) ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        a[ i ] = - a[ i ] ;
    }
}

void solve ( ) {
    long long ans = a[ 1 ] ;
    int pos = 2 ;
    int lft = 2 ;
    for ( int i = 3 ; i <= n ; ++ i ) {
        ans += a[ pos ] ;
        -- lft ;
        if ( lft == 0 ) {
            lft = 2 ; ++ pos ;
        }
    }
    cout << ans << "\n" ;
}


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


Measured memory_bytes: 4424
#include<bits/stdc++.h>
using namespace std;
int freq[10004];
char str[200005];
int main()
{
    int n, p;
    scanf("%d %d %s", &n, &p, str);
    long long res= 0;
    if(p==2)
    {
        for(int i=n-1; i>=0; i--)
        {
            if(!((str[i]-'0')&1))freq[0]++;
            res+= freq[0];
        }
    }
    else if(p==5)
    {
        for(int i=n-1; i>=0; i--)
        {
            if(str[i]=='5' || str[i]=='0')freq[0]++;
            res+= freq[0];
        }
    }
    else
    {
        freq[0]= 1;
        int mul= 1, rem= 0;
        for(int i=n-1; i>=0; i--)
        {
            rem= ((str[i]-'0')*mul + rem)%p;
            res+= freq[rem];
            freq[rem]++;
            mul*= 10;
            mul%= p;
        }
    }
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;


int main(){
	int N;
	map<long long, int> mp;
	vector<long long> v;

	scanf("%d", &N);
	for(int i=0;i<N;i++){
		long long a;
		scanf("%lld", &a);

		if(mp.count(a)==0){
			mp[a] = 1;
			v.push_back(a);
		}else{
			mp[a]++;
		}
	}

	long long ans = 0;
	for(int i=0;i<v.size();i++){
		long long tmp;
		if(mp[v[i]]<v[i]){
			tmp = mp[v[i]];
		}else{
			tmp = mp[v[i]] - v[i];
		}
		ans += tmp;
		//printf("tmp: %lld\n", tmp);
	}

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

	return 0;
}


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

int main()
{
	int s;
	cin >> s;
	auto memo = map<int, int>();
	memo.insert(make_pair(s, 1));
	int p = 2;
	while(1){
		if(s % 2 == 0) s /= 2;
		else s = 3 * s + 1;
		auto q = memo.insert(make_pair(s, p));
		if(!q.second){
			cout << p << endl;
			break;
		}
		++p;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
struct edge{ ll to; ll cap; ll rev;};
const ll MAXN=105;
vector<edge> G[MAXN];

bool used[MAXN];

void addEdge0(ll from, ll to, ll cap){
    edge A={to,cap,(ll)G[to].size()};
    edge B={from,0,(ll)G[from].size()};
    G[from].push_back(A);
    G[to].push_back(B);
    return;
}//有向グラフを作る

void addEdge1(ll a, ll b, ll cap){
    edge A={b,cap,(ll)G[b].size()};
    edge B={a,cap,(ll)G[a].size()};
    G[a].push_back(A);
    G[b].push_back(B);
    return;
}//無向グラフを作る

ll dfs(ll v, ll t, ll f){
    if(v==t) return f;
    used[v]=true;
    rep(i,G[v].size()){
        edge &e=G[v][i];
        if(!used[e.to] && e.cap>0){
            ll d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}

ll MaxFlow(ll Start, ll Goal){
    ll ans=0;
    while(true){
        rep(i,MAXN) used[i]=false;
        ll P=dfs(Start,Goal,INF);
        if(P==0) break;
        ans+=P;
    }
    return ans;
}

int main(){
    ll N; cin>>N;
    ll SUM=0;
    REP(i,1,N+1){
        ll x; cin>>x;
        if(x<=0) addEdge0(102,i,-x);
        if(x>0) {addEdge0(i,103,x); SUM+=x;}
    }

    REP(i,1,N){
        ll K=2*i;
        while(K<=N) {
            addEdge0(i,K,INF);
            K+=i;
        }
    }
    cout<<SUM-MaxFlow(102,103)<<endl;

    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  int souwa = A;
  for (int i = 1; i <= B; i++)
  {
    if ((souwa % B) == C)
    {
      // 総和をBで割った余りがCなら終了
      cout << "YES" << endl;
      return 0;
    }
    // 総和にAを加算
    souwa += A;
  }
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define print(x) cout << x << "\n"
#define print2(x, y) cout << x << " " << y << "\n"
#define printv(vec) rep(lp, vec.size()) cout << vec[lp] << " "; print(""); 
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;

const int mod = 1000000007;
class mint {
public:
    ll x;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res /= a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

ll modpow(ll a, ll n){
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

void Main(){

	string s;
	cin >> s;
	
	if(s[s.size() - 1] == 's') print(s + "es");
	else print(s + 's');

}

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	Main();
	return 0;
	
}





Measured memory_bytes: 3668
N,M=list(map(int,input().split()))
 
S=[]
s=0
for m in range(M):
    e = int(input())
    S.append(list(range(s,e)))
    s = e+1

e = int(N+1)
S.append(list(range(s,e)))
 
fibo=[0,1]
for n in range(2,N+2):
    fibo.append(fibo[n-2]+fibo[n-1])
    
ans=1
for s in S:
    ans=ans*fibo[len(s)]
print(ans%1000000007)

Measured memory_bytes: 521168
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();
		int c[]=new int[26];
		int s[][] = new int[D][26];
		for (int i = 0; i < 26; i++) {
			c[i]=sc.nextInt();
		}
		for (int i = 0; i < D; i++) {
			for (int j = 0; j < 26; j++) {
				s[i][j]=sc.nextInt();
			}
		}
		int mannzokudo = 0;
		int last[]=new int[26];
		for (int i = 0; i <26; i++) {
			last[i]=0;
		}
		for (int d = 1; d <D+1; d++) {
			int test = 0;
			for(int t=0;t<26;t++){
				int mannzokudotest=0;
				int lasttest[]=last.clone();
				mannzokudotest=mannzokudotest+s[d-1][t];
				lasttest[t]=d;
				for (int j = 0; j < 26; j++) {
					mannzokudotest=mannzokudotest-c[j]*(d-last[j]);
				}
				if(t==0){mannzokudo=mannzokudotest;}
				if(mannzokudotest>mannzokudo){
					mannzokudo=mannzokudotest;
					test=t;}
				lasttest=last;
				}
			System.out.println(""+(test+1));
			last[test]=d;
			mannzokudo=0;
		}
	}
}

Measured memory_bytes: 49496
#Rs,Gs,Bs,Ns= input().split()
#R=int(Rs)
#G=int(Gs)
#B=int(Bs)
#N=int(Ns)
#ans=0
#sub_ans=0
#while(sub_ans>=N):

ans=0
f_a=0
b_b=0
a_b=0
str_list=[]
N= int(input())
for i in range(N):
    str=input()
    ans=ans+str.count("AB")
    if(str[-1]=="A"):
        f_a=f_a+1
    if(str[0]=="B"):
        b_b=b_b+1
    if(str[-1]=="A"and str[0]=="B"):
        a_b=a_b+1

if(f_a==N and b_b==N):
    ans=ans+N-1
elif((f_a==a_b)and(b_b==a_b)and(f_a!=0)):
    ans=ans+f_a-1
elif(f_a< b_b):
    ans=ans+f_a
else:
    ans=ans+b_b

#print(f_a)
#print(b_b)
print(ans)


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

int main(){
	map<int,bool> mp;
	map<int,bool>::iterator it1, it2;
	for(int i = 0; i < 144; ++i)
	for(int j = 0; j < 144; ++j){
		int t = i * i + j * j;
		if(t > 1 && t < 20000) mp[t] = true;
	}

	for(it1 = mp.begin(); it1 != mp.end(); ++it1){
		if(it1->second){
			for(it2 = it1; it2 != mp.end(); ++it2){
				int t = it1->first * it2->first;
				if(t >= 20000) break;
				mp[t] = false;
			}
		}
	}

	int a, n, m;
	cin >> a;
	for(int i = 0; i < a; ++i){
		cin >> n >> m;
		cout << (mp[n * n + m * m] ? "P\n" : "C\n");
	}
}

Measured memory_bytes: 1400
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
ll f[5000001], invf[5000001];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
int main()
{
	int n;
	cin>>n;
	ll x[100010];
	ll s[100010];
	s[0]=0;
	for(int i=0; i<n; i++){
		cin>>x[i];
		s[i+1]=(s[i]+x[i])%MOD;
	}
	ll ans=0;
	for(int d=1; d<=n-2; d++){
		(ans+=(s[n-1]-s[d]-s[n-1-d]+MOD+MOD)%MOD*inv((ll)d*(d+1)%MOD))%=MOD;
	}
	for(int i=0; i<n-1; i++){
		(ans+=(x[n-1]-x[i]+MOD)*inv(n-i-1))%=MOD;
	}
	for(int i=1; i<n; i++){
		(ans*=i)%=MOD;
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 1792
use proconio::*;
use std::cmp::*;

// 割っていく方針

#[fastout]
fn run() {
    input! {
        t: usize,
        ask: [(i64, i64, i64, i64, i64); t],
    }
    for (n, a, b, c, d) in ask {
        let mut map = std::collections::BTreeMap::<i64, i64>::new();
        let mut h = std::collections::BinaryHeap::<Reverse<(i64, i64)>>::new();
        let mut ans = std::i64::MAX;
        map.insert(n, 0i64);
        h.push(Reverse((0i64, n)));
        while let Some(Reverse((x, v))) = h.pop() {
            if x > *map.get(&v).unwrap() {
                continue;
            }
            ans = std::cmp::min(ans, x.saturating_add(v.saturating_mul(d)));
            for &(cost, div) in [(a, 2i64), (b, 3i64), (c, 5i64)].iter() {
                let y = v / div;
                for &y in [y, y + 1].iter() {
                    let dis = (v - y * div).abs();
                    let x = x.saturating_add(dis.saturating_mul(d)).saturating_add(cost);
                    let po = map.entry(y).or_insert(std::i64::MAX);
                    if *po > x {
                        *po = x;
                        h.push(Reverse((x, y)));
                    }
                }
            }
        }
        println!("{}", ans);
    }
}

fn main() {
    run();
}


Measured memory_bytes: 2824
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

ll rep_pow(ll a, ll b){//繰り返し2乗法
    if(b==0) return 1;
    else if(b%2==0){
        ll memo = rep_pow(a, b/2);
        return memo*memo%mod;
    }else{
        return rep_pow(a, b-1)*a%mod;
    }
}

ll nCr(ll n, ll r){//mod逆元使ったnCr
    ll ret=1;
    rep(i,r){
        ret *= n-i;//分子
        ret %= mod;
        ret *=rep_pow(r-i, mod-2);//mod逆元によりr!で割ると同値
        ret %= mod;
    }
    return ret;
}
ll gcd(ll a, ll b){ if(b==0) return a; return gcd(b, a%b);}

int counter(int x){
    if(x==0) return 0;
    return counter(x>>1)+(x&1);
}


int main(){
    fast_io

    string s;
    cin>>s;
    int a=s[0]-'0', b=s[1]-'0', c=s[2]-'0', d=s[3]-'0';

    if(a+b+c+d == 7) printf("%d+%d+%d+%d=7", a, b, c, d);
    else if(a+b+c-d == 7) printf("%d+%d+%d-%d=7", a, b, c, d);
    else if(a+b-c+d == 7) printf("%d+%d-%d+%d=7", a, b, c, d);
    else if(a-b+c+d == 7) printf("%d-%d+%d+%d=7", a, b, c, d);
    else if(a-b-c+d == 7) printf("%d-%d-%d+%d=7", a, b, c, d);
    else if(a-b-c-d == 7) printf("%d-%d-%d-%d=7", a, b, c, d);
    else if(a+b-c-d == 7) printf("%d+%d-%d-%d=7", a, b, c, d);
    else if(a-b+c-d == 7) printf("%d-%d+%d-%d=7", a, b, c, d);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
 
int main(){
    int a, b;
    int h, m;
    cin >> a >> b >> h >> m;
    long double theta;
 
   
    //theta = 2.0*M_PI*((long double)h/12.0 + ((long double)m/60.0)/12.0 - (long double)m/60.0);
    long double arg = abs(30.0*(long double)h + 30.0*(long double) m/60.0 - 6.0*(long double)m);
    theta = min(arg, 360-arg);
    
    long double c = sqrtl((long double)(a*a + b*b) - (long double)(2.0*a*b)*cosl(2*M_PI*theta/360.0));
 
    printf("%.10Lf\n", c);
    //cout << c << endl;
 
    return 0;
 
}

Measured memory_bytes: 4156
#include<stdio.h>
#include<math.h>

typedef struct{
  double x;
  double y;
} Zahyou;

void don(int n,Zahyou a,Zahyou b){
  Zahyou c,d,e;
  double t=M_PI*60.0/180.0;
  
  if(n==0) return;

  c.x=(2.0*a.x+1.0*b.x)/3.0;
  c.y=(2.0*a.y+1.0*b.y)/3.0;
  d.x=(1.0*a.x+2.0*b.x)/3.0;
  d.y=(1.0*a.y+2.0*b.y)/3.0;
  e.x=(d.x-c.x)*cos(t)-(d.y-c.y)*sin(t)+c.x;
  e.y=(d.x-c.x)*sin(t)+(d.y-c.y)*cos(t)+c.y;

  don(n-1,a,c);
  printf("%.8f %.8f\n",c.x,c.y);

  don(n-1,c,e);
  printf("%.8f %.8f\n",e.x,e.y);

  don(n-1,e,d);
  printf("%.8f %.8f\n",d.x,d.y);

  don(n-1,d,b);

}

int main(){
  Zahyou a,b;
  int n;

  scanf("%d",&n);

  a.x=0;
  a.y=0;
  b.x=100;
  b.y=0;

  printf("%.8f %.8f\n",a.x,b.y);

  don(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);

  return 0;
}

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

#ifndef DEBUG
#define endl '\n'
#define debug(...)
#else
#define debug(...) __VA_ARGS__
#endif
#define debugf(...) debug(printf(__VA_ARGS__);)

const int N = 1e5 + 5;

int p[N], s[N], a[N];

int (((((main)))))() <%
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

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

    p[0] = a[0];
    for (int i = 1; i < n; i++) {
        p[i] = p[i-1] + a[i];
    }

    for (int i = n-1; i >= 0; i--) {
        s[i] = s[i+1] + a[i];
    }

    int ans = 1e9;
    for (int i = 0; i < n; i++) {
        ans = min(ans, abs(p[i] - s[i+1]));
    }

    cout << ans << endl;

    return 0;
%>

Measured memory_bytes: 256
using System.Collections.Generic;
using System.Linq;
using System;

public class P
{
    public List<int> to { get; set; }
    public int d { get; set; }
}

public class P2
{
    public int from { get; set; }
    public int to { get; set; }
}

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var ps = new P[n];
        for (int i = 0; i < n; i++) ps[i] = new P { to = new List<int>(), d = -1 };
        for (int i = 0; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line[0]) - 1;
            var b = int.Parse(line[1]) - 1;
            ps[a].to.Add(b);
            ps[b].to.Add(a);
        }
        goBfs(n, m, ps);
    }
    static void goBfs(int n, int m, P[] ps)
    {
        var ans = new int[n - 1];
        var q = new Queue<P2>();
        ps[0].d = 0;
        foreach (var x in ps[0].to)
            q.Enqueue(new P2 { from = 0, to = x });
        while (q.Count() > 0)
        {
            var w = q.Dequeue();
            if (ps[w.to].d == -1)
            {
                ps[w.to].d = ps[w.from].d + 1;
                ans[w.to - 1] = w.from + 1;
                foreach (var x in ps[w.to].to)
                    if (ps[x].d == -1) { q.Enqueue(new P2 { from = w.to, to = x }); }
            }
        }
        Console.WriteLine("Yes");
        Console.WriteLine(string.Join("\n", ans));
    }
}



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

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

const int N=2e5+100;

int a[N];

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

    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    int lo=1,hi=2e9;
    while(lo<hi)
    {
        int mi=(lo+hi)/2;
        int need=0;
        for(int i=1;i<=n;i++)
            need+=(a[i]-1)/mi;
        if(need>k)
            lo=mi+1;
        else
            hi=mi;
    }
    cout<<lo;
}


Measured memory_bytes: 5172
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 2000000

int main(){
  int n,m;
  cin>>n>>m;
  int data[MAX],dis[MAX];
  for(int i=0;i<m;i++){
    cin>>data[i];
  }
  sort(data,data+m);
  for(int i=1;i<m;i++){
    dis[i-1]=data[i]-data[i-1];
  }
  sort(dis,dis+m-1);
  int ans=0;
  for(int i=0;i<m-n;i++){
    ans+=dis[i];
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 4608
n = int(input())
s = input()

e = s[1:].count('E')
w = 0
a = e+w
for i in range(1,n):
    if s[i] == 'E':
        e -= 1
    if s[i-1] == 'W':
        w += 1
    a = min(a, e+w)
print(a)


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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int n;
  cin >> n;
  int ans = n/3;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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(0);
  int n, m;
  string s;
  cin >> n >> m >> s;
  vector<int> ans;
  int now = s.size()-1;
  while (now) {
    for (int i = m; i >= 0; i--) {
      if (!i) {
        cout << -1 << endl;
        return 0;
      }
      if (now-i >= 0 && s[now-i] == '0') {
        now -= i;
        ans.push_back(i);
        break;
      }
    }
  }
  reverse(ans.begin(), ans.end());
  rep(i, ans.size())
    cout << ans[i] << (i+1<ans.size()?' ':'\n');
  return 0;
}

Measured memory_bytes: 1096
n = int(input())
t_s = []
for i in range(n):
    a , b = map(int, input().split())
    t_s += [(b, a)]
t_s.sort()
Sum = 1
i = 1
t_now = t_s[0][0]
while i <= n-1:
    for a in t_s[i:]:
        i = i + 1
        if t_now < a[1]:
            Sum += 1
            t_now = a[0]
            
print(Sum)


Measured memory_bytes: 19880
from itertools import permutations
A = list(map(int, input().split()))
p = permutations([0, 1, 2])
ans = 10**9
for pi in p:
    t0 = pi[0]
    t1 = pi[1]
    t2 = pi[2]
    tmp = abs(A[t1] - A[t0]) + abs(A[t2] - A[t1])
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 61948
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int n;
struct edge{int to,cost;};
typedef pair<int,int> P;
const int MAX_V=2010;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s){
  priority_queue<P,vector<P>,greater<P> > que;
  fill(d,d+n,inf);
  d[s]=0;
  que.push(P(0,s));

  while(!que.empty()){
    P p=que.top();que.pop();
    int v=p.second;
    if(d[v]<p.first) continue;
    for(int i=0;i<G[v].size();i++){
      edge e=G[v][i];
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;
        que.push(P(d[e.to],e.to));
      }
    }
  }
}

int main(){
  int x,y; cin >> n >> x >> y;
  x--; y--;
  rep(i,n-1){
    G[i].push_back({i+1,1});
    G[i+1].push_back({i,1});
  }
  G[x].push_back({y,1});
  G[y].push_back({x,1});
  vector<int> ans(n);
  rep(i,n){
    dijkstra(i);
    rep(j,n){
      ans[abs(d[i]-d[j])]++;
    }
  }
  for(int i=1;i<n;i++){
    cout << ans[i]/2 << endl;
  }  
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10 , OO = 0x3f3f3f3f;

#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define xloop(i,a,b) for(int i = int(a);i <= int(b);i++)
#define range(vec) for(auto &x : vec) cin >> x;
#define ALL(v) ((v).begin()) , ((v).end())
#define SZ(v)  ((int)((v).size()))
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);




int main()
{

    #ifndef ONLINE_JUDGE
        //freopen("in.in", "r", stdin);
        //freopen("out.in", "w", stdout);
    #endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);



	 string S; 
	 cin >> S;
    if (S[0] == S[1] && S[1] == S[2])
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N, M;
	while (cin >> N >> M, N) {
		vector<vector<int> > G(N);
		for (int i = 0; i < M; ++i) {
			int a, b;
			cin >> a >> b; --a, --b;
			G[a].push_back(b);
			G[b].push_back(a);
		}
		int inibit = 0;
		for (int i = 0; i < N; ++i) {
			int x;
			cin >> x;
			inibit |= x << i;
		}
		vector<int> op(N);
		for (int i = 0; i < N; ++i) {
			int c;
			cin >> c;
			for (int j = 0; j < c; ++j) {
				int x;
				cin >> x; --x;
				if (x != i) op[i] |= 1 << x;
			}
		}
		vector<vector<int> > dist(1 << N, vector<int>(N, -1));
		vector<vector<pair<int, int> > > pre(1 << N, vector<pair<int, int> >(N));
		queue<pair<int, int> > que;
		if (inibit & 1) {
			dist[inibit][0] = 0;
			que.push(make_pair(inibit, 0));
		}
		while (!que.empty()) {
			pair<int, int> u = que.front(); que.pop();
			int bit = u.first, pos = u.second;
			for (int i : G[pos]) {
				if (((bit >> i) & 1) && dist[bit][i] == -1) {
					dist[bit][i] = dist[bit][pos] + 1;
					pre[bit][i] = make_pair(bit, pos);
					que.push(make_pair(bit, i));
				}
			}
			for (int i = 0; i < N; ++i) {
				if (((op[pos] >> i) & 1) && dist[bit ^ (1 << i)][pos] == -1) {
					dist[bit ^ (1 << i)][pos] = dist[bit][pos] + 1;
					pre[bit ^ (1 << i)][pos] = make_pair(bit, pos);
					que.push(make_pair(bit ^ (1 << i), pos));
				}
			}
		}
		if (dist[1 << (N - 1)][N - 1] == -1) {
			bool escape = false;
			for (int i = 0; i < 1 << N; ++i) {
				if (dist[i][N - 1] != -1) {
					escape = true;
					break;
				}
			}
			cout << (escape ? "You can not switch off all lights." : "Help me!") << endl;
		}
		else {
			cout << "You can go home in " << dist[1 << (N - 1)][N - 1] << " steps." << endl;
			pair<int, int> cur = make_pair(1 << (N - 1), N - 1);
			vector<pair<int, int> > path = { cur };
			while (cur != make_pair(inibit, 0)) {
				cur = pre[cur.first][cur.second];
				path.push_back(cur);
			}
			reverse(path.begin(), path.end());
			vector<pair<string, int> > ans;
			for (int i = 1; i < path.size(); ++i) {
				if (path[i - 1].second != path[i].second) {
					ans.push_back(make_pair("move", path[i].second));
				}
				else {
					int diff = -1;
					for (int j = 0; j < N; ++j) {
						if (((path[i - 1].first >> j) & 1) != ((path[i].first >> j) & 1)) {
							diff = j;
							break;
						}
					}
					if ((path[i - 1].first >> diff) & 1) {
						ans.push_back(make_pair("off", diff));
					}
					else {
						ans.push_back(make_pair("on", diff));
					}
				}
			}
			for (int i = 0; i < ans.size(); ++i) {
				for (int j = 1; j < ans.size(); ++j) {
					if (ans[j - 1].first != "move" && ans[j].first != "move" && ans[j - 1].second > ans[j].second) {
						swap(ans[j - 1], ans[j]);
					}
				}
			}
			for (pair<string, int> i : ans) {
				if (i.first == "move") {
					cout << "Move to room " << i.second + 1 << "." << endl;
				}
				else if (i.first == "off") {
					cout << "Switch off room " << i.second + 1 << "." << endl;
				}
				else {
					cout << "Switch on room " << i.second + 1 << "." << endl;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 10980
#include <iostream>
#include<vector>

#include <algorithm>


using namespace std;






int main (){
int n,k,q;
  int t;

  cin>>n;
  cin>>k;
  cin>>q;
  
vector<int> vec(n);  
vector<int> ans(q);
  
for(int i=0; i<vec.size(); i++){
    vec.at(i)=k-q;

}
  
  
 for(int i=0; i<ans.size(); i++){
    cin>>ans.at(i);

} 
  
   
 for(int i=0; i<ans.size(); i++){
   t= ans.at(i);


 vec.at(t-1)=vec.at(t-1)+1;
 
 
 
 } 
for(int i=0; i<vec.size(); i++){

   if( vec.at(i)>0)cout<<"Yes"<<endl;
	else{cout<<"No"<<endl;}
}  
  
  
}


Measured memory_bytes: 1408