akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    P = [int(x) - 1 for x in input().split()]
    C = [int(x) for x in input().split()]

    ans = -10 ** 9
    for start in range(N):
        # ループを探索
        now = start
        cycle = []
        total = 0
        for _ in [0] * N:  # while Trueでもおｋ
            now = P[now]
            cycle.append(C[now])
            total += C[now]
            if now == start:
                break
        # 最大スコアを探索
        length = len(cycle)
        score = 0
        for move in range(length):
            score += cycle[move]
            # 移動回数 >= Kなら，ループ途中でも探索終了
            if move >= K:
                break
            # ループを周回するので，それを利用して探索を省略
            res = score
            if total > 0:
                laps = (K - (move + 1)) // length
                res += total * laps
            ans = max(ans, res)

    print(ans)


if __name__ == '__main__':
    main()


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

def count_alphabets(s):
    alphabets = list("abcdefghijklmnopqrstuvwxyz")
    cnt = dict(zip(alphabets, [0 for _ in range(26)]))
    for c in s: cnt[c] += 1
    return cnt

ans = 0
for div in range(1, N):
    left_str, right_str = S[:div], S[div:]
    left_cnt, right_cnt = count_alphabets(left_str), count_alphabets(right_str)

    count = 0
    alphabets = list("abcdefghijklmnopqrstuvwxyz")
    for c in alphabets:
        if left_cnt[c] > 0 and right_cnt[c] > 0:
            count += 1
    ans = max(ans, count)
print(ans)


Measured memory_bytes: 9104
//@author :  |< U $ |-|
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<algorithm>
#include<list>
#include<cstring>
#define ll long long
#define vi vector<long long>
#define pb push_back
//#define pop pop_back
#define pi pair<long long ,long long>
#define vp vector<pair<long long,long long> >
#define mkp make_pair
#define in(i,n) for(i=0;i<n;i++)
#define fon(i,n,m) for(i=n;i<m;i++)
#define rfon(i,n,m) for(i=n;i>=m;i--)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);
#define map map<long long,long long>
#define inm1(b)  memset(b,-1,sizeof(b))
#define in0(b) memset(b,0,sizeof(b))
#define ininf(b) memset(b,1000000001,sizeof(b))
#define MOD         1000000007
#define I 10000000001
#define TakeInput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
using namespace std;
int gcd(int a, int b) {  if (a == 0)  return b; return gcd(b % a, a); }
ll log2(ll a){
    return log(a)/log(2);
}

ll power(ll x, ll y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}
int main()
{
    jaldi
    
    ll n;
    ll m,k,t,i,j;
    cin>>n>>m;
    ll a[n];
    priority_queue<ll> s;
    in(i,n){
        cin>>a[i];
        s.push(a[i]);
    }
    if(n==1){
        if(log2(a[i])<=m)cout<<0;
        else{
            cout<<a[0]/power(2,m);
        }
        
    }
    else{
    in(i,m){
        ll x=s.top();
        s.pop();
        ll y=s.top();
        s.pop();
        if(x==0 || y==0){
            s.push(x/power(2,m-i));
            s.push(0);
            break;
        }
        ll l=log2(x/y);
        if(x/y==1){
            l=1;
        }
        s.push(y);
        s.push(x/power(2,l));
    }
    ll sum=0;
    in(i,n){
        sum+=s.top();
        s.pop();
    }
    cout<<sum;
}
}
 
 








 



Measured memory_bytes: 1912
use std::io::prelude::*;

fn main() {
    let stdin_ = std::io::stdin();
    let mut stdin = stdin_.lock();
    let mut buf = String::new();
    let n = {
        stdin.read_line(&mut buf).unwrap();
        buf.trim().parse::<i64>().unwrap()
    };
    let t = {
        let mut v = Vec::new();
        for _ in 0..5 {
            buf.clear();
            stdin.read_line(&mut buf).unwrap();
            v.push(buf.trim().parse::<i64>().unwrap());
        }
        v
    };

    let min = t.iter().min().unwrap();
    let ans = 4 + n / min + (if n % min > 0 { 1 } else { 0 });
    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);

    int n = sc.nextInt();
    int a = sc.nextInt();

    int rem = n % 500;

    if(rem <= a){
    	System.out.println("Yes");
    }else{
    	System.out.println("No");
    }
  }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int main(){
    
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=0;
  int b[n];
  b[0]=0;
  b[1]=abs(a[1]-a[0]);
  for(int i=2;i<n;i++){
      b[i]=min((b[i-1]+abs(a[i]-a[i-1])),(b[i-2]+abs(a[i]-a[i-2])));
  }
    cout<<b[n-1]<<endl;
    return 0;
}

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

int main() {
	int l,r,d;
	cin>>l>>r>>d;
	int ans=0;
	for(int i=l;i<=r;i++) {
		if(i%d==0) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/operators.hpp>
#include <boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;


void Main()
{
	int N, X, Y;
	std::cin >> N >> X >> Y;
	std::vector<int> count(N);
	--X; --Y;
	for (auto i : boost::irange(0, N - 1))
	{
		for (auto j : boost::irange(i + 1, N))
		{
			auto min = std::min({
				j - i,
				std::abs(i - X) + std::abs(j - X),
				std::abs(i - Y) + std::abs(j - Y),
				std::abs(i - X) + std::abs(j - Y) + 1
				});
			++count[min];
		}
	}
	for (auto i : boost::irange(1, N))
	{
		std::cout << count[i] << std::endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 256
/*
 * FILE: ABC_130_A.cpp
 *
 * @author: Piyush Kanti Das <piyush123kantidas[at]gmail[dot]com>
 *
 * LINK:
 *
 * DATE CREATED: 01.07.2019 15:54:45 +06
 *
 * DESCRIPTION:
 *
 * DEVELOPMENT HISTORY:
 * Date         Version     Description
 * --------------------------------------------------------------
 * 01-07-2019	1.0         File Created
 *
 */


/*
// _______________________________________________________________/\\\_________
//  ______________________________________________________________\/\\\_________
//   ___/\\\\\\\\\___/\\\____/\\\__/\\\____________________________\/\\\_________
//    __/\\\/////\\\_\///____\//\\\/\\\___/\\\____/\\\__/\\\\\\\\\\_\/\\\_________
//     _\/\\\\\\\\\\___/\\\____\//\\\\\___\/\\\___\/\\\_\/\\\//////__\/\\\\\\\\\\__
//      _\/\\\//////___\/\\\_____\//\\\____\/\\\___\/\\\_\/\\\\\\\\\\_\/\\\/////\\\_
//       _\/\\\_________\/\\\__/\\_/\\\_____\/\\\___\/\\\_\////////\\\_\/\\\___\/\\\_
//        _\/\\\_________\/\\\_\//\\\\/______\//\\\\\\\\\___/\\\\\\\\\\_\/\\\___\/\\\_
//         _\///__________\///___\////_________\/////////___\//////////__\///____\///__
//
*/

#include<bits/stdc++.h>
using namespace std;

typedef long long           ll;
typedef double              lf;
typedef unsigned long long  ull;
typedef pair<int, int>      pii;
typedef vector<pii>         vpii;
typedef vector<int>         vi;
typedef vector<long long>   vll;

#define __FastIO        ios_base::sync_with_stdio(false); cin.tie(0)

#define forr(i, a, b)   for (__typeof (a) i=a; i<=b; i++)
#define rof(i, b, a)    for (__typeof (a) i=b; i>=a; i--)
#define rep(i, n)       for (__typeof (n) i=0; i<n; i++)
#define forit(i, s)     for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
#define all(ar)         ar.begin(), ar.end()

#define fill(ar)   		memset(ar, -1, sizeof(ar))
#define clr(a)          memset(a, 0, sizeof(a))

#define nl              cout << '\n';
#define sp              cout << ' ';
#define ckk             cout << "##########\n"

#define pb              push_back
#define MP 				make_pair

#define debug1(x)       cerr << #x << ": " << x << endl
#define debug2(x, y)    cerr << #x << ": " << x << '\t' << #y << ": " << y << endl
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z << endl

#define gama 0.57721566490
#define PI              acos(-1.0)
#define INF             0x7fffffff
#define MOD             1000000007
#define EPS             1e-7
#define MAX             100005

int Set(int N,int pos){return N=N | (1<<pos);}
int Reset(int N,int pos){return N= N & ~(1<<pos);}
bool Check(int N,int pos){return (bool)(N & (1<<pos));}


ll BM( ll a , ll b , ll m )
{
    if ( b == 0 ) return 1 ;
    ll x = BM(a,b/2,m);
    x = (( x % m) * (x % m))%m;
    
    if( b % 2 ) x = (( x % m) * (a %m)) % m ;
    return x ;
}

//Auto-format --> ctrl+shift+a
/********************* Code starts here ************************/

int main() {
    __FastIO;   //Be aware to use it!
    
	int X, A;
	
	cin >> X >> A;
	
	if(X < A){
		cout << 0 << endl;
	}else{
		cout << 10 << endl;
	}
	
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

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

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let n:u32 = read();
    let s:String = read();

    println!("{}",
        if n >= 3200 {s} else {String::from("red")}
    );
    
    
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll>dp(100002,-1);
ll n;
ll solve(vector<ll>&v,ll i)
{
    if(i==n-1) return 0;
    if(dp[i]!=-1) return dp[i];
    ll ans=abs(v[i]-v[i+1])+solve(v,i+1);
    if(i+2<n)
    {
        ans=min(ans,abs(v[i]-v[i+2])+solve(v,i+2));
    }
   return dp[i]=ans;

}
int main()
{

    cin>>n;
    vector<ll> v(n);
    for(ll i=0;i<n;i++)
    {
        cin>>v[i];
    }
    cout<<solve(v,0);
}


Measured memory_bytes: 9528
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60



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

	int N;
	cin >> N;
	vector<int> V;
	V.push_back(-1);
	for (int i = 0; i < N; i++) {
		int tmp; cin >> tmp;
		V.push_back(tmp);
	}

	bool flag = true;
	stack<int> S;

	for (int i = 0; i < N && flag; i++) {
		flag = false;
		for (int j = V.size()-1; j >= 1 && !flag; j--) {
			if (V[j] == j) {
				flag = true;
				S.push(j);
				V.erase(V.begin() + j);
			}
		}
	}

	if (!flag) cout << -1 << endl;
	else {
		for (int i = 0; i < N; i++) {
			cout << S.top() << " ";
			S.pop();
		}
		cout << endl;
	}
	

	return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

struct Node {
  int id;
  int cnt;

  Node(int id = -1, int cnt = -1) {
    this->id = id;
    this->cnt = cnt;
  }
};

struct Coord {
  int y;
  int x;
  int dist;

  Coord (int y = -1, int x = -1, int dist = -1) {
    this->y = y;
    this->x = x;
    this->dist = dist;
  }
};

const int MAX_N = 20;
int H, W;

int DY[4] = {-1, 0, 1, 0};
int DX[4] = {0, 1, 0, -1};
vector<string> S;

int calcPathDist(int sy, int sx, int ty, int tx) {
  queue<Coord> que;
  que.push(Coord(sy, sx, 0));

  bool visited[MAX_N][MAX_N];
  memset(visited, false, sizeof(visited));

  while (!que.empty()) {
    Coord coord = que.front();
    que.pop();

    if (visited[coord.y][coord.x]) continue;
    visited[coord.y][coord.x] = true;

    if (coord.y == ty && coord.x == tx) {
      return coord.dist;
    }

    for (int i = 0; i < 4; ++i) {
      int ny = coord.y + DY[i];
      int nx = coord.x + DX[i];

      if (ny < 0 || nx < 0 || H <= ny || W <= nx) continue;
      if (S[ny][nx] == '#') continue;

      que.push(Coord(ny, nx, coord.dist + 1));
    }
  }

  return 0;
}

int main() {
  cin >> H >> W;

  string s;
  for (int i = 0; i < H; ++i) {
    cin >> s;

    S.push_back(s);
  }

  int ans = 0;

  for (int i = 0; i < H * W - 1; ++i) {
    int y1 = i / W;
    int x1 = i % W;

    if (S[y1][x1] == '#') continue;

    for (int j = i + 1; j < H * W; ++j) {
      int y2 = j / W;
      int x2 = j % W;

      if (S[y2][x2] == '#') continue;

      int ret = calcPathDist(y1, x1, y2, x2);

      ans = max(ans, ret);
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main()
{
  vector<int> v(10);
  for (int i = 0; i < 10; i++)
    cin >> v[i];
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (int i = 0; i < 3; i++)
    cout << v[i] << endl;

  return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
int main(){
  std::string a,b;
  bool f=true;
  std::cin>>a>>b;
  if(a.size()==b.size()){
    for(int i=0;i<a.size();++i)if(a[i]!=b[i]){std::cout<<(a[i]<b[i]?"LESS":"GREATER")<<"\n";f=false;break;}
    if(f)std::cout<<"EQUAL"<<"\n";
  }  
  else std::cout<<(a.size()<b.size()?"LESS":"GREATER")<<"\n";
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K,x;
    cin>>N>>K;
    int a=0;
    for(int i=0;i<N;i++){
        cin>>x;
        if(x<K-x) a+=2*x;
        else a+=(K-x)*2;
    }
    cout<<a<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
   int a,b;cin>>a>>b;
   if ((a>b && b!=1)||(a==1 && b!=1)){
    cout<<"Alice";

   }
   else if ( (b>a&& a!=1)||(b==1 &&a!=1)){
    cout<<"Bob";
   }
   else {
    cout<<"Draw";
   }

    return 0;
}


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

Int solve(Int n){
	if(n % 2 == 1) return 0;
	Int res = 0;
	Int m = n / 2;
	for(Int i=5; i<=m; i*=5) res += m/i;
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int n; cin >> n;
	cout << solve(n) << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define mem0(s) memset(s,0,sizeof(s))
#define meminf(s) memset(s,0x3f,sizeof(s))
#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))
double pi=acos(-1);
typedef long long ll;
const double ex=1e-5;
typedef unsigned long long ull;
inline ll lowbit(ll x){return x&(-x);}
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll max(ll a,ll b){return a>b?a:b;}
const int INF=0x3f3f3f3f,max_n=200005;
const int mod=1000000007;
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
vector<int>v;
int x;
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		v.pb(x);
	}
	sort(all(v));
	int m=unique(v.begin(),v.end())-v.begin();
	if(m==n)
	{
		cout<<"YES";
	}
	else cout<<"NO";
}

Measured memory_bytes: 1400
map{/ /,push@
$`,$' for<>;map$q[$_]+=$q[$N]/@$N,@{$N=$_}}++$q[1]..<>;while(--$N){$s=0;$s+=$_ for@@=@e[@$N];$e[$N]=1+$s/@@;$a<($t=$q[$N]*=$#@&&($s-(sort@@)[-1])/$#@-$s/@@)or$a=$t}print"@e"+$a

Measured memory_bytes: 42368
#include <bits/stdc++.h>
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
using namespace std;

int32_t main() {
    // freopen("in.txt", "r", stdin);
    IOS;
    int x[2], y[2];
    cin >> x[0] >> x[1] >> y[0] >> y[1];
    int ans = -1e18;
    for(int i=0; i<2; i++) {
        for(int j=0; j<2; j++) {
            ans = max(ans, x[i]*y[j]);
        }
    }
    cout << ans;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    set<int>a;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        a.insert(x);
    }
    if(a.size()==n)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
	return 0;
}







Measured memory_bytes: 9600
# ABC079C

s = input()
ok = False
for i in ['-', '+']:
    for j in ['-', '+']:
        for k in ['-', '+']:
            expr = s[0]+i+s[1]+j+s[2]+k+s[3]
            if eval(expr) == 7:
                print(expr, '=7', sep="")
                ok = True
                break
        if ok: break
    if ok: break


Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(500000)

def get_cost(arr, n, dp):
  if dp[n] != -1:
    return dp[n]
  if n == 1:
    dp[1] = abs(arr[1] - arr[0])
    return dp[1]
  elif n == 0:
    dp[0] = 0
    return dp[0]
  else:
    dp[n] = min(
      abs(arr[n] - arr[n-1]) + get_cost(arr, n-1, dp),
      abs(arr[n] - arr[n-2]) + get_cost(arr, n-2, dp)
    )
    return dp[n]


N = int(input())
arr = [int(num) for num in input().split()]
dp_arr = [-1]*N
print(get_cost(arr, N-1, dp_arr))


Measured memory_bytes: 96676
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int maxn = 1000000 + 10;
int n, maxx, minn, a[maxn];

int main(int argc, char const *argv[])
{
//  freopen("hat.in", "r", stdin);
//  freopen("hat.out", "w", stdout);

  scanf("%d", &n);
    maxx = 0, minn = 1e9;
    for(int i = 1; i <= n; ++i)
      scanf("%d", &a[i]), maxx = max(maxx, a[i]), minn = min(minn, a[i]);
    if( maxx - minn > 1 ) {
      printf("No\n");
    }
    else if( maxx - minn == 0 ) {
      if( 2 * maxx <= n || minn == n - 1 ) printf("Yes\n");
      else printf("No\n");
    }
    else if( maxx - minn == 1 ) {
      int col = 0, x = 0, max_col, min_col, flag = 1;
      for(int i = 1; i <= n; ++i) a[i] == maxx ? ++x : ++col;
      min_col = col + 1, max_col = col + (x >> 1);
      // printf("%d %d\n", max_col, min_col);
      if( min_col > n && max_col < 1 ) flag = flag & 0;
      if( minn + 1 > max_col || minn + 1 < min_col ) flag = flag & 0;
      if( maxx > max_col || maxx < min_col ) flag = flag & 0;
      printf(!flag ? "No\n" : "Yes\n");
    }

//  fclose(stdin), fclose(stdout);
  return 0;
}

Measured memory_bytes: 640
nl = input().split(" ")
ls = []
al = []
for i in range(int(nl[0])):
    ls.append(int(nl[1])+i)
    al.append(abs(int(nl[1])+i))
if max(ls) < 0:
    print(sum(ls) + min(al))
    exit()
print(sum(ls) - min(al))


Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
using namespace std;
char s[20];
int n;
int main()
{
	int i,j,k;
	scanf("%s",s+1);
	if(s[1]=='Y'&&s[2]=='A'&&s[3]=='K'&&s[4]=='I')
		{printf("Yes\n");return 0;}
	printf("No\n");
	return 0;
} 

Measured memory_bytes: 128
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer


object Main {
  def read(): (Int, Int, String) = {
    val sc = new Scanner(System.in)
    val n, k = sc.nextInt()
    val s = sc.next()
    (n, k, s)
  }

  def compressRunlength(s: String): IndexedSeq[(Int, Char)] = {

    var currentChar = s(0)
    var currentCount = 1
    var buf = ArrayBuffer.empty[(Int, Char)]
    for (i <- 1 until s.length) {
      if (currentChar == s(i)) {
        currentCount += 1
      } else {
        buf.append((currentCount, currentChar))
        currentChar = s(i)
        currentCount = 1
      }
    }
    buf.append((currentCount, currentChar))
    buf.toIndexedSeq
  }

  def solve(n: Int, k: Int, s: String): Int = {
    // s.length == n
    val runLength = compressRunlength(s)
    val cumSum = runLength.map(_._1).scanLeft(0)(_ + _)

    // (i, ..., j-1)の和: cumSum(j)-cumSum(i)
    def sum(min: Int, max: Int): Int = cumSum(max + 1) - cumSum(min)

    def cut(i: Int) = Math.min(i, runLength.length - 1)

    // i番目が0: i, i+1,...,i+2k-1
    // i番目が1: i, i+1,...,i+2k
    runLength.indices
      .map(i =>
        if (runLength(i)._2 == '0') (i, cut(i + 2 * k - 1)) else (i, cut(i + 2 * k)))
      .map { case (min, max) =>
        sum(min, max)
      }.max
  }


  def main(args: Array[String]): Unit = {
    val (n, k, s) = read()
    println(solve(n, k, s))
  }
}

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


int digit_n(int n){
  int num = 0;
  while(n){
    n /= 10;
    num++;
  }
  return num;
}

int main() {
  long long n;
  cin >> n;
  int ans = 100;
  int nn = sqrt(n) + 1;
  rep(i, nn){
    int a, b;
    if(n % i == 0){
      a = i, b = n / i;
      ans = min(ans, max(digit_n(a), digit_n(b)));
    }
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include<map>
#include <utility>
#include <math.h>
using namespace std;
int  c = 0, e[100010] = {}, f[100010];
double syo = 0, su = 0;
long long mur, kmr, yju, counto = 0,counto1=0;
char mado[105];
string rik;
bool mazi[110], gi[110],zi,manji;
pair<int, int>n[110];
vector<int> aa[50] = {}, bb, cc;
map<int, int>kazu;
int gcd(int a,int b) {
	int d;
	if (a > b) {
		int t = b;
		b = a;
		a = t;
	}
	while ((d = b % a) != 0) {
		b = a;
		a = d;
	}
	return a;
}
int main() 
{
	cin >> c;
	for (int i = 0; i < c; i++) {
		cin >> e[i];
	}

	sort(e, e + c);
	counto = gcd(e[0], e[1]);
	for (int i = 2; i < c; i++) {
		counto = gcd(counto, e[i]);
	}
	/*d = e[0];
	for (int i = 1; i < a; i++) {
		e[i] = e[i] % e[0];
		
		if (e[i] == 0) {
			counto1++;
		}
	}
	if (counto1 == a - 1) {
		cout << e[0] << endl;
		return 0;
	}
	sort(e, e + a);
	while (zi == false) {
		for (int i = 0; i < a - 1; i++) {
			//cout << e[i + 1] - e[i] << endl;
			if (e[i + 1] - e[i] != 0) {
				d = min(d, e[i + 1] - e[i]);
			}
			e[i + 1] = e[i + 1] - e[i];
		    
		}
		
		if (b!=0&&counto == d) {
			zi = true;
		}
		counto = d;
		sort(e, e + a);
		b++;
	}*/
	cout << counto << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include <algorithm>
#include<cstdio>
#include<string>
#include<math.h>
#include<vector>
#include <queue>
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define srep(i,s,t) for (long long i = s; i < t; i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define mod 1000000007
using namespace std;
typedef vector<vector<char>> field_t;

typedef pair<int, int> point_t;



int main()
{
    long long N,Y,i,K,Z,j;
    cin >> N >> K;
	Z=0;
	srep(i,K,N+2){
		Y=i*(i-1)/2;
		srep(j,Y,i*N-Y+1){
			Z++;
		}
	}
		cout<<Z%mod<<endl;

}

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


int main()
{
   int a;

scanf("%d",&a);
   if(a==25)
    printf("Christmas");
   if(a==24)
   printf("Christmas Eve");
   if(a==23)
printf("Christmas Eve Eve");

 if(a==22)
    printf("Christmas Eve Eve Eve");

return 0;
}







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

void bo(int,int);

void bo(int t,int m){
  if(t==1){
    if(m%5==1) cout<<".";
  else if(m%5==2) cout<<",";
  else if(m%5==3)cout<<"!";
  else if(m%5==4)  cout<<"?";
  else cout<<" ";
  }else if(t==2){
    if(m%3==1) cout<<"a";
    else if(m%3==2) cout<<"b";
    else cout<<"c";
  }else if(t==3){
    if(m%3==1) cout<<"d";
    else if(m%3==2) cout<<"e";
    else cout<<"f";
  }else if(t==4){
    if(m%3==1) cout<<"g";
    else if(m%3==2) cout<<"h";
    else cout<<"i";
  }else if(t==5){
    if(m%3==1) cout<<"j";
    else if(m%3==2) cout<<"k";
    else cout<<"l";
  }else if(t==6){
    if(m%3==1) cout<<"m";
    else if(m%3==2) cout<<"n";
    else cout<<"o";
  }else if(t==7){
    if(m%4==1) cout<<"p";
    else if(m%4==2) cout<<"q";
    else if(m%4==3) cout<<"r";
    else cout<<"s";
  }else if(t==8){
    if(m%3==1) cout<<"t";
    else if(m%3==2) cout<<"u";
    else cout<<"v";
  }else if(t==9){
    if(m%4==1) cout<<"w";
    else if(m%4==2) cout<<"x";
    else if(m%4==3) cout<<"y";
    else cout<<"z";
  }
}
		     
int main(){
  string str;
  int n;
  cin>>n;
  int cou=0;
  for(int i=0;i<n;i++){
  cin>>str;
  for(int j=0;j<str.size();j++){
    if( j>0 && str[j]=='0' ){
	bo(str[j-1]-'0',cou);
      cou=0;
      continue;
    }
    else if(str[j]!='0') cou++;
  }
  cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int gcd(int a, int b){
    if(a<b){
        int t=a;
        a=b;
        b=t;
    }
    while(a%b!=0){
        int t=b;
        b=a%b;
        a=t;
    }
    return b;
}
signed main(){
    int n; cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a.at(i);
    int t=gcd(a.at(0), a.at(1));
    rep(i,n){
        if(a.at(i)%t!=0){
            t=gcd(t,a.at(i));
        }
    }
    cout<<t<<endl;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s, t;
	cin >> s >> t;
	ll a, b;
	cin >> a >> b;
	string u; cin >> u;
	(u == s ? a : b)--;
	cout << a << " " << b << endl;
}



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

int main() {
    
  int A,B;
  cin >>A>>B;
  int count=0;
  for(int i=A;i<=B;i++){
    int a=i/10000;
    int b=i/1000-a*10;
    int c=i/100-a*100-b*10;
    int d=i/10-a*1000-b*100-c*10;
    int e=i-a*10000-b*1000-c*100-d*10;
    if(a==e&&b==d){
      count++;
    }
  }
  cout<<count<<endl;
  

        
}


Measured memory_bytes: 256
/* tempate
 *
 *
 */

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll res = 1;
    rep(i, 3){
        res *= n;
    }
    cout << res;
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll a,b,c;cin>>a>>b>>c;
    if(a*b*4<(c-a-b)*(c-a-b)&&c>a+b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N];

int main()
{
	int n,m;
	while(cin >> n >> m){
		priority_queue<int> q;
		long long sum = 0;
		for(int i = 1; i <= n; i++){
			cin >> a[i];
			q.push(a[i]);
			sum += a[i];
		}
		for(int i = 1; i <= m; i++){
			sum -= (q.top() - q.top()/2);
			int t = q.top()/2;
			q.pop();
			q.push(t);
		}
		cout << sum << endl;
	}
	return 0;
 } 

Measured memory_bytes: 1148
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int n;  // スイッチの数
    int m;  // 電球の数
    cin >> n >> m;

    vector<vector<int>> v(m);  // v[i][j] : 電球iにつながっているj番目のスイッチ(i,jは0-index)
    rep(i, m) {
        int k;
        cin >> k;
        rep(j, k) {
            int s;
            cin >> s;
            s--;
            v[i].push_back(s);
        }
    }

    vector<int> p(m);  // p[i] : 電球iにつながっているスイッチでonのものの数の偶奇
    rep(i, m) {
        cin >> p[i];
    }

    int ans = 0;
    // スイッチのon,offを全探索
    for(int b = 0; b < (1<<n); b++) {  // bのkビット目が1のときスイッチkはon。0のときoff

        int flag = 0;  // 0のときok。1のときダメ
        rep(i, m) {  // 電球iについて考える

            int cnt = 0;  // 電球iにつながっているスイッチでonのものの数
            rep(j, v[i].size()) {
                if(b & 1<<v[i][j]) {
                    cnt++;
                }
            }

            if(cnt%2 != p[i]) {
                flag = 1;
                break;
            }
        }

        if(!flag) {
            ans++;
        }
    }
    
    cout << ans << endl;
    return 0;
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1000000000;

int main(){
   int n;cin>>n;
   string s[n];
   rep(i,n)cin>>s[i];
   rep(i,n-1){
      if(s[i].back() == s[i+1].front()){
      }else{
         cout << "No";
         return 0;
      }
   }
   rep(i,n){
      FOR(j,i+1,n){
         if(s[i] == s[j]){
            cout << "No";
            return 0;
         }
      }
   }
   cout << "Yes";
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

int main() {
  ll N,M;
  cin >> N >> M;
  
  ll ac = 0;
  ll wa = 0;

  vector<ll> wacount(N),isac(N);

  for(int i = 0; i < M; i++){
    int p;
    string s;
    cin >> p >> s;
    p--;
    if(s == "AC"){
      if(!isac[p]){
        ac++;
        wa += wacount[p];
        isac[p] = true;
      }
    }
    else{
      wacount[p]++;
    }
  }
  cout << ac << " " << wa << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n, m;
int len;
bool visit[1 << 12];
bool can[12][5100];
string e[20];

int calc(int depth, int used, int index) {
  if (visit[used]) { return 0; }
  visit[used] = true;
  if (depth == n) { return 1; }
  REP(i, n) {
    if (used & (1 << i) || !can[i][index]) { continue; }
    int nused = used | (1 << i);
    if (calc(depth + 1, nused, index + e[i].size()) == 1) {
      return 1;
    }
  }
  return 0;
}

int main() {
  while (cin >> n >> m, n|m) {
    MEMSET(can, false);
    REP(i, n) { cin >> e[i]; }
    string s;
    REP(i, m) {
      string t;
      cin >> t;
      s += t;
    }
    len = s.size();
    REP(i, n) {
      int index = 0;
      while (index < len) {
        index = s.find(e[i], index);
        if (index == (int)string::npos) { break; }
        can[i][index] = true;
        index++;
      }
    }
    int ans = 0;
    REP(i, len) {
      MEMSET(visit, false);
      ans += calc(0, 0, i);
    }
    cout << ans << endl;
  }
}

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

using namespace std;


int main() {
    int n;
    cin >> n;
    vector<tuple<string,int,int>> T;
    for(int i = 0; i < n; i++) {
        string s;
        int x;
        cin >> s >> x;
        x *= -1;
        T.push_back(make_tuple(s,x,i+1));
    }
    sort(T.begin(),T.end());
    for(int i = 0; i < n; i++) {
        cout << get<2>(T[i]) << "\n";
    }
    return 0;
}

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

int main(){
    int n, ans=0; cin >> n;
    vector <int> x(n), y(n);
    for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
    map<pair<int, int>, int> d;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i==j) continue;
            int p = x[i]-x[j], q= y[i]-y[j];
            d[{p, q}]++;
        }
    }
    int max = 0;
    for (map<pair<int, int>, int>::iterator it = d.begin(); it != d.end(); it++) {
        if (max < it->second) max = it->second;
    }
    cout << n-max << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n;
	cin>>n;
	bool f=0;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		if(x%2)f=1;
	}
	cout<<(f?"first":"second")<<endl;
	return 0;
}


Measured memory_bytes: 3632
import math

def is_prime(n):
    if n == 2:
        return True
    
    if n < 2 or n % 2 == 0:
        return False
    
    for i in range(3, int(math.sqrt(n))+1, 2):
        if n % i == 0:
            return False

    return True

n = int(input())
nums = [int(input()) for _ in range(n)]


result = 0
for num in nums:
    if is_prime(num):
        result += 1

    
print(result)


Measured memory_bytes: 6008
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#import math
#n=int(input())
#li=input().split()
#S=input()

n=int(input())
lis=list(map(int,input().split()))
ans=1
for i in range(1,n):
    a=0
    for j in range(i):
        if lis[i]>=lis[j]:
            a+=1
        else:
            break
    if a==i:
        ans+=1

print(ans)


Measured memory_bytes: 3060
# D

N = int(input())
A = [int(x) for x in input().split()]

minus_num = len([x for x in A if x < 0])
abs_list = [abs(x) for x in A]
if minus_num % 2:
    print(sum(abs_list) - min(abs_list)*2)
else:
    print(sum(abs_list))

Measured memory_bytes: 14332
//file_name:ABC44_B.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#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 srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    string s;
    cin >> s;
    int a[256] = {};

    rep(i,s.size()){
        a[(int)s[i]]++;
    }
    rep(i,256){
        if(a[i]%2!=0){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 256
S = {}
for i in 'ABC':
    S[i] = [w for w in input()]
ans = ''
judge = True
turn = S['A'].pop(0).upper()
while judge:
    if S[turn] == []:
        ans = turn
        judge = False
    else:
        turn = S[turn].pop(0).upper()
print(ans)

Measured memory_bytes: 8920
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int N,M;
vector<pair<int,int> >G[1<<17];
bool vis[2][1<<17];
long T[2][1<<17];
long ans=1e9;
void dfs(int u,int w)
{
	vis[w][u]=true;
	for(pair<int,int>p:G[u])
	{
		long t=p.second-T[w][u];
		if(vis[!w][p.first])
		{
			if(T[!w][p.first]!=t)
			{
				ans=0;
				break;
			}
		}
		else
		{
			T[!w][p.first]=t;
			dfs(p.first,!w);
		}
	}
}
main()
{
	cin>>N>>M;
	for(int i=0;i<M;i++)
	{
		int a,b,c;cin>>a>>b>>c;a--,b--;
		G[a].push_back(make_pair(b,c));
		G[b].push_back(make_pair(a,c));
	}
	dfs(0,0);
	long L=1,R=1e9;
	long fix=-1;
	for(int i=0;i<N;i++)
	{
		if(vis[0][i]&&vis[1][i])
		{
			long X=T[1][i]-T[0][i];
			if(X<=0||X%2)ans=0;
			else
			{
				if(fix<0)fix=X/2;
				else if(fix!=X/2)ans=0;
			}
		}
		if(vis[0][i])L=max(L,1-T[0][i]);
		if(vis[1][i])R=min(R,T[1][i]-1);
	}
	cout<<(fix>=0?ans>0&&L<=fix&&fix<=R:max(min(ans,R-L+1),0L))<<endl;
}

Measured memory_bytes: 18048
N,K=map(int,input().split())
h=list(map(int,input().split()))
INF=10**9
dp=[INF]*(N)#dp[i] 足場i+1にいるときの最小コスト
dp[0]=0
for i in range(N+1):
    for k in range(1,K+1):
        if i+k<=N-1:
            dp[i+k]=min(dp[i+k],abs(h[i]-h[i+k])+dp[i])
print(dp[N-1])


Measured memory_bytes: 52448
import java.util.Scanner;

public class Main {
	
	private static StringBuilder answer = new StringBuilder();
	
	private static String PRINT   = "print";
	private static String REVERSE = "reverse";
	private static String REPLACE = "replace";

	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		String target = sc.next();
		int numbers   = Integer.parseInt(sc.next());
		
		for(int i = 0; i<numbers;i++){
			
			String command = sc.next();
						
			target = operate(command,target,sc);
			
		}
		
		System.out.print(answer);
		
		sc.close();
	}

	private static String operate(String command, String target,Scanner sc) {
		
		if(PRINT.equalsIgnoreCase(command)){
			
			int a  = Integer.parseInt(sc.next());
			int b  = Integer.parseInt(sc.next());
			String print = target.substring(a,b+1);
			answer.append(print + "\n");
			
			return target;
		}
		else if(REPLACE.equalsIgnoreCase(command)){
			
			int a  = Integer.parseInt(sc.next());
			int b  = Integer.parseInt(sc.next());
			String strings = sc.next();
			
			char[] charOftarget = target.toCharArray();
			char[] charOfstrings= strings.toCharArray();
			
			for(int i = 0 ;i<target.length();i++){
				
				if( a <= i && i <= b){
					charOftarget[i] = charOfstrings[i-a];
				}
				
			}
			
			
			return String.valueOf(charOftarget);
			
		}else if(REVERSE.equalsIgnoreCase(command)){
			
			int a  = Integer.parseInt(sc.next());
			int b  = Integer.parseInt(sc.next());
			
			char[] charOftarget = target.toCharArray();
			char[] answer  = new char[charOftarget.length];
			for(int i = 0 ;i<target.length();i++){
				
				if(a <= i && i <= b){
					
					answer[i] = charOftarget[b-(i-a)];
					continue;
				}
				
				answer[i] = charOftarget[i];
				
				
				
			}
			
			return String.valueOf(answer);
			
		}
		
		
		return null;
	}

}



Measured memory_bytes: 30572
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vv<int> A = vvec(N, M, 0);
    rep(i, N) {
        cin >> C[i];
        rep(j, M) cin >> A[i][j];
    }

    int ans = INF;
    vector<int> master(M);
    rep(bit, 1 << N) {
        int cost = 0;
        master.assign(M, 0);
        rep(i, N) {
            if (bit >> i & 1) {
                cost += C[i];
                rep(j, M) master[j] += A[i][j];
            }
        }
        bool ok = true;
        rep(j, M) {
            if (master[j] < X) ok = false;
        }
        if (ok) ans = min(ans, cost);
    }
    write(ans == INF ? -1 : ans);
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<string> blue(N);
  for (int i = 0; i < N; i++) {
    cin >> blue.at(i);
  }
  int M;
  cin >> M;
  vector<string> red(M);
  for (int i = 0; i < M; i++) {
    cin >> red.at(i);
  }
  int A = 0;
  for (int i = 0; i < N; i++) {
    int S = 0;
    for (int j = 0; j < N; j++) {
      if (blue.at(i) == blue.at(j)) {S++;}
    }
    for (int j = 0; j < M; j++) {
      if (blue.at(i) == red.at(j)) {S--;}
    }
    if (A < S) {A = S;}
  }
  cout << A << endl;
}

Measured memory_bytes: 3588
import scala.io.Source.stdin

object Main {
  val v = new Array[Int](101)
  def main(args:Array[String]) =  {
    var i = 0
    stdin.getLines.foreach { a => v(a.toInt) += 1 }
    v.foreach { e =>
      if(e == v.max) println(i)
      i += 1
    }
  }
}

Measured memory_bytes: 44072
S = input()

if S == "SUN":
    print(7)

elif S == "MON":
    print(6)

elif S == "TUE":
    print(5)

elif S == "WED":
    print(4)

elif S == "THU":
    print(3)

elif S == "FRI":
    print(2)

elif S == "SAT":
    print(1)

Measured memory_bytes: 3060
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

int a, b;

map <int, int > bio;

priority_queue <pii> q;

int dijkstra(int x) {
	q.push(mp(0, x));

	int cvor;
	int d;

	while (!q.empty()) {
		while (!q.empty() && bio[q.top().sec]) q.pop();
		
		cvor = q.top().sec;
		d = -q.top().fi;
		q.pop();
		bio[cvor] = 1;

		if (cvor == b) return d;
		if (cvor < b) q.push(mp(-(d + b - cvor), b));
		if (cvor < -b) q.push(mp(-(d -b - cvor), -b));
		q.push(mp(-d -1, -cvor));
	}
	return -1;
}

int main() {
	scanf("%d %d",&a,&b);
	printf("%d\n",dijkstra(a));
	return 0;
}


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

vector<int> gr[100005];
int dp[100005];
int longPath(int i) {
	if (dp[i] != -1)
		return dp[i];
	int sub = 0;
	for (auto child : gr[i])
		sub = max(sub, longPath(child) + 1);
	return dp[i] = sub;

}


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

	memset(dp, -1, sizeof(dp));
	int n, m, x, y;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> x >> y;
		gr[x].push_back(y);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = max(ans, longPath(i));
	}
	cout << ans;


	return 0;
}

Measured memory_bytes: 11444
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>
#include <complex>
 
#define INF 100000000
#define EPS 1e-9
 
using namespace std;
 
typedef long long ll;  

int P, Q, R;
string str, tmpStr;

int myNot[] = {2,1,0};
int myAnd[3][3] = {{0,0,0},{0,1,1},{0,1,2}};
int myOr[3][3] = {{0,1,2},{1,1,2},{2,2,2}};

vector<int> ans_list;

//左から何番目を基準にしているか
bool solve(int num){

  int tmai = 0;
  int s = -1;
  if(tmpStr[num] == '-')
    tmai++;

  for(int i = num + 1; i < tmpStr.length(); i++){
    if(tmpStr[i] == '('){
      solve(i);
      break;
    }
    else if(tmpStr[i] == ')'){
      int mai = 0; //マイナスが何回現れたか
      int left = -1;
      int right = -1; //左と右の数字
      int ope = -1; //1:ans 2:or
      for(int k = num+1; k < i; k++){
	if(tmpStr[k] == '-')
	  mai++;
	else if(tmpStr[k] == '*')
	  ope = 1;
	else if(tmpStr[k] == '+')
	  ope = 2;
	else{
	  mai %= 2;
	  int tmp = tmpStr[k] - '0';
	  if(left == -1)
	    left = tmp;
	  else
	    right = tmp;
	  mai = 0;
	}
      }
      int tmp = -1;
      if(ope == 1)
	tmp = myAnd[left][right];
      else
	tmp = myOr[left][right];
      tmpStr.erase(num,i - num + 1);
      tmpStr.insert(tmpStr.begin() + num, tmp + '0'); 
      break;
    }
    
    else if(tmpStr[i] == '-'){
      tmai++;
      if(s == -1)
	s = i;
    }
    if(tmai > 0 && '0' <= tmpStr[i] && tmpStr[i] <= '2'){
      int t = tmpStr[i] - '0';
      if(tmai%2 == 1)
	t = myNot[t];
      if(tmpStr[num] == '-'){
	tmpStr.erase(num, i-num+1);
	tmpStr.insert(tmpStr.begin() + num, t + '0');
      }
      else{
	tmpStr.erase(s, i-s + 1);
	tmpStr.insert(tmpStr.begin() + s, t + '0');
      }
      break;
    }
    
  }

  //文字の長さが1なら、それが2になっているかの判定
  if(tmpStr.length() == 1){
    if(tmpStr == "2")
      return true;
    else
      return false;
  }
  
  return false;

}

int main(){

  while(true){
    
    cin >> str;
    if(str == ".")
      break;

    int ans = 0;
    for(int i = 0; i < 27; i++){
      P = i%3;
      Q = (i/3)%3;
      R = (i/9)%3;
      tmpStr.clear();
      tmpStr = str;
      
      for(int i = 0; i < tmpStr.length(); i++){
	if(tmpStr[i] == 'P')
	  tmpStr[i] = P + '0';
	else if(tmpStr[i] == 'Q')
	  tmpStr[i] = Q + '0';
	else if(tmpStr[i] == 'R')
	  tmpStr[i] = R + '0';
      }

      while(true){
	if(tmpStr.length() != 1)
	  solve(0);
	else
	  break;
      }

      if(solve(0))
	ans++;

    }

    ans_list.push_back(ans);

  }

  for(int i = 0; i < ans_list.size(); i++){
    cout << ans_list[i] << endl;
  }


  return 0;

}

Measured memory_bytes: 1216