akhauriyash/Code-Regression huggingface dataset:
def solve():
    if not (c11 - c21 == c12 - c22 == c13 - c23):
        return False
    if not (c11 - c31 == c12 - c32 == c13 - c33):
        return False
    if not (c11 - c12 == c21 - c22 == c31 - c32):
        return False
    if not (c11 - c13 == c21 - c23 == c31 - c33):
        return False
    return True
 
 
c11, c12, c13 = map(int, input().split())
c21, c22, c23 = map(int, input().split())
c31, c32, c33 = map(int, input().split())
 
print('Yes' if solve() else 'No')

Measured memory_bytes: 3064
import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def Main():
    n = read_int()
    a = read_int_list()
    b = [0] * n
    ans = []
    for i in range(n - 1, -1, -1):
        if sum(b[i::i + 1]) % 2 != a[i]:
            b[i] = 1
            ans.append(i + 1)
    print(len(ans))
    if len(ans): print(*ans)    
    
if __name__ == '__main__':
    Main()

Measured memory_bytes: 17952
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

ld pi=abs(acos(-1.0));

int main(void){
    ld A, B, H, M;
    cin >> A >> B >> H >> M;
    ld ag=pi*(H/6.0-(M*11.0)/360.0);
    cout << setprecision(15) << pow(A*A+B*B-A*B*cos(ag)*2.0, 0.5) << endl;
    return 0;
}


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

def f(nums):
  out=0
  for samp in abcd:
    if nums[samp[1]-1]-nums[samp[0]-1]==samp[2]:
      out+=samp[3]
  return out

def g(nums):
  if nums[-1]<M:
    nums[-1]+=1
    return nums, False
  
  i=N-1
  while i>=0 and nums[i]==M:
    i-=1
  if i<0:
    return None, True
  
  nums=nums[:i]+[nums[i]+1 for _ in range(N-i)]
  return nums, False

nums=[1]*N
fi=False
ans=0

while fi==False:
  p=f(nums)
  if ans<p:
    ans=p
  nums, fi=g(nums)
  
print(ans)


  

Measured memory_bytes: 9080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pint;
#define ms(arr) memset(arr,0,sizeof(arr))


int main() {
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    for (ll i = 0; i < n; ++i)
        cin >> a[i];
    for (ll j = n - 1; j >= 0; --j) {
        if (j > n / 2) {
            b[j] = a[j];
        } else if (j == 0) {
            continue;
        } else {
            ll tmp = j +j+1;
            ll cnt = 0;
            while (tmp < n) {
                cnt += b[tmp];
                tmp += j+1;
            }
            if (cnt % 2 == a[j]) {
                b[j] = 0;
            } else {
                b[j] = 1;
            }
        }
    }
    ll cnt = accumulate(b.begin() + 1, b.end(), 0);
    if (cnt % 2 == a[0]) {
        b[0] = 0;
    } else {
        b[0] = 1;
        ++cnt;
    }
    cout << cnt << endl;
    for (ll i = 0; i < n; ++i) {
        if (b[i] == 1)
            cout << i + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3968
from collections import Counter

n = int(input())
a = list(map(int,input().split()))
a_count = sorted(Counter(a).items(),reverse=True)
f = False

for k,v in a_count:
    if (4 <= v) and (not f):
        print (k**2)
        exit ()
    elif 2 <= v:
        if f:
            print (x*k)
            exit ()
        else:
            x = k
            f = True
    else:
        pass

print (0)

Measured memory_bytes: 21412
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}

int main(void) {
    int n, m;
    read(n); read(m);
    for (int x = 1; x <= n; x++)
	for (int y = 'A'; y <= 'A' + m - 1; y++) {
	    string str;
	    cin >> str;
	    if (str == "snuke") {
		cout << (char) y << x << "\n";
		return 0;
	    }
	}
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
 
using namespace std;
 
void print(char str[],int a,int b){
    for(int i = a; i <= b; i++)  printf("%c",str[i]);
    printf("\n");
}
 
void replace(char str[],char p[],int a,int b){
    int p_length = b-a+1;
    for(int i = 0; i < p_length;i++) str[a+i] = p[i];
}
 
void reverse(char str[],int a,int b){
    int left = a,right = b;
    while(left < right){
        swap(str[left++],str[right--]);
    }
}
 
int main(){
    char str[1001],p[1001],order[8];
    int q,a,b;
    scanf("%s",str);
    scanf("%d",&q);
    for(int i = 0; i < q; i++){
        scanf("%s %d %d",order,&a,&b);
        switch(order[2]){
        case 'i':
            print(str,a,b);
            break;
        case 'v':
            reverse(str,a,b);
            break;
        case 'p':
            scanf("%s",p);
            replace(str,p,a,b);
            break;
        }
    }
}


Measured memory_bytes: 2628
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      mut a: usize,
      mut b: usize,
      mut c: usize,
    }
    let mut ans = 0;
    loop {
        if a%2 == 1 || b%2==1 || c%2 == 1 {
            return println!("{}", ans);
        }
        if a == b && b == c {
            return println!("{}", -1);
        }

        let aa = b/2 + c/2;
        let bb = a/2 + c/2;
        let cc = a/2 + b/2;
        a = aa;
        b = bb;
        c = cc;
        ans += 1;
    }
}


Measured memory_bytes: 4352
'use strict'
function main(input) {
  const N = parseInt(input, 10);

  let maxB = 0;
  for (let A = 1; A < N; A++) {
    let B = N / A;
    if (Number.isInteger(B)) {
      maxB = B;
    }
    if (A > B) {
      break;
    }
  }

  const digit = maxB.toString().length;
  console.log(digit);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 8524
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>

using namespace std;

#define rep(i,a,n) for(int (i)=a;(i)<(int)(n);(i)++)
#define rrep(i,a,n) for(int (i)=(n)-1;(i)>=a;(i)--)
#define all(x) (x).begin(),(x).end()

typedef long long ll;

const int INF = 1e9;

int main() {
    int r,c;
	cin >> r >> c;
	int a[r+1][c+1];
	rep(i,0,r) rep(j,0,c) cin >> a[i][j];
	rep(i,0,r) {
		int sum = 0;
		rep(j,0,c) sum += a[i][j];
		a[i][c] = sum;
	}
	rep(i,0,c+1) {
		int sum = 0;
		rep(j,0,r) sum += a[j][i];
		a[r][i] = sum;
	}
	rep(i,0,r+1) {
		rep(j,0,c+1) {
			if(j>0) cout<<" ";
			cout<<a[i][j];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 3116
using System;
class Program
{
  static void Main(string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int k = int.Parse(input[0]);
    int x = int.Parse(input[1]);
    
    string s = string.Empty;
    int min = x - (k - 1);
    int max = x + (k - 1);
    
    for (int i = min; i <= max; i++) {
      if (i != min) { s += " "; }
      s += i.ToString();
    }
    Console.WriteLine(s);
  }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll a, b, c, n, m, x, y, z, w, h, ans, cnt, mx, mn;
string s, t;
vll dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n){
        vll v;
        ans = 0;
        rep(i, n){
            cin >> a;
            v.pb(a - i - 1);
        }
        sort(all(v));
        rep(i, n){
            ans += abs(v[i] - v[n / 2]);
        }
        print(ans);
    }
}


Measured memory_bytes: 2420
// clang-format off
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort(all(x), greater<>())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
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;}
// clang-format on

void solve(std::string S) {
  rep(i, S.size()) cout << "x";
  cout << endl;
}

// clang-format off
int main() {
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define N 1002
int f[N][N], n, m;
char c[N];
int main() {
    f[1][1] = 1;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf("%s", c + 1);
        for (int j = 1; j <= m; j++) {
            if (c[j] == '#') continue;
            if (i > 1 && f[i - 1][j] > 0)
                f[i][j] = (f[i][j] + f[i - 1][j]) % mod;
            if (j > 1 && f[i][j - 1] > 0)
                f[i][j] = (f[i][j] + f[i][j - 1]) % mod;
        }
    }
    printf("%d\n", f[n][m]);
    return 0;
}

Measured memory_bytes: 4224
sx,sy,tx,ty = map(int,input().split())
x = tx-sx
y = ty-sy
ans = ""
for i in range(x):
    ans += "R"
for i in range(y):
    ans += "U"
for i in range(x):
    ans += "L"
for i in range(y+1):
    ans += "D"
for i in range(x+1):
    ans += "R"
for i in range(y+1):
    ans += "U"
ans += "L"
ans += "U"
for i in range(x+1):
    ans += "L"
for i in range(y+1):
    ans += "D"
ans += "R"
print(ans)


Measured memory_bytes: 3064
from collections import Counter


N, A = map(int, input().split())
X = list(map(int, input().split()))
Y = [x - A for x in X]
L = Counter()
L[0] = 1

for y in Y:
    for key, value in list(L.items()):
        L[key + y] += value

print(L[0] - 1)


Measured memory_bytes: 3564
from collections import Counter,defaultdict
import sys,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

s = input()
print(s.count('1'))

Measured memory_bytes: 4068
N = int(input())
A_1 = list(map(int, input().split()))
A_2 = list(map(int, input().split()))

ans = 0

for i in range(N):
    S = sum(A_1[0:i+1]) + sum(A_2[i:N])
    if S > ans:
        ans = S

print(ans)

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

int main(){
    using namespace std;
    auto chmin = [](auto& a, auto b){return a > b && (a = b);};
    size_t K;
    cin >> K;
    deque<size_t> dfs(1, 1), dst(K, 46);
    dst[1] = 1;
    while(!dfs.empty()){
        auto i = dfs.front(), d = dst[i];
        dfs.pop_front();
        if(!i)return 0 & printf("%lu\n", d);
        if(chmin(dst[i * 10 % K], d))dfs.push_front(i * 10 % K);
        if(chmin(dst[++i %= K], d + 1))dfs.push_back(i);
    }
}

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int m = Integer.parseInt(str[1]);

		int k[] = new int[m];
		ArrayList<ArrayList<Integer>> list = new ArrayList<>();
		for (int i = 0; i < m; i++) {
			list.add(new ArrayList<>());
		}

		for (int i = 0; i < m; i++) {
			str = br.readLine().split(" ");

			k[i] = Integer.parseInt(str[0]);

			for (int j = 1; j <= k[i]; j++) {
				list.get(i).add(Integer.parseInt(str[j]));
			}
		}

		int p[] = new int[m];
		str = br.readLine().split(" ");

		for (int i = 0; i < m; i++) {
			p[i] = Integer.parseInt(str[i]);
		}

		List<String> com = conbination(Arrays.asList(""), n);

		int ans = 0;
		for (int i = 0; i < com.size(); i++) {
			String swit[] = com.get(i).split("");
			boolean flag = false;

			for (int j = 0; j < m; j++) {
				int count = 0;
				for (int l = 0; l < k[j]; l++) {
					if (swit[list.get(j).get(l) - 1].equals("1")) {
						count++;
					}
				}

				if (count % 2 != p[j]) {
					flag = true;
					break;
				}
			}
			if (!flag)
				ans++;
		}
		System.out.println(ans);
	}

	public static List<String> conbination(List<String> binary, int count) {
		if (count <= 0)
			return binary;
		List<String> list = new ArrayList<String>(binary.size() * 2);
		for (String s : binary) {
			list.add(s + 0);
			list.add(s + 1);
		}
		return conbination(list, count - 1);
	}
}


Measured memory_bytes: 26068
#include<stdio.h>

int main(void){
    int a,b,c,i,count;
    count = 0;
    scanf("%d %d %d", &a, &b, &c);
    for ( i = a ; i <= b ; i++ ){
        if ( (c % i) == 0 ){
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 2132
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;
//ここから

#define int64_t ll
map< int64_t, ll > prime_factor(int64_t n) {
  map< int64_t, ll > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

void solve(){
  ll n;
  cin>>n;
  map<ll,ll>mp,mp2;
  for(ll i=1;i<=n;++i){
    mp2=prime_factor(i);
    for(auto x:mp2){
      mp[x.first]+=x.second;
    }
  }
  ll ans=1;
  for(auto x:mp){
    //cout<<x.first<<" "<<x.second<<endl;
    ans*=x.second+1;
    ans%=mod;
  }
  cout<<ans;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


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


N,K=map(int, input().split())
H=list(map(int, input().split()))
G=[0]
G.extend(H[:])

dp=[[0]*(N+1) for i in range(N-K+1)]


tempa=0
if K<N-1:
    for jtemp in range(N):
        j=jtemp+1
        dp[1][j]=G[j]#min(dp[1][j-1],G[j])
    for itemp in range(N-K-1):
        i=itemp+2
        for jtemp in range(N-(i-1)):
            j=jtemp+i
            temp=int(N*1e9)
            
            for ktemp in range(j-(i-1)):
                k=ktemp+i-1
                val=G[j]-G[k]
                if val<0:
                    val=0
                if temp>dp[i-1][k]+val:
                    temp=dp[i-1][k]+val
            dp[i][j]=temp
    tempa=dp[N-K][-1]
    for jtemp in range(N):
        j=jtemp+1
        if tempa>dp[N-K][j] and dp[N-K][j]!=0:
            tempa=dp[N-K][j]
elif N-K==1:
    tempa=min(H[:])
else:
    tempa=0
print(tempa)

Measured memory_bytes: 43740
#include <iostream>

using namespace std;

const int maxn = 2e5 + 9;
const long long mod = 1e9 + 7;
long long arr[maxn], dp[maxn], last[maxn];

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

    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    for (int i = 0; i < maxn; i++) {
        last[i] = -1;
    }
    dp[0] = 1;
    last[arr[0]] = 0;
    for (int i = 1; i < n; i++) {
        if (arr[i] == arr[i - 1]) {
            dp[i] = dp[i - 1];
        } else {
            if (last[arr[i]] == -1) dp[i] = dp[i - 1];
            else dp[i] = dp[last[arr[i]]] + dp[i - 1];
        }
        last[arr[i]] = i;
        dp[i] %= mod;
    }
    cout << dp[n - 1] << '\n';
    // for (int i = 0; i < n; i++) {
    //     cerr << dp[i] << ' ';
    // }
    cerr << '\n';

    return 0;
}

Measured memory_bytes: 4992
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll N, K;
  cin >> N >> K;
  vector<ll> h(N);
  rep (i, N) cin >> h[i];

  unsigned long long INF = -1;
  INF >>= 1;
  vector<ll> ans(N, INF);
  ans[0] = 0;

  rep (i,  N) {
    for (ll j = 1; j <= K; j++) if (i + j < N) ans[i + j] = min(ans[i + j], ans[i] + abs(h[i] - h[i+j]));
  }

  cout << ans[N-1] << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main (void) {
  int a, b, c, d;
  int l, r;
  scanf("%d%d%d%d", &a, &b, &c, &d);
  l=a+b;
  r=c+d;
  if (l>r)
    printf("Left\n");
  else if (l<r)
    printf("Right\n");
  else
    printf("Balanced\n");
  return 0;
}

Measured memory_bytes: 128
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
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; }
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
int n, b, c;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        temp--;
        a[temp]=i;
    }
    int inc=1;
    int count=1;
    for(int i=0;i<n-1;i++){
        if(a[i+1]-a[i]>0){
            count++;
        }
        else{
            chmax(inc,count);
            count=1;
        }
    }
    chmax(inc,count);
    cout<<n-inc<<"\n";
}



Measured memory_bytes: 1024
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def f(N):
    return math.ceil(N / 10) * 10


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    D = il()

    ret = 0
    for d in itertools.combinations(D, 2):
        ret += d[0]*d[1]
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3932
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final Scanner sc = new Scanner(System.in);
    static final PrintStream so = System.out;
    public static void main(String[] args) {
        int N = sc.nextInt();
        int[] b = nints(N);
        for (int i = 0; i < N; i++) {
            if (b[i] > i+1) {
                so.println("-1");
                return;
            }
        }
        int[] ans = new int[N];
        
        for (int i = 0; i < N; i++) {
            ans = insert(ans, b[i]-1, b[i]);
        }
        for (int a: ans) {
            so.println(a);
        }
    }
    
    static int[] insert(int[] a, int index, int toInsert) {
        int[] newA = a.clone();
        int len = newA.length;
        for (int i = len-1; i >= index; i--) {
            newA[i] = (i == index) ? toInsert : newA[i-1];
        }
        return newA;
    }
    
    static int  nint()   { return sc.nextInt(); }
    static long nlong()  { return sc.nextLong(); }
    static String next() { return sc.next(); }
    static int[] nints(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = nint();
        return a;
    }
}


Measured memory_bytes: 24148
using System;
using System.Numerics;
using System.Text;
using static ConsoleReader;

class Program
{
    static void Main(string[] args)
    {
        var k = Read<int>();
        var mod = k % 10;
        var res = 0L;
        var count = 0;
        while (true)
        {
            var lastResDig = res % 10;
            var nextDig = 0;
            while (nextDig < 10)
            {
                if ((mod * nextDig + lastResDig) % 10 == 7) break;
                nextDig++;
            }
            if (nextDig == 10)
            {
                Console.WriteLine(-1);
                return;
            }
            count++;
            res = (res + k * nextDig) / 10;
            //Console.WriteLine($"{nextDig} : {res}");
            if (res == 0) break;
        }
        Console.WriteLine(count);
        //Console.WriteLine(res);
        //var num = new BigInteger(7);
        //var max = 1_000_000_000;
        //for (var i = 1; i < max; i++)
        //{
        //    if (num % k == 0)
        //    {
        //        Console.WriteLine(i);
        //        return;
        //    }
        //    num = num * 10 + 7;
        //}
        //Console.WriteLine(-1);

        //var num = 777777777777;
        //var div = 2;
        //while (div <= Math.Sqrt(num) + 1)
        //{
        //    if (num % div == 0)
        //    {
        //        Console.Write($"{div} ");
        //        num = num / div;
        //    }
        //    else
        //    {
        //        div++;
        //    }
        //}
        //if (num > 1) Console.Write(num);
        //for (var div = 2; div < num / 2; div++)
        //{
        //    if (num % div == 0) Console.Write($"{div} ");
        //}
    }
}

public static class IntExtentions
{
    public static void Times(this int n, Action<int> action)
    {
        for (var i = 0; i < n; i++)
        {
            action(i);
        }
    }

    public static void Times(this (int n, int m) dimensions, Action<int, int> action)
    {
        var (n, m) = dimensions;
        n.Times(i => m.Times(j => action(i, j)));
    }
}

public static class ConsoleReader
{
    public static T Read<T>()
        where T : IConvertible
    {
        var inputBuffer = new StringBuilder();
        int currChar;

        while ((currChar = Console.Read()) != -1)
        {
            if (!char.IsWhiteSpace((char)currChar))
            {
                inputBuffer.Append((char)currChar);
            }
            else if (inputBuffer.Length != 0)
            {
                break;
            }
        }

        return (T)Convert.ChangeType(inputBuffer.ToString(), typeof(T));
    }

    public static T[] ReadArray<T>(int count)
        where T : IConvertible
    {
        if (count < 0)
        {
            throw new ArgumentOutOfRangeException(nameof(count), $"'{nameof(count)}' must be >= 0");
        }

        var result = new T[count];

        for (var i = 0; i < count; i++)
        {
            result[i] = Read<T>();
        }

        return result;
    }
}

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

using namespace std;

int main(int argc, char *argv[]) {
	int N;
	cin >> N;
	vector<int> a(100002);

	for (int i = 0; i < N; i++) {
		int ai;
		cin >> ai;
		a[ai]++; a[ai+1]++; a[ai+2]++;
	}

	int ans = 0;
	for (int i = 0; i < a.size(); i++) {
		ans = max(ans, a[i]);
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int H,W; cin >> H >> W;
    string s[H+2];
    for(int i=0; i<H+2; i++) s[i] = "";
    for(int i=0; i<W+2; i++) s[0] += '#';
    for(int i=0; i<W+2; i++) s[H+1] += '#';
    
    for(int i=1; i<=H; i++){
        s[i] += '#';
        for(int j=0; j<W; j++){
            char c;
            cin >> c;
            s[i] += c;
        }
        s[i] += '#';
    }

    for(int i=0; i<H+2; i++){
        cout << s[i] << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
h = [0] + list(map(int, input().split())) + [0]

cnt = 0
while True:
    zero_ind = []
    for i in range(n+2):
        if h[i] == 0:
            zero_ind.append(i)

    start, end = [], []
    for i in range(len(zero_ind)-1):
        if zero_ind[i+1] - zero_ind[i] > 1:
            start.append(zero_ind[i]+1)
            end.append(zero_ind[i+1])

    for s, e in zip(start, end):
        for i in range(s, e):
            h[i] -= 1
        cnt += 1

    if h.count(0) == n+2:
        break
print(cnt)

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

using namespace std;

typedef long long ll;

int main()
{
    ll N, M;
    ll A[20000];
    cin >> N >> M;
    ll sum = 0;
    for (int i = 0; i < M; i++) {
        cin >> A[i];
        sum += A[i];
    }
    if (N >= sum) {
        cout << (N - sum) << endl;
    } else {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 3684
#include <iostream>

using namespace std;

int main()
{
	int a, b, c;
	string ans;
	cin >> a >> b >> c;
	if ((100 * a + 10 * b + c) % 4 == 0)
		ans = "YES";
	else
		ans = "NO";
	cout << ans <<"\n";
}

Measured memory_bytes: 256
/*  ***  In The Name of God ... ***  */
#include <bits/stdc++.h>

using namespace std ;

typedef long long ll ;
typedef long double ld ;


#define int long long
#define all(v) v.begin() , v.end()

template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

const int N = 3000 + 10 ;

int n , ar [ N ] , dp [ N ] ; 
vector < int > adj [ N ] ; 
pair < int , int > pi [ N ] ; 

int32_t main()                     
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n ;
	for ( int i = 0 ; i < n ; ++ i )
		cin >> ar [ i ] ;
	for ( int j = 0 ; j < n - 1 ; ++ j ) {
		int u , v ;
		cin >> u >> v ;
		-- u , -- v ;
		adj [ u ] . push_back ( v ) ;
		adj [ v ] . push_back ( u ) ; 
	}
	for ( int i = 0 ; i < n ; ++ i )
		pi [ i ] = make_pair ( ar [ i ] , i ) ;
	sort ( pi , pi + n ) ;
	for ( int j = 0 ; j < n ; ++ j ) {
		int v = pi [ j ] . second ;
		for ( int u : adj [ v ] ) {
			if ( ar [ v ] > ar [ u ] && !dp [ u ] )
				dp [ v ] = 1 ; 
		}
	}
	for ( int i = 0 ; i < n ; ++ i )
		if ( dp [ i ] )
			cout << i + 1 << ' ' ;
	cout << '\n' ; 
}


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

long long get_range_num(string s, int left, int right) {
  return stoll(s.substr(left, right - left + 1));
}

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

  int n = s.size();
  long long total = 0;
  for (int i = 0; i < (1 << n - 1); i++) {
    bitset<10> b(i);
    
    long long subtotal = 0; 
    int left = 0;
    for (int j = 0; j < n; j++) {
      if (b.test(j) || j == n - 1) {
        subtotal += get_range_num(s, left, j);
        left = j + 1;
      }
    }

    total += subtotal;
  }

  cout << total << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stack>/*** LIFO *** stack<type> var;
push(), top():to get data, pop():to remove, size(), empty() ***/
using namespace std;

#define Fp(I, STAT, END) for(int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for(int I = STAT; I > END; I--)

//最大公約数
long int GCD(long int a, long int b){
    long int temp;
    if(a > b){
        temp = b;
        b = a;
        a = temp;
    }
    long int r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

//最小公倍数
long int LCM(long int a, long int b){
    return a * b / GCD(a, b);
}

int main(){
    long int A, B;
    cin >> A >> B;
    cout << LCM(A, B) << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace _0100
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) break;
                Dictionary<long,long> dic = new Dictionary<long,long>();
                for (int i = 0; i < n; i++)
                {
                    long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
                    if (!dic.ContainsKey(x[0])) dic[x[0]] = 0;
                    dic[x[0]] += x[1] * x[2];
                }
                bool found = false;
                foreach (var i in dic)
                {
                    if (i.Value >= 1000000)
                    {
                        found = true;
                        Console.WriteLine(i.Key);
                    }
                }
                if (!found) Console.WriteLine("NA");
            }
        }
    }
}


Measured memory_bytes: 10152
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstring>
#include<set>
#include<map>
using namespace std;

int main(){
    int n,l[2001],ans=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&l[i]);
    }
    sort(l,l+n);
    l[n]=100000;
    for(int i=1;i<n-1;i++){
        int left=0,right=i+1;
        for(left=0;left<i;left++){
            while(l[right]<l[i]+l[left]){
                right++;
            }
            ans+=right-i-1;
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 888
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Black is
   A : Integer;
   B : Integer;
   C : Integer;
begin
   Get (A);
   Get (B);
   Get (C);
   if A+B+C >= 22 then
      Put_Line ("bust");
   else
      Put_Line ("win");
   end if;
end Black;

Measured memory_bytes: 3572
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
#include <bitset>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

const int MAX_N = 12;
int N, M;
int k[MAX_N], s[MAX_N][MAX_N], p[MAX_N];

bool is_all(std::bitset<MAX_N> bs) {
    for (int i = 1; i <= M; i++) {
        int num = 0;
        for (int j = 1; j <= k[i]; j++) {
            if (bs.test(s[i][j] - 1)) {
                num++;
            }
        }
        if (num % 2 != p[i]) {
            return false;
        }
    }
    return true;
}

int main(int argc, char **argv) {
    std::cin >> N >> M;

    for (int i = 1; i <= M; i++) {
        std::cin >> k[i];
        for (int j = 1; j <= k[i]; j++) {
            std::cin >> s[i][j];
        }
    }

    for (int i = 1; i <= M; i++) {
        std::cin >> p[i];
    }

    long long ret = 0;
    for (int w = 0; w < (1 << N); w++) {
        std::bitset<MAX_N> bs(w);
        if (is_all(bs)) {
            ret++;
        }
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	int* a = new int[n];
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	int scoa = 0;
	for (int i = 0;i < n;i += 2) {
		if (a[i] % 2 == 1) {
			scoa++;
		}
	}
	cout << scoa << endl;
}

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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9
#define MAX 1000

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;



int main(){
    string S;
    cin >> S;
    int N = S.size();
    ll cnt[26];
    fill(cnt,cnt+26,0);
    Rep(i,N){
        cnt[S[i]-'a']++;
    }
    ll ans = 0;
    Rep(i,26){
        ans += cnt[i]*(N-cnt[i]);
    }
    cout << ans/2 + 1 << endl;
    cin >> N;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=1050;
//↑templete
signed main(){
	
	string S;
	cin>>S;

    if(S=="AAA" || S=="BBB")
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

int main()
{
  int N;
  vector<pair<int, int> > vec_bulb;
  
  cin >> N;
  while (N--) {
    int A, B;
    pair<int, int> tmp;
    cin >> A >> B;
    tmp.first = A;
    tmp.second = 1;
    vec_bulb.push_back(tmp);
    tmp.first = B + 1;
    tmp.second = -1;
    vec_bulb.push_back(tmp);
  }

  sort(vec_bulb.begin(), vec_bulb.end());
  
  int max_count = 0;
  int count = 0;
  for (pair<int, int> v : vec_bulb) {
    count += v.second;
    if (count > max_count) max_count = count;
  }
  
  cout << max_count << endl;
}



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

const ll MOD = 1e9 + 7;
const int N = 1e5;

ll X[N + 1], Y[N + 1];

int main() {
  int n, m;
  cin >> n >> m;
  
  for (int i = 1; i <= n; i++) {
    cin >> X[i];
  }
  
  for (int i = 1; i <= m; i++) {
    cin >> Y[i];
  }

  ll x = 0, y = 0;
  
  for (int i = 1; i <= n; i++) {
    x += X[i] * (i - 1) - X[i] * (n - i);
  }
  
  for (int i = 1; i <= m; i++) {
    y += Y[i] * (i - 1) - Y[i] * (m - i);
  }
  
  cout << ((x%MOD) * (y%MOD)) % MOD << endl;
  
  return 0;
}


Measured memory_bytes: 5164
from statistics import mean, median,variance,stdev
import sys
import math
import fractions

def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

#n = ip()                              #入力整数1つ
#n,k= (int(i) for i in input().split())      #入力整数横2つ
#x,y,z = (int(i) for i in input().split())    #入力整数横3つ
n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列

#jの変数はしようできないので注意
#xor は(a ^ b)でいける
dx = x-n
dy = y-m
px = x
py = y
a = []
py+=dx
px-=dy
cx=px
cy=py
px-=dx
py-=dy
print(cx,cy,px,py)

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

int main(){
    int N; cin >> N;
    int d[110]; for (int i=0; i < N ; i++) cin >> d[i];

    int num[110]={0};
    for (int i=0; i < N; i++){
        num[d[i]]++;
    }

    int ans=0;

    for (int i=0; i <= 100 ; i++){
        if (num[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

typedef long long i64;

const int MOD = (int) 1e9 + 7;
const int NMAX = 2005;

int dp[NMAX][NMAX];
int dpc[2 * NMAX][NMAX];

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m, k;
    cin >> n >> m >> k;

    for (int j = 0; j <= m; ++j) {
        dpc[0][j] = 1;
    }
    for (int i = 1; i <= n + m; ++i) {
        for (int j = 0; j <= m && j <= i; ++j) {
            int zero = j;
            int one = i - j;
            if (i >= k - 1) {
                int minz = max(0, j - k + 1);
                int mino = max(0, one - k + 1);
                int maxz = min(zero, i - k + 1 - mino);
                dpc[i][j] = dpc[i - k + 1][maxz];
                if (minz > 0) {
                    dpc[i][j] -= dpc[i - k + 1][minz - 1];
                    dpc[i][j] %= MOD;
                }
            }
            if (j > 0) {
                dpc[i][j] += dpc[i][j - 1];
                dpc[i][j] %= MOD;
            }
        }
        for (int j = i + 1; j <= m; ++j) {
            dpc[i][j] = dpc[i][j - 1];
        }
    }

    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) {
            if ((i + j - 1) % (k - 1)) {
                continue;
            }
            if (i >= k) {
                dp[i][j] = dp[i - k + 1][j];
            }
            if (j >= k) {
                dp[i][j] += dp[i][j - k + 1];
                dp[i][j] %= MOD;
            }
            if (i >= k && j >= k) {
                dp[i][j] -= dp[i - k + 1][j - k + 1];
                dp[i][j] %= MOD;
            }
            if (i == 0 || j == 0) {
                dp[i][j] = 1;
                continue;
            }
            int x = i + j - k;
            int min0 = max(0, j - k + 1);
            int min1 = max(0, i - k + 1);
            int max0 = min(j - 1, i + j - k + 1 - min1);
            dp[i][j] += dpc[x][max0];
            dp[i][j] %= MOD;
            if (min0 > 0) {
                dp[i][j] -= dpc[x][min0 - 1];
                dp[i][j] %= MOD;
            }
        }
    }
    int ans = dp[n][m];
    ans %= MOD;
    if (ans < 0) ans += MOD;

    cout << ans << '\n';
}


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

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

int main(){
  long long N,M;
  string S,T;
  cin >>N>>M;
  cin>>S;
  cin>>T;
  long long L=N*M/gcd(N,M);
  
  long long p=L/N;
  long long q=L/M;
  long long r=p*q/gcd(p,q);
  for (long long i=0;i<L;i=i+r){
      if(!(S.at(i/p)==T.at(i/q))){    
      cout<<-1<<endl;
      return 0;
      }
  }
  cout<<setprecision(20)<<L<<endl;
  return 0;
}

  
  

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Math.abs;
import static java.lang.Math.min;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final long x = abs(scanner.nextLong());
        final long k = abs(scanner.nextLong());
        final long d = abs(scanner.nextLong());

        if (x / d >= k) {
            System.out.println(x - d * k);
            return;
        }

        final long k1 = x / d;
        if (k1 % 2 == k % 2) {
            System.out.println(abs(x - d * k1));
        } else {
            System.out.println(min(abs(x - d * (k1 + 1)), abs(x - d * (k1 - 1))));
        }
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

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

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

        long nextLong() {
            return Long.parseLong(next());
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}
    

Measured memory_bytes: 32816