akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
 
using namespace std;
long long mod=1e9+7;
long long INF=1e7;
double EPS = 1e-12;
const long long lim = 1e6+100;
typedef long long int lld;
typedef long long ll;

#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define mset(a, v) memset(a, v, sizeof(a))
#define Error(x...) { cout << "(" << #x << ")" << " = ( "; printIt(x); }
template <typename T1> void printIt(T1 t1) { cout << t1 << " )" << endl; }
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) { cout << t1 << " , "; printIt(t2...); }
 
 
#define popcount __builtin_popcountll
 
ll powP(ll x, ll y) {
    ll ans = 1, po = x % mod;
    while(y > 0) {
        if(y & 1) ans = ans * po % mod;
        y >>= 1; po = po * po % mod;
    }
    return ans;
}

ll findGcd(ll a, ll b){
    while(a != 0) { ll temp = b % a; b = a; a = temp; }
    return b;
}

set<ll> S[lim];
ll Array[lim], Prime[lim];



int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);

    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    
    lld T,i,p,j,l,e,r,b,c,k,m,q,a,d,w,x,y,u,v,z,t,curr,prev,sum=0,val,countA=0,indicator=0,pos,h,minA,maxA,type,n,ans=0,left,right;
    string A,B;
    A = "Yes", B="No";
    cin>>n>>m;
    set<ll> S; map<ll,ll> M;
    S.insert(1);
    rep(i,1,n) M[i]=1;
    rep(i,1,m) {
        cin>>x>>y;
        if(S.count(x)==0) {M[x]--, M[y]++;}
        else if(M[x]==1) {M[x]--, M[y]++; S.erase(x); S.insert(y);}
        else {M[x]--, M[y]++; S.insert(y);}
    }

    cout<<S.size()<<endl;

    return 0;
}
    

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

int main() {
    int x, a, b;
    cin >> x >> a >> b;

    if (a >= b) {
        cout << "delicious" << endl;
    } else if (a + x >= b) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
x, y = map(int, input().split())
if x == 1 and y == 1:
    print(300000*2 + 400000)
elif x == 1 and y == 2:
    print(300000+200000)
elif x == 1 and y == 3:
    print(300000+100000)
elif x == 2 and y == 1:
    print(300000 + 200000)
elif x == 2 and y == 2:
    print(200000+200000)
elif x == 2 and y == 3:
    print(200000+100000)
elif x == 3 and y == 1:
    print(100000+300000)
elif x == 3 and y == 2:
    print(100000+200000)
elif x == 3 and y == 3:
    print(100000+100000)
elif x == 1:
    print(300000)
elif x == 2:
    print(200000)
elif x == 3:
    print(100000)
elif y == 1:
    print(300000)
elif y == 2:
    print(200000)
elif y == 3:
    print(100000)
else:
    print(0)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
using namespace std;
using ll=long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    if(x==0){
        cout<<1<<endl;
        return 0;
    }
    else{
        cout<<0<<endl;
        return 0;
    }
}

Measured memory_bytes: 3592
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int check(vector<int> &v, int N, int K){
  int res = 0;
  REP(i, N - K + 1){
    int tmp = v[i];
    FOR(j, 1, K) tmp *= v[i + j];
    res = max(res, tmp);
  }
  return res;
}

int main() {
  int N, K;
  while(cin >>N >>K && N){
    vector<int> v(N);
    REP(i, N) cin >>v[i];
    int bef = check(v, N, K), ans = -1;
    REP(i, N){
      FOR(j, i + 1, N){
        swap(v[i], v[j]);
        int tmp = check(v, N, K);
        if(tmp - bef >= 0) ans = max(ans, tmp - bef);
        swap(v[i], v[j]);
      }
    }
    if(ans == -1) cout <<"NO GAME" <<endl;
    else cout <<ans <<endl;
  }

  return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
const int N=100010;
int n,m;
int to[N<<1],edge_tot;
vector<int> point[N];
void add_edge(int f,int t){
	to[edge_tot]=t;
	point[f].push_back(edge_tot++);
	return;
}
int color[N],tot[3];
bool vis[N];
bool fill(int k,int c){
	vis[k]=1,color[k]=c,tot[c]++;
	int x;
	for(int i=0;i<point[k].size();i++){
		x=to[point[k][i]];
		if(!vis[x]){
			if(!fill(x,!c)) return 0;
		}else if(color[x]==color[k]) return 0;
	}
	return 1;
}
int main(){
	int t1,t2;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&t1,&t2);
		add_edge(t1,t2);add_edge(t2,t1);
	}
	if(fill(1,1)) cout<<1LL*tot[0]*tot[1]-m;
	else cout<<1LL*n*(n-1)/2-m;
	return 0;
}

Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define llp 1000000007
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;

vector<int>adj[2][200005];
bool bvis[200005];
bool vis1[200005];
bool vis2[200005];
map<pair<int, int>, int>M;
   vi a(2000005),b(2000005);
int no=0;
vi buff;
void dfs1(int x){
    vis1[x]=true;
    // road.insert(x);
    a[x]=no;
    for(auto g:adj[0][x]){
        if(vis1[g]==false){
            dfs1(g);
        }
    }
}
void dfs2(int x){
    vis2[x]=true;
    // rail.insert(x);
    b[x]=no;
    for(auto g:adj[1][x]){
        if(vis2[g]==false){
            dfs2(g);
        }
    }
}


int32_t main(){
	ios::sync_with_stdio(false);
    int n, k, l;
    memset(bvis,false,sizeof(bvis));
    memset(vis1,false,sizeof(vis1));
    memset(vis2,false,sizeof(vis2));
    cin>>n>>k>>l;
    REP(i,0,k){
        int A, B;
        cin>>A>>B;
        adj[0][A].PB(B);
        adj[0][B].PB(A);
    }
    REP(i,0,l){
        int A, B;
        cin>>A>>B;
        adj[1][A].PB(B);
        adj[1][B].PB(A);
    }
    vi ans(n+1);
 
    
    for(int i=1;i<=n;i++){

        if(vis1[i]==false){
            no++;
            dfs1(i);
        }
    }
    for(int i=1;i<=n;i++){
        if(vis2[i]==false){
            no++;
            dfs2(i);
        }
    }

    for(int i=1;i<=n;i++){
        M[{a[i],b[i]}]++;
    }    

REP(i,1,n+1){
    cout<<M[{a[i],b[i]}]<<" ";
}
cout<<"\n"; 



return 0;
}

Measured memory_bytes: 60800
n, m = map(int, input().split())
klst = []
for i in range(m):
  klst.append(list(map(lambda x: int(x) - 1, input().split()))[1:])
plst = list(map(int, input().split()))
res = 0
for ibit in range(2 ** n):
  TF = True
  for j in range(m):
    cnt = 0
    for swnum in klst[j]:
      if ((ibit >> swnum) & 1):
        cnt += 1
    if cnt % 2 != plst[j]:
      TF = False
  if TF:
    res += 1
print(res)

Measured memory_bytes: 9012
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int x=0; char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return x;
}
int main(void)
{
	long n = read() + 1;
    long ans = n - 1;
	for (int i = 2; i < n; ++i)
	{
        long u = read(), v = read();
		if (u > v) swap(u, v);
        ans += i * (n - i) - u * (n - v);
	}
	printf("%lld\n", ans);
	
	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order  // k th index
#define ook order_of_key   // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;

ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */  // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */  // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */  // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */  // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */
const int N = 2e5 + 9;
ll ara[N];
ll dp[N][3];
int visited[N][3];
int n;
int cas;
int st = 1;
int jumpc = 0;
ll recur(int pos, int skipped) {
    if (pos > n)
        return 0;
    if (st == 1 && skipped == 0 && pos == n)
        return 0;
    ll& ans = dp[pos][skipped];
    int& visi = visited[pos][skipped];
    if (visi == cas)
        return ans;
    visi = cas;
    ans = -1e17;
    ans = max(ans, ara[pos] + recur(pos + 2, skipped));
    if (skipped < jumpc) {
        ans = max(ans, recur(pos + 1, skipped + 1));
    }
    return ans;
}
int main() {
    scanf("%d", &n);
    ll sum1 = 0, sum2 = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &ara[i]);
    }

    cas++;
    if(n%2)jumpc = 2;
    else jumpc = 1;
    ll ans = recur(1, 0);
    cas++;
    st++;
    jumpc--;
    ans = max(ans, recur(2, 0));
    cout << ans << "\n";
}


Measured memory_bytes: 16940
a, b, c, d, e, f = map(int, input().split())
water = set()
sugar = set()

i = 0
while True:
    j = 0
    if 100*a*i + 100*b*j > f:
        break
    while True:
        if 100*a*i + 100*b*j <= f:
            water.add(100*a*i + 100*b*j)
        else:
            break
        j += 1
    i += 1

i = 0
while True:
    j = 0
    if c*i + d*j > f:
        break
    while True:
        if c*i + d*j <= f:
            sugar.add(c*i + d*j)
        else:
            break
        j += 1
    i += 1

# print(water, sugar)
nodo = 0.0
ans = [0, 0]
for w in water:
    for s in sugar:
        if w != 0:
            if e/100 >= s/w and f >= s+w:
                if nodo <= s/w:
                    nodo = s/w
                    ans = s+w, s

print(*ans)


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int K;
  cin >> K;
  int n = 50;
  vint a(n);
  rep(i, n) a[i] = i + K/n;
  rep(i, K%n) {
    int mni = 0;
    rep(j, n) if(a[mni] > a[j]) mni = j;
    a[mni] += n;
    rep(j, n) if(j != mni) --a[j];
  }
  cout<<n<<endl;
  rep(i, n) cout << a[i] << " \n"[i==n-1];

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#define SIZE 1000000007
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;

int main(){
    char a;
    cin>>a;
    if(a=='A')cout<<'T'<<endl;
    else if(a=='T')cout<<'A'<<endl;
    else if(a=='G')cout<<'C'<<endl;
    else if(a=='C')cout<<'G'<<endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

K, T = list(map(int, input().split()))
a_list = list(map(int, input().split()))
a_list = sorted(a_list)
k = K

if T == 1:
    count = K - 1
elif T == 2:
    diff = a_list[-1] - a_list[-2]
    if diff <= 1:
        count = 0
    else:
        count = diff - 1
else:
    # 一番多いケーキと2番目に多いケーキの個数の差
    diff = a_list[-1] - a_list[-2]
    if diff <= 1:
        count = 0
    else:
        x = sum(a_list[:-2])
        if (a_list[-1] - 1) <= (a_list[-2] + x):
            count = 0
        else:
            count = a_list[-1] - (a_list[-2] + x) - 1
ans = count
print(ans)


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
    int n, ans = 1;
    string s;
    cin >> n >> s;
    for(int i = 0; i < n-1; i++){
        if(s[i] != s[i+1]) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin>>n>>k;
    int d=(n/k);
    n=n-(d*k);
    cout<<min(n,abs(n-k))<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
int a[maxn],ans;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=k;i++)
		ans+=a[i];
	cout<<ans<<endl;
	return 0;
}




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

int main() {
  int a, b;
  cin >> a >> b;
  if (a >= 13) cout << b << endl;
  else if (a <= 5) cout << 0 << endl;
  else cout << b/2 << endl;
  return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    map<int, vector<int>> mp;
    for(int i=0; i<m; i++)
    {
        int a, b;
        cin >> a >> b;
        mp[a].push_back(b);
        mp[b].push_back(a);
    }

    for(auto num : mp[1])
    {
        for(auto num2 : mp[num])
        {
            if(num2 == n)
            {
                cout << "POSSIBLE\n";
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE\n";

    return 0;
}


Measured memory_bytes: 22896
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 105;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int n, fa[MAXN], fb[MAXN];
vector <int> a[MAXN], b[MAXN];
void dfsa(int pos, int f) {
	fa[pos] = f;
	for (auto x : a[pos])
		if (x != f) dfsa(x, pos);
}
void dfsb(int pos, int f) {
	fb[pos] = f;
	for (auto x : b[pos])
		if (x != f) dfsb(x, pos);
}
bool vis[MAXN], unlock[MAXN], used[MAXN];
void dfs(int pos) {
	vis[pos] = true;
	for (auto x : a[pos])
		if (fa[x] == pos && fb[x] == pos) dfs(x);
}
bool root(int pos) {
	memset(unlock, false, sizeof(unlock)), unlock[pos] = true;
	memset(used, false, sizeof(used));
	for (int t = 1; t <= n; t++) {
		int pos = 0;
		for (int i = 1; i <= n; i++)
			if (!used[i] && unlock[i]) {
				int d = 0;
				for (auto x : a[i])
					if (!used[x]) d++;
				if (d <= 1) pos = i;
			}
		if (pos == 0) return false;
		used[pos] = true;
		for (auto x : b[pos])
			unlock[x] = true;
	}
	return true;
}
int work(int pos) {
	memset(vis, false, sizeof(vis)), dfs(pos);
	memcpy(unlock, vis, sizeof(vis));
	for (int i = 1; i <= n; i++)
		if (vis[i]) {
			for (auto x : b[i])
				unlock[x] = true;
		}
	memset(used, false, sizeof(used));
	int cnt = 0;
	for (int i = 1; i <= n; i++)
		if (!vis[i]) cnt++;
	for (int t = 1; t <= cnt; t++) {
		int pos = 0;
		for (int i = 1; i <= n; i++)
			if (!vis[i] && !used[i] && unlock[i]) {
				int d = 0;
				for (auto x : a[i])
					if (!used[x]) d++;
				if (d <= 1) pos = i;
			}
		if (pos == 0) return n + 1;
		used[pos] = true;
		for (auto x : b[pos])
			unlock[x] = true;
	}
	return cnt;
}
void solve() {
	int ans = n + 1;
	for (int i = 1; i <= n; i++) {
		dfsa(i, 0);
		dfsb(i, 0);
		chkmin(ans, work(i));
		if (root(i)) chkmin(ans, n);
	}
	if (ans == n + 1) puts("-1");
	else cout << ans << endl;
}
int main() {
	int T; read(T);
	while (T--) {
		read(n);
		for (int i = 1; i <= n; i++) {
			a[i].clear();
			b[i].clear();
		}
		for (int i = 1; i <= n - 1; i++) {
			int x, y; read(x), read(y);
			a[x].push_back(y);
			a[y].push_back(x);
		}
		for (int i = 1; i <= n - 1; i++) {
			int x, y; read(x), read(y);
			b[x].push_back(y);
			b[y].push_back(x);
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int a[10][10];

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, d;
    cin >> n >> d;
    rep(i, 0, n){
        rep(j, 0, d){
            cin >> a[i][j];
        }
    }
    int ans = 0;
    rep(i, 0, n){
        rep(j, i + 1, n){
            int tmp = 0;
            rep(k, 0, d){
                tmp += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
            }
            for(int k = 1; k * k <= tmp; k++){
                if(k * k == tmp){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<stack>
#include<unordered_map>
#include<bitset>
#include<limits>
#include<complex>
#include<array>
#include<numeric>
#include<functional>

using namespace std;
#define ll long long
#define ull unsigned long long
#define rrep(i,m,n) for(ll (i)=(ll)(m);(i)>=(ll)(n);(i)--)
#define rep(i,m,n) for(ll (i)=(ll)(m);i<(ll)(n);i++)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 61;
typedef vector<ll> Array;

ll popcount(ll x) {
	x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555);
	x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333);
	x = (x & 0x0F0F0F0F0F0F0F0F) + (x >> 4 & 0x0F0F0F0F0F0F0F0F);
	x = (x & 0x00FF00FF00FF00FF) + (x >> 8 & 0x00FF00FF00FF00FF);
	x = (x & 0x0000FFFF0000FFFF) + (x >> 16 & 0x0000FFFF0000FFFF);
	x = (x & 0x00000000FFFFFFFF) + (x >> 32 & 0x00000000FFFFFFFF);

	return x;
}

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

	ll n, a, b;
	cin >> n >> a >> b;
	if (popcount(a) % 2 == popcount(b) % 2) {
		cout << "NO" << "\n";
		return 0;
	}
	Array ans;
	ans.push_back(a);
	auto solve = [&](auto solve, ll a, ll b, ll used)->void {
		REP(i, n) {
			if (used & (1LL << i))continue;
			if ((a ^ b) & (1LL << i)) {
				used += 1LL << i;
				ll t = -1;
				REP(j, n) {
					if (used & (1LL << j)) continue;
					t = 1LL << j;
					break;
				}
				if (t != -1) {
					solve(solve, a, a ^ t, used);
					ll d = a ^ t ^ (1LL << i);
					ans.push_back(d);
					solve(solve, d, b, used);
				}
				else ans.push_back(b);
				break;
			}
		}
	};
	solve(solve, a, b, 0);
	cout << "YES" << "\n";
	REP(i, ans.size())cout << ans[i] << " ";
	cout << "\n";

	return 0;
}


Measured memory_bytes: 2164
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    int c[n][1];
    for(int i=0;i<n;i++){
        c[i][0]=0;
    }
    int a[k][n];
    for(int i=0;i<k;i++){
        int d;
        cin >> d;
        for(int j=0;j<d;j++){
            cin >> a[i][j];
            for(int k=0;k<n;k++){
                if(k+1==a[i][j]) c[k][0]++;
            }
        }
    }
    int counter=0;
    for(int i=0;i<n;i++){
        if(c[i][0]==0) counter++;
    }
    cout << counter << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    int N;
    string S;
    cin >> N >> S;
    int ans=0;
    for(int i=0; i < N-2; i++){
        if(S.substr(i,3) == "ABC") ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//Vivek
#pragma optimize("", off)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:36777216")
#include <bits/stdc++.h>

#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define all(v) v.begin(),v.end()
#define pb push_back
#define sz(i) int(i.size())
#define setto(n) cout << fixed << setprecision(n)
#define fi first
#define se second
#define inf LONG_MAX
const int mod = 1000000007;

using namespace std;

#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}
template<class T> void smax(T& a, T val) {if (a < val) a = val;}
template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}

const int N = 2*1e5 + 10;

int o, e, n;
int main(){_

	cin>>n;

	if(n % 2 == 0){
		o = n/2;
		e = n/2;
	}

	else{
		o = n/2 + 1;
		e = n/2;
	}

	cout<<o*e;

	return 0;
}

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

int main(){
	int n;
	cin>>n;
	long long a[n],b[n];
	long long sum=0;
	cin>>a[0];
	b[0]=a[0];
	sum+=a[0];
	for(int i=1;i<n;i++){
	    cin>>a[i];
	    b[i]=b[i-1]+a[i];
	    sum+=a[i];
	}
	long long ans=1e18;
	for(int i=0;i<n-1;i++){
	    long long res=abs(b[i]-(sum-b[i]));
	    ans=min(ans,res);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=500500,oo=1000000001;
int i,j,k,n,m,ch,x;
int d[N],pre[N],suf[N];
void R(int &x) {
	x=0;ch=getchar();
	while (ch<'0' || '9'<ch) ch=getchar();
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
}
int main() {
	R(n);R(pre[1]);
	for (i=1;i<=n;i++) R(d[i]);
	for (i=1;i<n;i++) pre[i+1]=min(pre[i],abs(pre[i]-d[i]));
	suf[n]=1;
	for (i=n;i>1;i--) {
		if (d[i]/2>=suf[i]) suf[i-1]=suf[i];
		else suf[i-1]=d[i]+suf[i];
		if (suf[i-1]>oo) suf[i-1]=oo;
	}
	R(m);
	for (i=1;i<=m;i++) {
		R(x);
		if (pre[x]>=suf[x]) puts("YES");
		else puts("NO");
	}
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
 int main() {
 int A,B,C,D;
   cin >> A >> B >> C >> D;
   if((A+B)>(C+D)){
     cout << "Left" << endl;
   }
   else if((A+B)<(C+D)){
     cout << "Right" << endl;
   }
   else{
    cout << "Balanced" << endl;
   } 
 
 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define REPE(i, a, b) for (int i = (a); i <= int(b); ++i)
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(), x.end()
#define PB push_back
#define EB emplace_back
using LL = long long;
using PII = pair<int, int>;
#define F first
#define S second

const int maxn = 1e5 + 10;
int n;
vector<int> g[maxn];

int dfs(int x) {
  int ret = 0;
  vector<int> a;
  for (int y : g[x])
    a.PB(dfs(y));
  sort(ALL(a));
  for (int y : a)
    ret = max(ret + 1, y + 1);
  return ret;
}

int main() {
  scanf("%d", &n);
  REPE(i, 2, n) {
    int p;
    scanf("%d", &p);
    g[p].PB(i);
  }
  printf("%d\n", dfs(1));
  return 0;
}



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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';
ll const mod = 998244353;

struct LazySegmentTree {
private:
    int n;
    vector<ll> node,lazy_b,lazy_c;
    vector<bool> upd;
public:
    LazySegmentTree(vector<ll> v) {
        int sz = v.size();
        n = 1;
        while (n < sz) n *= 2;
        node.resize(2*n-1);
        lazy_b.resize(2*n-1,1);
        lazy_c.resize(2*n-1,0);
        upd.resize(2*n-1,false);
        for (int i = 0;i < sz;++i) node[i+n-1] = v[i];
        for (int i = n-2;i >= 0;--i) node[i] = (node[i*2+1]+node[i*2+2])%mod;
    }

    void eval(int k,int l,int r) {
        if (upd[k]) {
            (node[k] *= lazy_b[k]) %= mod;
            (node[k] += lazy_c[k]*(r-l)%mod) %= mod;
            if (r-l > 1) {
                (lazy_b[2*k+1] *= lazy_b[k]) %= mod;
                (lazy_b[2*k+2] *= lazy_b[k]) %= mod;
                (lazy_c[2*k+1] *= lazy_b[k]) %= mod;
                (lazy_c[2*k+2] *= lazy_b[k]) %= mod;
                (lazy_c[2*k+1] += lazy_c[k]) %= mod;
                (lazy_c[2*k+2] += lazy_c[k]) %= mod;
                upd[2*k+1] = upd[2*k+2] = true;
            }
            lazy_b[k] = 1;
            lazy_c[k] = 0;
            upd[k] = false;
        }
    }

    void update(int a,int b,ll x,ll y,int k = 0,int l = 0,int r = -1) {
        if (r < 0) r = n;
        eval(k,l,r);
        if (b <= l || r <= a) return;
        if (a <= l && r <= b) {
            lazy_b[k] = x;
            lazy_c[k] = y;
            upd[k] = true;
            eval(k,l,r);
        } else {
            update(a,b,x,y,2*k+1,l,(l+r)/2);
            update(a,b,x,y,2*k+2,(l+r)/2,r);
            node[k] = (node[2*k+1]+node[2*k+2])%mod;
        }
    }

    ll getsum(int a,int b,int k = 0,int l = 0,int r = -1) {
        if (r < 0) r = n;
        if (b <= l || r <= a) return 0;
        eval(k,l,r);
        if (a <= l && r <= b) return node[k];
        ll vl = getsum(a,b,k*2+1,l,(l+r)/2);
        ll vr = getsum(a,b,2*k+2,(l+r)/2,r);
        return (vl+vr)%mod;
    }
};

int main() {
    int n,q;
    cin >> n >> q;
    vector<ll> a(n);
    // for (int i = 0;i < n;++i) cin >> a[i];
    for (int i = 0;i < n;++i) scanf("%d",&a[i]);
    LazySegmentTree seg(a);
    for (int i = 0;i < q;++i) {
        int t,l,r;
        // cin >> t >> l >> r;
        scanf("%d%d%d",&t,&l,&r);
        if (t) cout << seg.getsum(l,r) << newl;
        else {
            int b,c;
            // cin >> b >> c;
            scanf("%d%d",&b,&c);
            seg.update(l,r,b,c);
        }
    }
}

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

#define V vector
typedef long long ll;
typedef unsigned long long ull;

typedef V<int> vi;
typedef V<ll> vll;
typedef V<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define f(i,a) for(int i = 0 ; i < a ; i++)
#define fll(i,a) for(ll i = 0 ; i < a ;i++)
#define forab(i,a,b) for(int i = a ; i < b ; i++)
#define prec(x) cout<<fixed<<setprecision(x)
#define ff first
#define ss second

#define pb push_back
#define mp make_pair
#define numberofdigits(x) floor(log10(x)) + 1
#define all(x) (x).begin() ,(x).end()

const ll mod = 1e9 + 7;

ll binpow(ll a, long long b) {
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a);
		a = (a * a);
		b >>= 1;
	}
	return res;
}
const int MAXN = 1e6 + 5;
ll d[MAXN];
void solve() {

	int n;
	cin >> n;

	ll  ans = 0;
	memset(d , 0 , sizeof(d));

	for (int i = 1 ; i <= n ; i++) {
		for (int j = 1  ; j * i <= n ; j++)
			d[i * j]++;
	}

	for (int j = 1 ; j < n ; j++) {
		int x = n - j;

		if (x != 0) {

			ans += d[x];
		}
	}

	cout << ans << "\n";
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);


	int t = 1;
	//cin >> t;

	while (t--)
		solve();
	return 0;
}





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

#define ub        upper_bound            // first element >  val(itr)
#define lb        lower_bound            // first element >= val(itr)

#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end()) 
#define mem(a,b) memset( a, b, sizeof(a) )

#define bitcount(a) __builtin_popcount(a)   // count set bits
#define lzcount(x) __builtin_clz(x)        // count leading zeros in binary representation of number
#define tzcount(x) __builtin_ctz(x)        // count trailing zeros in binary representation of number

#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

typedef long long int ll;
const ll MOD = 1e9+7;

template<typename T> T gcd(T a,T b){ if(b>a) return gcd(b,a);return b==0?a:gcd(b,a%b); }
template<typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template<typename T> T fast_power(T x,T y,ll m=MOD){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
/*
inline ll mod(ll x,ll n) {if (x < n) return x; if (x >= n) return x - n;}
string IntToString(ll a){ ostringstream temp; temp << a; return temp.str();}
ll findMMI_fermat(ll n,ll M) {ll ans= fast_power(n,M-2,M);return ans;}//i.e In (a/b)%M..it calculates MMI of b wrt M,only if M is prime
ll add(ll a,ll b,ll M)  { return mod(( mod(a,M ) + mod(b,M )),M);     }
ll sub(ll a, ll b,ll M) { return mod((mod(a,M ) + M - mod(b,M )),M);   }
ll mult(ll a,ll b,ll M) { return  mod(( mod(a,M)*mod(b,M) ),M) ; }
bool isprime(ll a){ if(a==2) {return 1;}if(!(a&1) ) {return 0;}for(ll i=3;i*i<=a;i+=2){if(a%i==0) {return 0;} } return 1;} 

  
               /* -------------------------------Main Code------------------------------- */		


int main(){
	FAST
	int n;cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	stack<int> st;
	int mx = 0;
	for(int i=0;i<n;i++){
		if(st.empty()) st.push(a[i]);
		else{
			if(st.top()>=a[i]) {
				st.push(a[i]);
				
			}
			else if(st.top()<a[i]){
				if(st.size()>mx) mx = st.size();
				while(!st.empty()) st.pop();
				st.push(a[i]);
				
			} 
		}
		if(st.size()>mx) mx = st.size();
	}
	if(st.size()>mx) mx = st.size();
	cout<<mx-1<<endl;
    return 0;
}
	

 	




Measured memory_bytes: 1024
//minamoto
#include<bits/stdc++.h>
#define R register
#define ll long long
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
int read(char *s){
    R int len=0;R char ch;while(((ch=getc())>'z'||ch<'a'));
    for(s[++len]=ch;(ch=getc())>='a'&&ch<='z';s[++len]=ch);
    return s[len+1]='\0',len;
}
const int N=1e5+5,P=1e9+7;
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
char s[N];int a[N],cnt[31],flag,n,res,tmp;
int main(){
//	freopen("testdata.in","r",stdin);
	n=read(),read(s);
	fp(i,0,25)cnt[i]=1;
	for(R int i=1;i<=n;++i){
		tmp=1;
		fp(j,0,25)if(j+'a'!=s[i])tmp=mul(tmp,cnt[j]);
		res=add(res,tmp),++cnt[s[i]-'a'];
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define forsn(i,x,y) for(long long i = (x) ; i <= (y) ; ++i)
typedef long long ll;
typedef long double ld;

ll lpow(ll a, ll b) {
  if(b == 0) return 1;
  return (a * lpow(a,(b-1)));
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  if(n == 1) {
    cout << s << endl;
    return 0;
  }
  ll total = 0;
  for(int i = 0 ;i < lpow(2,n-1); i++) {
    //cout << "i:" << i << endl;
    vector<int> b(n-1,0);
    //cout << "  b: ";
    forn(j,n-1) {
      b[j] = (i >> j) & 1;
      //cout << b[j] << " " ;
    }
    //cout << endl;

    int donetill = -1;
    forn(k,n-1) {
      //cout << "    k: " << k << "b[k]: " << b[k] << endl;
      if(b[k] == 1) {
        int m = 0;
        for(int l = k;l > donetill; l--) {
          //cout << "    " << s[l] << " " << lpow(10,m) << endl;
          total += (int)(s[l]-'0') * lpow(10,m);
          m++;
        }
        donetill = k;
      }
    }
    //cout << "    donetill: " << donetill << endl;
    int m = 0;
    for(int l = n-1;l > donetill; l--) {
      total += (int)(s[l]-'0') * lpow(10,m);
      //cout << "    " << s[l] << " " << lpow(10,m) << endl;
      m++;
    }
  }
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 256
S = input()
T = input()

ans = []

for i in range(len(S) - len(T) +1):
    count = 0
    for j, k in zip(T,S[i:i+len(T)]):
        if j == k:
            count += 1
    ans.append(count)
    
print(len(T) - max(ans))

Measured memory_bytes: 9080
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define endl '\n'
#define L 51
#define INF 1e5
using namespace std;
int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1};
typedef pair<ll, ll> P;
int H, W;
char maze[L][L];
int d[L][L];

int bfs() {
    queue<P> q;
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            d[y][x] = INF;
        }
    }

    q.push(P(0, 0));
    d[0][0] = 0;

    while (!q.empty()) {
        P now = q.front();
        q.pop();

        if (now.first == H - 1 && now.second == W - 1) {
            break;
        }

        for (int i = 0; i < 4; i++) {
            int ny = now.first + dy[i], nx = now.second + dx[i];

            if (0 <= ny && ny < H && 0 <= nx && nx < W && maze[ny][nx] == '.' &&
                d[ny][nx] == INF) {
                q.push(P(ny, nx));
                d[ny][nx] = d[now.first][now.second] + 1;
            }
        }
    }
    return d[H - 1][W - 1];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W;
    int dot = 0;
    rep(i, H) {
        rep(j, W) {
            cin >> maze[i][j];
            if (maze[i][j] == '.') {
                dot++;
            }
        }
    }
    int len = bfs();
    if (len == INF) {
        cout << -1 << endl;
        return 0;
    } else {
        cout << dot - len - 1 << endl;
    }
    return 0;
}

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

int main(){
  int n, x, count;
  while (true){
    count = 0;
    cin >> n >> x;
    if (n == 0 && x == 0){
      break;
    }
    
    int num[n];
    for (int i = 0; i < n; i++){
      num[i] = i + 1;
    }
    
    for (int a = 0; a < n - 2; a++){
      for (int b = a + 1; b < n - 1; b++){
        for (int c = b + 1; c < n; c++){
          if(num[a] + num[b] + num[c] == x){
            count += 1;
          }
        }
      }
    }

    cout << count << endl;
  }
}


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

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int l = sc.nextInt();
		String[] s = new String[n];
		for (int i = 0; i < n; i++) {
			s[i] = sc.next();
		}
		Arrays.sort(s);
		for (int i = 0; i < n; i++) {
			System.out.print(s[i]);
		}
		System.out.println();
	}

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


Measured memory_bytes: 9812
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 100005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) {
		out(x / 10);
	}
	putchar('0' + x % 10);
}
int N,K,h[MAXN];
int dp[MAXN];
void Solve() {
	read(N);read(K);
	for(int i = 1 ; i <= N ; ++i) {
		read(h[i]);
	}
	dp[1] = 0;
	for(int i = 2 ; i <= N ; ++i) {
		dp[i] = dp[i - 1] + abs(h[i - 1] - h[i]);
		for(int j = 2 ; j <= K ; ++j) {
			if(i - j < 1) break;
			dp[i] = min(dp[i],dp[i - j] + abs(h[i - j] - h[i]));
		}
	}
	out(dp[N]);enter;
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
}


Measured memory_bytes: 1024
import itertools
def nasu(s, l):
  n = N - 2
  T = []
  for i in range(s, l + 1):
    T.append(i)
  L = list(itertools.combinations_with_replacement(T, n))
  ans = 0
  for i in L:
    P = [s] + list(i) + [l]
    ans = max(ans, honya(P))
  return ans

def honya(L):
  ans = 0
  for a, b, c, d in abcd:
    a -= 1
    b -= 1
    if L[b] - L[a] == c:
      ans += d
  return ans

N, M, Q = list(map(int, input().split()))
abcd = [list(map(int, input().split())) for _ in range(Q)]

ans = 0
for i in range(1, M + 1):
  for j in range(i, M + 1):
    ans = max(ans, nasu(i, j))

print(ans)

Measured memory_bytes: 11832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int D; //365
    cin >> D;

    int c[26];
    rep(i, 0, 26) {
        cin >> c[i];
    }

    int s[D][26];
    int t[D] = {};
    //各日について、s[i][j]が最大になるコンテストタイプで初期化
    rep(i, 0, D) {
        int mx = -1;
        rep(j, 0, 26) {
            cin >> s[i][j];
            if (mx < s[i][j]) {
                mx = s[i][j];
                t[i] = j;
            }
        }
    }

    //日程を乱数で初期化
    srand(time(NULL));
    /*rep(i, 0, D) {
        t[i] = rand() % 26;
    }*/

    ll mx_score = -1e18;
    int cnt = 200000;
    while (cnt--) {
        //d日目のコンテストをqに置き換えてスコアを計算し、改善しなければ元に戻す
        int d = rand() % 365;
        int q = rand() % 26;
        int old = t[d];
        t[d] = q;

        //スコアを計算する
        ll score[D] = {};
        vector<int> last_day(26, -1);
        rep(i, 0, D) {
            if (i != 0) score[i] = score[i - 1];
            //増加分
            score[i] += s[i][t[i]];

            last_day[t[i]] = i;

            //減少分
            ll decrease = 0;
            rep(j, 0, 26) {
                decrease += c[j] * (i - last_day[j]);
            }
            score[i] -= decrease;
        }
        //cout << "score[D - 1]: " << score[D - 1] << endl;
        if (mx_score > score[D - 1]) {
            t[d] = old;
        } else {
            mx_score = score[D - 1];
        }
    }

    rep(i, 0, D) cout << t[i] + 1 << endl;
    return 0;
}


Measured memory_bytes: 3680
using System;

namespace B___Card_Game_for_Two
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ');
            var a = new int[n];
            var alice = 0;
            var bob = 0;
            for(var i=0; i<n; i++)
            {
                a[i] = int.Parse(input[i]);
            }
            Array.Sort(a);
            Array.Reverse(a);
            for (var i = 0; i < n; i++)
            {
                if (i % 2 == 0)
                {
                    alice += a[i];
                }
                else
                {
                    bob += a[i];
                }
            }
            Console.WriteLine(alice - bob);
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
#define db double
#define zero(x) (fabs(x)<eps)
#define sgn(x) (zero(x)?0:((x)>0?1:-1))
const db eps=1e-10;
struct point{
    db x,y;
    point(){}
    point(db x,db y):x(x),y(y){}
    point operator + (point B){ return point(x+B.x,y+B.y); }
    point operator - (point B){ return point(x-B.x,y-B.y); }
    point operator * (db k){ return point(k*x,k*y); }
    db operator * (point B){ return x*B.y-y*B.x; }
    db operator ^ (point B){ return x*B.x+y*B.y; }
    bool operator < (point B){ return (y>0)!=(B.y>0)?y>0:((*this)*B)>0; }
};
db dis2(point A,point B){ return (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y); }
struct line{
    point A,B;
    line(){}
    line(point A,point B):A(A),B(B){}
};
point projection(line l,point P){
    point dir=l.B-l.A; P=P-l.A;
    return dir*((P^dir)/dis2(l.A,l.B))+l.A;
}
point reflection(line l,point P){
    return projection(l,P)*2-P;
}
int direction(point P0,point P1,point P2){
    db det=(P2-P0)*(P1-P0); return sgn(det);
}
bool parallel(line l1,line l2){
    return zero((l1.B-l1.A)*(l2.B-l2.A));
}
bool orthogonal(line l1,line l2){
    return zero((l1.B-l1.A)^(l2.B-l2.A));
}
bool intersect(line l1,line l2){//
    int d1=direction(l1.A,l1.B,l2.A),d2=direction(l1.A,l1.B,l2.B);
    int d3=direction(l2.A,l2.B,l1.A),d4=direction(l2.A,l2.B,l1.B);
    if (d1*d2>0||d3*d4>0) return false;
    if (l1.A.x>l1.B.x) swap(l1.A.x,l1.B.x);
    if (l1.A.y>l1.B.y) swap(l1.A.y,l1.B.y);
    if (l2.A.x>l2.B.x) swap(l2.A.x,l2.B.x);
    if (l2.A.y>l2.B.y) swap(l2.A.y,l2.B.y);
    return !(l1.B.x<l2.A.x||l2.B.x<l1.A.x||l1.B.y<l2.A.y||l2.B.y<l1.A.y);
}
point cross_point(line l1,line l2){
    db s1=fabs((l2.B-l2.A)*(l1.A-l2.A)),s2=fabs((l2.B-l2.A)*(l1.B-l2.A));
    return l1.A+(l1.B-l1.A)*(s1/(s1+s2));
}
db dis(line l,point P){//
    point proj=projection(l,P);
    if (min(l.A.x,l.B.x)-eps<proj.x&&proj.x<max(l.A.x,l.B.x)+eps)
        if (min(l.A.y,l.B.y)-eps<proj.y&&proj.y<max(l.A.y,l.B.y)+eps)
            return sqrt(dis2(P,proj));
    return sqrt(min(dis2(P,l.A),dis2(P,l.B)));
}
db distance(line l1,line l2){
    if (intersect(l1,l2)) return 0;
    return min(min(dis(l1,l2.A),dis(l1,l2.B)),min(dis(l2,l1.A),dis(l2,l1.B)));
}
db area(point *a,int n){
    db ans=0; for (int i=2;i<=n-1;++i) ans+=(a[i]-a[1])*(a[i+1]-a[1])/2;
    return ans;
}
bool check(point *a,int n){
    int t=sgn((a[2]-a[1])*(a[n]-a[1])),cnt1=0,cnt2=0;
    if (t>0)++cnt1;
    else if (t<0) ++cnt2;
    for (int i=2;i<=n;++i){
        t=sgn((a[i%n+1]-a[i])*(a[i-1]-a[i]));
        if (t>0) ++cnt1;
        else if (t<0) ++cnt2;
        if (cnt1&&cnt2) return false;
    }
    return true;
}
const int N=1e6+6;
point A[N];
int main(){
    int n; scanf("%d",&n);
    for (int i=1;i<=n;++i) scanf("%lf%lf",&A[i].x,&A[i].y);
    printf("%d\n",check(A,n));
}



Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
int main()
{
    int N;
    string s;
    cin >> N >> s;
    int ans=0;
    REP(i,10){
        REP(j,10){
            REP(k,10){
                int idx = 0;
                REP(n,N){
                    if(0 == idx && i == (s[n]-'0')){
                        idx++;
                        continue;
                    }
                    if(1 == idx && j == (s[n]-'0')){
                        idx++;
                        continue;
                    }
                    if(2 == idx && k == (s[n]-'0')){
                        idx++;
                        continue;
                    }
                }
                if(3 == idx){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3680