akhauriyash/Code-Regression huggingface dataset:
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll n,ans,sum,news;
void solve()
{
    cin>>n;ll ar[n];
    for(int i=0;i<n;i++)
    {cin>>ar[i];
        sum+=ar[i];}
    ans=sum;
    for(int i=0;i<n;i++)
    {
        news+=ar[i];
        ans=min(ans,abs(2*news-sum));
    }
    cout<<ans<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 9999999999;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define pb push_back
#define f first
#define s second
#define pi 3.141592653589793238
using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	
	ll k,s;
	cin>>k >> s;
	ll ans = 0;
	for(int i = 0;i<=k;i++)
	{
		for(int j =0;j<=k;j++)
		{
			ll sum = i+j;
			if(sum > s) continue;
			if((s-sum)<=k)ans++;
		}
	}
	cout << ans << endl;

	return 0;
}



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

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll n;
  cin >> n;
  set<ll> st;
  for(ll i = 1; i < 10; i++) {
  	for(ll j = 1; j < 10; j++) {
        st.insert(i*j);
  	}
  }
  if(st.find(n) != st.end()) cout << "Yes";
  else cout << "No";
  return 0;
} //good night.

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

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

    ll N, K;
    cin >> N >> K;

    vector<ll> V(N);
    rep (i, N) {
        cin >> V[i];
    }

    ll ans = 0;
    for (ll l = 0; l <= min(N, K); l++) {
        for (ll r = 0; r <= min(N, K)-l; r++) {
            ll num = K-l-r;
            vector<ll> tmp;
            ll point = 0;
            rep (i, l) {
                tmp.push_back(V[i]);
                point += V[i];
            }
            rep (i, r) {
                tmp.push_back(V[N-i-1]);
                point += V[N-i-1];
            }

            sort(tmp.begin(), tmp.end());

            for (ll i = 0; i < min(num, ll(tmp.size())); i++) {
                if (tmp[i] < 0) {
                    point -= tmp[i];
                } else {
                    break;
                }
            }

            ans = max(ans, point);
        }
    }

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

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

#define ll long long
#define MAXN 60
#define MAXM 110
using namespace std;
int N, M;
int S;

ll A[MAXM];
ll B[MAXM];
ll C[MAXN];
ll D[MAXN];


vector<pair<int, int> > e[MAXN];
pair<ll, ll> edges[MAXM];

ll min_time[MAXN][3000];

bool visited[MAXN][3000];

int u, v;

vector<int> path;

priority_queue<vector<ll> > q;


int main()
{
	cin>>N>>M>>S;
	for(int i = 1; i <= M; ++i)
	{
			cin>>u>>v>>A[i]>>B[i];
			e[u].push_back(make_pair(i, v));
			e[v].push_back(make_pair(i, u));
			edges[i] = make_pair(A[i], B[i]);
	}
	for(int i = 1; i <= N; ++i)
	{
			cin>>C[i]>>D[i];
	}
		ll high = 2800;
	for(int i = 1; i <= N; ++i)
	for(int j = 0; j <= high; ++j)
	{
			min_time[i][j] = (ll)(9223372036854775807LL);
			visited[i][j] = false;
	}
	if(S > high)
		S = high;
	q.push(vector<ll> {-0, -S, 1});
	min_time[1][S] = 0;
	while(!q.empty())
	{
		//cout<<"loop\n";
			auto vec = q.top();
			q.pop();
			ll time = -vec[0];
			ll coin = -vec[1];
			ll u = vec[2];
	
			coin = min(coin, high);
			if(min_time[u][coin] < time)
			{
					continue;
			}
			ll coin2 = coin;
			ll time2 = time;

			coin2 = coin2 + C[u];
			if(coin2 > high)
				coin2 = high;
			time2 += D[u];
			if(time2 < min_time[u][coin2])
			{
					min_time[u][coin2] = time2;
					q.push(vector<ll> {-time2, -coin2, u});
			}
			
			for(auto& p: e[u])
			{
					int index = p.first;
					int v = p.second;
					ll a = edges[index].first;
					ll b = edges[index].second;
					if(coin >= a)
					{
							ll coin2 = coin - a;
							ll time2 = time + b;
							if(time2 < min_time[v][coin2])
							{
								min_time[v][coin2] = time2;
								q.push(vector<ll> {-time2, -coin2, v});
							}
					}
			}
	}
	for(int i = 2; i <= N; ++i)
	{
			ll ans = (ll)(9223372036854775807LL);
			for(int j = 0; j <= high; ++j)
				ans = min(ans, min_time[i][j]);
			cout<<ans<<endl;
	}
	
	
	return 0;
}


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

int main(){

    int h,w;
    cin >> h>>w;
    vector<string> s(h+2);

    string t(w+2,'.');
    s[h+1]=t;
    s[0]=t;

    rep(i,h){
        cin >>s[i+1];
        s[i+1]='.'+s[i+1]+'.';
    }

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

    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(s[i][j]=='#'){
                for(int k=0;k<4;k++){
                    if(s[i+dy[k]][j+dx[k]]=='#'){
                        break;
                    }
                    if(k==3){
                        cout << "No" << endl;
                        return 0;
                    }
                }
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s=="AKIHABARA"||s=="AKIHABAR"||s=="AKIHABRA"||s=="AKIHBARA"||s=="KIHABARA"||s=="AKIHABR"||s=="AKIHBAR"||s=="KIHABAR"||s=="AKIHBRA"||s=="KIHABRA"||s=="KIHBARA"||s=="AKIHBR"||s=="KIHABR"||s=="KIHBAR"||s=="KIHBRA"||s=="KIHBR")cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
# import math
from string import ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    w = input()

    for ascii_char in ascii_lowercase:
        if w.count(ascii_char) % 2 != 0:
            print('No')
            exit()
    print('Yes')


if __name__ == "__main__":
    main()


Measured memory_bytes: 3768
def main():
    n, m, Q = map(int, input().split())
    Train= [[0 for _ in range(n)] for _ in range(n)]
    
    for i in range(m):
        l, r = map(int, input().split())
        l, r = l - 1, r - 1
        Train[l][r] += 1
    
    P_Train = [[0 for _ in range(n)] for _ in range(n)]
    for i in range(n):
        tmp = 0
        for j in range(n):
            tmp += Train[i][j]
            P_Train[i][j] = tmp

    for i in range(Q):
        p, q = map(int, input().split())
        p, q = p - 1, q - 1
        ans = solve(P_Train, n, p, q)
        print(ans)

def solve(P_Train, n, p, q):
    ans = 0
    for i in range(p, q + 1):
        if  p - 1 < 0:
            ans += P_Train[i][q]
        else:
            ans += P_Train[i][q] - P_Train[i][p - 1]
    return ans


if __name__ == '__main__':
    main()

Measured memory_bytes: 62680
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=3000+10,mod=1e9+7;
char s[maxn];
int dp[maxn][maxn],sum[maxn][maxn];
int main(){
	int n=read();
	scanf("%s",s+1);
	dp[1][1]=sum[1][1]=1;
	REP(i,2,n){
		if(s[i-1]=='<') REP(j,1,i) dp[i][j]=sum[i-1][j-1];
		else REP(j,1,i) dp[i][j]=(sum[i-1][i-1]-sum[i-1][j-1]+mod)%mod;
		REP(j,1,i) sum[i][j]=(sum[i][j-1]+dp[i][j])%mod;
	}
	printf("%d\n",sum[n][n]);
	return 0;
}


Measured memory_bytes: 69632
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
char p[201000];
long long res = 0, s;
int main() {
	int i;
	scanf("%s", p);
	for (i = 0; p[i]; i++) {
		if (p[i] == 'B')s++;
		else res += s;
	}
	printf("%lld\n", res);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pi pair<ll, ll>
#define mp make_pair
#define pb push_back
#define vi vector<ll>
#define pd pair<double, double>
#define vp vector<pi>
#define f(i, n) for(int i = 0; i < n; i++)
#define fo(i, a, n) for(int i = a; i < n; i++)
#define mod (1000*1000*1000+7)
#define sz(x) int((x).size())
#define all(x) x.begin(),x.end()
#define DBG(v) cerr << #v << " = " << (v) << endl;
ll INF = (1ll<<61);

using namespace std;

ll n, m;

vi dp(300000, -1);

ll fact(ll x){
  if(x == 0) return 1;
  if(dp[x] != -1) return dp[x];
  return dp[x] = (fact(x-1) * x)%m;
}

int main(int argc, char* argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin >>  n >> m;
    if(n==m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
int main() {
    int h,w;
    while (scanf("%d %d", &h, &w) && (h || w)) {
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (i == 0 || j == 0 || i == h - 1 || j == w - 1) printf("#");
                else printf(".");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2572
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ms(a,b) memset(a,b,sizeof(a))
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int maxn=1e6+10;
const int mod=1e9+7;
const int maxm=1e3+10;
using namespace std;
int main(int argc, char const *argv[])
{
    #ifndef ONLINE_JUDGE
       
        srand((unsigned int)time(NULL));
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    string mon;
    cin>>mon;
    int l=mon.length();
    vector<int>v(l+1,0);
    for(int i=l-1;i>=0;i--)
        v[l-1-i]=mon[i]-'0';
    int tot=0;
    for(int i=0;i<=l;i++)
    {
        int res=v[i];
        if(res>5)
        {
            tot+=(10-res);
            v[i+1]+=1;
        }
        else
        {
            if(res==5&&v[i+1]>=5)
                v[i+1]+=1;
            tot+=res;
        }
    }
    cout<<tot<<endl;
    #ifndef ONLINE_JUDGE
        cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s.\n";
    #endif
    return 0;
}

Measured memory_bytes: 5276
var
	i,a:Longint;
	ans:array[0..9]of Longint;
begin
	for i:=1 to 4 do begin
		read(a);
		inc(ans[a]);
	end;
	if(ans[1]>0)and(ans[4]>0)and(ans[7]>0)and(ans[9]>0)then begin
		writeln('YES');
	end else begin
		writeln('NO');
	end;
end.


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<double> x(n);
	vector<string> v(n);
	rep(i, n) cin >> x[i] >> v[i];
	double sum = 0;
	rep(i, n) {
		if (v[i] == "JPY") sum += x[i];
		else sum += x[i] * 380000;
	}
	printf("%.10f\n", sum);
	return 0;
}

Measured memory_bytes: 256
#import <stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int s = 0;
    for (int i=0;i<n;i++) {
        int a,b;
        scanf("%d %d",&a,&b);
        s += b-a+1;
    }
    printf("%d",s);
}


Measured memory_bytes: 4668
import sys

n, m, *xyz = map(int, sys.stdin.read().split())
xyz = zip(*[iter(xyz)] * 3)

root = list(range(n+1))
height = [0] * (n + 1)

sys.setrecursionlimit(10**7)
def find_root(v):
    u = root[v]
    if u == v:
        return u
    w = find_root(u)
    root[v] = w
    return w

def unite(u, v):
    ru = find_root(u)
    rv = find_root(v)
    if ru == rv:
        return
    if height[u] >= height[v]:
        root[rv] = ru
        height[ru] = max(height[ru], height[rv] + 1)
    else:
        root[ru] = rv

def main():
    for x, y, z in xyz:
        unite(x, y)
    
    for i in range(1, n+1):
        find_root(i)

    return len(set(root[1:]))

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 32172
<?php
fscanf(STDIN, "%d %d %d %d %d", $H1, $M1, $H2, $M2, $K);
$up = $H1*60 + $M1;
$down = $H2*60 + $M2;
$answer = $down - $up - $K;
print_r ($answer);
?>

Measured memory_bytes: 16144
a,b,c = input().split()
nums = []
nums.append(a)
nums.append(b)
nums.append(c)

nums = list(map(int,nums))

nums.sort()
count = 0

while(not (nums[0]==nums[1] and nums[1]==nums[2])):
	if(nums[1] == nums[0]):
		sa = nums[2]-nums[1]
		nums[1] += sa
		nums[0] += sa
		count += sa
		break
	elif(nums[1] - nums[0] >= 2):
		nums[0] += 2
		count += 1
		nums.sort()

	elif(nums[1] - nums[0] ==1):
		sa = nums[2] - nums[1]
		nums[1] += sa
		nums[0] += sa
		count += sa
		nums[0] += 2
		count += 1
		nums.sort()

print(count)

Measured memory_bytes: 3064
//g++ main.cpp -I /usr/local/include/ac-library
#include<cmath>
#include <atcoder/all>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
using namespace atcoder;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ll n,d;
    cin >> n>> d;
    ll x[n],y[n];
    rep(i,n){
        cin >> x[i]>> y[i];
    }
    two_sat ts(n);
    rep(i,n){
        for(int j=i+1;j<n;j++){
            ll pat1=abs(x[i]-x[j]);
            ll pat2=abs(x[i]-y[j]);
            ll pat3=abs(y[i]-x[j]);
            ll pat4=abs(y[i]-y[j]);
            if(pat1<d)ts.add_clause(i,true,j,true);
            if(pat2<d)ts.add_clause(i,true,j,false);
            if(pat3<d)ts.add_clause(i,false,j,true);
            if(pat4<d)ts.add_clause(i,false,j,false);
        }
    }
    if(ts.satisfiable()){
        cout<<"Yes"<<endl;
        vector<bool> v=ts.answer();
        rep(i,v.size()){
            if(!v[i])cout<<x[i]<<endl;
            else cout<<y[i]<<endl;
        }
    }
    else cout<< "No"<<endl;
    return 0;
}

Measured memory_bytes: 3724
fun main(arr: Array<String>) {
    println(if(getAns()) "Yes" else "No")
}

fun getAns():Boolean {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val pict = (1..n).map { readLine()!! }
    val template = (1..m).map { readLine()!! }

    for(i in (0 .. (n-m))) {
        for(j in (0 .. (n-m))) {
            var isMatch = true
            for(r in template.indices) {
                for(c in template.indices) {
                    if(template[r][c] != pict[r+i][c+j]) {
                        isMatch = false
                        break
                    }
                }
                if(!isMatch) {
                    break
                }
            }
            if(isMatch) {
                return true
            }
        }
    }
    return false
}

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

ll gcd(ll x, ll y) {
  if (x > y) swap(x,y);
  if (x == 0) return y;
  else if (y % x == 0) return x;
  else return gcd(y % x,x);
}

int main() {
  ll A,B;
  cin >> A >> B;
  ll C = gcd(A,B);
  ll count = 1;
  for (ll i = 2; i * i <= gcd(A,B); i++) {
    if (C % i == 0) {
      count++;
      while (C % i == 0) C /= i;
    }
  }
  if (C != 1) count++;
  
  cout << count << endl;  
}

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

int main() {
  int K;
  cin >> K;
  int A[32] = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
               1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << A[K - 1] << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const int INF = 1000000007;
string S;
string d[4] = {"maerd", "remaerd", "esare", "resare"};

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

  cin >> S;
  string T = "";
  rep_down(i, S.size()){
    T.push_back(S[i]);
  }
  bool flag = true;
  while(flag){
    if (!T.size()) break;
    rep(i, 4){
      string s = d[i];
      flag = true;
      rep(j, s.size()){
        if (T[j] != s[j]){
          flag = false;
          break;
        }
      }
      if (flag){
        T = T.substr(s.size());
        break;
      }
    }
    if (!flag) {
      cout << "NO" << "\n";
      return 0;
    }
  }

  cout << "YES" << "\n";
  return 0;
}

Measured memory_bytes: 592
#include<stdio.h>

int main(void) {
  int as, bs;
  int ae, be;
  int result = 0;

  scanf("%d%d%d%d",&as, &ae, &bs, &be);

  if(as <= bs && bs <= ae) {
    if(be <= ae) {
      result = be - bs;
    } else {
      result = ae - bs;
    }
  } else if(bs <= as && as <= be) {
    if(ae <= be) {
      result = ae - as;
    } else {
      result = be - as;
    }
  }

  printf("%d\n", result);

  return 0;
}

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

int main() {
  int N, x; cin >> N >> x;
  vector<ll> a(N); for (int i = 0; i < N; ++i) cin >> a[i];
  ll ans = 0;
  for (int i = 1; i < N; ++i) {
    ll diff1 = max(0ll, a[i - 1] + a[i] - x);
    a[i] = max(0ll, a[i] - diff1);
    ll diff2 = max(0ll, a[i - 1] + a[i] - x);
    a[i - 1] = max(0ll, a[i - 1] - diff2);
    ans += diff1;
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
    deque<int> A;
    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int command;
        cin >> command;
        if (command == 0)
        {
            int d, x;
            cin >> d >> x;
            if (d)
            {
                A.push_back(x);
            }
            else
            {
                A.push_front(x);
            }
        }
        if (command == 1)
        {
            int p;
            cin >> p;
            cout << A[p] << endl;
        }

        if (command == 2)
        {
            int d;
            cin >> d;
            if (d)
            {
                A.pop_back();
            }
            else
            {
                A.pop_front();
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4668
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N,Z,W;
  cin >> N >> Z >> W;
  vi A(N);
  rep(i,N) {
    cin >> A[i];
  }
  if(N==1) {
    cout << abs(W-A[0]) << endl;
  } else {
    cout << max(abs(W-A[N-1]),abs(A[N-1]-A[N-2])) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)


#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int Q;
const int MAX_Q = 200000;

int main(){
  cin >> Q;

  int q;
  ll a, b;

  cin >> q >> a >> b;

  ll s = b;
  priority_queue<ll> fro;
  priority_queue<ll, vector<ll>, greater<ll>> bac;
  fro.push(a);
  bac.push(a);
  bool odd = true;

  REP(i, Q - 1) {
    cin >> q;
    if(q == 1) {
      cin >> a >> b;
      fro.push(a);
      bac.push(a);

      ll ft = fro.top(), bt = bac.top();
      if(ft > bt) {
        fro.pop();
        bac.pop();
        fro.push(bt);
        bac.push(ft);
        s += ft - bt;
      }
      s += b;
    } else {
      cout << fro.top() << " " << s << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 4588
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;



int main(){
    int a,b;
    cin >> a >> b;
    if(b<a) out(a-1);
    else out(a);    
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int a, b, c;
	
	scanf("%d%d", &a, &b);
	for (c = 1; c <= 3; c++)
		if (a * b * c % 2) {
			printf("Yes\n");
			return 0;
		}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

int n;
int main() {
    cin >> n;
    int mi = n;
    int ans = 0;
    REP(i, n) {
        int a; 
        cin >> a;
        if(mi >= a) ans++;
        mi = min(mi, a);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    ll n; cin>>n;
    vector<bool> can(n+1);
    can[1] = 1;
    for(int i=2; i<=n; i++) {
        ll x = i*i;
        while(x<=n) {
            can[x] = 1;
            x *= i;
        }
    }
    for(int i=n; i>=-1; i--) {
        if(can[i]) {
            cout<<i;
            return 0;
        }
    }
}

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

using namespace std;
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define N 100010
ll f[N],cop[N],n,k;
int main(){
    cin>>n>>k;
    for(int i=0;i<=k;i++)f[i]=0; f[0]=1;
    while(n--){
     ll a;cin>>a;
     ll sum=0;
     for(int i=0;i<=k;i++){
         sum+=f[i];
         if(i-a-1>=0)sum-=f[i-a-1];
         sum%=mod;
         cop[i]=sum;
     }
     for(int i=0;i<=k;i++)f[i]=cop[i];
    }
    ll ans=f[k];
    if(ans<0)ans+=mod;
    cout<<ans<<endl;
 return 0;   
}

Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<queue>

using namespace std;

typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;

#define mp make_pair
#define pb push_back

#define repp(i,a,b) for(int i=(int)(a);i<=(int)(b);++i)
#define rep(i,n) repp(i,0,(n)-1)

int in(){int a; scanf("%d",&a); return a;}
int h,n,p,m,k;

int b[600];
double dp[2][110][110];

int main(){
	cin>>h>>n>>p>>m>>k;
	p--;
	rep(i,h)b[i]=-1;
	rep(i,m){
		int hoge=in(); int fuga=in();
		hoge--;fuga--;
		b[hoge] = fuga;
	}
	repp(i,0,k)repp(j,0,n)dp[0][i][j]=dp[1][i][j]=0;
	dp[0][0][p]=1;
	int x=0;
	for(int i=h-1;i>=0;i--){
		if(b[i]!=-1){
//cout<<" "<<i<<" "<<b[i]<<endl;
			repp(j,0,k)rep(t,n){
				if(t==b[i])dp[1][j][t]=dp[0][j][t+1];
				else if(t==b[i]+1)dp[1][j][t]=dp[0][j][t-1];
				else dp[1][j][t]=dp[0][j][t];
			}
		}
		else {
			x++;
			repp(j,0,k)rep(t,n)dp[1][j][t]=0;
			rep(j,k){
				rep(t,n){
					dp[1][j+1][t]=dp[0][j][t]*(1-(j+1<=x?x>0?1-(double)(j+1)/x:1:0));
				}
				rep(s,n-1){
					dp[1][j+1][s]-=dp[0][j][s]/(n-1)*(1-(j+1<=x?x>0?1-(double)(j+1)/x:1:0));
					dp[1][j+1][s]+=dp[0][j][s+1]/(n-1)*(1-(j+1<=x?x>0?1-(double)(j+1)/x:1:0));
					dp[1][j+1][s+1]-=dp[0][j][s+1]/(n-1)*(1-(j+1<=x?x>0?1-(double)(j+1)/x:1:0));
					dp[1][j+1][s+1]+=dp[0][j][s]/(n-1)*(1-(j+1<=x?x>0?1-(double)(j+1)/x:1:0));
				}
			}
			repp(j,0,k){
				rep(t,n){
					dp[1][j][t]+=dp[0][j][t]*(j<=x?x>0?1-(double)j/x:1:0);
				}
			}
		}
		repp(j,0,k){
			rep(t,n){
//cout<<dp[1][j][t]<<" ";
				dp[0][j][t]=dp[1][j][t];
			}
//cout<<endl;
		}
//cout<<endl;

	}
	double result=0;
	repp(i,0,n)if(result<dp[0][k][i])result=dp[0][k][i];
	printf("%.12f\n",result);
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#define rep(i,rept)	for(int i = 0; i<(ll)rept;++i)
typedef long long ll;
using namespace std;

int main() {

	int h = 0, w = 0;
	cin >> h >> w;

	int a[25][25] = {};

	rep(i, h) {
		rep(j, w) {
			cin >> a[i][j];
		}
	}

	int count = 0, ans = 1e+9;

	rep(i, h) {
		rep(j, w) {


			rep(k, h) {
				rep(l, w) {
					count += std::min(abs(k - i) * a[k][l], abs(l - j) * a[k][l]);
				}
			}

			ans = std::min(count, ans);
			count = 0;
		
		}
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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 inf = 1001001001;
const ll linf = 1001001001001001001;

int n;
vi a;
vvi tree;
vi ans;

P dfs(vi& dp,int v = 0,int p = -1,int cnt = 0) {
    int f,s;
    int now = a[v];
    if(cnt == 0 || dp[cnt-1] < now) {
        f = cnt;
        s = inf;
        dp[cnt] = now;
        cnt++;
    } else {
        auto it = lower_bound(all(dp),now);
        f = it-dp.begin();
        s = *it;
        *it = now;
    }
    ans[v] = cnt;
    for(int i : tree[v]) {
        if(i == p) continue;
        auto np = dfs(dp,i,v,cnt);
        dp[np.first] = np.second;
    }
    return make_pair(f,s);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin >> n;
    a.resize(n);
    cin >> a;
    tree.resize(n);
    rep(i, n-1) {
        int u,v;
        cin >> u >> v;
        u--; v--;
        tree[u].pb(v);
        tree[v].pb(u);
    }
    ans.resize(n);
    vi v(n,inf);
    dfs(v);
    rep(i,n) cout << ans[i] << endl;
}

Measured memory_bytes: 30752
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a,b,c = inpl()
for i in range(100000):
    if (c + b*i) % a == 0:
        print('YES')
        break
else:
    print('NO')

Measured memory_bytes: 38512
#include<stdio.h>

int main() {
	long long a, b, i;
	while(scanf("%lld%lld",&a,&b)!=EOF) {
		if(a%b==0) {
			printf("-1\n");
			continue;
		}
		else {
			for(i=2;;i++) {
				if((i*a)%b!=0) {
					printf("%lld\n",i*a);
					break;
				}
			}
		}
	}
}

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

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

	string s;
	int k;
	cin >> k >> s;
	if (s.length() <= k)
		cout << s << endl;
	else {
		cout << s.substr(0, k) << "..." << endl;
	}
}

Measured memory_bytes: 3616
double n,p[333][333][333],r;
c[4];
f(i,j,k,I){I=i+j+k;r=p[i][j][k]?:(p[i][j][k]=(i*(i?f(i-1,j,k),r+n/I:0)+j*(j?f(i+1,j-1,k),r+n/I:0)+k*(k?f(i,j+1,k-1),r+n/I:0))/I);}
main(a)
{
	for(***p=1;~scanf("%d",&a);)!n?n=a:c[a]++;
	printf("%.9f",r-1,f(c[1],c[2],c[3]));
}

Measured memory_bytes: 260224
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define out(s) cout << s << endl

int main(){
    int x,t;cin >> x >> t;
    int f=x-t;
    if(f<0)f=0;
    cout << f << endl;
    return 0;
}



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

using namespace std;

#define LOCAL
#define all(a) begin(a), end(a)
#define MOD 1000000007
#define PII pair<int, int>
#define REP(x, l, u) for(ll x = l;x<u;x++)
#define RED(x, l, u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(begin(a),end(a)),end(a))
#define mst(x, a) memset(x,a,sizeof(x))
typedef vector<int> VI;
typedef long long ll;

ll quick_pow(ll a, ll b) {
    long long res = 1;
    while (b) {
        if (b & 1) { res = a * res; }
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll gcd(ll a, ll b) {
    a = abs(a), b = abs(b);
    while (b != 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

bool is_prime(int n) {
    if (n == 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    int j = sqrt(n);
    for (int i = 2; i <= j; ++i) {
        if (n % i == 0) return false;
    }
    return true;
}

ll reverse_num(ll n) {
    ll x = 0, t = n;
    while (t != 0) {
        x = x * 10 + t % 10;
        t /= 10;
    }
    return x;
}

// TO-DO
// contest required
#ifdef LOCAL


void solve() {
    int n, t;
    cin >> n;
    int res = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> t;
        if (i % 2 == 1 && t % 2 == 1) res++;
    }
    cout << res;
}

int main() {
    // 加速输入和输出
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
    return 0;
}

#endif

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<utility>
#include<map>
#include<algorithm>
using namespace std;

int main() {
	int N, T;
	cin >> N >> T;

	vector<int> C;

	for (int i = 0; i < N; i++) {
		int c, t;
		cin >> c >> t;

		if (t > T)continue;

		C.push_back(c);
	}

	sort(C.begin(), C.end());

	if (C.size() == 0)cout << "TLE" << endl;
	else cout << C[0] << endl;


}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  vec h(n);
  for(ll i=0;i<n;i++) cin >> h[i];
  for(ll i=n-2;i>-1;i--) {
    if(h[i]>h[i+1]) h[i]--;
  }
  ll f=1;
  for(ll i=0;i<n-1;i++) {
    if(h[i]>h[i+1]) f=0;
  }
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>

using namespace std;

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

    const int NUM = str.length();
    vector<string> vs(NUM);
    for(int i=0;i<NUM;i++){
        vs[i] = str.substr(i,1);
    }
    for(int i=0;i<(1<<(NUM-1));i++){
        int sum = stoi(vs[0]);
        string ans;
        ans.push_back(str[0]);
        for(int j=0;j<(NUM-1);j++){
            if((i>>j)%2==0){
                sum += stoi(vs[j+1]);
                ans.push_back('+');
                ans.push_back(str[j+1]);
            }else{
                sum -= stoi(vs[j+1]);
                ans.push_back('-');
                ans.push_back(str[j+1]);
            }
        }
        if(sum == 7){
            cout << ans + "=7" << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 101
#define maxk 100001
#define mod 1000000007
using namespace std;

int n,k;
int ar[maxn];
int dp[maxn][maxk];
int sum[maxn][maxk];

int main() {
	scanf("%d%d",&n,&k);
	for( int i = 1 ; i <= n ; i++ )
		scanf("%d",&ar[i]);
	dp[0][0] = 1;
	for( int i = 0 ; i <= k ; i++ )
		sum[0][i] = 1;
	for( int i = 1 ; i <= n ; i++ ) {
		for( int j = 0 ; j <= k ; j++ ) {
			int l = max(j-ar[i], 0);
			dp[i][j] = sum[i-1][j];
			if(l > 0)
				dp[i][j] = ( dp[i][j] + mod - sum[i-1][l-1] ) % mod;
		}
		sum[i][0] = dp[i][0];
		for( int j = 1 ; j <= k ; j++ )
			sum[i][j] = ( sum[i][j-1] + dp[i][j] ) % mod;
	}
	printf("%d\n",dp[n][k]);
	return 0;
}


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

typedef long long int ll;
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)

int H, W;
int Ch, Cw;
int Dh, Dw;
char Map[1001][1001];
int dy[20] = { -2, -2, -2, -2, -2,
				-1, -1, -1, -1,
				0, 0,
				1, 1, 1, 1,
				2, 2, 2, 2, 2 };
int dx[20] = { -2, -1, 0, 1, 2,
				-2, -1, 1, 2,
				-2, 2,
				-2, -1, 1, 2,
				-2, -1, 0, 1, 2 };
int dy2[4] = { -1, 1, 0, 0 };
int dx2[4] = { 0, 0, -1, 1 };
int visited[1001][1001] = { 0, };

int BFS() {
	priority_queue<pair<int, pair<int, int>>> pq;
	pq.push({ 0, {Ch, Cw} });
	visited[Ch][Cw] = 1;
	while (!pq.empty()) {
		int y = pq.top().second.first;
		int x = pq.top().second.second;
		int cnt = -pq.top().first;
		pq.pop();
		if (y == Dh && x == Dw)
			return cnt;
		FOR(i, 0, 3) {
			int ny = y + dy2[i];
			int nx = x + dx2[i];
			if (ny < 1 || nx < 1 || ny > H || nx > W) continue;
			if (Map[ny][nx] == '#') continue;
			if (visited[ny][nx] == 1) continue;
			visited[ny][nx] = 1;
			pq.push({ -cnt, {ny, nx} });
		}
		FOR(i, 0, 19) {
			int ny = y + dy[i];
			int nx = x + dx[i];
			if (ny < 1 || nx < 1 || ny > H || nx > W) continue;
			if (Map[ny][nx] == '#') continue;
			if (visited[ny][nx]) continue;
			visited[ny][nx] = 2;
			pq.push({ -(cnt + 1), {ny, nx} });
		}
	}
	return -1;
}

int main() {
	FASTIO;
	cin >> H >> W;
	cin >> Ch >> Cw;
	cin >> Dh >> Dw;
	FOR(i, 1, H) {
		FOR(j, 1, W) {
			cin >> Map[i][j];
		}
	}
	cout << BFS();

	return 0;
}

Measured memory_bytes: 8640
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if ((a * b) % 2 == 0)
            System.out.println("Even");
        else
            System.out.println("Odd");
    }
}

Measured memory_bytes: 35676
#include <cstdio>
#include <cmath>


int main(){
	int n;
	scanf("%d",&n);
	int ans;
		ans = 1;	
		for(int i = 2;i <= (int)sqrt(n + 0.5) + 1;i++){
			for(int j = 1;pow(i,j) <= n;j++){
				if(pow(i,j) >= ans) ans = pow(i,j);
			}
		}
			printf("%d",ans);
	


	return 0;
}






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

int h,w;

int main(){
	while( cin >> h >> w ){
		if(!h)break;
		
		int i,j;
		int ansh = 200,answ = 200;
		for( i = 1; i < 200; i++ ){
			for( j = i+1; j < 200; j++ ){
				if( (h*h+w*w < i*i+j*j) || (h*h+w*w == i*i+j*j && h < i) ){
					//ansh,answより小さいものなら更新
					if( (ansh*ansh+answ*answ > i*i+j*j) || (ansh*ansh+answ*answ == i*i+j*j && ansh > j) ){
						ansh = i;
						answ = j;
					}
				}
			}
		}
		cout << ansh << " " << answ << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    map<int,int> mp_d;
    rep(i,n) {
        int x; cin >> x;
        mp_d[x]++;
    }
    int m; cin >> m;
    map<int,int> mp_t;
    rep(i,m) {
        int x; cin >> x;
        mp_t[x]++;
    }
    bool ok = true;
    for (P p : mp_t) {
        if (mp_d[p.first] < p.second) ok = false;
    }
    if (ok) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 22280
#include<iostream>

using namespace std;

char c[100][100];

int main(){
	int n, m; cin >> n >> m;
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cin >> c[i][j];
		}
	}
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if(c[i][j] == '.'){
				int cnt = 0;
				if(c[i + 1][j] == '#') cnt++;
				if(c[i][j + 1] == '#') cnt++;
				if(c[i - 1][j] == '#') cnt++;
				if(c[i][j - 1] == '#') cnt++;
				if(c[i + 1][j + 1] == '#') cnt++;
				if(c[i - 1][j - 1] == '#') cnt++;
				if(c[i + 1][j - 1] == '#') cnt++;
				if(c[i - 1][j + 1] == '#') cnt++;
				
				c[i][j] = char(cnt + 48);
			}
		}
	}
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cout << c[i][j];
		}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
n, k = map(int, input().split())
a = list(map(int, input().split()))

now = 1
# for i in range(k):
#     now *= a[i]
# before = now

for i in range(n - k):
    # now *= a[i + k]
    # now /= a[i]
    if a[i] < a[i + k]:
        print('Yes')
    else:
        print('No')
    # before = now


Measured memory_bytes: 31756
def resolve():
    N,M = map(int,input().split())
    if N % 2 == 1:
        for i in range(M):
            print(str(i+1) + " " + str(N-i))
    else:
        for i in range((M-1) // 2 + 1):
            print(str(i+1) + " " + str(N-i))
        for i in range((M-1) // 2 + 1 , M):
            print(str(i+1) + " " + str(N-i-1))
resolve()

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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef pair<int,int> P;

int main(){
    ll n,a,t;
    cin >> n;
    a=1;
    t=1;
    lrp(i,n){
        ll T,A;
        cin >> T >> A;
        ll m=max((t-1+T)/T,(a-1+A)/A);
        t=m*T;
        a=m*A;
    }
    cout << a+t << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
#define pb push_back
#define MAX 10000005
#define mod 1000000007
#define sp fixed<<setprecision(12)
using namespace std;
/*
vector<int> primes;
ll sumprime[MAX];
bool is_prime[MAX];
void sieve(){
    is_prime[0]=is_prime[1]=true;
    for(int i=4;i<MAX;i+=2){
        is_prime[i]=true;
    }
    for(int i=3;i*i<MAX;i+=2){
        if(!is_prime[i]){
            for(int j=i*i;j<MAX;j+=i){
                is_prime[j]=true;
            }
        }
    }
    for(int i=0;i<MAX;i++){
        if(!is_prime[i]){
            sumprime[i]=sumprime[i-1]+i;
        }else{
            sumprime[i]=sumprime[i-1];
        }
    }
}
*/


using namespace std;
int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    //double    pi=3.14159265358979323846;
    //sieve();
    int t=1;
    //cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        int a[n];
        int dp[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        dp[0]=0;
        //dp[1]=abs(a[1]-a[0]);
        for(int i=1;i<n;i++){
            dp[i]=INT_MAX;
            for(int j=i-1;j>=0 and j>=(i-k);j--){
                dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
            }
        }
        cout<<dp[n-1]<<'\n';

    }
    
    
    
    
    
    return 0;
    
}

Measured memory_bytes: 4392
#include <iostream>
#include <vector>
#include <unordered_map>

using ull = unsigned long long;

struct UnionFindWithSize {
  std::vector<size_t> par;
  std::unordered_map<size_t, ull> num_conn;

  UnionFindWithSize(size_t N) : par(), num_conn() {
    par.reserve(N);
    for (size_t i=0; i<N; i++) {
      par.push_back(i);
      num_conn.insert(std::make_pair(i, 1));
    }
  }

  size_t root(size_t x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }

  bool same(size_t x, size_t y) {
    return root(x) == root(y);
  }

  ull size(size_t x) {
    return num_conn[root(x)];
  }

  void unite(size_t x, size_t y) {
    size_t root_x = root(x);
    size_t root_y = root(y);
    if (root_x == root_y) return;

    par[root_y] = root_x;
    num_conn[root_x] += num_conn[root_y];
    num_conn.erase(root_y);
  }
};

int main() {
  size_t N, M;
  std::cin >> N >> M;

  std::vector<std::pair<size_t, size_t>> Edges;
  Edges.reserve(M);

  for (size_t i=0; i<M; i++) {
    size_t a, b;
    std::cin >> a >> b;
    Edges.push_back(std::make_pair(a-1, b-1));
  }

  UnionFindWithSize uf(N);
  std::vector<ull> ans;
  ans.reserve(M+1);

  ans.push_back(N * (N-1) / 2);

  for (auto i=Edges.crbegin();
       i!=Edges.crend();
       i++) {
    auto a = ans.back();

    auto v0 = i->first;
    auto v1 = i->second;

    if (uf.same(v0, v1)) {
      ans.push_back(a);
    } else {
      auto s0 = uf.size(v0);
      auto s1 = uf.size(v1);

      ans.push_back(a - s0 * s1);
      uf.unite(v0, v1);
    }
  }

  ans.pop_back();

  for (auto i=ans.crbegin(); i != ans.crend(); i++) {
    std::cout << *i << '\n';
  }

  return 0;
}


Measured memory_bytes: 8612
#include <stdio.h>

int main(void) {
	
	int a=1;
	int b;
	do{
		b=1;
		do{
			printf("%dx%d=%d\n",a,b,a*b);
	        b++;
		}while(b<10);
		
	a++;
	}while(a<10);
	
	return 0;
}

Measured memory_bytes: 520