akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file 
//#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define pb push_back
#define ff first
#define ss second
#define ii insert
#define ld long double
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define ppb pop_back
#define nuenxfiu ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define TT int testcases;cin>>testcases;while(testcases--)
#define mk make_pair
#define MAX ((int)2e9+17)
#define mod ((int)1e9+7)
#define MOD 1000003
//int fact[1000007]={0};
//upper_bound is maximum index of an array element not greater than the given one
//lower bound is minimum index of an array element not less than the given one

#define N (int)1e6+10
int fpow(int n, int k, int p = mod) {int r = 1; while(k > 0) {if (k & 1) r = r * n%p; n = n * n%p; k = k >> 1;} return r;}
int expo(int x,int y){ int res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
int sub(int a, int b) {return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b) {return ((a%mod)*(b%mod) + mod)%mod;}
int inv(int x) {return expo(x, mod-2);}
#define endl "\n";
using namespace std;

vector<int>adj[200001];
int vis[200001];


int dfs(int node)
{
	vis[node]=1;
	
	int count=1;
	
	for(auto it:adj[node])
	{
		if(!vis[it])
		{
			count+=dfs(it);
		}
	}
	return count;
}

void solve()
{	
	int n;
	cin>>n;
	int m;
	cin>>m;
	
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		
		adj[a].pb(b);
		adj[b].pb(a);
	}
	
	
	memset(vis,0,sizeof(vis));
	
	int ans=0;
	
	for(int i=0;i<=n;i++)
	{
		int maxi=dfs(i);
		ans=max(ans,maxi);
	}
	
	cout<<ans<<endl;
	
}


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

Measured memory_bytes: 25480
#include <sstream>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<ctime>
#include<cmath>
#include<map>
#include<unordered_map>
#include<stack>
#include<random>
#include<queue>
#include<list>
#include<math.h>
#include<bitset>
#include<fstream>
using namespace std;
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define ii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int> >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define nu 100001
#define mul(x,y) ((ll)(x)*(y))%mod
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < int(n); i++)
#include<fstream>
const ll INF=9223372036854775807;
const ll mod=1000000007;
int  MOD(int  a, int  b)
{
    if(a>b)
        return a-b;
    else
        return b-a;
}
ll  max3(ll  a,ll  b, ll  c)
{
    return max(c,max(a,b));
}
ll min3(ll  a,ll  b,ll  c)
{
    return min(a,min(b,c));
}
ll  power(ll  x,ll  y,ll mod1)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%mod1;
        y = y>>1;
        x = (x*x)%mod1;
    }
    return res;
}
ll logg(ll  a)
{
    ll  x=0;
    while(a>1)
    {
        x++;
        a/=2;
    }
    return x;
}
ll  gcd(ll  a,ll   b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll abso(ll x)
{
    if(x<0)
    {
        return -x;
    }
    return x;
}
ll ceiling (ll  a,ll  b)
{
    if(a%b==0)
    {
        return a/b;
    }
    else
    {
        return a/b+1;
    }
}
ll modinv(ll x,ll p)
{
    return power(x,p-2,p);
}
int main()
{
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        int j=i;
        int num=0;
        while(j>0)
        {
            j=j/10;
            num++;
        }
        if(num%2==1)
        {
            ans++;
        }
    }
    cout<<ans;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>

using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;

#define rep(i,x) for(Int i = 0; i < (Int)(x); i++)
#define rrep(i,x) for(Int i = ((Int)(x) - 1); i >= 0; i--)
#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back

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

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

Int dx[4] = {1,0,-1,0};
Int dy[4] = {0,1,0,-1};
//const Int INF = 1001002003004005006ll;
const Int mod = 1e9 + 7;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//




int dfs(int a,int b, int c){
        if(a%2 == 1 || b%2 == 1 || c%2 == 1){
                return 0;
        }

        if(a == b && b == c) return -1;

        return dfs((b+c)/2, (a+c)/2, (a+b)/2) + 1;
}


int main()
{
        int a,b,c;
        cin >> a >> b >> c;
        int ans = dfs(a,b,c);
        cout << ans << endl;
        return 0;
}














Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

int main() {
    long double A, B;
    cin >> A >> B;
    cout << (long long)(A * B) << endl;
}

Measured memory_bytes: 3728
# ARC079C - Cat Snuke and a Voyage (ABC068C)
import sys
input = sys.stdin.readline

def main():
    n, m = list(map(int, input().rstrip().split()))
    s, d = set(), set()
    for _ in range(m):
        a, b = list(map(int, input().rstrip().split()))
        if a == 1:
            s.add(b)
        elif b == n:
            d.add(a)
    ans = len(s & d)
    print("POSSIBLE" if ans else "IMPOSSIBLE")


if __name__ == "__main__":
    main()

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

int main(){
    string s;
    cin >> s;

    if(s == "ABC"){
        cout << "ARC" << endl;
    }else if(s == "ARC"){
        cout << "ABC" << endl;
    }
}

Measured memory_bytes: 3628
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
num1 = 9999
ans = 0

for i in range(n):
  num2 = abs(a - (t - h[i]*0.006))
  if num1 > num2:
    ans = i+1
  num1 = min(num1, num2)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long
#define N (100005)

using namespace std;

ll tim[N],del[N],dep[N],res,ans;
int id[N],a[N],n,m;

il int gi(){
	RG int x=0,q=1; RG char ch=getchar();
	while ((ch<'0' || ch>'9') && ch!='-') ch=getchar();
	if (ch=='-') q=-1,ch=getchar();
	while (ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return q*x;
}

il int cmp(const int &a,const int &b){ return dep[a]>dep[b]; }

il void work(){
	for (RG int x=1;x<=m;++x){
		RG ll dep=0;
		for (RG int i=2,cur,now;i<=n;++i){
			cur=a[i]-a[i-1]; if (cur<0) cur+=m;
			now=a[i]-x; if (now<0) now+=m; ++now;
			dep+=min(cur,now);
		}
		ans=min(ans,dep);
	}
	cout<<ans; return;
}

int main(){
	n=gi(),m=gi(),ans=1LL<<60;
	for (RG int i=1;i<=n;++i) a[i]=gi();
	if (1LL*n*m<=100000000) work(),exit(0);
	for (RG int i=2;i<=n;++i)
		if (a[i]>=a[i-1]){
			tim[a[i-1]]++,tim[a[i]+1]--;
			del[a[i-1]]-=a[i-1],del[a[i]+1]+=a[i-1];
		} else{
			tim[a[i-1]]++,del[a[i-1]]-=a[i-1];
			tim[1]++,tim[a[i]+1]--;
			del[1]+=m-a[i-1],del[a[i]+1]-=m-a[i-1];
		}
	for (RG int i=1;i<=m;++i)
		tim[i]+=tim[i-1],del[i]+=del[i-1],dep[i]=1LL*i*tim[i]+del[i],id[i]=i;
	sort(id+1,id+m+1,cmp);
	for (RG int j=1,sz=min(2000,m),x;j<=sz;++j){
		x=id[j]; RG ll res=0;
		for (RG int i=2,cur,now;i<=n;++i){
			cur=a[i]-a[i-1]; if (cur<0) cur+=m;
			now=a[i]-x; if (now<0) now+=m; ++now;
			res+=min(cur,now);
		}
		ans=min(ans,res);
	}
	cout<<ans; return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b,p,c1=0,c2=0,c3=0;
	cin>>n>>a>>b;
	while(cin>>p)
		if(p<=a)
			c1++;
		else if(p<=b)
			c2++;
		else
			c3++;
	cout<<min({c1,c2,c3})<<endl;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n; scanf("%d",&n);
	vector<int> ans(n);
	for(int u=1;u<n;u++){
		int p; scanf("%d",&p); p--;
		ans[p]++;
	}
	rep(u,n) printf("%d\n",ans[u]);
	return 0;
}


Measured memory_bytes: 4068
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
const long long MAXN = 2e5+5;
long long n;
vector<long long> v1[MAXN];
long long ans[MAXN];
long long res[MAXN];
long long col[MAXN];

long long sz[MAXN];
long long f(long long x){
    return 1LL*x*(x+1)/2;
}
void dfs(long long curr, long long par){
    long long tmp = res[col[curr]];
    for(long long x:v1[curr]){
        if(x!=par){
            res[col[curr]] = 0;
            dfs(x,curr);
            sz[curr] += sz[x];
            ans[col[curr]]-=f(sz[x]-res[col[curr]]);
        }
    }
    res[col[curr]] = tmp+sz[curr];
}
int main() {
    cin>>n;
    for(long long i=1;i<=n;i++){
        cin>>col[i];
        sz[i] = 1;
    }
    for(long long i=1;i<n;i++){
        long long x,y;
        cin>>x>>y;
        v1[x].push_back(y);
        v1[y].push_back(x);
    }
    dfs(1,1);
    for(long long i=1;i<=n;i++){
        //cout<<col[i]<<endl;
        cout<<(ans[i]+f(n)-f(n-res[i]))<<endl;
    }
}

Measured memory_bytes: 36444
#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>;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);
template<typename A> ostream& operator<<(ostream&,vector<A>&);
 
const int N=1000006;

void solve(){
	int n;
	cin>>n;
	vi a(n);
	cin>>a;
	sort(all(a));
	cout<<a[n/2]-a[n/2-1];

}
	
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	if(a<0)a+=mod;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
	    output<<i<<' ';
	return output;	
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

///////////////////////////////////////////////////
// -------------------- I/O -------------------- //
///////////////////////////////////////////////////
// https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
template<typename T> void outputVec(const std::vector<T>& vec, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	for (auto it = vec.begin(); it != vec.end() - 1; ++it) { std::cout << *it << " "; }
	std::cout << *(vec.end() - 1) << "\n";
}
template<typename T> void outputVal(const T& res, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	std::cout << res << "\n";
}
template<typename T> T inputVal() { T a; std::cin >> a; return a; }
template<typename T> std::vector<T> inputVec(int N) {
	std::vector<T> vec(N);
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
	return vec;
}
template<typename T> void inputVec(std::vector<T>& vec) {
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
}

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////
void Main() {
	const int N = inputVal<int>();
	const string S = inputVal<string>();
	int cnt=0;
	for (int i = 0; i < 1000; ++i) {
		vector<int> c = { i / 100, (i / 10) % 10, i % 10 };
		int f = 0;
		for (int j = 0; j < N; ++j) {
			if (c[f] == (S[j]-'0')) ++f;
			if (f == 3) break;
		}
		if (f == 3) ++cnt;
	}

	outputVal(cnt);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << std::fixed << std::setprecision(15);
	Main();

	double tmp;
	cin >> tmp;

	return 0;
}


Measured memory_bytes: 384
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

S = input()
T = input()
 
for i in reversed(range(len(S)-len(T)+1)):
    flag = 1
    for j in range(len(T)) :
        if S[i+j] != T[j] and S[i+j] != "?":
            flag = 0
    if flag:
        ans = S[:i] + T + S[i+len(T):]
        print(ans.replace("?", "a"))
        exit()
 
print("UNRESTORABLE")

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

int main() {

    int h, w;
    cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w));
    rep(i, h){
        rep(j, w){
            cin >> a[i][j];
        }
    }

    vector<P> before;
    vector<P> after;
    rep(i, h){
        rep(j, w){
            if(a[i][j] % 2 == 1){
                if(i == h-1 && j == w-1){
                    continue;
                }
                a[i][j] -= 1;
                before.emplace_back(i+1, j+1);
                if(j != w-1){
                    a[i][j+1] += 1;
                    after.emplace_back(i+1, j+2);
                }
                else if(i != h-1){
                    a[i+1][j] += 1;
                    after.emplace_back(i+2, j+1);
                }
            }
        }
    }
    
    int n = before.size();
    cout << n << endl;
    rep(i, n){
        cout << before[i].first << " " << before[i].second << " ";
        cout << after[i].first << " " << after[i].second << endl;   
    }
    return 0;
}

Measured memory_bytes: 5228
#include<stdio.h>

#define N 100000

typedef struct
{
  char suit;
  int num;
  int order;
}card;

int partition(card *, int, int);
void quicksort(card *, int, int);

int main()
{
  int n, i, j, min, flg=0;
  char str[2];
  card A[N];

  scanf("%d", &n);
  for(i=0; i<n; i++)
    {
      //printf("%d\n",i);
      scanf("%s%d", str, &A[i].num);
      A[i].suit = str[0];
      A[i].order = i;
    }

  quicksort(A, 0, n-1);
  
  for(i=0; i<n; i++)
    {
      if(i < n-1 && A[i].num == A[i+1].num)
	{
	  if(A[i+1].order < A[i].order) flg=1;
	}
    }
  
  if(flg == 0) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0; i<n; i++)
    {
      printf("%c %d\n", A[i].suit, A[i].num);
    }


  return 0;
}
int partition(card *A, int p, int r)
{
  int x, i, j;
  card t;

  x = A[r].num;
  i = p-1;

  for(j=p; j<r; j++)
    {
      if(A[j].num <= x)
	{
	  i++;
	  t = A[i];
	  A[i] = A[j];
	  A[j] = t;
	}
    }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;

  return i+1;
}
void quicksort(card *A, int p, int r)
{
  int q;
  
  if(p<r)
    {
      q = partition(A, p, r);
      quicksort(A, p, q-1);
      quicksort(A, q+1, r);
    }
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){

    int h, w;
    cin >> h >> w;
    rep(i,w+2) cout << '#';
    cout << endl;
    rep(i,h) {
        cout << '#';
        rep(j,w) {
            char a;
            cin >> a;
            cout << a;
        }
        cout << '#' << endl;
    } 
    rep(i,w+2) cout << '#';
    cout << endl;
}

Measured memory_bytes: 3632
H,W = map(int,input().split())
A = [input() for i in range(H)]
ans = []
for i in range(H):
    flag = 0
    for j in range(W):
        if A[i][j] == "#":
            flag = 1
    if flag == 1:
        ans.append(A[i])
H2 = len(ans)
W2 = len(ans[0])
ans2 = []
for j in range(W2):
    flag = 0
    for i in range(H2):
        if ans[i][j] == "#":
            flag = 1
    if flag == 1:
        ans2.append(j)
Ans = []  
for i in range(H2):
    Ans.append([])
    for j in ans2:
        Ans[i].append(ans[i][j])
        
W3 = len(Ans[0])
for i in range(H2):
    tmp = ""
    for j in range(W3):
        tmp += Ans[i][j]
    print(tmp)

Measured memory_bytes: 39536
#include<bits/stdc++.h>
//#include<boost\lexical_cast.hpp> 
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int> 
#define vl vector<ll>
#define vpi vector<pi> 
#define vpl vector<pl>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define INF 0x7fffffff
#define LINF 2000000000000000007
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define ss second
#define ff first
#define endl "\n"
#define mod 1000000007
#define MAX 100010
#define fill(a,x) memset(x,a,sizeof x)
#define all(x) x.begin(),x.end()
#define clr(x) memset(x,0,sizeof x)
#define rep(i,a,n) for(ll i=a;i<n;++i)
#define repr(i,n,b) for(ll i=n;i>=b;i--)
#define repit(itr,x) for(auto itr=x.begin();itr!=x.end();itr++)
using namespace std;
//using boost::lexical_cast;
//using boost::bad_lexical_cast;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int test=1;
	// cin>>test;
	while(test--){
		int n; cin>>n;
		int k; cin>>k;
		vi a(n+1,0);
		rep(i,0,n) cin>>a[i];
		ll ans=0;
		vi dp(n+1,INF);
		dp[0]=0;

		rep(i,0,n){
			rep(j,i+1,i+k+1){
				if(j<n)
				dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i]));
//				ans+=dp[i];
			}
		}
		cout<<dp[n-1]<<endl;
	}
}

Measured memory_bytes: 1152
// https://beta.atcoder.jp/contests/agc006/tasks/agc006_d

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define FOR(k,a,b) for(int k=(a); k<=(b); ++k)
#define IFOR(k,a,b) for(int k=(a); k>=(b); --k)
#define REP(k,a) for(int k=0; k<(a);++k)
#define IREP(k,a) for(int k=a-1; k>=(0);--k)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define x first
#define y second
#define INF 1000000001
#define INFLONG 1000000000000000000
#define MOD 1000000007
#define MAX 100
#define ITERS 100
#define MAXM 200000
#define MAXN 1000000
#define PI 3.1415926535897932384626
#define ERR -987654321
#define read1(a) scanf("%d",&a)
#define read2(a,b) scanf("%d%d",&a,&b)
#define read3(a,b,c) scanf("%d%d%d",&a,&b,&c)

int a[200500], b[200500], n, m, res;

bool verify(int l, int r, int length) {
    res = -1;
    if(length == 1 && l == m/2) res = b[l];
    else if(l <= m/2 && m/2 < r) {
        if((r-l)%2 == 0) {
            if((l+r)/2 <= m/2) res = b[r-1];
             else res = b[l];
        } else res = b[l];
    }
    if(res == -1) return false;
    else return true;
}

int check(int p) {
    bool flag = true;
    REP(i,m) {
        if(a[i] < p) b[i] = 0;
        else b[i] = 1;
        if(i && b[i] == b[i-1]) flag = false;
    }

    if(flag) return b[0];
    else {
        int l = 0, length = 1;
        FOR(i,1,m-1) {
            if(b[i] != b[i-1]) {
                length++;
            } else {
                if(verify(l, i, length)) return res;
                length = 1;
                l = i;
            }
        }
        if(verify(l, m, length)) return res;
        assert(false);
    }
    

}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    m = 2*n -1;
    REP(i,m) cin>>a[i];
    int lo = 1, hi = 2*n-1;
    while(lo<hi) {
        int mid = lo + (hi-lo+1)/2;
        if(check(mid)) lo = mid;
        else hi = mid - 1;
    }
    cout<<lo;
	return 0;
}

Measured memory_bytes: 1920
N, M= map(int, input().split())
H = list(map(int, input().split()))

l = H.copy()
for i in range(M):
  A, B = map(int, input().split())
  if H[A-1] > H[B-1]:
    l[B-1] = 0
  elif H[B-1] > H[A-1]:
    l[A-1] = 0
  elif H[A-1] == H[B-1]:
    l[A-1] = 0
    l[B-1] = 0
print(N - l.count(0))
  

Measured memory_bytes: 20044
# https://atcoder.jp/contests/abc085/tasks/abc085_c

import sys

n, y = map(int, input().split())

for a in range(n + 1):
    for b in range(n + 1 - a):
        total = 10000 * a + 5000 * b + \
            1000 * (n - a - b)
        if total == y:
            print("{} {} {}".format(a, b, n - a - b))
            sys.exit()
print("{} {} {}".format(-1, -1, -1))


Measured memory_bytes: 3060
//  Created by Vignesh Manoharan

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <cstring>
#include <cassert>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<vi> vvi;

const int INF = 1000000000;
const ll LINF = 1e17;
const double PI =3.141592653589793238;
#pragma unused(INF,PI,LINF)
#define F(i,a,n) for(int i=(a);i<(n);i++)

template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){
    for(int i=0;i<(t).size();i++)s<<t[i]<<((i<(t).size()-1)?" ":"");return s; }
template<typename T> ostream& operator<<(ostream &s,set<T> t){for(T x:t) s<<x<<" ";return s; }
template<typename T> istream& operator>>(istream &s,vector<T> &t){
    for(int _i=0;_i<t.size();_i++) s>>t[_i];return s; }

#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()

vector<vector<ii>> graph;

vector<int> dist;
void dijkstra(int s){
    dist[s]=0;
    priority_queue<ii,vector<ii>,greater<ii>> pq;
    pq.push(make_pair(0, s));
    while(!pq.empty()){
        ii front=pq.top();pq.pop();
        int d=front.first,u=front.second;
        if(d==dist[u]){
            for(auto p:graph[u]){
                int v=p.first,w=p.second;
                if(dist[u]+w<dist[v]){
                    dist[v]=dist[u]+w;
                    pq.push(make_pair(dist[v], v));
                }
            }
        }
    }
}
int main(int argc, const char * argv[]) {
#ifdef local_test
    //    input
    //    freopen("input","w",stdout);
    //    cout<<"1 \n 100 10 \n";
     freopen("input","r",stdin);
     freopen("output","w",stdout);
#endif
    int n,m;
    cin>>n>>m;
    int r;
    cin>>r;
    graph=vector<vector<ii>>(n, vector<ii>());
    dist=vi(n,INF);
    F(i,0,m){
        int s,t,d;
        cin>>s>>t>>d;
        graph[s].pb(mp(t,d));
//        graph[t].pb(mp(s,d));
    }
    dijkstra(r);
    for(int d:dist) if(d<INF) cout<<d<<"\n"; else cout<<"INF\n";
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A.at(i) = a;
  }

  bool flag = true;
  int ans_cnt = 0;

  while (flag) {
    for (int i = 0; i < N; i++) {
      if (A.at(i) % 2 == 0) {
        A.at(i) /= 2;
      }
      else {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans_cnt++;
    }
  }

  cout << ans_cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define loop(x,n) for(int x = 0; x < n; ++x)
#define ed end()  
#define bg begin()
#define ft first
#define sc second
# define ld long double
#define ll long long
#define ub(v,a) upper_bound(all(v),a)
#define lb(v,a) lower_bound(all(v),a)
#define sz(a) (int)(a.size())
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define tr(v,it) for(auto it=v.begin();it!=v.end();it++)
#define present(v,x) (v.find(x)!=v.end()) //set/map etc.
#define vpresent(v,x) (find(all(v),x)!=v.end()) // vector
#define M_PI 3.14159265358979323846
#define bs(v,x) binary_search(all(v),x)
typedef vector< int > vi;
typedef vector< long long > vll;
typedef vector<pair<ll,ll>> vp;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
const long long max_sz = 1e5 + 1;
const long long mod = 1e9 + 7;
char flip(char k){ if(k=='0') return '1'; return '0'; }
ll sum_digit(ll n){ ll a=0,i; for(i=n;i>0;i=i/10){ a+=(i%10);} return a; }
ll gcd(ll a, ll b){
	if(b == 0) return a;
	return gcd(b, a%b);
}
int main(){
                   // ios_base::sync_with_stdio(false);
                    //cin.tie(NULL);
                    //cout.tie(NULL);
 
                     ll t;
                   //  cin >> t;
                     t=1;
                     while (t--){
                      ll x;cin>>x;
                      if(x>=30)cout<<"Yes\n";
                      else cout<<"No\n";
                      
                     }
                      return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

int main(void) {
    int num,num_A[21],num_B[21],num_C[20],ans=0,temp,i;
    scanf("%d",&num);
    for (i=0;i<num;i++) {  //Aの要素を代入する
        scanf("%d",&num_A[i]);
    }
    for (i=0;i<num;i++) {  //Bの要素を代入する
        scanf("%d",&num_B[i]);
    }
    for (i=0;i<num-1;i++) {  //Cの要素を代入する
        scanf("%d",&num_C[i]);
    }
    for (i=0;i<num;i++) {
        ans+=num_B[num_A[i]-1];  //i番目の評価を足す
        if (i>0 && num_A[i]-temp==2) {  //連番の料理を食べた時の処理
            ans+=num_C[temp];
        }
        temp=num_A[i]-1;  //料理の番号を記録
    }
    printf("%d\n",ans);
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  int res = 0;
  
  for (int i = 0; i < S.size(); ++i) {
    for (int j = i + 1; j < S.size(); ++j) {
      if (S.at(i) == S.at(j)) ++res;
    }
  }
  
  if (res > 0) {
    cout << "no" << endl;
  } else {
    cout << "yes" << endl;
  }
  
  return 0;
  
}
      

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
#define ll long long 
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define maxn 100001

#define ll long long 



int main(){
	int n,m,k;
	cin>>n>>m>>k;
	vector<long long int> a(n+1),b(m+1);
	a[0]=0;
	b[0]=0;
	for (int i = 0; i < n; ++i)
	{
		int t;
		cin>>t;
		a[i+1]=a[i]+t;
	}
	for (int i = 0; i < m; ++i)
	{
		int t;
		cin>>t;
		b[i+1]=b[i]+t;
	}
	// for(auto x:a)
	// 	cout<<x<<" ";
	// cout<<endl;
	// for(auto x:b)
	// 	cout<<x<<" ";
	// cout<<endl;
	int ans=0;
	int i=0;
	while(b[i]<=k&&i<=m){
		long long int res=k-b[i];
		//cout<<res<<endl;
		int ind=upper_bound(a.begin(),a.end(),res)-a.begin();
		//cout<<a[ind]<<endl;
		ans=max(ans,i+ind-1);
		//cout<<i<<" "<<ind<<endl;
		i++;
	}
	cout<<ans<<endl;
	
}

Measured memory_bytes: 6328
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	// AtCoder Beginner Contest 087
	// https://atcoder.jp/contests/abc087/tasks
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int res = 0;
		
		for (int i = 0; i <= a; i++) {
			for (int j = 0; j <= b; j++) {
				for (int k = 0; k <= c; k++) {
					if (500 * i + 100 * j + 50 * k == x) {
						res++;
					}
				}
			}
		}
		
		System.out.println(res);
	}
	
	static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine()); 
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}


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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
 int x,y;cin>>x>>y;
  set<int> a={1,3,5,7,8,10,12};
  set<int> b={4,6,9,11};
  set<int> c={2};
  if(a.count(x) && a.count(y))cout<<"Yes"<<endl;
  else if(b.count(x) && b.count(y))cout<<"Yes"<<endl;
  else if(c.count(x) && c.count(y))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}





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

public class Main {

    public static int minCost(int[] h, int i, int[] dp) {

        if (i == 0) {
            return 0;
        }
        if (i == 1) {
            return Math.abs(h[0] - h[1]);
        }
        if(dp[i] !=-1){
            return dp[i];
        }


        return dp[i] = Math.min(minCost(h, i - 1,dp) + Math.abs(h[i] - h[i - 1]), minCost(h, i - 2,dp) + Math.abs(h[i] - h[i - 2]));
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        try {
            int size = scanner.nextInt();
            int[] nums = new int[size];
            for (int i = 0; i < nums.length; i++) {
                nums[i] = scanner.nextInt();
            }
            int[] dp = new int[size];
            Arrays.fill(dp, -1);
            System.out.println(minCost(nums, size - 1, dp));
        } finally {
            scanner.close();
        }
    }
}

Measured memory_bytes: 66100
n,m,p = map(int,input().split())
edges = []
for _ in range(m):
    a,b,c = map(int,input().split())
    edges.append((a-1,b-1,c-p))
d = [-float('inf')]*n
d[0] = 0
for i in range(n):
    for u,v,c in edges:
        if d[u] != -float('inf') and d[u]+c > d[v]:
            d[v] = d[u]+c
            if i ==n-1:
                d[v] = float('inf')

for i in range(n):
    for u,v,c in edges:
        if d[u] != -float('inf') and d[u]+c > d[v]:
            d[v] = d[u]+c
ans = d[-1]
if ans ==float('inf'):
    print(-1)
elif ans <=0:
    print(0)
else:
    print(ans)

Measured memory_bytes: 75904
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
//#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
#define puts(x) cout << x << endl
using namespace std;
int input() {
	int r;
	cin >> r;
	//scanf("%lld", &r);
	return r;
}

int f1(int a, int p) {
	if (p == 1)return a;
	if (p % 2)return f1(a, p - 1) * a % mod;
	else return f1(a * a % mod, p / 2) % mod;
}
int cbn(int n, int r) {
	int rt = 1;
	for (int i = 1; i <= n; i++) { rt *= i; rt %= mod; }
	for (int i = 1; i <= r; i++) { rt *= f1(i, mod - 2); rt %= mod; }
	for (int i = 1; i <= n - r; i++) { rt *= f1(i, mod - 2); rt %= mod; }
	return rt;
}
int h, w, a, b;
int ans = 0, kl = 1, kr = 1;
signed main() {
	cin >> h >> w >> a >> b; kr = cbn(h + w - b - 2, h - 1);
	for1(i, h - a) {
		//(b-1)+(i-1)C(i-1)*(h-1)+(w-b-1)C(h-1)
		//kl = cbn(b + i - 2, i - 1), kr = cbn(h + w - b - 1 - i, h - i);
		ans += kl * kr % mod; ans %= mod;
		kl *= b + i - 1; kl %= mod; kl *= f1(i, mod - 2); kl %= mod;
		kr *= h - i; kr %= mod; kr *= f1(h + w - b - 1 - i, mod - 2); kr %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
def longest():
    seq1 = raw_input()
    seq2 = raw_input()
  
    a, b = len(seq1), len(seq2)
    x1 = [0 for i in range(b+1)]
    for i in range(a):
        e1 = seq1[i]
        x2 = x1+[]
        for j in range(b):
            if e1 == seq2[j]:
                x1[j+1] = x2[j] + 1
            elif x1[j+1] < x1[j]:
                x1[j+1] = x1[j]
    return x1[-1]
  
n = input()
for i2 in range(n):
    print longest()

Measured memory_bytes: 6460
/*
  AOJ 0571
  Title:JJOOII
  @kankichi573
  WA 27/50 13/10/8
*/
#include <stdio.h>
#include <string.h>


char string[1000001];
char jo[21];

int count_char_forward(char * p,char c,int limit)
{
        int cnt;

        cnt=0;
        while(*p)
        {
                if(*p!=c || (cnt>=limit && limit!=0))
                        break;
                p++;cnt++;
        }
        return(cnt);
}
int count_char_backward(char * p,char c,int limit)
{
        int cnt;

        cnt=0;
        while(p>=string)
        {
                if(*p!=c || (cnt>=limit && limit!=0))
                        break; 
                p--;cnt++;
        }
        return(cnt);
}
void make_jo(int cnt)
{
        int i;

        if(cnt>10)
                cnt=10;
        for(i=0;i<cnt;i++)
                jo[i]='J';
        for(i=cnt;i<2*cnt;i++)
                jo[i]='O';
        
}

int solve()
{
        int olen,jlen,ilen,max_,jolen;
        char *ret;
        ret=string;
        max_=0;
        
        make_jo(max_+1);

        while((ret=strstr(ret,jo)))
        {
                //printf("jo=%s\n",jo);

                jolen=max_;
                if(jolen>=10)
                        jolen=9;

                olen=count_char_forward(ret+jolen+1,'O',0);
                jlen=count_char_backward(ret+jolen,'J',olen);
                ilen=count_char_forward(ret+jolen+1+olen,'I',olen);
                //printf("FIND joi=%d %d %d\n",jlen,olen,ilen);
                if(jlen==olen && ilen==olen && olen > max_)
                {
                        //printf("max=%d\n",max_);
                        max_=olen;
                        make_jo(max_+1);
                }
                ret+=(olen+ilen);                
        }
        return(max_);
}

main()
{
        int ret;

        scanf("%s",string);

        ret=solve();

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

  return(0);
}

Measured memory_bytes: 1524
#!/usr/bin/env python3
#AGC11 A

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,c,k = map(int,sys.stdin.readline().split())
t = [int(sys.stdin.readline()) for _ in range(n)]
t.sort()
ans = 0
time,passenger = 0,0
for i in range(n):
    if passenger == 0 or passenger == c or time + k < t[i]:
        passenger = 1
        ans += 1
        time = t[i]
    else:
        passenger += 1
print(ans)


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

int sur(int a){
	if(a%2 == 0)
		return 0;
	else
		return 1;
}

int main(){
	vector<int> s = {0};
	int N;
	cin >> N;
	int n = N;
	while(N != 0){
		s.at(0) = sur(N);
		N = (N - sur(N))/(-2);
		s.insert(s.begin(),0);
	}
	if(n != 0)
		s.erase(s.begin());
	for (int i = 0; i < s.size(); i++)
		cout << s.at(i);
	cout << endl;
	return 0;
} 

Measured memory_bytes: 256
/*B - Good Distance / */

#include <bits/stdc++.h>

using namespace std;

int main(){

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

	int ans = 0;
	int puntos;
	int coord;

	cin >> puntos >> coord;

	vector < vector <int> > dist(puntos, vector <int> (coord));
	
	for (int i = 0; i < puntos; ++i)
	{
		for (int j = 0; j < coord; ++j)
		{
			cin >> dist[i][j];
		}
	}

	int raiz;
	int num;
	int suma;

	for (int i = 0; i < puntos; ++i)
	{
		for (int j = i + 1; j < puntos; ++j)
		{
			num = 0;
			for (int k = 0; k < coord; ++k)
			{
				suma = abs(dist[i][k] - dist[j][k]);
				num += (suma * suma);
			}

			raiz = sqrt(num);
			if(raiz * raiz == num){
				ans++;
			}
		}
	}

	cout << ans;
	return 0;
}

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

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N, T, end_time = 0, ans = 0;
	cin >> N >> T;
	for (int i = 0; i < N; i++)
	{
		int pushed_time;
		cin >> pushed_time;
		ans += pushed_time + T - max(pushed_time, end_time);
		end_time = pushed_time + T;
	}
	cout << ans << "\n";
	return 0;
}



Measured memory_bytes: 256
N,K = list(map(int,input().split()))
h = list(map(int,input().split()))

inf = float("inf")
dp = [inf]*N
dp[0] = 0 #initial situation

for i in range(1,N):
	for k in range(K):
		if i-1-k >= 0:
			dp[i] = min(dp[i],dp[i-1-k] + abs(h[i]-h[i-1-k]))
			
print(dp[N-1])

Measured memory_bytes: 55392
//----->|try=0; while(!success) try++;|<------
//----->|Belief Yourself,Respect Yourself|<----
//----->|Be Proud Of Yourself,You're Doing Your best|<-----
#include<bits/stdc++.h>
using namespace std;
#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search;
#define lower(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Lower value search;
#define max3(a,b,c) max(max(a,b),c)//maximum value find three value;
#define min3(a,b,c) min(min(a,b),c)//minimum value find three value;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, n) for(int i = 1; i <= n; ++i)
#define rep1(i,start,n) for(int i=start;i<n;++i)
#define PI acos(-1.0)//PI Calculation
#define LL long long
#define AND(a,b) ((a) & (b))
#define OR(a,b) ((a)|(b))
#define XOR(a,b) ((a) ^ (b))
#define MP make_pair
#define sqr(x) ((x)*(x))
#define sqrt(x) sqrt(1.0*(x))
#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define MX 1000005
#define MOD 1000000007
template<typename T> T POW(T b,T p)          //Pow calculation
 {
    T r=1;
    while(p) {
        if(p&1)r=(r*b);
        b=(b*b);
        p>>=1;
    }
    return r;
}

template<typename T> T BigMod(T b,T p,T m) //BigMod Calculation
{
    T r=1;
    while(p) {
        if(p&1)r=(r*b)%m;
        b=(b*b)%m;
        p>>=1;
    }
    return r;
}

//||--------------------------->||Main_Code_Start_From_Here||<---------------------------------||
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    string s;
    while(cin>>s)
    {
        int flag=0;
        rep(i,s.size())
        {
            if(s[i]=='C')
            {
                for(int j=i+1;j<s.size();j++)
                {
                    if(s[j]=='F') flag=1;
                }
            }
        }
        if(flag) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}




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

using namespace std;

typedef long long ll;

const int maxn = 2e5+25;
const ll mod = 1e9+7;

bool buf;
ll h, w, a, b;
ll n[4];
ll ch[4][maxn];

inline ll inv(ll x) {
	// x^(mod-2) % mod

	ll ret = 1, y = mod-2;
	while (y) {
		if (y&1)
			ret = (ret*x) % mod;
		x = (x*x) % mod;
		y >>= 1;
	}

	return ret;
}

void init() {
	ch[1][0] = 1;
	ch[2][0] = 1;

	for (int c = 1; c <= 2; c++) {
		for (int i = 1; i <= n[c]; i++) {
			ch[c][i] = ((ch[c][i-1] * (n[c]-i+1)) % mod) * inv(i);
			ch[c][i] %= mod;
			//cout << ch[c][i] << ' ';
		}
		//cout << endl;
	}
}

int main() {

	buf = scanf("%lld%lld%lld%lld", &h, &w, &a, &b);
	h--; w--;

	n[1] = h-a+b; n[2] = w+a-b;

	init();

	ll res = 0;
	for (int i = h-a-(w-b); i <= h-a; i++) 
		res = (res + ch[1][i]*ch[2][h-i]) % mod;

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

	return 0;
}

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

#define FILL(mat, n, m) for(i=0; i<(n); ++i) for(j=0; j<(m); ++j) cin >> ((mat)[i][j]);

int main()
{
	int n, m, l, i, j;
	cin >> n >> m >> l;

	unsigned long a[n][m], b[m][l];
	FILL(a, n, m);
	FILL(b, m, l);

	for(i=0; i<n; ++i) {
		for(j=0; j<l; ++j) {
			unsigned long prod = 0;
			for(int k=0; k<m; ++k)
				prod += a[i][k] * b[k][j];
			cout << prod << ((j==l-1) ? '\n' : ' ');
		}
	}

	return 0;
}



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

int main(){
	int n, m, a, sum = 0;
  	cin>>n>>m;
  	for(int i = 0; i<m; i++){
		cin>>a;
     	sum += a;
    }
  
  	if(sum <= n){
		cout<<(n - sum)<<endl;
    }else{
		cout<<-1<<endl;
    }
	return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;


const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

vector<vector<int>> v(500,vector<int>(500,0));
int main()
{
    int n,m,q;
    cin >> n >> m >> q;
    REP(i,m){
        int l,r;cin >> l >> r;
        l--;r--;
        v[l][r]++;
    }
    REP(i,n){
        REP(j,n){
            if(j==0)continue;
            v[i][j]+=v[i][j-1];
        }
    }
    REP(i,q){
        int p,q;cin >> p >> q;
        p--;q--;
        int ans=0;
        FOR(j,p,q+1){
            ans+=v[j][q];
        }
        cout << ans << endl;
    }
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define For(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
typedef vector<long long> vlint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<vector<long long>> vlint2;



int main() {
    int n, m; cin >> n >> m;
    int cnt[n+1];
    rep(i, n) cnt[i+1] = 0;
    int a, b;
    rep(i, m){
        cin >> a >> b;
        cnt[a]++;
        cnt[b]++;
    }
    int count = 0;
    rep(p, n){
       count += cnt[p+1] % 2;
    }
    if (count > 1){
        cout << "NO" << endl;
    }
    else{
        cout << "YES" << endl;
    }

}



Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define SIZE 1000005
#define MOD 998244353LL

using namespace std;
typedef long long int ll;

ll fac[SIZE],finv[SIZE],inv[SIZE];

void make()
{
	inv[1]=1;
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	for(int i=2;i<SIZE;i++)
	{
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		fac[i]=fac[i-1]*(ll) i%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
ll C(int a,int b)
{
	if(a<b) return 0;
	return fac[a]*(finv[b]*finv[a-b]%MOD)%MOD;
}
int main()
{
	make();
	int n,k;
	scanf("%d %d",&k,&n);
	ll ret=0;
	for(int r=n;r>=0;r-=2)
	{
		int low=(n+r)/2-k;
		if(low<0) continue;
		if(r>0)
		{
			ret+=C(n,(n-r)/2);
			if(ret>=MOD) ret-=MOD;
			int tg=2*(low+1)+r;
			if(tg<=n)
			{
				ret-=C(n,(n-tg)/2);
				if(ret<0) ret+=MOD;
			}
		}
		else
		{
			n--,r++;
			ret+=C(n,(n-r)/2);
			if(ret>=MOD) ret-=MOD;
			int tg=2*(low+1)+r;
			if(tg<=n)
			{
				ret-=C(n,(n-tg)/2);
				if(ret<0) ret+=MOD;
			}
		}
	}
	printf("%lld\n",ret);
	return 0;
}


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

int main(){
  ll n;
  cin>>n;
  rep(i,n+1){
    if((int)(i*1.08)==n){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<":("<<endl;
}


Measured memory_bytes: 256