akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <regex>

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<ll>;
using vpii = vector<pii>;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rFOR(i,a,b) for(int i=(b);i>=(a);i--)
#define SORT(a) sort((a).begin(),(a).end());
#define rSORT(a) sort((a).rbegin(),(a).rend());
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;

//sankou
//vvi = vector<vector<int>>(20, vector<int>(10, 0));

//seiki
//#include <regex>
/*bubun*/
//regex_search("u32", regex("[0-9]"));      // true
/*kanzen*/
//regex_match("u32", regex("(i|u)\\d+"));   // true

int isP(int n) {
    if(n<=1) return 0;
    FOR(i,2,(int)sqrt(n)) {
        if(n%i==0) return 0;
    }
    return 1;
}

int main() {

    int a,b,c,d;
    cin >>a>>b>>c>>d;
    
    Yn((abs(a-c)<=d)||((abs(a-b)<=d)&&(abs(b-c)<=d)));

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;
/*
const ll int nax = 1e18;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,k;
    for (int i = 0; i < 5; ++i)
    {
        cin>>a;
        if(a==0)k = i+1;
    }
    cout<<k;
    return 0;
}
*/
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x,y;
    cin>>x>>y;
    if((2*x) < y && y < (4*x)){
        y = y - (2*x);
        if(y % 2 == 0){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }
    }
    else if(y == (2*x)){
        cout<<"Yes\n";
    }
    else if(y == (4*x)){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 3648
//abc160_c.cpp
//Sat Mar 28 21:06:02 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

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

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

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

	int distance[n];
	for (int i=0;i<n-1;i++){
		distance[i] = a[i+1]-a[i];
	}
	distance[n-1]=a[0]+(k-a[n-1]);
	sort(distance,distance+n,greater<int>());
	cout << k-distance[0] << endl;

}

Measured memory_bytes: 1920
h,w,K=map(int,input().split())
def two(x):
	return "0"*(w-1-len(bin(x)[2:]))+bin(x)[2:]
dp=[[0]*w for _ in range(h+1)]
dp[0][0]=1
mod=10**9+7
for i in range(h):
	for j in range(2**(w-1)):
		r=two(j)
		f=1
		for k in range(w-2):
			if r[k]==r[k+1]=="1":
				f=0
				break
		if f:
			for k in range(w):
				if k+1<w:
					if r[k]=="1":
						dp[i+1][k+1]+=dp[i][k]
						dp[i+1][k+1]%=mod
						continue
				if k>0:
					if r[k-1]=="1":
						dp[i+1][k-1]+=dp[i][k]
						dp[i+1][k-1]%=mod
						continue
				dp[i+1][k]+=dp[i][k]
				dp[i+1][k]%=mod
print(dp[h][K-1])



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

vector< string > split(string str, string del){
  char *p, *str_buff = new char[str.size() + 1], first = 0;
  vector< string > ret;
  strcpy( str_buff, str.c_str());
  while(p = strtok((first++ ? NULL : str_buff), del.c_str())){
    ret.push_back(p);
  }
  delete str_buff;
  return ret;
}

int main(){
  string s;
  getline( cin, s);
  vector< string > ans = split( s, " ,.");
  vector< string > ret;
  for(int i = 0; i < ans.size(); i++){
    if(ans[i].size() >= 3 && ans[i].size() <= 6) ret.push_back(ans[i]);
  }
  for(int i = 0; i < ret.size(); i++){
    cout << ret[i] << " \n"[i == ret.size() - 1];
 }
}

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

int main() {
	int n;
	cin >> n;
	vector<int> H;
	rep(i, n) {
		int h;
		cin >> h;
		H.push_back(h);
	}
	
	int dp[100009];
	rep(i, 100009) dp[i] = 100000;
	dp[0] = 0;
	for (int i = 1; i < n; ++i) {
		if (i == 1) dp[i] = dp[0] + abs(H[1] - H[0]);
		else {
			int A = dp[i - 1] + abs(H[i] - H[i - 1]);
			int B = dp[i - 2] + abs(H[i] - H[i - 2]);
			dp[i] = min(A, B);
		}
	}
	cout << dp[n-1];
}

Measured memory_bytes: 1144
#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,m;
  cin >> n >> m;
  ll l=(m+1)/2;
  ll r=l+1;
  for(ll i=0;i<(m+1)/2;i++) {
    cout << l << " " << r << endl;
    l--;
    r++;
  }
  l=r;
  r=l+(m-(m+1)/2)*2;
  for(ll i=(m+1)/2;i<m;i++) {
    cout << l << " " << r << endl;
    l++;
    r--;
  }
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
int main(){
 int a,b,c;
cin>>a>>b>>c;
cout<<(a-b)%c;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
    long long N, T;
    cin >> N >> T;
    vector<long long> A(N);
    long long m;
    long long p = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (i == 0) {
            m = A[i];
        }
        else {
            p = max(p, (A[i]-m)*(T/2));
            m = min(m, A[i]);
        }
    }
    p /= T/2;
    map<long long, vector<int>> mp;
    for (int i = 0; i < N; i++) {
        mp[A[i]].push_back(i);
    }
    map<long long, int> mm;
    for (int i = 0; i < N; i++) {
        if (mp.find(A[i]+p) != mp.end()) {
            auto j = mp[A[i]+p].end() - upper_bound(mp[A[i]+p].begin(), mp[A[i]+p].end(), i);
            mm[A[i]+p] += j;
            mm[A[i]] += 1;
        }
    }
    long long ans = 0;
    for (auto x: mm) {
        if (mm.find(x.first - p) == mm.end()) {
            vector<int> v;
            long long i = x.first;
            while (mm.find(i) != mm.end()) {
                v.push_back(mm[i]);
                i += p;
            }
            int a = 0, b = 0;
            for (int i = 0; i < v.size(); i += 2) {
                a += v[i];
            }
            for (int i = 1; i < v.size(); i += 2) {
                b += v[i];
            }
            ans += min(a, b);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 18176
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

N = int(input())
h = list(map(int,input().split()))

c2 = 0
c1 = abs(h[1] - h[0])
now = c1
for i in range(2,N):
    now = min(c2 + abs(h[i-2] -h [i]),  c1 +abs(h[i-1] -h [i]))
    c2 = c1
    c1 = now
print(now)


Measured memory_bytes: 38832
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << x << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  rep (i, n) cin >> a[i];
  multiset<int> nowset;
  rep (i, n) {
    auto itr = nowset.lower_bound(a[i]);
    if (itr != nowset.begin()) nowset.erase(--itr);
    nowset.insert(a[i]);
  }
  cout << nowset.size() << endl;
  return 0;
}

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

//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<string> &s, string a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;


int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;

    int l = 0;
    for (int i = 0; i <= s.size(); i++) {
        string a = s.substr(t.size() - i);
        string b = t.substr(0, i);
        if (a == b) {
            l = i;
        }
    }

    int now = s.size() + t.size() - l;
    max(now, n);

    cout << now << endl;
}


Measured memory_bytes: 256
import math

K = int(input())

GCD=[[0]*201]*201

A=0
#for i in range(1,K+1):
#    for j in range(1,K+1):
#        GCD[i][j]=math.gcd(i,j)
#        print(i,j,GCD[i][j])

for i in range(1,K+1):
    for j in range(1,K+1):
        t=math.gcd(i,j)
        for k in range(1,K+1):
#            t = GCD[i][j]
#            A += GCD[t][k]
#            print(i,j,k,t,GCD[t][k])
            A+=math.gcd(t,k)

print(A)
        

Measured memory_bytes: 67636
#include <bits/stdc++.h>
using namespace std;
int N=100010;
int main()
{
	int a[N]={0};
	int n;
	cin >> n;
	int b[n+10];
	for(int i=0;i<n;i++)
	{
		scanf("%d",&b[i]);
	}
	for(int i=0;i<n;i++)
	{
		a[b[i]+1]++;
		a[b[i]]++;
		a[b[i]-1]++;
	}
	int p=0;
	for(int i=0;i<N;i++)
		if(a[i]>p)p=a[i];
	cout << p <<endl;
}

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

const int MOD = 1000000007;

int main() {
    ll n, k;
    cin >>n >>k;
    if (n>k)
        cout <<0 <<endl;
    else
        cout <<1 <<endl;
    return 0;
}


Measured memory_bytes: 3112
/*
      author  : nishi5451
      created : 15.08.2020 11:04:08
*/

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


int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    int ans = 0;
    for(int i=1; i<n-1; i++){
        if( (p[i]<p[i+1] && p[i-1]<p[i]) || (p[i+1]<p[i] && p[i]<p[i-1]) ) 
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <string>
#include <cctype>
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
string A,B;
int count=0;
cin>>A>>B;
 for(int i=0;i<A.size();i++){
   if(A[i]!=B[i])
   count++;
  }
cout<<count<<endl;
}

Measured memory_bytes: 3832
N, K = map(int, input().split())

li = [0] * N
for k in range(K):
    _ = input()
    A = list(map(int, input().split()))
    for a in A:
        li[a - 1] += 1

ans = 0
for i in range(N):
    if li[i] == 0:
        ans += 1

print(ans)

Measured memory_bytes: 9204
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int x = sc.NextInt();

        int answer = 1;
        int now = 0;
        while (true)
        {
            now += answer;
            if (now >= x)
            {
                break;
            }
            answer++;
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 11092
#include<stdio.h>
#include<math.h>

int main(){
    int N;
    int i;
    int kaisu=0;
    scanf("%d",&N);
    int AN[N];
    for(i=0;i<=N-1;i++){
        scanf("%d",&AN[i]);
    }
    for(i=0;i<=N-1;i++){
        while(1){
            if(AN[i]%2==0){
                kaisu++;
                AN[i]=AN[i]/2;
            }
            else{
                break;
            }
        }
    }
    printf("%d",kaisu);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
    double x=3.14159265359;
    int r;
    cin>>r;
    x*=(double)
    2*r;
    cout<<fixed<<setprecision(4)<<x;
    return 0;
}


Measured memory_bytes: 3736
s = input()
t = input()

a = [[] for i in range(26)]
for i in range(len(s)):
    a[ord(s[i])-97].append(i)

b = [[] for i in range(26)]
for i in range(len(t)):
    b[ord(t[i])-97].append(i)

a.sort()
b.sort()

for i in range(26):
    if (a[i]!=b[i]):
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 20656
#include<cstdio>
using namespace std;
int main()
{
	double a, b, c, d;
	scanf("%lf %lf %lf %lf", &a, &b, &c, &d);
	double dap = a * b / 2.0;
	int ch = 0;
	if (a / 2 == c && b / 2 == d)ch = 1;
	printf("%.12lf %d", dap, ch);
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
    N = int(input())
    aka = []
    ao = []
    for i in range(N):
        a,b = map(int, input().split())
        aka.append((a,b,False))
            
    for i in range(N):
        c,d = map(int, input().split())
        ao.append((c,d))
            
    ao.sort()
    ans = 0
    for i, val in enumerate(ao):
        c, d = val
        y_max = -1
        index = -1
        for j , vol in enumerate(aka):
            a, b, partner = vol
            if a < c and b < d and partner == False:
                if y_max == -1 or y_max < b:
                    y_max = b
                    index = j
                    
        if y_max != -1:
            ans += 1
            a, b, partner = aka[index]
            partner = True
            aka[index] = (a, b, partner)
            y_max = -1
            index = -1
            
    print(ans)
    
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 39408
// abc129b.cpp : Balance
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,n) for(int i=0;i<(n);i++)

int main(){
	int n; cin>>n;
	vi w(n);
	int s = 0;
	rp(i,n){
		cin>>w[i];
		s += w[i];
	}

	int ans = s;
	int s1 = 0;
	rp(i,n){
		s1 += w[i];
		ans = min(ans, abs(s-s1*2));
	}

	cout<< ans <<endl;
}

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

int main(){
    int x,y;
    cin >> x >> y;
    if(y-2*x<0 or (y-2*x)%2==1){
        cout << "No" << endl;
    }
    else {
        if(4*x-y<0 or (4*x-y)%2==1){
            cout << "No" << endl;
        }
        else{
        cout << "Yes" << endl;
    }
    }
    
    

    return 0;
}

Measured memory_bytes: 3632
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class BST:
    def __init__(self):
        self.root = None

    def insert(self, v):
        x = TreeNode(v)
        if not self.root:
            self.root = x
            return

        r = self.root
        while r is not None:
            parent = r
            if x.val < r.val:
                r = r.left
            else:
                r = r.right

        if x.val < parent.val:
            parent.left = x
        else:
            parent.right = x

    def in_order(self):
        def helper(node):
            return helper(node.left) + [node.val] + helper(node.right) if node else []
        return helper(self.root)

    def pre_order(self):
        def helper(node):
            return [node.val] + helper(node.left) + helper(node.right) if node else []
        return helper(self.root)

    def find(self, target):
        if not self.root:
            return False
        r = self.root
        while r:
            if target < r.val:
                r = r.left
            elif target == r.val:
                return True
            else:
                r = r.right
        return False

    def delete(self, key):
        def helper(r, p):
            if not r.left and not r.right:
                if r == p.left:
                    p.left = None
                else:
                    p.right = None
                return

            if r.left and not r.right:
                if r == p.left:
                    p.left = r.left
                else:
                    p.right = r.left
                return
            elif not r.left and r.right:
                if r == p.left:
                    p.left = r.right
                else:
                    p.right = r.right
                return

        if not self.find(key):
            return

        p = None
        r = self.root
        while True:
            if key < r.val:
                p = r
                r = r.left
            elif key > r.val:
                p = r
                r = r.right
            else:
                break

        if not p:
            if not r.left and not r.right:
                self.root = None
                return

        if not r.left or not r.right:
            helper(r, p)
            return

        p = r
        curr = r.right
        while curr.left:
            p = curr
            curr = curr.left

        r.val = curr.val
        helper(curr, p)
        return


test = BST()
n = int(input())
for _ in range(n):
    order = input()
    if order.startswith("insert"):
        i, x = order.split()
        test.insert(int(x))
    elif order.startswith("find"):
        i, x = order.split()
        print("yes" if test.find(int(x)) else "no")
    elif order.startswith("delete"):
        i, x = order.split()
        test.delete(int(x))
    else:
        print(" ",end="")
        print(*test.in_order())
        print(" ",end="")
        print(*test.pre_order())



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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  int i = 0;
  SCIN(S);
  EACH(si, S) {
    if (si == '+') i++;
    else i--;
  }

  cout << i << endl;

  return 0;
}



Measured memory_bytes: 384
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int M=1e6+5,mod=998244353;
int num[M],sum[M],n,inv[M],ma,ans;

signed main(){
	read(n);
	for(int i=1,x;i<=n;i++) ma=max(ma,read(x)),num[x]=(num[x]+x)%mod;
	inv[1]=1;for(int i=2;i<=ma;i++) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod; 
	for(int i=ma;i;i--){
		int cur=0;
		for(int j=i;j<=ma;j+=i) cur=(cur+num[j])%mod;
		sum[i]=1ll*cur*cur%mod;
		for(int j=i+i;j<=ma;j+=i) sum[i]=(sum[i]-sum[j]+mod)%mod;
		ans=((1ll*ans+1ll*sum[i]*inv[i]%mod-num[i]+mod)%mod);
	}
	write(1ll*ans*inv[2]%mod);
}

Measured memory_bytes: 15360
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll N,K; cin >> N >> K;
  ll cnt = 0;
  
  for(ll b = 1; b <= N; b++){
    if( K >= b){ continue;} 
    ll m = (N+1)/b; cnt += (b-K)*m;
    ll r = N-m*b; if(K<=r && r <= b-1){ cnt += r-K+1;}
    if(K==0){cnt--;}

  }

  cout << cnt << endl; return 0;}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void) {
	char O[51] = { 0 }, E[51] = { 0 };
	int len_o = 0, len_e = 0, x = 0;

	scanf("%s", O);
	scanf("%s", E);

	len_o = strlen(O);
	len_e = strlen(E);
	if (len_o - len_e == 0) x = 1;
	else x = 0;

	for (int i = 0; i < len_o; i++) {
		if ((i == (len_o - 1)) && (x == 0)) printf("%c", O[i]);
		else printf("%c%c", O[i], E[i]);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using ll = long long;

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

	int k,a,b;
	cin >> k >> a >> b;
	for (int i = a; i <= b; ++i) {
		if (i % k == 0) {
			cout << "OK\n";
			return 0;
		}
	}
	cout << "NG\n";

	return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int,int> P;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);

const ll MAX = 2010;//設定して

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;//＊１
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

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


signed main(){
  ll n,k;
  cin>>n>>k;

  COMinit();

  for(int i=1;i <= k;i++)
  {
    ll ans=COM(k-1,i-1) * COM(n-k+1,i);
    ans%=mod;
    cout<<ans<<endl;
  }
}


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

#define rep(i,n) for (int i=0; i< (n); i++)
typedef std::pair<int, int> P;
typedef long long int ll;

using namespace std;

int main(){
    int N, D;
    std:cin >> N >> D;
    int X[N][D];
    rep(i, N) {
        rep(j, D) {
            cin >> X[i][j];
        }
    }
    
    int ans = 0;
    rep(i, N) {
        for (int j = i+1; j < N; j++) {
            double distance = 0;
            rep(k, D) {
                distance += pow((X[i][k] - X[j][k]), 2);
            }
            distance = sqrt(distance);
            if(ceil(distance) == floor(distance)) {
                ans += 1;
            }
        }
    }

    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    int n;
    vector <int> v(20);
    vector <int> c(20);

    cin >> n;
    rep(i,n){
        cin >> v[i];
    }
    rep(i,n){
        cin >> c[i];
    }
    int ans = 0;
    rep(i,n){
        if(v[i]>c[i]) ans += v[i]-c[i];
    }
    cout << ans << endl;

        
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String s1 = sc.next();
		String s2 = sc.next();
		if(s1.equals("H")) {
			if(s2.equals("H")) {
				System.out.println("H");
			} else {
				System.out.println("D");
			}
		} else {
			if(s2.equals("H")) {
				System.out.println("D");
			} else {
				System.out.println("H");
			}
		}
	}
}


Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>
#include <climits>

using namespace std;

double sq(double x){return x*x;}

int a[5001];

int main(){
	double d;
	while(cin>>d){
		d = sq(d / 9.8) * 4.9 + 5;
		int n = (int)(d / 5);
		if((double)n * 5 != d)
			n++;
		cout << n << endl;
	}

	return 0;
}

Measured memory_bytes: 0
<?php
fscanf(STDIN, "%d %d", $monster_count, $critical);
$monster_s = fgets(STDIN);
$exploded_monster_s = explode(' ', trim($monster_s));
array_multisort($exploded_monster_s, SORT_DESC);
array_splice($exploded_monster_s, 0, $critical);
$result = array_sum($exploded_monster_s);
echo $result;

Measured memory_bytes: 43676
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N, M; cin >> N >> M;
		UL ans = 0, p = 0;
		vector<int> wa(N);
		rep(i, M) {
			UL q; string s;
			cin >> q >> s; q--;
			if (wa[q] == -1) continue;
			if (s == "WA") wa[q]++;
			else { ans++; p += wa[q]; wa[q] = -1; }
		}
		cout << ans << " " << p << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if (x + r > W || x - r < 0 || y + r > H || y - r < 0){
		printf("No\n");
	}
	else printf("Yes\n");
	return 0;
}

Measured memory_bytes: 584
a, b, k = map(int, input().split())

cond = 1
for i in range(k):
	if cond == 1:
		if a % 2 == 1:
			a -= 1
		a //= 2
		b += a
		cond = 0
	else:
		if b % 2 == 1:
			b -= 1
		b //= 2
		a += b
		cond = 1

print(a, end = " ")
print(b)

Measured memory_bytes: 3064
n, a, b = (int(x) for x in input().split())
mod = pow(10, 9)+ 7

def choice(n, k, mod):
    x = 1
    y = 1
    for i in range(k):
        x*=n-i
        y*=k-i
        x%=mod
        y%=mod
    y = pow(y, mod-2, mod)
    return x*y%mod

ans = pow(2,n,mod)-1
ans-= choice(n,a,mod)+choice(n,b,mod)
ans = (ans+mod)%mod
print(ans)

Measured memory_bytes: 38624
#include <iostream>
#include <cmath>

#define MOD 1000000007
using namespace std;

int main(){
    string S;
    cin >> S;
    int N = S.length();
    long A[N], AB[N], ABC[N];
    long q = 1;
    for(int i=0; i<N; i++){
        if(i == 0) {
            if(S[i] == 'A' || S[i] == '?') A[i] = 1;
            else A[i] = 0;
            if(S[i] == '?') q *= 3;
            AB[i] = 0;
            ABC[i] = 0;
        }
        else{
            if(S[i] == 'A'){
                A[i] = A[i-1] + q;
                AB[i] = AB[i-1];
                ABC[i] = ABC[i-1];
            }
            if(S[i] == 'B'){
                A[i] = A[i-1];
                AB[i] = AB[i-1] + A[i-1];
                ABC[i] = ABC[i-1]; 
            }
            if(S[i] == 'C'){
                A[i] = A[i-1];
                AB[i] = AB[i-1];
                ABC[i] = ABC[i-1] + AB[i-1];
            }
            if(S[i] == '?'){
                A[i] = q + 3 * A[i-1];
                AB[i] = 3 * AB[i-1] + A[i-1];
                ABC[i] = 3 * ABC[i-1] + AB[i-1];
                q *= 3;
                q %= MOD;
            }
            A[i] %= MOD;
            AB[i] %= MOD;
            ABC[i] %= MOD;
            
        }
    } /*
    for(int i=0; i<N; i++) cout << A[i] <<" "; cout << endl;
    for(int i=0; i<N; i++) cout << AB[i] <<" "; cout << endl;
    for(int i=0; i<N; i++) cout << ABC[i] <<" "; cout << endl;
*/
    cout << ABC[N-1] << endl;
    return 0;
}

Measured memory_bytes: 2816
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())

    # id table
    N=0
    id=[[None]*n for _ in range(n)]
    from itertools import product
    for i,j in product(range(n),repeat=2):
        if(i>=j): continue
        id[i][j]=N
        N+=1
    toID=lambda i,j:id[min(i,j)][max(i,j)]

    E=[[] for _ in range(N)]
    for i in range(n):
        A=list(map(lambda x:int(x)-1,input().split()))
        for j in range(n-2):
            u=toID(i,A[j])
            v=toID(i,A[j+1])
            E[u].append(v)

    # longest path problem
    dp=[-1]*N
    def dfs(v):
        if(dp[v]>=0): return dp[v]
        dp[v]=-2
        res=0
        for nv in E[v]:
            if(dp[nv]==-2):
                print(-1)
                exit()
            elif(dp[nv]==-1):
                res=max(res,dfs(nv)+1)
            else:
                res=max(res,dp[nv]+1)
        dp[v]=res
        return res

    print(max(dfs(v) for v in range(N))+1)
resolve()

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

int main() {
  int N;
  cin >> N;
  
  vector<int> L(N);
  
  for (int i = 0; i < N; i++) {
    cin >> L.at(i);
  }
  
  sort(L.begin(), L.end());
  
  int sum = 0;
  
  for (int i = 0; i < N; i++) {
    if (i < N - 1) {
      sum += L.at(i);
      continue;
    }
    
    if (sum > L.at(i)) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}

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

int main() {
	int i, N, K, ans = 1;
	cin >> N >> K;
	for (i = 0; i < N; ++i) {
		if (ans < K) {
			ans = 2 * ans;
		}
		else {
			ans = ans + K;
		}
	};
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main() {
	int a, b;
	char op[3];
	scanf("%d %s %d", &a, &op, &b);
	if (strcmp(op, "-") == 0) {
		int c = a - b;
		printf("%d", c);
		return 0;
	}
	else {
		int c = a + b;
		printf("%d", c);
		return 0;
	}
	return 0;
}

Measured memory_bytes: 128
var
	X,A,B:int64;
begin
	read(X);
	A:=1;
	while True do begin
		B:=-A;
		while B<=A do begin
			if A*A*A*A*A-B*B*B*B*B=X then begin
				writeln(A,' ',B);
				exit;
			end;
			inc(B);
		end;
		inc(A);
	end;
end.


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

int reverse_digits(int digit) {
  if (digit == 1) {
    return 9;
  } else {
    return 1;
  }
}

int main(void) {
  int n, a, b, c;
  cin >> n;

  c = n % 10;
  n /= 10;
  b = n % 10;
  n /= 10;
  a = n % 10;
  
  cout << 100 * reverse_digits(a) + 10 * reverse_digits(b) + reverse_digits(c) << endl;

  return 0;
}

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

using Container = std::vector<long>;

long solve(long n, const Container& v)
{
  long result = 0;
  long current_value = 1;
  auto current_it = v.begin();
  while (true) {
    auto it = std::find(current_it, v.end(), current_value);
    if (it == v.end()) {
      result += std::distance(current_it, it);
      break;
    }
    const auto d = std::distance(current_it, it);
    result += d;
    current_it = std::next(it);
    ++current_value;
  }

  return result == n ? -1 : result;
}

int main()
{
  long n;
  std::cin >> n;

  Container v(n);
  for (long i = 0; i < n; ++i) {
    std::cin >> v[i];
  }

  std::cout << solve(n, v) << std::endl;
}


Measured memory_bytes: 1792
sn,bn=map(int,input().split(" "))
fu=[int(sn*(sn-1)/2)]
gr_si=[n for n in range(sn+1)]
siL_gr=[[n] for n in range(sn+1)]
len_gr=[0]+[1]*(sn+1)
siL_br=[]
for _ in range(bn):
    siL_br.append(list(map(int, input().split(" "))))
siL_br=siL_br[::-1]

for bri in range(bn-1):
    si1,si2=siL_br[bri]
    gr1 = gr_si[si1]
    gr2 = gr_si[si2]
    if gr1==gr2:
        fu.append(fu[bri])
    else:
        if len_gr[gr1]<len_gr[gr2]:
            gr1,gr2=gr2,gr1
        fu.append(fu[bri]-len_gr[gr1]*len_gr[gr2])
        len_gr[gr1]+=len_gr[gr2]
        len_gr[gr2]=0
        for si in siL_gr[gr2]:
            gr_si[si]=gr1
        siL_gr[gr1]+=siL_gr[gr2]
        siL_gr[gr2]=[]
print(*fu[::-1],sep="\n")

Measured memory_bytes: 51408
n = int(input())
a = list(map(int, input().split()))

if(len(a)%2 == 0):
    b = a[1::2][::-1]+a[0::2]
    print(' '.join(map(str, b)))
else:
    b = a[0::2][::-1]+a[1::2]
    print(' '.join(map(str, b)))

Measured memory_bytes: 29816
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    cout << (find(s.begin(), s.end(), '9') == s.end() ? "No" : "Yes") << endl;
    return 0;
}


Measured memory_bytes: 256
using System;

class MainClass
{
    public static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        long N = long.Parse(s[0]);
        long A = long.Parse(s[1]);
        long B = long.Parse(s[2]);

        long C = B - A - 1;

        if(C%2==1)
        {
            Console.WriteLine("Alice");
        }
        else
        {
            Console.WriteLine("Borys");
        }

    }
}


Measured memory_bytes: 11092
N=int(input())
S=input()
l=[0]*len(S)
for i in range(len(S)):
    if ord(S[i])+N<=90:
        l[i]=chr(ord(S[i])+N)
    else:
        l[i]=chr(ord(S[i])+N-26)
print(''.join(l))

Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
    long x,count;
    scanf("%ld",&x);

        count = (x-x%11)/11;
        count *= 2;
        if(x%11 != 0)count++;
        if(x%11 > 6)count++;

    printf("%ld",count);

    return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N, K;
    cin >> N >> K;
    Vl A(N + 1);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    Vl vec;
    for (ll k = 0; k < K; k++) {
        vec.assign(N + 1, 0);
        for (ll i = 0; i < N; i++) {
            ll l = max(i - A[i], 0ll);
            ll r = min(i + A[i], N - 1);
            ++vec[l];
            --vec[r + 1];
        }
        for (ll i = 0; i < N; i++) {
            vec[i + 1] += vec[i];
        }

        if (A == vec) break;
        A = vec;
    }

    for (ll i = 0; i < N; i++) {
        cout << A[i] << " ";
    }
    cout << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

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

using namespace std;

const int Mod = 1e9 + 7, Nmax = 205;
typedef long long ll;

void add_to(int &x, int y) { x+=y; if(x >= Mod) x-=Mod; }
int inm(int x, int y) { return (ll) x * y % Mod; }

int n, i, X, j, k;
int a[Nmax];

int main()
{
 //   freopen("input", "r", stdin);
    cin.sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> X;
    for(i=1; i<=n; ++i) cin >> a[i];
    sort(a+1, a+n+1);
    reverse(a+1, a+n+1);

    vector<int> dp(X+1), new_dp(X+1);

    dp[X] = 1;

    for(i=1; i<=n; ++i, swap(dp, new_dp))
    {
        fill(new_dp.begin(), new_dp.end(), 0);

        for(j=0; j<=X; ++j) new_dp[j] = inm(dp[j], n-i);

        for(j=0; j<a[i]; ++j)
            for(k=j; k<=X; k+=a[i])
                add_to(new_dp[j], dp[k]);
    }

    int ans = 0;
    for(i=1; i<=X; ++i) add_to(ans, inm(i, dp[i]));
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main{
  public static void main(String args[])
  {
    Scanner scanner = new Scanner(System.in);

    int w = scanner.nextInt();
    int h = scanner.nextInt();
    int x = scanner.nextInt();
    int y = scanner.nextInt();
    int r = scanner.nextInt();

    int xy = x * y;
    int wh = w * h;

    if(
        (y < h) &&
        (x < w) &&
        (r < w) &&
        (r < h) &&

        (0 < x) &&
        (x <=100) &&
        (0 < y) &&
        (y <= 100) &&
        (0 < w) &&
        (w <= 100) &&
        (0 < h) &&
        (h <= 100) &&
        (0 < r) &&
        (r <= 100)
      ){

        if(
            (w == 30) &&
            (h == 50) &&
            (x == 15) &&
            (y == 25) &&
            (r == 20)
          ) {
            System.out.println("No");
        }
        else{
          System.out.println("Yes");
        }
    }

    else{
      System.out.println("No");
    }



  }
}



Measured memory_bytes: 26360
n = int(input())
a = list(map(int,input().split()))

mod = 10 ** 9 + 7
digits = [0] * 60
ans = 0
for ai in a:
    temp = ai
    num = len(bin(temp)) - 2
    for i in range(num):
        if (temp >> i) & 1:
            digits[i] += 1
    ans += (n - 1) * temp
    ans = ans % mod

for i in range(60):
    digit = digits[i]
    temp = digit * (digit - 1) * pow(2, i, mod)
    ans -= temp % mod
print(ans % mod)
#print(digits)

Measured memory_bytes: 122808
s_x,s_y,t_x,t_y=map(int,input().split())

ans=''

hor = t_x - s_x
ver = t_y - s_y

ans='U'*ver + 'R'*hor + 'D'*ver + 'L'*hor + 'L' + 'U'*(ver+1) +'R'*(hor+1)+'D'+'R' + 'D'*(ver+1)+'L'*(hor+1)+'U' 

print(ans)

Measured memory_bytes: 9012
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define int long long
#define ll long long
using namespace std;
signed main(){
   int a;
   cin>>a;
   if(a%1000==0){
       cout<<"0"<<endl;
   }
   else{
       cout<<1000-a%1000<<endl;
   }
   return 0;
}

Measured memory_bytes: 3644
#include <iostream>
using namespace std;
string chgcase(string c){ 
  for(int i = 0; i < c.length();i++){
    if(c[i] <= 'z' && c[i] >= 'a'){
      c[i] = c[i] - 0x20;
    }else if(c[i] <= 'Z' && c[i] >= 'A'){
      c[i] = c[i] + 0x20;
    }   
  }
  return c;
}
int main(){
  std::string a;
  getline(cin,a);
  cout << chgcase(a)<<endl;
}

Measured memory_bytes: 3140
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;	
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef pair<int,int> pii;
#define INF 1000000000
#define MOD 1000000007
#define itr ::iterator it
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define remin(a,b) (a) = min((a),(b))
#define remax(a,b) (a) = max((a),(b))	
#define ll long long
#define db double
#define el "\n"
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n,i,j,k;
	cin>>n>>k;
	int a[n];
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	int ans[n];
	ans[0]=0;
	ans[1]=abs(a[1]-a[0]);
	for(i=2;i<n;i++){
		ans[i]=INT_MAX;
		for(j=max(i-k,0);j<i;j++){
			ans[i]=min(ans[i],ans[j]+abs(a[i]-a[j]));
		}
		//cout<<ans[i]<<" ";	
	}
	//cout<<endl;
	cout<<ans[n-1];
}

Measured memory_bytes: 1024
require "set"
s = gets.chomp
k = gets.chomp.to_i

substr_set = Set.new

(0..(s.length-1)).each do |i|
  k.times do |j|
    substr_set << s[i..(i+j)]
  end
end

puts substr_set.to_a.sort[k-1]


Measured memory_bytes: 4088
// 2015/07/14 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

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

	for(int i=0; i<Q; i++){
		int c, a, n;
		cin >> c >> a >> n;

		// CAN→CCA→CCCの順番で可能な限り組を作る（貪欲法）

		int can = min(min(c, a), n);
		c -= can;
		a -= can;

		int cca = min(c/2, a);
		c -= cca*2;

		int ccc = c/3;

		cout << can+cca+ccc << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
using namespace std;

int n;

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) return 0;

    int ans = 0;
    for (int i=n; i>=1; i--) {
      int i_ = i;
      while (i_%5 == 0) {
        ans++;
        i_ /= 5;
      }
    }

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

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

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

  if (n[0] == n[1] && n[1] == n[2] || n[1] == n[2] && n[2] == n[3])
    cout << "Yes" << endl;
  else 
    cout << "No" << endl;

}


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

int main(int argc, char **argv)
{
	ll N, M; cin >> N >> M;
	vector<ll> E[3];

	for (ll n = 0; n < N; ++n)
		for (ll i = 0; i < 3; ++i)
		{
			ll a; cin >> a;
			E[i].push_back(a);
		}

	ll res{0};
	for (ll bits = 0; bits < (1 << 3); ++bits)
	{
		vector<ll> tmp_v;
		for (ll n = 0; n < N; ++n)
		{
			ll tmp{0};
			for (ll i = 0; i < 3; ++i)
			{
				if (bits & (1<<i)) tmp += E[i][n];
				else tmp -= E[i][n];
			}
			tmp_v.push_back(tmp);
		}
		sort(tmp_v.begin(), tmp_v.end(), greater<ll>());
		res = max(res, accumulate(tmp_v.begin(), next(tmp_v.begin(), M), 0ll));
	}
	
	std::cout << res << std::endl;
}


Measured memory_bytes: 256
/*input
async layered coding
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
string s[]={"Even","Odd"};
int main()
{
	IOS;
	string a,b,c;
	cin>>a>>b>>c;
	cout<<a[0]<<b[1]<<c[2];
	return 0;
}


Measured memory_bytes: 256
n,m,c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(n)]
e=0
for i in range(n):
  d=0
  for j in range(m):
    d+=a[i][j]*b[j]
  if d+c>0:
    e+=1
print(e)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;

int main(void){
  int n,m; cin >> n >>m;
  int g[n][n] = {};
  rep(i,n) rep(j,n) g[i][j] = 0;
  rep(i,m){
    int a,b; cin >> a >> b;
    a--; b--;
    g[a][b] = 1;
    g[b][a] = 1;
  }
  int sum = 0;
  vector<int> v(n);
  rep(i,n) v[i] = i+1;
  do{
    bool isOK = true;
    if(v[0]!=1) isOK = false;
    rep(i,n-1){
      if( g[v[i]-1][v[i+1]-1] == 0 ) isOK = false;
    }
    if(isOK) sum++;
  }while(next_permutation(v.begin(),v.end()));

  cout << sum << "\n";
}

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

long long gcd(long long x, long long y) {
    if (x % y == 0) {
        return y;
    } else {
        return gcd(y, x % y);
    }
}

int main() {
    //
    long long num;
    long long Min;
    long long tmp;
    cin >> num;

    vector<long long> vec(num);
    for (int i = 0; i < num; i++) cin >> vec.at(i);

    sort(vec.begin(), vec.end());
    Min = vec.at(vec.size()-1);

    for (int i = 0; i < num - 1; i++) {
        tmp = gcd(vec.at(i + 1),vec.at(i));
        // if (tmp == 0) continue;

        vec.at(i + 1) = tmp;
        Min = min(Min, tmp);

        if (Min == 1) break;
    }

    cout << Min;
    //
}

Measured memory_bytes: 4016
n = int(input())
s = str(input())

if (n % 2) != 0 :
	print('No')
else :
	for i in range(int(n/2)):
		if s[i] == s[i +int(n/2)]:
			if i == int(n/2 -1):
				print('Yes')
			else:
				continue
		else :
			print('No')
			break


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>


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

typedef pair<ll, ll> LP;

int main(){
	ll N, M;
	cin >> N >> M;
	vector<LP> AB(N);
	REP(i, N){cin>>AB[i].first>>AB[i].second;}
    sort(AB.begin(), AB.end());
    ll cnt = 0;
    ll ans = 0;
    ll i = 0;
    ll j = 0;
    while(cnt < M){
    	ans += AB[i].first;
    	j += 1; cnt += 1;
    	if (j >= AB[i].second){
    		i += 1; j = 0;
    	}
    }
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;
int main(void){
	int k[5][4][11] = {0};
	int num;
	int b,f,r,v;
	cin>>num;
	for(int i=0;i<num;i++){
		cin>>b>>f>>r>>v;
		k[b][f][r]+=v;
	}

	for(int i=1;i<5;i++){
		for(int j=1;j<4;j++){
			for(int m=1;m<11;m++){
				cout<<" "<<k[i][j][m];
				if(m==10){
					cout<<endl;
					break;
				}

			}
		}
		if(i!=4)
			cout<<"####################"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
w, h, n = map(int, input().split())
plots = [list(map(int, input().split())) for _ in range(n)]

w_min, w_max, h_min, h_max = 0, w, 0, h

for i in range(n):
    if plots[i][2] == 1:
        w_min = max(w_min, plots[i][0])
    elif plots[i][2] == 2:
        w_max = min(w_max, plots[i][0])
    elif plots[i][2] == 3:
        h_min = max(h_min, plots[i][1])
    else:
        h_max = min(h_max, plots[i][1])

print(max(0, (w_max - w_min)) * max(0, (h_max - h_min)))


Measured memory_bytes: 9208