akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define revrep(i,n) for(long long i=n-1;i>=0;i--)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define test int t;cin>>t; while(t--)
#define set0(x) memset(x,0,sizeof(x))
#define set1(x) memset(x,1,sizeof(x))
#define getarr(arr,n) int arr[n];rep(i,0,n)cin>>a[i]
#define getvec(vec,n) vi vec;int x;rep(i,0,n){cin>>x;vec.pb(x);}
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
vi b_v;void bin(unsigned int n) { if (n > 1) bin(n>>1); b_v.pb(n & 1); }
int isPowerof2(int x) { return (x && !(x & x-1)); }

int32_t main(){
	boost;osit;
    string s;
    cin>>s;
    char prev;
    rep(i,0,s.size()){
        if(i>0){
            if(s[i]==prev){
                cout<<"Bad";
                return 0;
            }
        }
        prev=s[i];
    }
    cout<<"Good";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <cmath>
using namespace std;
int N, D, X[10][10];
int main()
{
	scanf("%d%d", &N, &D);
	for (int i = 0; i < N; ++i)
		for (int j = 0; j < D; ++j)
			scanf("%d", &X[i][j]);

	int ans = 0;
	for(int i=0;i<N;++i)
		for (int j = i + 1; j < N; ++j)
		{
			int sum = 0;
			for (int k = 0; k < D; ++k)
			{
				sum += (X[i][k] - X[j][k])*(X[i][k] - X[j][k]);
			}
			int sq = sqrt(sum);
			if (sq*sq == sum)ans++;
		}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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() {
    int n, m;
    cin >> n >> m;
    if(n == m) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<list>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back

#define ll __int64
#define P pair<ll,ll>
//#define __int64 long long
struct unionFind{
	int n;
	vector<int>par;
	vector<int>rank;
	unionFind(int x){
		n=x;
		par.resize(x);
		rank.resize(x);
		rep(i,n){
			par[i]=i;
			rank[i]=0;
		}
	}
	
	int find(int x){
		if(par[x]==x)return x;
		else return par[x]=find(par[x]);
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	
	void unite(int x,int y){//x,yを併合
		x=find(x);
		y=find(y);
		if(x==y)return;
		if(rank[x]<rank[y]){
			par[x]=par[y];
		}
		else{
			par[y]=x;
			if(rank[x]==rank[y])rank[x]++;
		}
	}
};

int n,m;
int t[111111];


int main(){	
	cin>>n>>m;
	rep(i,n)cin>>t[i];
	unionFind u(111111);

	rep(i,m){
		int x,y;
		cin>>x>>y;
		u.unite(x,y);
	}
	int ans=0;

	rep(i,n){
		if(u.find(t[i])==u.find(i+1))ans++;
	}
	cout<<ans<<endl;
	
	return 0;

}


Measured memory_bytes: 1536
n = int(input())
a = list(map(int, input().split()))

a1 = sorted(a, reverse=True)
com = 0

if n == 2:
    com = a1[0]
elif n%2 ==0:
    c = int(n/2)
    com = sum(a1[0:c])
    com += sum(a1[1:c])
else:
    c = int(n//2)
    com += sum(a1[0:c+1])
    com += sum(a1[1:c])
    
print(com)

Measured memory_bytes: 31756
c=[list(map(int,input().split())) for i in range(3)]
if (c[0][0]+c[1][1]+c[2][2])*2==c[0][1]+c[0][2]+c[1][0]+c[1][2]+c[2][0]+c[2][1]:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 9088
def main():
    N, K = [int(i) for i in input().split()]
    N = N - (K * (N // K))
    if N == 0:
        print(0)
        return

    prevs = set()
    while N not in prevs:
        prevs.add(N)
        N = abs(N - K)

    print(min(prevs))

main()

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  string s[3];
  cin>>s[0]>>s[1]>>s[2];
  int now = 0;
  int it[3] = {0};
  while(it[now] != s[now].size()) {
    char x = s[now][it[now]++];
    if(x == 'a') {
      now = 0;
    } else if(x == 'b') {
      now = 1;
    } else {
      now = 2;
    }
  }
  if(now == 0) {
    cout << 'A' << endl;
  } else if(now == 1) {
    cout << 'B' << endl;
  } else {
    cout << 'C' << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  static long MAX_ANSWER = 1000000000000000000l;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] input = new long[n];
    for(int i = 0; i < n; i++){
      long l = sc.nextLong();
      if(l == 0l){
        System.out.print(0);
        return;
      }
      input[i] = l;
    }
    long answer = 1;
    for(long l : input){
      if(Math.abs(MAX_ANSWER / l) < answer){
        System.out.print(-1);
        return;
      }
      answer *= l;
    }
    System.out.print(answer);
  }
}

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

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

long long dp[100010];
long long h[100010];

const long long INF = 1LL << 60;

int main() {
	long long n;
	int k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}

	for (int i = 0; i <= n; i++) {
		dp[i] = INF;
	}

	dp[0] = 0;

	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= k; j++) {
			chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
		}
	}

	cout << dp[n - 1] << endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	int n;
	std::cin >> n;
	if (n % 2 == 0) {
		std::cout << n << '\n';
	}
	else {
		std::cout << n * 2 << '\n';
	}
	return 0;
}


Measured memory_bytes: 256
n = int(input())
t,a = map(int,input().split())
h = [0] + list(map(int,input().split()))
kion = 99999
ans = 0
for i in range(1,n+1):
    tmp = t-h[i]*0.006
    #print(i,a,tmp,abs(a-tmp),kion,ans)
    if abs(a-tmp)<kion:
        kion = abs(a-tmp)
        ans = i
print(ans)


Measured memory_bytes: 9220
#include<iostream>
using namespace std;
long K;
main()
{
	cin>>K;
	long now=0;
	for(int i=1;i<2e6;i++)
	{
		now=(now*10+1)%K;
		if(now*7%K==0)
		{
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf=1e9+7;

int main(){
    double a,b,c,d;cin>>a>>b>>c>>d;
    if(ceil(c/b)<=ceil(a/d))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3724
#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()
{
    string s;
    cin >> s;
    int n = s.size();

    bool good = true;
    for(int i=0; i<n-1; ++i){
        if(s[i] == s[i+1]){
            good = false;
            break;
        }
    }
    if(good)
        cout << "Good" << endl;
    else
        cout << "Bad" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int x, k, q, t, a, low, up, jilei, kongsanjiao, now, ans, r[100007];
bool flag=0;
int cal(int tt, int lower = 0, int upper = x) {
    if (tt < lower) return lower;
    if (tt > upper) return upper;
    return tt;
}
int main()
{
    scanf("%d%d",&x,&k);
    for (int i = 1; i <= k; i++) scanf("%d",&r[i]);
        scanf("%d",&q);
    now = 1;
    low = x;
    up = 0;
    while (q--)
    {
        scanf("%d%d",&t,&a);
        while (t >= r[now] && now <= k)
        {
            kongsanjiao = (flag ? 1 : -1) * (r[now] - r[now - 1]);
            jilei += kongsanjiao;
            up = cal(kongsanjiao + up);
            low = cal(kongsanjiao + low);
            flag = !flag;
            now++;
        }
        ans = cal((flag ? 1 : -1) * (t - r[now - 1]) + cal(a + jilei, up, low));
        printf("%d\n",ans);
    }
    return 0;
}




Measured memory_bytes: 1536
#include <iostream>

#define llong long long
#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i++))
#define _min(a,b) ((a)<(b)?(a):(b))
#define _max(a,b) ((a)>(b)?(a):(b))
#define _abs(a,b) (((a)-(b))>0?((a)-(b)):((b)-(a)))

using namespace std;

int main(){
	int N,K;
	cin >> N >> K;
	int A[N];
	rep(i,0,N) cin >> A[i];
	
	rep(i,K,N){
		if( A[i-K] < A[i] ) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 4400
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int n,m;
int stone[155][11][2];
int dp[155][11][76];
int num[155];
int cost(int a,int b,int c){
	if(a==n || (a==n-1 && c<m)){
		return 0;
	}
	if(dp[a][b][c]!=-1) return dp[a][b][c];
	int mini=INF;
	for(int i=1;i<=num[a+1];i++){
		mini=min(mini,(stone[a+1][i][1]+stone[a][b][1])*abs(stone[a][b][0]-stone[a+1][i][0])+cost(a+1,i,c));
	}
	if(c!=m){
	for(int i=1;i<=num[a+2];i++){
		mini=min(mini,(stone[a+2][i][1]+stone[a][b][1])*abs(stone[a][b][0]-stone[a+2][i][0])+cost(a+2,i,1+c));
	}
	}
	return dp[a][b][c]=mini;
}
int main(){
	while(scanf("%d %d",&n,&m) && n){
		for(int i=1;i<=n;i++){
			scanf("%d",&num[i]);
			for(int g=1;g<=num[i];g++){
				scanf("%d %d",&stone[i][g][0],&stone[i][g][1]);
			}
		}
		memset(dp,-1,sizeof(dp));
		int ans=INF;
		for(int i=1;i<=num[1];i++){
			ans=min(ans,cost(1,i,0));
		}
		if(m>0){
			for(int i=1;i<=num[2];i++){
				ans=min(ans,cost(2,i,1));
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 1732
while True:
    n,x=map(int,input().split())
    if(n,x)==(0,0):
        break
    y=0
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if(i+j+k==x):
                    y+=1
    print(y)


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef long long ll;
const ll maxn = 1e5+100,mod = 1e9+7,INF = 1ll<<62;
char a[100][100];
int main(){
	ll n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j]=='.'){
				int ans=0;
				if(a[i-1][j-1]=='#'){
					ans++;
				}
				if(a[i-1][j]=='#'){
					ans++;
				}
				if(a[i-1][j+1]=='#'){
					ans++;
				}
				if(a[i][j-1]=='#'){
					ans++;
				}
				if(a[i][j]=='#'){
					ans++;
				}
				if(a[i][j+1]=='#'){
					ans++;
				}
				if(a[i+1][j-1]=='#'){
					ans++;
				}
				if(a[i+1][j]=='#'){
					ans++;
				}
				if(a[i+1][j+1]=='#'){
					ans++;
				}
				cout<<ans;
			}
			else{
				cout<<'#';
			}
		}
		cout<<endl;
	}
}


Measured memory_bytes: 256
h, w, k = [int(x) for x in input().split(' ')]
s = []
r = []
for i in range(h):
    s.append(list(input().rstrip()))
    r.append([-1] * w)

initial_row = -1
nothing_rows = []
index = 1
for i in range(h):
    nothing_flag = True
    for j in range(w):
        if s[i][j] == '#':
            nothing_flag = False
    if nothing_flag:
        nothing_rows.append(i)
    else:
        if initial_row == -1:
            initial_row = i
        first_flag = False
        for j in range(w):
            if s[i][j] == '#':
                if first_flag == False:
                    first_flag = True
                else:
                    index += 1
            r[i][j] = index
        index += 1

for i in nothing_rows:
    if i < initial_row:
        for j in range(w):
            r[i][j] = r[initial_row][j]
    else:
        for j in range(w):
            r[i][j] = r[i - 1][j]

for i in range(h):
    print(' '.join([str(x) for x in r[i]]))


Measured memory_bytes: 7924
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 100001
//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) 
        exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) 
        exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}
int main(void){
    char str[SIZE];
    int count=0,i;
    node *first = NULL;//最初のノードの指す先
    scanf("%s",str);
    for(i=0;i<strlen(str);i++){
        if(first!=NULL){
            if(str[i]==first->elem){//スタックにノードを追加
                push(&first,str[i]);
            }
            else{//スタックからデータを取り出す
                pop(&first);
                count+=2;
            }
        }else{//初期状態のノードにデータを追加
            push(&first,str[i]);
        }
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 4904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=2505,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f3f3f3f3f;

vector<ii> e[MAXn];
vector<ll> re[MAXn];
bool arr[MAXn];
ll dis[MAXn];
void dfs(ll x){
    arr[x] = true;
    for (auto i:re[x]) {
        if (!arr[i]) dfs(i);
    }
}
int main(){
    IOS();
    ll n,m,p;
    cin >> n >> m >> p;
    REP (i,m) {
        ll a,b,c;
        cin >> a >> b >> c;
        a--,b--;
        e[a].eb(b,c-p);
        re[b].eb(a);
    }
    dfs(n-1);

    REP (i,n) dis[i] = -INF;
    dis[0] = 0;
    REP (T,n-1) {
        REP (i,n) {
            if (dis[i] == -INF) continue;
            for (auto cur:e[i]) {
                if (dis[cur.X] < dis[i] + cur.Y) {
                    dis[cur.X] = dis[i] + cur.Y;
                }
            }
        }
    }
    debug("ALIVE");
    REP (i,n) {
        for (auto cur:e[i]) {
            if (dis[i] == -INF || dis[cur.X] == -INF) continue;
            if (dis[cur.X] < dis[i] + cur.Y && arr[cur.X]) {
                return cout << -1 << endl,0;
            }
        }
    }

    cout << max(0LL,dis[n-1]) << endl;
}


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

#define rep(i,n) for (int i=0; i < (n); i++)
typedef double D;
typedef complex<D> P;
typedef vector<P> VP;
const D EPS = 1e-7;
#define X real()
#define Y imag()

#define EQ(n,m) (abs((n)-(m)) < EPS)
VP crosspointCC(P a, D ar, P b, D br) {
  VP ps;
  P ab = b-a;
  D d = abs(ab);
  D crL = (norm(ab) + ar*ar - br*br) / (2*d);
  if (EQ(d, 0) || ar < abs(crL)) return ps;
 
  P abN = ab * P(0, sqrt(ar*ar - crL*crL) / d);
  P cp = a + crL/d * ab;
  ps.push_back(cp + abN);
  if (!EQ(norm(abN), 0)) ps.push_back(cp - abN);
  return ps;
}

int n;
D x[11],y[11],z[11],a[11];

bool ch(double mid){
  VP v;
  rep(i,n){
    a[i] = sqrt(z[i]*z[i] - mid*mid);
    if(a[i]<0)return 0;
    v.push_back(P(x[i],y[i]));
  }
  rep(i,n)rep(j,n)if(i<j){
    VP p=crosspointCC(P(x[i],y[i]),a[i],P(x[j],y[j]),a[j]);
    rep(k,p.size()){
      v.push_back(p[k]);
    }
  }
  rep(i,v.size()){
    int flag=0;
    rep(j,n){
      D dist=sqrt((x[j]-v[i].X)*(x[j]-v[i].X)+(y[j]-v[i].Y)*(y[j]-v[i].Y));
      if(dist<=a[j]+EPS)flag++;
    }
    if(flag==n)return 1;
  }
  return 0;
}

signed main(){
  while(cin>>n,n){
    rep(i,n)cin>>x[i]>>y[i]>>z[i];
    D l=0,r=1e9;
    rep(o,100){
      D mid=(l+r)/2;
      if(!ch(mid))r=mid;
      else l=mid;
    }
    printf("%.9f\n",l);
  }
}


Measured memory_bytes: 3304
import java.util.*;

public class Main {
	
	static int p[] = new int[100001];
	
	public static void create() {
		p[0] = -1;
		p[1] = -1;
		p[2] = 1;
		for(int i = 2; i < p.length; ++i) {
			if(p[i] != -1) {
				p[i] = 1;
				for(int j = 2; j * i < p.length; ++j) {
					p[i * j] = -1;
				}
			}
		}
	}
	
	public static boolean judge(int x) {
		if(p[x] != 1)return false;
		int tmp = (x + 1) / 2;
		if(p[tmp] != 1)return false;
		return true;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		int ans[] = new int[100001];
		create();
		for (int i = 1; i < ans.length; ++i) {
			ans[i] = ans[i - 1];
			if(judge(i))ans[i]++;
		}
		for(int i = 0; i < q; ++i) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int a = ans[r] - ans[l - 1];
			System.out.println(a);
		}
		sc.close();
	}

}


Measured memory_bytes: 67024
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<int> > mat;

int main()
{
  ll n, a;
  cin >> n >> a;
  ll x[55];
  for (int i = 0; i < n; i++)
  {
    cin >> x[i];
  }

  ll dp[55][2550][55];
  memset(dp, 0, sizeof(dp));
  dp[0][0][0] = 1;
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < 50 * (i + 1); j++)
    {
      for (int k = 0; k < i + 1; k++)
      {
        dp[i + 1][j][k] += dp[i][j][k];
        dp[i + 1][j + x[i]][k + 1] += dp[i][j][k];
      }
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++)
  {
    ans += dp[n][i * a][i];
  }
  cout << ans << "\n";
}

Measured memory_bytes: 60544
#include <stdio.h>

#define MAX 100

typedef struct{
  int src,dst;
} Node;

void DFS(int,int,int[MAX][MAX]);

int t;
int visited[MAX];
Node node[MAX];

int main(){
  int n;
  int u,k,v;
  int i,j;
  int G[MAX][MAX];
  for(i = 0 ; i < MAX ; i++){
    for(j = 0 ; j < MAX ; j++){
      G[i][j] = 0;
    }
  }
  
  t=0;
  scanf("%d",&n);
  
  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&u,&k);
    u=u-1;
    for(j = 0 ; j < k ; j++){
      scanf("%d",&v);
      v=v-1;
      G[u][v] = 1;
    }
    visited[i] = 0;
  }
  for(i = 0 ; i < n ; i++){
    if(!visited[i]){
      visited[i] = 1;
      DFS(i,n,G);
    }
  }
  for(i = 0 ; i < n ; i++){
    printf("%d %d %d",i+1,node[i].src,node[i].dst);
    printf("\n");
  }
  return 0;
}

void DFS(int v,int n,int G[MAX][MAX]){
  int i;
  node[v].src = ++t;
  for(i = 0 ; i < n ; i++){
    if(G[v][i] == 0){ continue; }
    if(visited[i] == 1){ continue; }
    visited[i] = 1;
    DFS(i,n,G);
  }
  node[v].dst = ++t;
}



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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;





void one_case() {
    string s;
    cin >> s;
    int c = 0;
    for (auto el : s) {
        c += el == '1';
    }
    cout << c << "\n";


}


int main() {
//    std::ios::sync_with_stdio(false);
//    std::cin.tie(nullptr);


    int t = 1;
//    cin >> t;
    while (t--) {
        one_case();
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
#include <cmath>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define INF 2000000000
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int n,a,m1=0,m2=0,m3=0,m4=0,m5,m6;
	cin >> n;
	map<int, int>ma1;
	map<int, int>ma2;
	rep(i, n) {
		cin >> a;
		if (i % 2 == 0) {
			if (!ma1.count(a)) {
				ma1[a] = 1;
			}
			else {
				ma1[a]++;
			}
		}
		else {
			if (!ma2.count(a)) {
				ma2[a] = 1;
			}
			else {
				ma2[a]++;
			}
		}
	}
	for (auto p : ma1) {
		auto k = p.first;
		auto v = p.second;
		if (v >= m1) {
			m2 = m1;
			m1 = v;
			m5 = k;
		}
		else {
			m2 = max(m2, v);
		}
	}
	for (auto p : ma2) {
		auto k = p.first;
		auto v = p.second;
		if (v >= m3) {
			m4 = m3;
			m3 = v;
			m6 = k;
		}
		else {
			m4 = max(v, m4);
		}
	}
	if (m5 == m6) {
		if (m1 - m2 > m3 - m4) {
			cout << n - m4 - m1 << endl;
		}
		else {
			cout << n - m2 - m3 << endl;
		}
	}
	else {
		cout << n - m1 - m3 << endl;
	}
}

Measured memory_bytes: 6528
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (a, b) = scan!(i64, i64);
    if b % a == 0 {
        println!("{}", a + b)
    } else {
        println!("{}", b - a)
    }
}


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

Measured memory_bytes: 24916
/*  -*- coding: utf-8 -*-
 *
 * 2784.cc: Similarity of Subtrees
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int P = 4073;
const int MOD = 1000000009;

/* typedef */

typedef long long ll;
typedef vector<int> vi;
typedef queue<int> qi;

struct Trp {
  int n, d, h;
  Trp() {}
  Trp(int _n, int _d, int _h): n(_n), d(_d), h(_h) {}

  bool operator==(const Trp &t) const {
    return n == t.n && d == t.d && h == t.h;
  }

  bool operator<(const Trp &t) const {
    return n < t.n || (n == t.n && (d < t.d || (d == t.d && h < t.h)));
  }

  void print() { printf("(%d,%d,%d)\n", n, d, h); }
};

/* global variables */

vi nbrs[MAX_N];
int prts[MAX_N], cns[MAX_N];
Trp ts[MAX_N];

/* subroutines */

inline void setmax(int &a, int b) { if (a < b) a = b; }

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    nbrs[a].push_back(b);
    nbrs[b].push_back(a);
  }

  fill(ts, ts + n, Trp(1, 0, 1));
  
  prts[0] = -1;
  qi q;
  q.push(0);

  while (! q.empty()) {
    int u = q.front(); q.pop();
    int &up = prts[u];
    vi &nbru = nbrs[u];
    for (vi::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int &v = *vit;
      if (v != up) {
	prts[v] = u;
	cns[u]++;
	q.push(v);
      }
    }
  }

  for (int i = 0; i < n; i++)
    if (! cns[i]) q.push(i);

  while (! q.empty()) {
    int u = q.front(); q.pop();
    int &up = prts[u];

    if (up >= 0) {
      ts[up].n += ts[u].n;
      setmax(ts[up].d, ts[u].d + 1);
      ts[up].h = (ts[up].h + (ll)ts[u].h * P) % MOD;
      if (--cns[up] == 0) q.push(up);
    }
  }
  sort(ts, ts + n);
  //for (int i = 0; i < n; i++) ts[i].print();

  ll c = 0;
  for (int i = 0, j = 0; i < n;) {
    while (j < n && ts[i] == ts[j]) j++;
    int d = j - i;
    c += (ll)d * (d - 1) / 2;
    i = j;
  }

  printf("%lld\n", c);
  return 0;
}



Measured memory_bytes: 11024
import java.util.*;
class Main {
  public static void main(String[] args){
    
      Scanner scanner = new Scanner(System.in);
      int x = scanner.nextInt();
      int y = scanner.nextInt();
      System.out.println(Buttons(x,y));
 

  }
    public static int Buttons(int A, int B) {
      if(A==B) return A+B;
      int result = Math.max(A, B);
      return result+result-1;
       
    }
}

Measured memory_bytes: 25172
n = int(input())
import collections
chk = collections.deque([])
for i in range(n):
  s = input()
  s = sorted(s)
  chk.append(''.join(s))
#chk = list(chk)
c = collections.Counter(chk)
c = dict(c)
ans = 0
for i in c.values():
  ans += i*(i-1)//2
print(ans)

Measured memory_bytes: 72504
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
int t[110], v[110];
int lm[202020];
int n, T;

bool f(double now, int since){
    for(int tm = since; tm <= T; tm++){
        if(lm[tm] < now) return false;
        now-=0.5;
    }
    return true;
}

int main(){
    cin >> n;
    rep(i, n){
        cin >> t[i];
        t[i] *= 2;
        T += t[i];
    }
    rep(i, n) cin >> v[i];
    int past = 0, st = 0;
    for(int i=0; i<=T; i++){
        if(past + t[st] == i){
            past += t[st];
            lm[i] = min(v[st], v[st+1]);
            st++;
        }else{
            lm[i] = v[st];
        }
        lm[i+1] = v[st];
    }

    double ans = 0;
    double now = 0;
    for(int i=0.; i<T; i++){
        if(f(now+0.5, i+1)){
            now += 0.5;
        }else if(!f(now, i+1)){
            now -= 0.5;
        }
        ans += now * 0.5;
        // cout << (i)/2. << "   "  << lm[i] << " " << now << endl;
    }
    cout << fixed << setprecision(15) << ans << endl;
}



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

long long gcd(long long x, long long y){
    if(x < y) swap(x, y);
    long long r = x % y;
    if(r == 0) return y;
    else return gcd(y, r);
}
 
long long lcm(long long x, long long y){
    return x * y / gcd(x, y);
}

long long div2Times(long long x){
    long long cnt = 0;
    while(x % 2 == 0){
        x /= 2;
        cnt++;
    }
    return cnt;
}

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

    int n;
    long long m;
    cin >> n >> m;
    int d2 = -1;
    vector<long long> A(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
        A[i] /= 2;
        if(i == 0) d2 = div2Times(A[i]);
        else{
            if(d2 != div2Times(A[i])){
                cout << 0 << endl;
                return 0;
            }
        }
    }

    long long l = A[0];
    for(int i = 1; i < n; i++){
        l = lcm(l, A[i]);
        if(l > m){
            cout << 0 << endl;
            return 0;
        }
    }

    long long ans = (m / l + 1) / 2;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n+1];
    int ans=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        ans^=a[i];
    }
    for(int i=0;i<n;i++)
    {
        int x=ans^a[i];
        cout<<x<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 4376
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define mp make_pair
#define pb push_back
#define pf push_fron
#define INF 1000000000
typedef long long ll;

int a[100010];

int main() {
	
	int n, maxnum = -1;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	

	for (int i = 1; i < 100010; i++) {
		int p, e;
		int *pre, *en;
		pre = lower_bound(a, a + n, i - 1);
		en = lower_bound(a, a + n, i + 2);
		p = distance(a, pre);
		e = distance(a, en);
		maxnum = max(maxnum, e - p);
	}

	cout << maxnum << endl;

	return 0;
}

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

int main(void)
{
  int N, K;
  cin >> N >> K;
  
  vector<int> sunuke(N);		//すぬけ君
  
  //おかしの数だけ入力
  for(int i = 0; i < K; i++)
  {
      int d;
      cin >> d;
      for(int j = 0; j < d; j++)
      {
          int A;
          cin >> A;
          sunuke[A-1]++;
      }
  }
  
  int No_sweets = 0;
  for(int i = 0; i < sunuke.size(); i++)
  {
      if(sunuke[i] == 0) No_sweets++;
  }
  
  cout << No_sweets << endl;
  return 0;
}


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

int main()
{
    long long  w,h,x,y;
    double s1,s2,s;
    cin >> w >> h >> x >> y;
    s = (double)(w*h)/2;
    if(2*x == w && 2*y == h)
    {
        printf("%7.6lf 1",s);
    }
    else if ( w == 0 || h == 0)
    {
        printf("%7.6lf 1",s);
    }
    else
    {
        printf("%7.6lf 0",s);
    }
    
    return 0;
}

Measured memory_bytes: 256
import sys,queue,math,copy,itertools,bisect,collections
LI = lambda : [int(x) for x in sys.stdin.readline().split()]

N,M = LI()
data = [LI() for _ in range(N)]
dp = [0] * (M+1)
data.sort(key=lambda x:x[1], reverse=True)

N0 = 2 ** M.bit_length()
seg = [0] * (2*N0)

def seg_set(i,x):
    i = i + N0- 1
    seg[i] = x
    while i > 0:
        i = (i-1) // 2
        seg[i] = max(seg[i*2+1],seg[i*2+2])

def seg_query(i):
    i = i + N0 - 1
    ret = seg[i]
    while i ^ (i+1) < i+1:
        i = (i-2) // 2
        ret = max(ret,seg[i])
    return ret

for i in range(M+1):
    seg_set(i,i)

for a,b in data:
    if a <= M:
        i = seg_query(M-a+1)
        if i > 0:
            dp[i] = b
            seg_set(i,0)
print(sum(dp))

Measured memory_bytes: 67032
#include "bits/stdc++.h"
using namespace std;
using lint = long long;
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (lint i = 0; i < lint(n); ++i)
#define Rep(i, n) for (lint i = lint(n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { int to; double cost; };
using P = pair<lint, lint>;
using D = pair<double, double>;
using DI = pair<double, int>;
//const lint mod = 998244353LL;
const lint mod = 1000000007LL;
const lint inf = 3LL * mod * mod;

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

lint modpow(lint x, lint n, lint m) {
	lint ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (m <= ans) ans %= m;
		}
		x *= x;
		if (m <= x) x %= m;
		n >>= 1;
	}
	return ans;
}

lint fact[1000000];
void f_init(lint n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint inver[1000000]; bool inve[100000];
lint inv(lint x) {
	if (x == 0) return 0;
	else if (inve[x]) return inver[x];
	else {
		inve[x] = true;
		return inver[x] = modpow(x, mod - 2, mod);
	}
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * inv(fact[n - r]) % mod * inv(fact[r]) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

lint gcd(lint a, lint b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

lint lcm(lint a, lint b) { return a / gcd(a, b) * b; }

bool pri(lint p) {
	for (lint i = 2; i * i <= p; i == 2 ? ++i : i += 2) if (p % i == 0) return false;
	return p > 1;
}

map<lint, lint> factring(lint n) {
	map<lint, lint>ans;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

double dis(D a, D b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); }

int x, n;
int main() {
	cin >> x;
	n = x / 100;
	x %= 100;
	if (x <= 5 * n) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define put(x) cout<<#x<<" = "<<x<<endl;
#define X first
#define Y second
#define pb push_back
#define pp pop_back
#pragma GCC optimize("O2")
using namespace std;
typedef long long num;
typedef pair<int,int> point;
const int maxn=1e5+10;

int a,b;
// nammmmooos soale in
int32_t main(){
    cin>>a>>b;
    if(a*b==15){
	cout<<"*\n";
    }else if(a+b==15){
	cout<<"+\n";
    }else{
	cout<<"x\n";
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
 
#define gc() getchar_unlocked()
int in()
{
    int n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc();
    while (c >= '0');
    return n;
}
 
int x[102], y[102];
 
int main()
{
    int n, i, t, t2;
    int d, d1, d2;
    long long d3;
     
    n = in();
    for (i = 0; i < n; i++) x[i] = in();
    for (i = 0; i < n; i++) y[i] = in();
    d = 0, d1 = 0, d2 = 0, d3 = 0;
    for (i = 0; i < n; i++) {
        t = x[i] - y[i];
        if (t < 0) t = -t;
        if (t > d) d = t;
        d1 += t;
        t2 = t*t, d2 += t2;
        d3 += t2*t;
    }
    printf("%d\n", d1);
    printf("%.8lf\n", sqrt((double)d2));
    printf("%.8lf\n", pow((double)d3, 1.0/3));
    printf("%d\n", d);
    return 0;
}


Measured memory_bytes: 2112
import numpy as np
N, M = [int(x) for x in input().split()]
X = [int(x) for x in input().split()]
X = sorted(X)
ans = np.zeros(M)
for i in range(M-1):
    ans[i] = X[i+1] - X[i]

ans = sorted(ans, reverse=True)

print(int(sum(ans[N-1:])))

Measured memory_bytes: 23024
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <queue>
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define sort_key(struct_name,key_name) [](const struct_name &x, const struct_name &y){return x.key_name < y.key_name;}
#define pb(x) push_back(x)
typedef long long ll;
const long long MOD = 1e9 + 7;
using namespace std;

//main
ll GCD(ll a, ll b){
    ll r, temp;
    if(a == 0) return b;
    else if (b == 0) return a;
    else{
        if(a<b){
            temp = a;
            a = b;
            b = temp;
        }
        r =  a%b;
        while(r!=0){
            a = b;
            b = r;
            r = a%b;
        }
        return b;
    }
}
ll IsPrime(ll N){
    ll i;
    ll Ns = sqrt(N);
    if(N<=2) return 1;
    else if(N%2 == 0) return 0;
    else {
        for(i=3; i<=Ns;i+=2){
            if(N%i == 0) return 0;
        }
        return 1;
    }
}

int main(){
    ll A,B; cin >> A >> B;
    ll G = GCD(A,B);
    ll ans = 0;
    ll Gs = sqrt(G);
    rep(i,Gs) if(G%(i+1)==0 && IsPrime(i+1)==1) ans += 1;
    rep(i,Gs) if((i+1)*(i+1)!=G && G%(i+1) == 0 && IsPrime(G/(i+1))==1) ans += 1;
    cout << ans << endl;
}



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

int P[10010];
int sum[10010]={0};

void prime() {
  int i=3,j,k,cnt=1;
  P[0] = 2;
  while(cnt < 10005){
    k=0;
    for(j=3;j<=sqrt(i);j+=2){
      if(i%j==0){
	k=1;
	break;
      }
    }
    if(k==0) {
      P[cnt] = i;
      cnt++;
    }
    i+=2;
  }
  sum[0] = P[0];
  for(int i=1;i<10005;i++){
    sum[i] = sum[i-1] + P[i];
  }
}

int main(){
  int n;
  prime();
  while(cin >> n , n){
    cout << sum[n-1] << endl;
  }
}

Measured memory_bytes: 1236
n, k = gets.chomp.split(" ").map(&:to_i)
v_arr = gets.chomp.split(" ").map(&:to_i)

max_value = 0
(0..k).each do |a|
  next if a > v_arr.length
  a_arr = a > 0 ? v_arr[0..(a-1)] : []
  (0..(k - a)).each do |b|
    next if b > v_arr.length - a
    b_arr = b > 0 ? v_arr[(b*(-1))..-1] : []
    arr = (a_arr + b_arr).sort
    cd = k - a - b
    next if cd < 0
    index = arr.index{|x| x >= 0}
    if index.nil? then
      value = 0
    elsif index == 0 then
      value = arr.inject(0){|sum, i| sum + i }
    elsif cd > index then
      if index == arr.length - 1 then
        value = 0
      else
        value = arr[index..-1].inject(0){|sum, i| sum + i }
      end
    else
      value = arr[cd..-1].inject(0){|sum, i| sum + i }
    end
    max_value = value if value > max_value
  end
end

puts max_value


Measured memory_bytes: 3836
#include <iostream>
#include <cstdlib>
#include <bitset>
#include <map>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#include <sstream>
#include <math.h>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecchar vector<char>
#define vecstr vector<string>
#define vec2str vector<vector<string>>
#define vecbool vector<bool>
#define vec2bool vector<vector<bool>>
#define pairll pair<ll,ll>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s >= 0;s--)

#define Pi 3.1415926535897932384626

int main() {
	ll n,ans=0;
	string s="No";
	bool flag = false;

	cin >> n;

	vec2ll a(n-1,vecll(3));

	forll(i, 0, n-1)
		cin >> a[i][0] >> a[i][1] >> a[i][2];

	forll(i, 0, n)
	{
		ll time = 0;
		ll count = i;

		while (count < n-1)
		{
			if (time < a[count][1])
			{
				time = a[count][1];
			}
			else if ((time - a[count][1]) % a[count][2] != 0)
			{
				time += a[count][2] - (time - a[count][1]) % a[count][2];
			}

			time += a[count][0];
			count++;
		}

		cout << time << "\n";
	}
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define SIZE 1000001
#define pib pair<int,bool>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin>>n;
	vector<int> num(n);
	for(int i=0;i<n;i++){
		cin>>num[i];
	}

	sort(num.begin(), num.end());

	vector<bool> isPrime(SIZE, true);
	vector<pib> ans;

	for(int i=0;i<n;i++){
		bool check = true;
		int sqrtn = (int)sqrt(num[i]);
		for(int j=1;j<=sqrtn && check;j++){
			if(!(num[i] % j)){
				if(!isPrime[j]) check = false;
				if(!isPrime[num[i] / j]){
					check = false;
					if(ans.back().first == num[i]) ans.back().second = true;
				}
			}
		}
		if(check){
			ans.push_back(make_pair(num[i], false));
		}
		isPrime[num[i]] = false;
	}

	int val = 0;
	for(int i=0;i<ans.size();i++){
		if(!ans[i].second) val++;
	}
	cout<<val;
}

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

 using namespace std;
 typedef long long ll;
 #define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

   vector<int> H(N);
   rep(i, N) cin >> H.at(i);

   int move_max = 0, move = 0;
   rep(i, N - 1) {
    if (H.at(i) < H.at(i + 1)) move = 0;
    else move++;

    move_max = max(move_max, move);
   }
   cout << move_max << endl;
 }


Measured memory_bytes: 640
using System;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = Convert.ToInt32(Console.ReadLine());
            int[] A = new int[N];
            for (var i = 0; i < N; i++)
            {
                A[i] = Convert.ToInt32(Console.ReadLine());
            }
            int[] copy = new int[N];
            A.CopyTo(copy, 0);
            Array.Sort(copy);
            for (var i = 0; i < N; i++)
            {
                if (copy[N - 1] == A[i])
                {
                    Console.WriteLine(copy[N - 2]);
                } else
                {
                    Console.WriteLine(copy[N - 1]);
                }
            }
        }
    }
}


Measured memory_bytes: 18004
#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() {
  string s;
  cin>>s;
  if(s=="RRR"){
    cout<<3<<endl;
  }
  else if(s=="RRS"||s=="SRR"){
     cout<<2<<endl;
  }
  else if(s=="SSS"){
    cout<<0<<endl;
  }
  else{
    cout<<1<<endl;
  }
}

Measured memory_bytes: 3620
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#define ll long long
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define loop(i,start, stop) for(int i = start; i < (stop); i++)
using namespace std;

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

  if (N % 10 == 3) cout << "bon" << endl;
  else if (1 < N % 10 && N % 10 < 6) cout << "hon" << endl;
  else if (N % 10 == 7 || N % 10 == 9) cout << "hon" << endl;
  else cout << "pon" << endl;

  return 0;
}


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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	int N;
	string S;
	cin >>N >>S;
	vector<int> s(N, 0);
	for (int i=0; i<N; i++)
		s.at(i)=S.at(i)-'0';
	vector<vector<int>> n(10, vector<int> {0, N, 0});
	for (int i=0; i<N; i++) {
		int nn=s.at(i);
		n.at(nn).at(0)++;
		n.at(nn).at(1)=min(n.at(nn).at(1), i);
		n.at(nn).at(2)=max(n.at(nn).at(2), i);
	}
	vector<bool> A(1000, false);
	for (int i=0; i<=9; i++) {
		if (0==n.at(i).at(0))
			continue;
		for (int j=0; j<=9; j++) {
			if (0==n.at(j).at(0))
				continue;
			int L=n.at(i).at(1);
			int R=n.at(j).at(2);
			int S=i*100+j;
			for (int k=L+1; k<R; k++)
				A.at(S+s.at(k)*10)=true;
		}
	}
	int SS=0;
	for (int i=0; i<1000; i++)
		if (A.at(i))
			SS++;
	cout <<SS <<endl;
	return 0;
}



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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e5+23;

vector<int> pows;
int dp[N];
int n;

int dfs(int m = 0) {
  int ret = 1e9;
  if (m > n) return ret;
  if (m == n) return 0;
  if (dp[m]) return dp[m];
  for (int x: pows) {
    if (m+x > n) continue;
    ret = min(ret, 1+dfs(m+x));
  }
  return dp[m] = ret;
}

void solve() {
  scanf("%d", &n);
  pows.push_back(1);
  for (int p = 6; p <= N; p *= 6) {
    pows.push_back(p);
  }
  for (int p = 9; p <= N; p *= 9) {
    pows.push_back(p);
  }
  sort(pows.begin(), pows.end(), greater<int>());
  printf("%d", dfs());
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 640