akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  int m;
  cin >> n >> m;
  vector<int> vec(n);
  
  for (int i = 0; i < m; i++) {
    int a;
    int b;
    cin >> a >> b;
    vec[a-1]++;
    vec[b-1]++;
  }
 
  for(int i = 0; i < n; i++){
  	cout << vec[i] << endl;
  }
}


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



int main(){

  int n, m, a;

  while(cin >> n >> m >> a && (n || m || a)){

    vector<pair<int,pair<int,int> > > v;
    int h, p, q;

    for(int i = 0; i < m; i++){
      cin >> h >> p >> q;
      v.push_back(make_pair(h,make_pair(p,q)));
	}
    sort(v.rbegin(),v.rend());
    for(int i = 0; i < m; i++){
      if(v[i].second.first == a){
	a = v[i].second.second;
      }else if(v[i].second.second == a){
	a = v[i].second.first;
      }
      //  cout << n << endl;
    }
    cout << a << endl;


    }



  }

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


ull gcd(ull a,ull b){
	if(!b) return a;
	return gcd(b,a%b);
}


int main(){
	int n;
	cin >> n;
	int a[2][n],dp[2][n] = {0};
	
	rep(i,0,2){
		rep(j,0,n){
			cin >> a[i][j];
		}
	}
	
	
	rep(i,0,2){
		rep(j,0,n){
			if(i+j == 0){
				dp[i][j] = a[i][j];
			}
			else if(i == 0 && j > 0){
				dp[i][j] = dp[i][j-1]+a[i][j];
			}
			else if(i == 1 && j == 0){
				dp[i][j] = dp[i-1][j]+a[i][j];
			}
			else{
				dp[i][j] = max(dp[i-1][j],dp[i][j-1])+a[i][j];
			}
		}
	}
	
	cout << dp[1][n-1] << endl;
	return 0;
}

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

using namespace std;

int main(){
    int a,b,tmp;
    scanf("%d %d",&a,&b);
    if (b==b%10) {
        tmp=a*10+b;
    } else if (b==b%100) {
        tmp=a*100+b;
    } else {
        tmp=a*1000+b;
    }
    for (int i=1;i<1000;i++){
        if (i*i==tmp) {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    var ans = 0
    for (n in 0..1000000000) {
        val m = n.to753() ?: continue
        if (m > N) break
        ans++
    }
    println(ans)
}

fun Int.to753(): Long? {
    val q = ArrayList<Long>()
    var n = this
    while (n > 0) {
        if (n % 4 == 0) return null
        q.add((n % 4 - 1) * 2 + 3L)
        n /= 4
    }
    val s = q.reversed()
    if (s.distinct().size != 3) return null
    return s.joinToString("").toLong()
}

Measured memory_bytes: 62616
n = int(input())
aa = list(map(int, input().split()))
from collections import Counter

dic = Counter(sorted(aa))
aa = list(dic.keys())

cnt = 0
for i in range(len(aa)-2):
    for j in range(i+1,len(aa)-1):
        for k in range(j+1,len(aa)):
            if (aa[i]+aa[j] > aa[k]):
                cnt += dic[aa[i]] * dic[aa[j]] * dic[aa[k]]
print(cnt)

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		String[] S = s.split("");
		int[] alphabetnum = new int[26];
		long answer = 1;
		for(int i = 0; i < n; i++) {
			if(S[i].equals("a")) alphabetnum[0] += 1;
			if(S[i].equals("b")) alphabetnum[1] += 1;
			if(S[i].equals("c")) alphabetnum[2] += 1;
			if(S[i].equals("d")) alphabetnum[3] += 1;
			if(S[i].equals("e")) alphabetnum[4] += 1;
			if(S[i].equals("f")) alphabetnum[5] += 1;
			if(S[i].equals("g")) alphabetnum[6] += 1;
			if(S[i].equals("h")) alphabetnum[7] += 1;
			if(S[i].equals("i")) alphabetnum[8] += 1;
			if(S[i].equals("j")) alphabetnum[9] += 1;
			if(S[i].equals("k")) alphabetnum[10] += 1;
			if(S[i].equals("l")) alphabetnum[11] += 1;
			if(S[i].equals("m")) alphabetnum[12] += 1;
			if(S[i].equals("n")) alphabetnum[13] += 1;
			if(S[i].equals("o")) alphabetnum[14] += 1;
			if(S[i].equals("p")) alphabetnum[15] += 1;
			if(S[i].equals("q")) alphabetnum[16] += 1;
			if(S[i].equals("r")) alphabetnum[17] += 1;
			if(S[i].equals("s")) alphabetnum[18] += 1;
			if(S[i].equals("t")) alphabetnum[19] += 1;
			if(S[i].equals("u")) alphabetnum[20] += 1;
			if(S[i].equals("v")) alphabetnum[21] += 1;
			if(S[i].equals("w")) alphabetnum[22] += 1;
			if(S[i].equals("x")) alphabetnum[23] += 1;
			if(S[i].equals("y")) alphabetnum[24] += 1;
			if(S[i].equals("z")) alphabetnum[25] += 1;
		}
		for(int i = 0; i < 26; i++) {
			answer *= (alphabetnum[i]+1);
			answer %= 1000000007;
		}
		answer -= 1;
		System.out.println(answer);
	}

}

Measured memory_bytes: 35092
from math import sin, cos, radians
a, b, ang = map(int, input().split())
ang = radians(ang)
area = a * b * sin(ang) / 2
c = (a ** 2 + b ** 2 - 2 * a * b * cos(ang)) ** 0.5
circ = a + b + c
height = area * 2 / a
print("%lf\n%lf\n%lf" % (area, circ, height))


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }



int main() {
    ll h,n; cin >> h >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    rep(i, n) cin >> a[i] >> b[i];

    vector<ll> dp(1e4+5,0);
    rep(i, dp.size()) {
        ll tmp = LONG_MAX;
        if(i ==0) continue;
        rep(j, n) {
            if(i-a[j] < 0) {
                tmp = min(tmp, b[j]);
            } else {
                tmp = min(tmp, dp[i-a[j]] + b[j]);
            }
        }
        dp[i] = tmp;
    }

    cout << dp[h] << endl;

}


Measured memory_bytes: 384
a, b, c, x = [int(input()) for i in range(4)]
count = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if x == (i * 500 + j * 100 + k * 50):
        count += 1
print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <limits>
#include <set>
#include <stack>
#include <queue>
#include <list>
#include <cmath>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

int main() {
    int a;
    string s;
    cin >> a;
    cin >> s;
    if(a < 3200) cout << "red" << endl;
    else cout << s << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;

int main()
{
	int sum = 0;
	int peo, day, s, a, b, c;
	scanf("%d", &peo);
	scanf("%d %d", &day, &s);
	for(int i = 0; i < peo; i++) {
		scanf("%d", &a);
		if(day % a == 0) sum = sum + day /a;
		else sum = sum + day / a + 1;
	}
	printf("%d\n", sum + s);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 100000007;
using Graph = vector<vector<int>>;

int main(){
    ll N;
    ll A,B;
    cin >> N >> A >> B;
    ll once = A+B;
    ll ans = 0;
    if(N%once==0){
        ll t = N/once;
        ans += A*t;
    }
    else{
        ll t = N/once;
        ans += A*t;
        ll re = N - t*once;
        if(A>re) ans += re;
        else ans += A;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
n, k = map(int, input().split())
comb = [[1 if (i >= j) else 0 for j in range(n+1)] for i in range(n+1)]

MOD = 10 ** 9 + 7

for i in range(1, n+1):
    for j in range(1, i):
        comb[i][j] = (comb[i-1][j] + comb[i-1][j-1]) % MOD


for i in range(1,k+1):
    print(comb[n-k+1][i] * comb[k-1][i-1] % MOD)



Measured memory_bytes: 76636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    deque<ll> d;
    rep(i, n) {
        auto itr = lower_bound(all(d), a[i]);
        if (itr == d.begin()) {
            d.push_front(a[i]);
        } else {
            itr--;
            d[itr - d.begin()] = a[i];
        }
    }
    cout << sz(d) << endl;
}

Measured memory_bytes: 1792
S = input()
A = S[:2]
A = int(A)
B = S[2:]
B = int(B)
if 0<A<13 and 0<B<13:
  print("AMBIGUOUS")
elif 0<A<13:
  print("MMYY")
elif 0<B<13:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 3060
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

def soinsubunkai_e(n,m): #高速素因数分解 m[n]=nを割ることの出来る最小の素数
    a = set()
    i = 1
    while n>1:
        a.add(m[n])
        n=n//m[n]
    nokori=n
    a.add(nokori)
    return a

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


def era(n): #b[n]=nを割ることの出来る最小の素数　の配列を生成　エラトステネスの篩
    b=[i for i in range(n+1)]
    for i in range(2,int(math.sqrt(n)+10)):
        j=1
        temp=i*j
        while temp<=n:
            b[temp]=min(i,b[temp])
            temp+=i
    return b


def main():
    #l,r,d=map(int,input().split())
    s=input()
    a=s[-1]
    if a=="s":
        s=s+"es"
    else:
        s=s+"s"
    print(s)





if __name__ == "__main__":

    main()


Measured memory_bytes: 72836
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		int count = 0;
		for (char c : n.toCharArray()) {
			if (c == '2') {
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n, k, m;
  while(cin >> n >> k >> m, n){
    vector<int> V;
    for(int i = 0; i < n; ++i)
      V.push_back(i+1);
    --m;
    while(V.size() > 1){
      V.erase(V.begin()+m);
      m = (m+k-1)%(int)V.size();
    }
    cout << V[0] << endl;
  }
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  ll a[n];
  for ( int i = 0; i < n; i++)cin >> a[i];
  sort(a, a+n);
  int idx, minV = MAX;
  for ( int i = 0; i < n; i++ ){
    if ( abs(a[n-1]/2.0 - a[i]) < minV){
      idx = i;
      minV = abs(a[n-1]/2.0 - a[i]);
    }
  }
  cout << a[n-1] << " " << a[idx];

  return 0;
}

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

int main()
{
    int n, x, ans, i, j;

    while (1)
    {

        scanf("%d %d", &n, &x);
        if (n == 0 && x == 0)
            break;
        int ans = 0;
        for (i = x / 3 + 1; i <= n; i++)
        {
            for (j = 2; j < i; j++)
            {
                if (x - i - j < j && x - i - j > 0)
                    ans++;
            }
        }

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


Measured memory_bytes: 3212
#include<iostream>
#include <vector>
#include <string>
#include <tuple>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <climits>
#include <map>
using namespace std;

#define ll int64_t
const long MOD = 1e9 + 7;


//しゃくとり法(条件を満たす区間をすべて求める方法)
//しゃくとり法では半区間[0,i)　で考えることが多い(ex:[0,2) なら0,1のみ )
int main()
{
  long n;
  cin >> n;
  vector<long> a(n);
  vector<long> b(n);
  vector<long> c(n);

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

  sort(a.begin(), a.end());//bsより小さい
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());//bsより大きい

    for (int i = 0; i < n; ++i) {
    cerr <<  a[i] << " ";
  } cerr << endl;
  for (int i = 0; i < n; ++i) {
    cerr <<  b[i] << " ";
  } cerr << endl;
  for (int i = 0; i < n; ++i) {
    cerr <<  c[i] << " ";
  } cerr << endl;

  long ans = 0;

  for (int i = 0; i < n; ++i) {
    long bs = b[i];
    auto it = lower_bound(a.begin(), a.end(), bs);// 指定要素以上の値が現れる最初のイテレータを返す
    auto it2 = upper_bound(c.begin(), c.end(), bs);// 指定要素より大きい値が現れる最初のイテレータを返す
    
    cerr << "a:"<<(it - a.begin()) << "c:"<<n - (long)(it2 - c.begin()) <<endl;
    ans +=  (it - a.begin() )*(n - (long)( it2 - c.begin()));
  }


  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n;
  long long x;
  cin>>n>>x;
  long long a[n];
  REP(i,n){
    cin>>a[i];
  }
  long long ans=0;
  REP(i,n){
    if(i==0){
      ans += max(a[i]-x,0LL);
      a[i] -= max(a[i]-x,0LL);
    }else{
      ans += max(a[i-1]+a[i]-x,0LL);
      a[i] -= max(a[i-1]+a[i]-x,0LL);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    map<string, int> dic;

    int n; cin >> n;
    rep(i, n){
        string in; cin >> in;
        dic[in]++;
    }
    int m; cin >> m;
    rep(i, m){
        string in; cin >> in;
        dic[in]--;
    }

    int res = 0;
    for(auto& e : dic){
        chmax(res, e.second);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

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

// value
ll dp[100010];
ll h[100010];
void solve() {

	int N, K;
	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		cin >> h[i];
	}

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

	}

	cout << dp[N] << endl;

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

A, B, T = mi()

print(B * (T//A))

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

using namespace std;

int main() {
	long long N, A, B;
	cin >> N >> A >> B;

	long long num = A + B;
	long long sho = N / num;
	long long mod = N % num;

	if (mod > A)cout << sho * A + A;
	else cout << sho * A + mod;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,k,i;
  scanf("%d%d%d",&a,&b,&k);
  if(b-a>=2*k){
    for(i=a;i<a+k;i++)
      printf("%d\n",i);
    for(i=b-k+1;i<=b;i++)
      printf("%d\n",i);
  }
  else
    for(i=a;i<=b;i++)
      printf("%d\n",i);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <complex>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <iomanip>

using namespace std;


#define INF (1<<29)

// math
#define Sq(x) ((x)*(x))

// container utility
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair
#define PB push_back
#define EACH(it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();it++)

// rep
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;

typedef long long ll;

// useful
#define FST first
#define SND second

#define CK(n,a,b) (a<=n && n<b)

// conversion
template<class T> inline string toStr(T a) { ostringstream oss; oss << a; return oss.str(); }
inline int toInt(string s) { return atoi(s.c_str()); }

// prime
bool isPrime(int a) { for(int i=2; i*i <=a; i++) if(a%i == 0) return false; return true; }

// !!! set SSIEVVE_MAX_L number !!!
#define SSIEVE_MAX_L (1000001)
#define SSIEVE_MAX_SQRT_B ((int)sqrt(INT_MAX)+1)
 
bool is_prime[SSIEVE_MAX_L];
vector<bool> is_prime_small(SSIEVE_MAX_SQRT_B);
 
void segment_sieve(ll a, ll b) {
   
  for(int i=0; (ll)i*i < b; i++) is_prime_small[i] = true;
  for(int i=0; i < b-a; i++) is_prime[i] = true;
   
  if(a == 1) {
    is_prime[0] = false;
  }
   
  for(int i=2; (ll)i*i<b; i++) {
    if(is_prime_small[i]) {
      for(int j=2*i; (ll)j*j<b; j+=i) is_prime_small[j] = false;
      for(ll j = max(2LL, (a+i-1)/i)*i; j<b; j+=i) is_prime[j-a] = false;
    }
  }
}

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

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

int main() {
  
  int N, M;
  int tcase = 1;
  
  while(cin >> N >> M && (N|M)) {
    VI next(22), now(22);
    
    /*
    for(int i=0; i<N/2; i++) {
      next[0] = ++ now[0], next[1] = ++ now[1];
    }
    if(N % 2) next[0] = ++ now[0];
    */
    
    now[0] = N;
    
    int ans = 0;
    while(now[M] == 0) {
      fill(ALL(next), 0);
      for(int i=0; i<22; i++) {
	next[i+1] += now[i] / 2;
	next[0] += now[i] / 2;
	next[i] += now[i] % 2;
      }
      ans ++;
      
      /*
	for(int i=0; i<22; i++) now[i] = next[i];
      */

      now.swap(next);
    }
    
    cout << "Case " << tcase ++ << ": " << ans << endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 1200
package main

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

var sosuu []int
var findsosuu int

func sosuuMake(a int) {

	sosuu = make([]int, 1)
	sosuu[0] = 2
	flg := false
	for i := 3; i < a/2; i++ {
		flg = true
		for j := 0; j < len(sosuu); j++ {
			if i%sosuu[j] == 0 {
				flg = false
				break
			}
		}
		if flg {
			sosuu = append(sosuu, i)
		}

	}
}

func sosuuFind(n int) {

	k := n
	for findsosuu == 1 {
		go sosuuFind2(k)
		time.Sleep(10 * time.Microsecond)
		k++
	}

}

func sosuuFind2(n int) {
	sosuuflg := true
	for i := 0; i < len(sosuu); i++ {
		if n%sosuu[i] == 0 {
			sosuuflg = false
			break
		}
	}
	if sosuuflg {
		findsosuu = n
	}
}

func main() {

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	x, _ := strconv.Atoi(sc.Text())
	findsosuu = 1
	if x > 2 {
		sosuuMake(x)

		sosuuFind(x)
		for findsosuu == 1 {

		}

	} else {
		findsosuu = 2
	}
	fmt.Println(findsosuu)
}


Measured memory_bytes: 896
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int a, b;
	cin >> a >> b;
	if(a == 2 || b == 2) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

int main() {
    ll H,r=0,c=0;
    cin >> H;

    while(H != 0) {
        r += (1ll<<c);
        c++;
        H /= 2;
    }

    cout << r << endl;
}

Measured memory_bytes: 256
n=int(input())
lista = [int(i) for i in input().split()]
listb = [int(i) for i in input().split()]
listc = [int(i) for i in input().split()]

ans1=sum(listb)
ans2=0
for i in range(n-1):
    if lista[i+1]==lista[i]+1:
        ans2=ans2+listc[lista[i]-1]
ans=ans1+ans2
print(ans)

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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int main(int argc, char** argv) {
//    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) {
        freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
        //freopen("d:\\code\\cpp\\contests\\stdout", "w", stdout);
    }

    int n;
    ll k;
    cin >> n >> k;

    vector<int> a(n), f(n);
    FOR(i, n)
        cin >> a[i];
    FOR(i, n)
        cin >> f[i];
    sort(a.begin(), a.end());
    sort(f.begin(), f.end(), greater<int>());
//    vector<ll> af(n);
//    FOR(i, n)
//        af[i] = 1ll * a[i] * f[i];

    ll x = 0, y = 1e18;
    ll sol = 1e18;
    while(x <= y){
        ll t = x + (y-x)/2;
        ll cost = 0;
        FOR(i, n){
            ll need = t / f[i];
            cost += max(0ll, a[i]-need);
        }
        if (cost <= k){
            sol = min(sol, t);
            y = t-1;
        }
        else{
            x = t+1;
        }
    }
    cout << sol << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789)        cerr << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
ac=0
wa=0
tle=0
re=0
for i in range(n):
  x = input()
  if x == 'AC':
    ac+=1
  elif x == 'WA':
    wa += 1
  elif x == 'TLE':
    tle +=1
  else:
    re +=1
print('AC x',ac)
print('WA x',wa)
print('TLE x',tle)
print('RE x',re)

Measured memory_bytes: 9208
#include<iostream>

using namespace std;

int main(){
	
	int d;
	while(cin>>d)
	{
		if(d==0) break;
		int y=0,m=0;
		while(m<600){
		
		y+=m*m*d;
		m+=d;;
		}
		cout<<y<<endl;
	}
}

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

int n,m,slen,plen,comb1,comb2,num;
string str[20];
int s[10], id[30];
bool head[10];
vector<int> can,comb[6];
vector<int> pre[1<<10], suf[1<<10];
bool use[10];

inline void rec_pre(int d, int sum){
  if(d == plen){
    pre[comb1].push_back(sum);
    return;
  }

  for(int i=0;i<plen;i++){
    if(!use[i]){
      if(can[i] == 0 && head[d])continue;
      use[i] = true;
      rec_pre(d+1,sum + s[d] * can[i]);
      use[i] = false;
    } 
  }
}

inline void rec_suf(int d, int sum){
  if(d == slen){
    suf[comb1].push_back(sum);
    return;
  }
  
  for(int i=0;i<slen;i++){
    if(!use[i]){
      if(can[i] == 0 && head[d+plen])continue;
      use[i] = true;
      rec_suf(d+1,sum + s[d+plen] * can[i]);
      use[i] = false;
    } 
  }
}

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

  int lim = 1<<10;
  for(int i=1;i<6;i++){
    int tmp = (1<<i)-1;
    while(tmp < lim){
      comb[i].push_back(tmp);
      int x = tmp & -tmp, y = tmp + x;
      tmp = ( ( (tmp & ~y) /x ) >> 1) | y;
    }
  }

  while(cin >> n,n){
    vector<char> v;
    for(int i=0;i<n;i++){
      cin >> str[i];
      for(int j=0;j<str[i].size();j++){
	v.push_back(str[i][j]);
      }
    }

    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());

    m = v.size();
    for(int i=0;i<m;i++)id[v[i]-'A'] = i;

    for(int i=0;i<m;i++){
      s[i] = 0; head[i] = false;
    }

    for(int i=0;i<n;i++){
      if(str[i].size()>1)head[id[str[i][0]-'A']] = true;

      int tmp = (i==n-1?-1:1);
      for(int j=str[i].size()-1;j>=0;j--){
	s[id[str[i][j]-'A']] += tmp;
	tmp *= 10;
      }
    }

    if(m==1){
      if(s[0] == 0 && !head[0])cout << 1 << endl;
      else cout << 0 << endl;
      continue;
    }

    plen = m/2; slen = m-plen;

    for(int i=0;i<comb[plen].size();i++){
      comb1 = comb[plen][i];
      pre[comb1].clear();

      can.clear();
      for(int j=0;j<10;j++){
	if( (comb1>>j)&1 )can.push_back(j);
	use[j] = false;
      }
      rec_pre(0,0);
      sort(pre[comb1].begin(),pre[comb1].end());
    }
    
    for(int i=0;i<comb[slen].size();i++){
      comb1 = comb[slen][i];
      suf[comb1].clear();

      can.clear();
      for(int j=0;j<10;j++){
	if( (comb1>>j)&1 )can.push_back(j);
	use[j] = false;
      }

      rec_suf(0,0);
      sort(suf[comb1].begin(),suf[comb1].end());
    }

    int ans = 0;
    for(int i=0;i<comb[plen].size();i++){
      for(int j=0;j<comb[slen].size();j++){
	comb1 = comb[plen][i]; comb2 = comb[slen][j];
	if(!(comb1&comb2)){
	  for(int k=0;k<pre[comb1].size();k++){
	    if(!k || (pre[comb1][k] != pre[comb1][k-1])){
	      num = upper_bound(suf[comb2].begin(),suf[comb2].end(),-pre[comb1][k])
		- lower_bound(suf[comb2].begin(),suf[comb2].end(),-pre[comb1][k]);
	    }
	    ans += num;
	  }
	}
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1628
use proconio::input;
use std::cmp::{min, max};

fn main() {
    input! {
        m: usize,
        n: usize,
    }

    let div = 1000000007;
    let mut ans = 0;
    match max(m, n) - min(m, n) {
        0 => {
            // 差がないとき
            ans = (power(m, div) * power(m, div)) % div * 2;
        },
        1 => {
            // 差が1の時
            ans = ((power(m, div) * power(n, div)) % div) % div;
        },
        _ => {},
    }
    println!("{}", ans % div);
}

fn power(x: usize, div: usize) -> usize {
    let mut ans = 1;
    for i in 1..=x {
        ans *= i;
        ans %= div;
    }
    ans
}

Measured memory_bytes: 2116
MOD=10**9+7
N=int(input())
A=list(map(int, input().split()))

huts=[0, 0, 0]
out=1
for i in range(N):
  out*=huts.count(A[i])
  if out==0:
    print(0)
    exit()
  huts[huts.index(A[i])]+=1
print(out%MOD)

Measured memory_bytes: 14056
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
if N%2 == 0:
  dp = [[0]*2 for _ in range(N)] #0index
  dp[0][0] = A[0]
  dp[1][1] = A[1]
  for i in range(2,N):
    dp[i][0] = dp[i-2][0]+A[i]
    if i-3>=0:
      dp[i][1] = max(dp[i-2][1],dp[i-3][0])+A[i]
    else:
      dp[i][1] = max(dp[i-2][1],0)+A[i]
  ans = max(dp[-2][0],dp[-1][1])
  print(ans)
#i個目を使ってj(0-2)回多く飛んでいる。
else: #N%2 == 1:
  dp = [[0]*3 for _ in range(N)] #0index
  dp[0][0] = A[0]
  dp[1][1] = A[1]
  dp[2][2] = A[2]
  dp[2][0] = A[0]+A[2]
  #print(dp)
  for i in range(3,N):
    dp[i][0] = dp[i-2][0]+A[i]
    if i-3 >= 0:
      dp[i][1] = max(dp[i-2][1],dp[i-3][0])+A[i]
    else:
      dp[i][1] = max(dp[i-2][1],0)+A[i]
    if i-4 >= 0:
      dp[i][2] = max(dp[i-2][2],dp[i-3][1],dp[i-4][0])+A[i]
    elif i-3 >= 0:
      dp[i][2] = max(dp[i-2][2],dp[i-3][1],0)+A[i]
  #else:
  #  dp[i][2] = max(dp[i-2][2],0,0)+A[i]
  #print(dp[-1],dp[-2],dp[-3])

  ans = max(dp[-3][0],dp[-2][1],dp[-1][2])
  print(ans)
  exit()

Measured memory_bytes: 113664
n, m, q = gets.to_s.split.map{|t|t.to_i}
abcd = Array.new(q) do
  a, b, c, d = gets.to_s.split.map{|t|t.to_i}
  [a-1, b-1, c, d]
end

ans = 0
(1..m).to_a.repeated_combination(n) do |ary|
  cnt = 0
  abcd.each do |(a,b,c,d)|
    cnt += d if ary[b] - ary[a] == c
  end
  
  ans = [ans, cnt].max
end

puts ans

Measured memory_bytes: 14688
n = int(input())
a_list = [int(input()) for _ in range(n)]
m1 = max(a_list)
k = a_list.index(m1)
m2 = max(a_list[:k]+a_list[k+1:])
for i in range(n):
  if i == k:
    print(m2)
  else:
    print(m1)

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

int N ;
int a[101][101];
int m[101][2];

int main() {
    cin >> N;
    for (int i = 1; i <= N; ++i) {
        cin >> m[i][0] >> m[i][1];
    }

    for (int j = 1; j <= N; ++j) {
        a[j][j] = 0;
    }

    for (int k = 1; k < N; ++k) {
        for (int l = 1; l <= N- k ; ++l) {
            int j = l + k;
            int mn = INT_MAX;
            for (int p = l; p <= j-1 ; ++p) {
                mn = min(mn, a[l][p] + a[p+1][j] + m[l][0] * m[p][1] * m[j][1]);
            }
            a[l][j] = mn;
        }
    }
    cout << a[1][N] << endl;

    return 0;
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    int num = 0,A = N;
    for(;A;A /= 10)num += A%10;
    cout << (N%num?"No":"Yes") << endl;
}

Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

var dp, dpr [5001]int

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	k := getNextInt(scanner)
	aa := make([]int, n)

	dp[0] = 1
	dpr[0] = 1

	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	for i := n - 1; i > 0; i-- {
		for ii := k; ii >= 0; ii-- {
			if ii-aa[i] < 0 {
				continue
			}
			if dpr[ii-aa[i]] > 0 {
				dpr[ii]++
			}
		}
	}

	ans := 0

	for i := 0; i < n; i++ {
		if needed(i, n, k, aa) == false {
			ans++
		}
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

func needed(ai, n, k int, aa []int) bool {
	if ai > 0 {
		for ii := k; ii >= 0; ii-- {
			if ii-aa[ai-1] < 0 {
				continue
			}
			if dp[ii-aa[ai-1]] > 0 {
				dp[ii]++
			}
		}
		for ii := 0; ii <= k; ii++ {
			if ii+aa[ai] > k {
				continue
			}
			if dpr[ii] == 0 {
				continue
			}
			if dpr[ii+aa[ai]] > 0 {
				dpr[ii+aa[ai]]--
			}
		}
	}

	var sr [5001]int
	sr[0] = dpr[0]
	for ii := 1; ii < k; ii++ {
		sr[ii] = sr[ii-1] + dpr[ii]
	}

	for i := 0; i < k; i++ {
		if dp[i] == 0 {
			continue
		}
		if i+aa[ai] >= k {
			return true
		}
		minr := k - aa[ai] - i - 1
		maxr := k - i - 1
		if minr < 0 {
			continue
		}
		if maxr < 0 {
			continue
		}
		if sr[maxr]-sr[minr] > 0 {
			return true
		}
	}
	return false
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
const int N=10;
int a[N],b[N],c[N],d[N];
int main() {
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),c[i]=i;
	for(int i=1;i<=n;i++) scanf("%d",&b[i]),d[i]=i;
	int ta=0,tb=0;
	do {
		ta++;
		bool f=true;
		for(int i=1;i<=n;i++) {
			if(a[i]!=c[i]) f=false;
		}
		if(f) break;
	}while(next_permutation(c+1,c+n+1));
	do {
		tb++;
		bool f=true;
		for(int i=1;i<=n;i++) {
			if(b[i]!=d[i]) f=false;
		}
		if(f) break;
	}while(next_permutation(d+1,d+n+1));
	printf("%d\n",abs(ta-tb));
	return 0;
}

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

//最大公約数
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}

int a[100010];


int main(){
    int n,k,num;cin>>n>>k;
    int a[n];
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]==1)num=i;
    }
    int ans=0;
    if((n-k)%(k-1)==0)ans = 1+(n-k)/(k-1);
    else ans = 2+(n-k)/(k-1);

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(void) {
    int n;
    cin >> n;
    // const auto igcd = gcd<int, int>;
    vector<int> a(n,0);
    rep(i,n){
        cin >> a[i];
    }
    int gcd_prev,gcd_now;
    gcd_now=a[0];
    gcd_prev=a[n-1];
    vector<int> up,down;
    rep(i,n){
       gcd_now=__gcd(gcd_now,a[i]);
       up.push_back(gcd_now);
    }
    rep(i,n){
        gcd_prev=__gcd(gcd_prev,a[n-1-i]);
        down.push_back(gcd_prev);
    }
    sort(down.begin(),down.end());
    DEBUG{
        cout << "up" << endl;
        rep(i,n){
            cout << up[i] << endl;
        }
        cout << "down" << endl;
        rep(i,n){
            cout << down[i] << endl;
        }
    }
    int res=0;
    rep(i,n){
        if(i==0)res=max(res,down[i+1]);
        else if(i==n-1)res=max(res,up[i-1]);
        else res=max(res,__gcd(up[i-1],down[i+1]));
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1784
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
//#include <unordered_map>
#include <stack>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define INF 21474836

int N;
int X[1000];

int main() {

	cin >> N;
	rep(i, N)cin >> X[i];
	
	bool ans = false;
	rep(i, N) {
		if (X[i] % 2 == 0) {
			if (X[i] % 3 != 0 && X[i] % 5 != 0)ans = true;
		}
	}
	
	if(ans)cout << "DENIED" << endl;
	else cout << "APPROVED" << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

char C[] = {'I', 'O', 'T', 'J', 'L', 'S', 'Z'};

LL func1(map<char, LL> mp) {
    LL ans = 0;


    LL buf = mp['I'] / 2;
    ans += (buf) * 2;
    buf = mp['L'] / 2;
    ans += (buf) * 2;
    buf = mp['J'] / 2;
    ans += (buf) * 2;
    mp['I'] %= 2;
    mp['L'] %= 2;
    mp['J'] %= 2;


    return ans;
}
LL func2(map<char, LL> mp) {
    LL ans =0;

    if (mp['I'] > 0 && mp['L'] > 0 && mp['J'] > 0) {
        mp['I'] --;
        mp['J'] --;
        mp['L'] --;
        ans += 3;
    }
    LL buf = mp['I'] / 2;
    ans += (buf) * 2;
    buf = mp['L'] / 2;
    ans += (buf) * 2;
    buf = mp['J'] / 2;
    ans += (buf) * 2;
    mp['I'] %= 2;
    mp['L'] %= 2;
    mp['J'] %= 2;


    return ans;
}

int main(void) {
    map<char, LL> mp;
    REP(i, 7) {
        LL buf;
        scanf("%lld", &buf);
        mp[C[i]] = buf;
    }

    cout << max(func1(mp), func2(mp)) + mp['O'] << endl;
}


Measured memory_bytes: 256
a = int(input())
l = []
for i in range(a):
    ta,tb = map(int,input().split())
    l.append([ta,tb])
l.sort()

ans =0
A = 1
B = 10000000010
for i , j in l:
    ans+= min(i-A,abs(B-j))
    A = i;B=j
    # print(ans)
print(ans+l[-1][1]+1)

Measured memory_bytes: 20056
#include <bits/stdc++.h>
#include "unistd.h"
using namespace std;
#define WA cout<<"char134217728";exit(0)
#define RE throw
#define TLE sleep(1000)
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end());
#define bit(n) (1<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n, a, b, c[17];
bool z[17];
stringstream s;
void rec(int d, bool p){
  if(d==n){
    s << ' ' << (a^b);
    return;
  }
  int i=0;
  while(z[i] || p&&((a&c[i])==0)) i++;
  z[i] = true;
  rec(d+1, false);
  a ^= c[i];
  rec(d+1, p);
  z[i] = false;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> a >> b;
  FOR(i, 0, n) c[i]=bit(i);
  a ^= b;
  if(__builtin_parity(a)){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
    return 0;
  }
  rec(0, true);
  cout << s.str().substr(1) << endl;
}

Measured memory_bytes: 3588
package main

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

func main() {
	sc := NewScanner()
	H, W := sc.NextInt(), sc.NextInt()
	_ = sc.NextInt()
	A := sc.NextIntArray()

	f := make([][]int, H)
	for i := 0; i < H; i++ {
		f[i] = make([]int, W)
	}

	c := 0
	for i := 0; i < H; i++ {
		if i%2 == 0 {
			for j := 0; j < W; j++ {
				f[i][j] = c + 1
				A[c]--
				if A[c] == 0 {
					c++
				}
			}
		} else {
			for j := W - 1; j >= 0; j-- {
				f[i][j] = c + 1
				A[c]--
				if A[c] == 0 {
					c++
				}
			}
		}
	}
	for i := 0; i < H; i++ {
		PrintI(f[i]...)
	}
}
func mapToString(arr []int) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.Itoa(arr[i])
	}
	return ret
}

func PrintI(args ...int) {
	fmt.Println(strings.Join(mapToString(args), " "))
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 1664