akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int H, W; cin >> H >> W;
  int N; cin >> N;
  vector<int> vs(N);
  rep (i, N) {
    cin >> vs[i];
  }

  int g[H][W];
  int y = 0, x = 0;
  int pos = 0;
  bool right = 1;
  while (y < H) {
    while (0 <= x && x < W) {
      while (vs[pos] == 0) {
        pos++;
        assert(pos < vs.size());
      }
      vs[pos]--;
      g[y][x] = pos + 1;
      if (right) x++;
      else x--;
    }
    if (x == W) {
      x = W - 1;
      right = 0;
    } else {
      x = 0;
      right = 1;
    }
    y++;
  }

  rep(i, H) {
    rep(j, W) {
      cout << g[i][j];
      if (j == W - 1) cout << "\n";
      else cout << " ";
    }
  }

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;

int main(){
   string X;
   cin >> X;
   stack <char> st;
   st.push(X[0]);
   int ans = X.size();
   for(int i = 1; i < X.size(); i++){
       if(!st.empty() && st.top() == 'S' && X[i] == 'T'){
           st.pop();
           ans -= 2;
       } else {
           st.push(X[i]);
       }
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;
#define reverse(s) reverse(s.begin(),s.end())

int main(){
    int c[3][3];

    rep(i,3){
        rep(j,3){
            cin >> c[i][j];
        }
    }

    int x[3],y[3];
    x[0] = 0;

    rep(i,3)    y[i] = c[0][i] - x[0];
    rep(i,3)    x[i] = c[i][0] - y[0];

    bool good(true);

    rep(i,3){
        rep(j,3){
            if(x[i]+y[j]!=c[i][j])
                good = false;
        }
    }

    if(good)
        puts("Yes");
    else
        puts("No");

    return 0;
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;

fn is_kaibun(s: &str) -> bool {
    let ss: String = s.chars().rev().collect();
    s == ss
}

fn main() {
    input! {
        s: String,
    }

    if is_kaibun(&s) &&  is_kaibun(&s[0..((s.len() - 1) / 2)]) && is_kaibun(&s[(s.len() + 2)/2..s.len()]) {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            long n = long.Parse(Console.ReadLine());

            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            long ret = 1;

            if (inputLongArray.Where(r => r == 0).Any())
            {
                ret = 0;
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    long b = inputLongArray[i];
                    if (IsOverFlow(ret, b) || (ret * b) > 1000000000000000000)
                    {
                        ret = -1;
                        break;
                    }
                    else
                    {
                        ret *= b;
                    }
                }
            }

            string result = ret.ToString();

            Console.WriteLine(result);

            Console.Out.Flush();
        }

        /// <summary>
        /// a * b > LONGMAX
        /// a > LONGMAX / b ならNG
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public static bool IsOverFlow(long a, long b)
        {
            return a > long.MaxValue / b;
        }
    }
}


Measured memory_bytes: 37188
import java.util.*;

class Main{
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int t = sc.nextInt();
	int a = sc.nextInt();

        int[] h = new int[n];
	for(int i = 0;i < n;i++){
	    h[i] = sc.nextInt();
	}

	double min = Math.abs(t - h[0]*0.006 - a);
	int id = 0;

	for(int i = 1;i < n;i++){
	    double dif = Math.abs(t - h[i]*0.006 - a);
	    if(min > dif){
		min = dif;
		id = i;
	    }
	}

	System.out.println(id+1);
    }
}


Measured memory_bytes: 23016
#include <iostream>
#include <string.h>
#include <algorithm>
typedef long long ll;
using namespace std;

int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
    int p=0;
	// ユークリッドの方法
	while( m > n )
	{
        m = m/2;
        p+=1;
	}
	return p;
}//gcd

int main()
{
    ll a,b,c;
    cin >> a >> b;
    if((b+a)%2 == 1)
    {
        cout << "IMPOSSIBLE";
    }else
    {
        c = (b+a)/2;
        cout << c;
    }
}

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

const int di[4] = {
	1, 0, -1, 0
};
const int di2[4] = {
	0, 1, 0, -1
};

const int max_size = 20;
int move(char area[max_size+2][max_size+2], int sh, int sw){
	if(area[sh][sw] == '#') return 0;
	int count = 1;
	area[sh][sw] = '#';
	for(int i = 0; i < 4; i++){
		count += move(area, sh + di[i], sw + di2[i]);
	}
	return count;
}

int main(){
	char area[max_size+2][max_size+2];
	int sh, sw;
	int h, w;
	while(cin >> w >> h){
		if(w == 0 && h == 0) break;
		for(int i = 0;i < max_size+2; i++){
			for(int j = 0; j < max_size+2; j++){
				area[i][j] = '#';
			}
		}
		for(int i = 1; i <= h; i++){
			for(int j = 1; j <= w; j++){
				cin >> area[i][j];
				if(area[i][j] == '@'){
					sh = i; sw = j;
				}
			}
		}
		cout << move(area, sh, sw) << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void)
{
	int a, b, tai;
	int tyou = 0;
	int hisi = 0;
	
	while (scanf("%d", &a) != EOF){
		scanf(",%d,%d", &b, &tai);
		
		if (tai * tai == a * a + b * b){
			tyou++;
		}
		if (a == b){
			hisi++;
		}
	}
	printf("%d\n%d\n", tyou, hisi);
	
	return (0);
}

Measured memory_bytes: 596
n=int(input())
a=list(map(int,input().split()))
even_cnt=0
odd_cnt=0
for i in a:
    if i%2==0:
        even_cnt+=1
    else:
        odd_cnt+=1
if 1<=odd_cnt:
    even_cnt+=odd_cnt//2
    odd_cnt=odd_cnt%2
    even_cnt=even_cnt%2
    if even_cnt==1 and odd_cnt==1:
        print("NO")
    else:
        print("YES")
else:
    print("YES")

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


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);


    int a;
    cin >> a;

    cout << a + a*a + a*a*a << endl;


    return 0;
}



Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 100005
#define int long long
ll p[maxn],q[maxn],r[maxn];
int x,y,c,a,b;
#pragma GCC optimize(2)
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>x>>y>>a>>b>>c;
    for (int k = 1; k <maxn ; ++k) {
        p[k]=q[k]=r[k]=20000000000;
    }
    for (int i = 1; i <=a ; ++i) {
        cin>>p[i];
    }
    for (int i = 1; i <=b ; ++i) {
        cin>>q[i];
    }
    for (int i = 1; i <=c ; ++i) {
        cin>>r[i];
    }
    sort(p+1,p+1+a);
    sort(q+1,q+1+b);
    sort(r+1,r+1+c);
    ll ans=0;
    int cnt=0;
    for (int j = a; j >=1 ; --j) {
        ans+=p[j];
        cnt++;
        if(cnt==x)break;
    }
    cnt=0;
    for (int j = b; j >=1 ; --j) {
        ans+=q[j];
        cnt++;
        if(cnt==y)break;
    }
    int l=a-x+1,rs=b-y+1;
    int pos=c;
    while(pos>=1){
        if(l>a&&rs>b)break;
        if(r[pos]<=q[rs]&&r[pos]<=p[l])break;
        if(q[rs]<=p[l]&&r[pos]>q[rs]){
            ans-=q[rs];
            rs++;
            ans+=r[pos];
            pos--;
        }else{
            if(r[pos]>p[l]){
                ans-=p[l];
                l++;
                ans+=r[pos];
                pos--;}
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
        int a[5];
        int flag,souwa = 0;
        int kettei =10;
        int last = 0;
        for(int i = 0; i < 5; i++){
                cin >> a[i];
                flag = a[i] % 10;
                if(flag < kettei && flag != 0){
                        kettei = flag;
                        last = i;
                }
        }
        if(kettei == 10){
                kettei = 0;
        }
        for(int j = 0; j < 5; j++){
                if(j != last && a[j] % 10 != 0){
                        a[j] = a[j] + (10 - a[j] % 10);
                }
                souwa = souwa + a[j];
        }
        cout << souwa << "\n";
}

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

struct StNode
{
  StNode* m_poParnt;
  StNode* m_poLeft;
  StNode* m_poRigt;
  int m_nKey;

  StNode(int nNo) :
    m_poParnt(nullptr), m_poLeft(nullptr), m_poRigt(nullptr), m_nKey(nNo)
  { }
};

void fnInsert(StNode*& rpoRoot, StNode* poNewMe)
{
  StNode*  poParnt = nullptr;
  StNode** ppoNode = &rpoRoot;

  while (*ppoNode)
  {
    poParnt = *ppoNode;
    if (poNewMe->m_nKey < poParnt->m_nKey)
      ppoNode = &poParnt->m_poLeft;
    else
      ppoNode = &poParnt->m_poRigt;
  }
  poNewMe->m_poParnt = poParnt;
  *ppoNode = poNewMe;
}

void fnInOrder(StNode* poNode)
{
  if (!poNode)  return;

  fnInOrder(poNode->m_poLeft);
  cout << " " << poNode->m_nKey;
  fnInOrder(poNode->m_poRigt);
}

void fnPreOrder(StNode* poNode)
{
  if (!poNode)  return;

  cout << " " << poNode->m_nKey;
  fnPreOrder(poNode->m_poLeft);
  fnPreOrder(poNode->m_poRigt);
}

void fnBinSchTree(StNode*& rpoRoot)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  for (int i = 0; i < nMaxSiz; ++i)
  {
    string sCmd;
    cin >> sCmd;
    if (sCmd[0] == 'i')
    {
      int nNo;
      cin >> nNo;
      StNode* poNewNod = new StNode(nNo);
      fnInsert(rpoRoot, poNewNod);
    }
    if (sCmd[0] == 'p')
    {
      fnInOrder(rpoRoot);
      cout << endl;
      fnPreOrder(rpoRoot);
      cout << endl;
    }
  }
}

void fnPstOrder(StNode* poNode)
{
  if (!poNode)  return;

  fnPstOrder(poNode->m_poLeft);
  fnPstOrder(poNode->m_poRigt);
  delete poNode;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  StNode* poRoot = nullptr;

  fnBinSchTree(poRoot);
//fnPstOrder(poRoot);
  return 0;
}

Measured memory_bytes: 26576
n=int(input())
s=input()
left=set()
ans=0

for i in range(n-1):
    left.add(s[i])
    right=set()
    for j in range(i+1,n):
        right.add(s[j])
    cnt=0
    for ll in left:
        if ll in right:
            cnt+=1
    ans=max(ans,cnt)

print(ans)

Measured memory_bytes: 80708
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int k,n;
  cin  >> k >> n;
  vi a(n);
  rep(i,n)cin >> a[i];
  int mx = 0;
  int ans = 0;
  srep(i,1,n){
    ans += abs(a[i]-a[i-1]);
    maxs(mx,abs(a[i]-a[i-1]));
  }
  ans += abs(a[n-1]-k - a[0]);
  maxs(mx,abs(a[n-1]-k - a[0]));
  cout<<ans-mx<<endl;
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,nr,m=0,s=0;
    cin>>n;
    while(n--)
    {
        cin>>nr;
        m=max(m,nr);
        s+=nr;
    }
    if(m<s-m)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
n,k = gets.chomp.split(' ').map(&:to_i)

if k.even?
  mod_zero = [*1..n].select{ |num| num % k == 0 }
  mod_half_k = [*1..n].select{ |num| num % k == k/2 }
  puts mod_zero.size ** 3 + mod_half_k.size ** 3
else
  puts [*1..n].select{ |num| num % k == 0 }.size ** 3
end

Measured memory_bytes: 9724
# -*- coding: utf-8 -*-
#ARC082C
import copy
import sys
import math

n = int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

hoge.sort()
hoge.append(-1)
a=0
b=0
c=1
maxhoge=0
for i in range(0,n):
	if(hoge[i]!=hoge[i+1]):
		if(i!=n-1):
			if(hoge[i+1]-hoge[i]==1):
				a=b
				b=c
				c=1
			elif(hoge[i+1]-hoge[i]==2):
				a=c
				b=0
				c=1
			else:
				a=0
				b=0
				c=1
	else:
		c+=1
#	print("i:{} | {} {} {}".format(i,a,b,c))

	maxhoge=max(maxhoge,a+b+c)



#print(hoge)
print(maxhoge)



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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, a, b;

int main() {
	cin >> n >> a >> b;
	
	LL ans = (n - 2) * (b - a) + 1;
	if((a > b) || (n == 1 && a != b)) { ans = 0; }
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(int i=(ll)(b);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


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

  vector<ll>dp(n,1e18),h(n);
  rep(i,n)cin>>h[i];
  dp[0]=0;
  dp[1]=abs(h[1]-h[0]);
  rep(i,n-2){
    chmin(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
    chmin(dp[i+2],dp[i+1]+abs(h[i+2]-h[i+1]));
  }
  cout<<dp[n-1]<<endl;



  return 0;

}


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

int main(){
    int h,w;
    cin>>h>>w;
    int sy,sx,gy,gx;
    cin>>sy>>sx>>gy>>gx;
    --sy; --sx; --gy; --gx;
    vector<string> s(h);
    for(int i=0;i<h;++i) cin>>s[i];

    deque<pair<int,int>> dq;
    vector<vector<int>> dist(h,vector<int>(w,1e9));
    dist[sy][sx]=0;
    dq.push_back(pair<int,int>(sy,sx));
    
    static const int dx[]={1,0,-1,0};
    static const int dy[]={0,1,0,-1};

    while(!dq.empty()){
        pair<int,int> cur=dq.front();
        dq.pop_front();
        int y=cur.first;
        int x=cur.second;
        for(int i=y-2;i<=y+2;++i){
            for(int j=x-2;j<=x+2;++j){
                if(!(0<=i&&i<h&&0<=j&&j<w&&s[i][j]=='.')) continue;
                int warp=(abs(y-i)+abs(x-j)!=1);
                int tdist=dist[y][x]+warp;
                if(dist[i][j]>tdist){
                    dist[i][j]=tdist;
                    if(warp) dq.push_back(pair<int,int>(i,j));
                    else dq.push_front(pair<int,int>(i,j));
                }
            }
        }
    }
    
    cout<<(dist[gy][gx]==1e9?-1:dist[gy][gx])<<endl;
}

Measured memory_bytes: 9476
#include<cstdio>
using namespace std;
int main(){
    int a,b,c,aa,bb,cc,ans=0;
    scanf("%d %d %d",&a,&b,&c);
    while(a%2==0&&b%2==0&&c%2==0){
        aa=(b+c)/2;
        bb=(a+c)/2;
        cc=(a+b)/2;
        if(a==aa&&b==bb&&c==cc){
            printf("-1\n");
            return 0;
        }
        ans++;
        a=aa;
        b=bb;
        c=cc;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  sort(a.rbegin(),a.rend());
  Int x=0,y=0;
  for(Int i=0;i<n;i++) if(i&1) y+=a[i];else x+=a[i];
  cout<<x-y<<endl;
  return 0;
}


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

using namespace std;

void Main() {
    int A, B;
    cin >> A >> B;
    cout << (A * B) - A - B + 1 << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
 
 
int main(){
  string str;
 

  cin >> str;

  cout << str.substr(0,4) << " "<<str.substr(4)<<endl;



}


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

int main(){
  int N;
  cin >> N;
  int H[N];
  for(int i = 0; i < N; i++){
    cin >> H[i];
  }
  int count = 0;
  int max = 0;
  for(int i = 0; i < N - 1; i++){
    if(H[i] >= H[i + 1]){
      count++;
    }
    else{
      if(count > max){
        max = count;
      }
      count = 0;
    }
  }
  if(max > count){
    cout << max << endl;
  }
  else{
    cout << count << endl;
  }
}

Measured memory_bytes: 640
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

fn main() {
    input! {
        s_: String,
    }
    let mut s: Vec<char> = s_.chars().collect();
    s[3] = '8';
    println!("{}", s.iter().collect::<String>());
}


Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		while(s.hasNext()){
			String a = s.next();
			int sum = 0;
			int n[]=new int[a.length()];
			for(int i = 0; i < a.length(); i++){

				switch (a.charAt(i)){
				case 'I': n[i] = 1; break;
				case 'V': n[i] = 5; break;
				case 'X': n[i] = 10; break;
				case 'L': n[i] = 50; break;
				case 'C': n[i] = 100; break;
				case 'D': n[i] = 500; break;
				case 'M': n[i] = 1000; break;

				}
			}
			for(int i = 0; i < a.length();i++){
				if(i < a.length() - 1 && n[i] < n[i+1])sum -= n[i];
				else sum += n[i];
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 25656
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int N,T,A,mini=100000000,minpos=0;

int main(){
    cin>>N>>T>>A;
    int H[1000];
    rep(i,N){
        cin>>H[i];
        if(mini>abs(A*1000-(T*1000-H[i]*6))){
            mini=abs(A*1000-(T*1000-H[i]*6));
            minpos=i;
        }
    }
    out(minpos+1);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#pragma GCC optimize(2)
#define int long long
#define MAXN 5000
#define INF 1e9 + 7

using namespace std;

inline int read()
{
	int x = 0, f = 1; char c = getchar();
	while(c > '9' || c < '0'){ if (c == '-') f = -1; c = getchar(); }
	while(c >= '0' && c <= '9'){ x = x * 10 + (c ^ 48); c = getchar(); }
	return f * x;
}

int a[MAXN], sum[MAXN][MAXN];

signed main()
{
	int n = read();
	for (int i = 1; i <= n; i++) a[i] = read();
	sort(a + 1, a + n + 1);
	for (int i = n; i >= 1; i--)
	{
		sum[i][a[i]]++;
		for (int j = 1; j <= 2000; j++) sum[i][j] += sum[i][j - 1];
		for (int j = 1; j <= 2000; j++) sum[i][j] += sum[i + 1][j];
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = i + 1; j <= n; j++)
		{
			int u = a[i], v = a[j];
			ans += sum[j + 1][u + v - 1] - sum[j + 1][abs(u - v)];
		}
	}
	cout << ans << endl;
	return 0;
}
/*
7
218 786 704 233 645 728 389
*/

Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define d double
#define INF INT_MAX
#define output for(int i=0;i<sizex;i++) { for(int j=0;j<sizey;j++) { cout << moveChart[i][j] << " "; }cout<<endl; }cout<<endl;

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

    int n; cin >> n;

    bool dp[101]; memset( dp, 0, sizeof dp ); dp[n] = true;

    for(int i=n;i>0;i--){
        if( dp[i] ){
            if( i - 7 >= 0 ) dp[i-7] = true;
            if( i - 4 >= 0 ) dp[i-4] = true; 
        }
    }

    if( dp[0] ) cout << "Yes" << endl;
    else        cout << "No" << endl;

}

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

using namespace std;

int main() {
  int N; cin >> N;
  int sumL = 0;
  int maxL = 0;
  for(int i = 0; i < N; i++){
    int l; cin >> l;
    if(maxL < l) {
      sumL += maxL;
      maxL = l;
    } else {
      sumL += l;
    }
  }
  cout << ((maxL < sumL) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double db;
typedef vector<ll> VI;
typedef vector<pair<ll,ll> > VII;
typedef map<ll,ll> mll;
typedef pair<ll,ll> pll;
//
#define mp make_pair
#define pb push_back
#define pob pop_back
#define eb emplace_back
#define F first
#define S second
#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
void fileioe(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout); 
	freopen("error.txt","w",stderr);
}
void error_out() { cerr << endl; }
template <typename Head, typename... Tail>
void error_out(Head H, Tail... T) {
  cerr << " " << H;
  error_out(T...);
}
void time_elapsed(){
  cerr<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
}
#ifndef ONLINE_JUDGE
#define error(...) cerr << "[" << #__VA_ARGS__ << "]:", error_out(__VA_ARGS__)
#define fioe() fileioe()
#define time() time_elapsed()
#else
#define error(...) 1
#define fioe() 1
#define time() 1
#endif
ll M=1000000007;
ll INF=(ll)0x3f3f3f3f3f3f3f3f;

//
int main()
{
	GO
	//fioe();
	string a,b;
	cin>>a>>b;
	ll x,y;
	cin>>x>>y;
	string h;
	cin>>h;
	if(h==a)x--;
	else y--;
	cout<<x<<" "<<y<<endl;
	time();
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  bool flg = false;
  for(int i = 1; i <= 9; i++){
    for(int j = 1; j <= 9; j++){
      if(i * j == n) flg = true;
    }
  }
  if(flg) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using pint = pair<int,int>;

int main() {
    int N; cin >> N;
    vector<pint> res;
    int dame = N;
    if (N % 2 == 1) --dame;

    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= N; ++j) {
            if (j <= i || j == dame) continue;
            res.push_back(pint(i, j));
        }
        --dame;
    }

    cout << res.size() << endl;
    for (auto p : res) {
        cout << p.first << " " << p.second << endl;
    }
}
        




Measured memory_bytes: 384
def prm(x):
  if x == 1:
    return False
  for i in range(2,x):
    if x%i == 0:
      return False
  else:
    return True
n=int(input())
ans=[]
for j in range(1,55551,5):
  if prm(j):
    ans.append(j)
    if len(ans) == n:
      break
print(*ans,sep=" ")      

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

char alphabet[] = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};

// 二分探索
// llrep(i,N){
//     b = B[i];
//     auto cntA = lower_bound(A.begin(), A.end(), b);//イテレータなのでそのままllに変換とかはできない
//     auto cntC = upper_bound(C.begin(), C.end(), b);
//     ll cntA_ll = distance(A.begin(), cntA);
//     ll cntC_ll = C.size() - distance(C.begin(), cntC);
//     cnt += (cntA_ll * cntC_ll);
// }



int main(){
    ll N,M,l,r;
    cin >> N >> M;
    ll l_max = 0, r_min = 100000;
    llrep(i,M){
        cin >> l >> r;
        if (l > l_max) l_max = l;
        if (r < r_min) r_min = r;
    }
    if (l_max <= r_min) cout << (r_min - l_max + 1) << endl;
    else cout << 0 << endl;

    return 0;
}


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


int main()
{

    int n;
    cin>>n;

    int a[2][n];

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


    int dp[2][n];

    //dp[0][1]=(dp[0][0]+dp[0][1]);
    dp[0][0]=a[0][0];
    for(int i=1;i<n;i++)
    {
        dp[0][i]=(a[0][i]+dp[0][i-1]);
    }

    dp[1][0]=a[1][0]+a[0][0];

    for(int i=1;i<n;i++)
    {
        dp[1][i]=(max(dp[0][i],dp[1][i-1])+a[1][i] );
    }

    cout<<dp[1][n-1]<<endl;

    return 0;
}


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

#define ll long long int

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n, x, t, p;
	cin >> n >> x >> t;
	p = n/x;
	if(n % x != 0){
		p++;
	}
	cout << p * t << "\n";
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define N (1<<17)
#define INF 0
using namespace std;
typedef long long ll;

class RMQ{
public:
  ll n,dat[2*N-1];

  //?????????
  RMQ(){
    n=N;
    for(int i=0;i<n;i++) dat[i]=INF;
  }
  
  //k???????????????a????????´
  void update(int k,ll a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
  }

  //[a,b)???????°????????±??????? query(a,b,0,0,n)
  ll query(int a,int b,int k=0,int l=0,int r=N){
    if(r<=a||b<=l)return INF;
    if(a<=l&&r<=b)return dat[k];
    ll vl=query(a,b,k*2+1,l,(l+r)/2);
    ll vr=query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }
};


int main(){  
  ll n,x[N];
  cin>>n;
  RMQ rmq;
  for(int i=0;i<n;i++) cin>>x[i];

  ll sum=n*(1+n)/2,ans=sum;
  for(int i=0;i<n;i++){
    ll mx=-rmq.query(1,x[i])+x[i];
    ans=min(ans,sum-mx);
    rmq.update(x[i],-mx);
  }
  cout <<ans<<endl;
  return 0;
}

Measured memory_bytes: 5684
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Traveling Salesman around Lake
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

/* global variables */

int as[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int k, n;
  scanf("%d%d", &k, &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  as[n] = as[0] + k;

  int maxd = 0;
  for (int i = 0; i < n; i++) {
    int d = as[i + 1] - as[i];
    if (maxd < d) maxd = d;
  }

  printf("%d\n", k - maxd);
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
 
int main() {
  int w, h, x, y;
  cin >> w >> h >> x >> y;
 
  double area = (double)w * h / 2;
  printf("%.10f\n", area);
 
  int multi;
  if (w % 2 == 0 && h % 2 == 0 && x == w / 2 && y == h / 2) {
    multi = 1;
  } else {
    multi = 0;
  }
  cout << multi << endl;
  return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
	int N, K;
	cin >> N >> K;
	vector<ll> x(N);
	REP(i, N) cin >> x[i];
	ll res = LLONG_MAX/3;
	for(int i=0;i<N-K+1;i++){
		ll score;
		if (x[i] <= 0 && x[i+K-1] <= 0){
			score = abs(x[i]);
		}else if(x[i] <= 0 && x[i+K-1] >= 0){
			score = min(2*abs(x[i]) + x[i+K-1], abs(x[i]) + 2*x[i+K-1]);
		}else{
			score = x[i+K-1];
		}
		res = min(res, score);
	}
	cout << res << endl;
    return 0;
}

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

int foo(long long a){
	long long i;
	if(a == 1)return 0;
	if(a == 2)return 1;
	if(a%2 == 0) return 0;
	for(i = 3; i * i <= a; i+=2){//cout<<a<<" "<<i<<endl;
		if(a%i == 0) return 0;
	}//cin>>i;
	return 1;
}

int main(){
	long long a, d, n, i, j, k, count, A;
	while(1){
		cin>>a>>d>>n;
		
		if(a == 0 && d == 0 && n == 0) break;
		
		
		//for(int i = 1; i < 100; i++)if(foo(i))cout<<i<<endl;
		A = a; count = 0;
		while(1){//cout<<count<<" "<<A<<" "<<foo(A)<<endl;
			if(foo(A)) count++;
			if(count == n) break;
			A += d;
		}
		
		cout<<A<<endl;
	}
	return 0;
}


Measured memory_bytes: 3084
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        s: [String; n],
    }
    let mut ac = 0;
    let mut wa = 0;
    let mut tle = 0;
    let mut re = 0;

    for s_i in s {
        if s_i == "AC" { ac += 1; }
        if s_i == "WA" { wa += 1; }
        if s_i == "TLE" { tle += 1; }
        if s_i == "RE" { re += 1; }
    }

    println!("AC x {}", ac);
    println!("WA x {}", wa);
    println!("TLE x {}", tle);
    println!("RE x {}", re);
}


Measured memory_bytes: 7780
from sys import stdin, setrecursionlimit


def cmb(n, r, mod=10 ** 9 + 7):
    r = min(r, n - r)
    x = y = 1
    for i in range(r):
        x *= n - i
        x %= mod
        y *= i + 1
        y %= mod
    return x * pow(y, mod - 2, mod) % mod


def main():
    mod = 10 ** 9 + 7
    input = stdin.buffer.readline
    x, y = map(int, input().split())

    if (x + y) % 3 != 0 or 2 * x < y or 2 * y < x:
        print(0)
    else:

        x_min = (x + y) // 3

        print(cmb((x + y) // 3, x - x_min, mod))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38512
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
long long INF = (long long)1E17;
#define i_7 (long long)(1E9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}

//typedef long long ll;
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

//配列のSIZEは問題ごとに定義する必要がある。
const int SIZE = 1'000'010;
long long inv[SIZE+1];//各iの逆元を格納する配列。
long long kai[SIZE+1];//i!のmodを格納する配列。
long long invkai[SIZE+1];//各i!の逆元を格納する配列。
const int MOD=i_7;
void invinit(){//上の配列を初期化する関数。
    inv[1]=1;
    for(int i=2;i<=SIZE;i++){
        inv[i] = MOD - ((MOD/i)*inv[MOD%i])%MOD;
    }
    
    kai[0]=invkai[0]=1;
    for(int i=1;i<=SIZE;i++){
        kai[i]=(kai[i-1]*i)%MOD;
        invkai[i]=(invkai[i-1]*inv[i])%MOD;
    }
}

long long comb(long long a, long long b){
    if(b<0 || a<b){
        return 0;
    }
    return mod(kai[a]*mod(invkai[b]*invkai[a-b]));
}

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int main(){
  invinit();
  using namespace std;
  int n;
  cin>>n;
  int a[n];
  REP(i,n){
    cin>>a[i];
  }
  vector<int> primes;
  map<int, int> idp;
  for(int i = 2; i<=1'000'000; i++){
    if(prime_(i)){
      primes.push_back(i);
    }
  }
  int m = primes.size();
  REP(i,m){
    idp[primes[i]] = i;
  }
  int num[m] = {};
  REP(i,n){
    int temp = a[i];
    REP(j, m){
      if(temp == 1)break;
      if(primes[j] > 1000){
        num[idp[temp]] = 1;
        break;
      }
      if(temp % primes[j] != 0)continue;
      int cnt = 0;
      while(temp % primes[j] == 0){
        temp /= primes[j];
        cnt++;
      }
      num[j] = max(num[j], cnt);
    }
  }
  long long l = 1;
  REP(i,m){
    l *= po(primes[i], num[i]);
    l = mod(l);
  }
  
  long long ans = 0;
  REP(i, n){
    ans += mod(inv[a[i]]);
    ans = mod(ans);
  }
  ans *= l;
  ans = mod(ans);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 28024
#include <iostream>

int main(){
  int a,b,c;
  char s;

  std::cin >> a;
  std::cin >> s;
  std::cin >> b;

  if(s == '+'){
    c = a+b;
  }else if(s == '-'){
    c = a-b;
  }

  std::cout << c << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = 1e16;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	long double A, B;
	cin >> A >> B;
	int C = floor(A*B);
	cout << C << endl;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
#define ll int
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define vi vector<ll>
#define vs vector<string>
#define vii vector<pii>
#define mi map<ll,ll>
#define mii map<pii,ll>
#define mc map<char,ll>
#define itr ::iterator
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fe(i,a,b) for(ll i=a;i<=b;i++)
#define fn(i,a,b) for(ll i=a;i>b;i--)
#define fne(i,a,b) for(ll i=a;i>=b;i--)
#define fm(it,m) for(it = m.begin();it != m.end();++it)
#define all(v) v.begin(),v.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define M 1000000007
#define pi 3.14159265358979323846


int main()
{  
   #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   #endif
   IOS;
   
   int T=1;
   //cin>>T;
   f(t,0,T)
    { 
      ll n=0,i=0,j=0,k=0,flag=INT_MAX;
      cin>>n>>k;

      vi a(n),dp(n);
      
      f(i,0,n)
       cin>>a[i];

      dp[0]=0;

      f(i,1,n)
       { 
         j=1;
         flag=INT_MAX;

         while(i-j>=0 && j<=k)
         {
          flag = min(flag,dp[i-j]+abs(a[i]-a[i-j]));
          j++;
         }

         dp[i] = flag;
       }
  
      cout<<dp[n-1]<<endl;
    }
  return 0;
}


Measured memory_bytes: 3948
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

typedef pair<int,int> pii;

int cutpos(pii p, int x) {         // cÈç³A¡Èç
  int w = p.first, h = p.second;

  x %= 2*w+2*h;
  if (x < w)                   // EÌÓ
    return x;
  else if (x < w+h)
    return -(x-w);
  else if (x < 2*w+h)
    return x-w-h;
  else
    return -(x-2*w-h);
}

int main() {
  int n,w,d;
  while(cin>>n>>w>>d,n||w||d) {
    vector<pii> v;
    v.push_back(pii(w,d));
    REP(i,n) {
      int p,s;
      cin >> p >> s;
      p--;
      int pos = cutpos(v[p], s);
      // cout << p << " " << pos <<endl;
      pii new1, new2;
      if (pos > 0) {            // cÉØé
        new1 = pii(v[p].first-pos, v[p].second);
        new2 = pii(pos, v[p].second);
        } else {
        new1 = pii(v[p].first, v[p].second+pos);
        new2 = pii(v[p].first, -pos);
       }
      v.erase(v.begin() + p);
      if (new1.first*new1.second > new2.first*new2.second)
        swap(new1,new2);
      // printf("%d,%d\n",new1.first, new1.second);
      // printf("%d,%d\n",new2.first, new2.second);
      v.push_back(new1);
      v.push_back(new2);
    }
    vector<int> res;
    FOR(it, v) {
      res.push_back(it->first*it->second);
    }
    sort(ALL(res));
    REP(i,res.size()) {
      if (i)cout << " ";
      cout << res[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 0
p = int(input())
a_list = list(map(int, input().split()))
r_list = [0] * p

fact = [0] * p
fact[0] = 1
for i in range(1, p):
    fact[i] = fact[i - 1] * i % p

fact_inv = [0] * p
fact_inv[-1] = pow(fact[-1], p-2, p)
for i in range(p-2, -1 ,-1):
    fact_inv[i] = (fact_inv[i+1] * (i+1)) % p

ncr = [(fact[p-1] * fact_inv[p-1-i] * fact_inv[i]) % p for i in range(p)]

for j in range(p):
    if a_list[j] == 0:
        continue
    k = 1
    for i in range(p-1, -1, -1):
        r_list[i] -= ncr[i] * k
        r_list[i] %= p
        k *= -j
        k %= p
    r_list[0] += 1

r_list[0] %= p
print(*r_list)


Measured memory_bytes: 44380
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
long long power(long long a,long long now) {
	long long ans = 1;
	while (now != 0) {
		if (now % 2 == 1) {
			ans *= a;
			ans %= MAX_MOD;
		}
		now /= 2;
		a *= a;
		a %= MAX_MOD;
	}
	return ans;
}
long long inv(long long a) {
	return power(a, MAX_MOD - 2);
}
long long Permutation(long long a, long long b) {
	long long ans = 1;
	for (long long i = 0; i < b; ++i) {
		ans *= (a - i);
		ans %= MAX_MOD;
	}
	return ans;
}
long long Combination(long long a, long long b) {
	long long ans = 1;
	for (long long i = 0; i < b; ++i) {
		ans *= (a - i);
		ans %= MAX_MOD;
		ans *= inv(i + 1);
		ans %= MAX_MOD;
	}
	return ans;
}
int main() {
	long long n, k;
	cin >> n >> k;
	long long ans = 0;
	for (long long i = 0; i < k; ++i) {
		long long tmp = Combination(k,i);
		tmp *= power(k - i, n);
		tmp %= MAX_MOD;
		if (i % 2 == 0) {
			ans += tmp;
		}
		else {
			ans -= tmp;
		}
		ans += MAX_MOD;
		ans %= MAX_MOD;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3080
#include<iostream>
using namespace std;
int main () {
  int N;
  cin >> N;
  int A[N];
  int max = 0;
  int max2 = 0;
  int maxindex = -1;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] > max) {
      max = A[i];
      maxindex = i;
    } else if (A[i] > max2) {
      max2 = A[i];
    }
  }

  for (int i = 0; i < N; i++) {
    if (maxindex!=i) {
      cout<<max<<endl;
    } else {
      cout<<max2<<endl;
    }
  }
  
  return 0;
}


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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  int n, q;
  string s;
  cin >> n >> q >> s;
  vector<int> dp(n);
  dp[0] = 0;
  for(int i = 1; i < n; ++i) {
    dp[i] = dp[i-1];
    string cmp = "";
    cmp += s[i-1];
    cmp += s[i];
    if(cmp == "AC") {
      ++dp[i];
    }
  }
  
  for(int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    --l;
    --r;
    int ans = 0;
    ans = dp[r] - dp[l];
    cout << ans << endl;
  }
  return 0;
}
  

Measured memory_bytes: 3880
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

int kosuu(int x){
    int ans=1;
    for(int i=2;i<=sqrt(x);i++){
        if(x%i==0){
            ans++;
        }
        while(x%i==0){
            x /=i;
        }
    }
    if(x!=1){
        ans++;
    }
    return ans;
}

int gcd(int x,int y){
    int ret;
    while(true){
        if(y==1){
            ret=1;
            break;
        }
        if(y>x){
            swap(x,y);
        }
        if(x%y==0){
            ret =y;
            break;
        }
        x %=y;
    }
    return ret;
}

signed main(){
    int A,B;
    cin >>A >> B;
    cout << kosuu(gcd(A,B)) <<endl;
}

Measured memory_bytes: 256
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, m = LI()
ans = 0
e = 2 ** m  # AC がもらえるまでの回数の期待値
ans = (1900 * m + 100 * (n - m)) * e
print(ans)


Measured memory_bytes: 9152
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
ll  mod = 1000000007;

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

    int d1,d2;
    string s = "";
    for(int i =0 ;i < n;i++)
    {
        cin >> d1>>d2;

        if(d1 == d2)
            s += "1";
        else
            s += "0";
    }

    std::size_t found = s.find("111");
    if( found != std::string::npos )
    {
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << endl;
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << endl;
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  int N, X;
  cin >> N >> X;
  int min;
  cin >> min;
  X -= min;
  rep(i, 1, N){
    int tmp;
    cin >> tmp;
    X -= tmp;
    if(tmp < min){
      min = tmp;
    }
  }
  cout << (N + X/min) << endl;
  return 0;
}

Measured memory_bytes: 256