akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

long long N, M;
long long S, T;
long long ans[100005][3];
//           pos     , mod
vector<pair<long long, long long> > tree[100005][3];
set<pair<long long, long long> > visit;

int main(){
	cin >> N >> M;
	for(long long i = 0; i < M; i++){
		long long u, v;
		cin >> u >> v;u--;v--;
		tree[u][0].push_back(make_pair(v, 1));
		tree[u][1].push_back(make_pair(v, 2));
		tree[u][2].push_back(make_pair(v, 0));
	}
	cin >> S >> T;S--;T--;

	//<pos, mod> 
	queue<pair<pair<long long, long long>, long long> >Q;
	Q.push(make_pair(make_pair(S, 0), 0));

	while(!Q.empty()){
		pair<long long, long long> p = Q.front().first;
		long long cost = Q.front().second;
		Q.pop();
		if(visit.count(p)){
			continue;
		}
		visit.insert(p);
		if(p.first == T && p.second == 0){
			cout << cost/3 << endl;
			return 0;
		}


		for(long long i = 0; i < tree[p.first][p.second].size(); i++){
			pair<long long, long long> np = tree[p.first][p.second][i];
			long long ncost = cost + 1;
			if(visit.count(np)){
				continue;
			}
			Q.push(make_pair(np, ncost));
		}
	}
	cout << -1 << endl;
}


Measured memory_bytes: 36608
#include <iostream>
#include <cstring>
using namespace std;
typedef long long LL;
LL mod = 1000000007L;
int n;
char s1[1000], s2[1000];
LL ans;
int main() {
	cin>>n;
	cin>>s1>>s2;
	int len = strlen(s1);
	ans = 0;
	for (int i = 0; i < len; i++) {
		if (s1[i] == s2[i]) {
			if (i == 0) {
				ans = 3;
			} else if (s1[i-1] == s2[i-1]) {
				ans = (ans * 2) % mod; 
			}
		}else {
			if (i == 0) {
				ans = 6; 
			} else {
				if (s1[i-1] == s2[i-1]) {
					ans = (ans * 2) % mod; 
				} else {
					ans = (ans * 3) % mod; 
				} 
			}
			i++; 
		}
	}
	cout<<ans<<endl; 
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  long double R, A;
  cin >> R;
  long double pie = 2.0 * (long double)asin(1.0);
  cout << R * 2 * pie << endl;
}

Measured memory_bytes: 3744
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)
 
int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
 
typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
 
const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
 
// --------------------------------------
int n, m;
vector<int> s[10];
 
ll bfs(int a, int sum, bool c[8]) {
  if(sum >= n) return 1;
  ll ans = 0;
  REP(i, s[a].size()) {
    if(c[s[a][i]]) {
      bool c_c[10];
      memcpy(c_c, c, sizeof(c));
      c_c[s[a][i]] = false;
      ans += bfs(s[a][i], sum + 1, c_c);
    }
  }
  return ans;
}
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  cin >> n >> m;
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    s[a].push_back(b);
    s[b].push_back(a);
  }
 
  bool c[10];
  fill(c, c + n + 1, true);
  c[0] = false;
  cout << bfs(0, 1, c) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (long long i = 0; i < N; i++)
using ll = long long;

int main() {
    ll N;
    string c;
    cin >> N >> c;
    ll ans = 0;
    string copyc = c;
    sort(copyc.begin(), copyc.end());
    rep(i, N) {
        if (copyc[i] == 'W') {
            break;
        }
        if (c[i] != copyc[i]) {
            ans++;
        }
    }

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


Measured memory_bytes: 3908
//  s.at(0) = toupper(s.at(0));//小文字なら大文字へ//大文字の場合はそのまま
//  s.at(i) = tolower(s.at(i));//大文字なら小文字へ//小文字の場合はそのまま
//  string s;
//  cin >> s;
//  cout << s.at(0) <<endl;
//  cout << s.at(0)-'0' <<endl;
//  Aが16？
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  ll n,k;
  cin >> n >> k;
  ll sum = 0;
  vector<ll>t(n);
  rep(i,n)cin>>t.at(i);
  for(int i=0;i<n-1;i++){
    if(t.at(i+1)-t.at(i) < k){
      ll num = t.at(i+1) - t.at(i);
      num = k - num;
      sum += num;
    }
  }
  cout << n*k - sum << endl;
}

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

int main() {
  string S;
  cin >> S;
  if (S == "AAA" || S == "BBB") {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
def solve(string):
    x = int(string)
    for i in range(x, 2 * x):
        for j in range(2, int(i**0.5)):
            if i % j == 0:
                break
        else:
            return str(i)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n),b(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    b.at(a.at(i)-1) = i;
  }
  for(int i=0;i<n;i++){
    cout << b.at(i)+1 << endl;
  }
  
  
  return 0;
}


Measured memory_bytes: 1664
fun main(args: Array<String>) {
  val N = readInt()
  val A = readInts()

  var leafNum = 0L
  A.forEach { leafNum += it }

  var cnt = 0L
  var n = 1L
  for (i in A.indices) {
    val a = A[i]
    n -= a
    leafNum -= a
    if (n < 0 || leafNum < 0) {
      println(-1)
      return
    }
    cnt += (n + a)
    n = Math.min(n * 2, leafNum)
  }
  println(cnt)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 51080
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

x = read().rstrip().decode()

def solve(x):
    if x.count('RRR'):
        return 3
    elif x.count('RR'):
        return 2
    elif x.count('R'):
        return 1
    else:
      return 0

print(solve(x))

Measured memory_bytes: 9024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  vector<int> w(n);
  rep(i,n) cin >> w.at(i);
  int ans = INF;
  rep(t,n){
    int s1 = 0;
    int s2 = 0;
    for(int i = 0; i<t; i++){
      s1+=w.at(i);
    }
    for(int i = t; i<n; i++){
      s2+=w.at(i);
    }
    ans = min(ans,abs(s1-s2));
  }
  cout << ans << endl;
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

template<class T>
class BIT{
public:
	vector<T>bit;
	T cnt;
	BIT(int n){
		bit=vector<T>(n+10);
		cnt=0;
	}
	void add(int k,T x){
		k++;
		while(k<(int)bit.size()){
			bit[k]+=x;
			k+=k&-k;
		}
		cnt+=x;
	}
	T sum(int k){
		k++;
		T res=0;
		while(k){
			res+=bit[k];
			k-=k&-k;
		}
		return res;
	}
	T sum2(int k){
		return cnt-sum(k);
	}
};

int c[600000];
int nx[600000];
int ans[600000];

struct st{
	int l,r,id;
};
int main(){
	int n,q;cin>>n>>q;
	map<int,int>mp;
	rep(i,n){
		scanf("%d",&c[i]);
	}
	vector<st>v;
	for(int i=n-1;i>=0;i--){
		int L=i,R;
		if(!mp.count(c[i]))R=n;
		else R=mp[c[i]];
		v.push_back({L,R,-1});
		mp[c[i]]=i;
	}
	rep(i,q){
		int l,r;scanf("%d%d",&l,&r);l--;
		v.push_back({l,r,i});
	}
	sort(v.begin(),v.end(),[](st a,st b){
		if(a.r==b.r)return a.id>b.id;
		return a.r<b.r;
	});
	BIT<int>bit(n);
	for(auto s:v){
		if(s.id==-1){
			bit.add(s.l,1);
		}
		else{
			int all=s.r-s.l;
			ans[s.id]=all-(bit.cnt-bit.sum(s.l-1));
		}
	}
	rep(i,q){
		printf("%d\n",ans[i]);
	}
}

Measured memory_bytes: 44788
#include<bits/stdc++.h>
#define LL long long
#define MAXN 50005
#define INF (1<<25)
#define P int(998244353)
using namespace std;

string s;

int main(){
	
	cin>>s;
	
	int cnt = 0;
	for(int i=1;i<s.length();i++){
		if(s[i] != s[i-1]) ++cnt;
	}
	
	cout<<cnt<<endl;
	
	return 0;
}

Measured memory_bytes: 512
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]


from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

#### START
n, m= map(int,input().split())
fune = []
for _ in range(m):
    li = list(map(int,input().split()))
    if 1 in li:
        li.remove(1)
        fune.append(li[0])
    elif n in li:
        li.remove(n)
        fune.append(li[0])

if len(fune)-len(set(fune))>0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 32544
n,d = map(int,input().split())
x = [0 for i in range(n)]
import math
for i in range(n):
    x[i] = list(map(int,input().split()))
    
count = 0
for i in range(n-1):
    for k in range(i+1,n):
        dist2 = 0
        for j in range(d):
            dist2 += (x[i][j] - x[k][j])**2
        dist = math.sqrt(dist2)
        if dist == math.floor(dist):
            count +=1
print(count)

Measured memory_bytes: 3064
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
/* }}} */

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

// #define int long long

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int, int> pii;
typedef double D;
typedef complex<D> P;

/* const */
const int INF = 999999999;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T> void print(T x) {std::cout << x << '\n';}
template <typename T>
void print(std::vector<T>& v, string s = " ") {
  REP(i, v.size()) {
    if (i != 0) std::cout << s;
    std::cout << v[i];
  }
  std::cout << '\n';
}

/* }}} */

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a = in(), b = in(), h = in();

  print((a + b) * h / 2);

  return 0;
}



Measured memory_bytes: 764
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<ctime>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;

int main()
{
	int a, b, x;
	cin >> a >> b;
	x = a/2 + b/2;
	if(x * 2 != (a + b)) x++;
	printf("%d\n", x);
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
h = Array.new(n + 1)
m = Array.new(n + 1){Array.new(n + 1){0}}
1.upto n do |i|
	h[i - 1], h[i] = gets.split.map(&:to_i)
end

2.upto n do |l|
	1.upto n - l + 1 do |i|
		j = i + l - 1
		m[i][j] = Float::INFINITY
		i.upto j - 1 do |k|
			m[i][j] = [m[i][j], m[i][k] + m[j][k] + m[k + 1][j] + h[i - 1] * h[k] * h[j]].min
		end
	end
end

puts m[1][n]

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

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int y=sc.nextInt();
		for(int i=0;i<=n;i++)
			for(int j=0;j<=n-i;j++)
				if(i*10000+j*5000+(n-i-j)*1000==y)
				{
					System.out.println(i+" "+j+" "+(n-i-j));
					return;
				}
		System.out.println("-1 -1 -1");
				
	}
	static class Scanner 
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException 
		{
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}
		
		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}
		
		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}
		
		public boolean ready() throws IOException {return br.ready();}


	}
}


Measured memory_bytes: 21972
n, m =map(int,input().split())
A = list(map(int,input().split()))
BC = [tuple(map(int,input().split()))for i in range(m)]

A.sort()
BC.sort(key= lambda x : -x[1])


i = 0
for b, c in BC:
    for _ in range(b):
        if c <=  A[i] : break
        A[i] = c
        i += 1
        if i >= n: break
    else:continue
    break
print(sum(A))

Measured memory_bytes: 25644
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInt4() (int, int, int, int) {
	return nextInt(), nextInt(), nextInt(), nextInt()
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, a, b, c := nextInt4()
	l := nextInts(n)

	var dfs func(x, y, z, i, mp int) int
	dfs = func(x, y, z, i, mp int) int {
		if i == n {
			if x*y*z == 0 {
				return 1 << 50
			}
			return mp + abs(a-x) + abs(b-y) + abs(c-z)
		}

		res := dfs(x, y, z, i+1, mp)
		if x == 0 {
			res = min(res, dfs(x+l[i], y, z, i+1, mp))
		} else {
			res = min(res, dfs(x+l[i], y, z, i+1, mp+10))
		}
		if y == 0 {
			res = min(res, dfs(x, y+l[i], z, i+1, mp))
		} else {
			res = min(res, dfs(x, y+l[i], z, i+1, mp+10))
		}
		if z == 0 {
			res = min(res, dfs(x, y, z+l[i], i+1, mp))
		} else {
			res = min(res, dfs(x, y, z+l[i], i+1, mp+10))
		}
		return res
	}

	puts(dfs(0, 0, 0, 0, 0))
}


Measured memory_bytes: 1788
def f():
    n, k = map(int, input().split())
    if k > (n - 1) * (n - 2) // 2:
        print(-1)
        return
    c = (n - 1) * n // 2 - k
    print(c)
    for i in range(1, n):
        for j in range(i + 1, n + 1):
            if c <= 0: return
            print(i, j)
            c -= 1

f()

Measured memory_bytes: 3608
sx, sy, tx, ty = map(int, input().split())

s = ''
for _ in range(ty - sy):
    s += 'U'

for _ in range(tx - sx):
    s += 'R'

for _ in range(ty - sy):
    s += 'D'

for _ in range(tx - sx):
    s += 'L'

s += 'L'

for _ in range(ty - sy + 1):
    s += 'U'

for _ in range(tx - sx + 1):
    s += 'R'

s += 'DR'

for _ in range(ty - sy + 1):
    s += 'D'

for _ in range(tx - sx + 1):
    s += 'L'

s += 'U'

print(s)


Measured memory_bytes: 9208
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define ll long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	ll x;
	cin >> x;
	ll ans = x / 11 * 2;
	if(x%11!=0 && x % 11 <= 6)ans++;
	else if (x % 11 != 0 && x % 11 >6)ans += 2;
	println(ans);
}

Measured memory_bytes: 3608
//author:satwik_bhv1
#include<bits/stdc++.h>
//datatypes
#define ll long long 
#define ld long double
//loops
#define fr(i,z,n) for(ll i=z;i<n;i++)
#define br(i,z,n) for(ll i=z;i>n;i--)
//operations
#define mp  make_pair
#define ff  first
#define ss  second
#define pub push_back
#define all(v) v.begin(),v.end()
//map
#define mi map<ll,ll>
//vectors
#define vi vector<ll>
#define vpi vector<pair<ll,ll> >
//constants
#define pi 3.1415926535897932384626
#define mod 1000000007 
#define MAXN 100001
/*notes
    Don't use inbuilt fun for power
    Range of longlong=(-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 )
    INT_MAX = 2147483647(aprox 2*10^10)
    INT_MIN = -2147483648
    LLONG_MAX = 9223372036854775807 
    LLONG_MIN = -9223372036854775808
    __gcd is the function in built for hcf
    priority queue is max heap by default
    topological sort -> khan's algo use bfs and indegree of node  
    sssp(positive weighted edges) -> Dijkstras
    apsp -> Floydwarshall
    MST -> kruskal(DSU)
*/
using namespace std;
//functions
ll power(ll x,ll y){ll res=1;while(y){if(y%2){res*=x;}y/=2;x*=x;} return res;}
ll power(ll x,ll y,ll z){ll res=1;while(y){if(y%2){res=(res*x)%z;}y/=2;x=(x*x)%z;} return res;}
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
bool sortbysec(const pair<ll, ll>& a, const pair<ll, ll>& b) { return (a.second > b.second); }
ll ceil(ll x,ll y){return (x/y)+(x%y!=0);}
ll n,k;
vi v(100001);
vi dp(100001,-1);
ll fun(ll pos)
{
    if(pos==n-1)
    {
        return 0;
    }
    ll ans=LLONG_MAX;
    fr(i,1,k+1)
    {
        if(i+pos<n)
        {
            if(dp[i+pos]!=-1)
            {
                ans=min(ans,abs(v[i+pos]-v[pos])+dp[i+pos]);
            }
            else
            {
                ans=min(ans,abs(v[i+pos]-v[pos])+fun(i+pos));
            }
        }
        else
        {
            break;
        }
    }
    return dp[pos]=ans;
}
void solve()
{
    cin>>n>>k;
    fr(i,0,n)
    {
        cin>>v[i];
    }
    cout<<fun(0);
}
int main()
{
    fast();
    ll t;
    t=1;
    //cin>>t;
    fr(i,0,t)
    {
        solve();
    }
}
/*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
*/


Measured memory_bytes: 11120
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

constexpr int dx[] = {-1, 0, 1, 0};
constexpr int dy[] = {0, -1, 0, 1};

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	string x;
	cin >> x;
	int n = x.size();
	int result = 0;
	int c = 0;
	REP(i, n) {
		if(x[i] == 'S') {
			c++;
		} else {
			if(c == 0) {
				result++;
			} else {
				c--;
			}
		}
	}
	cout << result * 2 << endl;
	return 0;
}


Measured memory_bytes: 3732
#include <iostream>
#include <vector>
#include <set>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
int n, m, q;
int a[51], b[51], c[51], d[51];
int v[11];
int ans = 0;
 
 
int main() {
    int N, M;
    cin >> N >> M;
    
    vector<long long> H;
    vector<long long> ma;
    for (int i= 0;i<N;i++){
        long long HM = 0;
        cin >> HM;
        H.push_back(HM);
        ma.push_back(0);
    }
    for (int i= 0;i<M;i++){
        long long n1 ,n2;
        cin >> n1 >> n2;
        ma[n1-1] = max(ma[n1-1], H[n2-1]);
        ma[n2-1] = max(ma[n2-1], H[n1-1]);
    }
    int ans = 0;
    for (int i= 0;i<N;i++){
        if (H[i] > ma[i]) {
            ans++;
        }
    }
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 5056
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int X;
  cin >> X;
  if (X >= 30) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3632
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

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

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    vector<PII> a(n);
    for(int i = 1; i <= n; i++){
        cin >> a[i - 1].F;
        a[i - 1].S = i;
    }
    sort(ALL(a));
    for(auto x : a){
        cout << x.S << ' ';
    }
    return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define pii pair<int, int> 
#define mod 1000000007
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b%2!=0) res=(res*a);
        a=(a*a);
        b/=2;
        if(res>INT_MAX){
            return INT_MAX;
        }
    }
    return res;
}
ll ncr(ll n,ll k){
    if(k==0||k==n) return 1ll;
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i));
        pro/=(i+1);
    }
    return pro;
}
vector<int> prime;
void seive(){
    vector<bool > isprime(101,true);
    for(int i=2;i*i<=100;i++){
        if(isprime[i]){
            for(int j=i*i;j<=100;j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2;i<=100;i++){
        if(isprime[i]) prime.push_back(i);
    }
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k,a;
    cin>>n;
    vector<ll> A,B;
    priority_queue<pll> pq;
    for(int i=0;i<n;i++) {
        cin>>a;
        A.push_back(a);
    }
    for(int i=0;i<n;i++){
        cin>>a;
        B.push_back(a);
        pq.push({a,i});
    }
    ll count=0;
    while(!pq.empty()){
        pll p=pq.top();
        pq.pop();
        ll pr=(p.se-1+n)%n;
        ll nxt=(p.se+1)%n;
        //cout<<pr<<" "<<nxt<<endl;
        if(B[p.se]==A[p.se]){
            continue;
        }
        if(B[p.se]<A[p.se]) {
            cout<<"-1";
            return 0;
        }
        if(A[p.se]>B[pr] && A[p.se]>B[nxt]){
            if((B[p.se]-A[p.se])%(B[pr]+B[nxt])!=0) {
                cout<<"-1";
                return 0;
            }
            count+=(B[p.se]-A[p.se])/(B[pr]+B[nxt]);
            B[p.se]=A[p.se];
            continue;
        }
        if(B[p.se]<B[pr]+B[nxt]) {
            cout<<"-1";
            return 0;
        }
        count+=B[p.se]/(B[pr]+B[nxt]);
        B[p.se]%=(B[pr]+B[nxt]);
        if(B[p.se]==0) {
            cout<<"-1";
            return 0;
        }
        pq.push({B[p.se],p.se});
    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 11248
N, M = map(int, input().split())

AB = [tuple(map(int, input().split())) for _ in range(M)]

AB.sort(key=lambda x: x[1])
num = 0
p = 0
for i in AB:
    if i[0] >= p:
        num += 1
        p = i[1]

print(num)


Measured memory_bytes: 18248
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) {
		FastScanner fs = new FastScanner();
		String s = fs.nextLine();
		int c=0,max=0;
		for(int i=0;i<s.length();i++)
		{
			
			if(s.charAt(i)=='R')
			{
				c++;
				max = Math.max(max, c);
			}
			else
			{
				c=0;
			}
			
		}
		System.out.println(max);

	}

	
	
	
	
	
	
	static class FastScanner
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastScanner() 
        { 
            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: 32752
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let x = v[0];
	let v:Vec<i32> = procon_read();
	let a = v[0];
	let v:Vec<i32> = procon_read();
	let b = v[0];
	let n = (x - a) / b;
	println!("{}", x - a - n*b);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimization_level 3
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    ll n;
    cin >> n;
    vector<ll> h(n);

    rep(i, n) cin >> h.at(i);

    for(int i = n - 2; i >= 0; i--) {
        if(h.at(i) > h.at(i + 1))
            h.at(i)--;
    }

    bool ans = true;
    for(size_t i = 0; i < n - 1; i++) {
        if(h.at(i) > h.at(i + 1))
            ans = false;
    }

    if(ans)
        cout << "Yes";
    else
        cout << "No";
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const int mod = 1e9+7;
const int N = 1e5+5;
int a[N];

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int arr[3];

    cin >> arr[0] >> arr[1] >> arr[2];

    sort(arr, arr+3);

    cout << arr[2]-arr[1] + arr[1]-arr[0];

    return 0;
}


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

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  int num = 100 * r + 10 * g + b;
  if (num % 4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
N = int(input())
ans = 0
for m in range(1,10**6):
    if N // m == N % m:
        ans += m
for k in range(1,10**6):
    if (N-k) % k == 0:
        m = (N-k) // k
        if m > 10**6:
            ans += m
print(ans)

Measured memory_bytes: 64908
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	stack<int> s1;
	stack<pair<int,int> > s2;
	int sum=0;
	char ch;
	for(int i=0;cin>>ch;i++)
	{
		if(ch=='\\') s1.push(i);
		else if(ch=='/'&&s1.size()>0)
		{	
		int j=s1.top();s1.pop();
		sum+=i-j;
		int a=i-j;
		while(s2.size()>0&&s2.top().first>j)
		{
			a+=s2.top().second;s2.pop();
		}
		s2.push(make_pair(j,a));
		}
	}
	vector<int> ans;
	while(s2.size()>0)
	{
		ans.push_back(s2.top().second);s2.pop();
	}
	reverse(ans.begin(),ans.end());
	cout<<sum<<endl;
	cout<<ans.size();
	for(int i=0;i<ans.size();i++)
	{
		cout<<" ";
		cout<<ans[i];
	}
	cout<<endl;
	return 0;
 } 

Measured memory_bytes: 3232
function main(input){
    var a,b;
    [a,b] = input.split(' ');
    a = parseInt(a);
    b = parseInt(b);

    if (a > b) {
        console.log("a > b");
    } else if(a < b){
        console.log("a < b");
    }
    else{
        console.log("a == b");
    }

}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 17152
n = int(input())
check = [list(map(int, input().split())) for _ in range(n)]
prev = [0,0,0]
feasible = True

for point in check:
    time = point[0] - prev[0]
    dist = abs(point[1] - prev[1]) + abs(point[2] - prev[2])
    if time - dist < 0 or (time - dist) % 2:
        feasible = False
        break
    else:
        prev = point

if feasible:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 27380
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
 
 

int main (){
    int l[100] = {0};
    int ans = 0;
    int n,k;
    int i; 
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&l[i]);
    }
    sort(l,l+n);
    for(i=0;i<k;i++){
        ans += l[n-1-i];
    }
    printf("%d\n",ans);
    
    return 0;
}


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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  map<int, int> vs;
  for(int i = A; i <= min(B, A + K - 1); ++i) {
    vs[i]++;
  }
  for(int i = B; i >= max(A, B - K + 1); --i) {
    vs[i]++;
  }
  for(auto v : vs) {
    cout << v.first << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int D = sc.nextInt();
			final int T = sc.nextInt();
			final int S  =sc.nextInt();
			
			System.out.println(T * S >= D ? "Yes" : "No");
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 32612
S=input()

S=S.replace("BC","D")
T=[0]*len(S)
#print(S)

for i in range(len(S)):
  if S[i]=="A":
    T[i]=T[i-1]+1
  elif S[i]=="D":
    T[i]=T[i-1]
  else:
    T[i]=0
#print(T)

ans=0
for i in range(len(S)):
  if S[i]=="D":
    ans+=T[i]
print(ans)

Measured memory_bytes: 43376
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <deque>
#include <bitset>
typedef long long ll;
using namespace std;
#define trace(x) cerr << #x << " is " << x << endl;




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

    int a , b;
    cin >> a >> b;
    cout << a * b <<endl;

    return 0;
}


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

using namespace std;

#ifdef NeverBeRed
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second



int main()
{
	#ifdef TurnRed
		//freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	ll x, vx, y, vy, t;
	cin >> x >> vx >> y >> vy >> t;
	y = abs(x - y);
	if (vx * t >= y + vy * t)
		cout << "YES\n";
	else
		cout << "NO\n";

	return 0;
}


Measured memory_bytes: 3648
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)

	x := make([]int, n)
	for i := range x {
		fmt.Scan(&x[i])
	}

	y := make([]int, n)
	for i := range y {
		fmt.Scan(&y[i])
	}

	p1 := 0.0
	p2 := 0.0
	p3 := 0.0
	max := 0.0
	for i := 0; i < n; i++ {
		p1 += absDistance(x[i], y[i])
		p2 += absDistance(x[i], y[i]) * absDistance(x[i], y[i])
		p3 += absDistance(x[i], y[i]) * absDistance(x[i], y[i]) * absDistance(x[i], y[i])
		if max < absDistance(x[i], y[i]) {
			max = absDistance(x[i], y[i])
		}
	}
	fmt.Printf("%f\n", p1)
	fmt.Printf("%f\n", math.Sqrt(p2))
	fmt.Printf("%f\n", math.Cbrt(p3))
	fmt.Printf("%f\n", max)
}

func absDistance(x, y int) float64 {
	return math.Abs(float64(x) - float64(y))
}



Measured memory_bytes: 1164
import math
N=int(input())
a=[]
A=0
for _ in range(N):
    x,y=map(int,input().split())
    a.append((x,y))
b=math.factorial(N)*2//N
for i in range(N):
    for j in range(i+1,N):
        route=math.sqrt((a[i][0]-a[j][0])**2+(a[i][1]-a[j][1])**2)
        A+=b*route
c=math.factorial(N)
print(A/c)

Measured memory_bytes: 3064
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n;i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;
#define mo 1000000007
#define ull unsigned long long 

int main(){
  string n;cin>>n;
  string ans="No";
  if(n.at(0)==n.at(1)&&n.at(1)==n.at(2) || n.at(1)==n.at(2)&&n.at(2)==n.at(3))
    ans="Yes";
  cout<<ans;
}


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

using namespace std;


#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 1e6 + 1, MOD = 1e9 + 7, mod = 998244353, INF = 3e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;


bool used[N];

signed main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);
   string s;
   cin >> s;
   for (int i = 0; i < s.size(); i++) {
      used[s[i]] = 1;
   }
   for (char c = 'a'; c <= 'z'; c++) {
      if (!used[c]) {
         cout << s << c;
         return 0;
      }
   }

   for (int i = s.size() - 1;  i >= 0; i--) {
      for (char c = 'a'; c <= 'z'; c++) {
         if (c > s[i] && !used[c]) {
            for (int j = 0;  j < i; j++) cout << s[j];
            cout << c;
            return 0; 
         }
      }
      used[s[i]] = 0;
   }
   cout << -1;
   return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}
int dp[10000005]={0};

void findDivisors(int n) 
{ 
  
  
    // For every number from 1 to n 
    for (int i = 1; i <= n; i++) { 
  
        // Increase divisors count for 
        // every number divisible by i 
        for (int j = 1; j * i <= n; j++) 
            dp[i * j]++; 
    } 
  int ans=0;
    // Print the divisors 
    for (int i = 1; i <= n; i++) 
        ans+=i*dp[i];
    
    
    cout << ans;

} 
int32_t main()
{
	fast;
	int n;
	cin >> n;
	findDivisors(n);
}



Measured memory_bytes: 81760
N = int(input())
H = list(map(int, input().split()))

tmp = [0 for _ in range(N)]
tmp[1] = abs(H[1] - H[0])
for i in range(2, N):
    tmp[i] = min(tmp[i - 2] + abs(H[i] - H[i - 2]), tmp[i - 1] + abs(H[i] - H[i - 1]))
    
print(tmp[N-1])

Measured memory_bytes: 13928
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)b - *(long int*)a; // 大きい順
}
int compare_int_small(const void *a, const void *b){
  return *(long int*)a - *(long int*)b; // 小さい順
}
// 公約数
long long int gcd(long long int a, long long int b){
  if(b == 0){
    return a;
  }else{
    return gcd(b, a % b);
  }
}
// 最小公倍数 = a * b / 最大公約数
// 公倍数
long long int lcm(long long int a, long long int b){
  return a * b / gcd(a, b);
}

// 15min
int main(void){
  int n, m, c;
  //  int a[21][21] = {0};
  int b[21] = {0};
  int ans = 0;

  scanf("%d%d%d", &n, &m, &c);

  // bの配列取得
  for(int i = 0; i < m; i++){
    scanf("%d", &b[i]);
  }

  // aの値の計算。n回計算する。
  for(int i = 0; i < n; i++){
    int sum = 0; 
    for(int j = 0; j < m; j++){
      int tmp;
      scanf("%d", &tmp);
      sum += tmp * b[j];
    }
    if(sum + c > 0){
      ans++;
    }
  }
  
  
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int a = 0, b = 0;
  ll ans = 0;
  if (A % 2 == 1)
    a++;
  else
    b++;
  if (B % 2 == 1)
    a++;
  else
    b++;
  if (C % 2 == 1)
    a++;
  else
    b++;
  if (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
  } else if (A % 2 == 1 && B % 2 == 1 && C % 2 == 1) {
  } else if (a == 2) {
    ans++;
    if (A % 2 == 0) {
      B++;
      C++;
    } else if (B % 2 == 0) {
      A++;
      C++;
    } else {
      A++;
      B++;
    }
  } else {
    ans++;
    if (A % 2 == 1) {
      B++;
      C++;
    } else if (B % 2 == 1) {
      A++;
      C++;
    } else {
      A++;
      B++;
    }
  }
  ll mx = max(A, max(B, C));
  ll num = mx * 3 - A - B - C;
  ans += num / 2;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void) {

	int N, a[100], hai = 0, cha = 0, mido = 0, mizu = 0, ao = 0, ki = 0, dai = 0, aka = 0, nazo = 0, ans = 0,min=0,max=0;

	cin >> N;

	for (int i = 0; i < N; i++) {

		cin >> a[i];

		if (a[i] <= 399) {

			hai++;
			if (hai == 1)
				ans++;

		}

		else if (a[i] <= 799) {

			cha++;
			if (cha == 1)
				ans++;

		}

		else if (a[i] <= 1199) {

			mido++;
			if (mido == 1)
				ans++;

		}

		else if (a[i] <= 1599) {

			mizu++;
			if (mizu == 1)
				ans++;
		}

		else if (a[i] <= 1999) {

			ao++;
			if (ao == 1)
				ans++;
		}

		else if (a[i] <= 2399) {

			ki++;
			if (ki == 1)
				ans++;
		}

		else if (a[i] <= 2799) {

			dai++;
			if (dai == 1)
				ans++;
		}

		else if (a[i] <= 3199) {

			aka++;
			if (aka == 1)
				ans++;
		}

		else {
			nazo++;
		}


	}

	if (N >= 8) 
			max = ans + nazo;

	else
			max = ans + nazo;

	min = ans;

	if (min == 0)
		min = 1;

	cout << min <<" "<< max << endl;

}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline
MOD = 1000000007

O = input()[:-1]
E = input()[:-1]


for i in range(min(len(O),len(E))):
    print(O[i],end="")
    print(E[i],end="")

if len(O) > len(E):
    print(O[-1])
if len(O) < len(E):
    print(E[-1])
else:
    print()



Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define eps 1e-6
using namespace std;

int main()
{
  int n;
  cin>>n;
  ll ans=0;
  ans+=1000*(n/500);
  n=n-n/500*500;
  ans+=5*(n/5);
  cout<<ans<<endl;
}


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

int main(){
  int n,k;
  cin >> n >> k;
  const ll INF = pow(10,9)+7;
  vector<vector<ll>> comb(n+1, vector<ll>(n+1));
  comb[0][0] = 1;
  rep(i,n){
    rep(j,i+1){
      comb[i][j] %= INF;
      comb[i+1][j] += comb[i][j];
      comb[i+1][j+1] += comb[i][j];
    }
  }
  rep1(i,k){
    ll comb1 = comb[n-k+1][i];
    ll comb2 = comb[k-1][i-1];
    cout << comb1*comb2%INF << endl;
  }
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w;
	cin >> h >> w;
	vector<string> v(h);
	REP(i, h)cin >> v[i];
	vvi cnt(h, vi(w, 0));
	REP(i, h) {
		REP(j, w) {
			if (v[i][j] == '#') {
				REP(k, 8) {
					int ni = i + dx[k], nj = j + dy[k];
					if (ni < 0 || nj < 0 || ni >= h || nj >= w)continue;
					cnt[ni][nj]++;
				}
			}
		}
	}
	REP(i, h) {
		REP(j, w) {
			if (v[i][j] == '.')v[i][j] = cnt[i][j] + '0';
		}
	}
	REP(i, h) {
		cout << v[i] << endl;
	}

}


Measured memory_bytes: 256
K = int(input())

import sys
if K%2 == 0 or K%5 == 0:
    print(-1)
    sys.exit()
mod = 0

for i in range(1000000):
    mod += (7*pow(10,i,K))%K
    mod = mod%K
    if mod%K == 0:
        print(i+1)
        sys.exit()

Measured memory_bytes: 9180
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
#include<functional>
using namespace std;

int MOD = 1e9 + 7;

typedef long long ll;
typedef pair<int, int> P;

string s;

int reversi(char B, char W) {
	int ans = 0;
	bool x = false;
	for (int i = 1; i < s.size(); i++) {
	if (s[i] == B && x == true) {
		x = false;
			ans++;
		}
		else if (s[i] == W && x == false) {
			x = true;
			ans++;
		}
	}	
	return ans;
}

int main() {
	cin >> s;

	char B = 'B', W = 'W';
	if (s[0] == 'B') cout << reversi(B, W) << endl;
	else cout << reversi(W, B) << endl;
}

Measured memory_bytes: 636