akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define VUNIQUE(v) sort(v.begin(), v.end());v.erase(unique(v.begin(), v.end()), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

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

	int n;
	cin >> n;
	vector <PP> info(n);
	REP(i, n) cin >> info[i].second.first >> info[i].second.second >> info[i].first;


	for (PP point : info) {
		if (point.first == 0) continue;
	}

	REP(x,101) {
		REP(y,101) {
			int h;
			for (PP point : info) {
				if (point.first == 0) continue;
				h = point.first + abs(point.second.first-x) + abs(point.second.second-y);
			}
			for (PP point : info) {
				int hi = h - abs(point.second.first-x) - abs(point.second.second-y);
				if (hi < 0) hi = 0;
				if (point.first != hi) goto NEXTPOINT;
			}

			cout << x << " " << y << " " << h;
			return 0;

			NEXTPOINT:
			;
		}
	}

	return 0;
}

Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))
dp = [10e9] * N
dp[0] = 0
dp[1] = abs(h[0] - h[1])


for i in range(2, N):
    if dp[i-1] + abs(h[i] - h[i-1]) < dp[i-2] + abs(h[i] - h[i-2]):
        dp[i] = dp[i-1] + abs(h[i] - h[i-1])
    else:
        dp[i] = dp[i-2] + abs(h[i] - h[i-2])


print(dp[-1])

Measured memory_bytes: 13776
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;


int main(){
    string s;
    cin >> s;
    int ans = 0;
    REP(i,s.length()) if(s[i] == '2') ans ++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using vin=vector<int>;
using vll=vector<long long>;
using vdo=vector<double>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vvdo=vector<vector<double>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using pqin=priority_queue<int>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
int main()
{
    int n;
    string s;
    cin>>n;
    cin>>s;
    int sum=1;
    rep2(i,1,n){
        if(s[i]!=s[i-1])sum++;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void){
  int color[3];
  int count=0;
  int i,j;
  for(i=0;i<3;i++){
    scanf("%d",&color[i]);
    if(i!=0){
      for(j=0;j<i;j++){
        if(color[i]==color[j]){
          count++;
          break;
        }
      }
    }
  }
    int a=3-count;
    printf("%d",a);
    return 0;
}

Measured memory_bytes: 128
M=8**7
m=M*476+1
f=[1]*M
g=[1]*M
h=[1]*M
for i in range(2,M):
	f[i]=f[i-1]*i%m
	h[i]=-h[m%i]*(m//i)%m
	g[i]=g[i-1]*h[i]%m
A,B=map(int,input().split())
if A<B:A,B=B,A
a=0
b=1
for j in range(1,B+1):
	a+=b*f[A+B-j]*g[B-j]
	b=b*2%m
print((a*f[B]*g[A+B]+A)%m)

Measured memory_bytes: 90972
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <list>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;

int main()
{
    int N, M, C;
    cin >> N >> M >> C;
    vector<int> B;
    REP(i, M)
    {
        int b;
        cin >> b;
        B.push_back(b);
    }

    int ret = 0;
    REP(n, N)
    {
        int total = 0;
        REP(i, M)
        {
            int a;
            cin >> a;
            total += a * B[i];
        }
        if (total + C > 0)
            ret++;
    }

    cout << ret << endl;
}

void cheatsheet()
{
    // loop
    // vector<int> vec(10);
    vector<int> vecloop;
    REP(i, 10)
    {
        vecloop.push_back(i);
    }

    // swap
    int a = 1;
    int b = 5;
    swap(a, b); // -> a = 5, b = 1

    // sort
    int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    sort(arr, arr + 9, greater<int>()); // 9 8 7 6 5 4 3 2 1

    // lower
    vector<int> vec(arr, end(arr));
    sort(vec.begin(), vec.end());
    cout << lower_bound(vec.begin(), vec.end(), 2)[0]; // 2

    // map
    map<Pll, ll> m;
    m[Pll(10, 100)] = 100;
}

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

const int MAXN=1000;

int main(void)
{   ios::sync_with_stdio(false);
    int n, k, sum, i;
    int p[MAXN];
    cin>>n>>k;
    for(i=0; i<n; i++)
        cin>>p[i];
    sort(p, p+n);
    for(sum=i=0; i<k; i++)
        sum += p[i];
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3576
N = int(input())
t,x,y = 0,0,0

for i in range(N):
  next_t,next_x,next_y = map(int,input().split())
  interval = next_t - t
  distant_x = int(next_x - x)
  distant_y = int(next_y - y)
  distant = distant_x + distant_y
  
  if(distant > interval):
    print('No')
    break
  elif( (interval - distant) % 2 == 1 ):
    print('No')
    break
  elif(i == N - 1):
    print('Yes')
    
    
  
  t , x , y = next_t , next_x , next_y
 

Measured memory_bytes: 3064
# A
a,b =map(int,input().split())

if 0 < a and 0 < b:
  print("Positive")
elif (a == 0 or b == 0) or (a < 0 and 0 < b):
  print("Zero")
else:
  if (a-b)%2 == 0:
    print("Negative")
  else:
    print("Positive")


Measured memory_bytes: 9152
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

llong gcd(llong a, llong b);

llong lcm(llong a, llong b){
  return a  / gcd(a, b) * b;
}

llong gcd(llong a, llong b){
  if(b > a) swap(a,b);

  llong r = a % b;
  if(r == 0) return b;

  return gcd(b, r);
}

int main(){

  int n;
  while(true){
    scanf("%d", &n);

    if(n == 0) break;

    vector<llong> d(n), v(n);
    REP(i,n){
      scanf("%lld %lld", &d[i], &v[i]);
      llong tmp = gcd(d[i], v[i]);
      d[i] /= tmp; v[i] /= tmp;
    }

    llong D = d[0], V = v[0];
    FOR(i,1,n){
      D = lcm(D, d[i]); V = gcd(V, v[i]);
    }

    REP(i,n){
      printf("%lld\n", D * v[i] / V / d[i]);
    }

  
  }

  return 0;
}




Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] / (fac[k] * fac[n - k]);
}


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

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll dp[10101][110];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll a, b, x;
	cin >> a >> b >> x;
	ll ans = b / x - a / x;
	if (a % x == 0)ans++;
	cout << ans << endl;
	return 0;
}


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

int main(){
	int n,a[110];
  cin >> n;
  for(int i=0; i<n; i++) cin >> a[i];
  int ans=0;
  for(int i=0; i<n; i+=2){
  	if(a[i] % 2 == 1) ans++;
  }
  cout << ans;
}

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

typedef long long ll;

int n;
string s;
ll mod = 1000000007, a[26], ans = 1;

int main()
{
    cin >> n >> s;
    for (int i = 0; i < n; i++)
        a[(int) (s[i] - 'a')]++;
    for (int i = 0; i < 26; i++)
        ans = (ans * (a[i] + 1)) % mod;
    cout << ans - 1 << endl;
    return 0;
}


Measured memory_bytes: 512
import collections

N, K = map(int, input().split())
p = list(map(int, input().split()))

# サイコロ（1...p）の期待値は(1+p)/2
cum_sum = [0]
for i in range(0, N):
    cum_sum.append(cum_sum[i] + (1 + p[i]) / 2)
# print(cum_sum)
# 調べる区間は[1,...,K],...,[N-K+1,...N]
ans = 0
for i in range(1, N - K + 2):
    temp = cum_sum[i + K - 1] - cum_sum[i - 1]
    # print(temp)
    ans = max(ans, temp)
print(ans)


Measured memory_bytes: 32712
from copy import copy

def get_input():
    data_list = input().split()
    for i, v in enumerate(data_list):
        data_list[i] = int(v)
    return data_list


def remove_over_budeget(value_list, budget):
    tmp_list = copy(value_list)
    for i, v in enumerate(tmp_list):
        if v >= budget:
            del value_list[i:]
            return value_list
    return value_list

def get_max_value_list(value_list,budget):
    if value_list == []: # in preperation for all value is over budget
        return "NONE"
    max_value = 0
    for i in range(0, len(value_list)-1):
        for j in range(i+1,len(value_list)):
            # print("j", j) # debug
            # print("i", i) # debug
            combination_plan = value_list[i] + value_list[j]
            if combination_plan <= budget and combination_plan > max_value:
                max_value = combination_plan
    if max_value == 0:
        return "NONE"
    return max_value





if __name__ == "__main__":
    while True:
        item_num, budget = get_input()
        if item_num == 0:
            break
        value_list = get_input()
        value_list.sort()
        value_list = remove_over_budeget(value_list, budget)
        max_value = get_max_value_list(value_list,budget)
        # print("max_value", max_value) # debug
        print(max_value)



Measured memory_bytes: 6344
#ABC138D
#node:節 edge:枝
def main():
    import sys
    sys.setrecursionlimit(200005)
    N, Q = map(int, sys.stdin.readline().split())
    edge = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N-1)]
    #1:ノードのリストを作る
    nodeL = [[] for _ in range(N)]
    for a, b in edge:
        nodeL[a-1].append(b-1)
        nodeL[b-1].append(a-1)
    #print(nodeL)
    px = [tuple(map(int, sys.stdin.readline().split())) for _ in range(Q)]
    #print(px)
    score = [0 for i in range(N)]
    for p, x in px:
        score[p-1] +=x
    #print(score)
    result = score.copy()
    
    def dfs(p, g=-1):
        for c in nodeL[p]:
            if c !=g:
                score[c] +=score[p]
                dfs(c, p)
    
    
    dfs(0)
    print(*score)
    


if __name__=='__main__':
    main()


Measured memory_bytes: 328172
n=int(input())
s=input()
L=len(s)
ans=0

r=s.count('R')
b=s.count('B')
g=s.count('G')

for i in range(L-2):
    for j in range(i+1,L-1):
        if s[j]!=s[i]:
            if j+j-i<=L-1:
                if s[j+j-i]!=s[i] and s[j+j-i]!=s[j]:
                    ans+=1
print(r*b*g-ans)

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

int main() {
  int64_t N, D;
  cin >> N >> D;
  vector<vector<int64_t>> V(N, vector<int64_t>(2));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> V.at(i).at(j);
    }
  }
  int64_t count = 0LL;
  for (int i = 0; i < N; i++) {
    //cout << i << ' ' << V.at(i).at(0) * V.at(i).at(0) + V.at(i).at(1) * V.at(i).at(1) << endl;
    if (V.at(i).at(0) * V.at(i).at(0) + V.at(i).at(1) * V.at(i).at(1) <= D * D) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 14344
n,m=map(int,input().split())
a=[input() for _ in range(n)]
b=[input() for _ in range(m)]
for y in range(n-m+1):
    for x in range(n-m+1):
        f=1
        for i in range(m):
            for j in range(m):
                if a[i+x][j+y]!=b[i][j]:
                    f=0
        if f:
            print("Yes")
            exit()
print("No")


Measured memory_bytes: 40816
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		List<Integer> answer = new ArrayList<Integer>();
		int count = 0 ;
		while (true) {
			String line = br.readLine();
			if ("0 0".equals(line)) {
				break;
			}
			String[] inputData = line.split(" ");
			int n = Integer.parseInt(inputData[0]);
			int x = Integer.parseInt(inputData[1]);

			count = 0;
			for (int i =1; i< n-1 && i < x; i++) {
				for (int j = i + 1; j < n && j < x; j++) {
					for (int k = j + 1; k < n + 1 && k < x; k++) {
						if ((i + j + k) == x) {
							count++;
						}
					}
				}
			}
			answer.add(count);
		}

		for(int output : answer) {
			System.out.println(output);
		}
	}
}

Measured memory_bytes: 25288
package main

import (
	"fmt"
)

func checkHowManyDivideByTwo(val int) int {
	counter := 0
	for val%2 == 0 {
		val /= 2
		counter++
	}
	return counter
}

func main() {
	var (
		N   int
		val int
		sum int
	)
	fmt.Scan(&N)

	for i := 0; i < N; i++ {
		fmt.Scan(&val)
		sum += checkHowManyDivideByTwo(val)
	}

	fmt.Println(sum)
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;

int partition(vector<int>& as, int p, int r) {
    int x = as[r];
    int i = p - 1;
    for (int j = 0; j < r; ++j) {
        if (as[j] <= x) {
            i++;
            swap(as[i], as[j]);
        }
    }
    swap(as[i + 1], as[r]);
    return i + 1;
}

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

    int n;
    cin>>n;
    vector<int> as(n);
    rep(i, n) cin>>as[i];

    int q = partition(as, 0, n - 1);
    rep(i, n - 1) {
        if (i == q) cout<<"["<<as[i]<<"]"<<" ";
        else cout<<as[i]<<" ";
    }
    cout<<as[n - 1]<<endl;
}


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

int main() {
  int N; cin >> N;
  int m = 0, n = 0;
  int long long sum = 0;
  vector<int> a(N);
  for( int i = 0; i < N; i++ )
    cin >> a.at(i);
  for( int i = 0; i < N; i++ ) {
    if( a.at(i) == 0 )
      m++;
    else if( a.at(i) < 0 ) {
      n++;
      a.at(i) *= -1;
    }
  }
  sort(a.begin(),a.end());
  
  if( m == 0 & n % 2 == 1 ) {
    for( int i = 0; i < N; i++ ) {
      if( a.at(i) != 0 ) {
        a.at(i) *= -1;
        break;
      }
    }
  }
  
  for( int i = 0; i < N; i++ )
    sum += a.at(i);
  cout << sum << endl;
}

Measured memory_bytes: 640
N = int(input())
T_list = list(map(int, input().split()))
M = int(input())
X_list = []
for i in range(M):
    X = list(map(int, input().split()))
    X_list.append(X)
time_list = []
for i in range(M):
    time = 0
    for j in range(N):
        if X_list[i][0]-1 == j:
            time += X_list[i][1]
        else:
            time += T_list[j]
    time_list.append(time)
for i in range(M):
    print(time_list[i])

Measured memory_bytes: 3064
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools

def main():
    x = int(input())
    cnt = 0
    a = 100
    while True:
        if a >= x:
            print(cnt)
            exit()
        a = a*101//100
        cnt += 1

if __name__=="__main__":
    main()


Measured memory_bytes: 63736
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  VEC<int> C(N);
  REP(i, 0, N) {
    if (S[i] == '1')
      C[i] = 1;
    else
      C[i] = 0;
  }
  VEC<pair<int, int>> Combo;
  int b = 0;
  DUMP(C);
  REP(i, 0, N) {
    if (i + 1 < N && C[i] == C[i + 1]) {
      continue;
    } else {
      Combo.push_back(make_pair(C[i], i - b + 1));
      b = i + 1;
    }
  }
  if (K >= Combo.size()) {
    cout << N << endl;
    return 0;
  }
  DUMP(Combo);

  int zeros = 0;
  int cnt = 0;
  int right = Combo.size();
  REP(i, 0, Combo.size()) {
    if (Combo[i].first == 0) ++zeros;
    if (zeros > K) {
      right = i;
      break;
    }
    cnt += Combo[i].second;
  }
  int ans = cnt;
  // DUMP(0, right, cnt);
  REP(left, 1, Combo.size()) {
    if (Combo[left].first == 0) {
      if (left - 1 >= 0) cnt -= Combo[left - 1].second;
    } else {
      if (left - 1 >= 0) cnt -= Combo[left - 1].second;
      if (right < Combo.size())
        cnt += Combo[right].second;
      if (right + 1 <= Combo.size() )
        cnt += Combo[right+1].second;
      right += 2;
    }
    // DUMP(left, right, cnt);
    ans = max(ans, cnt);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
int arr[100009];
int dp[100009];
int main(){
    int n,k;
    cin >> n>>k;
    for(int i=0;i<n;i++){
        cin >> arr[i];
        dp[i]=1e9;
    }
    dp[0]=0;
    for(int i=1;i<n;i++){
        for(int j=1;j<=min(i,k);j++){
            dp[i] = min(dp[i-j]+abs(arr[i]-arr[i-j]),dp[i]);
        }
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll, ll, ll> triple;
typedef double D;

struct P {
  double x;
  double y;
};

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

ll n;
vector<P> p;

double dist(P a, P b) {
  double dx = a.x-b.x;
  double dy = a.y-b.y;
  return sqrt(dx*dx + dy*dy);
}

double f(double x, double y) {
  double res = 0;
  rep(i, n) {
    res = max(res, dist((P){x, y}, p[i]));
  }
  return res;
}

double g(double x) {
  double l = 0, r = 1000;
  rep(i, 80) {
    double c1 = (l*2+r)/3;
    double c2 = (l+r*2)/3;
    if (f(x,c1) > f(x,c2)) {
      l = c1;
    } else {
      r = c2;
    }
  }
  return f(x,l);
}

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  cout << setprecision(10) << fixed;

  cin >> n;
  p.resize(n);
  rep(i, n) {
    cin >> p[i].x >> p[i].y;
  }

  double l = 0, r = 1000;
  rep(i, 80) {
    double c1 = (l*2+r)/3;
    double c2 = (l+r*2)/3;
    if (g(c1) > g(c2)) {
      l = c1;
    } else {
      r = c2;
    }
  }

  double ans = g(l);
  cout << ans << endl;
}


Measured memory_bytes: 256
// Template
#include "bits/stdc++.h"
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T>
inline bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T> 
inline bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}
struct IOSET {
    IOSET() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} ioset;

// Main
int main() {
    auto st = chrono::high_resolution_clock::now();
    auto tim = [&]() {
        auto ed = chrono::high_resolution_clock::now();
        return chrono::duration_cast<chrono::milliseconds>(ed - st).count();
    };

    int d;
    cin >> d;
    vector<int> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d) rep(j, 26) cin >> s[i][j];

    vector<int> t(d);
    vector<vector<int>> ds(26);
    int score = 0;
    auto rescore = [&](int x, int y) {
        if (y == t[x]) return;
        int mn = -inf, mx = inf;
        for (int i : ds[t[x]]) {
            if (i < x) chmax(mn, i);
            if (i > x) chmin(mx, i);
        }
        score -= s[x][t[x]];
        score += (x - mn) * (x - mn - 1) / 2 * c[t[x]];
        score += (mx - x) * (mx - x - 1) / 2 * c[t[x]];
        score -= (mx - mn) * (mx - mn - 1) / 2 * c[t[x]];
        mn = -inf, mx = inf;
        for (int i : ds[y]) {
            if (i < x) chmax(mn, i);
            if (i > x) chmin(mx, i);
        }
        score += s[x][y];
        score += (mx - mn) * (mx - mn - 1) / 2 * c[y];
        score -= (x - mn) * (x - mn - 1) / 2 * c[y];
        score -= (mx - x) * (mx - x - 1) / 2 * c[y];
        vector<int> new_;
        for (int i : ds[t[x]]) if (i != x) new_.push_back(i);
        ds[t[x]] = new_;
        new_.clear();
        rep(i, ds[y].size()) {
            if (ds[y][i] > x && ds[y][i - 1] < x) new_.push_back(x);
            new_.push_back(ds[y][i]);
        }
        ds[y] = new_;
        t[x] = y;
    };

    vector<int> last(26, -1);
    rep(i, d) {
        int mx = -inf, idx = -1;
        rep(j, 26) {
            if (chmax(mx, (i - last[j]) * c[j] * 13 + s[i][j])) idx = j;
        }
        t[i] = idx;
    }
    last = vector<int>(26, -1);
    rep(i, d) {
        score += s[i][t[i]];
        last[t[i]] = i;
        rep(j, 26) score -= (i - last[j]) * c[j];
    }
    rep(i, 26) ds[i].push_back(-1);
    rep(i, d) ds[t[i]].push_back(i);
    rep(i, 26) ds[i].push_back(d);

    rep(i, d) cout << t[i] + 1 << "\n";
}

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

int main() {
  ll k;
  cin>>k;
  ll ans=0;
  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
      for(int p=1;p<=k;p++){
        ans+=__gcd(i,__gcd(j,p));
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    scanf("%d\n", &N);
    long long T, A;
    for (int i = 0; i < N; ++i){
        int Ti, Ai;
        scanf("%d %d\n", &Ti, &Ai);
        if (i == 0){
            T = Ti;
            A = Ai;
        }else{
            const long long n = max(((Ti > 0) ? T / Ti + ((T % Ti) ? 1 : 0) : 0), ((Ai > 0) ? A / Ai + ((A % Ai) ? 1 : 0) : 0));
            T = n * Ti;
            A = n * Ai;
        }
    }
    printf("%lld\n", T + A);
}


Measured memory_bytes: 128
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main implements Runnable{
	int N,M;
	public void solve() {
		while(true){
			M = nextInt();
			N = nextInt();

			if(N + M == 0)break;
			boolean[] used = new boolean[7368792];
			int cnt = 0;
			for(int i = M;i < 7368792;i++){
				if(used[i])continue;
				if(!used[i]){
					if(cnt < N) cnt++;
					else {
						out.println(i);
						break;
					}
				}
				for(int j = i;j < 7368792;j+=i){
					used[j] = true;
				}
			}
		}
	}

	public static void main(String[] args) {
		new Thread(null,new Main(),"",32 * 1024 * 1024).start();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

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

	@Override
	public void run() {
		out.flush();
		new Main().solve();
		out.close();

	}
}

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

bool IsPrime(int n){
    if (n<2) return false;
    else if (n==2) return true;
    else if (n%2==0) return false;
    double q=sqrt(n);
    for(int i=3;i<q+1;i+=2){
        if(n%i==0){
            return false;
        }
    }
    return true;
}

int main(){
    cin>>n>>m;
    bool flag=IsPrime(m);
    while(true){
        if(flag){
            m=n;
            break;
        }
        if(m%n==0) break;
        n++;
    }
    cout<<m/n<<endl;
}

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

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

    int ans = 0;
    for(int a = 1; a <= n; a++){
        int cnt = 0;
        for(int i = 1; i <= a; i++){
            if(a % i == 0){
                cnt++;
            }
        }
        ans += cnt == 8 && a % 2;
    }
    cout << ans << endl;

    return 0;
}


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

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

ret = 0
while H.count(0) != N:
    f = False
    for i in range(N):
        if H[i]:
            if not f:
                f = True
                ret += 1
            H[i] -= 1
        else:
            f = False

print(ret)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int A, B, T;
    cin >> A >> B >> T;

    A *= 10;
    // B *= 10;
    T *= 10;

    cout << ((T+5) / A) * B << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;

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

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

  ll x[2];
  std::cin>>x[0]>>x[1];

  ll ans=0;

  rep(i,0,2){
    if(x[i]==1)ans+=300000;
    if(x[i]==2)ans+=200000;
    if(x[i]==3)ans+=100000;
  }

  if(x[0]==1&&x[1]==1)ans+=400000;

  std::cout<<ans<<"\n";

  return 0;
}

Measured memory_bytes: 256
module.exports=function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";var n=r(1),i=new(r(2))(n.readFileSync("/dev/stdin","utf8").trim().split(/\s+/g));r(4)(i)},function(t,e){t.exports=require("fs")},function(t,e,r){"use strict";var n=r(3);t.exports=class{constructor(t){this.inp=new n(t)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,r){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,r){"use strict";t.exports=function(t){var e=t.in();if(0!=e){for(var r=[],n=0,i=e>=0,s=Math.abs(e),o=1;n<s;)i&&o>0&&(n+=o),!i&&o<0&&(n+=Math.abs(o)),r.push(o),o*=-2;for(var u=0,c=r.length,l=new Array(c).fill(0),a=0;a<c;a++){var f=2*Math.abs(r[a]),p=e%f,d=(u+r[a])%f;p<0&&(p+=f),d<0&&(d+=f),p==d?(l[c-1-a]="1",u+=r[a]):l[c-1-a]="0"}console.log(l.join(""))}else console.log("0")}}]);

Measured memory_bytes: 7372
import java.util.*;
import java.io.*;
 class Main{
public static void main(String[] args)throws IOException {
    FastReader in=new FastReader(System.in);
    int n=in.nextInt();
    int t=in.nextInt();
    int arr[][]=new int[n][2];
    int f=-1,i,max=1001;
    for(i=0;i<n;i++)
    {
        arr[i][0]=in.nextInt();
        arr[i][1]=in.nextInt();
        if(arr[i][1]<=t)
        {
            if(arr[i][0]<max)
            max=arr[i][0];
            f=1;
        }
    }
    if(f==-1)
    System.out.println("TLE");
    else
    System.out.println(max);
}
}
class FastReader {
 
    byte[] buf = new byte[2048];
    int index, total;
    InputStream in;
 
    FastReader(InputStream is) {
        in = is;
    }
 
    int scan() throws IOException {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0) {
                return -1;
            }
        }
        return buf[index++];
    }
 
    String next() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan());
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }
    String nextLine() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan());
        StringBuilder sb = new StringBuilder();
        for (; c !=10; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }
    char nextChar() throws IOException{
        int c;
         for (c = scan(); c <= 32; c = scan());
         return (char)c;
        }
 
    int nextInt() throws IOException {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan());
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }
 
    long nextLong() throws IOException {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan());
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    if ((A + B) % 2 == 0) cout << (A + B) / 2 << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll a,b,c;
    cin>>a>>b>>c;
    __int128 x,y,z,hi,lo,mid;
    y=4*a*b;
    
    lo=0;
    hi=y;
    if (a+b>=c){
        cout<<"No\n";
        return 0;
    }
    while (hi>lo){
        mid=lo+(hi-lo)/2;
        //cout<<mid<<'\n';
        if (mid*mid<=y){
            lo=mid+1;
        }
        else {
            hi=mid;
        }
    }
    if (lo*lo>y&&lo>0){
        lo--;
    }
    z=lo;
    x=a+b+z;
    if (c<=x){
        cout<<"No\n";
    }
    else {
        cout<<"Yes\n";
    }

}

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

using namespace std;

typedef long long LL;

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ALL(a)  (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define dump(x)  cerr << #x << " = " << (x) << endl;

LL p = 1000*1000*1000 + 7;

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

  LL a_count = 0, h_cum = 1, incre = 0, count = 0;

  for (const auto &c : S) {
    if (c == 'A') {
      a_count = (a_count + h_cum)%p;
    } else if (c == 'B') {
      incre = (incre + a_count)%p;
    } else if (c == 'C') {
      count = (count + incre)%p;
    } else if (c == '?') {
      count = (count*3 + incre)%p;
      incre = (incre*3 + a_count)%p;
      a_count = (a_count*3 + h_cum)%p;
      h_cum = (h_cum*3)%p;
    }
  }
  
  cout << count % p << endl;


  return 0;
}

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

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; read(n);
	vector<ll> a(n);
	vector<ll> freq(100001);
	ll ans = 0;
	rep(i, 0, n) {
		read(a[i]);
		freq[a[i]]++;
		ans += a[i];
	}
	int q; read(q);
	rep(i, 0, q) {
		ll b, c; read(b, c);
		ans -= b * freq[b] + c * freq[c];
		freq[c] += freq[b];
		freq[b] = 0;
		ans += c * freq[c];
		write(ans);
	}
}


Measured memory_bytes: 4780
k = int(input())
sum = 0


def euclid(a, b):
    while b:
        a, b = b, a % b
    return a


for a in range(1, k + 1):
    for b in range(a, k + 1):
        for c in range(b, k + 1):
            if a == b == c:
                sum += a
            elif a == b or b == c:
                sum += euclid(euclid(a, b), c) * 3
            else:
                sum += euclid(euclid(a, b), c) * 6
print(sum)


Measured memory_bytes: 69116
#include <iostream>
using namespace std;
 
int main(){
	int a, b;
	cin >> a >> b;
	
	if (a < b) cout<<"a < b"<<endl;
	if (a > b) cout<<"a > b"<<endl;
	if (a == b) cout<<"a == b"<<endl;
	
	return 0;
}

Measured memory_bytes: 3084
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
#define U(v) cerr << #v << ": " << (v) << endl;

int bl[4001][4001];
int wh[4001][4001];

int main() {
    int n, k;
    while (cin >> n >> k) {
        struct S {
            int x, y;
            char c;
        };
        memset(bl, 0, sizeof(bl));
        memset(wh, 0, sizeof(wh));
        for (int i = 0; i < n; ++i) {
            S s;
            cin >> s.x >> s.y >> s.c;
            int x = s.x % (k * 2);
            int y = s.y % (k * 2);
            if (s.c == 'B') {
                bl[y + 1][x + 1]++;
                bl[y + k * 2 + 1][x + 1]++;
                bl[y + 1][x + k * 2 + 1]++;
                bl[y + k * 2 + 1][x + k * 2 + 1]++;
            } else {
                wh[y + 1][x + 1]++;
                wh[y + k * 2 + 1][x + 1]++;
                wh[y + 1][x + k * 2 + 1]++;
                wh[y + k * 2 + 1][x + k * 2 + 1]++;
            }
        }
        for (int y = 1; y <= k * 4; ++y) {
            for (int x = 1; x <= k * 4; ++x) {
                bl[y][x] += bl[y - 1][x] + bl[y][x - 1] - bl[y - 1][x - 1];
                wh[y][x] += wh[y - 1][x] + wh[y][x - 1] - wh[y - 1][x - 1];
            }
        }
        int mx = 0;
        for (int y = 0; y < k * 2; ++y) {
            for (int x = 0; x < k * 2; ++x) {
                int p = bl[y + k][x + k] + bl[y][x] - bl[y + k][x] - bl[y][x + k];
                int q = bl[y + k * 2][x + k * 2] + bl[y + k][x + k] - bl[y + k * 2][x + k] - bl[y + k][x + k * 2];
                int r = wh[y + k * 2][x + k] + wh[y + k][x] - wh[y + k][x + k] - wh[y + k * 2][x];
                int s = wh[y + k][x + k * 2] + wh[y][x + k] - wh[y + k][x + k] - wh[y][x + k * 2];
                mx = max(mx, p + q + r + s);
            }
        }
        cout << mx << endl;
    }
    return 0;
}


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

int main(){

    string s;
    cin >> s;

    int num = s.size();
    int l = 1e6, r = 0, ans = -1;
    for (int i=0; i<num; i++){
        int buf;
        if (s.at(i) == 'A') {
            buf = i;
            l = min(buf, l);
        }
        if (s.at(num-1-i) == 'Z') {
            buf = num-1-i;
            r = max(buf, r);
        }
        buf = r-l+1;
        ans = max(buf, ans);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;
typedef vector<unordered_map<lli,lli>> graph;

const lli mod = 1000000007;

lli n,a,b,c,d;
mat dp;

lli factorial(lli n){
  static lli dp[100000];
  if(dp[n]) return dp[n];
  if(n == 0) return dp[n] = 1;
  return dp[n] = (n*factorial(n-1))%mod;
}

lli pow(lli x,lli r,lli mod = 1000000007){
  lli ret = 1;
  for(;r != 0;r >>= 1){
    if(r&1 != 0) ret *= x,ret %= mod;
    x *= x,x %= mod;
  }
  return ret;
}

lli inverse(lli x,lli mod = 1000000007){
  return pow(x,mod-2,mod);
}

int main(){
  cin >> n >> a >> b >> c >> d;
  dp = mat(n+1,vll(n+1));
  dp[0][0] = 1;
  for(lli i = 1;i <= n;i++){
    for(lli j = 0;j <= n;j++){
      dp[i][j] = dp[i-1][j];
      if(i >= a && i <= b){
        for(lli k = c;k <= d;k++){
          if(j-i*k < 0) break;
          lli x = dp[i-1][j-i*k];
          x *= factorial(j);x %= mod;
          x *= inverse(factorial(k)); x %= mod;
          x *= inverse(pow(factorial(i),k)); x %= mod;
          x *= inverse(factorial(j-i*k));x %= mod;
          dp[i][j] += x;
          dp[i][j] %= mod;
        }
      }
    }
  }
  cout << dp[n][n] << endl;
  return 0;

}


Measured memory_bytes: 10112
#include<iostream>
#include <cstdlib> 
using namespace std;
int main()
{
    long long n,k,min;
    cin>>n>>k;
    if(n/k>0)
    {
        long long r=n%k;
        if(r<abs(r-k))
            min=r;
        else
            min=abs(r-k);
    }
    else
    {
        if(n<abs(n-k))
            min=n;
        else
            min=abs(n-k);
    }
    cout<<min;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	vector<vi> cnt(10, vi(10));
	for(int i = 1; i <= n; i++) if(i % 10){
		vi d;
		for(int j = i; j; j /= 10) d.pb(j % 10);
		cnt[d.back()][d[0]]++;
	}
	ll ans = 0;
	rep(i, 10) rep(j, 10) ans += (ll)cnt[i][j] * cnt[j][i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <sstream>
#include <map>
#include <deque>
#include <queue>
#include <set>
using namespace std;
int main(){
	int ans=0;
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s[i]=='-') ans--;
		else ans++;
	}
	cout<<ans<<endl;
	return 0;
}
 

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
n,k = readInts()
ans = 0
A = readInts()
for i in range(1,n):
    ans += min(k, A[i] - A[i-1])
print(ans+k)


Measured memory_bytes: 32100