akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};

fn main() {
    let n: usize = read();
    let m: i64 = read();
    let mut a: Vec<i64> = vec![-1; n];
    let mut ans = 0;

    if n == 1 && m == 0 {
        println!("{}", 0);
        return;
    }

    for _ in 0..m {
        let s: usize = read();
        let c: i64 = read();
        if a[s - 1] != -1 && a[s - 1] != c {
            ans = -1;
        }
        a[s - 1] = c
    }

    if ans == -1 || (n != 1 && a[0] == 0) {
        println!("{}", -1);
        return;
    }

    let mut ansa: String = "".to_string();
    for i in 0..n {
        let ai = a[i];
        if ai != -1 {
            ansa += &ai.to_string();
        } else {
            if i != 0 {
                ansa += &"0".to_string();
            } else {
                ansa += &"1".to_string();
            }
        }
    }

    println!("{}", ansa);
}


Measured memory_bytes: 4352
#include<cstdio>
#include<cmath>
#include<algorithm>

using namespace std;

typedef double Real;

const Real G=9.8;
const Real inf=1e9;
const Real eps=1e-9;

template<class T> bool eq(T a,T b){
	return abs(a-b)<eps;
}

template<class T> int sgn(T a){
	if(eq(a,0.0)) return 0;
	if(a>0) return 1;
	return -1;
}

Real a[1010],b[1010];

int vx[1010],vy[1010];
int N;

int X,Y;

Real getmin(){
	Real res=inf;
	for(int i=0;i<N;i++){
		Real cur=X*a[i]-X*X*b[i];
		res=min(res,cur);
	}
	return res;
}

Real getMax(){
	Real ub=inf,lb=-inf;
	Real res;
//	for(int i=0;i<N;i++) ub=min(ub,a[i]);
	for(int stage=0;stage<150;stage++){
		Real mid=(ub+lb)/2;
		Real x=0,y=0;
		for(int i=0;i<N;i++){
			if(a[i]<mid) continue;
			Real cx=(a[i]-mid)/(b[i]*2);
			Real cy=a[i]*cx-b[i]*cx*cx;
			x+=cx;y+=cy;
		}
		if(x>X){
			lb=mid;
		}else{
			ub=mid;
		}
		res=y;
	}
	return res;
}

void input(){
	scanf("%d",&N);
	if(N==0) exit(0);
	for(int i=0;i<N;i++){
		scanf("%d%d",vx+i,vy+i);
	}
	scanf("%d%d",&X,&Y);
}

void precalc(){
	for(int i=0;i<N;i++){
		a[i]=(Real)vy[i]/vx[i];
		b[i]=0.5*G/(vx[i]*vx[i]);
	}
}

int main(){
	while(true){
		input();
		precalc();
		Real mi=getmin();
		Real Ma=getMax();
//		printf("%f %f\n",mi,Ma);
		if(sgn(Ma-Y)>=0&&sgn(Y-mi)>=0){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1036
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  replace(s.begin(),s.end(),',' , ' ');
  cout << s << endl;
  return 0;
}

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

using namespace std;

#define vi vector<int>
#define all(v) v.begin(),v.end()
#define ll long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define D1(x) {cerr<<" [" <<#x<<": "<<x<<"]";cout << endl;}
#define D2(x) {cerr<<" [" <<#x<<": ";for(auto it:x)cerr<<it<< " ";cerr<<"] ";cout << endl;}

const ll MOD = 1e9 + 7;
const ll maxn = 2e5 + 5;

void solve(){
	int n,k;
	cin >> n >> k;
	ll sum=0;
	vi v(n);
	for(int i=0;i<n;i++)cin >> v[i];
	sort(all(v));
	for(int i=0;i<k;i++){
		sum += v[i];
	}
	cout << sum;
}

int main() {
    IOS
        
        solve();
    cerr << endl << "[ Time : " << (float) clock() / CLOCKS_PER_SEC << " secs ]" << endl;

}
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 3808
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,s;
  int b[2100];
  cin >> a ;
  for(int i=0;i<a;i++){
    cin >> b[i];
  }
  sort(b,b+a);
  for(int i=0;i<a-2;i++){
    for(int j=i+1;j<a-1;j++){
      if(b[i]+b[j]<b[j+1])continue;
      for(int k=j+1;k<a;k++){
        if(b[k]<b[j]+b[i]){
          s=s+1;
        }
      }
    }
  }
 
 
  cout << s << endl;


}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int i,A[100],N,aLen=0,j,tmp,count=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
 
   
  for(i=0;i<N-1;i++){
    for(j=N-1;j>i;j--){
      if(A[j]<A[j-1]){
	tmp = A[j];
	A[j] = A[j-1];
	A[j-1] = tmp;
	count++;
      }
    }
  }
  
  for(i=0;i<N;i++){
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0; 
}

Measured memory_bytes: 604
function Main(input) {
  "use strict";
	const lines = input.split("\n");
  const line1 = lines[0].split(" ");
  let nums = line1.map(s => parseInt(s, 10));
  let t = nums.pop();
  let b = nums.pop();
  let a = nums.pop();
  console.log( Math.floor((t+0.5)/a)*b)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "<command-line>" 2
# 1 "<stdin>"

using namespace std;

# 1 "../Algo/NumberTheory/modulo.h" 1
class ModuloOps {
public:
    ModuloOps(long long mod): MOD(mod) {
    }

    long long binPow(long long a, long long b) {
        if (b < 0) {
            throw "invalid op";
        }
        if (b == 0) {
            return 1;
        }
        auto prev = binPow(a, b/2);
        return mul(mul(prev, prev), b % 2 == 1 ? normalize(a) : 1);
    }

    long long inv(long long a) {
        return binPow(a, MOD - 2);
    }

    inline long long add(long long a, long long b) {
        return normalize(a + b);
    }

    inline long long sub(long long a, long long b) {
        return normalize(a - b);
    }

    inline void inc(long long &a, long long b) {
        a = add(a, b);
    }

    inline long long mul(long long a, long long b) {
        return normalize(normalize(a) * normalize(b));
    }

    inline long long div(long long a, long long b) {
        return mul(a, inv(b));
    }

private:
    long long MOD;

    inline long long normalize(long long a) {
        return (a%MOD + MOD) % MOD;
    }
};
# 5 "<stdin>" 2

ModuloOps MOD(1e9+7);

vector<long long> pw2;
vector<long long> invPw2;

long long calc(vector<int> &a) {
    auto all = 1ll;
    for (auto sz: a) {
        all = MOD.mul(all, invPw2[sz]);
    }
    auto bad = all;
    for (auto sz: a) {
        MOD.inc(bad, MOD.mul(MOD.mul(all, pw2[sz]), MOD.sub(1, invPw2[sz])));
    }
    auto res = MOD.div(MOD.sub(1, bad), 2);
    return res;
}

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

    cin >> n;
    pw2.assign(n+1, 1ll);
    for (int i = 1; i <= n; i++) {
        pw2[i] = MOD.mul(pw2[i-1], 2);
    }
    invPw2.assign(n+1, 1ll);
    for (int i = 1; i <= n; i++) {
        invPw2[i] = MOD.div(1, pw2[i]);
    }
    vector<vector<int>> g(n);
    for (int i = 0; i < n-1; i++) {
        int u, v;
        cin >> u >> v;

        u--; v--;
        g[v].push_back(u);
        g[u].push_back(v);
    }
    long long ans = 0;
    function<int(int, int)> enter;
    enter = [&] (int v, int p) {
        vector<int> a;
        int tot = 1;
        for (int u: g[v]) {
            if (u != p) {
                int sz = enter(u, v);
                a.push_back(sz);
                tot += sz;
            }
        }
        if (p != -1) {
            a.push_back(n-tot);
        }
        MOD.inc(ans, calc(a));
        return tot;
    };
    enter(0, -1);
    cout << ans << endl;
}


Measured memory_bytes: 37356
#include<stdio.h>

int main(void){

		int a, b;
		char op;
		scanf("%d %c %d",&a,&op,&b);

		do{
			if (op == '+'){ printf("%d\n", a + b); }
			else if (op == '-'){ printf("%d\n",a-b); }
			else if (op == '*'){ printf("%d\n", a * b); }
			else if (op == '/'){ printf("%d\n", a / b); }
			else if (op == '?'){ break; }

			scanf("%d %c %d", &a, &op, &b);

		} while (op != '?');

	

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int x;
  cin>>x;
  cout<<(x>=30 ? "Yes" : "No")<<'\n';
  return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    int n;
    cin >> n;

    map<string , int> cnt;

    long long ans = 0;
    for (int i = 1 ;i <= n ;i++) {
        string num = to_string(i);
        ans += cnt[string(1 , num.back()) + num.front()];
        cnt[string(1 , num.front()) + num.back()]++;
        ans += cnt[string(1 , num.back()) + num.front()];
    }

    cout << ans;
}


Measured memory_bytes: 3724
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, a, b = 0; cin >> n;
	int test[101] = { 0 }, uiop[1001] = { 0 };
	for (int h = 1; h <= n; h++) {
		cin >> a;
		if (a > 0) {
			test[a]++;
			if (test[a] == 2) {
				cout << h << endl;
				cin >> n; return 0;
			}
			uiop[b] = a; b++;
		}
		else {
			test[abs(a)]--;
			if (uiop[b - 1] != abs(a)) {
				cout << h << endl;
				cin >> n; return 0;
			}
			else {
				uiop[b - 1] == 0; b--;
			}
		}
	}
	cout << "OK" << endl;
	cin >> n;
}


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

using namespace std;

const int MAXN = 1e5 + 5;
int mem[MAXN] , a[MAXN];
int n,k;
int solve(int i)
{
if(i == n - 1) return 0;
if(i >= n) return 1e9;

int &ret = mem[i];
if(ret != -1) return ret;
 ret = 1e9;
for(int j = 1 ; j <= k ; ++j)
{
    ret = min(ret , solve(i + j) + abs(a[i] - a[i + j]));
    
}
return ret;

}

int main()
{
cin >> n >> k;
for(int i = 0 ; i < n ; i++) cin >> a[i];
memset(mem,-1,sizeof(mem));
cout << solve(0) ;


}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
int main(){
 ll a,b,c;
  cin>>a>>b>>c;
  ll d=c-b-a;
  if(d>0&&4*a*b<d*d)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 300003, M = N << 1;

int h, n, m, a, b;
char s[N];

int main()
{
	//File("");
	a = gi(), b = gi(), h = gi(), m = gi();
	double du1 = 1. * h * 30 + 1. * m * 0.5;
	double du2 = 1. * 6 * m;
	double x = fabs(du1 - du2);
	if (x >= 180) x = 360.0 - x;
	double PI = acos(-1.0);
	printf("%.20lf\n", sqrt(1. * a * a + 1. * b * b - 2. * a * b * cos(x * PI / 180.0)));
	return 0;
}

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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define drrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	os << "{";
	rep(i, (int)v.size()) {
		if (i)
			os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
	for (auto val : array)
		std::cout << val << ", ";
	std::cout << "\n";
}

const int MOD = 1'000'000'000 + 7;
const int INF = 1'000'000'000 + 5;

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

	string day[] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
	string s; std::cin >> s;
	int today = 0;
	rep(i, 7) if (day[i] == s) today = i;
	std::cout << (7 - today) << "\n";
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(int i =(a);i<(n);i++)
#define urep(i,a,n) for(int i = (a);i>(n);i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int N,M;
ll a[10000];
int ans;
int main(){
	cin >> N;
	ans = 0;
	rep(i, 0, N) {
		cin >> a[i];
		while (a[i] % 2 == 0) {
			a[i] /= 2;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int ans = 0;
		int num = 0;
		for(int i = 1;i <= n;i++){
			num = i*i;
			if(num <= n){
				ans = Math.max(ans, num);
			} else {
				break;
			}
		}
		System.out.println(ans);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

ll gcd(ll a,ll b){
	if(a==0)
		return b;
	if(b==0)
		return a;
	if(a>b)
		return gcd(a-b,b);
	else
		return gcd(a,b-a);
}

int main(){
	ll x,y;
	cin>>x>>y;
	cout<<(x*y)/gcd(x,y)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef pair<int, int> i_i;
  
int H, W, M;

int main() {
  cin >> H >> W >> M;
  set<i_i> st;
  map<int, int> sumh, sumw;
  int max_h = 0, max_w = 0;
  for (int i = 0; i < M; i++) {
    int h, w;
    cin >> h >> w;
    st.insert({h, w});
    max_h = max(max_h, ++sumh[h]);
    max_w = max(max_w, ++sumw[w]);
  }
  
  vector<int> max_hs, max_ws; // 最大値の行、列番号リスト
  for (auto i = sumh.begin(); i != sumh.end(); i++) {
    if (max_h == i->second) {
	  max_hs.push_back(i->first);
    }
  }
  for (auto i = sumw.begin(); i != sumw.end(); i++) {
    if (max_w == i->second) {
	  max_ws.push_back(i->first);
    }
  }
  
  int ans = max_h + max_w - 1;
  
  // 爆破地点に対象物がなければそれが最大値
  for (auto h : max_hs) {
    for (auto w : max_ws) {
	 if (st.find({h, w}) == st.end()) {
       ++ans;
       cout << ans;
       return 0;
     }
    } 
  }
  
  cout << ans;
}

Measured memory_bytes: 49128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CGreenBin solver = new CGreenBin();
        solver.solve(1, in, out);
        out.close();
    }

    static class CGreenBin {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int a[] = new int[26];
            HashMap<String, Integer> map = new HashMap<>();
            long ans = 0;
            for (int i = 0; i < n; i++) {
                Arrays.fill(a, 0);
                String x = in.next();
                StringBuilder ansd = new StringBuilder("");
                for (int j = 0; j < x.length(); j++) {
                    a[x.charAt(j) - 'a']++;
                }
                for (int j = 0; j < 26; j++) {
                    ansd.append(Integer.toString(a[j]));
                }
                if (map.containsKey(ansd.toString())) {
                    ans += map.get(ansd.toString());
                    map.put(ansd.toString(), map.get(ansd.toString()) + 1);
                } else {
                    map.put(ansd.toString(), 1);
                }
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

typedef unsigned long long ull;
const ull MUL = (ull)1e9 + 7;

int main() {
	int n, m;
	cin >> n >> m;
	
	string s;
	cin >> s;
	
	vector< ull > mulv(n + 1, 1);
	vector< ull > hshs(n + 1, 0);
	
	for_(i,1,n + 1) {
		mulv[i] = mulv[i - 1] * MUL;
		hshs[i] = hshs[i - 1] * MUL + s[i - 1];
	}
	
	set< ull > strs;
	int l = 1, r = 1;
	
	for_(i,0,m) {
		string q;
		cin >> q;
		
		if (q == "L++") ++l;
		if (q == "L--") --l;
		if (q == "R++") ++r;
		if (q == "R--") --r;
		
		ull hs = hshs[r] - hshs[l - 1] * mulv[r - l + 1];
		//cout << hs << " " << s.substr(l - 1, r - l + 1) << endl;
		strs.insert(hs);
	}
	
	cout << strs.size() << endl;
}

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

int main(void){
    int n = 0, r = 0; 

    scanf("%d%d", &n, &r);

    if(n < 10){
        printf("%d\n", r + 100*(10-n));

    }else{
        printf("%d\n", r);
    }

    return 0;

} 


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	vector<int>a(w),root;
	vector<pair<int, int>>memo(h*w);
	rep(i, h) {
		rep(j, w) {
			cin >> a[j];
			if (i % 2==0)memo[w*i + j] = mp(i + 1, j + 1);
			else memo[w*i + j] = mp(i+1, w-j);
		}
		if (!(i % 2))rep(j, w)root.pb(a[j]);
		else rep(j, w)root.pb(a[w - 1 - j]);//1次元に落とす
	}
	vector<pair<int, int>>ans1, ans2;
	ll cnt = 0;
	rep(i, h* w-1) {
		if (root[i] % 2) {
			root[i]--;
			root[i + 1]++;
			++cnt;
			ans1.pb(memo[i]); ans2.pb(memo[i + 1]);
		}
	}
	cout << cnt << endl;
	rep(i, cnt)cout << ans1[i].first << " " << ans1[i].se << " " << ans2[i].first << " "<<ans2[i].se << endl;
}

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

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

  vector<int> p(n);
  vector<int> q(n);

  p[0] = 0;
  q[n - 1] = 0;
   rep(i,n - 1){
    p[i+1] = p[i];
    if (s[i] == 'W')
      p[i + 1]++;
  }
  for(int i=n-1;i>0;i--){
    q[i-1] = q[i];
    if (s[i] == 'E')
      q[i - 1]++;
  }
  int ans = n;
  rep(i,n)
    ans = min(ans, p[i] + q[i]);
  cout<<ans<<endl;
}

Measured memory_bytes: 6156
n, m, q = map(int, input().split())
a, b, c, d = [], [], [], []
for _ in range(q):
    i, j, k, l = map(int, input().split())
    a.append(i-1)
    b.append(j-1)
    c.append(k)
    d.append(l)

l = [[i] for i in range(1, m+1)]
for i in range(n-1):
    lcopy = []
    for j in l:
        for k in range(j[-1], m+1):
            lcopy.append(j + [k])
    l = lcopy

ans = []
for i in l:
    num = 0
    for j in range(q):
        if i[b[j]] - i[a[j]] == c[j]:
            num += d[j]
    ans.append(num)

print(max(ans))

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

int main()
{

	int n,m,a,b[25],c,sum,ans=0;
	cin>>n>>m>>c;
	for(int i=0;i<m;i++)
	{
		cin>>b[i];
	}
	for(int i=0;i<n;i++)
	{
		sum=c;
		for(int j=0;j<m;j++)
		{
			cin>>a;
			sum+=a*b[j];
		}
		if(sum>0)ans++;
	}
	cout<<ans<<endl;
	return 0;
}


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

typedef long long ll;
int T;
ll n, A, B, C, D;

int main() {
    scanf("%d", &T);
    while (T--) {
        scanf("%lld %lld %lld %lld %lld", &n, &A, &B, &C, &D);
        unordered_map<ll, ll> mp;
        function<ll(ll)> solve = [&](ll x) {
            if (mp.count(x)) return mp[x];
            mp[x] = x * D;
            if ((ll)1e18 / x < D) mp[x] = 1e18;
            if (x >= 2) {
                ll y = x / 2 * 2;
                mp[x] = min(mp[x], solve(y / 2) + A + (x - y) * D);
                if (y / 2 + 1 < x) mp[x] = min(mp[x], solve(y / 2 + 1) + A + (y + 2 - x) * D);
            }
            if (x >= 3) {
                ll y = x / 3 * 3;
                mp[x] = min(mp[x], solve(y / 3) + B + (x - y) * D);
                mp[x] = min(mp[x], solve(y / 3 + 1) + B + (y + 3 - x) * D);
            }
            if (x >= 5) {
                ll y = x / 5 * 5;
                mp[x] = min(mp[x], solve(y / 5) + C + (x - y) * D);
                mp[x] = min(mp[x], solve(y / 5 + 1) + C + (y + 5 - x) * D);
            }
            return mp[x];
        };
        printf("%lld\n", solve(n));
    }
    return 0;
}

Measured memory_bytes: 4568
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define     FAST            ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);
int main()
{
    FAST;
    char x;
    cin>>x;

    int p=x;


    if(x>=97&&x<=122)
    {
        cout<<"a"<<endl;
    }
    else
    {
        cout<<"A"<<endl;
    }


    return 0;

}


Measured memory_bytes: 3644
import sys

def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))

A = []
B = [[0,0,0],[0,0,0],[0,0,0]]
ans = "No"
for i in range(3):A.append(ILI())
n = int(input())
for k in range(n):
	b = int(input())
	for i in range(3):
		for j in range(3):
			if A[i][j] == b:B[i][j]=1
B2 = list(zip(*B))
for i in range(3):
	if sum(B[i])==3 or sum(B2[i])==3:
		ans = "Yes"
if B[0][0]+B[1][1]+B[2][2]==3:ans="Yes"
if B[0][2]+B[1][1]+B[2][0]==3:ans="Yes"
print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>

int main(){
  int i, j, len, res, cnt;
  char str[201];

  scanf("%s", str);
  
  len=strlen(str);

  res=len;
 
  for(i=0; i<len-1; i++){ 
    res--;
    if(res%2==1){
      continue;
    }else{
      cnt=0;
      for(j=0; j<res/2; j++){
	if(str[j]==str[res/2+j]){
	  cnt++;
	}
      }
      if(cnt==res/2){
	printf("%d\n", res);
	break;
      }
    }
   
  }
  
  return 0;
}


Measured memory_bytes: 128
n,x=gets.strip.split.map(&:to_i)
a=gets.strip.split.map(&:to_i)
a.sort!
a.each_with_index do |v,i|
  x-=v
  if x<0
    puts i
    exit
  end
end

if x==0
  puts n
else
  puts n-1
end

Measured memory_bytes: 1788
#include <cstdio>
#include <string>
#include <iostream>
#include <map>
#define maxN 11
#define rep(i,n) for(int i = 0; i < n; ++i)
#define it map<string,int>::iterator

using namespace std;

int n, len, ans;
string s[maxN][2];
map<string,int> h;
string S, T;

void travel(const string& S, int step){
	//cout<<S<<endl;
	if (S.length() > len) return;


	// end
	if (S == T){
		ans = min(ans, step);
		return;
	}

	// travel
	rep(i,n){
		string tmp = S;
		int pos = 0;
		int cnt = 0;
		while (1){
			pos = tmp.find(s[i][0],pos);
			if (pos==string::npos)
				break;
			++cnt;
			tmp = tmp.replace(pos, s[i][0].length(), s[i][1]);
			pos += s[i][1].length();
			//cout<<tmp<<endl;
		}
		if (cnt == 0)
			continue;
		travel(tmp, step+1);
	}
}

int main(){
	ios::sync_with_stdio(false);
	//freopen("t.in", "r", stdin);
	while (1){
		h.clear();
		cin>>n;
		if (n==0) break;
		ans = 11;
		rep(i,n){
			cin>>s[i][0]>>s[i][1];
		}
		cin>>S>>T;
		len = T.length();
		travel(S,0);
		if (ans == 11)
			ans = -1;
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1264
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
    int a,b,c=0;
    cin >> a >> b;
    for(int i=a;i<=b;i++){
        string s=to_string(i);
        if(s[0]==s[4]&&s[1]==s[3]){
            c++;
        }
    }
    cout << c;
}

Measured memory_bytes: 256
LI = lambda: list(map(int, input().split()))

n = int(input())
a = LI()
prod = 1
if 0 in a:
    print(0)
else:
    for x in a:
        prod *= x
        if prod > 10**18:
            print(-1)
            break
    else:
        print(prod)

Measured memory_bytes: 21576
using System;
using System.Linq;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class program{
  static void Main(string[] args){
    program p = new program();
    p.Run();
  }
  void Run(){
	int n =Readint()[0];
    int[] w=Readint();
    int s1=0, s2=0;
    for(int i=0;i<n;i++) s1+=w[i];
    
    int diff=s1;
    for(int i=0;i<n;i++){
      s2+=w[i];
      if(Abs(2*s2-s1)<diff) diff=Abs(2*s2-s1);
    }
    WriteLine(diff.ToString());
  }

  int[] Readint(){
    string[] s = ReadLine().Split();
    int[] res=new int[s.Length];
    Parallel.For(0,s.Length,i=>{
      res[i]=int.Parse(s[i]);
    });
    return res;
  }
}

Measured memory_bytes: 15704
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int n,k,a[200000];
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int ub=0,lb=mod;
    while(lb-ub>1){
        int mid=(lb+ub)/2;
        int ans=0;
        for(int i=0;i<n;i++)
            ans+=(a[i]+mid-1)/mid;
        (ans<=n+k?lb:ub)=mid;
    }
    cout<<lb<<endl;
}


Measured memory_bytes: 5168
n = int(input())

p = [int(s) for s in input().split()]
flag = -1
m_ans = 1
p_z = p[0]
for i in range(1,n):
    p_z = min(p_z,p[i])
    if(p_z >= p[i]):
        #print(p[j],p[i])
        m_ans += 1
    
print(m_ans)

Measured memory_bytes: 25768
#include <stdio.h>

int main(void) {
	const char *A = "Alice", *B = "Bob", *D = "Draw";
	int T1, T2, R1, R2;
	if (scanf("%d%d%d%d", &T1, &T2, &R1, &R2) != 4) return 1;
	if (R1 < 0 || R2 < 0) {
		puts(T1 < T2 ? A : (T1 > T2 ? B : D));
	} else {
		puts(R1 > R2 ? A : (R1 < R2 ? B : D));
	}
	return 0;
}



Measured memory_bytes: 2144
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 104;
int n,k;
int c[MAXN];
int main(){
    cin>>n>>k;
    for(int i=1;i<=k;i++){
        int d,x;
        cin>>d;
        for(int j=1;j<=d;j++){
            cin>>x;
            c[x] ++;
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++) if(!c[i]) ++ ans;
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 3644
d= input().rstrip()
d_list = d.split(" ")

def solution(d_list):
    if d_list.count("5") !=2:
        return "NO"
    else:
        if d_list.count("7") !=1:
            return "NO"
        else:
            return "YES"
            
def main():
    print(solution(d_list))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
N ,M, X = map(int, input().split())
li = []
minkane = -1
for i in range(N):
    li.append(list(map(int, input().split())))
for i in range(2 ** N):
    kane = 0
    li2 = [0 for k in range(M)]
    for j in range(N):
        if i & (1 << j) != 0:
            kane += li[j][0]
            for l in range(len(li2)):
                li2[l] += li[j][l+1]
    flag = 1
    for j in range(len(li2)):
        if li2[j] < X:
            flag = 0
    if flag == 1:
        if minkane == -1:
            minkane = kane
        else:
            minkane = min(minkane, kane)
print(minkane)



Measured memory_bytes: 68668
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int X[101010];
ll mo=1000000007;

int can[101010];
int first[101010];

int cnt[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	
	int fail=0,prex=0;
	FOR(i,N) {
		cin>>X[i];
		
		if(i==0) {
			X[0]=1;
		}
		else if(i==1) {
			
			if(X[1]>X[0]+2) X[1]=X[0]+2;
		}
		else {
			if(X[i-2]+1==X[i-1]) {
				fail++;
			}
			if(X[i]>=X[i-1]+2) {
				X[i]=X[i-1]+2;
			}
			first[i]=(fail+1)/2;
		}
		//_P("%d:%d\n",X[i],first[i]);
		cnt[first[i]]++;
	}
	
	ll ret=1;
	ll tot=cnt[0];
	for(i=1;i<=N;i++) {
		//cout<<tot<<endl;
		ret=ret*tot%mo;
		tot+=cnt[i];
		tot--;
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 1280
import java.util.*;

public class Main {
		public static void main(String[] args) {
			int i = 0;
			int atari = 0;
			Scanner scanner = new Scanner(System.in);
			String s = scanner.nextLine();
			String t = scanner.nextLine();
			String s_ = "";
			String t_ = "";
			for (i=0; i<3; i++) {
				s_ = s.substring(i, i+1);
				t_ = t.substring(i, i+1);
				if (s_.equals(t_)) {
					atari++;
				}
			}
			System.out.println(atari);
		}
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

class UnionFind {
public:
  vector<ll> par;
  vector<ll> siz;
  
  UnionFind(ll sz_) : par(sz_), siz(sz_, 1) {
    for(int i = 0; i < sz_; i++) par[i] = i;
  }
  
  void init(ll sz_){
    par.resize(sz_);
    siz.assign(sz_, 1);
    for (ll i = 0; i < sz_; ++i) par[i] = i;
  }
  
  ll root(ll x){
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  
  bool unite(ll x, ll y){
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }
  
  bool same(ll x, ll y){
    return root(x) == root(y);
  }
    
  ll size(ll x){
    return siz[root(x)];
  }
};

int main(){
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--, b--;
    uf.unite(a, b);
  }
  set<int> st;
  rep(i, n){
    st.insert(uf.root(i));
  }
  
  int ans = st.size() - 1;
  cout << ans << endl;
  
  return 0;
}

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

typedef long long ll;

/* メモリ食い過ぎ注意 */
#define int ll
#define ALL(v) v.begin(), v.end()
#define _REP(i, n) for (int i = 0; i < n; i++)
#define REP(n) _REP(i, n)

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    ll n;
    ll x[200000], xx[200000];
    cin >> n;
    REP(n)
    {
        cin >> x[i];
        xx[i] = x[i];
    }
    sort(x, x + n);

    map<ll, ll> m;
    // cout << "=" << n / 2 - 1 << "," << (n + 1) / 2 - 1 << endl;
    REP(n)
    {

        if (i < n / 2)
        {
            // cout << x[i] << "," << x[n / 2] << endl;
            // ;
            m.insert(make_pair(x[i], x[n / 2]));
        }
        else
        {
            // cout << x[i] << "," << x[(n) / 2 - 1] << endl;
            m.insert(make_pair(x[i], x[(n) / 2 - 1]));
        }
    }

    REP(n)
    {
        cout << m[xx[i]] << endl;
    }
}


Measured memory_bytes: 18816
n,a,b,k=map(int,input().split())
mod=998244353
ans=0
p=[1]*(n+1)
for i in range(n):
    p[i+1]=((i+1)*p[i])%mod
for ai in range(n+1):
    if k-a*ai>=0 and (k-a*ai)%b==0:
        bi=(k-a*ai)//b
        if bi<=n:
            ans+=p[n]*pow(p[ai],mod-2,mod)*pow(p[n-ai],mod-2,mod)*p[n]*pow(p[bi],mod-2,mod)*pow(p[n-bi],mod-2,mod)
            ans%=mod
print(ans)


Measured memory_bytes: 43628
#include <bits/stdc++.h>
using namespace std;
int main() {
	string x;
	cin >> x;
	int flag = 0;
	int keep = 0;
	long long int count = 0;
	while(1) {
		for(int i = keep; i < x.length(); i++) {
			if(i == x.length() - 1) {
				flag = 1;
				break;
			}
			if((x[i] == 'S')&&(x[i + 1] == 'T')) {
				keep = i - 1;
				if(keep < 0) keep = 0;
				x.erase(i, 2);
				break;
			}
		}
		if(x.length() < 2) break;
		if(flag) break;
		count++;
	}

	cout << x.length() << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 3e3 + 5;
const ll LINF = 1e18 + 5;
double dp[N][N], p[N];
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cout << fixed << setprecision(12);
 	int n;
 	cin >> n;
 	for(int i=1; i<=n; i++) cin >> p[i];
 	dp[0][0] = 1.0;
 	for(int i=1; i<=n; i++)
 	{
 		for(int j=0; j<=i; j++)
 		{
 			dp[i][j] += dp[i-1][j]*(1-p[i]);
 			if(j-1>=0) dp[i][j] += dp[i-1][j-1]*p[i];
 		}
 	}
 	double ans = 0.0;
 	for(int i=n/2+1; i<=n; i++) ans += dp[n][i];
 	cout << ans;
	return 0;
}


Measured memory_bytes: 69120
print=console.log;
ls=require("fs").readFileSync("/dev/stdin","utf-8").split("\n");ls.length--

(function (){

var cx = 0;
for (var i=1; i<ls.length; ++i) {
  n = +ls[i].split(" ")[1];
  if (ls[i][0] == "(") cx += n;
  else cx -= n;
  if (cx < 0) {
    print("NO");
    return;
  }
}
print(cx == 0 ? "YES" : "NO");
return;

})();

Measured memory_bytes: 8704
/*author : Yashvardhan
Saturday, January 12, 2019
*/
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << 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 debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int dp[100005];

int pow(int a, int b, int m)
{
	int ans = 1;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int n,k;
	cin>>n>>k;

	int hs[n+1];
	for(int i = 1; i <= n ; i++){
		cin>>hs[i];
	}
	dp[1] = 0;
	dp[2] = abs(hs[2]-hs[1]);

	
	for(int i = 3; i <= n ; i++){
		int count = 0;
		int j = 0; 
		int tempi = 1;
		int val = i - k;
		j = max(tempi,val);
		int minil = inf;
		while(j<i){
			minil = min(minil,(dp[j]+abs(hs[j]-hs[i])));
			j++;
		}
		dp[i] = minil;
	}
	cout<<dp[n]<<endl;
	

	t2 = clock();
	cerr<<endl<<t2-t1<<endl;
	
	return 0;
}



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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    vvi a(3,vi(3));
    rep(i,3)rep(j,3)cin>>a[i][j];
    int n;
    cin>>n;
    vi b(n);
    rep(i,n)cin>>b[i];

    rep(i,n){
        rep(j,3){
            rep(k,3){
                if(b[i]==a[j][k]){
                    a[j][k]=0;
                }
            }
        }
    }

    rep(i,3){
        rep(j,3){
            if(a[i][j])break;
            if(j==2){
                cout<<"Yes\n";
                return 0;
            }
        }
    }

    rep(i,3){
        rep(j,3){
            if(a[j][i])break;
            if(j==2){
                cout<<"Yes\n";
                return 0;
            }
        }
    }

    rep(i,3){
        if(a[i][i])break;
        if(i==2){
            cout<<"Yes\n";
            return 0;
        }
    }

    rep(i,3){
        if(a[2-i][i])break;
        if(i==2){
            cout<<"Yes\n";
            return 0;
        }
    }

    cout<<"No\n";

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
int w[N];

signed main() {
    IOS;
    #ifdef LOCAL
        freopen("input.txt","r", stdin);
        freopen("output.txt","w",stdout);
    #endif
    int n, s = 0;  cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> w[i], s += w[i];
    int p = s, t = 0;
    for(int i = 1; i <= n; i++){
        t += w[i];  s -= w[i];
        p = min(p, abs(s-t));
    }   
    cout << p;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
template<typename T> void read(T &num){
	char c=getchar();T f=1;num=0;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+(c^48);c=getchar();}
	num*=f;
}
template<typename T> void qwq(T x){
	if(x>9)qwq(x/10);
	putchar(x%10+'0');
}
template<typename T> void write(T x){
	if(x<0){x=-x;putchar('-');}
	qwq(x);putchar('\n');
}
int num[10][10];int co[200010][2];
inline void scz(int x){
	int y=x;int n1=0;int n2=y%10;
	while(y){n1=y%10;y/=10;}
	num[n1][n2]++;co[x][0]=n1;co[x][1]=n2;
	return;
}

int main(){
	int n;read(n);
	rep(i,1,n)scz(i);
	
	long long ans=0;
	rep(i,1,n)ans+=num[co[i][1]][co[i][0]];
	write(ans);
	return 0;
}


Measured memory_bytes: 1792
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.map f

[<EntryPoint>]
let main argv =
    let xs = reads int
    Array.sort xs
    |> fun x -> x.[0] + x.[1]
    |> printfn "%i"
    0

Measured memory_bytes: 14812
using System;

public class Hello 
{
    public static void Main() 
    {
    
        int [] All = new int [9];
        
        for(int i=0; i<3; i++)
        {
            string[] a = Console.ReadLine().Split(' ');
            
            for(int j =0; j<3; j++ )
            {
                  All[i*3+j] = int.Parse(a[j]); 
            }
        }
        
        int N = int.Parse(Console.ReadLine());
        
        for(int k=0; k<N; k++)
        {
            int get =int.Parse(Console.ReadLine());
       
            for(int l = 0; l<9; l++)
            {
                if(get == All[l])
                {
               //           System.Console.WriteLine(l);
                    All[l] = 0; //フラグ
                }
            }
        }
    
        for(int m=0; m<3; m++)
        {
            int P = 0;
            int Q = 0;
              
            for(int n=0; n<3; n++)
            {
                P += All[m*3+n]; //横
                Q += All[m+n*3]; //縦
              //   System.Console.WriteLine(P);
            }
            if(P==0 || Q ==0)
            {
                 System.Console.WriteLine("Yes");
                 return;
            }
        }
        
        if(All[0] + All[4] + All[8] ==0 ||
             All[2] + All[4] + All[6] ==0)
        {
             System.Console.WriteLine("Yes");
             return;
        }

        System.Console.WriteLine("No");
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int inf = 1e9;

int cnt_digits(ll X){
	int cnt=0;
	while(X>0){
		X/=10;
		cnt++;
	}
	return cnt;
}

int main() {
	ll N;
	cin>>N;
	int ans=cnt_digits(N);
	rep1(A,1e5+1){
		if(N%A==0){
			ll B=N/A;
			int C=max(cnt_digits(A),cnt_digits(B));
			ans=min(ans,C);
		}
	}
	cout<<ans<<endl;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

//ミス

int main()
{
    int d, n;
    cin >> d >> n;
    int ans = 101;
    if (d == 0)
    {
        if (n != 100)
            ans = n;
    }
    else
    {
        if (n != 100)
            ans = pow(100, d) * n;
        else
        {
            ans *= pow(100, d);
        }
    }

    OP(ans);
    return 0;
}

Measured memory_bytes: 384
#include<cstdio>

int main(){
    char s[3];
    for(int i=0;i<3;i++) scanf("%c", &s[i]);
    int ans = 0;
    int an = 0;
    for(int i=0;i<3;i++){
        if(s[i] == 'R') ans++;
        else ans = 0;

        if(ans > an) an = ans;
    }
    printf("%d", an);
    return 0;
}

Measured memory_bytes: 1668
#include<iostream>
using namespace std;
int main()
{
	int k,ans=0;
	long long k1,n;
	cin>>n>>k;
	k1=1;
	while(1)
	{
		if(n<=k1-1) break;
		k1=k1*k;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int a[4], b[4];
	int hit, blow;
	while (cin >> a[0] >> a[1] >> a[2] >> a[3]) {
		cin >> b[0] >> b[1] >> b[2] >> b[3];
		hit = blow = 0;
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 4; j++) {
				if (b[i] == a[j]) {
					if (i == j)
						hit++;
					else
						blow++;
				}
			}
		}
		cout << hit << " " << blow << endl;
	}
	return 0;
}

Measured memory_bytes: 1160