akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

void solve() {
	int n;
	cin >> n;
	for(int i = 0; i < 10; i++) {
		for(int j = 0; j < 10; j++) {
			if(i * j == n) {
				cout << "Yes" << endl;
				return;
			}
		}
	}
	
	cout << "No" << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{

    class Program
    {
        static void Main(string[] args)
        {

            String S = Console.ReadLine();
            String[] L = S.Split(' ');
            int P = int.Parse(L[0]);
            int Q = int.Parse(L[1]);
            int R = int.Parse(L[2]);

            if(P + Q <= P + R && P + Q <= Q + R)
            {
                Console.WriteLine(P + Q);
            }
            else if(P + R <= P + Q && P + R <= Q + R)
            {
                Console.WriteLine(P + R);
            }
            else
            {
                Console.WriteLine(Q + R);
            }

        }
    }
}

Measured memory_bytes: 11092
use std::io;
use std::cmp::Ordering;


fn main() {
    let n = read_one::<usize>();
    let mut rest = Vec::new();
    for i in 0..n {
        let (s, p) = {
            let i = read::<String>();
            (i[0].clone(), i[1].clone().parse::<usize>().unwrap())
        };
        rest.push((i + 1, s, p));
    }

    rest.sort_by(|a, b| {
        match (a.1).cmp(&b.1) {
            Ordering::Equal => (b.2).cmp(&a.2),
            x => x,
        }
    });

    for r in rest {
        println!("{}", r.0);
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <math.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

int main()
{
int n,x;
cin >> n >> x;
while(!(n==0&&x==0))
{
int ans=0;
for(int i=1;i<n-1;i++)
{
for (int j=i+1;j<n;j++)
{
if(x-i-j>j&&x-i-j<n+1)ans++;
}
}
cout << ans << endl;
cin >> n >> x;
}
}



Measured memory_bytes: 3092
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.System.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static void solve() throws Exception {
        long A = scanLong(), B = scanLong(), C = scanLong(), K = scanLong();
        long ans = 0;

        if (K <= A) {
            System.out.println(K);
        } else {
            ans = A;
            K -= A;

            if (K <= B) {
                System.out.println(ans);
            } else {
                K -= B;
                System.out.println(ans - K);
            }
        }
    }

    static int scanInt() throws IOException {
        return parseInt(scanString());
    }

    static long scanLong() throws IOException {
        return parseLong(scanString());
    }

    static String scanString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            in.close();
            out.close();
        }
        catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}

Measured memory_bytes: 32936
/**
 *     author: qodjf
 *     created: 04.24.2020 14:56:03
 */
#include <bits/stdc++.h>
using namespace std;

string to_string(string s) { return '"' + s + '"'; }

string to_string(const char *s) { return to_string((string)s); }

string to_string(bool b) { return (b ? "true" : "false"); }

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

#define mst(x, a) memset(x, a, sizeof(x))

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr ll LLINF = 0x3f3f3f3f3f3f3f3f;
constexpr ll MOD = 1e9 + 7;

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

void solve() {}

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

  int N, M;
  cin >> N >> M;
  vector<vector<int>> like(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> like[i][j];
      like[i][j]--;
    }
  }

  int ans = N;
  vector<int> choose(N, 0);
  vector<vector<int>> sport2Participants(M);
  vector<bool> excluded(M, false);
  for (int i = 0; i < N; i++) {
    sport2Participants[like[i][0]].push_back(i);
  }

  for (int k = 0;; k++) {
    int maxCnt = 0, maxSport = -1;
    for (int i = 0; i < M; i++) {
      if (sport2Participants[i].size() > maxCnt) {
        maxCnt = sport2Participants[i].size();
        maxSport = i;
      }
    }
    ans = min(ans, maxCnt);
    excluded[maxSport] = true;
    if (k == M - 1) break;

    for (int per : sport2Participants[maxSport]) {
      int c = choose[per] + 1;
      while (c < M && excluded[like[per][c]]) c++;
      sport2Participants[like[per][c]].push_back(per);
      choose[per] = c;
    }

    sport2Participants[maxSport].clear();
  }
  cout << ans << endl;
}


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

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

  ll sum=0;

  map<int,int> m;

  rep(i,n){
      int a;
      cin >> a;
      sum += a;
      m[a] ++;

  }

  cin >> q;

  rep(i,q){
   int b,c;
   cin >> b >> c;

   if(m[b]>0){
       int gap = c-b;
       sum += gap * m[b];
       
       m[c] += m[b];

       m[b] =0;

   }
   cout << sum << endl;
  }

  
}

Measured memory_bytes: 7800
s = list(map(int,input().split()))
n=s[0]
m=s[1]
q=s[2]
f=[]
ans=0

for i in range(q):
    s = list(map(int, input().split()))
    f.append([s[0],s[1],s[2],s[3]])

def score_cal(y):
    score=0
    for i in f:
        if y[i[1]-1]-y[i[0]-1]==i[2]:
            score+=i[3]
    return score

def dfs(A):
    if len(A)==n:
        score=score_cal(A)
        global ans
        if ans<score:
            ans=score
        return 
    for v in range(A[-1],m+1):
        A.append(v)
        dfs(x)
        A.pop()

for i in range(1,m+1):
    x=[]
    x.append(i)
    dfs(x)

print(ans)


Measured memory_bytes: 9168
import sys
def s():
 n,k=map(int,input().split())
 w=list(map(int,sys.stdin.readlines()))
 def f():
  c=t=0
  for j in w:
   t+=j
   if t>m:
    t=j
    c+=1
    if c>=k:return 0
  return 1
 l,r=max(w),sum(w)
 while l<r:
  m=(l+r)//2
  if f():r=m
  else:l=m+1
 print(r)
if'__main__'==__name__:s()



Measured memory_bytes: 15832
n=int(input())
h=list(map(int,input().split()))
count=0
ans=0
for i in range(n-1):
    if h[i]>=h[i+1]:
        count+=1
    else:
        if ans<count:
            ans=count
            count=0
        else:
            count=0
print(ans if ans>count else count)

Measured memory_bytes: 14252
use std::cmp::{max, min};
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let x: i32 = read();
    let a: i32 = read();
    let b: i32 = read();

    println!("{} {}", min(a, b), max(0, (a + b) - x));
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rt return 0
#define endln "\n"
#define all(v) v.begin(), v.end()
#define for1(i, a, b) for (long long int i = a; i < b; i++)
#define for2(i, a, b) for (long long int i = a; i > b; i--)
//  cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;typedef long long int i;
typedef long long int lli;
typedef pair<lli, lli> pll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli n;
    cin >> n;
    if (n == 2)
    {
        cout << "1" << endl;
        return 0;
    }
    vector<lli> v;
    lli a = n - 1;
    lli c = 0;
    map<lli, lli> m;
    for (lli i = 1; i * i <= a; i += 1)
    {
        if (a % i == 0)
        {
            lli x = a / i;
            if (n % i != 0)
            {
                m[i] = 1;
                c += 1;
            }
            if (x != i)
            {
                if (n % x != 0)
                {
                    m[x] = 1;
                    c += 1;
                }
            }
        }
    }
    // lli i1  = sqrt(n);
    // cout << "1" << endl;
    for (lli i = 2; i * i <= n; i += 1)
    {
        if (n % i == 0)
        {
            lli x = n / i;
            lli p = n, q = n;
            while (p % i == 0)
            {
                p /= i;
            }
            if (p % i == 1)
            {
                c += 1;
            }
            if (i != x)
            {
                while (q % x == 0)
                {
                    q /= x;
                }
                if (q % x == 1)
                {
                    c += 1;
                }
            }
        }
    }
    if (n != 2)
    {
        c += 1;
    }
    cout << c << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 10000
#define Q 500

int main(){
  int n,n1[N],q,q1[Q],i,sum=0,j;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&n1[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&q1[i]);
  }
  
  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(n1[j]==q1[i]){
	sum++;
	break;
      }
    }
  }
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 640
#include <cstdio>

int main()
{
	int n;
	scanf("%d", &n);
	if (n % 10 == 7 || (n / 10)% 10 == 7 || n / 100 == 7) 
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}

Measured memory_bytes: 1616
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long int i,j,n,ans;
    ans=0;
    cin >> n;
    vector<long long int> vec(n);
    for(i=0;i<n;i++){
    cin >> vec.at(i);
    }
    if(vec.at(0)>1){vec.at(0)=vec.at(0)-1;}
    for(i=0;i<n-1;i++){
        if(vec.at(i)==vec.at(i+1)){
            vec.at(i+1)=vec.at(i+1);
        }
        else if(vec.at(i)<vec.at(i+1)){
            vec.at(i+1)=vec.at(i+1)-1;
        }
        else {
            ans=1;
        }
    }
    if(ans==1){
        cout<<"No"<<endl;
    }else
    {
        cout<<"Yes"<<endl;
    }
    
}

Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#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 ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  int a,b; cin >>a>>b;
  cout <<a*b<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 



int color[100005]; // 0:=fennic 1:=snule
vi to[100005];

int n;
vi path;

int F, S;
void dfs(int v, int from=-1, int len=0) {
  if (v==n-1) {
    // printf("Len = %d\n", len);
    // printf("Path size = %d\n ", path.size());
    len--;
    int f=(len-1)/2 +1 ;
    rep(i,f) if (color[path[i]] != 2) color[path[i]] = 3;
    // rep(i,path.size()) cout << path[i] << endl;
    if (path.size()>f) color[path[f]] = 4;
    // cout << path[f] << endl;
    return;
  }
  for (int u: to[v]) {
    if (u==from) continue;
    path.push_back(u);
    dfs(u, v, len+1);
    path.pop_back();
  }
}

int main() {
  cin >> n;
  rep(i,n-1) {
  int a,b; cin >> a >> b; a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  color[0] = 1;
  color[n-1] = 2;

  dfs(0); 

  queue<int> q;
  q.push(0);
  while (q.size()) {
    int v=q.front(); q.pop();
    for (int u: to[v]) {
      if (color[u]==1 || color[u]==4 || color[u] == 2) continue;
      color[u] = 1;
      q.push(u);
    }
  }
  q.push(n-1);
  while (q.size()) {
    int v=q.front(); q.pop();
    for (int u: to[v]) {
      if (color[u]==1||color[u]==2||color[u]==3) continue;
      color[u] = 2;
      q.push(u);
    }
  }
  // rep(i, n) cout << color[i] << endl;
  q.push(0);
  while (q.size()) {
    int v=q.front(); q.pop();
    if (color[v] == 1) F++;  
    if (color[v] == 2) S++;
    color[v] = 0;
    for (int u:to[v]) {
      if (color[u] == 0) continue;
      q.push(u);
    }
  }
  int rest = n-(F+S);
  string winner = "Fennec";
  if (F>S) winner = "Fennec";
  if (F<S) winner = "Snuke";
  if (F==S) {
    winner = "Snuke";
  }
  cout << winner << endl;
  return 0;
}

Measured memory_bytes: 15900
from collections import deque


def main():
    N, M = list(map(int, input().split()))
    graphs = [[] for i in range(N)]
    for i in range(M):
        a, b = list(map(int, input().split()))
        graphs[a-1].append(b-1)
        graphs[b-1].append(a-1)

    INF = 100000000

    distance = [INF for i in range(N)]
    visited = [False] * N
    #    distance = [[None]*field_x_length]*field_y_length
    visited[0] = True
    distance[0] = 0

    def bfs():
        queue = deque([0])
        distance[0] = 0

        while queue:
            x = queue.popleft()
            for y in graphs[x]:
                if visited[y]:
                    continue
                else:
                    distance[y] = x
                    visited[y] = True
                    queue.append(y)
        return distance

    d = bfs()
    for i in range(N):
        if not visited[i]:
            print("No")
            exit()
    print("Yes")
    for i in range(1, N):
        print(d[i]+1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 34848
a, b = map(int, input().split())
cnt = 0

for i in range(a, b+1):
    l = []
    while (i > 0):
        l.append(i%10)
        i//=10
    if (l[0] == l[4] and l[1] == l[3]):
        cnt+=1
print(cnt)


Measured memory_bytes: 9080
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, int> pli;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 1000010;

int main(){
        int e;
        while(scanf("%d", &e) && e){
                int m=MAX;
                for(int z=0; z*z*z<=e; ++z){
                        for(int y=0; y*y<=e; ++y){
                                int x=e-z*z*z-y*y;
                                if(x>=0) chmin(m, x+y+z);
                        }
                }
                printf("%d\n", m);
        }
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
string s,s2,s3 ;
int a ,b ;
const int N =1e7  + 9 ;
int arr[N];
string st;
int main() {



cin>>st>>s2>>s3;

cout<<st[0]<<s2[1]<<s3[2];



}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1000000000
#define MOD 3
#define mod(x) ((x % MOD) + MOD) % MOD
#define MAX_Q 100001
#define MAX_L 100001

using namespace std;

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

int main() {
  string S, T;
  ll q, a[MAX_Q], b[MAX_Q], c[MAX_Q], d[MAX_Q];
  cin >> S >> T >> q;
  for (ll i = 0; i < q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  ll sum_s[MAX_L], sum_t[MAX_L];
  sum_s[0] = 0;
  sum_t[0] = 0;

  for (ll i = 0; i < S.size(); i++) {
    ll s = (S[i] == 'A') ? 1 : -1;
    sum_s[i+1] = mod(sum_s[i] + s);
  }
  for (ll i = 0; i < T.size(); i++) {
    ll t = (T[i] == 'A') ? 1 : -1;
    sum_t[i+1] = mod(sum_t[i] + t);
  }

  for (ll i = 0; i < q; i++) {
    if (mod(sum_s[b[i]] - sum_s[a[i]-1]) ==
        mod(sum_t[d[i]] - sum_t[c[i]-1])) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }

  return 0;
}


Measured memory_bytes: 5632
#include <stdio.h>
#include <math.h>
int get_kaijyo(int n);
double get_distance(double x1,double y1,double x2,double y2);
int main() {
  	double x[8];
  	double y[8];
  	int num,i,j,kaijyo,kaijyo2;
  	double ans=0;
  	scanf("%d",&num);
  	for(i=0; i<num; i++) {
  		scanf("%lf %lf", &x[i],&y[i]);
    }
  	kaijyo = get_kaijyo(num-1);
  	kaijyo2=kaijyo*num;
  	for(i=0;i<num-1;i++) {
    	for(j=i+1;j<num;j++) {
        	ans+=(double)(get_distance(x[i],y[i],x[j],y[j])*kaijyo*2);
        }
    }
  	ans=ans/kaijyo2;
  	printf("%lf",ans);
	return 0;
}

int get_kaijyo(int n) {
	int ans=1;
  	int i;
  	for(i=2;i<=n;i++) {
    	ans=ans*i;
    }
  	return ans;
}

double get_distance(double x1,double y1,double x2,double y2) {
  	double distance;
  	distance=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  	return distance;
}

Measured memory_bytes: 128
mod=10**9+7
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a,b=mi()
l=list(mi())
dp=[0]*a
dp[0]=0
for i in range(1,a):
    dp[i]=min(abs(l[i]-l[i-j-1])+dp[i-j-1] for j in range(min(i,b)))
print(dp[-1])

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

int main(){
  int N; cin>>N;
  string S; cin>>S;
  vector<int> A(N);
  vector<int> B(N);
  for(int i=0;i<N;i++){
    if(S[i]=='#')
      A[i]=1;
    if(i)
      A[i]+=A[i-1];
    if(S[N-1-i]=='.')
      B[N-1-i]=1;
    if(i)
      B[N-1-i]+=B[N-i];
  }
  vector<int> C(N+1);
  C[N]=B[0];
  for(int i=0;i<N;i++){
    if(i==N-1){
      C[i]=A[i];
    }
    C[i]=A[i]+B[i+1];
  }
  sort(C.begin(),C.end());
  cout<<C[0]<<endl;
}

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

int main() {
    int n;
    long long total = 0;
    cin >> n;
    int a[n];
    for (int i=0;i<n;i++) {
        cin >> a[i];
        total += a[i];
    }
    cout << *min_element(a, a+n) << " " << *max_element(a, a+n) << " " <<total << endl;
}


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

using namespace std;

    char s[3123];
    char t[3123];
    int dp[3123][3123];
    string resp;
    
int main() {
    scanf(" %s", s+1);
    scanf(" %s", t+1);
    //printf("%s\n", s+1);
    //printf("%s\n", t+1);
    dp[0][0] = 0;
    int max1 = strlen(s+1);
    int max2 = strlen(t+1);
    
    for(int i = 1; i<= max1; i++){
        
        for(int j = 1; j<=max2; j++){
            if(s[i] == t[j]){
               dp[i][j] = dp[i-1][j-1] +1;
                //printf("i = %d j = %d\n", i, j);
                
            }
            else  dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        
        }
     
        
    }
    int aux = max1;
    int aux2 = max2;
    
    while(aux > 0 && aux2 > 0){
        
        if(s[aux] == t[aux2]){
            resp.push_back(s[aux]);
            aux--;
            aux2--;
        }
        else{
            if(dp[aux][aux2-1]>dp[aux-1][aux2] ) aux2--;
            else aux--;
            
            
        }
    }
    
    for(int i = resp.size()-1; i >= 0 ; i-- ) printf("%c", resp[i]);

    return 0;
}

Measured memory_bytes: 37120
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <tuple>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int a,b,c; cin>>a>>b>>c;
    int x; cin>>x;
    int ans = 0;
    for(int acnt = 0; acnt<=a&& acnt*500<=x; ++acnt){
        int sum = acnt*500;
        for(int bcnt = 0; bcnt<=b&& sum+bcnt*100<=x; ++bcnt){
            if(0<=(x-sum-bcnt*100)/50&&(x-sum-bcnt*100)/50<=c)ans++;
        }
    }
    cout<<ans<<endl; return 0;
}


Measured memory_bytes: 256
/*
@author: sharrad99
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define	PI 3.141592653589793238462643383279502884197169399375105820974944592307816406286
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vll vector<ll>
#define vbl vector<bool>
#define vpll vector<pll>
#define pb push_back
#define eb emplace_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(x) x.begin(),x.end()
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define mod 1000000007
#define INF 1000000000000000
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set_pll;
#define ook order_of_key
#define fbo find_by_order
/*  
	Query 1 - order_of_key(k) : Number of items strictly smaller than k.
	Query 2 - find_by_order(k) : K-th element in the set (counting from zero).
	less<ll> means Query 1 will return numbers strictly less than k.
	greater<ll> means Query 1 will return numbers strictly greater than k.
*/
ll powmod(ll x, ll n){
	ll res = 1;
	while(n){
		if(n & 1){
			res *= x;
			res %= mod;
		}
		x *= x;
		x %= mod;
		n >>= 1;
	}
	return res;
}
ll invmod(ll a){
	return powmod(a, mod - 2);
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin >> n;
	ll res = 0;
	for(ll k = 10; k <= n; k *= 5){
		res += (n / k);
	}
	cout << (n % 2 ? 0 : res);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int i = (0);i < (n);++i)
#define rep(i,s,g) for(int i = (s);i < (g);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cerr << v[a][b] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;


struct UF{
    vector<int> d;
    UF(int n):d(n,-1){}
    bool set(int x,int y){
        x=root(x),y=root(y);
        if(x!=y){if(d[y]<d[x])swap(x,y);d[x]+=d[y];d[y]=x;}
        return x!=y;
    }
    bool find(int x,int y){return root(x)==root(y);}
    int root(int x){
        while(d[x]>=0){if(d[d[x]]>=0)d[x]=d[d[x]];x=d[x];}
        return x;
    }
    int size(int x){return -d[root(x)];}
};


int main()
{
	int n,q;
	cin >> n >> q;
	UF uf(n);
	
	REP(i,q)
	{
		int s,x,y;
		cin >> s >> x >> y;
		if(s == 0)
		{
			uf.set(x,y);
		}
		else
		{
			bool ret = uf.find(x,y);
			cout << ret << endl;
		}
	}
	
	
	return 0;
}

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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;

	for (int ii = 0; ii < 100; ++ii){
		int val = ii * a + 1 - ii;
		if (val >= b){
			cout << ii << "\n";
			return 0;
		}
	}


	return 0;
}


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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

int n,k;cin>>n>>k;
ll ans=0;
vector<ll> v(n);
for(int i=0;i<n;i++)cin>>v[i];

for(int i=0;i<=max(n, k);i++){
  for(int j=0;j<=max(n,k);j++){
    if(i+j>k)break;
    if(i+j>n)break;

    vector<int> vt;
    for(int j=0;j<i;j++)vt.push_back(v[j]);

    for(int j2=0;j2<j;j2++)vt.push_back(v[n-j2-1]);

    sort(vt.begin(), vt.end());
    ll t=0;
    int rest=k-i-j;
    for(int j2=0;j2<vt.size();j2++){
      if(rest>0 && vt[j2]<0){
        rest--;continue;
      }
      t+=vt[j2];
    }
    // cout<<i<<':'<<j<<':'<<t<<endl;
    ans=max(t,ans);
  }
}
cout<<ans<<endl;
  
  return 0;
}


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

int main(void)
{
  string S, T;
  cin >> S >> T;
  int A, B;
  cin >> A >> B;
  string U;
  cin >> U;

  if (S == U)
  {
    A--;
  }
  else if (T == U)
  {
    B--;
  }

  cout << A << " " << B << endl;
}

Measured memory_bytes: 256
data = input().split()
N = int(data[0])
A = int(data[1])
B = int(data[2])
C = int(data[3])

i = 0
kd = []
while i < N:
  kd.append(int(input()))
  i += 1


cur = 0 
sc = 0
def ans(cur,a,b,c):
  if cur == N:
    return abs(a-A) + abs(b-B)+ abs(c-C) - 30 if min(a,b,c) > 0 else 1000000
  ret0 = ans(cur+1,a,b,c)
  ret1 =  ans(cur+1,a+kd[cur],b,c) + 10
  ret2 = ans(cur + 1,a,b+kd[cur],c) +10 
  ret3 = ans(cur+1,a,b,c+kd[cur])+ 10
  return min(ret0,ret1,ret2,ret3)

print(ans(0,0,0,0))
    
    

       
  


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  int aa, bb, cc;
  int ans = 0;
  cin >> a >> b >> c;
  aa = a;
  bb = b;
  cc = c;
  if (a == b && b == c && a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (aa % 2 == 0 && bb % 2 == 0 && cc % 2 == 0) {
    a = (bb + cc) / 2;
    b = (cc + aa) / 2;
    c = (aa + bb) / 2;
    aa = a;
    bb = b;
    cc = a;
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

int d[201][201];

int main(){
    int n, m, r;
    cin >> n >> m >> r;
    
    const int INF = 1e9;
    rep(i, n){
        rep(j, n) if(i != j) d[i][j] = INF;
    }

    vector<int> v(r);
    rep(i, r){
        cin >> v[i];
        v[i]--;
    } 

    rep(i, m){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        d[a][b] = c;
        d[b][a] = c;
    }

    rep(k, n){
        rep(i, n){
            rep(j, n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
    }

    int ans = 1e9;

    vector<int> per(r);
    rep(i, r) per[i] = i;
    do {
        int sum = 0;
        rep(i, r-1){
            int from = v[per[i]], to = v[per[i+1]];
            sum += d[from][to];
        }
        ans = min(ans, sum);
    } while(next_permutation(all(per)));

    cout << ans << endl;
}

Measured memory_bytes: 384
def main():
    s = input()
    ans = [0] * (len(s) + 1)

    for i in range(len(s)):
        if s[i] == '<':
            ans[i + 1] = max(ans[i + 1], ans[i] + 1)
    
    #print(ans)
            
    for i in reversed(range(len(s))):
        if s[i] == '>':
            ans[i] = max(ans[i], ans[i + 1] + 1)
    
    #print(ans)
    print(sum(ans))



if __name__ == "__main__":
    main()


Measured memory_bytes: 23340
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int A = nextInt();
		int B = nextInt();
		int C = nextInt();

		int ans = 0;
		if(A==B&&B==C&A%2==0){
			System.out.println(-1);
			return;
		}
		while(A%2==0 && B%2==0 && C%2==0){
			int tmpA = B/2+C/2;
			int tmpB = A/2+C/2;
			C=A/2+B/2;
			A=tmpA;
			B=tmpB;
			ans++;
		}

		System.out.println(ans);

	}

	public static boolean is2n(long a){
		int x=1;
		while((int)Math.pow(x, 2) <= a){
			if((int)Math.pow(x, 2) == a){
				return true;
			}
			x*=2;
		}
		return false;
	}
	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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

int main(){
  long long A,B,C,K,ans=0;
  cin>>A>>B>>C>>K;
  if(K<A){
    ans=K;
  } else if(K<A+B){
    ans=A;
  } else if(K<=A+B+C){
    ans=A-(K-A-B);
  }
  cout<<ans<<endl;
}

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

#define asc(v) sort(v.begin(), v.end())
#define desc(v) sort(v.begin(), v.end(), greater<int>())
#define vi vector<int>
#define vvi vector<vi>

using namespace std;

typedef long long ll;

int main() {
  ll N, M;
  cin >> N >> M;
  if (N == 1 && M >= 2)
    cout << M - 2 << endl;
  else if (M == 1 && N >= 2)
    cout << N - 2 << endl;
  else if (N == 1 && M == 1)
    cout << 1 << endl;
  else
    cout << (N - 2) * (M - 2) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    int N, K; cin >> N >> K;
    vector<int> A(N+1);
    rep(i, N) cin >> A[i];
    if (N <= K) {
        rep(i, N) {
            if (i) cout << " ";
            cout << N;
        }
        cout << endl;
        return 0;
    }
    rep(i, K) {
        vector<int> memo(N+1);
        rep(i, N) {
            memo[max(i-A[i], 0)]++;
            memo[min(i+A[i]+1, N)]--;
        }
        bool flag = true;
        rep(i, N) {
            memo[i+1] = memo[i] + memo[i+1];
            if (memo[i] != N) flag = false;
        }
        swap(memo, A);
        if (flag) break;
    }
    rep(i, N) {
        if (i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 5152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	int N, M, C;
	cin >> N >> M >> C;
	int B[100];
	rep(i, M) cin >> B[i];

	int kotae = 0;
	rep(i, N) {
		int A[100];
		rep(i, M) cin >> A[i];
		int kari = C;
		rep(i, M) kari += A[i] * B[i];
		if (kari > 0) kotae++;
	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<int> a(n);
for(int i = 0;i < n;i++){
    cin >> a.at(i);
}

int ans = 1;

for (int i = 0; i < n; i++){
    if(a.at(i)%2 == 0){
        if(a.at(i)%3 == 0 || a.at(i)%5 == 0){
        }else{
            ans = 0;
        }
    }
}

int count = 0;

for (int i = 0; i < n; i++){
    if(a.at(i)%2 == 1){
        count++;
    }
}
if(count == n){
    ans++;
}

if(ans >= 1){
    cout << "APPROVED" << endl;
}else {
    cout << "DENIED" << endl;
}


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

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,k,s;
	cin>>n>>k>>s;
	for(ll i=0;i<n;i++){
		if(i<k){
			cout << s;
		}
		else{
			if(s==1000000000){
				cout << 1;
			}
			else{
			cout << s+1;
			}
		}
		cout << " ";
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <math.h>
#include <stack>
#include <tuple>
#include <cstring>
#include <chrono>
#include <bitset>
#include <list>
#include <stdlib.h>
#include <iomanip>
#include <bitset>
#include <chrono>
 
using namespace std;
 
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
 
bool comparator(const pair<ll, ll> &x, const pair<ll, ll> &y)
{
    return x.second - x.first < y.second - y.first;
}
 
ll gcd(ll x, ll y)
{
    return y == 0LL ? x : gcd(y, x % y);
}
 
struct interval {
    int len;
    ll value;
};

 
int main()
{
    std::ios::sync_with_stdio(false);
 
    char c;
    cin >> c;
    c++;
    cout << c << endl;
    
    return 0;
}


Measured memory_bytes: 256
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    a, b, c, d = list(map(int, _in[0].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    ans = -float('inf')
    for _ in [a * c, a * d, b * c, b * d]:
        ans = max(ans, _)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()


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

int n,l;
int a[1000005];
multiset<int>s;

int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>l;
    for (int i=0;i<n;++i) cin>>a[i];
    for (int i=0;i<l;++i) s.insert(a[i]);
    cout<<*s.begin();
    for (int i=l;i<n;++i) {
        s.erase(s.find(a[i-l]));
        s.insert(a[i]);
        cout<<' '<<*s.begin();
    }
    cout<<'\n';
}


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

int main(int argc, const char * argv[]) {
    int n, d, ans;
    
    cin >> n >> d;
    
    if(n % (2*d+1) == 0) ans = n / (2*d+1);
    else ans = n / (2 * d + 1) + 1;
    
    cout << ans;
    
    return 0;
}



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

int main(void)
{
    int A, B;
    char op;
    cin >> A;
    cin >> op;
    cin >> B;
    if(op=='+')
        cout << A+B << endl;
    else if(op=='-')
        cout << A-B << endl;
}

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

int main() {
	int N, K; cin >> N >> K;
	vector<ll> a(N);
	for (int i = 0; i < N; ++i) { cin >> a[i]; }
	sort(a.begin(), a.end());

	int low = -1, high = N;
	int res;
	while (high - low != 1) {
		int mid = (high + low) / 2;

		vector<bool> dp(K, false);
		dp[0] = true;

		for (int i = 0; i < N; ++i) {
			if (i == mid) continue;
			if (a[i] >= K) continue;

			vector<bool> next(K, false);
			for (int j = 0; j < K; ++j) {
				next[j] = (next[j] | dp[j]);
				if (j - a[i] >= 0) {
					next[j] = (next[j] | dp[j - a[i]]);
				}
			}
			dp = next;
		}

		bool is_need = false;
		for (int sum = max(0LL, (ll)K - a[mid]); sum < K; ++sum) {
			if (dp[sum]) {
				is_need = true;
				break;
			}
		}

		if (is_need) { high = mid; }
		else { low = mid; }
	}

	cout << low + 1 << endl;
	return 0;
}


Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
int a[10];
int main()
{
     for(int i=1;i<=3;i++)
     cin>>a[i];
     sort(a+1,a+4);
     cout<<a[3]*10+a[1]+a[2]<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  OUT((n-1)/2);
}

Measured memory_bytes: 256
// @gaurav_512
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define bs(v,val) binary_search(v.begin(),v.end(),val)
#define mod 1e9+7
#define ff first
#define ss second
#define fi(n) for(int i=0;i<n;i++)
#define fj(n) for(int j=0;j<n;j++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define m_p make_pair
#define endl '\n'
 
ll power(ll x, ll y, ll p)
{  
    ll res = 1;
    x = x % p;  
    if (x == 0) return 0;
    while (y > 0){  
        if (y & 1)  res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p); 
}
// ********** CODE STARTS HERE ****************//
 
 
void solve()
{
	int n,k;
	cin>>n>>k;
	vi h(n);
	fi(n)cin>>h[i];
	vi dp(n,INT32_MAX);
	dp[0] = 0;
	for(int i=1; i<n; i++)
	{
		for(int j=1;j<=k;j++)
		{
			if(i<j)
				break;
			dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
		}
	}
//	fi(n)cout<<dp[i]<<' ';
	cout<<dp[n-1]<<endl;
}
int main()
{
	fastio;
    int T;
//    cin>>T;
//    while(T--)
        solve();
	return 0;
}

Measured memory_bytes: 3992
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n - 1); i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using priority_queuel = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T>
constexpr int sz(const T &a) { return (int)a.size(); }
template <class T>
constexpr T pow2(const T a) { return a * a; }
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class A, int N, class T>
void fillArray(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

string a;
ll dp[1000005][2];
void solve() {
    cin >> a;
    reverse(all(a));
    a += '0';
    fillArray(dp, inf);
    dp[0][0] = 0;
    rep(i, sz(a)) rep(j, 2) {
        int x = a[i] - '0' + j;
        if (x < 10) mins(dp[i + 1][0], dp[i][j] + x);
        if (x > 0) mins(dp[i + 1][1], dp[i][j] + (10 - x));
    }
    cout << min(dp[sz(a)][0], dp[sz(a)][1]) << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


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

using namespace std;

int main(void){
	int N,x;
	long long ans =0;
	cin >> N>>x;
	int a[N];
	for(int i=0;i<N;i++)cin >> a[i];
	for(int i=1;i<N;i++){
		if((a[i-1]+a[i])>x){
			ans +=	a[i-1]+a[i] -x;
			a[i] -= a[i-1]+a[i] -x;
			if(a[i]<0){
				a[i-1]-=abs(a[i]);
				a[i]=0;
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(){
	int w,n;
	scanf("%d%d", &w,&n);

	int h[w];
	for(int i=0;i<w;i++) h[i] = i+1;

	for(int i=0;i<n;i++){
		int a,b;
		scanf("%d,%d", &a,&b);
		h[a-1] += h[b-1];
		h[b-1] = h[a-1]-h[b-1];
		h[a-1] = h[a-1]-h[b-1];
	}

	for(int i=0;i<w;i++) printf("%d\n", h[i]);
}

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

int main() {
  int N;
  cin >> N;
  int a=N/100000000;
  int b=N%100000000/10000000;
  int c=N%100000000%10000000/1000000;
  int d=N%100000000%10000000%1000000/100000;
  int e=N%100000000%10000000%1000000%100000/10000;
  int f=N%100000000%10000000%1000000%100000%10000/1000;
  int g=N%100000000%10000000%1000000%100000%10000%1000/100;
  int h=N%100000000%10000000%1000000%100000%10000%1000%100/10;
  int i=N%100000000%10000000%1000000%100000%10000%1000%100%10;
  int sum=a+b+c+d+e+f+g+h+i;
  
  if (N%sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
	int n,m,i,j,flg;
	char s[100],t[100],x;
	scanf("%s",s);
	scanf("%s",t);
	n=strlen(s);
	m=strlen(t);
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(s[i]>s[j]){
				x=s[j];
				s[j]=s[i];
				s[i]=x;
			}
		}
	}
	for(i=0;i<m-1;i++){
		for(j=i+1;j<m;j++){
			if(t[i]<t[j]){
				x=t[j];
				t[j]=t[i];
				t[i]=x;
			}
		}
	}
	if(strcmp(s,t)<0){
		printf("Yes\n");	
	}
	else{
		printf("No\n");
	}
	return 0;
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;

constexpr int MOD = 1000000007;

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

    int n;
    cin >> n;

    vi a(n);
    rep(i, 0, n) { cin >> a[i]; }

    vector<vll> dp(n + 1, vll(n + 1, 0));

    rep(k, 1, n + 1) {
        rep(i, 0, n - k + 1) {
            bool first = (n + k) % 2 == 0;
            if (k == 1) {
                dp[i][i + k] = a[i] * (first ? 1 : -1);
            }
            else if (first) {
                dp[i][i + k] = max(dp[i + 1][i + k] + a[i], dp[i][i + k - 1] + a[i + k - 1]);
            } else {
                dp[i][i + k] = min(dp[i + 1][i + k] - a[i], dp[i][i + k - 1] - a[i + k - 1]);
            }
        }
    }

    cout << dp[0][n] << endl;
    return 0;
}

Measured memory_bytes: 70784
#include <iostream>
using namespace std;
using ll=long long;

int main(){
    ll N, K;
    cin >> N >> K;
    ll one;
    if((N - 1) % (K - 1) == 0) cout << (N - 1) / (K - 1) << endl;
    else cout << (N + K - 2) / (K - 1) << endl;
}

Measured memory_bytes: 256
<?php
while(1){
  list($n,$x)=explode(' ',trim(fgets(STDIN)));

  if(!$n) break;

  $ok=0;
  $ni=$n-2;
  $nj=$n-1;
  for($i=1;$i<=$ni;$i++)
    for($j=$i+1;$j<=$nj;$j++)
      for($k=$j+1;$k<=$n;$k++)
        if(($i+$j+$k)==$x) ++$ok;

  echo $ok,PHP_EOL;
}

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

using namespace std;

int main () {

  int a, b, c, d, e, k;
  bool ans = true;
  cin >> a >> b >> c >> d >> e >> k;

  int arr[] = { a, b, c, d, e };

  for (int i = 0; i < 5; i++) {
    for (int j = i + 1; j < 5; j++) {
      if (arr[j] - arr[i] > k) {
        ans = false;
        break;
      }
    }
  }

  if (ans) {
    cout << "Yay!" << endl; 
  } else {
    cout << ":(" << endl;
  }
  

  return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int d[2][10]={
	{20,19,20,19,20,19,20,19,20,19},
	{20,20,20,20,20,20,20,20,20,20}
};
int m[1000];
main()
{
	int n;
	cin>>n;
	for(int i=1000;--i;)
	{
		m[i]=m[i+1];
		for(int j=0;j<10;j++)m[i]+=d[i%3<1][j];
	}
	for(;n--;)
	{
		int Y,M,D;cin>>Y>>M>>D;
		int cnt=d[Y%3<1][M-1]-D+1;
		for(int i=M;i<10;i++)cnt+=d[Y%3<1][i];
		cout<<m[Y+1]+cnt<<endl;
	}
}



Measured memory_bytes: 3076