akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int n, m, dp1[3009][3009], dp2[3009][3009], dp3[3009][3009], dp4[3009][3009]; long long sum1[3009], sum2[3009], mod = 1000000007;

int main() {
	cin >> n >> m;
	dp1[0][0] = 1; dp2[0][1] = 1; dp3[0][0] = 1; dp4[0][1] = 1;
	for (int i = 0; i <= m; i++) {
		for (int j = 0; j <= n; j++) {
			if (j >= 2) {
				dp1[i + 1][j - 1] += dp1[i][j]; dp1[i + 1][j - 1] %= mod;
				dp1[i + 1][j] += dp1[i][j]; dp1[i + 1][j] %= mod;
				dp2[i + 1][j - 1] += dp2[i][j]; dp2[i + 1][j - 1] %= mod;
				dp2[i + 1][j] += dp2[i][j]; dp2[i + 1][j] %= mod;
			}
			if (j < n && j >= 1) {
				dp1[i + 1][j + 1] += dp1[i][j]; dp1[i + 1][j + 1] %= mod;
				dp1[i + 1][j] += dp1[i][j]; dp1[i + 1][j] %= mod;
				dp2[i + 1][j + 1] += dp2[i][j]; dp2[i + 1][j + 1] %= mod;
				dp2[i + 1][j] += dp2[i][j]; dp2[i + 1][j] %= mod;
			}
			if (j >= 1) {
				dp3[i + 1][j - 1] += dp3[i][j]; dp3[i + 1][j - 1] %= mod;
				dp3[i + 1][j] += dp3[i][j]; dp3[i + 1][j] %= mod;
				dp4[i + 1][j - 1] += dp4[i][j]; dp4[i + 1][j - 1] %= mod;
				dp4[i + 1][j] += dp4[i][j]; dp4[i + 1][j] %= mod;
			}
			if (j < n) {
				dp3[i + 1][j + 1] += dp3[i][j]; dp3[i + 1][j + 1] %= mod;
				dp3[i + 1][j] += dp3[i][j]; dp3[i + 1][j] %= mod;
				dp4[i + 1][j + 1] += dp4[i][j]; dp4[i + 1][j + 1] %= mod;
				dp4[i + 1][j] += dp4[i][j]; dp4[i + 1][j] %= mod;
			}
		}
	}
	for (int i = 0; i <= m; i++) {
		for (int j = 0; j <= n; j++) {
			sum1[i] += dp3[i][j]; sum1[i] %= mod;
			sum2[i] += dp4[i][j]; sum2[i] %= mod;
		}
	}
	long long sum = 0;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			sum += 1LL * dp1[j][i] * sum1[m - j];
			if (j < m) {
				sum += 1LL * dp2[j][i] * sum1[m - j - 1];
				sum += 1LL * dp2[j][i] * sum2[m - j - 1];
			}
			sum %= mod;
		}
	}
	cout << sum << endl;
	return 0;
}

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

#define pb push_back
#define pf push_front
#define pp pop_back
#define sz(a) (int)(a.size())
#define mp make_pair
#define F first
#define S second
#define next _next
#define prev _prev
#define left _left
#define right _right
#define y1 _y1
#define all(x) x.begin(), x.end()
#define what_is(x) #x << " is " << (x)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = (int)1e6 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;

void megaRandom() {                  
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  srand(FOR);
}

ll a[10];

int main() {
	megaRandom();
	for(int i = 1; i <= 7; i ++) 
		cin >> a[i];

	ll k = a[2] * 2, k2 = k, res = 0;
	for(int it = 0; it <= min({(ll)1e8, a[1], a[4], a[5]}); it ++) {
		a[1] -= it, a[4] -= it, a[5] -= it;
		ll now = k + (a[1] / 2) * 4 + (a[4] / 2) * 4 + (a[5] / 2) * 4 + it * 6;
		//cout << now << ' ';
		res = max(res, now);
		a[1] += it, a[4] += it, a[5] += it;
	}
	//cout << "\n";
	cout << res / 2;
	return 0;  
}


Measured memory_bytes: 256
from collections import deque
from copy import deepcopy

h, w = map(int, input().split())
INF = float("inf")
s = [list(map(lambda x: -1 if x == "#" else INF, input())) for _ in range(h)]

ans = 0

def bfs(init_y, init_x, s):
    vect = ((-1, 0), (0, -1), (1, 0), (0, 1))
    if s[init_y][init_x] == -1: return 0
    s[init_y][init_x] = 0
    q = deque([(init_y, init_x)])
    while q:
        y, x = q.popleft()
        for dy, dx in vect:
            ny, nx = y + dy, x + dx
            if ny < 0 or ny >= h or nx < 0 or nx >= w or s[ny][nx] != INF: continue
            s[ny][nx] = s[y][x] + 1
            q.append((ny, nx))
    return max(map(max, s))

for i in range(h):
    for j in range(w):
        ans = max(ans, bfs(i, j, deepcopy(s)))

print(ans)


Measured memory_bytes: 3436
#include "bits/stdc++.h"
using namespace std;    

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))    
#define OUT(P) cout << (P) << endl    
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl    
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;    
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)    
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)    
typedef long long ll;    
const long DIVIDE = 1e9+7;

int sum_digits(int num);    
template <class T>    
vector<T> copy_vector(vector<T> vec);    
long gcd(long a, long b);    
long lcm(long a, long b);
// ****** print functions ****** //
template <class T, class U>
void print_pairs(const vector<pair<T, U>> pairs);
template <class K, class V>
void print_map(const map<K, V> m);


int main() {    
    int n;
    cin >> n;

    vector<int> p(n);
    for(int i=0; i<n; i++) {
        cin >> p[i];
    }
    int cnt = 0;
    for(int i=1; i<n-1; i++) {
        int p0 = p[i-1];
        int p1 = p[i];
        int p2 = p[i+1];
        vector<int> tmp{p0, p1, p2};
        sort(tmp.begin(), tmp.end());

        if(p1 == tmp[1]) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;    
}    

/******************************/    
/***** DECRARED FUNCTIONS *****/    
/******************************/    

int sum_digits(int num) {    
    int rtn = 0;    
    while(num != 0) {    
        int tmp = num % 10;    
        rtn += tmp;    
        num /= 10;    
    }    
    return rtn;    
}    

// vectorのコピー    
template <class T>    
vector<T> copy_vector(vector<T> vec) {    
    vector<T> rtn;    
    rtn.reserve(vec.size());    
    copy(vec.begin(), vec.end(), back_inserter(rtn));    
    return rtn;    
}    

long gcd(long a, long b) {    
    if(b==0) return a;    
    else return gcd(b, a % b);    
}

long lcm(long a, long b) {
    long gcd_ = gcd(a, b);
    return (a * b) / gcd_;
}

template <class T, class U>
void print_pairs(const vector<pair<T, U>> &pairs) {
    for(int i=0; i<pairs.size(); i++) { 
        cout << "(" << pairs[i].first << ", " << pairs[i].second << ")" << " "; 
    } 
    cout << endl;
}

template <class K, class V>
void print_map(const map<K, V> &m) {
    for(auto it=m.cbegin(); it!=m.cend(); it++) {
        cout << it->first << ": " << it->second << endl;
    }
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

bool check(string s) {
    int ind = -1;
    for(int i = 2; i < s.length() - 1; ++i) {
        if(s[i] == 'C') {
            if(ind != -1) { return false; }
            ind = i;
        }
    }
    if(ind == -1) { return false; }
    for(int i = 1; i < s.length(); ++i) {
        if(i == ind) { continue; }
        if(s[i] >= 'A' && s[i] <= 'Z') { return false; }
    }
    return true;
}

signed main()
{
    string S;
    cin >> S;
    if(S[0] == 'A' && check(S)) {
        printf("AC\n");
    }
    else {
        printf("WA\n");
    }
    return 0;
}


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

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;

using namespace std;

/*typedef struct job_
{
    int delay;
    int wage;
    bool done;
    
    job_(int delay_, int wage_, bool done_){
        delay = delay_;
        wage = wage_;
        done = done_;
    }
    
    bool operator<(const job_ &another) const
    {
        return wage > another.wage;
    };
} job*/

int main(void){
    int N, M;
    vector<vector<int> > Job(M+1);
    cin >> N >> M;
    
    int a, b;
    rep(i, N){
        cin >> a >> b;
        if(M >= a){
            Job[a].push_back(b);
        }
    }
    
    //sort(all(Job));
    
    int total=0;
    
    priority_queue<int> que;
    for(int i = 1; i <= M; i++){
        for(int b : Job[i]){
            que.push(b);
        }
        if(!que.empty()){
            total += que.top();
            que.pop();
        }
        /*rep(j, N){
            if(Job[j].delay <= i && Job[j].done == false){
                Job[j].done = true;
                total += Job[j].wage;
                break;
            }
        }*/
//        cout << total << endl;
    }
    
    cout << total << endl;
    
    return 0;
}


Measured memory_bytes: 150912
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>

using namespace std;

int main()
{
    int n;
    cin >> n;
    string ans="Three";
    for(int i=0; i<n; i++){
        char tmp;
        cin >> tmp;
        if(tmp=='Y'){
            ans="Four";
        }
    }
    cout << ans;

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define B 10007
#define mod 1000000033

ll mod_pow(ll x,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*x%mod;
    x=x*x%mod;
    n>>=1;
  }
  return res;
}

string S,T;
vector<int> col;
vector<int> mem,nxt;
vector<int> ind;

bool dfs(int i){
  col[i]=1;
  if(nxt[i]==-1){
    col[i]=2;
    return true;
  }
  if(col[nxt[i]]==1)return false;
  if(col[nxt[i]]==0&&!dfs(nxt[i]))return false;
  col[i]=2;
  return true;
}

int dfs2(int i){
  if(mem[i]!=-1)return mem[i];
  if(nxt[i]==-1)return 0;
  else return mem[i]=dfs2(nxt[i])+1;
}

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

  cin>>S>>T;
  {
    string sS;
    while(sS.size()<T.size()){
      sS+=S;
    }
    S=sS;
  }

  int N=S.size();
  int M=T.size();
  vector<ll> Sh(N+1,0),Th(N+1,0);
  nxt.resize(N,-1); ind.resize(N,0);
  rep(i,N)Sh[i+1]=(Sh[i]+S[i]*mod_pow(B,i)%mod)%mod;
  rep(i,M)Th[i+1]=(Th[i]+T[i]*mod_pow(B,i)%mod)%mod;

  auto extract = [&](ll l,ll r,bool f) {
    if(!f) return (Sh[r]-Sh[l]+mod)*mod_pow(mod_pow(B,mod-2),l)%mod;
    else return (Th[r]-Th[l]+mod)*mod_pow(mod_pow(B,mod-2),l)%mod;
  };

  rep(i,N){
    if(i+M<=N){
      if(extract(i,i+M,false)==extract(0,M,true)){
        nxt[i]=(i+M)%N;
      }
    }else{
      int l=N-i;
      if(extract(i,N,false)==extract(0,l,true)&&extract(0,M-l,false)==extract(l,M,true)){
        nxt[i]=(i+M)%N;
      }
    }
  }

  ind.resize(N,0);
  rep(i,N)if(nxt[i]!=-1)ind[nxt[i]]++;

  col.resize(N,0);
  rep(i,N){
    if(col[i]!=0)continue;
    if(!dfs(i)){
      cout<<-1<<endl;
      return 0;
    }
  }
  mem.resize(N,-1);
  int res=0;
  rep(i,N){
    if(ind[i]>0)continue;
    maxch(res,dfs2(i));
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 37424
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
#include <unordered_set>
using namespace std;


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

  int32_t N;
  cin >> N;
  unordered_map<string, int> cnt;
  int max_cnt = 0;
  vector<string> max_strings;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    cnt[s]++;
    if (cnt[s] == max_cnt) {
      max_strings.emplace_back(s);
    } else if (cnt[s] == max_cnt + 1) {
      max_cnt++;
      max_strings.clear();
      max_strings.push_back(s);
    }
  }

  sort(max_strings.begin(), max_strings.end());
  for (auto s : max_strings) {
    cout << s << endl;
  }

  return 0;
}

Measured memory_bytes: 24248
// 最小の集合場所の座標はどこかわからないので、
// 総当たりで場所を探し一番コストが少ない場所を集合場所の座標とする

// inputに入力データ全体が入る
function Main(inputString) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    let inputLineArray = inputString.split("\n");

    // 住んでる座標の文字列配列
    let livingPointStringArray = inputLineArray[1].split(" ");

    // 想定される最小の移動コスト
    let minRequiredPhysicalStrength = 999999;

    // 住んでる座標の文字列配列を数値配列に変換する
    let livingPointArray = [];
    livingPointStringArray.forEach( element => {
        let livingPoint = parseInt( element, 10)
        livingPointArray.push(livingPoint); 
    });

    // 住んでる座標のうち、最小値と最大値を求める
    let minLivingPoint = Math.min.apply( null, livingPointArray);
    let maxLivingPoint = Math.max.apply( null, livingPointArray);

   // 移動コストが最小の座標を求める
    for( i = minLivingPoint; i <= maxLivingPoint; i++ ){
        let tmpMeetingPoint = i;   
        minRequiredPhysicalStrength = requiredPhysicalStrengthFunction(livingPointArray, tmpMeetingPoint, minRequiredPhysicalStrength);
    }

 

    console.log('%d', minRequiredPhysicalStrength);
}

    // 必要な体力を計算する関数
function requiredPhysicalStrengthFunction(in_livingPointArray, in_meetingPoint, in_minRequiredPhysicalStrength){
    // 必要な体力の合計値
    let tmpAllRequiredPhysicalStrength = 0;

    // 住んでる座標の配列
    in_livingPointArray.forEach( livingPoint => {
        //必要な体力は(住んでる座標 - 集合場所の候補の座標)の2乗
        let requiredPhysicalStrength = Math.pow(( livingPoint - in_meetingPoint ) , 2);
        tmpAllRequiredPhysicalStrength += requiredPhysicalStrength;
    });
    // 一番小さいと思っている消費コストより今回の座標の消費コストの方が小さければそれを最小値とする
    if(in_minRequiredPhysicalStrength > tmpAllRequiredPhysicalStrength){
        return tmpAllRequiredPhysicalStrength;
    } else {
        return in_minRequiredPhysicalStrength;
    }
}

    //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
    Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include<iostream>
using namespace std;
int main()
{
long long int n,k;
cin>>n>>k;
long long int arr[n];
for(int i=0; i<n; ++i)
cin>>arr[i];
for(int i=0; i<n-k; ++i)
{
if(arr[i+k]>arr[i])
cout<<"Yes\n";
else
cout<<"No\n";
}
return 0;
}



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

int main()
{
	int x = 0;
	string s, t;

	cin >> s >> t;

	for (int i = 0; i < 3; i++) {
		if (s.at(i) == t.at(i)) {
			x++;
		}
	}

	cout << x;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char a[10],b[10],c[10];
    scanf("%s%s%s",a,b,c);
    if(a[strlen(a)-1]==b[0] && b[strlen(b)-1]==c[0]) printf("YES\n");
    else printf("NO\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int a, b, c;
	cin >> a >> b >> c;
	repl(i, 1, b + 1) {
		if (a * i % b == c) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}

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

public class Main {

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

		String str = br.readLine();
		StringTokenizer st = new StringTokenizer(str, " ");
		int a = Integer.parseInt(st.nextToken());
		int b = Integer.parseInt(st.nextToken());

		int d = a / b;
		int r = a % b;
		double f = 1.0 * a / b;
		String str2 = String.format("%.8f", f);

		System.out.println(d + " " + r + " " + str2);

	}
}


Measured memory_bytes: 24828
N = int(input())
X = [50] * 26
for _ in range(N):
    S = input()
    for i in range(26):
        X[i] = min(X[i], S.count(chr(97+i)))

ANS = ""
for i in range(26):
    ANS += chr(97+i) * X[i]
print(ANS)


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

int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    if(a+b==c||b+c==a||c+a==b){
        cout<<"Yes";
    }else cout<<"No"<<endl;

    return 0;
    }

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
  public static void main(String[] args) throws Exception {
    String line = null;
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    line = br.readLine();
    int size = Integer.parseInt(line);
    line = br.readLine();
    String data[] = line.split(" ");
    long[] array = new long[size];
    for (int i = 0; i < size; i ++) {
      long num = Long.parseLong(data[i]);
      array[i] = num;
    }
    int count = 0;
    while (true) {
      boolean flag = false;
      for (int i = 0; i < size; i ++) {
        long val = array[i];
        long res = val%2;
        if (res != 0) {
          flag = true;
        }
        val = val/2;
        array[i] = val;
      }
      if (flag) break;
      count = count + 1;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 22100
from sys import stdin
from collections import deque, defaultdict as ddic
from itertools import combinations, permutations, product
import bisect
import heapq


rs = lambda: stdin.readline().strip()
ri = lambda: int(rs())
rsl = lambda: stdin.readline().split()
rim = lambda: map(int, rsl())
ril = lambda: list(rim())

N = ri()
A = list(rim())
B = [abs(elem) for elem in A]

low = min(B)
minus = 0
for i in range(len(A)):
    if A[i] < 0:
        minus += 1

if minus % 2 == 0:
    print(sum(B))
else:
    print(sum(B) - (low*2))

Measured memory_bytes: 14660
from collections import defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 9)
def solve(num):
    #base case:
    if(dic[num]==0):
        return 0

    mx = 0
    for el in dic[num]:
        if(dp[el]==-1):
            temp1 = solve(el)
            mx = max(mx, 1 + temp1)
            dp[el] = temp1
        else:
            mx = max(mx, 1 + dp[el])

    return mx

n, m = map(int, input().split())
dic = defaultdict(int)

for _ in range(m):
    xtemp, ytemp = map(int, input().split())
    if(xtemp not in dic):
        dic[xtemp] = []
        dic[xtemp].append(ytemp)
    else:
        dic[xtemp].append(ytemp)
#init dp:
dp = [-1]*(n+1)

mxGl = 0
keys = list(dic.keys())
for node in keys:
    if(dp[node]==-1):
        temp = solve(node)
        dp[node] = temp
        mxGl = max(mxGl, temp)
    else:
        mxGl = max(mxGl, dp[node])
print(mxGl)

Measured memory_bytes: 68656
#include <bits/stdc++.h>
using namespace std; 
int main(){
	int N; cin >> N; 
	int A[114514] = {}; 
	for(int i = 1; i <= N; i++){
		cin >> A[i]; 
	}
	int B[114514] = {}; B[0] = 1; 
	for(int i = 1; i < 100010; i++){
		B[i] = A[B[i-1]]; 
		if(B[i] == 2){
			cout << i << endl; break; 
		}
		if(i == 100005){
			cout << -1 << endl; 
		}
	}
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}


int main(){
    int K, A, B;
    cin >> K >> A >> B;
    int ans = 0;
    while(1){
        ans += K;
        // cout << ans << endl;
        if(B < ans){
            cout << "NG" << endl;
            return 0;
        }
        if(A <= ans){
            cout << "OK" << endl;
            return 0;
        } 
        
    }
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
} 
int main(){
    ll a,b,c;cin >> a >> b >> c;
    ll k;cin >> k;
    ll cnt=0;
    while(a>=b){
        b*=2;
        cnt++;
    }
    while(b>=c){
        c*=2;
        cnt++;
    }
    if(cnt<=k)cout << "Yes" <<endl;
    else cout << "No" <<endl;
} 

Measured memory_bytes: 3628
from itertools import groupby

n = input()
li = list(map(int, input().split()))
lii = [val == (itr + 1) for itr, val in enumerate(li)]
gbli = [[key, len(list(group))] for key, group in groupby(lii)]
 
ans = 0
for key, val in gbli:
  if key:
    ans += (val - 1) // 2 + 1
    
print(ans)


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

int main(){
  int a,b,c;
  c = 0;
  vector<int> v;
  for(int i = 0;i < 4;i++){
    cin >> a;
    v.push_back(a);
  }
  cin >> a >> b;
  sort(v.begin(),v.end());
  for(int i = 1;i < v.size();i++){
    c += v[i];
  }
  c += max(a,b);
  cout << c << endl;
  return 0;
}

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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    int n;
    cin >> n;

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

    int pos = 1;
    for (int i = 0; i < 1000000; i++) {
        if (pos == 2) { // 最初に判定
            cout << i << endl;
            return 0;
        }
        
        pos = a[ pos ];
    }

    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

import javax.swing.*;

import static java.util.Arrays.binarySearch;
import static java.util.Arrays.copyOfRange;
import static java.util.Arrays.sort;

public class Main {

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;

        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }
}

class Task {

    private static int mod = 998244353;


    public void solve(int testNumber, InputReader in, PrintWriter out) {
        long x = in.nextLong();
        for (long a = -2000; a <= 2000; a++) {
            for(long b = -2000; b <= 2000; b++) {
                if (a * a * a * a * a - b * b * b * b * b == x) {
                    out.println(a + " " + b);
                    return;
                }
            }
        }
    }



}

class InputReader {

    private final BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(nextLine());
        }
        return tokenizer.nextToken();
    }

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

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

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

}


Measured memory_bytes: 25792
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  vector<ll> ls(n);
  for (auto& l : ls) {
    cin >> l;
  }

  ll ans = 0;
  
  bool flag = true;
  while (flag) {
    flag = false;
    for (auto& l : ls) {
      if (l > n - 1) {
        flag = true;
        ll m = l / n;
        l = l % n;
        for (auto& l2 : ls) {
          l2 += m;
        }
        l -= m;
        ans += m;
      }
    }
  }
  cout << ans << endl;
  return 0;
}



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

using namespace std;

#define forn(i, x, n) for (int i = int(x); i <= int(n); ++i)
#define for1(i, n, x) for (int i = int(n); i >= int(x); --i)
#define F first
#define S second
#define pb push_back

typedef long long ll;
typedef pair <int, int> pii;
typedef long double ld;
typedef vector <ll> vi;

const int N = 2e6 + 1;
const ll INF = 1e18 + 9;
const int B = 1e9 + 7;

int main() {
    #ifdef black
    freopen("in", "r", stdin);
    #endif // black
    ios_base :: sync_with_stdio(0);
    cin.tie(0);

    int x, y;   
    cin >> x >> y;
    int ans = 2e9 + 30;
    if (x <= y)
        ans = min(ans, y - x);
    if (-x <= y)
        ans = min(ans, y + x + 1);
    if (x <= -y)
        ans = min(ans, -y - x + 1);
    if (-x <= -y)
        ans = min(ans, -y + x + 2);
    cout << ans << "\n";

    return 0;
}


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

bool BinarySearch(int n, int *S, int value){
	int left = 0;
	int right = n;
	while(left < right){
		int mid = (left + right)/2;
		if(S[mid] == value)
			return 1;
		else if(value < S[mid])
			right = mid;
		else
			left = mid + 1;
	}
	return 0;
}

int main(){
	int n; cin >> n;
	int S[n];
	for(int i=0; i<n; i++)
		cin >> S[i];
	int q; cin >> q;
	int count = 0;
	for(int i=0; i<q; i++){
		int value; cin >> value;
		count += BinarySearch(n,S,value);
	}
	cout << count << endl;
	return 0;
}

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


int main() {

    int n, m, X, Y;
    cin >> n >> m >> X >> Y;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    vector<int> y(m);
    rep(i,m) cin >> y[i];
    for (int z = X+1; z <= Y; ++z) {
        int cnt = 0;
        rep(j,n) {
            if (x[j] < z) ++cnt;
        }
        rep(k,m) {
            if (y[k] >= z) ++cnt;
        }
        if (cnt == n+m) {
            cout << "No War" << endl;
            return 0;
        }
    }
    cout << "War" << endl;
    return 0;
}

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

int main(){
    string str;
    int q;
    string inst;
    int op1,op2;
    string op3;
    cin>>str;
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>inst;
        if(inst=="replace"){
            cin>>op1>>op2>>op3;
            str=str.substr(0,op1)+op3+str.substr(op2+1);
        }else if(inst=="reverse"){
            cin>>op1>>op2;
            string temp="";
            for(int j=op2;j>=op1;j--){
                temp+=str[j];
            }
            str=str.substr(0,op1)+temp+str.substr(op2+1);
        }else if(inst=="print"){
            cin>>op1>>op2;
            for(int j=op1;j<=op2;j++){
                cout<<str[j];
            }
            cout<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3200
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mk make_pair
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define sf(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pf(a) printf("%d\n",a);
#define pfl(a) printf("%lld\n",a);
#define TEST int test; cin >> test;while(test--)
#define ii pair<int,int>
#define iil pair<ll,ll>
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define INF 2147483647


int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const double pi = acos(-1.0);


void solve()
{
   string s;
   cin >> s;
   if(s =="ABC") cout << "ARC" <<endl;
   else cout <<"ABC" <<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //TEST
    solve();
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
    int n;
    int s[13]={0}, h[13]={0}, cr[13]={0}, d[13]={0};
    cin>>n;
    for(int i=0; i<n; i++){
        char c;
        int k;
        cin>>c>>k;
        if(c=='S'){
            s[k-1]=k;
        }
        else if(c=='H'){
            h[k-1]=k;
        }
        else if(c=='C'){
            cr[k-1]=k;
        }
        else{
            d[k-1]=k;
        }
    }
    for(int i=0; i<13; i++){
        if(s[i]==0){
            cout<<"S "<<i+1<<endl;
        }
    }
    for(int i=0; i<13; i++){
        if(h[i]==0){
            cout<<"H "<<i+1<<endl;
        }
    }
    for(int i=0; i<13; i++){
        if(cr[i]==0){
            cout<<"C "<<i+1<<endl;
        }
    }
    for(int i=0; i<13; i++){
        if(d[i]==0){
            cout<<"D "<<i+1<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3096
def main():
    n, m = map(int, input().split())
    p = 2**n
    inf = 10**7
    dp = [inf]*p
    dp[0] = 0
    for _ in range(m):
        a, _ = map(int, input().split())
        c = sum([1<<(int(i)-1) for i in input().split()])
        for s in range(p):
                if dp[s|c] > dp[s] + a:
                    dp[s|c] = dp[s] + a
    ans = dp[-1]
    if ans == inf:
        ans = -1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 46168
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

template <class T> struct Dinic{
    const T inf;
    struct edge{
        int cd;
        T c;
        size_t rv;
        bool f;
    };
    vector<vector<edge>> v;
    vector<int> m,it;
    Dinic(int n):inf(numeric_limits<T>::max()),v(n){}
    void ad(int dm,int cd,T c){
        v[dm].emplace_back((edge){cd,c,v[cd].size(),0});
        v[cd].emplace_back((edge){dm,c,v[dm].size()-1,1});
    }
    bool bfs(int s,int t){
        m.assign(v.size(),-1);
        queue<int> q;
        m[s]=0;
        q.push(s);
        while(!q.empty()&&m[t]==-1){
            int p=q.front();q.pop();
            for(auto &e:v[p]){
                if(e.c>0&&m[e.cd]==-1){
                    m[e.cd]=m[p]+1;
                    q.push(e.cd);
                }
            }
        }
        return m[t]!=-1;
    }
    T dfs(int i,int t,T f){
        if(i==t) return f;
        for(int j=it[i];j<v[i].size();++j){
            edge &e=v[i][j];
            if(e.c>0&&m[i]<m[e.cd]){
                T d=dfs(e.cd,t,min(f,e.c));
                if(d){
                    e.c-=d;
                    v[e.cd][e.rv].c+=d;
                    return d;
                }
            }
        }
        return 0;
    }
    T mf(int s,int t){
        T fl=0;
        while(bfs(s,t)){
            it.assign(v.size(),0);
            T f=0;
            while((f=dfs(s,t,inf))>0) fl+=f;
        }
        return fl;
    }
};

class FLotusLeaves {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int h,w,s=0,t=0;
        in>>h>>w;
        Dinic<int> din(h+w);
        char c;
        fr(i,h) fr(j,w){
            in>>c;
            if(c=='o') din.ad(i,j+h,1);
            if(c=='S') s=i,din.ad(i,j+h,1<<30);
            if(c=='T') t=i,din.ad(i,j+h,1<<30);
        }
        if(s==t){
            out<<-1<<endl;
            return;
        }
        int a=din.mf(s,t);
        if(a>=1<<30) out<<-1<<endl;
        else out<<a<<endl;
    }
};

int main() {
    FLotusLeaves solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 896
#include <iostream>

using namespace std;

char a[50][50], b[50][50];

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

	int flag = 0;
	for (int i = 0; i <= n - m; i++) {
		for (int j = 0; j <= n - m; j++) {
			for (int i2 = 0; i2 < m; i2++) {
				for (int j2 = 0; j2 < m; j2++) {
					//cout << "i+i2:" << i + i2 << "\tj+j2:" << j + j2 << endl;
					if (a[i + i2][j + j2] != b[i2][j2]) {
						flag = 1;
						break;
					}
				}
				if (flag) break;
			}
			if (!flag) {
				cout << "Yes" << endl;
				return 0;
			}
			flag = 0;
		}
	}

	cout << "No" << endl;
}

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

using namespace std;

const int N = 510;
int p[10010];
vector<int> primes;
int a[N * 2], b[N * 2];

void init() {
    for (int i = 2; i < 10000; i++) {
        if (!p[i]) {
            for (int j = i + i; j < 10000; j += i) {
                p[j] = 1;    
            }
            primes.push_back(i);
        }
    }
}

long long res[N][N];
set<long long> has;

long long lcm(long long a, long long b) {
    long long c = __gcd(a, b);
    return (a / c) * b;
}

int main() {
    init();    
    int n;
    scanf("%d", &n);
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        a[i] = primes[cnt++];
    }   
    for (int i = 0; i < n; i++) {
        b[i] = primes[cnt++];
    }
    memset(res, -1, sizeof res);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if ((i + j) % 2 == 0) {
                int aa = i + j >> 1;
                int bb = (i - j + n) >> 1;
                res[i][j] = 1ll * a[aa] * b[bb];
            }
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if ((i + j) % 2 == 0) {
                continue;
            }
            long long foo = 1ll;
            if (i > 0) {
                foo = lcm(foo, res[i - 1][j]);
            }
            if (i + 1 < n) {
                foo = lcm(foo, res[i + 1][j]);
            }
            if (j > 0) {
                foo = lcm(foo, res[i][j - 1]);
            }
            if (j + 1 < n) {
                foo = lcm(foo, res[i][j + 1]);
            }
            int it = 1;
            while (has.count(foo * it)) {
                it++;
            }
            has.insert(foo * it);
            res[i][j] = foo * it + 1;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            printf("%lld ", res[i][j]);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

int main(){

  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((a + b) == (c + d)){
    cout << "Balanced" << endl;
  }
  else if ((a + b) > (c + d)){
    cout << "Left" << endl;
  }
  else {
    cout << "Right" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////

#define N 100005
ll n,m,v,p;
ll a[N];
bool calc(ll mid){
    ll tar=n-p;
    if(mid>=tar)return true;
    /*
    if(mid+1+p<=v){
        if(a[mid]+m>=a[tar])return true;
        else return false;
    }*/
    if(a[mid]+m<a[tar])return false;
    ll cnt=0;
    rep(i,0,n-1){
        if(i<=mid||i>tar){
            cnt+=m;
        }else{
            cnt+=min(m,a[mid]+m-a[i]);
        }
    }
    if(cnt>=m*v)return true;
    else return false;
    
}

int main(){fastio
    cin>>n>>m>>v>>p;
    rep(i,0,n-1)cin>>a[i];
    sort(a,a+n);
    ll ok=n-1,ng=-1;
    while(abs(ok-ng)>1){
        ll mid=(ok+ng)/2;
        if(calc(mid))ok=mid;
        else ng=mid;
    }
    cout<<n-ok<<endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

// https://atcoder.jp/contests/abc082/tasks/abc082_b

int main() {
    string s, t; cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    cout << (s<t?"Yes":"No") << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
const ll mod = 1e9+7;
#define rep(i,a,b) for(ll i=a;i<b;i++)

void swap(ll &a , ll &b){
    ll t = a;
    a = b;
    b = t;
}

ll min(ll a, ll b){
    if(a<b)return a;
    return b;
}

ll max(ll a, ll b){
    if(a>b)return a;
    return b;
}

 ll pow(ll a, ll b) {
    a %= mod;
    ll ans = 1;
    while (b > 0) {
        if (b & 1)
            ans = ans * a % mod;
        a = a * a % mod;
        b /= 2;
    }
    return ans;
}


int main(){


   ios_base :: sync_with_stdio(0);
   cin.tie(0);
   /// 1 2 3 4  ....
   ll n;
   cin>>n;
   ll K;cin>>K;
   ll a[n];
   rep(i ,0 , n){
    cin>>a[i];
   }
    vector<ll> dp( n , INT_MAX);
   dp[0] = 0;
    for(int i = 0 ; i <n;i++){
        for(int k = 1;k<=K;k++){
            if(i+k < n)
                dp[i+k] = min( dp[i+k] , abs(a[i+k]-a[i])+dp[i]  );
        }
    }
    cout<<dp[n-1];





}


Measured memory_bytes: 1792
n = gets.chomp.to_i

l = [1]

tmp = 6
while tmp < 10**5
  l.push(tmp)
  tmp *= 6
end

tmp = 9
while tmp < 10**5
  l.push(tmp)
  tmp *= 9
end

l.sort!


dp = Array.new(n+1, 10**10)

dp[0] = 0

def min(a,b)
  a < b ? a : b
end


1.upto(n) do |i|
  l.each do |num|
    next if i - num < 0
    dp[i] = min(dp[i], dp[i-num] + 1)
  end
end

p dp[n]


Measured memory_bytes: 2556
#include <stdio.h>
int main(){
int x, a, b;
	scanf("%d%d%d", &x, &a, &b);
 
	int da = abs(x - a), db = abs(x - b);
	if (da < db) {
		printf("A");
	} else {
		printf("B");
	}return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

//????????????

int dx[] = { 0, 1, 0, -1 };
int dy[] = { -1, 0, 1, 0 };
int m, n, f[90][90], ans;
bool used[90][90];

void dfs(int y, int x, int d) {
	used[y][x] = true;
	ans = max(ans, d);
	for (int i = 0; i < 4; ++i) {
		int ny = y + dy[i];
		int nx = x + dx[i];
		if (ny < 0 || ny >= n || nx < 0 || nx >= m || f[ny][nx] == 0 || used[ny][nx] == true)
			continue;
		dfs(ny, nx, d + 1);
	}
	used[y][x] = false;
}

int main() {
	while (cin >> m >> n && m != 0) {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				cin >> f[i][j];
			}
		}

		ans = 0;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				if (f[i][j]) {
					fill(used[0], used[n], false);
					dfs(i, j, 1);
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3116
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;
long long calc_an(int n)  //レベルnの層の総数
{
    if (n > 0){
        return 2 * calc_an(n - 1) + 3;
    }else{
        return 1;
    }
}

long long calc_bn(int n)  //レベルnのパティの総数
{
    if (n > 0){
        return 2 * calc_bn(n - 1) + 1;
    }else{
        return 1;
    }
}

long long f(int n, long long x)
{
    if (n == 0){
        return 1;
    }
    else if (x <= n){
        return 0;
    }
    else if (x == calc_an(n - 1) + 2){
        return calc_bn(n - 1) + 1;
    }
    else if (x > 2 * calc_an(n - 1) + 2){
        return calc_bn(n);
    }

    //下のn-1バーガー
    else if (x <= calc_an(n - 1) + 1){
        return f(n - 1, x - 1);
    } 
    //上のn-1バーガー
    else{
        return f(n - 1, x - calc_an(n - 1) - 2) + calc_bn(n - 1) + 1;
    }
}

int main()
{
    int n;
    long long x;
    cin >> n >> x;

    cout << f(n, x) << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  char c[3];
  cin>>c[0]>>c[1]>>c[2];
  int ans=700;
  if(c[0]=='o')ans+=100;
  if(c[1]=='o')ans+=100;
  if(c[2]=='o')ans+=100;
  cout<<ans<<endl;
}

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

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

  int cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '+')
      cnt++;
    else if (s[i] == '-')
      cnt--;
  }
  cout << cnt << endl;
}

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

using namespace std;

int main()
{
    vector<int>v;
    //vector<int>r;
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        v.push_back(i+1);
        cin>>a[i];
    }
    int k=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]-v[i]!=0)
        {
            k++;
        }
    }
    if(k>2)
    {
        cout<<"NO"<<endl;
    }else
    {
        cout<<"YES"<<endl;
    }
}


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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

vector <ll> factors;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll N;
    cin >> N;

    ll ans = 1e15;

    for(ll i=1; i*i<=N; i++)
    {
        if(N%i==0)
        {
            ll a = i;
            ll b = N/i;

            ll cnt1 = 0;
            ll cnt2 = 0;
            while(a)
            {
                cnt1++;
                a/=10;
            }

            while(b)
            {
                cnt2++;
                b/=10;
            }

            ll c = max(cnt1, cnt2);

            ans = min(ans, c);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,tmp;
double nn,ans;




int main(){
  cin>>n;

  if((n%2)==0){
    ans=1.0/2.0;
    printf("%f\n",ans);
  }else{
    nn=n;
    tmp=(nn/2)+1;

    ans=tmp/nn;
    printf("%f\n",ans);
  }


  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define test(t) int t;cin>>t;while(t--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
const int MOD = 1e9+7,MAX = 1e5+5;
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
vector<bool> is_prime(MAX+1, true);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
        	for (j = i * i; j <= MAX; j += i)
            	is_prime[j] = false;
    	}
	}
}
ll modInv(ll a)
{
	return powN(a,MOD-2);
}


int main()
{
	int h,w,k;
	cin>>h>>w>>k;
	vector<string> V(h);
	vector<int> N(h);
	for(int i=0;i<h;i++)
	{
		cin>>V[i];
		for(int j=0;j<w;j++) if(V[i][j]=='#') N[i]++;
	}
	int p=1,f=-1;
	vector<vector<int>> A(h,vector<int>(w));
	if(N[0]==0) f=0;
	for(int i=0;i<h;i++)
	{
		if(N[i]==0)
		{
			if(f==-1)
			{
				for(int j=0;j<w;j++) A[i][j]=A[i-1][j];
				N[i]--;
			}
			else f=i;
			
		}
		else
		{
			f=-1;
			int j=0;
			while(1)
			{
				A[i][j]=p;
				if(V[i][j]=='#'&&N[i]>1) {p++;N[i]--;}
				else if(V[i][j]=='#') N[i]--;
				j++;
				if(j==w) break;
			}
			N[i]--;
			p++;

		}
	}
	// for(int i=0;i<h;i++) cout<<N[i]<<endl;
	for(int i=h-1;i>=0;i--)
	{
		
		for(int j=0;j<w;j++)
		{
			if(A[i][j]==0) A[i][j]=A[i+1][j];
		}
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cout<<A[i][j]<<" ";
		}
		cout<<endl;
	}

}

Measured memory_bytes: 1280
#include <stdio.h>
#define MAX 100

int count = 0;

void print_array(int *A, int N) {
  int i;
  for(i = 0; i < N - 1; i++) {
    printf("%d ", A[i]);
  }
  printf("%d\n", A[i]);
}

void bubbleSort(int *A, int N) {
  int j, v, frag = 1;
  while(frag) {
    frag = 0;
    for(j = N - 1; j >= 1; j--) {
      if(A[j] < A[j-1]) {
	v = A[j];
	A[j] = A[j-1];
	A[j-1] = v;
	frag = 1;
	count++;
      }
    }
  }
}

int main() {
  int n, i, a[MAX];
  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  bubbleSort(a, n);
  print_array(a, n);
  printf("%d\n", count);
  return 0;
}



Measured memory_bytes: 1976