akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void){
    int maxX,maxY,nowX,nowY,n,pointX[1000]={0},pointY[1000]={0};
    int i,ans=0;
    scanf("%d %d %d",&maxX,&maxY,&n);
    for(i=0;i<n;i++){
        scanf("%d %d",&pointX[i],&pointY[i]);
    }
    nowX=pointX[0];
    nowY=pointY[0];
    for(i=0;i<n-1;i++){
        while(nowX!=pointX[i+1]||nowY!=pointY[i+1]){
            ans++;
            if(nowX<pointX[i+1]&&nowY<pointY[i+1]){
                nowX++;
                nowY++;
                continue;
            }
            if(nowX>pointX[i+1]&&nowY>pointY[i+1]){
                nowX--;
                nowY--;
                continue;
            }
            if(nowX<pointX[i+1]){
                nowX++;
                continue;
            }
            if(nowX>pointX[i+1]){
                nowX--;
                continue;
            }
            if(nowY<pointY[i+1]){
                nowY++;
                continue;
            }
            if(nowY>pointY[i+1]){
                nowY--;
                continue;
            }

        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 604
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

}

#[allow(unused_imports)]
use input::*;

fn calc(v: &mut Vec<usize>, n: usize) -> bool {
    let mut buf = 0;
    let mut n_buf = n + n;
    while n_buf <= v.len() {
        buf += v[n_buf - 1];
        n_buf += n;
    }
    buf %= 2;
    if buf == 1 && v[n - 1] == 1 {
        v[n - 1] = 0;
    } else if buf == 1 && v[n - 1] == 0 {
        v[n - 1] = 1;
    } else if buf == 0 && v[n - 1] == 1 {
        v[n - 1] = 1;
    } else {
        v[n - 1] = 0;
    }
    true
}

fn main() {
    let n: usize;
    input!(n);
    let mut v = input_vector::<usize>();

    for z in 0..n {
        calc(&mut v, n - z);
    }

    let mut one_count = 0;
    for z in 0..n{
        if v[z]==1{
            one_count+=1;
        }
    }
    p(one_count);
    for z in 0..n{
        if v[z] == 1 {
            print!("{} ", z + 1);
        }
    }
    println!("");
}

Measured memory_bytes: 8444
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

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

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

    string s;
    cin >> s;
	int ct =0;
	int n = (int) s.size();
    for(int i =0; i< n/ 2; ++i)
    {
		if(s[i] != s[n-i-1])
		{
			ct++;
		}
    }
	cout << ct;



    return 0;
}

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

#define int long long

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



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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const double INF=1e20;

double dp[555][555];

signed main(){
    int N,M;
    cin>>N>>M;

    vint A(N);rep(i,N)cin>>A[i];

    fill_n(*dp,555*555,-INF);
    dp[0][0]=0;

    rep(i,N){
        rep(j,M){
            int sum=0;
            chmax(dp[i][j+1],dp[i][j]);
            for(int k=1;i+k<=N;k++){
                sum+=A[i+k-1];
                chmax(dp[i+k][j+1],dp[i][j]+1.0*sum/k);
            }
        }
    }

    printf("%.20f\n",dp[N][M]);
    return 0;
}



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

int main(){
  int n;
  cin >> n;
  string ans = "No";
  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      int temp = i * j;    
      if(n==temp) ans = "Yes";
    }
  }
  cout << ans << endl;
      

}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <utility>
#include <queue>

using namespace std;
typedef pair<int, int> P;
typedef pair<int, pair<P, int> > S;

int n, x_0, y_0, t;
int a[55][55];
int b[1005];
int sum = 0;
bool used[1005][55][55][4];
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int get(char c)
{
  if(c == 'E') return 0;
  if(c == 'N') return 1;
  if(c == 'W') return 2;
  if(c == 'S') return 3;
  return -1;
}

void bfs()
{
  queue<S> Q;
  for(int i = 0; i < 4; i++){
    if(a[x_0][y_0] & (1<<i)){
      used[0][x_0][y_0][i] = true;
      Q.push(make_pair(0, make_pair(make_pair(x_0, y_0), i)));
    }
  }

  int t, x, y, d;
  while(Q.size()){
    t = Q.front().first;
    x = Q.front().second.first.first, y = Q.front().second.first.second;
    d = Q.front().second.second;
    Q.pop();
    //if((a[x][y] & (1<<d)) == 0) continue;
    int nx = x + dx[d], ny = y + dy[d];
    if(t == sum) continue;
    for(int i = 0; i < 4; i++){
      if((i+2)%4 == d) continue;
      if((a[nx][ny] & (1<<i))){
        if(used[t+1][nx][ny][i]) continue;
        if(b[t+1] != -1 && d != b[t+1] && i != b[t+1]) continue;
        used[t+1][nx][ny][i] = true;
        Q.push(make_pair(t+1, make_pair(make_pair(nx, ny), i)));
      }
    }
  }
}

int main(void)
{
  cin >> n >> x_0 >> y_0 >> t;
  int sx, sy, tx, ty;
  for(int i = 1; i <= n; i++){
    cin >> sx >> sy >> tx >> ty;
    if(sx == tx){
      if(sy > ty) swap(sy, ty);
      for(int y = sy; y <= ty; y++){
        if(y != sy) a[sx][y] |= 8;
        if(y != ty) a[sx][y] |= 2;
      }
    }
    else{
      if(sx > tx) swap(sx, tx);
      for(int x = sx; x <= tx; x++){
        if(x != sx) a[x][sy] |= 4;
        if(x != tx) a[x][sy] |= 1;
      }
    }
  }
  for(int i = 0; i < 1005; i++) b[i] = -1;
  int d; char c;
  for(int i = 1; i <= t; i++){
    cin >> d >> c;
    sum += d;
    b[sum] = get(c);
  }

  bfs();

  for(int i = 0; i <= 50; i++){
    for(int j = 0; j <= 50; j++){
      for(int k = 0; k < 4; k++){
        if(used[sum][i][j][k]){
          cout << i << " " << j << endl;
          break;
        }
      }
    }
  }

  return 0;
}



Measured memory_bytes: 9728
import math
import itertools

N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))

nara = []
for v in itertools.permutations(list(range(1,N+1)), N):
  nara.append(list(v))

Pcount = nara.index(P)
Qcount = nara.index(Q)
print(abs(Pcount-Qcount))

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Shiritori
            var words = GetItemsFromReadLines<string>().ToList();

            bool isShiritori = IsShiritori(words);

            if (isShiritori)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

        static bool IsShiritori(List<List<string>> words)
        {
            string lastChar = "";
            var dic = new Dictionary<string, string>();

            for (int i = 0; i < words.Count; i++)
            {
                string word = words[i][0];

                //その単語が初めて使用されたのかチェック
                if (dic.ContainsKey(word))
                {
                    return false;
                }
                else
                {
                    dic.Add(word, "");
                }
                
                //前の単語の最後の文字から始まっているかチェック
                if (i != 0)
                {
                    if (!word.StartsWith(lastChar))
                    {
                        return false;
                    }
                }
                
                lastChar = word.Substring(word.Length - 1);
            }

            return true;
        }

        static IEnumerable<List<T>> GetItemsFromReadLines<T>(int count = 0, char separator = ' ')
        {
            //[summary]コンソールの値を読み込んで、List<T>のコレクションを返却

            //読み込む行数が未指定のときは、1行目の値を"count"とみなす
            if (count == 0)
            {
                string line = Console.ReadLine().TrimEnd();
                count = int.Parse(line);
            }
            
            for(int i = 0; i < count; i++)
            {
                //コンソールを1行読み込み
                string line = Console.ReadLine().TrimEnd();

                //読み込んだ値を"separator"で区切る
                var list = line.Split(separator).ToList();

                //int型のときは数値に変換
                if (typeof(T) == typeof(int))
                {
                    var numbers = list.ConvertAll(int.Parse);
                    yield return (List<T>)(object)numbers;
                }
                else
                {
                    yield return (List<T>)(object)list;
                }
            }
        }
    }
}


Measured memory_bytes: 13536
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
int main(){
    ll n;
    while(cin>>n){
        int ans;
        set<ll> st;
        for(ll i=2; i*i<=n; ++i){
        	ll tmp=n;
        	while(tmp>=i){
        		if(tmp%i==0){
        			tmp/=i;
        		}
        		else{
        			tmp%=i;
        		}
        	}
        	if(tmp==1){
        		st.insert(i);
        	}
        }
        --n;
        for(ll i=2; i*i<=n; ++i){
        	if(n%i){
        		continue;
        	}
        	ll tmp=n+1;
        	while(tmp>=i){
        		if(tmp%i==0){
        			tmp/=i;
        		}
        		else{
        			tmp%=i;
        		}
        	}
        	if(tmp==1){
        		st.insert(i);
        	}
        	tmp=n+1;
        	while(tmp>=(n/i)){
        		if(tmp%(n/i)==0){
        			tmp/=n/i;
        		}
        		else{
        			tmp%=(n/i);
        		}
        	}
        	if(tmp==1){
        		st.insert((n/i));
        	}
        }
        // for(auto it:st){
        // 	cout<<it<<endl;
        // }
        ans=st.size()+2;
        if(n==1){
        	ans=1;
        }
        printf("%d\n",ans);
    }
  return 0;
}




Measured memory_bytes: 256
def extended_euclid(a, b):
    x1, y1, m = 1, 0, a
    x2, y2, n = 0, 1, b
    while m % n != 0:
        q = m // n
        x1, y1, m, x2, y2, n = x2, y2, n, x1 - q * x2, y1 - q * y2, m - q * n
    return x2, y2  # , n
print(*extended_euclid(*map(int, input().split())))


Measured memory_bytes: 5600
import sys

def ep(*params):
    print(*params,file=sys.stderr)

l = ''
r = ''

S = input().rstrip()

Q = int(input())
mode = 0
for _ in range(Q):
    ope = list(input().split())
    if ope[0] == '1':
        mode = (mode + 1)%2
    else:
        op = (int(ope[1]) + mode)%2
        if op == 1:
            l += ope[2]
        else:
            r += ope[2]
    #print(mode,l[::-1],S,r,sep=":",file=sys.stderr)    

if mode == 0:
    print(l[::-1],S,r,sep="")    
else:
    print(r[::-1],S[::-1],l,sep="")    


Measured memory_bytes: 4048
#include<bits/stdc++.h>
using namespace std;
const long long int N=100090;
long long ara[N];
int main()
{
    long long int n,x,p,cnt=0;
    cin>>n>>x;
    for(int i=0;i<n;i++)
        cin>>ara[i];
    for(int i=0;i<n-1;i++)
    {
        p=ara[i]+ara[i+1];
        if(p>x)
        {
            cnt+=(p-x);
            ara[i+1]=ara[i+1]-min(ara[i+1],(p-x));
        }
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 1152
h, w = map(int, input().split())

if h % 3 == 0 or w % 3 == 0:
    print(0)
    exit()
ans = 10 ** 10
if h >= 3:
    ans = min(h, ans)

if w >= 3:

    ans = min(ans, w)
    # print(kouho)

for i in range(1, h):
    num1 = w * (i)
    num2 = (h - i) * (w // 2)
    num3 = (h - i) * (w - w // 2)
    kouho = [num1, num2, num3]
    kouho.sort()
    ans = min(ans, kouho[-1] - kouho[0])
for i in range(1, w):
    num1 = h * (i)
    num2 = (w - i) * (h // 2)
    num3 = (w - i) * (h - h // 2)
    kouho = [num1, num2, num3]
    kouho.sort()
    ans = min(ans, kouho[-1] - kouho[0])
print(ans)


Measured memory_bytes: 9140
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
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...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    int ans = 0;
    for (int r = 0; r <= N; r++) {
        for (int g = 0; g <= N; g++) {
            int n = N - (r * R + g * G);
            if (0 <= n && n % B == 0) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}


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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n"
#define rep(i,n) for(int i=0; i<(n); ++i)

typedef pair<int, int> P;
typedef pair<string, int> Psi;


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

	int n; cin>>n;

	map<ll,ll> mp;

	rep(i,n){
		int tmp; cin>>tmp;

		mp[tmp]++;
		mp[tmp-1]++;
		mp[tmp+1]++;
	}

	int ans =0;

	for(auto e: mp){
		ans = max((ll)ans,e.second);
	}

	writeln(ans);


}


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

using ll = long long;

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

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

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

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

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

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

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

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  int n; std::cin >> n;
  map<string, int> s;
  rep(i, n) {
    string si; std::cin >> si;
    s[si]++;
  }
  int m; std::cin >> m;
  map<string, int> t;
  rep(i, m) {
    string ti; std::cin >> ti;
    t[ti]++;
  }
  int ans = 0;
  for (auto p : s) {
    int tmp = p.se - t[p.fi];
    chmax(ans, tmp);
  }
  std::cout << ans << "\n";
}


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

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    vector<vector<int>> s(10,vector<int>(10,0));

    for(int i = 1 ; i <= n ; i++){
        int head,tail;
        int tem = i;
        
        while(tem > 9)
            tem /= 10;
        head = tem;
        tail = i%10;
        s[head][tail]++;
    }

    int ans = 0;
    for(int i = 0 ; i < 10 ; i++){
        for(int j  = 0 ; j < 10 ; j++){
            ans += s[i][j] * s[j][i];
        }
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
	int n, i;
	scanf("%d", &n);
	int ans=0;
	int a, min=INT_MAX;
	for(i=0; i<n; i++){
		scanf("%d", &a);
		if(a<min){ans++; min=a;}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define pb push_back
#define mem(arr,x) memset(arr,x,sizeof(arr))
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,k,ans=0;
    cin>>a>>b>>c>>k;
	ans=min(a,k);
	k=k-ans;
    if(k>0)
    k=k-min(b,k);
	if(k>0)
	ans=ans-min(c,k);
	cout<<ans;
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
    int n,x,y,z;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> x >> y >> z;
        int X,Y,Z;
        X = x*x;
        Y = y*y;
        Z = z*z;
        if(X+Y==Z || Y+Z==X || X+Z==Y){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3104
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    dic1 = {}
    total = 0
    for i in range(n):
        if a[i] in dic1:
            dic1[a[i]] += 1
        else:
            dic1[a[i]] =1
        total += a[i]

    for i in range(q):
        b, c = map(int, input().split())
        if not b in dic1:
            print(total)
            continue
        bcount = dic1[b]
        if bcount == 0:
            print(total)
            continue
        inc = bcount * (c-b)
        if c in dic1:
            dic1[c] += bcount
        else:
            dic1[c] = bcount
        dic1[b] = 0
        total += inc
        print(total)
resolve()

Measured memory_bytes: 20720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  int N,M;cin>>N>>M;
  cout << N*(N-1)/2 + M*(M-1)/2;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a[5];
	char b[5];
	while(scanf("%s",b)!=EOF){
		for(int i=0;i<=3;i++){
			a[i]=b[i]-'0';
		}
		if(a[0]+a[1]+a[2]+a[3]==7){
			printf("%d+%d+%d+%d=7\n",a[0],a[1],a[2],a[3]);
		}else if(a[0]+a[1]+a[2]-a[3]==7){
			printf("%d+%d+%d-%d=7\n",a[0],a[1],a[2],a[3]);
		}else if(a[0]+a[1]-a[2]+a[3]==7){
			printf("%d+%d-%d+%d=7\n",a[0],a[1],a[2],a[3]);
		}else if(a[0]+a[1]-a[2]-a[3]==7){
			printf("%d+%d-%d-%d=7\n",a[0],a[1],a[2],a[3]);
		}else if(a[0]-a[1]+a[2]+a[3]==7){
			printf("%d-%d+%d+%d=7\n",a[0],a[1],a[2],a[3]);
		}else if(a[0]-a[1]+a[2]-a[3]==7){
			printf("%d-%d+%d-%d=7\n",a[0],a[1],a[2],a[3]);
		}else if(a[0]-a[1]-a[2]+a[3]==7){
			printf("%d-%d-%d+%d=7\n",a[0],a[1],a[2],a[3]);
		}else if(a[0]-a[1]-a[2]-a[3]==7){ 
			printf("%d-%d-%d-%d=7\n",a[0],a[1],a[2],a[3]);
		}
	}
	return 0;
}

Measured memory_bytes: 128
n, m = map(int, input().split())
s = input()
ans = True
res = []
i = n
while i > 0:
    flag = 0
    for j in range(max(0, i - m), i):
        if s[j] == '0':
            flag = 1
            res.append(i - j)
            i = j
            break
    if flag == 0:
        ans = False
        break
if ans == False:
    print(-1)
else:
    for i in range(len(res) - 1, -1, -1):
        print(res[i])

Measured memory_bytes: 4848
#include<iostream>

const int RANK = 13;
const int MARK = 4;

int changeMark(char mark){
	if(mark == 'S') return 0;
	if(mark == 'H') return 1;
	if(mark == 'C') return 2;
	if(mark == 'D') return 3;
}

char changeMarkR(int mark) {
	if(mark == 0) return 'S';
	if(mark == 1) return 'H';
	if(mark == 2) return 'C';
	if(mark == 3) return 'D';
}

int main()
{
	int n;
	std::cin >> n;
	bool cards[MARK][RANK];
	for(int i=0; i<MARK; i++) {
		for(int j=0; j<RANK; j++) {
			cards[i][j] = false;
		}
	}
	char mark_char;
	int mark_number, rank_number, rank_number_array;
	while(std::cin >> mark_char >> rank_number) {
		mark_number = changeMark(mark_char);
		rank_number_array = rank_number - 1;
		cards[mark_number][rank_number_array] = true;
	}
	char output_mark;
	int output_number;
	for(int i=0; i<MARK; i++) {
		for(int j=0; j<RANK; j++) {
			if(cards[i][j] == false) {
				output_mark = changeMarkR(i);
				output_number = j + 1;
				std::cout << output_mark << " " << output_number << "\n";
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1160
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
int a[1010101], cnt[1010101], d[1010101];

int main(){
    
    // 1. 入力情報.
    int N;
    set<int> s;
    scanf("%d", &N);
    rep(i, N){
        scanf("%d", &a[i]);
        cnt[a[i]]++;
        s.insert(a[i]);
    }
    
    // 2. 割り切れるか確認.
    for(auto &p : s){
        repex(i, p * 2, 1010101, p) if(cnt[i]) d[i]++;
    }
    
    // 3. 出力.
    int ans = 0;
    rep(i, N) if(cnt[a[i]] == 1 && !d[a[i]]) ans++;
    printf("%d\n", ans);
    return 0;
    
}

Measured memory_bytes: 20840
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using lint = long long;
using ldouble = long double;

void solve() {
    int n, q;
    std::cin >> n >> q;

    while (q--) {
        int x, y;
        std::cin >> x >> y;
        --x, --y;

        x = std::min(x, n - 1 - x);
        y = std::min(y, n - 1 - y);

        int i = std::min(x, y);
        std::cout << i % 3 + 1 << "\n";
    }
}

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

    solve();

    return 0;
}



Measured memory_bytes: 3228
// Rustで競技プログラミングの入力をスッキリ記述するマクロ
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8

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

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

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

use std::cmp;

fn main() {
  input! {
      s: chars
  };
  let mut ans = 0;
  let mut count = 0;
  for c in s.iter() {
      match *c {
          'A' | 'C' | 'G' | 'T' => count += 1,
          _ => {
              ans = cmp::max(ans, count);
              count = 0;
          }
      }
  }
  ans = cmp::max(ans, count);
  println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			
			String color = sc.next();
			int N =color.length();
			
			int odd_0 = 0;
			int even_0 = 0;
			int odd_1 = 0;
			int even_1 = 0;
			
			
			for (int i=0;i<N;i=i+2) {
				if (color.charAt(i) == '0')
					odd_0+=1;
				else 
					odd_1=odd_1-1;
			}	
			
			for (int i=1;i<N;i=i+2) {
				if (color.charAt(i) == '0')
					even_0+=1;
				else 
					even_1=even_1-1;
			}
			
			
			int ans = Math.max(odd_0-even_1, even_0-odd_1);
			System.out.println(N-ans);
			
		}

	}


Measured memory_bytes: 25196
#include <stdio.h>

int egara(char c){
  if(c=='S')return 0;
  if(c=='H')return 1;
  if(c=='C')return 2;
  if(c=='D')return 3;
  return 0;
}
char Egara(int n){
  if(n==0)return 'S';
  if(n==1)return 'H';
  if(n==2)return 'C';
  if(n==3)return 'D';
  return 'S';
}
int main(){
  int n,a[4][13],i,j,m;
  char c,d;
  for(i=0; i<4; i++){
    for(j=0; j<13; j++){
      a[i][j]=1;
    }
  }
  scanf("%d\n",&n);
  for(i=0; i<n; i++){
    scanf("%c %d\n",&c,&m);
    a[egara(c)][m-1]=0;
  }
for(i=0; i<4; i++){
    for(j=0;j<13; j++){
      if(a[i][j])
      printf("%c %d\n",Egara(i),j+1);
    }
  }
  return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int a[4];
    for(int i=0;i<4;i++) cin>>a[i];
    sort(a,a+4);
    if(a[0]==a[1]&&a[2]==a[3]) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    return 0;
}

Measured memory_bytes: 3128
#include<iostream>
#include<string>
#include<cmath>
#include<iomanip>
#define PI 3.141592653589793238462643383279502884197
using namespace std;

int main() {
double pi = acos(-1);
double a, b, S, L,  h;
int C;
cin >> a >> b >> C;
double c = PI * C / 180;

S = a * b * sin(c) / 2;
L = a + b + sqrt(pow(a,2) + pow(b,2) - 2*a*b*cos(c));
h = b*sin(c);

cout <<  std::fixed << std::setprecision(5) << S << endl;
cout <<  std::fixed << std::setprecision(5) << L << endl;
cout <<  std::fixed << std::setprecision(5) << h << endl;
return 0;
}


Measured memory_bytes: 3464
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = 0;

        for(int i = 0; i < N; i++){
            int c = sc.nextInt();
            int r = sc.nextInt();
            
            ans += r - c + 1;
        }
        System.out.println(ans);
    }
}


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

public class Prime
{
    int n;
    // Sieve of Eratosthenes
    BitArray sieve;

    public Prime(int _n)
    {
        n = _n;
        sieve = new BitArray(n + 1);
        var end = (int)(Math.Sqrt(n) + 0.1);
        for (int i = 2; i <= end; i++)
        {
            if (!sieve.Get(i))
            {
                for (int j = i * 2; j <= n; j += i)
                {
                    sieve.Set(j, true);
                }
            }
        }

        sieve.Set(1, true);
    }

    public bool IsPrime(int i)
    {
        return !sieve.Get(i);
    }
}

class Solution
{
    static void Main()
    {
        var q = int.Parse(Console.ReadLine());
        var l = new int[q];
        var r = new int[q];

        for (int i = 0; i < q; i++)
        {
            var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            l[i] = vals[0];
            r[i] = vals[1];
        }

        var min = l.Min();
        var max = r.Max();
        var prime = new Prime(max);

        var accSum = new int[max + 1];

        for (int i = 1; i <= max; i++)
        {
            var isLike2017 = prime.IsPrime(i) && prime.IsPrime((i + 1) / 2);
            accSum[i] = accSum[i - 1];
            if (isLike2017)
            {
                accSum[i]++;
            }
        }

        for (int i = 0; i < q; i++)
        {
            var x = accSum[r[i]] - accSum[l[i] - 1];
            Console.WriteLine(x);
        }
    }
}

Measured memory_bytes: 18872
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main() {
  int n,m;
  cin >> n >> m;
  int d[n+1];
  fill(d,d+n+1,MAX);
  d[0]=0;
  while(m--) {
    int x;
    cin >> x;
    for(int i=x; i<=n; i++) d[i]=min(d[i],d[i-x]+1);
  }
  pr(d[n]);
  return 0;
}


Measured memory_bytes: 1356
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (100000)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int N, H, as[MAX_N], bs[MAX_N];
  scanf("%d %d", &N, &H);
  for (int i = 0; i < N; i++) {
    scanf("%d %d", &as[i], &bs[i]);
  }

  // sort
  sort(as, as + N);
  sort(bs, bs + N);

  // solve greedy
  //   only one katana needs to be swung
  //   katanas are thrown at the end
  int i_throw_b, i_throw_e = N, hp = H;
  const int max_damage_swing = as[N - 1];
  for (i_throw_b = N; i_throw_b > 0; i_throw_b--) {
    if (bs[i_throw_b - 1] <= max_damage_swing) {
      break;
    }
  }
  int num_throw = 0;
  for (int i = i_throw_e - 1; i >= i_throw_b; i--) {
    if (hp > 0) {
      hp -= bs[i];
      num_throw++;
    } else {
      break;
    }
  }
  const int num_swing =
      hp > 0 ? (hp + max_damage_swing - 1) / max_damage_swing : 0;
  printf("%d\n", num_throw + num_swing);

  return 0;
}


Measured memory_bytes: 896
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			int[] A = new int[n];
			for(int i=0; i<n;i++) {
				A[i] = sc.nextInt();
			}
			int q = sc.nextInt();
			for(int i=0; i<q;i++) {
				int b = sc.nextInt();
				int e = sc.nextInt();
				int k = sc.nextInt();
				int cnt = 0;
				for(int j=b;j<e;j++) {
					if(A[j]==k) cnt++;
				}
				System.out.println(cnt);
			}
		}
	}
}


Measured memory_bytes: 37852
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int dp[N][3], n;
vector<int> gr[N];
void getAns(int v, int par = -1) {
	for (auto u : gr[v]) {
		if (u != par) {
			getAns(u, v);
			dp[v][1] += dp[u][0], dp[v][0] += dp[u][0], dp[v][0] += (dp[u][0] == dp[u][1]);
		}
	}
	dp[v][0] = min(dp[v][0], dp[v][1] + 1);
//	cout << "v = " << v << " : " << dp[v][0] << " : " << dp[v][1] << endl; 
}
int main() {
	ios_base::sync_with_stdio (false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		gr[x].push_back(y), gr[y].push_back(x);
	}
	getAns(0);
	if (dp[0][0] == (n + 1) / 2)
		cout << "Second";
	else
		cout << "First";
	return 0;
}

Measured memory_bytes: 10392
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Control.Arrow
import Data.Ord
import Data.Maybe
import Numeric
import Data.Char
import Text.Printf

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine


r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


main :: IO ()
main = do
    [h,w,k] <- r'
    choco <- replicateM h (map (read.pure) <$> getLine) :: IO[[Int]]
    let sepH = seps (h-1)
    let vert = map (length &&& sepWLO k) $ filter (prep k) $ map (map (foldzip sum) . (\s->sepBy s choco)) sepH
    print $ minimum (map (\(l,v)->l-1+v) vert)

sepWLO :: Int -> [[Int]] -> Int
sepWLO lim xxs = sepWL lim (replicate (length xxs) 0) 0 xxs

prep :: Int -> [[Int]] -> Bool
prep lim xxs = maximum (map maximum xxs) <= lim

sepWL :: Int -> [Int] -> Int -> [[Int]] -> Int
sepWL lim whites seps ([]:xxs) = seps
sepWL lim whites seps xxs = let zipped = zipWith (+) (map head xxs) whites in
    if maximum zipped > lim
    then sepWL lim (map head xxs) (seps+1) (map tail xxs)
    else sepWL lim  zipped         seps    (map tail xxs)



foldzip :: ([Int] -> Int) -> [[Int]] -> [Int]
foldzip f xs
    | null (head xs) = []
    | otherwise = f (map head xs):foldzip f (map tail xs)

sepBy :: [Int] -> [a] -> [[a]]
sepBy [] xs = [xs]
sepBy (0:sp) (x:xs) = (x:) `onHeadOf` (sepBy sp xs)
sepBy (1:sp) (x:xs) = [x]:(sepBy sp xs)

f `onHeadOf` (x:xs) = (f x):xs

seps :: Int -> [[Int]]
seps n = map ((map (read.pure)).(printf ("%0"++show n++"b"))) [0..(2^n :: Int)-1]



Measured memory_bytes: 2428
#include <iostream>

class Point
{
public:
	double m_X;
	double m_Y;

	Point(double x, double y)
		: m_X( x )
		, m_Y( y )
	{}
	~Point() {}
	double DiffX(const Point& rhs) const
	{
		return(rhs.m_X - m_X);
	}

	double DiffY(const Point& rhs) const
	{
		return(rhs.m_Y - m_Y);
	}
};

class Vec
{
	double m_X;
	double m_Y;

public:
	Vec(Point start, Point end)
		: m_X(end.m_X - start.m_X)
		, m_Y(end.m_Y - start.m_Y)
	{
	}
	~Vec() {}

	double CrossProduct(const Vec& rhs)
	{
		return(m_X*rhs.m_Y - m_Y*rhs.m_X);
	}
};

int main()
{
	double ax, ay, bx, by, cx, cy, dx, dy;
	char s;
	while (std::cin >> ax >> s >> ay >> s >> bx >> s >> by >> s >> cx >> s >> cy >> s >> dx >> s >> dy)
	{
		Point a(ax, ay);
		Point b(bx, by);
		Point c(cx, cy);
		Point d(dx, dy);

		Vec ab(a, b);
		Vec bc(b, c);
		Vec cd(c, d);
		Vec da(d, a);

		double cp_ab = ab.CrossProduct(bc);
		double cp_bc = bc.CrossProduct(cd);
		double cp_cd = cd.CrossProduct(da);
		double cp_da = da.CrossProduct(ab);

		if ( (cp_ab > 0 && cp_bc > 0 && cp_cd > 0 && cp_da > 0) || ((cp_ab < 0 && cp_bc < 0 && cp_cd < 0 && cp_da < 0)) )
		{
			std::cout << "YES" << std::endl;
		}
		else
		{
			std::cout << "NO" << std::endl;
		}
	}

	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a.at(i);
  }
  
  int now = a.at(0);
  int count = 1;
  for ( ; ; ){
    if (now == 2){
      cout << count << endl;
      break;
    }
    if (count >= N){
      cout << -1 << endl;
      break;
    }
    now = a.at(now - 1);
    count++;
  }
}

Measured memory_bytes: 640
def main():
    N, M = [int(n) for n in input().split()]
    X = [int(n) for n in input().split()]
    X.sort()
    diffs = [X[i+1]-X[i] for i in range(M-1)] # diffs[i]:=X[i+1]-X[i]
    diffs.sort(reverse=True)
    # print(diffs)
    cut = sum(diffs[:N-1])
    # print(cut)
    print(X[-1] - X[0] - cut)

if __name__ == "__main__":
    main()

Measured memory_bytes: 57512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  int nn = n;
  int fx = 0;
  while(n > 0){
    fx += n%10;
    n /= 10;
  }
  if(nn%fx == 0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

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

using namespace std ;
typedef long long ll;
typedef string str;
typedef vector<int> vint;
typedef vector<double> vdou ;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii ;

#define REP(i, n) for (ll (i) = 0; (i) < (ll)(n); i++) 
#define FOR(i, a, b) for(ll (i) = a; (i) < (ll)b; i++)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (ll)x.size()
#define SP(x)  setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  str s ;
  cin >> s ;
  vstr st ;
  int n = SZ(s) ;
  vint cnt(26,0);
  if(s=="zyxwvutsrqponmlkjihgfedcba"){
    cout << -1 <<endl ;
    return 0 ;
  }
  REP(i,n){
    cnt[s[i]-'a']++ ;
  }
  if(n<=25){
    cout << s ;
    REP(i,26){
      if(cnt[i]==0){
        cout << (char)(i+'a') <<endl ;
        return 0 ;
      }
    }
  }
  else{
    set<char> S ;
    for(int i=n-1;i>=1;i--){
      str hoge = s ;
      S.insert(s[i]) ;
      auto itr = S.begin() ;
      hoge = s.substr(0,i-1) + (*itr) ;
      if(s<hoge){
        set<char> T ;
        REP(j,SZ(hoge)){
          T.insert(hoge[j]) ;
        }
        if(SZ(T)==SZ(hoge)){
          st.PB(hoge) ;
        }
      }
      hoge = s.substr(0,i-1) ;
      REP(j,26){
        hoge[SZ(hoge)-1] =  (char)(hoge[SZ(hoge)-1]+1) ;
        if(hoge[SZ(hoge)-1]-'a'<0 ||hoge[SZ(hoge)-1]-'a'>=26){
        continue ; ;
        }
        if(s<hoge){
          set<char> T ;
          REP(j,SZ(hoge)){
            T.insert(hoge[j]) ;
          }
          if(SZ(T)==SZ(hoge)){
            st.PB(hoge) ;
          }
        }
      }
    }
  }
  sort(ALL(st)) ;
  cout << st[0] <<endl ;
        
   
  return 0 ;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef unsigned long long ull;
ull base=13;
ull a[10010];
char s[10010];
int n,m,q,ans=1;
int b[50001];
int prime=10007; 
ull mod=10009;
bool cmp(int a,int b)
{
    return a>b;
}
ull hashe(char s[])
{
    int len=strlen(s);
    ull ans=0;
    for (int i=0;i<len;i++)
    ans=(ans*base+(ull)s[i])%mod+prime;
    return ans;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%s",s);
        q=hashe(s);
		b[q]++;
    }
	scanf("%d",&m);
	for(int i=1;i<=m;i++)
    {
        scanf("%s",s);
        q=hashe(s);
		b[q]--;
    }
    sort(b,b+50001,cmp);
    if(b[0]<=0) 
			{
			cout<<"0"<<endl;
			return 0;
			}
	cout<<b[0]<<endl;
	return 0;
} 

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

int main()
{
	int n,k;
	cin>>n>>k;
	int arr[n];
	int dp[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	dp[0]=0;
	for(int i=1;i<min(k,n);i++)
	{
		dp[i]=abs(arr[i]-arr[0]);
	}
	for(int j=k;j<n;j++)
	{
		dp[j]=INT_MAX;
		for(int h=1;h<=k;h++)
		{
			dp[j]=min(dp[j],dp[j-h]+abs(arr[j]-arr[j-h]));
		}
	}
	cout<<dp[n-1]<<endl;
return 0;
}

Measured memory_bytes: 1024
//#pragma GCC optimize("-Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()

const ld pi=3.14159265359;
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

inline ll add(ll a,ll b,ll m){
    if((a+b)>=m)return (a+b)%m;
    return a+b;
}

inline ll mul(ll a,ll b,ll m){
    if((a*b)<m)return a*b;
    return (a*b)%m;
}

int main(){
    int n;cin>>n;
    vector<ll> v(n);
    map<ll,ll> m;
    ll sum=0;
    rep(i,0,n)cin>>v[i],m[v[i]]++,sum+=v[i];
    int q;cin>>q;
    fastio;
    while(q--){
        ll b,c;cin>>b>>c;
        sum+=m[b]*(c-b);
        m[c]+=m[b];
        m[b]=0;
        cout<<sum<<endl;
    }
}


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

#define mp make_pair
#define pb push_back
#define ll long long int
#define sd(x) scanf("%lld",&x)
#define inf 1000000000000000000
#define pll pair<ll,ll>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define bits(x) __builtin_popcountll(x)
#define ld long double
#define test() ll test; cin>>test; while(test--)
#define fi first
#define se second


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


inline ll GCD(ll x, ll y) {
    if(x<y) swap(x,y);
    if(x==0) return y;
    if(y==0) return x;
    return GCD(x%y,y);
}

ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}

ll power(ll x, ll n, ll mod) {
    ll res = 1;
    x %= mod;
    while(n) {
        if(n&1) {
            res = ((res*x)%mod+mod)%mod;
        }
        x = ((x*x)%mod+mod)%mod;
        n>>=1;
    }

    return res;
}

int main() {
    fastio;

    ll n;
    cin>>n;

    vector<pll> v;

    ll x,y;

    for(ll i=0;i<n;i++) {
        cin>>x>>y;
        v.pb(mp(x,y));
    }

    for(ll i=0;i<=n-3;i++) {
        if(v[i].fi==v[i].se && v[i+1].fi==v[i+1].se && v[i+2].fi==v[i+2].se) {
            cout<<"Yes"<<endl;
            return 0;
        }
    }

    cout<<"No"<<endl;

    
}




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


int main() {
  int a, b, c;
  cin >> a >> b >> c;
  string ans = "No";
  if(c >= a && c <= b) ans = "Yes";
  cout << ans << endl;
  return 0;
  
}

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

int64_t MOD = 1e9 + 7;

/* 冪乗　*/
int64_t power ( int64_t a, int64_t n){
    if ( n == 0 ) return 1;
    int64_t res = 1;
    while ( n > 0 ){
        if ( n % 2 == 1 ){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        n = n / 2;
    }
    return res;
}

/* 逆元　*/
int64_t inv ( int64_t a ){
    return power(a,MOD-2);
}
/* フルマーの小定理 */

/* 組み合わせ　*/
int64_t nCr (int64_t n, int64_t r){
    int64_t numerator = 1, denominator = 1;
    for ( int64_t i = 0; i < r; ++i){
        numerator = numerator * ( n - i ) % MOD;
        denominator = denominator * ( i + 1 ) % MOD;
    }
    return numerator * inv(denominator) % MOD;
}

int main(){
    int64_t n,a,b;
    cin >> n >> a >> b;
    int64_t ans;
    
    ans = power(2,n) - nCr(n, a) - nCr(n, b) - 1;
    
    while (ans < 0) {
        ans += MOD;
    }
    cout << ans << 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 (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * 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};

ll n, a, b, c, d;
string s;
bool hantei(ll start, ll goal){
  for(ll i = start; i < goal; i++){
    if(s[i] == '#' && s[i + 1] == '#') return false;
  }
  return true;
}
int main(){
  cin >> n >> a >> b >> c >> d; cin >> s;
  a--; b--; c--; d--;
  bool ans = hantei(a, c) && hantei(b, d);
  if(d < c){
    bool tmp = false;
    for(ll i = b; i <= d; i++){
      if(s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.'){
        tmp = true;
        break;
      }
    }
    ans = ans && tmp;
  }
  cout << ((ans) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int n,a[100],b[100],c[100],i,p,t,s,f;
    scanf("%d",&n);
    s=0;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
    for(i=0;i<(n-1);i++)
    {
        scanf("%d",&c[i]);
    }
    for(i=0;i<n;i++)
    {
        p=i-1;
        if(i==0||a[i]!=a[p]+1)
        {
            t=a[i]-1;
            s=s+b[t];
        }
        else
        {
            t=a[i]-1;
            f=a[i]-2;
            s=s+b[t]+c[f];
        }
    }
    printf("%d\n",s);
    return 0;
}


Measured memory_bytes: 128