akhauriyash/Code-Regression huggingface dataset:
//迷路探索(幅優先探索)
char go, stop, Goal, Start;
int memo2 = -1;
int stx, sty, gox, goy;
int check(int x, int y, int memo, int n, int m);
char map[1000][1000];
//すでに進んだ場所
int not_map[1000][1000] = {};
//そこに行くまで何ターンかかるか
int turn[1000][1000] = {};
//次に調べる座標を入れておく
int task[1000000][2] = {};
//探索開始
int start(int n, int m) {
	int memo = 0;
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			if (map[j][i] == Start) {
				turn[j][i] = 0;
				not_map[j][i] = 1;
				if (j != 1) { turn[j - 1][i] = 1; }
				if (j != n) { turn[j + 1][i] = 1; }
				if (i != 1) { turn[j][i - 1] = 1; }
				if (i != m) { turn[j][i + 1] = 1; }
				return check(j, i, memo, n, m);
			}
		}
	}
}

//迷路ターン処理
int map_turn(int x, int y, int n, int m) {
	if (x != 1 && turn[x - 1][y] == 0) { turn[x - 1][y] = turn[x][y] + 1; }
	if (x != n && turn[x + 1][y] == 0) { turn[x + 1][y] = turn[x][y] + 1; }
	if (y != 1 && turn[x][y - 1] == 0) { turn[x][y - 1] = turn[x][y] + 1; }
	if (y != m && turn[x][y + 1] == 0) { turn[x][y + 1] = turn[x][y] + 1; }
}

//迷路進めるかの判定
int check(int x, int y, int memo, int n, int m) {

	if (map[x][y] == Goal) { return turn[x][y]; }
	if (map[x][y] == stop) {
		memo2++;
		return -1;
	}
	map_turn(x, y, n, m);


	if (x != 1 && map[x - 1][y] != stop && not_map[x - 1][y] != 1) {
		task[memo][0] = x - 1;
		task[memo][1] = y;
		memo++;
		not_map[x - 1][y] = 1;
	}
	if (x != n && map[x + 1][y] != stop && not_map[x + 1][y] != 1) {
		task[memo][0] = x + 1;
		task[memo][1] = y;
		memo++;
		not_map[x + 1][y] = 1;
	}
	if (y != 1 && map[x][y - 1] != stop && not_map[x][y - 1] != 1) {
		task[memo][0] = x;
		task[memo][1] = y - 1;
		memo++;
		not_map[x][y - 1] = 1;
	}
	if (y != m && map[x][y + 1] != stop && not_map[x][y + 1] != 1) {
		task[memo][0] = x;
		task[memo][1] = y + 1;
		memo++;
		not_map[x][y + 1] = 1;
	}
	memo2++;
	if(memo2==memo){return -1;}
	return check(task[memo2][0], task[memo2][1], memo, n, m);
}
//mainの例
int main() {
	int n, m,result=0,tmp;
	go = '.';
	stop = '#';
	Start = 'S';
	Goal = 'G';
	scanf("%d%d", &m, &n);
	gox = n;
	goy = m;
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			scanf(" %c", &map[j][i]);
			if (map[j][i] == '.')result++;
		}
	}
	map[1][1] = 'S';
	map[gox][goy] = 'G';
  tmp=start(n, m);
  	if(tmp==-1){printf("-1");return 0;}
	printf("%d\n", result-tmp-1);
}

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

const int N=503;
int c[N], s[N], f[N];

int main(){

    int n;
    scanf("%d", &n);
    for(int i=0; i<n-1; ++i){
        scanf("%d%d%d", c+i, s+i, f+i);
    }

    int time=0;
    for(int i=0; i<n-1; ++i){
        time=s[i]+c[i];
        for(int j=i+1; j<n-1; ++j){
            if(s[j]>=time){
                time=s[j];
            }
            else{
                int num=(((time-s[j])-1)/f[j])+1;
                time=(num*f[j])+s[j];
            }
            time+=c[j];
        }
        printf("%d\n", time);
    }
    puts("0");






    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), r[] = new int[4001], g[] = new int[4001], b[] = new int[4001], rn = 0, gn = 0, bn = 0;
        long ans = 0;
        char[] s = in.next().toCharArray();
        for (int i = 0; i < n; i++) {
            if (s[i] == 'R') {
                r[rn++] = i;
            } else if (s[i] == 'G') {
                g[gn++] = i;
            } else {
                b[bn++] = i;
            }
        }
        for (int i = 0; i < rn; i++) {
            for (int j = 0; j < gn; j++) {
                int max = Math.max(r[i], g[j]);
                int min = Math.min(r[i], g[j]);
                int x = max - min, a = bn;
                if (x + max < n && s[x + max] == 'B')
                    a--;
                if (min - x >= 0 && s[min - x] == 'B')
                    a--;
                if ((min + max) % 2 == 0 && s[(min + max) / 2] == 'B')
                    a--;
                ans += (long) a;
            }
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 28240
import sys

import numpy as np

readline = sys.stdin.buffer.readline

A, B, M = map(int, readline().split())

a = np.array(list(map(int, readline().split())))
b = np.array(list(map(int, readline().split())))

XYC = [list(map(int, readline().split())) for _ in range(M)]

m = np.min(a) + np.min(b)

for x, y, c in XYC:
    x -= 1
    y -= 1
    s_c = a[x] + b[y] - c
    if s_c < m:
        m = s_c

print(m)


Measured memory_bytes: 41064
M, D = map(int, input().split())

D1 = D % 10
D10 = D // 10

ans = 0
for month in range(1, M+1):
    for day in range(1, D+1):
        d1 = day % 10
        d10 = day // 10
        if d1 >= 2 and d10 >= 2 and d1*d10 == month:
            ans += 1

print(ans)

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

using namespace std;

#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define double long double
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define deb(x) cout << x << endl
#define done(x) {cout << x << endl;return;}
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 998244353;
//const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;


const int N = 2e6+5;


void solve() {

  int a,b,x,y;
  cin>>a>>b>>x>>y;
  vvi dp(x+1,vi(y+1,0));
  dp[a][b]=1;
  fr(r,a,x){
    fr(c,b,y){
      if(r==a&&c==b)
        continue;
      int p=dp[r-1][c],q=dp[r][c-1], s=dp[r-1][c-1];
      dp[r][c]=p*(c-1)+q*(r-1)-(c-1)*(r-1)%mod*s;
      dp[r][c]=((dp[r][c]+p+q)%mod+mod)%mod;
    }
  }
  cout<<dp[x][y];

}


signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout << fixed << setprecision(15);
    int t = 1;
   //cin >> t;

    while (t--)
        solve();
#ifdef aa
    cout << endl << endl << endl << endl << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}



int powm(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)
            res = (res*a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}

int divide(int a, int b) {
    return (a % mod) * powm(b, mod - 2) % mod;
}

int norm(int a) {
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}


int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}


Measured memory_bytes: 73700
#include<iostream>
#define MAXN 1000000+20 
using namespace std;
int n,a[MAXN],t[MAXN];
int tot;

void msort(int l,int r){
	if (l < r-1){
		int mid=l+(r-l)/2;
		int now=l;
		int p=l,q=mid;
		
		msort(l,mid);
		msort(mid,r);
		
		while (p < mid || q < r){
			tot++;
			if (p < mid && a[p] < a[q] || q == r) {
				t[now++]=a[p++];
			}
			else t[now++]=a[q++];
		}
		for (int i = l;i < now;++i)
			a[i]=t[i];
	}
}

int main(){
	int i;
	cin>>n;
	for (i = 0;i < n;++i){
		cin>>a[i];
	}
	
	msort(0,n);
	
	for (i = 0;i < n;++i){
		if (i) cout<<" ";
		cout<<a[i];
	}
	
	cout<<endl;
	cout<<tot<<endl;
	return 0;
}

Measured memory_bytes: 6984
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    for(int i = 0; i < m; i++){
        cin >> x[i];
    }
    sort(x.begin(), x.end());
    vector<int> ab(m-1);
    for(int i = 0; i < m-1; i++){
        ab[i] = abs(x[i] - x[i+1]);
    }

    sort(ab.begin(), ab.end());
    int sum = 0;
    for(int i = 0; i < m-1-n+1; i++){
        sum += ab[i];
    }
    cout << sum << endl;

    
}

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

static const int ra =1000;

int lcs(string A, string B){
  int ca[ra+1][ra+1];
  int mi =A.size();
  int ni = B.size();
  int most = 0;

  A = ' ' + A;
  B = ' '+B;

  for(int i=1;i<=mi;i++){
    ca[i][0]=0;
  }
  for(int j=0;j<=ni;j++){
    ca[0][j] = 0;
  }

  for(int i =1;i<=mi;i++){
    for(int j=1;j<=ni;j++){
      if(A[i] == B[j]){
	ca[i][j] = ca[i-1][j-1]+1;
      }
      else{
	ca[i][j] = max(ca[i-1][j],ca[i][j-1]);
      }
      most = max(most,ca[i][j]);
    }
  }
  return most;
}

int main(){
  string K1,K2;
  int num,i;
  cin >>num ;
  for(i=0;i<num;i++){
    cin >> K1 >> K2;
    cout << lcs(K1,K2) << endl;
  }
  return 0;
}



Measured memory_bytes: 6956
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 21, P = 1e9 + 7;
int n, m, k, ans;
int go[1 << N][N], put[1 << N], dp[1 << N], need1[N * N], need2[N * N];
int main() {
	scanf("%d%d%d", &n, &m, &k);
	while(k--) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		--a;
		--b;
		need1[a] |= (1 << b);
		need2[a] |= (1 << b) * c;
	}
	--n;
	memset(go, -1, sizeof(go));
	memset(put, -1, sizeof(put));
	dp[0] = 1;
	for(int i = 0; i < (1 << n); ++i) {
		int id = 0;
		for(int j = 0; j < n; ++j) {
			if(i & (1 << j)) {
				if(j && !(i & (1 << (j - 1)))) {
					go[i][id] = i ^ (1 << j) ^ (1 << (j - 1));	
				}
				++id;
			}
		}
		for(int j =  n - 1; j >= 0; --j) {
			if(!(i & (1 << j))) {
				put[i] = i ^ (1 << j);
				break;
			}
		}
	}
	for(int t = 0; t < m; ++t) {
		for(int i = 0; i < (1 << n) - 1; ++i) {
			if(put[i] != -1) {
				dp[put[i]] = (dp[put[i]] + dp[i]) % P;
//				printf("%d -> %d\n", i, put[i]);
			}
		}
		for(int j = 0; j < n; ++j) {
			for(int i = (1 << n) - 1; i >= 0; --i) {	
				if(go[i][j] != -1) {
//					printf("%d -> %d\n", i, go[i][j]);
					dp[go[i][j]] = (dp[go[i][j]] + dp[i]) % P;
				}
			}
		}
		for(int i = 0; i < (1 << n); ++i) {
			if((i & need1[t]) != need2[t]) {
				dp[i] = 0;
			}
		}
	}
	for(int i = 0; i < (1 << n); ++i) {
		ans = (ans + dp[i]) % P;
	}
	printf("%d\n", ans);
	return 0;
}

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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

int H, W;
int main() {
    std::cin >> H >> W;
    REP(i, H) {
        std::string str;
        std::cin >> str;
        std::cout << str << std::endl;
        std::cout << str << std::endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);

    		int a=sc.nextInt();
    		int b=sc.nextInt();
    		int c=sc.nextInt();
    		int y=0;

    		for(int x=a;x<=b;x++){
    			if(c%x==0){
    			y++;
    		}
    		}
    		System.out.println(y);
    		}
    		}
    		


Measured memory_bytes: 26356
def gcd(a,b):
  if b==0:
    return a
  return gcd(b, a%b)

A,B,C,D = map(int, input().split())
if C > D:
  g = gcd(C,D)
else:
  g = gcd(D,C)
g = int(C*D/g)
ac = (A-1) // C
bc = B // C
ad = (A-1) // D
bd = B // D
ag = (A-1) // g
bg = B // g
print(int(B-A+1 -(bc-ac) -(bd-ad) +(bg-ag)) )


Measured memory_bytes: 3064
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <numeric>
#include <random>
#include <vector>
#include <chrono>
#include <fstream>

using namespace std;

#define LOCAL 1

#if LOCAL
#define pv(val) cerr << #val << '=' << (val) << endl
#define pvn(name, val) cerr << name << '=' << (val) << endl
#define pl cerr << '@' << __LINE__ << endl
#else
#define pv(val)
#define pvn(name, val)
#define pl
#endif

template <class T>
ostream &operator<<(ostream &os, vector<T> const &vec)
{
    if (vec.empty())
    {
        os << "{}";
    }
    else
    {
        os << '{';
        for (size_t i = 0; i < vec.size() - 1; i++)
            os << vec[i] << ", ";
        os << vec.back() << '}';
    }
    return os;
}

template <class T, size_t S>
ostream &operator<<(ostream &os, array<T, S> const &arr)
{
    if (arr.empty())
    {
        os << "{}";
    }
    else
    {
        os << '{';
        for (size_t i = 0; i < arr.size() - 1; i++)
            os << arr[i] << ", ";
        os << arr.back() << '}';
    }
    return os;
}

uint64_t hoge(uint64_t a)
{
    uint64_t ans = 0;
    while (a > 0)
        ans += a--;
    return ans;
}

int main(void)
{
    int N;
    cin >> N;
    vector<string> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];

    uint64_t ans = 0;
    for(int i = 0; i < N; i++){
        for(int y = 0; y < N; y++){
            for(int x = 0; x < N; x++){
                if(A[y][(x + i) % N] != A[x][(y + i) % N]) goto FAILED;
            }
        }
        ans += N;

        FAILED:;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
	
	int n,a[100001],b[100001],min=1000000001,max=-1,min2=1000000001,max2=-1;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		if(max<a[i])max=a[i];
		if(min>a[i])min=a[i];
		if(max2<b[i])max2=b[i];
		if(min2>b[i])min2=b[i];
	}
	cout<<max-min+1+min-1+min2<<endl;
	
	return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.regex.Pattern;

public class Main {
    public void exec(Stdin stdin, PrintWriter stdout) {
        int[] x = stdin.nextIntArray(5);
        for (int i = 0; i < 5; i++) {
            if (x[i] == 0) {
                stdout.println(i+1);
                return;
            }
        }
    }

    public static void main(String[] args) {
        Stdin stdin = new Stdin();
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().exec(stdin, stdout);
        stdout.flush();
    }


    public static class Stdin {
        private BufferedReader stdin;
        private Deque<String> tokens;
        private Pattern delim;

        public Stdin() {
            stdin = new BufferedReader(new InputStreamReader(System.in));
            tokens = new ArrayDeque<>();
            delim = Pattern.compile(" ");
        }

        public String nextString() {
            try {
                if (tokens.isEmpty()) {
                    String line = stdin.readLine();
                    delim.splitAsStream(line).forEach(tokens::addLast);
                }
                return tokens.pollFirst();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

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

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }
    }
}


Measured memory_bytes: 33868
N = int(input())

dp_a = [0]*(N+1)#[i]にi日目の幸福度
dp_b = [0]*(N+1)
dp_c = [0]*(N+1)

for i in range(N):
    a, b, c = map(int,input().split())#i+1日目の幸福度
    dp_a[i+1] = max(dp_b[i],dp_c[i]) + a
    dp_b[i+1] = max(dp_c[i],dp_a[i]) + b
    dp_c[i+1] = max(dp_a[i],dp_b[i]) + c

print(max(dp_a[-1],dp_b[-1],dp_c[-1]))




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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void solve() {
  int n, a;
  cin >> n >> a;
  cout << n * n - a << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


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

int main(){
  int S;
  cin >> S;
  const int64_t mod=1e9+7;
  vector<int64_t> dp(S+1,0);
  dp.at(0)=1;
  for(int i=1;i<=S;i++){
    for(int j=0;j<=i-3;j++){
      dp.at(i)+=dp.at(j);
      dp.at(i)%=mod;
    }
  }
  cout << dp.at(S) << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
 
int main() {

    char c;

    while (true)
    {
        scanf("%c", &c);

        if ('a'<=c && c<='z')
        {
            printf("%c", c-32);
        }
        else if('A'<=c && c<='Z')
        {
            printf("%c", c+32);
        }
        else if(c == '\n')
        {
            putchar('\n');
            break;
        }
        else
            printf("%c", c);
    }
    
    return 0;
}


Measured memory_bytes: 2620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    string s;
    cin >> s;
    int n = sz(s);
    for (int i = 0; i < n; i += 2) {
        if (s[i] == 'h' && s[i + 1] == 'i') continue;
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
import sys
n, l = map(int, input().split())
a = [int(x) for x in input().split()]

key = -1
for i in range(n-1):
  if a[i]+a[i+1] >= l:
    key = i
    break

if key == -1:
  print("Impossible")
else:
  print("Possible")
  for i in range(key):
    print(i+1)
  for i in range(n-1, key, -1):
    print(i)

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

using namespace std;

int main() {
  vector<int> v;
  int n;
  int m;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> m;
    v.push_back(m);
  }

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

  int s = n/2;
  cout << v[s] - v[s-1] << endl;

  return 0;
}


Measured memory_bytes: 892
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007

//qsort用、昇順
int compare_int(const void *a, const void *b)
{
	return *(int*)a-*(int*)b;
}
//qsort(data, 10, sizeof(int), compare_int)

char s[200100], t[200100];

int main(){
	scanf("%s%s", s, t);
	int len = strlen(s), count=0;
	for(int i=0; i<len; i++){
		if(s[i] != t[i]) count++;
	}
	printf("%d\n", count);
	
	return 0;
}


Measured memory_bytes: 2072
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

const int mod = 998244353;

vector<int> X[100009];
int N, K, A[100009], B[100009];
long long dp[100009][309][2], dp2[100009][309], sz[100009];

void dfs(int pos) {
	sz[pos] = 1;

	vector<int>Y;
	for (int i = 0; i < X[pos].size(); i++) {
		if (sz[X[pos][i]] != 0) continue;
		Y.push_back(X[pos][i]);
		dfs(X[pos][i]);
		sz[pos] += sz[X[pos][i]];
	}

	vector<pair<int, int>> A;
	for (int i = 0; i < Y.size(); i++) A.push_back(make_pair(sz[Y[i]], Y[i]));
	sort(A.begin(), A.end());

	Y.clear();
	for (int i = 0; i < A.size(); i++) Y.push_back(A[i].second);

	// 含まない場合
	for (int i = 0; i <= Y.size(); i++) {
		for (int j = 0; j <= K; j++) dp2[i][j] = 0;
	}

	int S = 0; dp2[0][0] = 1;
	for (int i = 0; i < Y.size(); i++) {
		for (int j = 0; j <= S; j++) {
			for (int k = 0; k <= min(K, (int)sz[Y[i]]); k++) {
				if (j + k + 1 <= K) {
					dp2[i + 1][j + k + 1] += dp2[i][j] * dp[Y[i]][k][1];
					dp2[i + 1][j + k + 1] %= mod;
				}
				if (j + k <= K) {
					dp2[i + 1][j + k] += dp2[i][j] * dp[Y[i]][k][0];
					dp2[i + 1][j + k] %= mod;
				}
			}
		}
		S += sz[Y[i]]; S = min(S, K);
	}
	for (int i = 0; i <= K; i++) dp[pos][i][0] = dp2[Y.size()][i];

	// 含む場合
	for (int i = 0; i <= Y.size(); i++) {
		for (int j = 0; j <= K; j++) dp2[i][j] = 0;
	}

	S = 0; dp2[0][0] = 1;
	for (int i = 0; i < Y.size(); i++) {
		for (int j = 0; j <= S; j++) {
			for (int k = 0; k <= min(K, (int)sz[Y[i]]); k++) {
				if (j + k + 1 <= K) {
					dp2[i + 1][j + k + 1] += dp2[i][j] * dp[Y[i]][k][1];
					dp2[i + 1][j + k + 1] %= mod;
				}
				if (j + k <= K) {
					dp2[i + 1][j + k] += dp2[i][j] * dp[Y[i]][k][1];
					dp2[i + 1][j + k] %= mod;
				}
				if (j + k <= K) {
					dp2[i + 1][j + k] += dp2[i][j] * dp[Y[i]][k][0];
					dp2[i + 1][j + k] %= mod;
				}
			}
		}
		S += sz[Y[i]]; S = min(S, K);
	}
	for (int i = 0; i <= K; i++) dp[pos][i][1] = dp2[Y.size()][i];
}

int main() {
	scanf("%d%d", &N, &K);
	for (int i = 1; i <= N - 1; i++) {
		scanf("%d%d", &A[i], &B[i]);
		X[A[i]].push_back(B[i]);
		X[B[i]].push_back(A[i]);
	}
	dfs(1);
	cout << (dp[1][K][0] + dp[1][K - 1][1]) % mod << endl;
	return 0;
}


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

using namespace std;

int main()
{
    int x[3];
    scanf("%d %d %d", &x[0], &x[1], &x[2]);
    sort(x, x + 3);

    printf("%d\n", x[2] * 10 + x[1] + x[0]);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

int main(void){
  int n;
  cin >> n;
  vector<double> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];

  sort(v.begin(), v.end());
  for (int i = 0; i < n - 1; i++){
    v[1] = (v[0] + v[1])/2;
    v[0] = 10000000;
    sort(v.begin(), v.end());
  }

  printf("%.10lf\n", v[0]);

  return 0;
}


ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


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


int main() {
  int a;
  cin >> a;
  cout << a+a*a+a*a*a << endl;
  return 0;
}

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

int gcd(int a,int b) {
  return (b? gcd(b,a%b):a);
}
    
int main() {
  int n;
  cin>>n;
  int a[100005];
  for (int i=0; i<n; i++) {
    cin>>a[i];
  }
  int g=a[0];
  for (int i=1; i<n; i++) {
    g=gcd(g,a[i]);
  }
  cout<<g<<endl;
  return 0;
}

Measured memory_bytes: 640
import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args)throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String line = br.readLine();
        String[] temp = line.split("\\s");
        br.close();

        int num1 = Integer.parseInt(temp[0]);
        int num2 = Integer.parseInt(temp[1]);
        int num3 = Integer.parseInt(temp[2]);
        int count = 0;

        ArrayList<Integer> yakusu = new ArrayList<Integer>();

        for(int i=1;i<=num3;i++){
            if(num3 % i == 0){
                yakusu.add(i);
            }                        
        }

        for(int i=num1;i<=num2;i++){
            int j = yakusu.indexOf(i);
            if(j != -1){
                count++;
            }
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 25120
n,y = map(int,input().split())
man, gosen, sen =-1,-1,-1
for i in range(n+1):
    for j in range(n+1-i):
        if 1e+4*i+5e+3*j+1e+3*(n-i-j)==y:
            man, gosen, sen = i, j, n-i-j
            break
print(man, gosen, sen)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <atcoder/all>
#define F first
#define S second
using namespace std;
using namespace atcoder;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
typedef pair<int, int> P;
const ll Mod = 1000000007;
int main() {
  string ans = "";
  int K;
  cin >> K;
  for (int i = 0; i < K; i++) {
    ans += "ACL";
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
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 <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
int MOD = 10000000;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 105;
const int MM = 1000000007;

int v[MX][MX], D[MX][MX];
pii E[MX][MX];

int main()
{
	int A, B;
	scanf("%d%d", &A, &B);
	for(int i = 1; i <= A; i++){
		for(int j = 1; j <= B; j++){
			scanf("%d", D[i]+j);
			E[i][j] = pii(-1, -1);
		}
	}
	for(int kk = 100; kk >= 0; kk--){
		for(int l = kk; l >= 0; l--){
			int k = kk - l;
			int mx = 0;
			for(int x = 1; x <= A; x++){
				for(int y = 1; y <= B; y++){
					mx = max(mx, D[x][y] - x*k - y*l);
				}
			}
			v[k][l] = mx;
			for(int x = 1; x <= A; x++){
				for(int y = 1; y <= B; y++){
					if( mx == D[x][y] - x*k - y*l) E[x][y] = pii(k, l);
				}
			}
		}
	}
	vector<t3> L;
	map<pii, int> V;
	for(int i = 1; i <= A; i++){
		for(int j = 1; j <= B; j++){
			int a = E[i][j].first, b = E[i][j].second;
			if( a == -1 ) return !printf("Impossible\n");
			L.emplace_back(a, b, v[a][b]);
		}
	}
	sort(L.begin(), L.end());
	L.erase(unique(L.begin(), L.end()), L.end());

	int mx = 0, cur = 1;
	for(t3 c : L) mx = max(mx, get<0>(c));
	vector<t3> G;
	V[pii(0, 0)] = 1;
	for(int i = 1; i <= mx; i++){
		G.emplace_back(cur, cur+1, -1);
		cur += 1;
		V[pii(i, 0)] = cur;
	}
	for(int i = 0; i <= mx; i++){
		int mx2 = 0, prv = i+1;
		for(t3 c : L){
			if( get<0>(c) == i ) mx2 = max(mx2, get<1>(c));
		}
		for(int j = 1; j <= mx2; j++){
			G.emplace_back(prv, ++cur, -2);
			V[pii(i, j)] = cur;
			prv = cur;
		}
	}
	for(t3 e : L){
		int a, b, c;
		tie(a, b, c) = e;
		G.emplace_back(V[pii(a, b)], cur+1, c);
	}
	printf("Possible\n");
	printf("%d %d\n", cur+1, G.size());
	for(t3 e : G){
		int a, b, c;
		tie(a, b, c) = e;
		printf("%d %d ", a, b);
		if( c == -1 ) printf("X\n");
		else if( c == -2 ) printf("Y\n");
		else printf("%d\n", c);
	}
	printf("1 %d\n", cur+1);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n[200];
    int n_cnt,output=-1;
    int i;
    int flag=0;

    scanf("%d",&n_cnt);
    for(i=0;i<n_cnt;i++)
        scanf("%d",&n[i]);

    while(!flag)
    {
        output++;
        for(i=0;i<n_cnt;i++)
        {
            if(n[i]%2==0)
                n[i]/=2;
            else
            {
                flag=1;
                break;
            }
            
        }
    }

    printf("%d",output);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
        	int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            while(!(a <= b && b <= c)){ //ソートできるまでやる
            	if(a > b) {
            		a = a ^ b;
            		b = a ^ b;
            		a = a ^ b; //aとb入れ替え
            	}
            	if(b > c) {
            		b = b ^ c;
            		c = b ^ c;
            		b = b ^ c; //bとc入れ替え
            	}
            }
            System.out.println(String.format("%d %d %d", a, b, c));
        }
    }
}



Measured memory_bytes: 26184
#include <iostream>
#include <vector>

using namespace std;

bool LinearSerach(vector<int> &S,int &key)
{
	for(int i=0; i<S.size(); i++){
		if(S[i] == key)return true;
	}
	return false;
} 

int main()
{
	int n,q;
	vector<int> S;
	
	cin >> n;
	for(int i=0; i<n; i++){
		int j;
		cin >> j;
		S.push_back(j);
	}
	cin >> q;
	int count = 0;
	for(int i=0; i<q;i++){
		int key;
		cin >> key;
		if(LinearSerach(S,key))count++;
	}
	cout << count << endl;
}

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

const int N = 100001;
int q,l,r;
bool prime[N];
int like[N];

void eratosthenes(bool prime[N]) {
    for (size_t i = 2; i < N; i++)
    {
        prime[i] = 1;
    }
    prime[0] = prime[1] = 0;
    for (size_t i = 2; i < N; i++)
    {
        if (prime[i]) {
            for (int j = i + i; j < N; j += i) {
                prime[j] = 0;
            }
        }
    }
}

int main()
{
    eratosthenes(prime);
    like[1] = 0;
    for (size_t i = 2; i < N; i++)
    {
        if (i % 2 == 0)
        {
            like[i] = like[i - 1];
        }
        else {
            like[i] = like[i - 1] + prime[i] * prime[(i + 1) / 2];
        }
    }
    cin >> q;
	for (size_t i = 0; i < q; i++)
	{
		cin >> l >> r;
        cout << like[r] - like[l - 1] << endl;
	}
	
}

Measured memory_bytes: 1784
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 03/22/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int N; cin>>N;
  vector<int> A(N);
  vector<int> cnt(N+1);
  for (int i = 0; i < N; i++) {
    cin>>A[i];
    cnt[A[i]]++;
  }
  ll all = 0;
  for (ll c : cnt) {
    all += c*(c-1)/2;
  }

  for (auto a : A) {
    cout << all-(cnt[a]-1) << endl;
  }

  return 0;
}


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

int main() {
 
  string w;
  cin >> w;
  int N = w.size();
  sort(w.begin(), w.end());
  
  if(w.size() == 1){
    cout << "No" << endl;
  }
  
  int cnt = 1;
  for(int i = 1; i < N; i++){
    if(w.at(i - 1) == w.at(i)){
      cnt++;
      if(i == N - 1){
        if(cnt % 2 == 0){
          cout << "Yes" << endl;
        }
        else{
          cout << "No" << endl;
        }
      }
    }
    
    else{
      if(cnt % 2 == 0){
        cnt = 1;
        continue;
      }
      else{
        cout << "No" << endl;
        break;
      }
    }
  }
}


Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    S = [SS() for _ in range(N)]

    cnt = collections.Counter([i[0] for i in S])
    # print(cnt)
    ans = 0
    for i, j, k in itertools.combinations(('M', 'A', 'R', 'C', 'H'), 3):
        ans += cnt[i] * cnt[j] * cnt[k]

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 17604
(let ((a (read))
    (b (read))
    (ans "Impossible"))

    (if (zerop (rem a 3))
        (setq ans "Possible")
        (if (zerop (rem b 3))
            (setq ans "Possible")
            (if (zerop (rem (+ a b) 3))
                (setq ans "Possible"))
        )
    )
    (princ ans)
)

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int N;
int bit[1000100];
void ini(){
  for(int i=0;i<1000010;i++) bit[i]=0;
  return;
}
void add(int a, int w) {
   for (int x = a; x <= N; x += x & -x) bit[x] += w;
}
int sum(int a) {
int ret = 0;
for(int x = a; x > 0; x -= x & -x) ret += bit[x];
return ret;
}
struct aaa{
  int num;
  int t;
  bool operator<(const struct aaa & right) const{
    return (t==right.t?num<right.num:t<right.t);
  }
};

int main(){
  LL n;
  cin >> n;
  N=n;
  vector<int> a(n),b(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
    b[i]=a[i];
  }
  if(n==1){
    cout << a[0] << endl;
    return 0;
  }
  sort(b.begin(),b.end());
  vector<struct aaa> x(n+1);
  vector<int> topos(n+1);
  vector<struct aaa>::iterator itr;
  struct aaa aa;
  LL count;
  int l=0,r=n,mid;
  while(r-l>1){
    mid=(l+r)/2;
    // cout <<mid << ":"<< b[mid] << endl;
    x[0]={0,0};
    for(int i=0;i<n;i++){
      if(a[i]<=b[mid]) x[i+1]={i+1,1};
      else x[i+1]={i+1,-1};
      x[i+1].t+=x[i].t;
    }
    sort(x.begin(),x.end());
    count=0;
    for(int i=0;i<=n;i++){
      topos[x[i].num]=i;
      // cout << x[i].t << " ";
    }
    // cout << endl;
    // for(int i=0;i<=n;i++){
    //   cout << x[i].num << " ";
    // }
    // cout <<endl;
    ini();
    for(int i=0;i<=n;i++){
      // cout << x[topos[i]].t << endl;
      aa={-1,x[topos[i]].t};
      itr=lower_bound(x.begin(),x.end(),aa);
      if(itr!=x.begin()){
        itr--;
        count+=sum(distance(x.begin(),itr)+1);
      }
      // cout << sum(distance(x.begin(),itr)+1) << " ";
      add(topos[i]+1,1);
    }
    // cout << endl;
    // cout << count << endl;
    // cout <<n*(n+1)/4 << endl;
    if(count>n*(n+1)/4){
      r=mid;
    }else{
      l=mid;
    }
  }
  cout << b[l+1] << endl;
  return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using  namespace std;
int main()
{
	int n;
	cin>>n;
	char a[n];
	cin>>a;
	int v;
	if(n%2!=0){
		cout<<"No"<<"\n";
		return 0;
	}
	else if(n%2==0){
		for(int i=0;i<n/2;i++){
			if(a[i]==a[i+(n/2)]){
				v=1;
			}
			else {
				cout<<"No"<<"\n";
				return 0;
			}
		}
		if(v==1){
			cout<<"Yes"<<"\n";
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstring>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define INF = 1000000100;

int main(){
    int N;
    string S;
    cin >> N >> S;
    if(S.size()%2==1){
        cout << "No" << endl;
        return 0;
    }
    bool c= true;
    for(int i=0;i<S.size()/2;i++){
        if(S[i]!=S[S.size()/2+i]) c = false;
    }
    if(c) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            int j = digitSum(i);
            if (a <= j && j <= b) {
                sum += i;
            }
        }
        System.out.println(sum);
    }

    static int digitSum(long n) {
        int sum = 0;
        while (n != 0) {
            sum += n % 10;
            n /= 10;
        }
        return sum;
    }
}

Measured memory_bytes: 23764
#include <iostream>
 
using namespace std;
 
int main() {
    int N;
    cin >> N;
    int amari = (N % 1000);
    int waru = (N / 1000);
    int out = 0;
    if(amari ==0){
        out = 1000*(waru) - N;
    }
    else{
      out = 1000*(waru + 1) - N;
    }
  
    
 
    cout << out << endl;
}

Measured memory_bytes: 3596
/////////////////////////   _LeMur_
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

using namespace std;

const int N = 100005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

int order[N];

int main(){
    for(int i=1;i<=3;i++){
        int a , b;
        scanf("%d%d",&a,&b);
        order[a]++;
        order[b]++;
    }
    int z = 0;
    for(int i=1;i<=4;i++){
        if(order[i] % 2){
            ++z;
        }
    }
    if(z == 0 || z == 2)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}


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

using namespace std;

#define loopinc(i, a, b, inc) for(int i = a; i < (b); i += inc)
#define loop(i, a, b) for(int i = a; i < (b); i++)
#define rep(i, n) loop(i, 0, n)
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tuple<int, int, int> tii;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int main() {
	// freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;

	vi arr(n);
	rep(i, n) cin >> arr[i];

	vi dp(n);
	loop(i, 1, n) {
		int best = INT_MAX;
		loop(j, max(0, i-k), i) {
			best = min(best, abs(arr[i] - arr[j]) + dp[j]);
		}
		dp[i] = best;
	}

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


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;

using namespace std;

int main(int argc,char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll n,m;
    cin>>n>>m;
    if(abs(n-m)>=2){cout<<0<<endl;return 0;}
    else if(n-m >0 || m - n >0)
    {
        ll fact=1;
        for(ll i = 1;i < n+1;i++){fact*=i;fact%=ll(1e9+7);}
        for(ll i = 1;i < m+1;i++){fact*=i;fact%=ll(1e9+7);}
        cout<<fact<<endl;
    }
    else
    {
        ll fact=1;
        for(ll i = 1;i < n+1;i++){fact*=i;fact%=ll(1e9+7);}
        for(ll i = 1;i < m+1;i++){fact*=i;fact%=ll(1e9+7);}
        fact *=2;fact%=ll(1e9+7);
        cout<<fact<<endl;
    }

    return 0;
}

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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (b % 2 == 0) return (pow(a * a, b / 2, m) % m); else return (pow(a * a, b / 2) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};

int main(){
   ll a[3], b[3];
   ll deg[4] = {};
   REP(i, 3) {
      cin >> a[i] >> b[i];
      a[i]--; b[i]--;
      deg[a[i]]++;
      deg[b[i]]++;
   }
   sort(deg, deg + 4);
   (deg[0] == 1 && deg[1] == 1 && deg[2] == 2 && deg[3] == 2) ? cout << "YES" : cout << "NO";
   cout << endl;

}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());

		while(n-- > 0){
			char[] s = sc.nextLine().toCharArray();
			for(int i=0;i<s.length;i++) s[i] -= 'a';

			String aft = "";

			for(int a=1;aft.equals("");a++){
				if(gcd(a,26) != 1) continue;
				for(int b=0;b<26;b++){
					for(int i=0;i<s.length;i++){
						if(0<=s[i] && s[i]<26){
							aft += (char)((a * s[i] + b) % 26 + 'a');
						}
						else{
							aft += (char)(s[i] + 'a');
						}
					}

					if(aft.contains("that") || aft.contains("this")) break;
					aft = "";
				}
			}

			System.out.println(aft);
		}
	}

	private static int gcd(int a,int b){
		return b==0 ? a : gcd(b,a%b);
	}
}

Measured memory_bytes: 12000
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
		a[i]--;
	}
	vector<int> visited(n, 0);
	
	vector<int> start;
	int next = 0;
	rep(i, n + 1) {
		if (visited[next] > 0) {
			start.push_back(next);
			start.push_back(i);
			break;
		}
		visited[next]++;
		next = a[next];
	}
	
	next = start[0];
	rep(i, n) {
		if (a[next] == start[0]) {
			start.push_back(i + 1);
			break;
		}
		next = a[next];
	}

	if (k < start[1]) {
		next = 0;
		rep(i, k) {
			next = a[next];
		}
		out(next + 1);
	}
	else {
		k -= start[1];
		k = k % start[2];
		next = start[0];
		rep(i, k) {
			next = a[next];
		}
		out(next + 1);
	}

	return 0;
}

Measured memory_bytes: 4732
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
using namespace std;

int main()
{
    int a[3];
    
    cin >> a[0] >> a[1] >> a[2];
 
    sort(a, a+3);
 
    if((a[0] == 5) && (a[1] == 5) && (a[2] == 7)) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    
    return 0;
}

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

int main(){
    ll N, K;
    cin >> N >> K;
    vector<P> V(N);
    for(P &e : V) cin >> e.second >> e.first;
    sort(V.begin(), V.end());
    reverse(V.begin(), V.end());
    bool used[N + 10] = {};
    priority_queue<ll, vector<ll>, greater<ll>> q;
    ll kind = 0;
    ll ans = 0;
    for(ll i = 0; i < K; i++){
        ans += V[i].first;
        if(!used[V[i].second]){
            kind++;
            used[V[i].second] = 1;
        }else{
            q.push(V[i].first);
        }
    }
    ans += kind * kind;
    ll idx = K;
    ll pre = ans;
    while(q.size()){
        for(; idx < N; idx++) if(!used[V[idx].second]) break;
        if(idx == N) break;
        used[V[idx].second] = 1;
        pre += V[idx].first;
        pre -= q.top();
        q.pop();
        pre -= kind * kind;
        kind++;
        pre += kind * kind;
        //cout << kind << ", " << pre << endl;
        ans = max(ans, pre);
    }
    cout << ans << endl;
    return 0;
}


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

import sys

def main():
    numbers=[]
    x,n = map(int,input().split())
    numbers=list(map(int,input().split()))
    if n==0:
        print(x)
        sys.exit()
    dp_list=list(range(-1000, 1000))
    dp_list=set(dp_list)-set(numbers)

    for i in range(101):
        if abs(x-i) in dp_list:
            print(x-i)
            break
        elif abs(x+i) in dp_list:
            print(x+i)
            break

if __name__ == "__main__":
    main()

Measured memory_bytes: 9276