akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3

A, B, C = list(map(int, input().split()))


def is_continue(x_list):
    for x in x_list:
        if x % 2 == 1:
            return False
    return True


count = 0

while is_continue([A, B, C]):
    if A == B and B == C:
        count = -1
        break
    a, b, c = A, B, C
    a = B // 2 + C // 2
    b = A // 2 + C // 2
    c = A // 2 + B // 2
    A, B, C = a, b, c
    count += 1

ans = count
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long

void solve()
{
    ll n;
    cin >> n;
    vector<ll> p(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> p.at(i);
    }

    ll count = 0;
    for (ll i = 1; i < n - 1; i++)
    {
        if (p.at(i - 1) < p.at(i) && p.at(i) < p.at(i + 1) || p.at(i - 1) > p.at(i) && p.at(i) > p.at(i + 1))
        {
            count++;
        }
    }
    cout << count << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
//Only for codeforces
#include<bits/stdc++.h>
using namespace std;
//#define ll long long int
#define ld long double
#define int long long
#define pb push_back 
#define mod 1000000007
#define mod2 998244353
#define Z(c) (int)(c).size()
#define F first
#define S second
#define nl "\n"
//#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define clber cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define rep(i,iv,n) for(int (i)=(iv);(i)<(n);(i)++)
#define D1(x) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<nl
#define D2(x,y) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<nl
#define D3(x,y,z) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<nl
#define pi 3.1415926536
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define tr(it,ct) for(auto &(it) : (ct))
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
typedef vector< pii > vp;

int power(int a,int n,int lelo)
{
        if(n==0)
                return 1;
        if(n==1)
                return a;
        if(n==2)
                return (a*a)%lelo;
        if(n%2)
                return (a*power(a,n-1,lelo))%lelo;
        else
                return power(power(a,n/2,lelo),2,lelo)%lelo;
}


void swap(int &a,int &b)
{ int tm=a; a=b; b=tm; }

 const int N=1e+5;
 

void solve()
{ 
  int n,w; cin>>n>>w; vi v(n+1),a(n+1); rep(i,1,n+1) cin>>a[i]>>v[i];
  int dp[w+1]={0};
  
  rep(i,1,n+1)
  for(int j=w;j>=a[i];j--)
  dp[j]=max(dp[j-a[i]]+v[i],dp[j]);
  cout<<dp[w];
 /* rep(i,0,w+1)
  cout<<i<<" "<<dp[i]<<nl;  */
}


signed main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0); 
  
  
  
  int t=1;
   
//  cin>>t;
rep(i,1,t+1)
  { // cout<<"Case #"<<i<<": ";
   solve();
   
   if(i<t)
   cout<<"\n";
  }
 
 
 return 0; 
}

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

int main(){
  ll N, K;
  cin >> N >> K;
  
  vector<ll> num(100001, 0);
  for (int i = 0; i < N; i++){
    ll a, b;
    cin >> a >> b;
    num.at(a) += b;
  }
  
  ll pos = 0, ans = 0;
  while (pos < K){
    pos += num.at(ans);
    ans++;
  }
  
  cout << ans - 1 << endl;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    string s;
    cin>>s;
    bool ok=true;
    for(int i = 0; i < 3; i++)
    {
        if(s[i]==s[i+1])
        {
            ok=false;
            break;
        }
    }
    if(ok) cout<<"Good"<<endl;
    else cout<<"Bad"<<endl;
 
    return 0;
}

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

#define ll long long
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))

const int N =100;

bool isprime(int n)
{
    if (n <= 1)
        return false;
    for (int i = 2; i*i<=n; i++)
        if (n % i == 0)
            return false;

    return true;
}
int binarySearch(int arr[], int l, int r, int x)
{
    if (r >= l) {
        int mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
long long lcm(long long a,long long b)
{
    long long p,r;
    p = a*b;
    r = __gcd(a, b);
    return p/r;
}
bool ispalindrome(string s)
{
    int n = s.length();
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-i-1])
            return false;
    }
    return true;
}
bool isPerfectSquare(long double x)
{
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);

}
ll f(ll n) {
	return n * (n - 1) / 2;
}
bool cmp(const tuple<int, string, string>& a,
               const tuple<int, string, string>& b)
{
    return (get<0>(a) < get<0>(b));
}
void solve()
{
   int n;
   cin>>n;
   long long a[n];
   for(int i=0;i<n;i++)
   {
       cin>>a[i];
   }
   int ans=0;
   for(int i=0;i<n;i++)
   {
       for(int j=i+1;j<n;j++)
       {
           for(int k = j+1;k<n;k++)
           {
               if(a[i]+a[j]>a[k] && a[j]+a[k]>a[i] && a[i]+a[k]>a[j] && a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k])
                ans++;
           }
       }
   }
   cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

long comb(long n){
    return (n * (n-1)) /2;
}

int main(){
    long N; cin >> N;
    map<long, long> A; //入力個数のマップ
    vector<long> A_origin; // 入力列A
    long temp;  
    for(int i = 0; i < N; i++){
        cin >> temp;
        A_origin.push_back(temp);
        A[temp]++;
    }
    //　とらない場合の組み合わせ
    map<long,long>comb_map;
    long total = 0;
    for(auto itr = A.begin(); itr != A.end(); itr++){
       comb_map[itr->first] = comb(itr->second);
       total += comb_map[itr->first];
    }
    // 一個とった場合の組み合わせ
    map<long,long>taken_comb;
    for(auto itr = A.begin(); itr != A.end(); itr++){
       taken_comb[itr->first] = comb(itr->second-1);
    }

    long ans = 0;
    for(auto itr = A_origin.begin(); itr != A_origin.end(); itr++){
         ans = (total - comb_map[*itr]) + taken_comb[*itr];
         cout << ans << endl;
    }


    // チェック
    /*
    for(auto itr = A.begin(); itr != A.end(); itr++){
       cout << itr -> first << ":" << itr-> second <<endl;
    }
    for(auto itr = taken_comb.begin(); itr != taken_comb.end(); itr++){
       cout << itr -> first << ":" << itr-> second <<endl;
    }
    */
}

Measured memory_bytes: 26864
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    ll n;
    ll A[1000000];
    cin >> n;
    REP(i, n) cin >> A[i];

    ll minus=0;
    ll abs_min=1e9;
    REP(i, n){
        if(A[i]<0) minus++;
        abs_min=min(abs(A[i]), abs_min);
    } 

    ll ans=0;
    REP(i, n) ans+=abs(A[i]);

    // cout << "ans is " << ans << endl;
    if(minus % 2 == 1) ans = ans-abs_min*2;
    // cout << "abs_min is " << abs_min << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    int max_n = 1e6+1, INF = max_n+1;

    // max_nを超えるまで、正四面体数を用意する
    vector<int> st, ost;
    int tn = 0, ti = 1;
    while (tn <= max_n) {
        tn = ti * (ti+1) * (ti+2) / 6;
        st.emplace_back(tn);
        if (tn % 2 == 1) {
            ost.emplace_back(tn);
        }
        ti += 1;
    }

    // 全ての数を使用する
    vector<int> dp(max_n+1, INF);
    dp[0] = 0;
    rep(i, max_n) {
        rep(j, st.size()) {
            if (i+1 - st[j] >= 0) {
                dp[i+1] = min(dp[i+1], dp[i+1 - st[j]] + 1);
            }
        }
    }

    // 奇数だけ使用
    vector<int> odp(max_n+1, INF);
    odp[0] = 0;
    rep(i, max_n) {
        rep(j, ost.size()) {
            if (i+1 - ost[j] >= 0) {
                odp[i+1] = min(odp[i+1], odp[i+1 - ost[j]] + 1);
            }
        }
    }

    int N;
    while(cin >> N) {
        if (N == 0){
            break;
        }
        cout << dp[N] << " " << odp[N] << endl;
    }

    return 0;
}


Measured memory_bytes: 10576
N = int(input())
S = input()

ans = S.count("R")*S.count("G")*S.count("B")

for i in range(N-2):
    for j in range(i+1, N-1):
        k = j-i + j
        if k < N and S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            ans -= 1

print(ans)

Measured memory_bytes: 9204
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    static Map<Integer, Integer> map = new HashMap<>();

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();

        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }

        /*//note the value of k
        if (k > arr.length) {
            k = arr.length;
        }*/

        System.out.println(solve(arr, arr.length - 1, k));
    }

    public static int solve(int[] arr, int index, int k) {

        //note
        if (k > index) {
            k = index;
        }
        //memoization
        if (map.containsKey(index)) {
            return map.get(index);
        }
        //base case
        if (index == 0) {
            return 0;
        }

        //recursive case
        int min = Integer.MAX_VALUE;
        for (int i = 1; i <= k; i++) {
            min = Math.min(min, (solve(arr, index - i, k) + Math.abs(arr[index] - arr[index - i])));
        }
        map.putIfAbsent(index, min);
        return min;
    }


}


Measured memory_bytes: 176160
N = int(input())
D = [list(map(int,input().split())) for i in range(N)]

for i in range(N-2):
    if D[i][0] == D[i][1] and D[i+1][0] == D[i+1][1] and D[i+2][0] == D[i+2][1]:
        print("Yes")
        break
else:
    print("No")


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

line = input().split(" ")
A = int(line[0])
B = int(line[1])
C = int(line[2])
X = int(line[3])
Y = int(line[4])

ret = 99999999999
for a in range(X+1):
    t = a*A
    t += (X-a)*2*C
    if Y-(X-a)>0:
        t += (Y-(X-a))*B

    if t<ret:
        ret = t

for b in range(Y+1):
    t = b*B
    t += (Y-b)*2*C
    if X-(Y-b)>0:
        t += (X-(Y-b))*A

    if t<ret:
        ret = t
print(ret)


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

int main() {
    long long h,w;
    long long ans=0;
    cin>>h>>w;
    if(h==1 || w==1){
        cout<<"1";
    }
    else if((h*w)%2==0){
        ans=(h*w)/2;
        cout<<ans;
    }
    else{
        ans=((h*w)/2)+1;
        cout<<ans;
        
    }
    return 0;
       
}

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

using namespace std;

#define ll long long
#define ld long double

vector<vector<int>> g;
int n, m;
bool used[1000];

vector<int> tps;

bool exist(int s, int t) {
	if (g[s].size() == 0) return false;
	if (lower_bound(g[s].begin(), g[s].end(), t) == g[s].end())
		return false;
	if (*lower_bound(g[s].begin(), g[s].end(), t) == t)
		return true;
	return false;
}

void dfs(int u) {
	if (used[u]) return;
	used[u] = true;
	for (auto& i : g[u]) dfs(i);
	// 帰りがけ順で追加
	tps.push_back(u);
}

void tsort() {
	for (int i = 0; i < n; ++i) dfs(i);
	reverse(tps.begin(), tps.end());
}


signed main() {
	cin >> n >> m;
	g.resize(n);
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		g[a].push_back(b);
	}
	for (int i = 0; i < n; ++i)
		sort(g[i].begin(), g[i].end());

	tsort();
	//for (int i : tps) cout << i << " ";
	//cout << endl;

	vector<bool> visited(n, false);
	for (int i = 0; i < tps.size(); ++i) {
		visited[tps[i]] = true;
		for (auto c : g[tps[i]]) {
			if (visited[c]) {
				// TODO
				cout << 0 << endl;
				exit(0);
			}
		}
	}

	cout << -1 << endl;

	return 0;
}


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

using namespace std;

int N;
int arr[25];

int main(){
    cin >> N;
    for(int i=1 ; i<=N; i++){
        cin >> arr[i];
    }
    int ans = 0;
    for(int i= 2; i<N; i++){
        if(max(arr[i-1], arr[i+1]) > arr[i] && min(arr[i-1], arr[i+1]) < arr[i]){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  (k : n : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  as <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    ds = zipWith subtract as (tail as ++ [head as + k]) :: [Int]
    m = maximum ds :: Int
  print $ k - m

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 8956
using System;
class Program
{
    static void Main(string[] args)
    {
        //// 整数の入力
        //int a = int.Parse(Console.ReadLine());
        //// スペース区切りの整数の入力
        //string[] input = Console.ReadLine().Split(' ');
        //int b = int.Parse(input[0]);
        //int c = int.Parse(input[1]);
        //// 文字列の入力
        //string s = Console.ReadLine();
        ////出力
        //Console.WriteLine((a + b + c) + " " + s);


        int n = int.Parse(Console.ReadLine());
        int[] order = new int[n];
        
        
        string[] AA = Console.ReadLine().Split(' ');
        for(int i = 0; i < AA.Length; i++)
        {
            order[int.Parse(AA[i]) - 1] = i+1;
        }
        foreach (var o in order)
        {
            Console.Write(o + " ");
        }
    }
}


Measured memory_bytes: 22616
//i ll be the king
#include<bits/stdc++.h>
#define ll long long int
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_orde(ind)
using namespace std;
int main()
{
	sync;
	ll a,b,c;
	cin>>a>>b>>c;
	cout<<max({a,b,c})*9+a+b+c;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
const int N = 1e6+7;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = acos(0.0) * 2;
int a;
char s1[54];
char s2[54];
int main() {
    while(~scanf("%d%s%s",&a,s1+1,s2+1)) {
        LL ans = 1;
        for(int i = 1;i<=a;i++) {
            if(s1[i] == s2[i]&&i == 1) ans *= 3;
            else if(s1[i] == s1[i+1]&&s2[i] == s2[i+1]&&i == 1) {
                ans *= 6;
                i++;
            }
            else if(s1[i] == s2[i]&&s1[i-1] == s2[i-1]) ans *= 2;
            else if(s1[i] == s2[i]&&s1[i-1] == s1[i-2]) ans *= 1;
            else if(s1[i] == s1[i+1]&&s1[i-1] == s1[i-2]) {
                ans *= 3;
                i++;
            }
            else if(s1[i] == s1[i+1]&&s1[i-1] == s2[i-1]) {
                ans *= 2;
                i++;
            }
        }
        printf("%lld\n",ans%MOD);
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
/**
 * Main
 */
public class Main {
       static int mod  = 1000000007;
        static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] args) {
       MyScanner ms  = new MyScanner();
        double side = ms.nextDouble();
        side/=3;
        pw.println(side*side*side);
        pw.flush();
       
      

    pw.flush();

    }public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
   
        public MyScanner() {
           br = new BufferedReader(new InputStreamReader(System.in));
        }
   
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
   
        int nextInt() {
            return Integer.parseInt(next());
        }
   
        long nextLong() {
            return Long.parseLong(next());
        }
   
        double nextDouble() {
            return Double.parseDouble(next());
        }
   
        String nextLine(){
            String str = "";
        try {
           str = br.readLine();
        } catch (IOException e) {
           e.printStackTrace();
        }
        return str;
        }
  
     }
}

Measured memory_bytes: 20948
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;

struct Timer {

    double CYCLE_PER_SEC = 2400000000.0;
    unsigned long long BEGIN_CYCLE = 0;

    Timer() {}
    Timer(double cycle) : CYCLE_PER_SEC(cycle) {}

    unsigned long long int getCycle() {
        unsigned int low, high;
        __asm__ volatile ("rdtsc" : "=a" (low), "=d" (high));
        return ((unsigned long long int)low) | ((unsigned long long int)high << 32);
    }

    void start(void) {
        BEGIN_CYCLE = getCycle();
    }

    double get_time(void) {
        return (double)(getCycle() - BEGIN_CYCLE) / CYCLE_PER_SEC;
    }

} timer;

int N;
char flag[512];
char S[512 * 512];
char str[512];

int main() {

    scanf("%d", &N);
    for (int i = 0; i < N; i++) scanf("%s", S + (i << 9));

    fill(flag, flag + N, 1);
    str[N] = '\0'; 

	// timer.start();

    for (int j = 0; j < N; ++j) {
        for (int i = 0; i < N; i++) {
            str[i] = S[(i << 9) + j];
        }
        for (int i = 0; i < N; ++i) {
            int row = (i + j) % N;
            if (strcmp(S + (row << 9), str)) flag[i] = 0;
            std::rotate(str, str + 1, str + N);
        }
    }

    int res = 0;
    for (int i = 0; i < N; i++) {
        if (flag[i]) {
            res += (i + 1);
            if (i + N <= (N - 1) * 2) {
                res += (N - 1) * 2 + 1 - (i + N);
            }
        }
    }

    // cerr << timer.get_time() << endl;

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

    return 0;
}



Measured memory_bytes: 384
n = gets.strip.to_i
p = gets.strip.split.map { |v| v.to_i }
q = gets.strip.split.map { |v| v.to_i }

def permutation_order(n, permutation)
  a = (1..n).to_a
  order = 1
  (0..n-2).each do |i|
    order += (a.index(permutation[i]) - 1) * (1..n-i-1).inject(1,:*)
    a.delete(permutation[i])
  end

  order
end

puts (permutation_order(n, p) - permutation_order(n, q)).abs


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int main () {
  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i,n) cin >> a[i];
  
  int a_mi = *min_element(rng(a));
  int cnt = 0;
  rep(i,n) {
    if (a[i] != a_mi) cnt++;
  }

  int ans = dup(cnt, k-1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,M=map(int,input().split())
    A=sorted(list(map(int,input().split())))
    S=[0]*(N+1)
    for i in range(N):
        S[i+1]=S[i]+A[i]
    def nibutan(ok,ng):
        while abs(ok-ng) > 1:
            mid = (ok + ng) // 2
            if solve(mid):
                ok = mid
            else:
                ng = mid
        return ok
    
    def solve(mid):
        c=0
        for i in range(N):
            c+=N-bisect_left(A,mid-A[i])
        if c>=M:
            return True
        else:
            return False
        
    x=nibutan(0,10**11)
    ans=0
    count=0
    for i in range(N):
        b_l=bisect_left(A,x-A[i])
        count+=(N-b_l)
        ans+=S[N]-S[b_l]+A[i]*(N-b_l)
    if count==M:
        print(ans)
    else:
        print(ans+(M-count)*x)
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 55684
#include <iostream>
#include <cstdlib>
#include <vector>

#define POSITIVE 1
#define ZERO 0
#define NEGATIVE -1
#define SWAP_SIGN(s) (s * -1)

using namespace std;


int getsign(long long int n){
	if(n > 0){
		return POSITIVE;
	}
	if(n < 0){
		return NEGATIVE;
	}
	return ZERO;
}

long long int count(int sign0, vector<long long> a, int n){
	long long int sum = 0;
	long long int sign = sign0;
	long long int count = 0;

	for(int i=0; i<n; ++i){
		sum += a[i];
		if (getsign(sum) != sign){
			count += abs(sign - sum);
			sum = sign;
		}
		sign = SWAP_SIGN(sign);
	}

	return count;
}



int main(){
	int n;

	cin >> n;

	vector<long long> a(n);

	for(int i=0;i<n;++i){
		cin >> a[i];
	}

	cout << min(count(POSITIVE,a,n),count(NEGATIVE,a,n)) << endl;
	return 0;
}


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


int calc(int x,int r){
	return x * (r+100) / 100;
}
int main(){
	int x,y,s;
	while(cin >> x >> y >> s && x){
		int ans = 0;
		for(int i = 1 ; i <= s-1 ; i++){
			for(int j = 1 ; j <= s-1 ; j++){
				int sum = calc(i,x) + calc(j,x);
				if( s == sum ){
					ans = max(ans,calc(i,y)+calc(j,y));
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>

using namespace std;

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

  if( S[ 0 ] == 'A' )
  {
    int index = S.find( "C" );
    if( ( index >= 2 ) && ( index <= ( S.length() - 2 ) ) )
    {
        auto isUpperCase = []( char c )
        {
          return ( c >= 'A' ) && ( c <= 'Z' );
        };

        int upperCaseNum = 0;
        for( auto c : S )
        {
          if( isUpperCase( c ) )
          {
            ++upperCaseNum;
          }
        }

        if( upperCaseNum == 2 )
        {
          cout << "AC" << endl;
          return 0;
        }
    }
  }

  cout << "WA";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <functional>
#include <list>
#include <utility>
#include <map>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))
const ll mod = 1000000007;
const double eps = 1e-10;
const int MAX = 200000;

int main() {
	int n, m, k;
	cin >> n >> m;
  vector<int> v;
  rep(i, m) {
    cin >> k;
    v.push_back(k);
  }
  sor(v);
  vector<int> d;
  rep(i, m-1) {
    d.push_back(v.at(i + 1) - v.at(i));
  }
  sor(d);
  int sum = 0;
  if (m - n < 1) {
    cout << 0 << endl;
  } else {
    rep(i, m-n) {
      sum += d.at(i);
    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define mod 1000000007
ll k;
ll Frog_Problem(ll n, ll a[], ll dp[]) {
    if (n <= 0) {
        return 0;
    }
    if (dp[n] != -1) {
        return dp[n];
    }
    ll ans = INT_MAX;
    for (int i = 1; i <= k; i++) {
        if (n - i >= 0) {
            ans = min(ans, abs(a[n] - a[n - i]) + Frog_Problem(n - i, a, dp));
        }
    }
    return dp[n] = ans;
}
int main() {
    fio;
    ll n;
    cin >> n;
    cin >> k;
    ll a[n];
    ll dp[n];
    memset(dp, -1, sizeof(dp));
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    cout << Frog_Problem(n - 1, a, dp);
    return 0;
}

Measured memory_bytes: 12984
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
int h, w;
vector<string> b;
vector<vector<ll>> dp;
const ll MOD = 1e9 + 7; 

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> h >> w;
    b.assign(h, "");
    dp.assign(h, vector<ll>(w, 0));
    F0R(i, h) cin >> b[i];    
    dp[0][0] = 1;
    F0R(i, h)
    {
        F0R(j, w)
        {
            if(i > 0) dp[i][j] += dp[i - 1][j];
            if(j > 0) dp[i][j] += dp[i][j - 1];
            if(b[i][j] == '#') dp[i][j] = 0;
            dp[i][j] %= MOD;
        }
    }
    cout << dp[h - 1][w - 1];
    return 0;
}

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

class Program
{

	static void Main(string[] args)
	{
		// スペース区切りの整数の入力
		var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
		var targetList = new List<int>();
		// 最初に指定された値までループ
		for (int i = 1; i <= input[0]; i++)
		{
			var sum = 0;
			var checkTargetValue = i;
			while (checkTargetValue > 0)
			{
				sum += checkTargetValue % 10;
				checkTargetValue = checkTargetValue / 10;
			}

			if (sum >= input[1] && input[2] >= sum)
			{
				targetList.Add(i);
			}
		}
		var answer = targetList.Sum();
		Console.WriteLine(answer);
	}

}

Measured memory_bytes: 13320
n, m = [int(i) for i in input().split()]
e = [[] for _ in range(n)]
for _ in range(m):
    a, b = [int(i)-1 for i in input().split()]
    e[a].append(b)
    e[b].append(a)

used = [False] * n
used[0] = True
ans1 = [1]
ans2 = []
i = 0
while True:
    for j in e[i]:
        if not used[j]:
            i = j
            ans1.append(j + 1)
            used[j] = True
            break
    else:
        break
i = 0
while True:
    for j in e[i]:
        if not used[j]:
            i = j
            ans2.append(j + 1)
            used[j] = True
            break
    else:
        break

ans = list(reversed(ans2)) + ans1

print(len(ans))
print(" ".join(map(str, ans)))


Measured memory_bytes: 33700
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  int i,j,k;
  int x,y;
  set<int> s;
  int d[n];
  for(i=0;i<n;i++) d[i]=1;
  s.insert(0);
  for(i=0;i<m;i++){
    cin >> x >> y;
    x--;y--;
    d[x]--;d[y]++;
    if(s.find(x)!=s.end()){
      s.insert(y);
      if(d[x]==0) s.erase(x);
    }
  }
  cout << s.size() << endl;
  return 0;
}


Measured memory_bytes: 5376
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){

    int A;
    int B;
    
    cin >> A;
    cin >> B;

    if(B>=A) cout << "unsafe" << endl;
    else cout << "safe" << endl;

}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  ll N;
  cin>>N;
  vector<ll> A(5);
  rep(i,5) cin>>A[i];
  sort(all(A));
  ll ans=5+N/A[0];
  if(N%A[0]==0) ans--;
  cout<<ans<<endl;
}



Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
ans = 'Yes'
for i in range(1, N):
    j = N - i
    if not H[j - 1] > H[j]:
        continue
    elif H[j - 1] - H[j] == 1:
        H[j - 1] -= 1
        continue
    else:
        ans = 'No'
        break
print(ans)


Measured memory_bytes: 14396
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <string>

using namespace std;

void solve();

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

void solve() {
    int n;
    cin >> n;
    int p[n];
    for(int i = 0; i < n; i++) {
        cin >> p[i];
    }
    int ma = 0;
    for(int i = 0; i <= n; i++) {
        int count = 0;
        for(int j = 0; j < n; j++) {
            if(p[j] >= i) count++;
        }
        if(count >= i) ma = i;
    }
    cout << ma << endl;




}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1005,INF=1<<25;
vector<int> prime;//i番目の素数
bool is_prime[MAX*MAX+1];

void sieve(int n){
    for(int i=0;i<=n;i++){
        is_prime[i]=true;
    }
    
    is_prime[0]=is_prime[1]=false;
    
    for(int i=2;i<=n;i++){
        if(is_prime[i]){
            prime.push_back(i);
            for(int j=2*i;j<=n;j+=i){
                is_prime[j] = false;
            }
        }
    }
}
int id[MAX][MAX];
pair<int,int> dp[MAX][MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    sieve(1000003);
    
    for(int i=0;i<MAX;i++){
        for(int j=0;j<MAX;j++){
            id[i][j]=INF;
        }
    }
    
    ll t=0;
    
    int i=501,j=501;
    vector<int> whi(1000003),whj(1000003);
    for(ll k=1;k<=1000000;k++){
        id[i][j]=k;
        whi[k]=i;
        whj[k]=j;
        
        if(k>t*t) t++;
        if(t%2==1){
            if(k<=(t-1)*t) i++;
            else j++;
        }else{
            if(k<=(t-1)*t) i--;
            else j--;
        }
    }
    
    while(1){
        int M,N;cin>>M>>N;
        if(M+N==0) break;
        
        for(int i=0;i<MAX;i++){
            for(int j=0;j<MAX;j++){
                dp[i][j]={-INF,0};
            }
        }
        int i=whi[N],j=whj[N];
        dp[i][j].first=0;
        if(is_prime[N]){
            dp[i][j].first=1;
            dp[i][j].second=N;
        }
        
        for(int a=i;a<=1002;a++){
            for(int b=1;b<=1002;b++){
                for(int c=-1;c<=1;c++){
                    if(id[a+1][b+c]>M) continue;
                    
                    if(is_prime[id[a+1][b+c]]){
                        dp[a+1][b+c]=max(dp[a+1][b+c],{dp[a][b].first+1,id[a+1][b+c]});
                    }else{
                        dp[a+1][b+c]=max(dp[a+1][b+c],dp[a][b]);
                    }
                }
            }
        }
        
        pair<int,int> ans={-INF,0};
        
        for(int i=0;i<MAX;i++){
            for(int j=0;j<MAX;j++){
                ans=max(ans,dp[i][j]);
            }
        }
        
        cout<<ans.first<<" "<<ans.second<<endl;
        
    }
}





Measured memory_bytes: 23788
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int N;
	scanf("%d", &N);
	int i, a[100000 + 2] = {};
	int real_length = 0;
	a[0] = 0, a[N + 1] = 0;
	for ( i = 0; i < N; i++)
	{
		scanf("%d", &a[i + 1]);
		real_length += abs(a[i] - a[i + 1]);
	}
	real_length += abs(a[N]);

	for ( i = 1; i <= N; i++)
	{
		printf("%d\n", real_length - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]));
	}
	return 0;
}

Measured memory_bytes: 1536
//C - Good Sequence: 
//Assunto: 
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100005
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, x, ans = 0;
    map<int, int> seq;
    cin >> n;
    loop(i, 0, n) {
        cin >> x;
        seq[x]++;
    }
    for(auto x : seq) {
        if(x.fi > x.se) {
            ans += x.se;
        } else if(x.fi < x.se) {
            ans += x.se - x.fi;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 4736
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>

using namespace std;

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

typedef long long ll;
const int Mod = static_cast<int>(1e9 + 7);

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	bool ans = false;
	while (1) {
		c -= b;
		if (c <= 0) {
			ans = true;
			break;
		}
		a -= d;
		if (a <= 0) break;
	}
	if (ans)  cout << "Yes" << endl;
	else  cout << "No" << endl;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A <= C && C <= B)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim(){
   int u, minv;
   int d[MAX], p[MAX], color[MAX];

   for(int i = 0; i < n; i++){
     d[i] = INFTY;
     p[i] = -1;
     color[i] = WHITE;
   }

   d[0] = 0;

   while(1){
     minv = INFTY;
     u = -1;
     for(int i = 0; i < n; i++){
       if(minv > d[i] && color[i] != BLACK){
         u = i;
         minv = d[i];
       }
     }
     if(u == -1) break;
     color[u] = BLACK;
     for(int v = 0; v < n; v++){
       if(color[v] != BLACK && M[u][v] != INFTY){
         if(d[v] > M[u][v]){
           d[v] = M[u][v];
           p[v] = u;
           color[v] = GRAY;
         }
       }
     }
   }
   int sum = 0;
   for(int i = 0; i < n; i++){
     if(p[i] != -1) sum += M[i][p[i]];
   }

   return sum;
}

int main(){
  cin >> n;

  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      int e; cin >> e;
      M[i][j] = (e == -1) ? INFTY : e;
    }
  }

  cout << prim() << endl;

  return 0;
}

Measured memory_bytes: 1200
n, a, b = map(int, input().split())
arr = []
for i in range(n):
  i = str(i + 1)
  k = 0
  for e in range(len(i)):
    k += int(i[e])
  if a <= k and k <= b:
    arr.append(int(i))
print(sum(arr))

Measured memory_bytes: 3284
import java.util.*;
class Main{
	void aa(){
		Scanner sc=new Scanner(System.in);
		while(true){
			int A=sc.nextInt();
			if(A==0)break;
			long B=0;
			int[] D=new int[A-1];
			for(int i=0;i<A;i++)B+=sc.nextInt();
			for(int i=0;i<A-1;i++)D[i]=sc.nextInt();
			Arrays.sort(D);
			long max=0;
			for(int i=A;i>0;i--){
				if(max<B*i)max=B*i;
				if(i!=1)B+=D[i-2];
			}
			System.out.println(max);
		}
	}
	public static void main(String[]arg){
		new Main().aa();
	}
}

Measured memory_bytes: 158880
#include <stdio.h>

int main(void) {

  int num[3];
  int i, j;
  int temp;

  scanf("%d %d %d", &num[0], &num[1], &num[2]);

  for (i = 0; i < 3; i++) {
    for (j = 2; j > i; j--) {
      if(num[j - 1] > num[j]) {
        temp = num[j];
        num[j] = num[j - 1];
        num[j - 1] = temp;
      }
    }
  }

  printf("%d %d %d\n", num[0], num[1], num[2]);

  return 0;
}



Measured memory_bytes: 2124
#include <stdio.h>
#include <stdlib.h>


long int digits( long int n );
long int max( long int a, long int b );


long int main(){
	
	long int N;
	scanf("%ld", &N);
	
	long int min = max( digits(1), digits(N) );
	long int a = 2;
	long int b;
	while( a * a <= N ){
		
		if( N % a == 0 ){
			b = N / a;
			long int value = max( digits(a), digits(b) );
			
			if( value < min ){
				min = value;
			}
			
		}
		
		a++;		
		
	}
	
	printf("%d\n", min);	
	
	return 0;
	
}


long int digits( long int n ){
	
	long int i = 1;
	long int rest = n;
	while( rest >= 10 ){
		rest = rest / 10;
		i++;
	}
	
	return i;	
	
}


long int max( long int a, long int b ){
	
	if( a >= b ){
		return a;
		
	}else{
		return b;
	}
	
}

Measured memory_bytes: 128
import java.util.Scanner;
 
class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long N = sc.nextLong();
        long max = 0;
        
        max = Math.min(N, B-1) * A / B;
        
        System.out.print(max);
	}
}



Measured memory_bytes: 35612
/*This Code Is Nude*/
#include <bits/stdc++.h>
 
#define pb push_back
#define ll long long
#define int long long
#define max(a,b) max((long long) a , (long long) b)
#define min(a,b) min((long long) a , (long long) b)

using namespace std;

const int inf = 1e12 + 10; 
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
 
bool mark [maxn];
vector<int>adj[maxn];
int a[maxn];
int ans[maxn];

int32_t main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	for(int i = 1 ; i < n ; i ++){
		int x;
		cin >> x;
		ans[x-1]++;
	}
	for(int i = 0 ; i < n ; i++)
		cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 9892
#include <bits/stdc++.h>
using namespace std;
// clang-format off

const int INF = 1e9;
using LL = long long;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
 
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
// clang-format on

void solve(long long N, long long K, std::vector<long long> h) {
  // solver code
  vector<LL> c(N, INF);

  c[0] = 0;

  for (int i = 1; i < N; i++) {
    for (int j = 1; j <= K; j++) {
      if (i - j >= 0) {
        c[i] = min(c[i], c[i - j] + abs(h[i] - h[i - j]));
      }
    }
  }

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

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> h(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &h[i]);
  }
  solve(N, K, std::move(h));
  return 0;
}


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


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 100010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n,cnt;

char st[20];

PLL A[maxn];

ll sm[maxn];

void Work(){
	ll ans=0;
	int x;read(x);ans+=x;
	bool ok=0;
	ll pos=0,tot=0;
	REP(i,2,n){
		scanf("%s",st);read(x);
		if(!ok){
			if(st[0]=='+')ans+=x;
			else{
				ok=1;
				pos=x;tot=0;
			}
		}
		else{
			if(st[0]=='+')tot+=x;
			else{
				A[++cnt]=MP(pos,tot);
				pos=x;tot=0;
			}
		}
	}
	A[++cnt]=MP(pos,tot);
	ll mx=0;
	REP(i,1,cnt)mx+=A[i].se-A[i].fi;
	RREP(i,cnt,1)sm[i]=sm[i+1]+A[i].fi+A[i].se;
	ll now=0;
	REP(i,1,cnt){
		mx=max(mx,now+sm[i+1]-A[i].fi-A[i].se);
		now+=A[i].se-A[i].fi;
	}
	cout<<mx+ans<<endl;
}

void Init(){
	read(n);
}

int main(){
	Init();
	Work();
	return 0;
}


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

int main() {
    ll n,k;
    cin>>n>>k;
    rep(i,n) {
        int temp;
        cin>>temp;
    }
    cout<<(n+k-3)/(k-1)<<endl;
}


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

using namespace std;
using ll = long long;
const ll N = 1001, mod = 1e9 + 7;

char a[ N ][ N ];
ll dp[ N ][ N ];

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

    ll n, m;
    cin >> n >> m;


    for(ll i = 1; i <= n; i += 1)
        for(ll j = 1; j <= m; j += 1)
            cin >> a[ i ][ j ];

    for(ll i = 1; i <= m; i += 1) {
        if( a[ i ][ 1 ] == '#') break;
        dp[ i ][ 1 ] = 1;
    }
    for(ll i = 1; i <= n; i += 1) {
        if( a[ 1 ][ i ] == '#') break;
        dp[ 1 ][ i ] = 1;
    }

    for(ll i = 2; i <= n; i += 1) {
        for(ll j = 2; j <= m; j += 1) {
            if( a[ i ][ j ] == '#' ) continue;
            if( a[ i ][ j - 1 ] == '.' )
                dp[ i ][ j ] += dp[ i ][ j - 1 ];
            if( a[ i - 1 ][ j ] == '.' )
                dp[ i ][ j ] += dp[ i - 1 ][ j ];
            dp[ i ][ j ] %= mod;
        }
    }
    cout << dp[ n ][ m ] << '\n';
    return 0;
}


Measured memory_bytes: 9088
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

int main(){
	int n=ci(), m=ci();
	puts(n==m?"Yes":"No");
	return 0;
}


Measured memory_bytes: 888
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
#define int long long
inline int read(){
	int sum(0),f(1);
	char ch(getchar());
	for(;ch<'0'||ch>'9';ch=getchar())
		if(ch=='-')
			f=-1;
	for(;ch>='0'&&ch<='9';sum=sum*10+(ch^48),ch=getchar());
	return sum*f;
}
struct node{
	int x,y;
}a[55];
int posx[55],posy[55];
int n,k;
int numx,numy;
inline int findx(int x){
	return lower_bound(posx+1,posx+numx+1,x)-posx;
}
inline int findy(int x){
	return lower_bound(posy+1,posy+numy+1,x)-posy;
}
inline int check(int aa,int bb,int cc,int dd){
	int ret(0);
	for(int i=1;i<=n;++i)
		if(findx(a[i].x)>=aa&&findx(a[i].x)<=cc&&findy(a[i].y)>=bb&&findy(a[i].y)<=dd)
			++ret;
	return ret;
}
int ans(0x7fffffffffffffffLL);
inline int cal_area(int aa,int bb,int cc,int dd){
	return (posy[dd]-posy[bb])*(posx[cc]-posx[aa]);
}
signed main(){
	n=read(),k=read();
	for(int i=1;i<=n;++i)
		posx[i]=a[i].x=read(),posy[i]=a[i].y=read();
	sort(posx+1,posx+n+1);
	sort(posy+1,posy+n+1);
	numx=unique(posx+1,posx+n+1)-posx-1;
	numy=unique(posy+1,posy+n+1)-posy-1;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			for(int l=i;l<=n;++l)
				for(int o=j;o<=n;++o)
					if(check(i,j,l,o)>=k)
						ans=min(ans,cal_area(i,j,l,o));
	printf("%lld",ans);
}

Measured memory_bytes: 256