akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
#define fi first
#define sc second
#define pii pair<int,int>
#define vi vector<int>
#define msi map<string,int>
#define si set<int>
#define all(v) v.begin(),v.end()
#define sz(v)  int((v).size())
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define dep(i,a,b)	for(int i=a;i>=b;i--)
#define isinarr(i,n) ((i>=0)?((i<n)?1:0):0)
#define fastio  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ppb pop_back
#define present(container, element) (container.find(element) != container.end())      //set,map etc.
#define cpresent(container, element) (find(all(container),element) != container.end())    //vector
#define hell 1000000007
#define PI 3.14159265
#define mp make_pair
#define	endl '\n'

using namespace std;
void solve()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	map<int,int>m;
	rep(i,0,n)
	{
		cin>>a[i];
		int min=1000000001;
		if(i>=k)
		{
			for(int j=1;j<=k;j++)
			{
				if(m[i-j]+abs(a[i]-a[i-j])<min)
					min=m[i-j]+abs(a[i]-a[i-j]);
			}
			m[i]=min;
		}
		else if(i==0)
		{
			m[i]=0;
		}
		else
		{
			for(int j=1;j<=i;j++)
			{
			if(m[i-j]+abs(a[i]-a[i-j])<min)
				min=m[i-j]+abs(a[i]-a[i-j]);	
			}
			m[i]=min;
		}
	}
	cout<<m[n-1];
} 



signed main()
{
    fastio
    int t=1;
    //cin>>t;
    while(t--)
    	solve();
    return 0;
}

Measured memory_bytes: 7296
#include <stdio.h>

int main(){

  int sec = 0;
  int total = 0;
  int i;
  int minutes = 0;

  for(i = 0; i < 4; i++){
    scanf("%d", &sec);
    total += sec;
  }

  while((total / 60) >= 1 ){
    total = total - 60;
    minutes++;
  }
  printf("%d\n", minutes);
  printf("%d\n", total);




  return 0;
}

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

int n, a[200004];
multiset<int> s;

int over(int k) {
    int ans = 1;
    while (ans <= k) {
        ans *= 2;
    }
    return ans;
}

int main() {
    cin >> n;
    for (int i=0; i<n; i++) cin >> a[i], s.insert(a[i]);

    sort(a, a+n);
    
    int ans = 0;
    for (int i=n-1; ~i; i--) if (s.find(a[i]) != s.end()) {
        int k = over(a[i]) - a[i];
        s.erase(s.lower_bound(a[i]));
        if (s.find(k) != s.end()) {
            s.erase(s.lower_bound(k)); ans += 1;
        }
    }

    cout << ans;
}

Measured memory_bytes: 10368
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	int n;
	cin >> n;
	vector<vector<int>> M(n);
	vector<int> a(n-1),b(n-1);
	rep(i,n-1)
	{
		int foo,fooo;
		cin >> foo >> fooo;
		foo--;fooo--;
		M[foo].push_back(fooo);
		M[fooo].push_back(foo);
		a[i]=foo;
		b[i]=fooo;
	}
	vector<int> weight(n);
	rep(i,n)cin >> weight[i];
	sort(ALL(weight));
	vector<int> ans(n);
	stack<int> S;

	S.push(0);
	ans[0]=ans.back();
	ans.pop_back();

	while(!S.empty())
	{
		int now = S.top();
		if(ans[now]==0)
		{
			ans[now]=weight.back();
			weight.pop_back();
		}
		int next = -1;
		rep(i,M[now].size())
		{
			if(ans[M[now][i]]==0)
			{
				S.push(M[now][i]);
				next = M[now][i];
			}	
		}
		if(next==-1)S.pop();
	}
	int sum = 0;
	rep(i,n-1)
	{
		sum += min(ans[a[i]],ans[b[i]]);
	}
	cout<<sum<<endl;
	rep(i,n)
	cout<<ans[i]<<endl;



	
	

	return 0;
}

Measured memory_bytes: 1152
import sys
import math
def input(): return sys.stdin.readline().rstrip()

def main():
    A, B = map(int, input().split())
    a = math.floor(A // 0.08)

    for i in range(a, a + 20):
        if math.floor(i * 0.08) == A and math.floor(i * 0.1) == B:
            print(i)
            exit()
    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;

int main(){
  int h,w;
  while(true){
    cin >> h >> w;
    if(h==0&&w==0) break;
    for(int i = 0;i < h;i++){
      for(int j = 0;j < w;j++){
	cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;
vector<int> S[MAX];
map<pair<int,int>,int> M;

int DFS(int u,int v){
    int ans=0;
    stack<pair<int,int>> ST;
    for(int i=0;i<S[u].size();i++){
        int a=S[u][i];
        ST.push(make_pair(u,a));
        M[make_pair(u,a)]++;
    }
    
    while(!ST.empty()){
        int a=ST.top().first;
        int b=ST.top().second;
        ST.pop();
        if(b==v){
            ans++;
            continue;
        }
        for(int i=0;i<S[b].size();i++){
            int c=S[b][i];
            if(M[make_pair(b,c)]) continue;
            ST.push(make_pair(b,c));
            M[make_pair(b,c)]++;
        }
    }
    
    return ans;
}

int main(){
    
    int N;cin>>N;
    
    vector<int> cnt(N,0),T;
    
    int M;cin>>M;
    
    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        cnt[a]++;
        cnt[b]++;
        S[a].push_back(b);
        S[b].push_back(a);
    }
    
    bool ok=true;
    int sum=0;
    
    for(int i=0;i<N;i++){
        if(cnt[i]%2) ok=false;
        if(cnt[i]!=2){
            sum++;
            T.push_back(i);
        }
    }
    
    if(N+1>=M) ok=false;
    if(N+2==M&&sum==2){
        if(DFS(T[0],T[1])>=3) ok=false;
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}




Measured memory_bytes: 18688
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e16
using namespace std;
typedef pair<ll, ll> P;

class UnionFind {
public:
	vector<int>par, rank, node;
	UnionFind(int n) :par(n), rank(n, 0), node(n, 1) {
		for (int i = 0;i < n;i++)par[i] = i;
	}
	
	int find(int x) {
		return par[x] == x ? x : par[x] = find(par[x]);
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}

	//木の高さ
	void unite_tree(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (rank[x] < rank[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rank[x] == rank[y])rank[x]++;
		}
	}
	int root_size(int x) {
		return rank[find(x)];
	}

	int size(int x) {
		return node[find(x)];
	}

	//連結成分
	void unite_node(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (size(x) < size(y))swap(x, y);
		node[x] += node[y];
		par[y] = par[x];
	}
};


int main(void) {
	int n, m, ans = 0;
	int x, y, z;
	cin >> n >> m;
	UnionFind tree = UnionFind(n + 1);
	for (int i = 0;i < m;i++) {
		cin >> x >> y >> z;
		tree.unite_tree(x, y);
	}
	for (int i = 1;i <= n;i++) {
		if (i == tree.find(i))ans++;
	}
	cout << ans << endl;
	return 0;
}

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

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

using ll = long long;
using P = pair<int,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    int m = 0, x = INF;
    rep(i, n){
        int a, b;
        scanf("%d %d", &a, &b);
        m = max(a, m);
        x = min(x, b);
    }

    int ans = m + x;
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
     
    using namespace std;
     
    #define all(x) x.begin(), x.end()
    typedef vector<int> vi;
    typedef pair<int,int> ii;
    typedef long long ll;
     
    const ll inf = 3e18 + 5;
     
    const int MAXN = 1 << 19;
    int N = 400000;
    int seg[2 * MAXN], A[MAXN];
    typedef vector<vi> vvi;
     
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
     
        vi a(3);
        cin >> a[0] >> a[1] >> a[2];
        sort(all(a));
        if(a[0] + a[1] == a[2])
            cout << "Yes";
        else
            cout << "No";
    }

Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=[1]
di={}
di[1]=1
for i in a:
    b=a[l[-1]-1]
    if b in di:
        x=b
        break
    l.append(b)
    di[b]=1
t1=0
for j in l:
    if j==x:
        break
    else:
        t1+=1
t2=len(l)-t1
if k<=t1:
    print(l[k])
else:
    num=(k-t1)%t2
    print(l[t1+num])

Measured memory_bytes: 35592
from collections import deque
n = int(input())
d = deque()
d.append("3")
d.append("5")
d.append("7")
p = ["3","5","7"]
ans = 0
while d:
    now = d.popleft()
    for i in p:
        d.append(now+i)
    if now.count("3")*now.count("5")*now.count("7") > 0 and int(now) <= n:
        ans += 1
    if int(now) > n:
        break
print(ans)

Measured memory_bytes: 7540
//
//  500 Yen Coins.cpp
//  NYU Progteam
//
//  Created by Xinyu Qu on 3/6/20.
//  Copyright © 2020 Xinyu Qu. All rights reserved.
//

#include <stdio.h>
#include <iostream>

using namespace std;

int main(){
    long long a,b;
    cin >> a >> b;
    if(500 * a >= b) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s1[4000],s2[4000],s3[4000];
vector<int> lis(vector<int>&v, int &ans){
	int n = v.size();
	int inf = INT_MAX;
	vector<int> d(n+2,inf);
	d[0] = -inf;
	vector<int> id(n+1),pre(n+1);
	for(int i = 0; i < n; i++){
		int j = upper_bound(d.begin(), d.end(), v[i]) - d.begin();
		if(d[j-1] < v[i]){
			d[j] = v[i];
			pre[i] = id[j-1];
			id[j] = i;
		}
	}
	ans = upper_bound(d.begin(),d.end(),inf-1) - d.begin();
	ans--;
	vector<int> sec(ans);
	int j = id[ans];
	for(int i = ans-1; i >= 0; i--){
		sec[i] = v[j];
		j = j = pre[j];
	}
	return sec;
}
int main(){
	scanf("%s %s",s1,s2);
	int a,b;
	a = strlen(s1); b=strlen(s2);
	vector<vector<int> > gr(a);
	int tot=0;
	for(int i = b-1; i >=0; i--){
		for(int j = 0; j < a; j++)
			if(s1[j] == s2[i]){
				gr[j].push_back(i);
				tot++;
			}
	}
	vector<int> v;
	v.reserve(tot);
	for(int i = 0; i < a; i++)
		for(int x : gr[i])
			v.push_back(x);
	int k;
	vector<int>sec=lis(v,k);
	s3[k] = 0;
	for(int i = 0; i < k; i++)
		s3[i] = s2[sec[i]];
	printf("%s\n",s3);
	return 0;
}

Measured memory_bytes: 191688
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	int N;
	cin >> N;
	int ki = 0;
	int gu = 0;
	for(int i=0; i<N; i++){
		int tmp;
		cin >> tmp;
		if(tmp%2 == 0) gu++;
		else ki++;
	}
	if(ki%2 == 0) cout << "YES" << endl;
	else{
		gu += ki/2; ki = 0;
		if(gu%2 == 0) cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;
}

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

long long n, x;
long long res;
long long t;
deque <long long> per;

int main() {
	cin >> n >> x;

	for (int i = 1; i <= 2 * n - 1; i++)
		per.push_back(i);

	if (x == 1 || x == 2 * n - 1)
		return cout << "No" << '\n', 0;

	res = per[n - 1];
	
	while (res != x) {
		t = per.back();
		per.push_front(t);
		per.pop_back();
		res = per[n - 1];
	}

	cout << "Yes" << '\n';
	
	for (auto i: per)
		cout << i << " ";
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REPR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
#define INF 1e9
int main()
{
  int N,M;
  cin>>N>>M;

const int NMMAX=50;
int A[NMMAX],B[NMMAX];

for (int i = 0; i < M; i++)
{
  cin>>A[i]>>B[i];
}

int road[NMMAX];
for (int  i = 0; i < N; i++)
{
  road[i]=0;

}
for (int i = 0; i < M; i++)
{
  road[A[i]-1]+=1;
  road[B[i]-1]+=1;

}
for (int i = 0; i < N; i++)
{
  cout<<road[i]<<endl;
}}

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

int mae_max (vector<int> &c ,int i){
int kaeshi_max = c.at(0);
  
  if (i == 0){
   return  c.at(0);
  }
    
kaeshi_max = max(mae_max (c ,i - 1),c.at(i - 1) );    
return kaeshi_max;
}
  

int main (){
int N;
cin >> N;
vector<int> vec(N);
for (int i = 0; i < N; i++){
   cin >> vec.at(i);
  }
int count = 0;
for (int i = 0; i < N; i++){
   if(mae_max (vec , i) <= vec.at(i) )
    count++;
  }
cout << count << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <set>
#include <algorithm>
using namespace std;
#define LL long long
#define MX 200005

int main ()
{
    LL k;
    scanf("%lld",&k);
    LL t = k/50;
    LL m = k%50;
    printf("50\n");
    for (int i=0;i<49;i++)
    {
        if (i<m)
            printf("%lld ",t+i+50-(m-1));
        else
            printf("%lld ",t+i-m);
    }
    printf("%lld\n",t+49-m);
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

typedef long long LL;
const int Mod = 924844033;
const int MN = 2005;

int N, K;
int A[MN * 2], M;
int f[2][2][MN];

int main() {
	scanf("%d%d", &N, &K);
	for (int i = 1; i <= K; ++i) {
		for (int j = i; j <= N; j += K) A[++M] = j != i;
		for (int j = i; j <= N; j += K) A[++M] = j != i;
	}
	int o = 0;
	f[0][0][0] = 1;
	for (int i = 1; i <= M; ++i) {
		o ^= 1;
		for (int j = 0; j <= N; ++j) {
			f[o][0][j] = f[o][1][j] = 0;
			f[o][0][j] = (f[o ^ 1][0][j] + f[o ^ 1][1][j]) % Mod;
			if (A[i] && j)
				f[o][1][j] = f[o ^ 1][0][j - 1];
		}
	}
//	for (int j = 0; j <= N; ++j) printf("%d, ", (f[o][0][j] + f[o][1][j]) % Mod);
	int Coef = 1, Ans = 0;
	for (int i = N; i >= 0; --i) {
		Ans = (Ans + (i & 1 ? -1ll : 1ll) * Coef * (f[o][0][i] + f[o][1][i])) % Mod;
		Coef = (LL)Coef * (N - i + 1) % Mod;
	}
	printf("%d\n", (Ans + Mod) % Mod);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;

int main(void) {
  vivi c(3,vi(3));
  rep(i,3)rep(j,3) cin >> c[i][j];
  bool ok = true;
  rep(i,2){
    if(c[i][0]-c[i+1][0] != c[i][1]-c[i+1][1] || c[i][0]-c[i+1][0] != c[i][2]-c[i+1][2]){
      cout << "No" << endl;
      return 0;
    }
  }
  rep(i,2){
    if(c[0][i]-c[0][i+1] != c[1][i]-c[1][i+1] || c[0][i]-c[0][i+1] != c[2][i]-c[2][i+1]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  
  
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
  int n;
  cin>>n;
  vector<ll>a(n);
  rep(i,n) cin>>a[i];
  sort(a.begin(),a.end());
  ll ans=a[n-1];
  int x=n-2;
  int left=2;
  rep(i,n-2){
    ans+=a[x];
    left--;
    if(left==0){
      x--;
      left=2;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int divide(int n)
{
	if(n%2)return 0;
	else
	{
		int cnt=0;
		while(n%2==0)
		{
			n/=2;
			cnt++;
		}
		return cnt;
	}
}

int main()
{
	int n,a,ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		ans+=divide(a);
	}
	cout<<ans<<endl;
	return 0;
}

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

int digitplus(int x){
    int ans = 1;
    while(x > 0){
        ans *= 10;
        x--;
    }

    return ans;
}

int main(){
    int N,M,digi,ans=0;
    bool trans = true;
    cin >> N >> M;
    vector<int> s(M),c(M),ansv(N);

    for(int i = 0;i < M;i++){
        cin >> s.at(i) >> c.at(i);
    }

    for(int i = 0;i < N;i++)
        ansv.at(i) = -1;

    for(int i = 0;i < M;i++){
        digi = digitplus((N - s.at(i))) * c.at(i);
        if(ansv.at(N - s.at(i)) == -1 || ansv.at(N - s.at(i)) == digi){
            if(s.at(i) == 1 && c.at(i) == 0 && N >= 2){
                trans = false;
                break;
            }else{
                ansv.at(N - s.at(i)) = digi;
            }
        }else{
            trans =false;
            break;
        }
    }

    for(int i = 0;i < N;i++){
        if(ansv.at(i) == -1)
            ansv.at(i) = 0;
    }


    if(trans){
        for(int i = 0;i < N;i++){
            if(i == N - 1 && ansv.at(i) == 0 && i != 0){
                ans += digitplus(i);
            }
            ans += ansv.at(i);
        }
        cout << ans << endl;
    }else
        cout << -1 << endl;
}

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

ss = []
cnt = 0
for c in s:
    if c == '1':
        cnt += 1
    else:
        if cnt > 0:
            ss.append(cnt)
            cnt = 0
        ss.append(cnt)
if cnt > 0:
    ss.append(cnt)
def solve(seq):
    l = len(seq)
    if not seq:
        return 0
    while seq[-1] == 0:
        seq.pop()

    #dp = [0]*(l+1)
    dp = [[0]*3 for i in range(l+1)]
    #print(seq)
    for i in range(l):
        # 0 -> 0, 1 -> 0, 2 -> 0
        nxt = max(dp[i])
        dp[i+1][0] = max(dp[i+1][0], nxt)
        if i+1 < l:
            if seq[i] >= 2:
                # 0 -> 1
                dp[i+1][1] = max(dp[i+1][1], dp[i][0] + seq[i])
            if seq[i] >= 2 and seq[i+1] >= 2:
                # 1 -> 1
                dp[i+1][1] = max(dp[i+1][1], dp[i][1] + seq[i]-1)
                # 2 -> 1
                dp[i+1][1] = max(dp[i+1][1], dp[i][2] + 1)
                # 1 -> 2
                dp[i+1][2] = max(dp[i+1][2], dp[i][1] + max(seq[i], seq[i+1])-1)
                # 2 -> 2
                dp[i+1][2] = max(dp[i+1][2], dp[i][2] + seq[i+1]-1)
            if seq[i+1] >= 2:
                # 0 -> 2
                dp[i+1][2] = max(dp[i+1][2], dp[i][0] + max(seq[i], seq[i+1]-1))
        if i+2 <= l:
            dp[i+2][0] = max(dp[i+2][0], dp[i][0] + max(seq[i], seq[i+1]))
            if seq[i] >= 2:
                dp[i+2][0] = max(dp[i+2][0], dp[i][1] + max(seq[i]-1, seq[i+1]))
                dp[i+2][0] = max(dp[i+2][0], dp[i][2] + seq[i+1])
        #print(dp[i])
    #print(dp[l])
    #print("-")
    return max(max(e) for e in dp)
idx = 0
cur = []
ans = 0
while idx < len(ss):
    if idx+1 < len(ss) and ss[idx] == ss[idx+1] == 0:
        idx += 2
        ans += solve(cur)
        cur = []
    elif not cur and ss[idx] == 0:
        idx += 1
    else:
        if ss[idx]:
            cur.append(ss[idx])
        idx += 1
if cur:
    ans += solve(cur)
print(ans)


Measured memory_bytes: 8460
package main
 
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
 
var sc = bufio.NewScanner(os.Stdin)
var ReadString func() string
var ReadLine func() string
var ReadInt64 func() int64
var ReadInt func() int
var ReadIntSlice func(int) []int
var ReadInt64Slice func(int) []int64
var GetIntAbs func(int) int
var Atoi func(string) int
var FindMin func([]int) int
var FindMax func([]int) int
var StrReverse func(string) string
var NthB func(int, int) int
 
func init() {
	ReadString = newReadString()
	ReadLine = readLine
	ReadInt64 = readInt64
	ReadInt = readInt
	ReadIntSlice = readIntSlice
	FindMin = findMin
	FindMax = findMax
	StrReverse = strReverse
	GetIntAbs = getIntAbs
	NthB = nthB
}
 
func main() {
	a := ReadInt64()
	b := ReadInt64()
	c := ReadInt64()
  if (a == b && a == c) {
	fmt.Println("No")
  } else if ((a == b && b != c) || (b == c && c != a) || (a == c && b != c)) {
        fmt.Println("Yes")
  } else {
    fmt.Println("No")
  }
}
 
func strReverse(s string) string {
	runes := []rune(s)
	l := len(runes)
	for i, j := 0, l-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}
 
func newReadString() func() string {
	sc.Buffer(make([]byte, 202400), 404800)
	sc.Split(bufio.ScanWords)
	return func() string {
		if !sc.Scan() {
			panic("scanできなかった")
		}
		return sc.Text()
	}
}
 
func readLine() string {
	if !sc.Scan() {
		panic("line をscanできなかった")
	}
	return sc.Text()
}
 
func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		fmt.Println("parseInt失敗")
		panic(err.Error())
	}
	return int64(i)
}
 
func readInt() int {
	i := ReadInt64()
	return int(i)
}
 
func readIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}
 
func readInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt64()
	}
	return arr
}
 
/*------ number util ------*/
 
func getIntAbs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}
 
func atoi(a string) int {
	i, err := strconv.Atoi(a)
	if err != nil {
		panic(err.Error())
	}
	return i
}
 
func findMin(arr []int) int {
	if len(arr) == 0 {
		return 0
	}
	min := arr[0]
	for _, v := range arr {
		if v < min {
			min = v
		}
	}
	return min
}
 
func findMax(arr []int) int {
	if len(arr) == 0 {
		return 0
	}
	max := arr[0]
	for _, v := range arr {
		if v > max {
			max = v
		}
	}
	return max
}
 
// nのnthビット目
func nthB(n, nth int) int {
	return n >> uint(nth) & 1
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define UNIQUE(c) sort(ALL(c)), c.erase(unique(ALL(c)), c.end())

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  string S; cin >> S;
  int N = S.size();

  ll ans = 0;

  REP(i, N) {
    if (S[i] == 'A') {
      vector<int> A(1), BC(1);
      while (i < N) {
        if (S[i] == 'A') {
          A.emplace_back(1);
          BC.emplace_back(0);
          i++;
        } else if (i < N-1 and S[i] == 'B' and S[i+1] == 'C') {
          A.emplace_back(0);
          BC.emplace_back(1);
          i += 2;
        } else {
          break;
        }
      }
      REP(i, BC.size()-1) BC[i+1] += BC[i];
      REP(i, A.size()) {
        if (A[i] == 1) ans += BC[BC.size()-1] - BC[i];
      }
      i--;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2448
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int ac = 0;
        int wa = 0;
        int tle = 0;
        int re = 0;
        for(int i=0; i<n; i++) {
            String s = sc.next();
            if(s.equals("AC")) ac++;
            else if(s.equals("WA")) wa++;
            else if(s.equals("TLE")) tle++;
            else re++;
        }
        System.out.println("AC x "+ac);
        System.out.println("WA x "+wa);
        System.out.println("TLE x "+tle);
        System.out.println("RE x "+re);
    }
}

Measured memory_bytes: 58048
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
	long long N = 0, ans = 0;
	std::cin >> N;

	std::vector<long long> A(N), B(N);
	for (int i = 0; i < N; i++){
		std::cin >> A[i];
	}

	B = A;
	std::sort(B.begin(), B.end());

	long long max_1 = B[N - 1];
	long long max_2 = B[N - 2];

	for (int i = 0; i < N; i++){
		if (max_1 <= A[i]){
			ans = max_2;
		}
		else{
			ans = max_1;
		}	
		std::cout << ans << std::endl;
	}	

	return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> istream& operator>>(istream &is, pair<S, T> &p){ return is >> p.first >> p.second; }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ return os << "[" << p.first << ", " << p.second << "]"; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define For1(i, n) for(int i = 1; i <= (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)
#define Return(x) { Cout(x); return 0; }

// constexpr int MOD = 1e9+7;

using Pii = pair<int, int>;

int main(void){
    Cin(int, n);
    Cins(Pii, n, x);
    sort(Range(x), [](auto &x, auto &y){ return x.first+x.second > y.first+y.second; });
    // Couts(x);
    
    ll ans = 0;
    For(i, n) ans += ((i % 2 == 0) ? x[i].first : -x[i].second);
    Cout(ans);
}


Measured memory_bytes: 1024
n,k = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)

k.times do
  imos = Array.new(n+1, 0)
  n.times do |i|
    ind = i+1
    aa = a[i]
    left = [ind-aa,1].max
    right = [ind+aa,n].min
    imos[left-1] += 1
    imos[right] -= 1
  end
  next_a = []
  n.times do |i|
    if i == 0
      next_a[i] = imos[i]
    else
      next_a[i] = next_a[i-1] + imos[i]
    end
  end

  break if a == next_a

  a = next_a
end

puts a.join(' ')


Measured memory_bytes: 94560
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int data[10];

int main(){
for(int i=0;i<10;i++)cin>>data[i];
sort(data,data+10,greater<int>());

for(int i=0;i<3;i++)cout<<data[i]<<endl;

}

Measured memory_bytes: 1176
N, M = map(int, input().split())

shops = []
class Shop:
    def __init__(self,a,b):
        self.a = a
        self.b = b
    def __lt__(self, other):
        return self.a < other.a

for _ in [0]*N:
    a, b = map(int, input().split())
    shop = Shop(a, b)
    shops.append(shop)

shops = sorted(shops)

m = 0
idx = 0
ans = 0
while m < M:
    buy = min(M-m, shops[idx].b)
    ans += buy * shops[idx].a
    m += buy
    idx += 1
print(ans)

Measured memory_bytes: 63208
#include <iostream>
using namespace std;
int main(void){
  int one;
  int two;
  int three;
  cin>>one>>two>>three;
  if(one==two){
     if(one!=three||two!=three){
     cout<<"Yes";
     }
    else{
    cout<<"No";
    }
  }
  else if(one ==three){
       if(one!=two||three!=two){
    cout<<"Yes";
    }
    else{
    cout<<"No";
    }
  }
  else if(two==three){
    if(two!=one||three!=one){
    cout<<"Yes";
    }
    else{
    cout<<"No";
    }
  }
  else{
  cout<<"No";
  }
return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
 
    string s;
    cin >> s;
    int n = s.size();
 
    int res = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i; j < n; ++j){
            string sub = s.substr(i, j-i+1);
            int num = sub.size();

            bool flg = true;
            for(int k = 0; k < num; ++k){
                char c = sub[k];
                if(c!='A' && c!='C' && c!='G' && c!='T') {
                    flg = false;
                }
            }
 
            if(flg) res = max(res, num);
        }
    }
 
    cout << res << endl;
 
 
    return 0;
}

Measured memory_bytes: 256
a, b, k = map(int, input().split())

ans = []

for i in range(1, a + 1):
    if a % i == 0:
        ans.append(i)

ans2 = []

for j in ans:
    if b % j == 0:
        ans2.append(j)

if len(ans2) == 1:
    print(ans2[0])
else:
    print(ans2[-k])


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
 
using namespace std;
 
const LL MOD=1e9+7;

int n,x,y,ans[200010];
vector <int> g[200010],v[2],num[3],allpos,allval;

void dfs(int pos,int no,int d)
{
	v[d].pb(pos);
	rep(i,g[pos].size()) if(g[pos][i]!=no) dfs(g[pos][i],pos,d^1);
}

int main()
{
	cin>>n;
	rep(i,n-1)
	{
		scanf("%d%d",&x,&y);
		g[x].pb(y);
		g[y].pb(x);
	}
	dfs(1,0,0);
	repn(i,n) num[i%3].pb(i);
	if(v[0].size()<v[1].size()) swap(v[0],v[1]);
	rep(i,v[0].size()) allpos.pb(v[0][i]);
	rep(i,v[1].size()) allpos.pb(v[1][i]);
	if(v[1].size()>=num[2].size())
	{
		rep(i,num[1].size()) allval.pb(num[1][i]);
		rep(i,num[0].size()) allval.pb(num[0][i]);
		rep(i,num[2].size()) allval.pb(num[2][i]);
	}
	else
	{
		rep(i,num[1].size()) allval.pb(num[1][i]);
		rep(i,num[2].size()) allval.pb(num[2][i]);
		rep(i,num[0].size()) allval.pb(num[0][i]);
	}
	rep(i,n) ans[allpos[i]]=allval[i];
	repn(i,n) cout<<ans[i]<<' ';
	cout<<endl;
	return 0;
}

Measured memory_bytes: 21872
require "prime"
N,D = gets.split.map &:to_i
XS = (0...N).map{ gets.split.map &:to_i }
ans = 0
(0...N).each{ |i|
  (i+1...N).each{ |j|
    d2 = (0...D).reduce(0){ |a,k|
      a + (XS[i][k] - XS[j][k])**2
    }
    ans += 1 if d2.prime_division.all?{ |q,d| d % 2 == 0 }
  }
}
p ans


Measured memory_bytes: 2044
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(0,a+1):
    for j in range(0, b+1):
        if 0 <= ((x-500*i-100*j)//50) <= c:
            ans += 1
print(ans)

Measured memory_bytes: 9188
N = int(input())
A = list(map(int, input().split()))


def show(arr):
    for k in range(len(arr)):
        if k != len(arr) - 1:
            print(arr[k], end=' ')
        else:
            print(arr[k])


# 挿入ソート
for i in range(len(A)):
    v = A[i]
    j = i - 1

    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j = j - 1

    A[j+1] = v

    show(A)



Measured memory_bytes: 5980
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
int x[11][11];
signed main(){
	int a,b,ans=0;
	cin>>a>>b;
	f(i,a){
		f(j,b){
			cin>>x[i][j];
		}
	}
	f(i,a){
		for(int j=i+1;j<a;j++){
			int sum=0;
			f(k,b){
				sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			}
			if((int)(sqrt(sum))*(int)(sqrt(sum))==sum)ans++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <deque>
using namespace std;


int main() {
	long long a, b, c;
	cin >> a >> b >> c;
	if((a == b && b != c) || (a == c && a != b) || (b == c && a != b)) cout << "Yes";
	else cout << "No";
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define bitcnt(v) __builtin_popcount(v)
#define all(v) v.begin(), v.end()

void solution(){
	string s; cin >> s;
	if(s.back() == 's'){
		s += "es";
	}
	else{
		s += "s";
	}
	cout << s << endl;


	

}	


int main(){ 
	fio;
	int t;
	t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++){
		// cout << "Case #" << i << ": ";
		solution();
	} 
	return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* class */
class Info {
    public:
    int n, m, l;
    Info(int n, int m, int l):
    n(n), m(m), l(l) {}
    bool operator < (const Info &f) const {
        return n < f.n;
    }
    bool operator > (const Info &f) const {
        return n > f.n;
    }
};
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    map<int, int> mp1, mp2;
    for (int i = 0; i < N; i++) {
        if (i % 2) mp1[a[i]]++;
        else mp2[a[i]]++;
    }

    vector<Info> v;
    for (auto m : mp1) { v.push_back(Info(m.second, m.first, 1)); }
    for (auto m : mp2) { v.push_back(Info(m.second, m.first, 2)); }
    v.push_back(Info(0, 0, 1));
    v.push_back(Info(0, 0, 2));
    sort(v.begin(), v.end(), greater<Info>());
    Info f1 = Info(0, -1, 1);
    Info f2 = Info(0, -1, 2);
    for (int i = 0; i < v.size(); i++) {
        if (f1.m == f2.m) {
            if (v[i].l == 1) { f1 = v[i]; }
            if (v[i].l == 2) { f2 = v[i]; }
        }
        else if (f1.m == -1) {if (v[i].l == 1) f1 = v[i];}
        else if (f2.m == -1) {if (v[i].l == 2) f2 = v[i];}
    }

    cout << N - f1.n - f2.n << '\n';

}


Measured memory_bytes: 7032
#include <cstdio>
#include <cctype>
#include <utility>
#include <complex>
#include <iostream>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template<typename T>
#define _HT template<typename H,typename... T>
_T _DEF(T,in,int c){T n{};int m{1};while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int,in,){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c{gcu()};return c==EOF?false:(n=in<T>(c),true);}
_DEF(bool, scan, int &c){c=gcu();gcu();return c!=EOF;}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=(char)c;}}
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p{b};T m=n<0?pcu('-'),-1:1;if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{int e,b{0},s{1};range(int _b,int _e,int _s):e(_e),b(_b),s(_s){}range(int _b,int _e):e(_e),b(_b){}range(int _e):e(_e){}
	struct it{int v,s;it(int _v,int _s):v(_v),s(_s){}operator int()const{return v;}operator int&(){return v;}int operator*()const{return v;}it& operator++(){v+=s;return *this;}};
	it begin(){return{b, s};}it end(){return{e,s};}};

using P = complex<double>;
P read() {
	int x {in()};
	return P(x, in());
}

int main() {
	P p1 {read()}, p2 {read()}, a {p2 - p1}, r {a / abs(a)};
	for (int q {in()}; q; q--) {
		P p {conj((read() - p1) / r) * r + p1};
		printf("%.10lf %.10lf\n", p.real(), p.imag());
	}
}


Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define REP(i, n) for (LL i = 0; i < (int)(n); i++)
int main()
{
    LL n,a=0;
    cin >> n;
    vector<LL>t(n+1);
    REP(i,n+1)cin>>t[i];
    vector<LL>y(n);
    REP(i,n)cin>>y[i];
    REP(i,n){
    if(y[i]>=t[i]+t[i+1]){
        a+=t[i]+t[i+1];
        t[i+1]=0;
    }else if(y[i]>=t[i]){
        a+=t[i];
        y[i]-=t[i];
        t[i]=0;
        a+=y[i];
        t[i+1]-=y[i];
    }else if(y[i]<t[i]){
        a+=y[i];
    }
    }
  cout <<a;
}

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

long long numbers[500005];
long long sum=0;

string S;

int main()
{
    numbers[0]=0;

    cin>>S;

    for (int i=0; i<S.size(); i++)
    {
        if (S[i]=='<')
        {
            numbers[i+1]=numbers[i]+1;
        }
    }

    for (int i=S.size()-1; i>=0; i--)
    {
        if (S[i]=='>')
        {
            if (numbers[i]<=numbers[i+1])
            {
                numbers[i]=numbers[i+1]+1;
            }
        }
    }

    for (int i=0; i<=S.size(); i++)
    {
        sum=sum+numbers[i];
    }

    cout<<sum<<endl;
}

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

int main(){
    int flag=0;
    int n;
    cin>>n;
    while(n>0){
        int r=n%10;
        n/=10;
        if(r==7) flag=1;
    }
    if(flag) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3572
# -*- coding: utf-8 -*-

import numpy as np

def EDPC_B_flog():
    """
    5 3
    10 30 40 50 20
    ans 30
    0 20 30 40 30
    
    3 1
    10 20 10
    ans 20
    
    2 100
    10 10
    ans 0
    
    10 4
    40 10 20 70 80 10 20 70 80 60
    ans 40
    0 30 20 30 40 30 20 30 40 40
    """
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    k = min(n-1, k)
    a = np.array(a)
    dp = np.concatenate([np.abs(a - a[0])[:k+1], np.zeros(n-k-1, dtype="int")])
    for i in range(k+1, n):
        dp[i] = np.min(dp[i-k:i] + np.abs(a[i-k:i] - a[i]))
    print(dp[-1])



def EDPC_C_vacation():
    """
    3
    10 40 70
    20 50 80
    30 60 90
    ans 210
    
    1
    100 10 1
    ans 100
    
    7
    6 7 8
    8 8 3
    2 5 2
    7 8 6
    4 6 8
    2 3 4
    7 5 1
    ans 46
    8, 8, 5, 8, 8, 4, 7 -> 48
    8, 8, 5, 7, 8, 3, 7 -> 46
    """
    n = int(input())
    a = np.array([list(map(int, input().split())) for i in range(n)])  
    arr = a
    dp = [[0, 0, 0] for _ in range(n)]
    dp[0] = arr[0]
    for i in range(1, n):
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + arr[i][0]
        dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + arr[i][1]
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + arr[i][2]
    print (max(dp[-1]))


def EDPC_D_knapsack():
    """
    3 8
    3 30
    4 50
    5 60
    ans 90
    
    5 5
    1 1000000000
    1 1000000000
    1 1000000000
    1 1000000000
    1 1000000000
    ans 5000000000(>int32)
    
    6 15
    6 5
    5 6
    6 4
    6 6
    3 5
    7 2
    ans 17
    """
    N, W = map(int, input().split())
    WV = np.array([tuple(map(int, input().split())) for _ in range(N)], dtype="int64")
    dp = np.zeros(W + 1, dtype="int64")
    for w, v in WV:
        dp[W:w-1:-1] = np.max(np.vstack([dp[W:w-1:-1], dp[W-w::-1] + v]), axis=0)
    print(dp[-1])


def EDPC_E_knapsack():
    """
    3 8
    3 3
    4 5
    5 6
    ans 9
    
    6 15
    6 5
    5 6
    6 4
    6 6
    3 5
    7 2
    ans 17
    
    N<100, W<10*9
    wi<10**9, vi<10**3 
    """
    N, W = map(int, input().split())
    WV = np.array([tuple(map(int, input().split())) for _ in range(N)], dtype="int64")
    Wsum = np.sum(WV[:, 0])
    Vsum = np.sum(WV[:, 1])
    
    dp = np.full(Vsum+1, Wsum, dtype="int64")
    for w, v in WV:
        dp[:Vsum-v+1] = np.min(np.vstack([dp[:Vsum-v+1], dp[v:] - w]), axis=0)
    
    print(dp[dp < W+1].size - 1) # == np.where(dp < W+1)[0][-1]

    
EDPC_C_vacation()


Measured memory_bytes: 41900
N = int(input())
ps = tuple(map(int, input().split()))
qs = tuple(map(int, input().split()))
from itertools import permutations
for i, x in enumerate(permutations(range(1,N+1), N)):
    if x == ps:
        j = i
    if x == qs:
        t = i
print(abs(t-j))



Measured memory_bytes: 39152
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
void decimal(int x){cout<<fixed<<setprecision(x);}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve() {
  int m;
  cin>>m;
  ll n=0;
  REP(i,1,m+1)REP(j,1,m+1)REP(k,1,m+1){
    int p=gcd(i,j);
    n+=gcd(p,k);
  }
  out(n);
}

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


Measured memory_bytes: 3656
#include<cstdio>
#include<iostream>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<bitset>
#define inf 999999999
using namespace std;
int l[100001];
signed main()
{
	int n,maxx=0,sum=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&l[i]),maxx=max(maxx,l[i]),sum+=l[i];
	if(maxx>=sum-maxx)
		printf("No");
	else
		printf("Yes");
	return 0;
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;


int main() {
    int n;
    cin >> n;
    vector<P> a(n);
    rep(i, n) cin >> a[i].first >> a[i].second;

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

    for (P p : a) {
        printf("%lld %lld\n", p.first, p.second);
    }
}


Measured memory_bytes: 4424
import java.util.Map.Entry;
import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		int N = sc.nextInt();
		int K = sc.nextInt();
		int min = Integer.MAX_VALUE;
		int[] h = new int[N];
		for(int i = 0; i < N; i++) h[i] = sc.nextInt();
		Arrays.sort(h);
		for(int i = 0; i < N-K+1; i++){
			min = Math.min(min, h[i+K-1]-h[i]);
		}
		System.out.println(min);
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}


Measured memory_bytes: 23724
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
using namespace std ;

int n ;
string a ;

void input ( ) {
    cin >> a ;
    n = a.size ( ) ;
}

void solve ( ) {
    string lst = "" ;
    lst += a[ 0 ] ;
    int ans = 1 ;
    string cur = "" ;
    for ( int i = 1 ; i < n ; ++ i ) {
        cur += a[ i ] ;
        if ( cur == lst ) { continue ; }
        else {
            lst = cur ;
            cur = "" ;
            ++ ans ;
        }
    }
    cout << ans << "\n" ;
}

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


Measured memory_bytes: 720