akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

struct Node {
  int i, j, rev, cost;
  bool operator>(const Node &n) const {
    return cost > n.cost;
  }
};

int main() {
  int H, W;
  cin >> H >> W;

  vector<vector<char>> table(H);
  vector<vector<bool>> check(H);
  for (int i = 0; i < H; i++) {
    table[i].resize(W);
    check[i].resize(W, false);
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> table[i][j];
    }
  }

  priority_queue<Node, vector<Node>, greater<Node>> q;
  if (table[0][0] == '.') {
    q.push({0, 0, 0, 0});
  } else {
    q.push({0, 0, 1, 1});
  }

  while (!q.empty()) {
    Node n = q.top();
    q.pop();
    if (check[n.i][n.j] == true) {
      continue;
    }
    check[n.i][n.j] = true;

    if (n.i == H - 1 && n.j == W - 1) {
      cout << n.cost << endl;
      break;
    }

    if (n.i < H - 1) {
      int rev = n.rev;
      if (n.rev == 0 && table[n.i + 1][n.j] == '#' ||
	  n.rev == 1 && table[n.i + 1][n.j] == '.') {
	rev = 1 - n.rev;
      }
      int cost = n.cost;
      if (n.rev == 0 && table[n.i + 1][n.j] == '#') {
	cost++;
      }
      q.push({n.i + 1, n.j, rev, cost});
    }

    if (n.j < W - 1) {
      int rev = n.rev;
      if (n.rev == 0 && table[n.i][n.j + 1] == '#' ||
	  n.rev == 1 && table[n.i][n.j + 1] == '.') {
	rev = 1 - n.rev;
      }
      int cost = n.cost;
      if (n.rev == 0 && table[n.i][n.j + 1] == '#') {
	cost++;
      }
      q.push({n.i, n.j + 1, rev, cost});
    }
  }

  return 0;
}

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

const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	int cnt = 1;
	rep(i,n){
		if(a.at(i) == cnt) cnt++;
	}
	if(cnt == 1) cout << -1 << endl;
	else cout << n - cnt + 1 << endl;
} 

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

int main() {
  int N;
  vector<int> ai;
  cin >> N;
  for(int i = 0; i < N; i++) {
    int temp;
    cin >> temp;
    ai.push_back(temp);
  }
  sort(ai.begin(), ai.end(), greater<int>());
  int alice = 0;
  int bob = 0;
  for(int i = 0; i < N; i++) {
    if(i % 2 == 0) alice += ai[i];
    else bob += ai[i];
  }
  cout << alice - bob << endl;
  return 0;
}


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

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  newl           cout<<"\n"
#define  pb             push_back
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define  deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define  deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   MAXN  =  1e+5+7;

vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll n;
ll a[200005];
map<ll,ll>map1;
set<ll>set2,set1;
ll b[1000007];
//<<-----Implement Functions Here---->>//


//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>n;ll count1 = 0;ll max1 = -1;
		for(ll i=0;i<n;i++)
		{
			cin>>a[i];b[a[i]]++;max1 = max(max1,a[i]);
		}
		set2.insert(0);
		for(ll i=0;i<n;i++)
		{
			for(ll j=2*a[i];j<=max1;j+=a[i])set2.insert(j);
		}

		for(ll i=0;i<n;i++)
		{
			if(b[a[i]]>=2)continue;
			if(set2.find(a[i])==set2.end())count1++;
		}
		cout<<count1;
	
		
}

int main(){
	fastio;randomINIT;

	//cin>>t;
	while(t--){
		MAIN();
	}

   
}

Measured memory_bytes: 61960
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int N;
	string S[100], X;
	int t[100];

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> S[i] >> t[i];
	}
	cin >> X;

	int ans = 0;

	for (int i = 0; i < N; i++) {
		if (X == S[i]) {
			ans = i;
		}
	}

	int res = 0;

	for (int i = ans + 1; i < N; i++) {
		res += t[i];
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define pb(x)                       push_back(x)
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const int MAXN = 1e3 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;
char a[MAXN][MAXN];
ll dp[MAXN][MAXN];

ll h, w;

int main()
{
    fast_io;
    cin >> h >>w ;
    for (int i = 1; i <= h;i++){
        for (int j = 1;j <= w;j++){
            cin >> a[i][j];
        }
    }
    dp[1][1] = 1;
    for (int i = 1;i <= h;i++){
        for (int j = 1;j <= w;j++ ){
            if (a[i][j] == '#')
                continue;
            dp[i + 1][j] += dp[i][j];
            dp[i+1][j] %= MOD;
            dp[i][j + 1] += dp[i][j];
            dp[i][j + 1] %= MOD;
        }
    }
    cout << dp[h][w] << endl;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
int a[40];
int main()
{
    long long n,k,i,j,nr,s=0;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>nr;
        for(j=0;nr;j++,nr>>=1)
            a[j]+=nr&1;
    }
    for(i=39,j=1LL<<39;i>=0;i--,j>>=1)
        if(k>=j&&2*a[i]<n)
            k-=j,s+=(n-a[i])*j;
        else
            s+=a[i]*j;
    cout<<s;
    return 0;
}


Measured memory_bytes: 256
fn main() {
    let n = read::<usize>();
    let heights = read_vec::<u64>();

    println!("{}", if solve(n, heights) { "Yes" } else { "No" });
}

fn solve(n: usize, mut heights: Vec<u64>) -> bool {
    for i in 0..(n - 1) {
        if heights[n - i - 2] - 1 == heights[n - i - 1] {
            heights[n - i - 2] -= 1;
        } else if heights[n - i - 2] > heights[n - i - 1] {
            return false;
        }
    }
    true
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++) 
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    int dp[3100][3100]={0};
    string s,t;
    cin >> s >> t;
    rep(i,s.length()){
        rep(j,t.length()){
            if(s[i]==t[j])chmax(dp[i+1][j+1],dp[i][j]+1);
            chmax(dp[i+1][j+1],dp[i+1][j]);
            chmax(dp[i+1][j+1],dp[i][j+1]);
        }
    }
    string res="";
    int i=(int)s.size();
    int j=(int)t.size();
    while(i>0 && j>0){
        if(dp[i][j]==dp[i-1][j]){
            i--;
        }
        else if(dp[i][j]==dp[i][j-1]){
            j--;
        }
        else{
            res=s[i-1]+res;
            i--;
            j--;
        }
    }
    cout << res << endl;
    


}

/*



 */



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

int main() {
  int n;
  vector<int> pri(1000000, 1);
  vector<int> p_sum;
  pri[0] = 0;
  pri[1] = 0;

  for(int i = 2; i < sqrt(1000000); i++) {
    for(int j = i*i; j < 1000000; j+=i) {
      pri[j] = 0;
    }
  }

  int cnt	= 0;
  p_sum.push_back(2);

  for(int i = 3; i < 1000000; i++) {
    if(pri[i] == 1) {
      p_sum.push_back(i+p_sum[cnt]);
      cnt++;
    }   
  }

  while(cin >> n, n) {
    cout << p_sum[n-1] <<	endl;
  }
  return 0;
}



Measured memory_bytes: 7212
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define first first
#define second se
using namespace std;
typedef pair<int, int> P;
typedef vector<int> vi;

signed main(){
    string s;
    cin >> s;
    int l = -2, r = -2;
    rep(i, 0, s.size()){
        if((i + 1) < s.size() && s[i] == s[i + 1]){
            l = i, r = i + 1;
            break;
        }else if((i + 2) < s.size() && s[i] == s[i + 2]){
            l = i; r = i + 2;
            break;
        }
    }
    o(l + 1 << " " << r + 1);
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

//関数宣言
//int func(int x, int y);

int main(void){

  //文字列入力
  char str[5];
  scanf("%s", str);

  int num;
  num = atoi(str);

  int fst,snd;

  fst = num/100;
  snd = num%100;

  /* printf("%d %d\n", fst, snd); */

  int YM=0,MY=0;

  if(fst >= 1 && fst <= 12){
    MY=1;
  }
  if(snd >= 1 && snd <= 12){
    YM=1;
  }

  if(MY){
    if(YM){
      printf("AMBIGUOUS\n");
    }else{
      printf("MMYY\n");
    }
  }else{
    if(YM){
      printf("YYMM\n");
    }else{
      printf("NA\n");
    }
  }

  return 0;
}


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

int main(){
  string s; cin >> s;
  int n = s.size();
  for(int i=0; i<n/2; ++i){
    if(s[i] != s[n-1-i]){
      cout << "No" << endl;
      return 0;
    }
  }
  for(int i=0; i<n/4; ++i){
    if(s[i] != s[n/2-1-i]){
      cout << "No" << endl;
      return 0;
    }
  }
  for(int i=0; i<n/4; ++i){
    if(s[i+(n/2+1)] != s[n-i-1]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

class myDLList{
private:
    struct Node {
        int key;
        Node *prev, *next;
    };
    Node *nil;

public:
    myDLList () {
        nil = (Node *)malloc(sizeof(Node));
        nil->next = nil;
        nil->prev = nil;
    }

    Node* search (int key) {
        Node *current = nil->next;

        while (current->key != key && current != nil) {
            current = current->next;
        }
        return current;
    }

    void erase (Node *t) {
        if (t == nil) {
            //cout << "null node" << endl;
            return;
        }
        t->prev->next = t->next;
        t->next->prev = t->prev;
        free(t);
    }
    
    void eraseKey (int key) {
        erase(search(key));
    }
    
    void eraseFirst() {
        erase(nil->next);
    }
    
    void eraseLast() {
        erase(nil->prev);
    }

    void insertAfter (int newkey, Node *t) {
        Node *x = (Node *)malloc(sizeof(Node));
        x->key  = newkey;
        x->next = t->next;
        t->next->prev = x;
        x->prev = t;
        t->next = x;
    }

    void insertBefore (int newkey, Node *t) {
        Node *x = (Node *)malloc(sizeof(Node));
        x->key  = newkey;
        x->prev = t->prev;
        t->prev->next = x;
        x->next = t;
        t->prev = x;
    }

    void insertFirst (int key) {
        insertAfter(key, nil);
    }

    void insertLast (int key) {
        insertBefore(key, nil);
    }

    void display () {
        Node *t = nil->next;
        while(t != nil) {
            cout << t->key;
            if (t->next != nil) {cout << " ";}
            t = t->next;
        }
        cout << endl;
    }
};

int main () {
    int n, x;
    cin >> n;
    string order;
    myDLList dll;

    for (int i = 0; i < n; i++) {
        cin >> order;
        if (order == "insert") {
            cin >> x;
            dll.insertFirst(x);
        } else if (order == "delete") {
            cin >> x;
            dll.eraseKey(x);
        } else if (order == "deleteFirst") {
            dll.eraseFirst();
        } else if (order == "deleteLast") {
            dll.eraseLast();
        } else {
            cout << "input order value error" << endl;
            break;
        }
    }
    
    dll.display();
    return 0;
}


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

int main()
{
  int k, a, b;
  cin >> k >> a >> b;
  
  bool ok = false;
  for ( int i = a; i<=b; i++)
  {
    if (i%k == 0)
      ok = true;
    
  }
  if (ok) cout << "OK" << endl;
  else cout << "NG" << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
using namespace std;

long long int nextRun(long long int x){
  if(x == 0) return 1 ;
  long long int box = x, now, next, byten = 1 ;
  int check = 1, mode = 0 ;
  while(check){
    byten *= 10 ;
    now = (box % byten) / (byten/10) ;
    next = (box % (byten * 10) ) / byten ;
    if((now <= next ) && (now != 9) ){
      check = 0 ;
      mode = 1 ;
    }
    else if((byten >= box) && (now != 9) ){
      check = 0 ;
      mode = 2 ;
    }
    else if((byten >= box)){
      check = 0 ;
      mode = 3 ;
    }
  }
  if(mode == 1){
    box = (box / byten) * byten ;
    now++ ;
    while(byten>=10){
      byten /= 10 ;
      box += (now * byten) ;
      if(now) now-- ;
    }
  }
  if(mode == 2){
    byten /= 10 ;
    box = (now+1) * byten ;
    while(byten>=10){
      byten /= 10 ;
      box += (now * byten) ;
      if(now) now-- ;
    }
  }
  if(mode == 3){
    box = byten ;
  }
  return box ;
}


int main(){
  long long int N, K, total = 0, ans = 0 ;
  cin >> K ;
  for(int i=0;i<K;i++){
    ans = nextRun(ans) ;
  }
  cout << ans << endl ;
  return 0 ;
}  

Measured memory_bytes: 256
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          (x).begin(),(x).end()
#define     rz(x)           resize(x)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)+(x)-1)/(x))
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        (((a)*(b))/gcd((a),(b)))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
    int n,m;
    cin>>n>>m;

    vector<int> h(n);
    for(int i=0;i<n;++i)
        cin>>h[i];

    set<int> st[n];

    int a,b;
    for(int i=0;i<m;++i)
    {
        cin>>a>>b;
        --a,--b;

        st[a].ins(b);
        st[b].ins(a);
    }

    bool fl;
    int ans=0;
    for(int i=0;i<n;++i)
    {
        fl=0;
        for(auto c:st[i])
        {
            if(h[c]>=h[i])
            {
                fl=1;
                break;
            }
        }

        if(!fl)
            ++ans;
    }

    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 17984
#include <stdio.h>

int main(){
	int i,l[10],v[2];
	double far;
	while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&v[0],&v[1]) != EOF){
		for(i = 1;i < 10;i++){
			l[i] += l[i - 1];
		}
		far = (double)(l[9] * v[0]) / (v[0] + v[1]);
		for(i = 0;i < 10;i++){
			if(far <= l[i]) {
				printf("%d\n",i + 1);
				break;
			}
		}
	}
	return 0;
}

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

#define trav(a, A) for (auto & a : A)
#define f first
#define s second

typedef long long ll;

const ll MOD = 1e+9+7;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+5+7;

int main ()
{
	ios_base::sync_with_stdio (0);
	cin.tie (0);
	ll i, j, n;
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        String word = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        Scanner sc = new Scanner(System.in);
        int i = sc.nextInt();
        String str = sc.next();
        StringBuilder sb = new StringBuilder();
        for(char c : str.toCharArray()){
            sb.append( word.charAt( ((word.indexOf(c)+i) % word.length() ) ) );
        }
        System.out.println(sb);
    }
}


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

int main(){
    #define int unsigned long long int
    int n, a, b;
    cin >> n;
    cin >> a;
    cin >> b;
    int u;

    if((b-a) % 2 == 0){
        cout << (b-a)/2 << endl;
    }else{
        if(b-1 < n-a){
            u = (a-1)+1;
            cout << (((b-u)-1)/2)+u << endl;
        }else{
            u = (n-b)+1;
            cout << ((n-(a+u))/2)+u << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main ()
{
	int cnt=0,i,n,ar[100];
	cin>>n;
	for (i=1; i<=n; i++)
	cin>>ar[i];
	
	for (i=1; i<=n; i++)
	{
		if (i != ar[i]) cnt++;
	}
	if (cnt==0 || cnt==2) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 500005;

int a, b;

int main() {
scanf("%d %d", &a, &b);
if (a * 500 >= b) printf("Yes\n"); else printf("No\n");
}





Measured memory_bytes: 256
package main

import "fmt"

const (
	mod   = 998244353
	limit = 200001
)

var (
	fac  = make([]int, limit)
	finv = make([]int, limit)
	inv  = make([]int, limit)
)

func powMod(a, n int) int {
	if n == 0 {
		return 1
	}
	if n%2 == 0 {
		d := powMod(a, n/2) % mod
		return d * d % mod
	}
	return a * powMod(a, n-1) % mod
}

func combModInit() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1
	for i := 2; i < limit; 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
	}
}

func combMod(n, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % mod) % mod
}

func main() {
	var n, m, k int
	fmt.Scan(&n, &m, &k)

	combModInit()
	ans := 0
	for i := 0; i <= k; i++ {
		ans += (((m * (combMod(n-1, i) % mod)) % mod) * powMod(m-1, n-i-1)) % mod
		ans %= mod
	}
	fmt.Println(ans)
}


Measured memory_bytes: 6732
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  string s; cin>>s;
  int x,y; cin>>x>>y;
  int n = s.size();
  VI a, b; // a:x方向に一度に進む回数 b:y方向に一度に進む回数
  int check = 1; // 1ならx方向に進む 0ならy方向に進む
  int cnt = 0;
  if(n==1&&s[0]=='T'){ //入力がTのみだったらさっさと処理(testcaseには含まれていない)
    if(x==0&&y==0) return cout<<"Yes"<<endl, 0;
    else return cout<<"No"<<endl, 0;
  }

  // x,yのabsはsのabs以下なので配列外アクセスは生じないのでは？

  rep(i,n){
    if(s[i]=='F'){
      cnt++;
    }else{
      if(check) a.PB(cnt); else b.PB(cnt);
      check++; check%=2; cnt=0;
    }
  }
  if(s[n-1]=='F'){
    if(check) a.PB(cnt); else b.PB(cnt);
  }
  int m = 2*n+1;
  // ここからDPでi回目にj+nの座標にいられるかboolで決めていく
  // まずはxについて
  int u = a.size();
  if(u==0){
    if(x) return cout<<"No"<<endl, 0;
  }else{
    bool dpx[u][m];
    rep(j,m) dpx[0][j] = false;
    dpx[0][a[0]+n] = true;
    reps(i,u-1){
      rep(j,m) dpx[i][j] = false;
      rep(j,m){
        if(dpx[i-1][j]){
          dpx[i][j+a[i]]=true; dpx[i][j-a[i]]=true;
        }
      }
    }
    if(!dpx[u-1][x+n]) return cout<<"No"<<endl, 0;
  }


  // 次にyについて
  u = b.size();
  if(u==0){
    if(y) return cout<<"No"<<endl, 0;
  }else{
    bool dpy[u][m];
    rep(j,m) dpy[0][j] = false;
    dpy[0][b[0]+n] = true; dpy[0][-b[0]+n] = true;
    reps(i,u-1){
      rep(j,m) dpy[i][j] = false;
      rep(j,m){
        if(dpy[i-1][j]){
          dpy[i][j+b[i]]=true; dpy[i][j-b[i]]=true;
        }
      }
    }
    if(!dpy[u-1][y+n]) return cout<<"No"<<endl, 0;
  }

  cout << "Yes" << endl;


  return 0;
}


Measured memory_bytes: 61824
/**
 * Title: D - Floor Function
 * Url: https://atcoder.jp/contests/abc165/tasks/abc165_d
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

ll funcA(ll a, ll b, ll x) {
    return floor(a*x/b);
}

ll funcB(ll a, ll b, ll x) {
    return a*floor(x/b);
}

int main() {
    ll a, b, n; cin >> a >> b >> n;
    if(n>=b) {
        cout << funcA(a,b,b-1) - funcB(a,b,b-1) << endl;
    } else {
        cout << funcA(a,b,n) - funcB(a,b,n) << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <queue>
#define N 300005
using namespace std;

typedef long long ll;
ll n, ans = -1e19, a[N], mn[N], mx[N];
priority_queue<ll> qn, qx;
int main()
{
	ll i, t;
	cin >> n;
	for (i = 0; i < n * 3; i++) scanf("%lld", &a[i]);
	for (i = 0; i < n; i++) mx[n - 1] += a[i], qx.push(-a[i]);
	for (; i < n * 2; i++) {
		qx.push(-a[i]);
		t = qx.top(), qx.pop();
		mx[i] = mx[i - 1] + a[i] + t;
	}
	for (i = n * 3 - 1; i >= n * 2; i--) mn[n * 2] += a[i], qn.push(a[i]);
	for (; i >= n; i--) {
		qn.push(a[i]);
		t = qn.top(), qn.pop();
		mn[i] = mn[i + 1] + a[i] - t;
	}
	for (i = n - 1; i < 2 * n; i++) ans = max(ans, mx[i] - mn[i + 1]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8308
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main() {


	int n, x[100];
	scanf("%d", &n);

	int i = 0, j = 0;


	for(i = 0; i < n; i++) {
		scanf("%d", &x[i]);
	}

	int sum = 0;
	int min = x[0];
	int max = x[0];

	for(i = 0; i < n; i ++){
		if(x[i] < min) {
			min = x[i];
		}
		if(x[i] > max) {
			max = x[i];
		}
	}
	int sum_min = (100-1)*100*1000;

	for(i = min; i <= max; i++){
		for(j = 0; j < n; j++) {
			sum += (x[j]-i) * (x[j]-i);
		}
		if(sum_min > sum) {
			sum_min = sum;
		}
		sum = 0;
	}

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


	return 0;


}


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

int64_t solve(const string &S, char a, char b, char c) {
    int N = S.size();
    int64_t ans = 0;
    int64_t A = 0, C = 0;
    for(int i = 0; i < N; ++i) {
        if(S[i] == c) C++;
    }
    for(int i = 0; i < N; ++i) {
        if(S[i] == c) C--;
        if(S[i] == b) {
            ans += A * C;
        }
        if(S[i] == a) A++;
    }
    return ans;
}

int main() {
    int N; cin >> N;
    string S; cin >> S;
    int64_t ans = solve(S, 'R', 'G', 'B');
    ans += solve(S, 'B', 'G', 'R');

    ans += solve(S, 'R', 'B', 'G');
    ans += solve(S, 'G', 'B', 'R');

    ans += solve(S, 'G', 'R', 'B');
    ans += solve(S, 'B', 'R', 'G');

    for(int j = 1; j < N - 1; ++j) {
        for(int a = 1; a < N; ++a) {
            int i = j - a, k = j + a;
            if(i < 0 || k >= N) continue;
            if((S[i] != S[j]) and (S[i] != S[k]) and (S[j] != S[k])) ans--;
        }
    }
    cout << ans << '\n';
    return 0;
}


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

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

int n, k;
ll x[60], y[60];

int main() {
   cin >> n >> k;
   rep (i, n) {
      cin >> x[i] >> y[i];
   }

   ll ans = 1LL << 62;
   rep (xi, n) {
      rep (xj, n) {
         rep (yi, n) {
            rep (yj, n) {
               if (x[xi] < x[xj] && y[yi] < y[yj]) {
                  int cnt = 0;
                  rep (p, n) {
                     if (x[p]>=x[xi] && x[p]<=x[xj] && y[p]>=y[yi] && y[p]<=y[yj]) {
                        cnt++;
                     }
                  }
                  if (cnt >= k) {
                     ans = min(ans, (x[xj] - x[xi]) * (y[yj] - y[yi]));
                  }
               }
            }
         }
      }
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<int,int> P;
typedef pair<int,P> P2;
typedef pair<int,P2> P3;
const int MAX=1000000007;
 
int dy[4]={-1,0,1,0},dx[4]={0,-1,0,1};
bool check(int n,int m,int x,int y) {
  if(x<0 || x>=n) return false;
  if(y<0 || y>=m) return false;
  return true;
}
int d[1001][1001][4];
priority_queue<P3,vector<P3>,greater<P3> > que;
 
int main() {
  int n,m,k;
  while(cin >> n >> m >> k && (n||m||k)) {
    while(!que.empty()) que.pop();
 
    string c;
    string s[n];
    cin >> c;
    for(int i=0; i<n; i++) cin >> s[i];
    for(int i=0; i<n; i++) {
      for(int j=0; j<m; j++) {
    for(int l=0; l<4; l++) d[i][j][l]=MAX;
      }
    }
 
    int sx,sy,tx,ty;
    for(int i=0; i<n; i++) {
      for(int j=0; j<m; j++) {
    if(s[i][j]=='S') {
      sx=i;sy=j;
    }
    if(s[i][j]=='G') {
      tx=i;ty=j;
    }
      }
    }
 
    que.push(P3(0,P2(1,P(sx,sy))));
    d[sx][sy][1]=0;
    bool ck=false;
    while(!que.empty()) {
      P3 p=que.top();que.pop();
      int j=p.F,z=p.S.F,nx=p.S.S.F,ny=p.S.S.S;
      if(nx==tx && ny==ty) {
    ck=true;
    break;
      }
 
 
      int x=nx+dx[z],y=ny+dy[z];
      if(check(n,m,x,y) && s[x][y]!='#' && d[x][y][z]>j) {
    d[x][y][z]=j;
    que.push(P3(j,P2(z,P(x,y))));
      }
       
      x=nx;y=ny;
      int z2=z;
      bool b[4];
      memset(b,false,sizeof(b));
      b[z]=true;
      for(int i=j; i<k; i++) {
    if(c[i]=='L') z2--;
    else z2++;
    if(z2<0) z2+=4;
    else if(z2>=4) z2-=4;
    if(b[z2]) continue;
    b[z2]=true;
    if(d[x][y][z2]>i+1) {
      d[x][y][z2]=i+1;
      que.push(P3(i+1,P2(z2,P(x,y))));
    }
      }
    }
    if(ck) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, s; cin>>n>>s;
	ll ans=-1;
	ll M;
	for(M=2; M*M<=n; M++){
		ll sum=0, cur=n;
		do{
			sum+=cur%M;
		}while(cur/=M);
		if (sum==s){
			ans = M;
			break;
		}
	}
	if (ans<0){
		for(ll i=M; i>=1; i--){
			ll left = n/(i+1)+1;
			ll right = n/i;
			if (left>right || i*i>=n) continue;
			ll D = n%left - s + i;
			if (D>=0 && D%i == 0 && left+D/i <= right && left+D/i>=2){
				ans = left+D/i;
				break;
			}
		}
	}
	if (ans<0 && s==n){
		ans = s+1;
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>S
#define PP pair<P,P>
using namespace std;

int main(){
    int a,b,q; cin >> a >> b >> q;
    vector<ll> s(a),t(b);
    rep(i,a) cin >> s[i];
    rep(i,b) cin >> t[i];

    rep(i,q){
        ll x; cin >> x;
        ll ans=400000000000;
        auto ids=lower_bound(all(s),x);
        auto idt=lower_bound(all(t),x);
        ll sl,sr,tl,tr;
        sl=sr=tl=tr=-1;
        if(ids!=s.begin()) sl=s[ids-s.begin()-1];
        if(idt!=t.begin()) tl=t[idt-t.begin()-1];
        if(ids!=s.end()) sr=s[ids-s.begin()];
        if(idt!=t.end()) tr=t[idt-t.begin()];
        //cout << sl << ' ' << sr << ' ' << tl << ' ' << tr << endl;

        if(sl!=-1) sl=x-sl;
        if(sr!=-1) sr=sr-x;
        if(tl!=-1) tl=x-tl;
        if(tr!=-1) tr=tr-x;
        if(sl!=-1 && tl!= -1) ans=min(ans,max(sl,tl));
        if(sr!=-1 && tr!= -1) ans=min(ans,max(sr,tr));
        if(sl!=-1 && tr!= -1) ans=min(ans,sl*2+tr);
        if(tl!=-1 && sr!= -1) ans=min(ans,tl*2+sr);
        if(sr!=-1 && tl!= -1) ans=min(ans,sr*2+tl);
        if(tr!=-1 && sl!= -1) ans=min(ans,tr*2+sl);
        cout << ans << endl;
    }
return 0;
}


Measured memory_bytes: 2944
import java.util.Scanner;

public class Main {
	static int cnt=0;
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for(i = 0; i < n; i++) {
        	a[i] = sc.nextInt();
        }
        a = sellect(a, n);
        outPut(a, n);
        System.out.println(cnt);
	}
	
	public static int[] sellect(int[] a, int n) {
		int tmp;
		for(int i = 0; i < n-1; i++){
			boolean flag = false;
			int minj = i;
			for(int j = i+1; j < n; j++) {
				if(a[j] < a[minj]) {
					minj = j;
					flag = true;
				}
			}
			if(flag) cnt++;
			tmp = a[i];
			a[i] = a[minj];
			a[minj] = tmp;
		}
		return a;
	}
	public static void outPut(int[] a, int n) {
		for(int i = 0; i < n-1; i++) {
			System.out.print(a[i] + " ");
		}
		System.out.println(a[n-1]);
	}
}


Measured memory_bytes: 26400
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Rep(i, N) for(int i = 0; i < N; i++)
 
signed main()
{
  int N, K;
  int A[5005];
  
  int it = 0, cnt = 0;
  
  cin >> N >> K;
 
  Rep(i, N) cin >> A[i];
 
  sort(A, A + N, greater<int>());
 
  Rep(i, N) {
    int sum = 0, j;
    for(j = i; j < N; j++) {
      sum += A[j];
      if(sum >= K) {
	it = max(it, j + 1);
	sum -= A[j];
      }
    }
  }
 
  cout << N - it << endl;
 
  return 0;
}
 
  

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	var ans int
	d := int(1e9) + 7
	for i := k; i <= n+1; i++ {
		min := (i - 1) * i / 2
		max := (2*n - i + 1) * i / 2
		ans += max - min + 1
	}
	fmt.Println(ans % d)
}


Measured memory_bytes: 1756
fn main() {
  let (n, z, w): (usize, isize, isize) = get::tuple3();
  let mut xs: Vec<isize> = get::list();

  if xs.len() == 1 {
    println!("{}", (xs[0] - w).abs());
    return
  }

  xs.insert(0, z);

  let s1 = (xs[n] - w).abs();
  let s2 = (xs[n-1] - xs[n]).abs();
  let ans = std::cmp::max(s1, s2);

  println!("{}", ans);
}

#[allow(dead_code)]
mod get {
  use std::io::*;
  use std::str::*;

  pub fn val<T: FromStr>() -> T {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().parse::<T>().ok().unwrap()
  }

  pub fn vals<T: FromStr>(n: usize) -> Vec<T> {
    let mut vec: Vec<T> = vec![];
    for _ in 0 .. n {
      vec.push(val());
    }
    vec
  }

  pub fn tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    (x, y)
  }

  pub fn tuples<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)> {
    let mut vec: Vec<(T1, T2)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple());
    }
    vec
  }

  pub fn tuple3<T1: FromStr, T2: FromStr, T3: FromStr>() -> (T1, T2, T3) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    let z = it.next().unwrap().parse::<T3>().ok().unwrap();
    (x, y, z)
  }

  pub fn tuple3s<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)> {
    let mut vec: Vec<(T1, T2, T3)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple3());
    }
    vec
  }

  pub fn list<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
  }

  pub fn lists<T: FromStr>(h: usize) -> Vec<Vec<T>> {
    let mut mat: Vec<Vec<T>> = vec![];
    for _ in 0 .. h {
      mat.push(list());
    }
    mat
  }

  pub fn chars() -> Vec<char> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().chars().collect()
  }
}



Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

int main() {
  int a, b;
  cin >> a >> b;
  cout << max({a + b, a - b, a * b}) << endl;
  return 0;
}


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

int main(){
  int n;
  cin>>n;
  vector<P> p(n);
  rep(i,n) cin>>p[i].second>>p[i].first;
  sort(p.begin(),p.end());
  ll t=0;
  rep(i,n){
    t+=p[i].second;
    if(p[i].first<t){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  

  return 0;
}


Measured memory_bytes: 1792
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for(int n=0;n<N;n++){
        	a[n]=sc.nextInt();
        }
        
        //let m = a[1]*a[2]*...*a[n-1]-1
        //m%a[n] = a[n]-1
        int ans = 0;
        for(int n=0;n<N;n++){
        	ans += (a[n]-1);
        }
        System.out.println(ans);
    }
}

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

typedef long long ll;
const int mod=1e9+7;

int main(){
	int a, b;
	cin >> a >> b;
	int ans=-a;
	for(int i=1; i<b-a; i++)
		ans += i;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//Author:: Pham Ngoc Minh- Chuyen Thai Binh
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
#define fl float
#define db double
#define ii pair<ll,ll>
#define pii pair<ii,ii>
#define ford(i,a,b) for(int i=a;i<=b;i++)
#define foru(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,a,b) for(int i=a;i<b;i++)
#define oo 10000000000001
#define ooo -1000000000001
#define bost  ios_base::sync_with_stdio(false); cin.tie(0);
int const maxn=1e5+5;
int n,k,a[maxn],dp[maxn];
void nhap()
{
    cin>>n>>k;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        if(i>=3)
        {
            dp[i]=oo;
        }
    }
}
void qhd()
{
    dp[1]=0;
    dp[2]=abs(a[2]-a[1]);
    for(int i=3; i<=n; i++)
    {
        for(int j=1;j<=k;j++){
            if(i-j>0){
                dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
            }
        }
    }
}
void kq()
{
    cout<<dp[n];
}
int main()
{
    bost
    nhap();
    qhd();
    kq();
    //Write Code Here :>>>>
    return 0;
}
// I love Chuyen Thai Binh Verry much ! Now, you alaways in my code of me <3
// Chuyen Thai Binh La Nha :>>



Measured memory_bytes: 1024
#include<iostream>
using namespace std;
bool a[15] = { false };
bool f(int n) {
	while (n > 0) {
		int p = n % 10;
		if (a[p])return false;
		n /= 10;
	}return true;
}
int main() {
	int n, k; cin >> n >> k;
	for (int i = 0; i < k; i++) { int p; cin >> p; a[p] = true; }
	while (!f(n))n++;
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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

    ll a[n];
    ll b[n];

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

    pair<ll, ll> x[n];
    x[0].first = a[0];
    x[0].second = 1;
    rep(i, 1, n){
        if(a[i - 1] < a[i]){
            x[i].second = 1;
        }else if(a[i - 1] == a[i]){
            x[i].second = 0;
        }else{
            cout << 0 << endl;
            return 0;
        }
        x[i].first = a[i];
    }

    if(x[n - 1].second == 1){
        if(x[n - 1].first != b[n - 1]){
            cout << 0 << endl;
            return 0;
        }else{
            x[n - 1].first = b[n - 1];
            x[n - 1].second = 1;
        }
    }else{
        if(x[n - 1].first < b[n - 1]){
            cout << 0 << endl;
            return 0;
        }else{
            x[n - 1].first = b[n - 1];
            x[n - 1].second = 1;
        }
    }
    rrep(i, n - 2, 0){
        if(b[i + 1] < b[i]){
            if(x[i].second == 1){
                if(x[i].first != b[i]){
                    cout << 0 << endl;
                    return 0;
                }else{
                    x[i].first = b[i];
                    x[i].second = 1;
                }
            }else{
                if(x[i].first < b[i]){
                    cout << 0 << endl;
                    return 0;
                }else{
                    x[i].first = b[i];
                    x[i].second = 1;
                }
            }
        }else if(b[i + 1] == b[i]){
            if(x[i].second == 1){
                if(x[i].first > b[i]){
                    cout << 0 << endl;
                    return 0;
                }
            }else{
                x[i].first = min(x[i].first, b[i]);
            }
        }else{
            cout << 0 << endl;
            return 0;
        }
    }

    ll sum = 1;
    rep(i, 0, n){
        if(x[i].second == 0){
            sum *= x[i].first % 1000000007;
            sum %= 1000000007;
        }
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3328
object Main extends App {
  val Array(n, m) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
  var ACseq = Map.empty[Int, Int]
  var wacnt = Map.empty[Int, Int]

  (1 to m).foreach { i =>
   // println(ACseq)
   // println(wacnt)
    val Array(p, s) = scala.io.StdIn.readLine.split(" ")
    val pp = p.toInt

    if (!ACseq.isDefinedAt(pp)) {
      if (s == "AC") {
        val wacnt_tmp = wacnt.getOrElse(pp, 0)
        ACseq += (pp -> wacnt_tmp)
      } else {
        val wacnt_tmp = wacnt.getOrElse(pp, 0)
        wacnt += (pp -> (wacnt_tmp + 1))
      }
    }
  }
  println(ACseq.size + " " + ACseq.foldLeft(0)(_ + _._2))
}


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

using namespace std;

const int N = 301;

int n;
double memo[N][N][N];

void init() {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < N; k++) {
        memo[i][j][k] = -1.0;
      }
    }
  }
}

double dp(int a, int b, int c) {
  if (!a && !b && !c) return 0.0;
  if (memo[a][b][c] != -1.0) return memo[a][b][c];
  int here = a + b + c;
  double ans = (n / (double) here);
  if (a) {
    ans += (a / (double) here) * dp(a - 1, b, c);
  }
  if (b) {
    ans += (b / (double) here) * dp(a + 1, b - 1, c);
  }
  if (c) {
    ans += (c / (double) here) * dp(a, b + 1, c - 1);
  }
  return memo[a][b][c] = ans;
}

int main() {
  fixed(cout); cout.precision(12);
  init();
  cin >> n;
  int cnt[4] = {};
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
  }
  cout << dp(cnt[1], cnt[2], cnt[3]) << endl;
  return 0;
}


Measured memory_bytes: 213504
// Contest: AtCoder Beginner Contest 166 (https://atcoder.jp/contests/abc166)
// Problem: E: This Message Will Self-Destruct in 5s (https://atcoder.jp/contests/abc166/tasks/abc166_e)


// region {{{ boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion }}}

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

    int n; cin >> n;
    vi a(n);
    trav(ai, a) cin >> ai;

    ll cnt = 0;
    map<int, int> s;
    rep(i, n)
        cnt += s[i - a[i]], s[i + a[i]]++;
    cout << cnt << '\n';

    return 0;
}

Measured memory_bytes: 20932
n,k = map(int,input().split())
a = list(map(int,input().split()))
p = []
m = []
mod = 10**9 + 7
if n == k:
  ans = 1
  for x in a:
    ans *= x
    ans %= mod
  print(ans)
  exit()
zero = 0
for x in a:
  if x == 0:
    zero += 1
  if x > 0:
    p.append(x)
  else:
    m.append(-x)
p.sort(reverse=True)
m.sort(reverse=True)
#print(zero,p,m)
nowp = 0
nowm = 0
lenp = len(p)
lenm = len(m)
if k + zero > n:
  print(0)
  exit()
n -= zero
ans = 1
def inv(x):
  y = 1
  while x != 1:
    y *= mod // x + 1
    y %= mod
    x -= mod % x
  return y
pp = 0
for _ in range(k):
  if nowp == lenp:
    ans *= m[nowm]
    ans *= -1
    ans %= mod
    nowm += 1
    pp = 1-pp
  elif nowm == lenm:
    ans *= p[nowp]
    ans %= mod
    nowp += 1
  elif p[nowp] >= m[nowm]:
    ans *= p[nowp]
    ans %= mod
    nowp += 1
    #print('$$')
  else:
    ans *= m[nowm]
    ans *= -1
    ans %= mod
    nowm += 1
    pp = 1-pp
    #print('$')
  #print(pp,nowp,nowm)
#print(pp,ans)
if pp == 0:
  print(ans)
  exit()
if lenm == 0:
  print(ans)
  exit()
if lenp == 0:
  ans = 1
  m.reverse()
  for d in range(k):
    ans *= -m[d]
    ans %= mod
  print(ans)
  exit()
ans *= -1
ans %= mod
if lenp == nowp:
  ans *= inv(p[-1])
  ans *= m[nowm]
  ans %= mod
  print(ans)
  exit()
if lenm == nowm:
  ans *= inv(m[-1])
  ans *= p[nowp]
  ans %= mod
  print(ans)
  exit()
if nowp == 0:
  ans *= inv(m[nowm-1])
  ans *= p[0]
  ans %= mod
  print(ans)
  exit()
if nowm == 0:
  ans *= inv(p[nowp-1])
  ans *= m[0]
  ans %= mod
  print(ans)
  exit()
pl = p[nowp-1]
pr = p[nowp]
ml = m[nowm-1]
mr = m[nowm]
if mr * ml > pl * pr:
  ans *= inv(pl)
  ans *= mr
  ans %= mod
  print(ans)
else:
  ans *= inv(ml)
  ans *= pr
  ans %= mod
  print(ans)

Measured memory_bytes: 104820