akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll c=0;
    for(int i=0;i<n-2;i++)
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
        c++;
    cout<<c;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;
using pii = pair<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}
int binary_search_index(Int Y, vi &q){
    int left = 0, right = q.size() - 1;
    while (right >= left) {
        int mid = left + (right - left) / 2;
        if (q[mid] == Y) return mid;
        else if (q[mid] > Y) right = mid - 1;
        else if (q[mid] < Y) left = mid + 1;
    }
    return -1;
}


Int combination(Int n, Int r) {
    if(n == 1){return 0;}
    if ( r * 2 > n ) r = n - r;
    uintmax_t dividend = 1;
    uintmax_t divisor  = 1;
    for ( unsigned int i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return dividend / divisor;
}

int main() {
    Int N;
    Int ans =0;
    cin >> N;
    vector<Int> v = vector<Int>(N-1);

    rep(i,N-1){
        cin>>v[i];
    }

    if (N==2){
        cout << v[0]*2 << endl;
        return 0;
    }

    vi A = vi(N,inf);

    rep(i,N-1){
        Int b = v[i];
        A[i] = min(A[i],b);
        A[i+1] = min(A[i+1],b);
    }

    A[N-1]=v[N-2];

    rep(i,N){
        ans += A[i];
    }

    cout << ans << endl;

    return 0;
}

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

bool check(int n,int d[]) {
  while (n>0) {
    if (d[n%10]!=0) {
      return false;
    }
    n/=10;
  }
  return true;
}
int main() {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int N,K;
  cin>>N>>K;
  int D[10];
  memset(D,0,sizeof(D));
  for (int i=0; i<K; i++) {
    int d;
    cin>>d;
    D[d]=1;
  }
  int ans=N;
  while (!check(ans,D)) {
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)1e9+7)

int dir_h[]={-1,0,0,1};
int dir_w[]={0,-1,1,0};

int main(){
	int h, w;
	cin >> h >> w;
	char s[h][w];
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cin >> s[i][j];
		}
	}

	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(s[i][j]=='.') continue;
			int cnt=0;
			for(int m=0; m<4; m++){
				if(i+dir_h[m]<0 || i+dir_h[m]>=h || j+dir_w[m]<0 || j+dir_w[m]>=w) continue;
				if(s[i+dir_h[m]][j+dir_w[m]]=='#') cnt++;
			}
			if(cnt==0){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
from typing import List


def main():
    h, w = map(int, input().split())
    g = []
    for _ in range(h):
        gg = list(input())
        g.append(gg)
    print(gr(h, w, g))


def gr(h: int, w: int, g: List[List[str]]) -> int:
    m = [[-1] * w for _ in range(h)]
    q = deque([(0, 0)])
    m[0][0] = 0
    while q:
        x, y = q.popleft()
        for nx, ny in [(x + 1, y), (x, y + 1), (x - 1, y), (x, y - 1)]:
            if (0 <= nx <= w - 1 and 0 <= ny <= h - 1) and g[ny][nx] == "." and m[ny][nx] < 0:
                m[ny][nx] = m[y][x] + 1
                if nx == w - 1 and ny == h - 1:
                    break
                q.append((nx, ny))

    if m[h - 1][w - 1] < 0:
        return -1
    return sum(gg.count(".") for gg in g) - m[h - 1][w - 1] - 1


if __name__ == "__main__":
    main()


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

using namespace std;
#define ll long long int
#define all(x) x.begin(), x.end()
ll dp[5007][5007];
pair<int,int> a[5007];
int main()
{
    int n;
    cin >> n;
    //vector<pair<int,int>> a(n+1);
    for(int i=1;i<=n;i++){
        cin >> a[i].first;
        a[i].second = i;
    }
    ll ans = 0;
    sort(a+1,a+n+1);
    for(int len = n; len>=1;len--){
        for(int st = 1; st+len-1<=n;st++){
            if(len==1){
                ans = max(ans, dp[st][st]+1ll*a[len].first*abs(a[len].second-st));
            }
            else{
                dp[st+1][st+len-1] = max(dp[st+1][st+len-1], dp[st][st+len-1]+1ll*a[len].first*abs(a[len].second-st));
                dp[st][st+len-2] = max(dp[st][st+len-2], dp[st][st+len-1]+1ll*a[len].first*abs(a[len].second-(st+len-1)));
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 27244
#include <bits/stdc++.h>
#define LL long long
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Re(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define REP(I, N) for (int I = 0; I < (N); I++)
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define SZ(a) ((int)a.size())
#define endl "\n"
//#pragma GCC optimize(2)
using namespace std;
const int N=1e3+1;
const int M=1e9+7;
const double eps=1e-6;
typedef complex<double>C;
const double PI(acos(-1.0));
//__gcd, atan2(y,x)=y/x , __int128
//c(n,k)=c(n-1,k-1)+c(n-1,k)
//c(i,r),i for r to n =c(n+1,r+1)
//void add(int x){while(x<N)BIT[x]++,x+=x&-x;}
//int sum(int x){return x?BIT[x]+sum(x-(x&-x)):0;}
//int find(int x){return x==p[x]?x:p[x]=find(p[x]);}
//LL pw(LL a, LL b,LL M) { return b ? b & 1 ? a*pw(a, b - 1,M) % M : pw(a*a%M, b>>1,M) : 1; }
//log() = ln() , log(x)/log(y)=log(y)-base-x
//INT_MAX 127,INT_MIN 128
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
int n,m,a,b;
char p[N][N];
int main(){
	cin>>n>>m>>a>>b;
	FOR(i,1,n)FOR(j,1,m)p[i][j]='.';
	for(int i=1;m&1&&i<n&&b>0;i+=2)
		p[i][m]='^',p[i+1][m]='v',b--;
	if(b&1&&n&1&&m>=3&&n>=2)
		p[n-1][m-2]='^',p[n][m-2]='v',b--;
	FOR(i,1,n-1)
		for(int j=1;j<=m-(m&1)&&b>0;j++)
			if(p[i][j]=='.'&&p[i+1][j]=='.')
				p[i][j]='^',p[i+1][j]='v',b--;
	if(b){
		cout<<"NO"<<endl;return 0;
	}
	FOR(i,1,n)
		for(int j=1;j<m&&a>0;j++)
			if(p[i][j]=='.'&&p[i][j+1]=='.')
				p[i][j]='<',p[i][j+1]='>',a--;
	if(a){
		cout<<"NO"<<endl;return 0;
	}
	cout<<"YES\n";
	FOR(i,1,n){
		FOR(j,1,m)cout<<p[i][j];
		cout<<endl;
	}
}

Measured memory_bytes: 2176
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int top;
int s[1000];

void Push( int x ) {	
    s[++top] = x; 
}

int Pop() {
    return s[top--];
}

int main() {
    int a, b;
    top = 0;
    char ch[100];
    
    while ( scanf( "%s", ch ) != EOF ) {
        if ( '+' == ch[0] ) {
            a = Pop();
            b = Pop();
            Push( a+b );
        } else if ( '-' == ch[0] ) {
            a = Pop();
            b = Pop();
            Push( b-a );
        } else if ( '*' == ch[0] ) {
            a = Pop();
            b = Pop();
            Push( a*b ); 
        } else {
            Push( atoi(ch) );
    	}
    }
    
    printf( "%d\n", Pop() );
    
    return 0;
}

Measured memory_bytes: 2756
#include<stdio.h>
#include<limits.h>
int n,tmp,A[20000000];
int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}
void heapIncreaseKey(int i,int key){
  if(key<A[i]){
    return;
  }
  A[i]=key;
  while(i>1 && A[parent(i)]<A[i]){
    tmp=A[i];
    A[i]=A[parent(i)];
    A[parent(i)]=tmp;
    i=parent(i);
  }
}
void maxHeapInsert(int key){
  n=n+1;
  A[n]=INT_MIN;
  heapIncreaseKey(n,key);
}

void maxHeapify(int i){
  int l,r,largest,tmp;
  l= left(i);
  r =right(i);
  if(l<=n && A[l]>A[i])largest =l;
  else largest =i;
  if(r<=n&&A[r]>A[largest])largest=r;
  if(largest != i){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeapify(largest);
  }
}

int heapExtractMax(){
  int max;
  if(n<1){
    return 0;
  }
  max=A[1];
  A[1]=A[n];
  n=n-1;
  maxHeapify(1);
  return max;
}



int main(){
  char b[100];
  int j;
  while(1){
    scanf("%s",b);
      if(b[0] =='i') {
      scanf("%d",&j);
      maxHeapInsert(j);
      
    }
      else if(b[1]=='x'){
      printf("%d\n",heapExtractMax());
    }
    else break;
  }
  
  
  return 0;
}

  

Measured memory_bytes: 4692
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		cin >> vec.at(i);
	}
	int counter = 0;
	int answer = 0;
	for (int i = 1; i < n; i++) {
		if (vec.at(i) <= vec.at(i - 1)) {
			counter++;
		}
		else {
			counter = 0;
		}
		if (counter > answer) {
			answer = counter;
		}
	}
	cout << answer << endl;
}

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

using namespace std;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}

int start[502], interval[502], duration[502];

int main(){

    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    //freopen("input.txt", "r", stdin);

    long long x, y, z;

    cin >> x >> y >> z;

    if(x % 2 == 0 || y % 2 == 0 || z % 2 == 0){
        cout << 0;
        return 0;
    }

    cout << min(x * y, min(x * z, y * z));

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define un unsigned
using namespace std;
int main()
{
    int n,i,j,k;
    cin>>n;
    int a[n],b[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
    }
        k=0;
    for(i=0;i<n;i++)
    {
        if(k==3) break;
    if(a[i]==b[i]) k++;
    else k=0;
    }
    if(k==3) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


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

int main() {
	string s, ans = "";
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != 'B') {
			ans += s[i];
		} else {
			if (ans.size() > 0) {
				ans = ans.erase(ans.size() - 1);
			}
		}
	}

	cout << ans << endl;
}

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

#define ll long long

int main() {
    ll n,k,i,sum=0;
    cin>>n>>k;
    ll a[n];
    for(i=0;i<n;i++) cin>>a[i];
    if(k>=n)
    {
        cout<<"0";
    }
    else
    {
        sort(a,a+n,greater<int>());
        for(i=k;i<n;i++)
        {
            sum+=a[i];
        }
        cout<<sum;
    }
    return 0;
}

Measured memory_bytes: 5172
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n == 100000) {
			System.out.println(90909);
		}else if(n < 100000 & n >= 10000){
			System.out.println(909 + n - 9999);
		}else if(n < 10000 & n >= 1000) {
			System.out.println(909);
		}else if(n < 1000 & n >= 100){
			System.out.println(9 + n -99);
		}else if(n < 100 & n >= 10){
			System.out.println(9);
		}else {
			System.out.println(n);
		}
	}
}

Measured memory_bytes: 21972
#include <stdio.h>

int search(int A[], int n,int key){
	int i=0;
	A[n]=key;
	while(A[i]!=key) i++;
	return i != n;
}

int main(){
	int i,n,A[10000+1],q,key,sum=0;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	scanf("%d",&q);
	for(i=0;i<q;i++)
	{
		scanf("%d",&key);
		if(search(A,n,key)) sum++;
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 636
#include <iostream>
using namespace std;
int main(void){
    int n, count = 0;
    cin >> n;
    
    while(n >= 100){
        n -= 100;
        count++;
    }
  
 if((n % 100) <= count * 5){
      cout << 1;
  }else{
      cout << 0;
  }
  
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a=new int[N];
        int[] count=new int[(int)Math.pow(10,5)+1];
        long res = 0;

        for(int i=0; i<N; i++){
            a[i]=sc.nextInt();
            count[a[i]]++;
            res = res + (long)a[i];
        }

        int Q = sc.nextInt();
        
        for(int i=0; i<Q; i++){
            int b=sc.nextInt();
            int c=sc.nextInt();
            res = res + (c-b)*count[b];
            count[c] += count[b];
            count[b] = 0;
            System.out.println(res);
        }

        
        
        
        
        
        
        
        
        
        }
    }

Measured memory_bytes: 60896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main() {
  int n;
  cin>>n;
  vector<int> path[n];
  rep(i,0,n-1){
    int a,b;
    cin>>a>>b;
    path[a-1].push_back(b-1);
    path[b-1].push_back(a-1);
  }
  int m;
  cin>>m;
  vector<P> abc[m];
  rep(i,0,m){
    int u,v;
    cin>>u>>v;
    u--;
    v--;
    int dp[n];
    rep(j,0,n) dp[j]=810;
    dp[u]=0;
    queue<int> q;
    q.push(u);
    while(q.size()){
      int r=q.front();
      q.pop();
      for(int x:path[r]){
        if(dp[x]==810){
          dp[x]=dp[r]+1;
          q.push(x);
        }
      }
    }
    int cur=v;
    while(cur!=u){
      for(int x:path[cur]){
        if(dp[cur]==dp[x]+1){
          P p=P(cur,x);
          if(p.first>p.second) swap(p.first,p.second);
          abc[i].push_back(p);
          cur=x;
          break;
        }
      }
    }
  }
  ll power[n];
  power[0]=1;
  rep(i,0,n-1) power[i+1]=power[i]*2;
  ll ans=0;
  rep(i,0,1<<m){
    set<P> st;
    int cnt=0;
    rep(j,0,m){
      if(i>>j & 1){
        cnt++;
        for(P pp:abc[j]){
          st.insert(pp);
        }
      }
    }
    if(cnt%2==0){
      ans+=power[n-1-st.size()];
    }
    else{
      ans-=power[n-1-st.size()];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


bool is_sq(ll N) {
    ll i = 0;
    while (i*i < N) {
        i += 1;
    }
    if (i*i == N)
        return true;
    return false;
}

int main() {
    int N, D, val;
    vector<vector<int>> point;
    cin >> N >> D;
    for(int i = 0; i < N; i++) {
        vector<int> dims(D, 0);
        for(int j = 0; j < D; j++)
            cin >> dims[j];
        point.push_back(dims);
    }
    int ans = 0;
    for(int i = 0; i < N; i++) {
        for(int j = i+1; j < N; j++) {
            int acc = 0;
            for(int d = 0; d < D; d++) {
                int diff = point[i][d] - point[j][d];
                acc += diff*diff;
            }
            if (is_sq(acc))
                ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e12;
const int MOD = 1e9 + 7;

#define MAX_N 200000

int n;
ll k;
ll a[MAX_N],f[MAX_N];

bool isOK(ll m){
    ll use = 0;
    REP(i,n){
        use += max((ll)0, a[i] - m / f[i]);
    }
    return use <= k;
}

signed main(){
    cin >> n >> k;
    REP(i,n){
        cin >> a[i];
    }
    REP(i,n){
        cin >> f[i];
    }
    sort(a, a + n);
    sort(f, f + n);
    reverse(f, f + n);
    ll ng = -1, ok = INF + 1;
    while(abs(ok - ng) > 1){
        ll mid = (ok + ng) / 2;
        if(isOK(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int A,B;
  cin>>A>>B;
  if(A%2==0 or B%2==0)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define MOD 1000000007ULL;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	ll N,M;
  	cin>>N>>M;
  	
  	if(N+M>=10) cout<<"error"<<endl;
  	else cout<<N+M<<endl;
  	
}

Measured memory_bytes: 3584
using System;
class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int i = 1;
        int x;
        string line = "";
        while (true)
        {
            x = i;
            if (x % 3 == 0)
            {
                line = line + " " + i.ToString();
            }
            else
            {
                while (true)
                {
                    if (x % 10 == 3)
                    {
                        line = line + " " + i.ToString();
                        break;
                    }
                    x /= 10;
                    if (x != 0)
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (++i > n)
            {
                Console.WriteLine(line);
                break;
            }
        }
    }
}

Measured memory_bytes: 5948
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,S,x[N],i,L=1,R,lst,v;
long long ans,p[N];bool fl;
int main(){
	scanf("%d%d",&n,&S);
	for(i=1;i<=n;++i)scanf("%d%lld",x+i,p+i);R=n;
	for(;;){
		if(S>x[R]){ans+=S-x[L];break;}
		if(S<x[L]){ans+=x[R]-S;break;}
		fl=0;v=x[R]-x[L];if(p[L]>=p[R])fl=lst!=L,p[lst=L]+=p[R--];else fl=lst!=R,p[lst=R]+=p[L++];
		if(fl)ans+=v;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1408
import numpy as np

from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

N, M, L = map(int, input().split())

if M == 0:
    Q = int(input())
    for _ in range(Q):
        print(-1)
    exit()

R = np.array([tuple(map(int, input().split())) for _ in range(M)])
matr = csr_matrix((R[:, 2], (R[:, 0] - 1, R[:, 1] - 1)), shape=(N, N))
way = floyd_warshall(matr, directed=False).astype(int)

way = np.where((way >= 0) & (way <= L), 1, 0)
matr_replenishment = csr_matrix(way)
way_replenishment = floyd_warshall(matr_replenishment, directed=False).astype(int).tolist()

Q = int(input())
for _ in range(Q):
    S, T = map(int, input().split())
    print(res - 1 if (res := way_replenishment[S - 1][T - 1]) >= 0 else -1)


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

const long long MAX_A=1000000000000000000LL;

int main(void){
    int N;
    cin >> N;
    vector<unsigned long long> A(N);
    
    for(int i=0;i<N;i++){
        cin >> A.at(i);
        if(A.at(i)==0){
            cout << 0 << endl;
            return 0;
        }
    }
    
    long long ans=1;
    for(int i=0;i<N;i++){
        if(A[i]<=MAX_A/ans){
            ans*=A[i];
        }else{
            cout << -1 << endl;
            return 0;
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 4036
def c_step():
    N = int(input())
    A = [int(i) for i in input().split()]

    current_max = A[0]
    ans = 0
    for a in A:
        current_max = max(current_max, a)
        ans += max(current_max - a, 0)
    return ans

print(c_step())

Measured memory_bytes: 32188
N = gets.to_i
A = gets.split.map(&:to_i)

hash = Hash.new { 0 }

A.each do |a|
  hash[a] += 1
end

min = 0
hash.each do |k, v|
  tmp = hash[k - 1] + hash[k] + hash[k + 1]
  if tmp > min
    min = tmp
  end
end

puts min


Measured memory_bytes: 12164
{-# LANGUAGE
    BangPatterns, MultiWayIf, TupleSections, TypeApplications #-}
{-# OPTIONS_GHC -O2 #-}

import Control.Monad
import qualified Data.ByteString.Char8 as C
import Data.Bits
import Data.List
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

main = do
    n <- readLn :: IO Int
    x <- C.getLine
    let bitsSet = C.count '1' x
        xLow = bsToModInt (bitsSet - 1) x
        xHi  = bsToModInt (bitsSet + 1) x

    arr <- UM.replicate (2*10^5 + 1) (-1 :: Int)
    UM.write arr 0 0
    forM_ [1..2*10^5] (\i -> do
            rc <- UM.read arr (step i)
            UM.write arr i (rc+1)
        )

    forM_ [0..n-1] (\i -> if bitsSet == 1 && C.index x i == '1'
                then print 0
                else let memo = if C.index x i == '1'
                            then minusMod
                                (bitsSet - 1)
                                xLow
                                (powMod (bitsSet - 1) 2 (n-i-1))
                            else plusMod
                                (bitsSet + 1)
                                xHi
                                (powMod (bitsSet + 1) 2 (n-i-1))
                    in do
                        rc <- UM.read arr memo
                        print (rc+1)
        )

step n = n `rem` (popCount n)

bsToModInt :: Int -> C.ByteString -> Int
bsToModInt md bs = let l = C.length bs
    in foldr1 (plusMod md) $
        map (\flipPos -> if C.index bs (l-flipPos-1) == '1'
                then powMod md 2 flipPos else 0) [l-1,l-2..0]

powMod :: Int -> Int -> Int -> Int
powMod mdl b e = powAux (b `rem` mdl) e 1 `mod` mdl
    where 
        powAux _ 0 !ac = ac
        powAux b e !ac = powAux (b*b `rem` mdl) (e `quot` 2)
            (if odd e then b*ac `rem` mdl else ac)

plusMod  mdl a b = (a + b) `rem` mdl
minusMod mdl a b = (a - b) `mod` mdl


Measured memory_bytes: 15436
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

const int N=100000+10;

int n,A,B,a[N]; ll b[N];

bool check(int mid) {
	for (int i=1;i<=n;++i) b[i]=a[i]-1ll*mid*B;
	ll r=mid;
	for (int i=1;i<=n;++i) {
		if (b[i]>0) r-=(b[i]-1)/(A-B)+1;
		if (r<0) return 0;
	}
	return 1;
}

int main() {
	n=read(),A=read(),B=read();
	for (int i=1;i<=n;++i) a[i]=read();
	int L=0,R=1e9;
	while (L<R) {
		int mid=(L+R)>>1;
		if (check(mid)) R=mid;
		else L=mid+1;
	}
	printf("%d\n",L);
	return 0;
}

Measured memory_bytes: 4928
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(12);
	int N, L;
	cin >> N >> L;
	vector<int> A(N);
	for(int i = 0; i < N; i++) cin >> A[i];
	double ans_x = 0, ans_y = 0;
	for(int i = 0; i < N; i++) {
		vector<int> D[2];
		for(int j = (i+1)%N; j != i; j = (j+1)%N) {
			int d = A[j]-A[i];
			if(d < 0) d += L;
			if(2*d < L) D[0].push_back(d);
			if(2*d > L) D[1].push_back(L-d);
		}
		reverse(begin(D[1]), end(D[1]));
		double sum = (N-1) * (N-2) / 2;
		for(int j = 0; j < N; j++) if(2*abs(A[j]-A[i]) == L) {
			for(auto d : D[0]) sum -= tan(pi/4) * tan(.5*pi*d/L);
			for(auto d : D[1]) sum -= tan(pi/4) * tan(.5*pi*d/L);
		}
		double sum_tan[2] = {0, 0};
		for(int k = 0; k < 2; k++) for(auto d : D[k]) {
			sum -= sum_tan[k] / tan(.5*pi*d/L);
			sum_tan[k] += tan(.5*pi*d/L);
		}
		sum -= sum_tan[0] * sum_tan[1];
		sum /= 2;
		double ang = 2*pi*A[i]/L;
		ans_x += sum * cos(ang), ans_y += sum * sin(ang);
	}
	cat n_tr = 1LL * N * (N-1) * (N-2) / 6;
	ans_x /= n_tr, ans_y /= n_tr;
	cout << ans_x << " " << ans_y << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 640
#include<stdio.h>

int main() {
  int i,j,H,W;
  while(1) {
    scanf("%d %d",&H,&W);
    if(H == 0 && W == 0) break;
    for(i = 0; i < H; i++){
      for(j = 0; j < W; j++){
	if((i+j)%2 == 1){
	  printf(".");
	}else {
	  printf("#");
	}
      }
      printf("\n");
    }
    printf("\n");
  }
}



Measured memory_bytes: 2044
import sys
from functools import reduce
input = sys.stdin.readline

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))

a.sort(reverse=True)
a_sum = reduce((lambda x,y: x+y), a)
a_min = a_sum * (1/(4*m))

if (a[m-1] >= a_min):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define fast ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define F(i,a,b) for(int i= (int)(a); i<(int)(b);i++)
#define FI(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define what_is(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007
const int N = 1e6+7 ;
string s ;

int main(){fast ;
	int n,k ;
	cin >> n >> k;
	cin >> s ;
	s = '$' + s ;
	n = s.length() ;
	vector<int> a(n,0) ;
	for(int i = 1 ; i < n ; i++){
		if(s[i] == 'C' and s[i-1] == 'A')
			a[i] = a[i-1] + 1 ;
		else a[i] = a[i-1] ;
	}
	int l ; int r ;
	for(int i = 0 ; i < k ; i++){
		cin >> l >> r ;
		cout << a[r] - a[l] << endl ;
	}
}




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

int64_t mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int N;
    cin >> N;
    vector<int64_t> list(87);
    list[0] = 2, list[1] = 1;
    for (int i = 2; i < N + 1; i++)
        list[i] = list[i - 1] + list[i - 2];
    cout << list[N];
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.io.BufferedInputStream;
import java.lang.Math;
import java.util.*;

public class Main{
    static long tmp = 10000 * 10000;
    static long MAX_COUNT = tmp * tmp + 999;

    static int N;
    static long K = 0;
    static long [] A;

    public static void main(String [] args) {
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        N = sc.nextInt();
        A = new long [N];
        long sum = 0;
        for(int i = 0; i < N ; i++) {
            A[i] = sc.nextLong();
            sum = sum + A[i];
        }
        K = sum - (N-1) * N;
        if(K > 0) {
            decreaseK();
        } else {
            K = 0;
        }
        while(decrease());
        System.out.println(K);
    }

    static boolean decrease() {
        boolean ok = true;
        for(int i = 0; i < N; i++) {
            if(A[i] >= N) {
                ok = false;
            }
        }
        // System.out.println(Arrays.toString(A));
        if(ok) return false;
        int p = 0;
        for(int i = 0; i < N; i++) {
            if(A[i] > A[p]) {
                p = i;
            }
        }
        for(int i = 0; i < N; i++) A[i] = A[i] + 1;
        A[p] = A[p] - N - 1;
        K = K + 1;
        return true;
    }

    static void decreaseK() {
        for(int i = 0; i < N; i++) {
            A[i] = A[i] + K;
        }
        long l = 0, r = MAX_COUNT * 4;
        while(r - l > 1) {
            long mid = (r + l) / 2;
            if(totalCount(mid) > K)
                l = mid;
            else r = mid;
        }
        long sum = totalCount(r);
        for(int i = 0; i < N; i++) {
            long cnt = count(A[i]-r);
            A[i] = A[i] - cnt * (N + 1);
            A[i] = A[i] - K + sum;
        }
        K = sum;
    }

    static long totalCount(long limit) {
        long ret = 0;
        for(int i = 0; i < N; i++) {
            ret = ret + count(A[i] - limit);
        }
        return ret;
    }

    static long count(long x) {
        if(x <= 0) return 0;
        long cnt = x / (N + 1);
        if(x % (N + 1) > 0) {
            cnt += 1;
        }
        return cnt;
    }
}


Measured memory_bytes: 23764
Module Module1
    Structure HUMAN
        Public hp As Long
        Public power As Long
        Public downCount As Long
    End Structure

    Sub main()
        Dim user2 As List(Of String) = New List(Of String)(Split(Console.ReadLine(), " "))
        Dim result As String = "No"
        Dim enemy As HUMAN
        Dim user As HUMAN

        enemy.hp = user2(0)
        enemy.power = user2(1)
        user.hp = user2(2)
        user.power = user2(3)
        enemy.downCount = Math.Ceiling(enemy.hp / user.power)
        user.downCount = Math.Ceiling(user.hp / enemy.power)

        If enemy.downCount >= user.downCount Then result = "Yes"

        Console.WriteLine(result)
    End Sub
End Module

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1L << 30
#define long long long
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


int A, B, M;
//vector<vector<int>> coupon(pow(10, 5)+1, vector<int>(pow(10, 5)+1, -1));
//vector<int> coupon(pow(10, 7)+1, 0);
int main(){
	cin >> A >> B >> M;
	vector<int> a(A);
	vector<int> b(B);
	//vector<int> x(M);
	//vector<int> y(M);
	//vector<int> c(M);

	rep(i, A) cin >> a.at(i);
	rep(i, B) cin >> b.at(i);
	int min_A = *min_element(a.begin(), a.end());
	int min_B = *min_element(b.begin(), b.end());

	int sum = min_A + min_B;
	rep(i, M) {
		int x, y, c;
		cin >> x >> y >> c; x--, y--;
		//cin >> x.at(i) >> y.at(j) >> c.at(i);
		
		chmin(sum, a.at(x)+b.at(y) - c);
		//chmax(coupon.at(x).at(y), c);
	}
	
	cout << sum << endl;
}
	

Measured memory_bytes: 1024
#include <stdio.h>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
using namespace std;
int res, k;
void get(int num, int val){
    if(k >= num){
        res += val*num;
        k -= num;
    }else{
        res += val*k;
        k -= k;
    }
}
int main(){
    int a, b, c;
    cin>>a>>b>>c>>k;
    res = 0;
    while(k>0){
        get(a, 1);
        get(b, 0);
        get(c, -1);
    }
    cout<<res<<endl;
    
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int 

//power of 2 ...n&(n-1)==0

int main()
{
	FAST;
	//#ifndef ONLINE_JUDGE
	//	freopen("input.txt","r",stdin);
	//	freopen("output.txt","w",stdout);
	//#endif
	 //ll testcase;
	 //cin>>testcase;
	 //for(ll t=0;t<testcase;t++)
	{
		// use long long
		//donot memeset other than 0 or 1 or -1
		//segmentation fault-> check for uninitialized global variable or out of bounds
		//always check for bottle neck (whether original constraints can be reduced by introducing some condition)
		//dont rush to writing code think through the logic	
		//implement dijkstra again ---it is bfs because we vis all the points connected to the current point first
		//from every not visited cell we will update the distances of cell which can be visited
		int n;
		cin>>n;
		ll a[n];
		for(int i=0;i<n;i++)
			cin>>a[i];
		sort(a,a+n);
		bool flag=false;
		long double mul=1;
		for(int i=0;i<n;i++)
		{
			mul=mul*a[i];
			if(mul>1e18+5)
			{
				cout<<-1<<'\n';
				flag=true;
				break;
			}
		}
		if(!flag)
		{
			cout<<(ll)mul<<'\n';
		}
		
	}
	return 0;
}





























































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

int main(){
  ll n,a,b,c,d,e;
  cin>>n>>a>>b>>c>>d>>e;
  ll mi=min(min(a,b),min(c,min(d,e)));
  ll ans;
  if(n%mi==0)ans = n/mi+5-1;
  else ans = n/mi+5;
  cout<<ans<<endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
 
int main() {
  std::string boxes;
  std::cin >> boxes;
  int numOfBalls = 0;
  for (size_t i = 0U; i < boxes.length(); ++i) {
    if (boxes.at(i) == '1') {
      numOfBalls++;
    }
  }
  std::cout << numOfBalls;
}

Measured memory_bytes: 3152
// Palace

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

int n;
int t, a;

float calc_temp(int h) {
    return t - h * 0.006;
}
int main() {
    cin >> n;
    cin >> t >> a;

    int h;
    float diff = 10000000;

    int res;
    for (int i = 0; i < n; i++) {
        cin >> h;
        if (abs(calc_temp(h) - a) < diff) {
            diff = abs(calc_temp(h) - a);
            res = i + 1;
        }
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
num = int(input())
input_list = input().split()
list = []
for one in input_list:
    list.append(int(one))

count = 0
out = True
lists = [list]
while out:
    new_list = []
    for one in lists[count]:
        div = one % 2
        if div != 0:
            out = False
            break
        new_list.append(one/2)
    lists.append(new_list)
    if out:
        count = count + 1
print(count)

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

#define     Boost               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define     all(cont)           cont.begin(),cont.end()
#define     rall(cont)          cont.rbegin(),cont.rend()
#define     foreach(cont)       for(auto &value: cont)
#define     show(val)           cout<< #val << " -> " << val << endl
#define     flush               cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define     Case                cout<< "Case "<< ++cs << ": "
#define     mk                  make_pair
#define     pb                  push_back
#define     ff                  first
#define     ss                  second

typedef     long long                   ll ;
typedef     unsigned long long          ull ;
typedef     pair <int, int>             pii ;

const ll INF = (1LL<<60)-1 ;


//#define DEBUG
int main()
{
    Boost;

    #ifdef DEBUG
    freopen("input.txt","r",stdin);    // Read
    freopen("output.txt","w",stdout);  // Write
    #endif

    ll n,sum=0;
    cin>> n ;
    
    for(ll i=1; i<=n; i++){
        for(ll j=1; j<=n; j++){
            for(ll k=1; k<=n; k++)
                sum += __gcd(__gcd(i,j),k) ;
        }
    }
    
    cout<< sum << endl ;

    return 0;
}




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

int main() {
   long double a,b,c,twoab;
   cin >> a >> b >>c ;
  
  twoab=2*sqrt(a*b);

 
  //cout <<a<<" "<<b << " "<<c << endl;
  if(a+twoab+b < c)
  {cout << "Yes" << endl;}
  else
  {
   cout << "No" << endl;
  }
   return 0;
}
//vector <int> a(3);


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

typedef int64_t Int;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int n;
    cin >> n;
    string s;
    cin >> s;
    Int res = 0;
    for (Int i = 1; i < (Int)n - 1; i++) {
        Int left_R, left_G, left_B;
        left_R = left_G = left_B = 0;
        Int right_R, right_G, right_B;
        right_R = right_G = right_B = 0;
        for (Int j = 1; i - j >= 0; j++) {
            if (s[i - j] == 'R') left_R++;
            if (s[i - j] == 'G') left_G++;
            if (s[i - j] == 'B') left_B++;
        }
        for (Int j = 1; i + j < n; j++) {
            if (s[i + j] == 'R') right_R++;
            if (s[i + j] == 'G') right_G++;
            if (s[i + j] == 'B') right_B++;
        }
        Int sub = 0;
        for (Int j = 1; i - j >= 0 and i + j < n; j++) {
            if (s[i] != s[i - j] and s[i - j] != s[i + j] and s[i + j] != s[i]) sub++;
        }
        if (s[i] == 'R') {
            res += left_G * right_B + left_B * right_G;
        }
        if (s[i] == 'G') {
            res += left_R * right_B + left_B * right_R;
        }
        if (s[i] == 'B') {
            res += left_G * right_R + left_R * right_G;
        }
        res -= sub;
    }
    print(res);
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c;cin >> a >> b >> c;
	string ans = (b - a) == (c - b) ? "YES" : "NO";
	cout << ans << endl;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc114/tasks/abc114_c

# 7,5,3がそれぞれ1回以上現れる数
# 3進数を自分で作ってしまうのは？→3,5,7の順にiterateするのは十分間に合う
# 10進数で10**9は3進数だけ考慮するなら10**4.5ぐらいですむ


from itertools import product
N = int(input())
number = ['0'] * 9
nums = ['0', '3', '5', '7']
arg = [nums] * 9


ans = 0
for iters in product(*arg):  # 頭がわるいので
    tmp = int(''.join(iters))
    if tmp > N:
        break
    tmp = str(tmp)
    if tmp.count('0') > 0 or tmp.count('3') == 0 or tmp.count('5') == 0 or tmp.count('7') == 0:
        continue
    else:
        ans += 1


print(ans)


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

int main()
{
    int D;
    cin >> D;
    if(D == 25)printf("Christmas\n");
    if(D == 24)printf("Christmas Eve\n");
    if(D == 23)printf("Christmas Eve Eve\n");
    if(D == 22)printf("Christmas Eve Eve Eve\n");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main() {
    set<int> S;
    int a, b, c; cin >> a >> b >> c;
    S.insert(a);
    S.insert(b);
    S.insert(c);

    cout << S.size() << endl;
    return 0;
}

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

int main() {
	int a[3];
	for(int i = 0; i < 3; ++i) cin >> a[i];
	sort(a, a + 3);
	if(a[0] == a[1] and a[0] != a[2]) {
		cout << "Yes" << '\n';
	} else if(a[0] != a[1] and a[1] == a[2]) {
		cout << "Yes" << '\n';
	} else {
		cout << "No" << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<ctime>
#include<queue>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
int read(){
    int f=1,x=0;char c=getchar();
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
    while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();
	x*=f;
    return x;
}
#define MAXN 100000
#define INF 0x3f3f3f3f
int x[MAXN+5],y[MAXN+5];
int main(){
	int n=read(),m=read();
	for(int i=1;i<=m;i++)
		x[i]=read();
	if(n>=m){
		puts("0");
		return 0;
	}
	sort(x+1,x+m+1);
	for(int i=1;i<m;i++)
		y[i]=x[i+1]-x[i];
	sort(y+1,y+m);
	LL ans=x[m]-x[1];
	for(int i=m-1;i>=m-n+1;i--)
		ans-=y[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
//#define local
int main()
{
#ifdef local
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif
    int n,k,ans;
    cin>>n>>k;
    ans=k;
    ans*=pow(k-1,n-1);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return (rand()<<16|rand())%x;
}
ll sol(ll a,ll b,int k){
	//cout<<a<<" "<<b<<endl;
	if(a>b)swap(a,b); int p=-1;
	for(int i=k-1;i>=0;i--)if(b>>i&1){p=i; break;}
	ll t1=((ll)1<<k)+((ll)1<<(p+1)),t2=a+((ll)1<<k);
	//cout<<t1<<" "<<t2<<" "<<a<<" "<<((ll)1<<(k+1))<<endl;
	return t1>t2?((ll)1<<(k+1))-a:t1-a+((ll)1<<(k+1))-t2;
}
int main(){
	ll a,b,c;
	cin>>a>>b; c=a; 
	if(a==b){
		puts("1"); return 0;
	}
	ll dq=1;
	for(int i=60;i>=0;i--){
		if((a>>i&1)!=(b>>i&1)){
			cout<<sol(a,b,i)<<endl; return 0;
		}else dq<<=a>>i&1;
		if(a>>i&1)a^=(ll)1<<i; if(b>>i&1)b^=(ll)1<<i;
	}
}
/*

*/

Measured memory_bytes: 256
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    N, M = read_int_list()
    p = [0] * M
    S = [''] * M
    for i in range(M):
      l = read_str_list()
      p[i] = int(l[0])
      S[i] = l[1]
      
    r = set()
    for i in range(M):
      if S[i] == 'AC':
        if p[i] not in r:
          r.add(p[i])

    correct, penalties = 0, 0
    f = set()  
    for i in range(M):
      if S[i] == 'AC':
        if p[i] not in f:
          f.add(p[i])
          correct += 1
      # print(p[i], S[i], f, r)
      
      if S[i] == 'WA':
        if p[i] not in f and p[i] in r:
          penalties += 1

    print(correct, penalties)

main()


Measured memory_bytes: 24808
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    if(b/a>=c){
      System.out.println(c);
    }else{
      System.out.println(b/a);
    }
 }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, m, c;
  cin >> n >> m >> c;
  int b[m];int a[n][m];
  for(int i=0;i<m;i++) cin >> b[i];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++) cin >> a[i][j];
  int count=0;
  int ans=c;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      ans+=a[i][j]*b[j];
    }
    if(ans>0){
      count++;
    }
    ans=c;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
class BIT
    def initialize(n)
        @n = n+1
        @dat = Array.new(@n+1, 0)
    end

    def sum(i)
        s = 0
        while i >= 0 do
            s = (s + @dat[i]) % MOD
            i = (i & (i + 1)) - 1
        end
        s
    end

    def sum_between(a, b)
        b >= a ? (sum(b) - sum(a-1)) % MOD : 0
    end

    def add(i, x)
        while i <= @n do
            @dat[i] = (@dat[i] + x) % MOD
            i |= i + 1
        end
    end
end

MOD = 10**9+7

N, A, B = gets.split.map(&:to_i)
S = [-10**20] + N.times.map{gets.to_i}

left_A = Array.new(N+1)
left_B = Array.new(N+1)
la, lb = -1, -1
(1..N).each do |r|
    la += 1 while S[r] - S[la+1] >= A
    lb += 1 while S[r] - S[lb+1] >= B
    left_A[r] = la
    left_B[r] = lb
end

dpA = BIT.new(N+1)
dpB = BIT.new(N+1)
dpA.add(0, 1)
dpB.add(0, 1)

la, lb = 0, 0
(2..N).each do |i|
    addA = dpB.sum_between(lb, left_A[i])
    addB = dpA.sum_between(la, left_B[i])
    dpA.add(i-1, addA)
    dpB.add(i-1, addB)
    la = i-1 if left_A[i] != i-1
    lb = i-1 if left_B[i] != i-1
end
puts (dpA.sum_between(la, N-1) + dpB.sum_between(lb, N-1)) % MOD

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

int main(){
  string s;
  cin >> s;
  
  int l = s.size();
  vector<int> a(l+1);
  int now = 0;
  for(int i = 0; i < l; i++){
    char c = s.at(i);
    if(c == '<'){
      a.at(i) = now++;
      a.at(i+1) = now;
    }
    else now = 0;
  }
  now = 0;
  for(int i = l-1; i >= 0; i--){
    char c = s.at(i);
    if(c == '<') now = 0;
    else{
      a.at(i+1) = max(a.at(i+1), now);
      now++;
      a.at(i) = max(a.at(i), now);
    }
  }
  
  long long ans = 0;
  for(auto k : a) ans += k;
  
  cout << ans << endl;
}

Measured memory_bytes: 2820
K = int(input())

mods = [0] * (K+1)
mods[1] = 7 % K

for i in range(2,K+1):
    mods[i] = (mods[i-1] * 10 + 7) % K

for i in range(1,K+1):
    if mods[i] == 0:
        print(i)
        exit(0)    
print(-1)

Measured memory_bytes: 48496
#include <bits/stdc++.h> //msh salah skor 10 dri 25
using namespace std;

bool cek(int a,int b,int r, int w, int h){
	bool wow = true;
	if ((a + r < 0)||(a + r > w)){
		wow = false;
	}
	if ((b + r < 0 )||(b + r > h)){
		wow = false;
	}
		if ((a - r < 0)||(a - r > w)){
		wow = false;
	}
	if ((b - r < 0 )||(b - r > h)){
		wow = false;
	}
	return wow;
}

int main(){
int w,h,x,y,r;
cin>>w>>h>>x>>y>>r;
if (cek(x,y,r,w,h)) {
	cout << "Yes" << endl;
} else {
	cout << "No" << endl;
	
}
}


Measured memory_bytes: 3096
import sys
import math
from functools import reduce


def num_of_zeros(num):
    return (num ^ (num - 1)).bit_length() - 1


def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def main():
    input = sys.stdin.buffer.readline
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    if len(set(map(num_of_zeros, a))) != 1:
        print(0)
    else:
        lcm = lcm_list(list(map(lambda x: x // 2, a)))
        ub = 10 ** 9
        lb = 0
        while ub - lb > 1:
            mid = (ub + lb) // 2
            if lcm * (2 * mid + 1) <= m:
                lb = mid
            else:
                ub = mid
        if lcm <= m:
            lb += 1
        print(lb)


if __name__ == "__main__":
    main()


Measured memory_bytes: 19152