akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <utility>

using namespace std;
typedef pair<int, int> pii;

pii lex_expr(const char *s, int p);
pii lex_term(const char *s, int p);

pii lex_expr(const char *s, int p){
	pii r = lex_term(s, p);
	p = r.second;
	while(s[p] == '+'){
		const pii q = lex_term(s, p + 1);
		r.first += q.first;
		r.second = p = q.second;
	}
	return r;
}
pii lex_term(const char *s, int p){
	pii r(s[p] - '0', p + 1);
	++p;
	while(s[p] == '*'){
		r.first *= s[p + 1] - '0';
		r.second = p = p + 2;
	}
	return r;
}

int solve(const char *s){
	int p = 1, result = s[0] - '0';
	while(s[p] != '\0'){
		if(s[p] == '+'){
			result += s[p + 1] - '0';
		}else{
			result *= s[p + 1] - '0';
		}
		p += 2;
	}
	return result;
}

int main(){
	ios_base::sync_with_stdio(false);
	string s;
	int n;
	cin >> s >> n;
	const char table[] = "IMLU";
	int answer = 0;
	if(lex_expr(s.c_str(), 0).first == n){ answer |= 1; }
	if(solve(s.c_str()) == n){ answer |= 2; }
	cout << table[answer] << endl;
	return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

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

    int n;
    cin >> n;
    vll x(n), l(n);
    rep(i, n) cin >> x[i] >> l[i];

    vector<pair<ll, ll>> p(n);
    rep(i, n) {
        p[i].second = x[i] - l[i];
        p[i].first = x[i] + l[i];
    }

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

    ll t = p[0].first;
    ll cnt = 1;
    for (int i = 1; i < n; i++) {
        if (t <= p[i].second) {
            cnt++;
            t = p[i].first;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3456
using System;

namespace ABC100B
{
    class Program
    {
        static void Main(string[] args)
        {
            var aaa = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = Math.Pow(100, aaa[0]);

            if (aaa[1] == 100)
            {
                Console.WriteLine(N *(aaa[1] +1));
            }
            else
            {
                Console.WriteLine(N * aaa[1]);
            }
        }
    }
}

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

using namespace std;

int n, m, x[200005], ca[200005], cb[200005], ans, ta, tb, tc;

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%d", x + i);
		ta = max(0, x[i] - ca[x[i]]);
		ca[x[i]]++;
		cb[ta]++;
	}
	for (int i = 1; i <= n; i++)
		ans += (cb[i] == 0);
	while (m--) {
		scanf("%d%d", &ta, &tb);
		ca[x[ta]]--;
		tc = max(0, x[ta] - ca[x[ta]]);
		cb[tc]--;
		if (tc && !cb[tc])
			ans++;
		x[ta] = tb;
		tc = max(0, x[ta] - ca[x[ta]]);
		ca[x[ta]]++;
		if (tc && !cb[tc])
			ans--;
		cb[tc]++;
		printf("%d\n", ans);
	}
	return 0;
}


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

char map_[10][10];
int temp,one,dian,ok;
int h,w;
void dfs(int x,int y,int s)
{
    if (x==h&&y==w)
    {
        if (temp==1&&s==one)
            ok=1;
        if (temp==2&&s==dian)
            ok=1;
        return;
    }
    if (y+1<=w&&map_[1][1]==map_[x][y+1])
        dfs(x,y+1,s+1);
    if (x+1<=h&&map_[1][1]==map_[x+1][y])
        dfs(x+1,y,s+1);
}

int main()
{
    while (scanf("%d%d",&h,&w)!=EOF)
    {
        getchar();
        one=dian=0;
        for (int i=1;i<=h;i++)
        {
            for (int j=1;j<=w;j++)
            {
                scanf("%c",&map_[i][j]);
                if (map_[i][j]=='#')
                    one++;
                else
                    dian++;
            }
            getchar();
        }
        ok=0;
        if (map_[1][1]=='#')
            temp=1;
        else
            temp=2;
        dfs(1,1,1);
        if (ok)
            printf("Possible\n");
        else
            printf("Impossible\n");
    }
    return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import math
import heapq


def main():
    N, M = map(int,input().split())
    A = list(map(lambda x:int(x)*-1,input().split()))
    heapq.heapify(A)
    for _ in range(M):
        v = heapq.heappop(A) * -1
        v = v // 2
        heapq.heappush(A,v*-1)
    print(sum(A)*-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14380
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * @author author
 *
 */
public class Main {

  /**
   * @param args
   */
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    Set<String> judge = new HashSet<>(Arrays.asList(sc.next().split("")));

    if (judge.size() == 2) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }

}


Measured memory_bytes: 22608
#include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
inline char gc() {
//	return getchar();
	static char buf[100000],*l=buf,*r=buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void rd(T &x) {
	x=0; int f=1,ch=gc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=gc();}
	x*=f;
}
typedef long long ll;
const int mod=998244353;
const int MAXC=3000+5,MAXD=3000+5;
int A,B,C,D;
int dp[MAXC][MAXD];
int main() {
	rd(A),rd(B),rd(C),rd(D);
	dp[C][D]=1;
	for(int i=C;i>=A;--i) {
		int sum=0;
		for(int j=D;j>=B;--j) {
			sum=((ll)sum*i+dp[i][j+1])%mod;
			dp[i-1][j]=(ll)j*(dp[i][j]+sum)%mod;
		}
	}
	int an=0;
	for(int i=B,r=1;i<=D;++i) {
		an=(an+(ll)dp[A][i]*r)%mod;
		r=(ll)r*A%mod;
	}
	printf("%d\n",an);
	return 0;
} 

Measured memory_bytes: 38860
#include<stdio.h>

int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    if(a==b) printf("a == b\n",a,b);
    if(a>b)printf("a > b\n",a,b);
    if(a<b)printf("a < b\n",a,b);
    return 0;
    }


Measured memory_bytes: 2128
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			if(n==0)
				return;
			int num[]=new int[n];
			int p[]=new int[n];
			int q[]=new int[n];
			int r[]=new int[n];
			int cal[]=new int[n];
			int j=0;
			for(int i=0;i<n;i++)
			{
				num[i]=in.nextInt();
				p[i]=in.nextInt();
				q[i]=in.nextInt();
				r[i]=in.nextInt();
				cal[i]=p[i]*4+q[i]*9+r[i]*4;
			}
			int P=in.nextInt(),Q=in.nextInt(),R=in.nextInt(),C=in.nextInt();
			for(int i=0;i<n;i++)
			{
				if(p[i]<=P&&q[i]<=Q&&r[i]<=R&&cal[i]<=C)
				{
					System.out.println(num[i]);
					j=1;
				}
			}
			if(j==0)
				System.out.println("NA");
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int n;
vector<vector<int>> v(2);

int dfs(int h, int w, int total) {
  if (h == 1 && w == n - 1)
    return total + v[h][w];
  int one = 0, two = 0;
  if (h < 1)
    one = dfs(h + 1, w, total + v[h][w]);
  if (w < n - 1)
    two = dfs(h, w + 1, total + v[h][w]);
  return max(one, two);
}

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

  cin >> n;
  rep(i, 0, 2) {
    rep(j, 0, n) {
      int a;
      cin >> a;
      v[i].push_back(a);
    }
  }

  cout << dfs(0, 0, 0) << endl;
}


Measured memory_bytes: 256
lis1 = [1,3,5,7,8,10,12]
lis2 = [4,6,9,11]

x,y = map(int,input().split())

if  x in lis1 and y in lis1:
    print("Yes")
elif x in lis2 and y in lis2:
    print("Yes")
elif x == 2 and y ==2:
    print("Yes")
else:
    print("No")

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

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define REP2(i,n) for(int i=0;i<(int)(n);i++)
#define REP3(i,m,n) for(int i=m;i<(int)(n);i++)
#define REP4(i,m,n,s) for(int i=m;(s>0 and i<(int)(n)) or (s<0 and i>(int)(n));i+=s)
#define REP(...) GET_MACRO(__VA_ARGS__, REP4, REP3, REP2)(__VA_ARGS__)
#define REPIT(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define PIS(x) printf("%d ",x)
#define PN() putchar('\n')
#define MP make_pair
#define PB push_back
#define EB emplace_back

typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ULL;

void RI() {}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
void PI() {putchar('\n');}
template<typename... T>
void PI(const int head, T... tail ) {
    printf("%d ", head);
    PI(tail...);
}

const int MOD = 1000000007;
#define MAX_N 105
char s[MAX_N];
char s2[MAX_N];
int ans = INT_MAX;

void test(char c) {
    int n = strlen(s);
    strcpy(s2, s);
    int cnt = 0;
    REP(i, n) {
        if(s2[i] != c) {
            cnt++;
        }
    }
    int l = n;
    int nop = 0;
    while(cnt != 0) {
        cnt = 0;
        l -= 1;
        REP(i, l) {
            if(s2[i] == c or s2[i+1] == c) {
                s2[i] = c;
            } else {
                cnt++;
            }
        }
        nop += 1;
    }
    ans = min(ans, nop);
}

int main()
{
    scanf("%s", s);
    int n = strlen(s);
    REP(i, n) {
        test(s[i]);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
n = int(input())
tmp = input().split(' ')
tmp_map = map(int,tmp)
prices = list(tmp_map)
money = 1000

for i in range(n-1):
  if prices[i] < prices[i+1]:
    stocks = int(money/prices[i])
    money += stocks*(prices[i+1]-prices[i])

print(money)

Measured memory_bytes: 9040
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,d,x,y,ans=0;
  cin>>n>>d;
  for(int64_t i=0;i<n;i++){
    cin>>x>>y;
    if(x*x+y*y<=d*d) ans++;
  }
  cout<<ans<<endl;
}

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

int main(void){
    int h,w;

    while(1){    
        cin >> h >> w;
        if((h == 0) && (w == 0)) break;
        for(int i = 0; i < h; i++){
            cout << '#';
            for(int j = 1; j < w-1; j++){
                if((i == 0) || (i == h-1)) cout << '#';
                else cout << '.';
            }
            cout << '#' << endl;
        }
        cout << endl;
    }

    return 0;
}


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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ll n,m;
  cin >> n >> m;
  VI x(m);
  rep(i,m) cin >> x[i];

  sort(all(x));
  VI diff(m-1);
  rep(i,m-1) diff[i] = x[i+1] - x[i];
  sort(all(diff),greater<int>());
  ll ans = 0;
  FOR(i,n-1,m-1)  ans += diff[i];
  cout << ans << endl;

  return 0;
}


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

int main(void){
    int n;cin>>n;
    int taro_score = 0;
    int hanako_score = 0;
    for (int i = 0; i < n; i++) {
        string taro,hanako;cin>>taro>>hanako;
        if (taro == hanako) {
            taro_score++;
            hanako_score++;
            continue;
        } else if (taro < hanako) {
            hanako_score += 3;
        } else {
            taro_score += 3;
        }
    }
    cout << taro_score << " " << hanako_score << endl;
    return 0;
}


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

using namespace std;

#define ll long long
#define N 2000

int n, c, a[N + 5], b[N + 5];
ll ans = 0x7f7f7f7f7f7f7f7f;

int main() {
	scanf("%d%d", &n, &c);
	for (int i = 0; i < n; ++i)
		scanf("%d", &a[i]);
	memset(b, 0x3f, sizeof b);
	for (int t = 0; t < n; ++t) {
		ll sum = 0;
		for (int i = 0; i < n; ++i) {
			b[i] = min(b[i], a[(i - t + n) % n]);
			sum += b[i];
		}
		ans = min(ans, sum + 1LL * t * c);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define LL long long
#define R register
long long a,b=2;
int main()
{
    cin>>a;
    for(R int i=0;i<a;i++)b=(b+1)*2;
    cout<<b<<endl;
}

Measured memory_bytes: 256
import java.util.*;

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

        Map<Integer, List<Integer>> graph = new HashMap<>();
        int n = sc.nextInt();

//        for (int i = 1; i <= n; i++) {
//            graph.put(i, new ArrayList<>());
//        }

        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            List<Integer> edges = graph.computeIfAbsent(x, k -> new ArrayList<>());
            edges.add(y);
        }

        Integer[] maxes = new Integer[n+1];
        int maxPath = 0;
        for (int i = 1; i <= n; i++) {
            maxPath = Math.max(maxPath, maxPath(graph, i, maxes));
        }

        System.out.println(maxPath);
    }

    private static int maxPath(Map<Integer, List<Integer>> graph, int i, Integer[] maxes) {
        if(maxes[i] != null) {
            return maxes[i];
        }

        List<Integer> edges = graph.get(i);
        if(edges == null || edges.isEmpty()) {
            return 0;
        }

        int max = 0;
        for (int edge: edges) {
            int path = maxPath(graph, edge, maxes);
            max = Math.max(path, max);
        }

        max++;
        maxes[i] = max;
        return max;
    }
}

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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V) \
    for (auto v : (V)) cout << v << ' ';
#define PRINT_ENTER() cout << endl;

int main() {
    /* code */
    int a, p;
    cin >> a >> p;
    int a_kake = a * 3;
    cout << (a_kake + p) / 2 << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{string s1,s2;
 cin>>s1>>s2;
 long long int sum=0;
 for(long long int i=0;i<s1.size();i++)
 {if(s1[i]!=s2[i])
   sum++;}
 cout<<sum;}

Measured memory_bytes: 3856
#include <stdio.h>
int main(void)
{
    while (1)
    {
        int n, x;
        int a, b, c;
        int i = 0;
        scanf("%d %d", &n, &x);
        if (n == 0 && x == 0)
        {
            break;
        }
        for (a = 1; a <= n; a++)
        {
            for (b = 1; b <= n; b++)
            {
                for (c = 1; c <= n; c++)
                {
                    if (a + b + c == x)
                    {
                        if (a != b && b != c && c != a)
                        {
                            i++;
                        }
                    }
                }
            }
        }
        printf("%d\n", i / 6);
    }
    return 0;
}


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

ll modpow(ll n, ll m, ll mod) {
    ll ret = 1;
    while(m > 0) {
        if(m & 1) ret = ret * n % mod;
        n = n * n % mod;
        m >>= 1;
    }
    return ret;
}

vector<vector<ll>> combination_array(int n, ll MOD) {
    vector<vector<ll>> nCk(n + 1, vector<ll>(n + 1));
    nCk[0][0] = 1;
    repeat(i, 1, n + 1) {
        nCk[i][0] = nCk[i-1][0];
        repeat(j, 1, i + 1) {
            nCk[i][j] = (nCk[i-1][j] + nCk[i-1][j-1]) % MOD;
        }
    }
    return nCk;
}

class Solver {
  public:
    bool solve() {

        ll N, M; cin >> N >> M;

        vector<vector<ll>> ways2(N + 1, vector<ll>(N + 1, 0));
        // ways2[i][j] := 1,..,i がすべて１杯以下 and
        //                1,...,i の少なくとも１つが乗っているラーメンがちょうど j 杯である
        //                ようなラーメンの組み合わせの総数
        rep(i, N + 1) ways2[i][0] = 1; // ０杯

        repeat(i, 1, N + 1) {
            repeat(j, 1, N + 1) {
                ways2[i][j] += ways2[i - 1][j];     // i を使わない
                ways2[i][j] += ways2[i - 1][j - 1]; // i だけが乗った新規ラーメンを生成
                ways2[i][j] += ways2[i - 1][j] * j; // i を既存のラーメンに乗っける
                ways2[i][j] %= M;
            }
        }

        vector<ll> ways(N + 1);
        // ways[i] := 1,...,i がすべて１杯以下 なラーメンの組み合わせの総数
        rep(i, N + 1) {
            vector<ll> p(N + 1); { // p[j] := (2^(N-i))^j
                ll base = modpow(2, N - i, M);
                p[0] = 1;
                rep(j, N) p[j + 1] = p[j] * base % M;
            }
            rep(j, N + 1) {
                ways[i] += ways2[i][j] * p[j] % M;
                ways[i] %= M;
            }
        }

        auto nCk = combination_array(N, M);
        vector<ll> pow22i(N + 1); { // pow22i[i] := 2^(2^i)
            pow22i[0] = 2;
            rep(i, N) pow22i[i + 1] = pow22i[i] * pow22i[i] % M;
        }

        ll ans = 0;
        rep(i, N + 1) {
            ll a = (i % 2 == 0 ? 1 : -1) * nCk[N][i] * ways[i] % M * pow22i[N - i] % M;
            while(a < 0) a += M;
            ans = (ans + a) % M;
        }
        cout << ans << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 141184
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> p2;
char arr[1000005],jok[100005];
vector<p2> v;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll q;
  string st;
  cin>>st>>q;
  ll s=300000,e=300000+ll(st.length())-1;
  for(ll qc=0;qc<q;qc++){
    ll op;
    cin>>op;
    if(op==2){
      ll f;
      char c;
      cin>>f>>c;
      if(f==1)
        s--;
      else
        e++;
      v.push_back({op,f});
      jok[qc]=c;
    }
    else
      v.push_back({op,0});
  }
  ll ns=s,ne=e,val=0;
  for(ll i=ll(v.size())-1;i>=0;i--){
    if(v[i].first==1)
      val^=1;
    else if(v[i].second==1){
      if(val==0)
        arr[s++]=jok[i];
      else
        arr[e--]=jok[i];
    }
    else{
      if(val==0)
        arr[e--]=jok[i];
      else
        arr[s++]=jok[i];
    }
  }
  if(val==0)
    for(ll i=0;i<st.length();i++)
      arr[s++]=st[i];
  else
    for(ll i=ll(st.length())-1;i>=0;i--)
      arr[s++]=st[i];
  for(ll i=ns;i<=ne;i++)
    cout<<arr[i];
}

Measured memory_bytes: 6464
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<string>
#include <ios>     
#include <iomanip> 
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

llong gcd(llong a, llong b) {
	if (a < b) swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}

llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}

//ここまで共通

int H, W;
int MEMO[60][60] = { 0 };
char s[60][60];
queue<pair<int, int>> A;
int SHIRO = 0;


bool inRange(int a, int b) {
	return 0 <= a && a < H && 0 <= b && b < W;
}

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> s[i][j];
			if (s[i][j] == '.') SHIRO++;
		}
	}

	pair<int, int>p = make_pair(0, 0);
	MEMO[0][0] = 1;

	A.push(p);

	int ANS = 10000;

	while (!(A.empty())) {
		pair<int, int> q = A.front();
		A.pop();

		if (q.first == H - 1 && q.second == W - 1) {
			ANS = min(ANS, MEMO[H - 1][W - 1]);
			continue;
		}

		for (int i = -1; i <= 1; i++) {
			for (int j = -1; j <= 1; j++) {
				if (i != 0 && j != 0) {
					continue;
				}

				if (inRange(q.first + i, q.second + j)) {
					if (s[q.first + i][q.second + j] == '.' && (MEMO[q.first + i][q.second + j] > MEMO[q.first][q.second] + 1 || MEMO[q.first + i][q.second + j] == 0)) {
						pair<int, int>r = make_pair(q.first + i, q.second + j);
						A.push(r);
						MEMO[q.first + i][q.second + j] = MEMO[q.first][q.second] + 1;
					}
				}
			}
		}
	}

	if (ANS == 10000) cout << -1;
	else cout << SHIRO - ANS;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

constexpr long long MAX = 1000000000000001;

string solve2(int N){
	string x;
	int num = 26;
	int num2 = 26;
	int sum = 0;
	int sum2 = 0;
	
	while(N > sum){
		sum2 = sum;
		sum += num2;
		num2 *= num;
		x += 'a';
	}
	num2 /= num;
	
	N -= sum2;
	N--;
	
	for(int i = x.size()-1; i >= 0; i--){
	// for(int i = 0; i < x.size(); i++){
		x[i] = 'a' + N % 26;
		N /= 26;
	}
	
	return x;
}

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N;
	
	cin>>N;
	
	cout<<solve2(N)<<endl;
	
	
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(){
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    
    string ans = "";
    
    ans += s1[0];
    ans += s2[0];
    ans += s3[0];
    
    transform(ans.begin(), ans.end(), ans.begin(), ::toupper);
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// atoi : atoi(str.c_str())
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  string s,t;
  cin >> s >> t;
  int n = s.size();
  bool com;
  rep(i,n){
    com = true;
    rep(j,n){
      if(s.at((j+i)%n) != t.at(j%n)){
        com = false;
        break;
      }
    }
    if(com){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> bool max_self(T & a, const T & b){ 
  return b > a ? a = b, true : false; 
}
template<class T> bool min_self(T & a, const T & b){ 
  return b < a ? a = b, true : false;    
}
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

int N, M;
vector<pair<int, int>> q;

int main(){
  FAST_IO
  cin >> N >> M;
  q.resize(M);
  for(auto &ele : q){
    cin >> ele.F >> ele.S;
  }

  sort(ALL(q));

  int left = 0, right = 0, cnt = 0;
  for(auto &ele : q){
    int f = ele.F, t = ele.S; 
//    cout << f << " & " << t << '\n';
    if(f < right){
      max_self(left, f);
      min_self(right, t);
    }else{
      cnt++;
      left = f;
      right = t;
    }
  }

  cout << cnt << '\n';
  return 0;
}


Measured memory_bytes: 3972
/*17D8103001E Fukushima Emi persimmon8 c++ 19.10.31*/

#include<iostream>
using namespace std;

int min(int a,int b,int n){
  int c=0,m=0;

  if(n<a) return 1;
  else if(n<7*a){
    while(1){
      m+=a;
      c++;
      if(m>=n) break;
    }
    return c;
  }else{
    while(1){
      m+=a;
      c++;
      if(c%7==0) m+=b;
      if(m>=n) break;
    }
    return c;
  }
  return c;
}

int main(){
  int n,a,b;
  cin>>a>>b>>n;
  //cout<<n<<a<<b;
  
  int ans=min(a,b,n);
  cout<<ans<<endl;

  return 0;
}



Measured memory_bytes: 3112
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main() {
    int a[3];
    cin>>a[0]>>a[1]>>a[2];;
    sort(a,a+3);
    if(a[0]+a[1]==a[2]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}   



Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include<stack>
#include<iomanip>

using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SRTVG(v) sort(v.begin(),v.end(),greater<>())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}

int atcoder(){
    int n,k;
    string S;
    cin>>n>>k>>S;
    if(n<k){cout<<n<<ENT;return 0;}
    Vi s;
    int cnt=0;
    bool black=true;
    REP(i,0,n){
        if(black){
            if(S[i]=='1') cnt++;
            else{s.push_back(cnt);black=false;cnt=0;i--;}
        }else{
            if(S[i]=='0') cnt++;
            else{s.push_back(cnt);black=true;cnt=0;i--;}
        }
    }
    if(cnt>0) s.push_back(cnt);
    if(s.size()%2==0)s.push_back(0);
//    REP(i,0,s.size()) cout<<s[i]<< " ";
//    cout<<ENT;
    
    if(s.size()/2<=k){cout<<n<<ENT;return 0;}
    int tmp=0,ans=0;
    REP(i,0,2*k+1) tmp += s[i];
    ans=tmp;
 //   cout<<tmp<<ENT;
    REP(i,0,(s.size()/2)-k){
//        cout<<"i="<<i<<ENT;
        tmp -= (s[2*i]+s[2*i+1]);// cout << "-" << s[i] << " "<<s[i+1]<<ENT;
        tmp += (s[2*(k+i)+1]+s[2*(k+i)+2]);// cout <<s[2*(k+i)+1] << " "<<s[2*(k+i)+2]<<ENT;
        chmax(ans,tmp);
 //       cout<<tmp<<ENT;
    }
    cout<<ans<<ENT;
    return 0;
}


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


Measured memory_bytes: 1020
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define maxii 100005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
 vector<int> vi[maxii];
 vector<int>:: iterator child;
typedef vector<lln> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


int arr[maxii];
int arr2[maxii];
bool check[maxii];

bool dfs(int node,int c)
{
    check[node]=true;
    arr2[node]=c;
    for(int child=0;child<vi[node].size();child++)
    {
        if(check[vi[node][child]]==false)
        {
            if(dfs(vi[node][child],c^1)==false)
            {
                return false;
            }
        }
        else if(arr2[node]==arr2[vi[node][child]])
        {
            return false;
        }
        //else if()
    }
    return true;
}

int main()
{
   //string a,b,c;
   stack<char>aa,bb,cc;
   string a,b,c;
   cin>>a>>b>>c;
   int len1=a.size();
   int len2=b.size();
   int len3=c.size();
   for(int i=len1-1;i>=0;i--)
   {
       aa.push(a[i]);
   }
   for(int i=len2-1;i>=0;i--)
   {
       bb.push(b[i]);
   }
   for(int i=len3-1;i>=0;i--)
   {
       cc.push(c[i]);
   }
   char ccc=aa.top();
   while(1)
   {
       //cout<<ccc<<" ";

       if(ccc=='a')
       {
           if(aa.empty())
           {
             cout<<"A";
             break;
          }
           ccc=aa.top();
           aa.pop();
       }
       else if(ccc=='b')
       {
           if(bb.empty())
           {
             cout<<"B";
             break;
           }
           ccc=bb.top();
           bb.pop();
       }
       else if(ccc=='c')
       {
            if(cc.empty())
           {
             cout<<"C";
              break;
           }
           ccc=cc.top();
           cc.pop();
       }

   }
}






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

int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if((a+b) == (c+d))
  {
    cout << "Balanced" << endl;
  }
  else if((a+b) > (c+d))
  {
    cout << "Left" << endl;  
  }
  else{
    cout << "Right" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i,k,h,w,idx,flag;
        h = sc.nextInt();
        w = sc.nextInt();
        int[][] answer = new int[h][w];
        for(i = 0; i < h; i ++ ){
            char weather[] = sc.next().toCharArray(); 
            flag = 0;
            idx = 0;
            for(k = 0; k < weather.length; k ++ ){
                if(weather[k] == 'c'){
                    answer[i][k] = 0;
                    idx = k;
                    flag++;
                }
                if(flag == 0){
                    if(weather[k] == '.')answer[i][k] = -1;
                }
                else{
                    if(weather[k] == '.')answer[i][k] += k - idx;
                }
            }
        }
        for(i = 0; i < h; i ++ ){
            for(k = 0; k < w; k ++ ){
                if(k != w-1)System.out.print(answer[i][k]+" ");
                else System.out.println(answer[i][k]);
            }
        }
    }
}

Measured memory_bytes: 33852
from collections import deque

N, M = map(int, input().split())
routes = [[] for _ in range(N+1)]
for _ in range(M):
  a, b = map(int, input().split())
  routes[a].append(b)
  routes[b].append(a)
checked = [0 for _ in range(N+1)]
route = deque(routes[1])
for r in routes[1]:
  checked[r] = 1
while(len(route) > 0):
  r = route.popleft()
  for rr in routes[r]:
    if checked[rr] == 0:
      checked[rr] = r
      route.append(rr)
for i in range(2, N+1):
  if checked[i] == 0:
    print('No')
    exit()
print('Yes')
for j in range(2, N+1):
  print(checked[j])


Measured memory_bytes: 100052
#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);
	string s; cin >> s;
	ll cnt=1, ans=0;
	vll pool;
	rep(i, s.size()-1){
		if (s[i]!=s[i+1]){
			pool.pb(cnt);
			cnt = 1;
		}else{
			cnt++;
		}
	}
	pool.pb(cnt);
	rep(i, pool.size()-1){
		if (pool[i]<pool[i+1]){
			ans += pool[i];
			pool[i+1] -= pool[i];
		}else{
			ans += pool[i+1];
			if (i+2<pool.size())
				pool[i+2] += pool[i]-pool[i+1];
			i++;
		}
	}
	cout << ans*2 << endl;
	return 0;
}

Measured memory_bytes: 1480
n = int(input())
ans = []
for i in range(40):
  if i % 2 == 0:
    if n % 2 == 1:
      n -= 1
      n //= 2
      ans.append(1)
    else:
      n //= 2
      ans.append(0)
  else:
    if n % 2 == 1:
      n += 1
      n //= 2
      ans.append(1)
    else:
      n //= 2
      ans.append(0)
  if n == 0:
    break
ans.reverse()
print("".join(map(str, ans)))

      
      

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,i,j,l;
    cin>>n>>k;
    unsigned long long int a[n],b[n];
    unsigned long long int o=1;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=k;i<n;i++){
        if(a[i]>a[i-k]){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 5184
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	ans := 0
L0:
	for {
		for i := 0; i < N; i++ {
			if a[i]%2 != 0 {
				break L0
			}
			a[i] /= 2
		}
		ans++
	}
	out(ans)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int A;
    string S;
    cin >> A >> S;
    if(A < 3200)cout << "red" << endl;
    else cout << S << endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        if(x == 3 || x == 5 || x == 7) System.out.println("YES");
        else System.out.println("NO");
    }
}


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

int main()
{
  ll a, v, b, w, t;
  cin >> a >> v;
  cin >> b >> w;
  cin >> t;
  // printf("%d %d %d %d %d", a, v, b, w, t);
  bool flag = false;

  ll x = abs(a - b);
  ll y = (v - w) * t;
  // cout << result << endl;

  if (x <= y)
  {
    cout << "YES" << endl;
  }
  else
    cout << "NO" << endl;
}


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

typedef long long ll;

ll A, B, C, D, E, F;
vector<bool> W, S;
tuple<double, ll, ll> R = make_tuple(-1, 0, 0);

int main() {
  cin >> A >> B >> C >> D >> E >> F;
  W.resize(F + 1);
  S.resize(F + 1);
  for (ll a = 0; a <= F; a += A * 100)
    for (ll b = 0; a + b <= F; b += B * 100) W[a + b] = true;
  for (ll c = 0; c <= F; c += C)
    for (ll d = 0; c + d <= F; d += D) S[c + d] = true;
  for (ll w = 0; w <= F; ++w)
    for (ll s = 0; w + s <= F; ++s)
      if (W[w] && S[s] && s <= w / 100 * E)
        R = max(R, make_tuple(100. * s / (w + s), w + s, s));
  cout << get<1>(R) << " " << get<2>(R) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

ll lcm(ll a, ll b) { //最小公倍数
  return a * b / gcd(a, b);
}

ll digit_sum(ll a){ //10進桁和
  ll ans=0;
  while(a>0){
    ans+=a%10;
    a/=10;
  }
  return ans;
}



int main()
{

  ll s;
  cin>>s;

  ll ans=0;
  if(s==1||s==2){
    cout<<4<<endl;
    return 0;
  }


  while(s>1){
    ans++;
    if(s%2==0){
      s=s/2;
    }else{
      s=3*s+1;
    }
  }


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


Measured memory_bytes: 3500
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
using namespace std;
char str1[16];
char str2[16];
vector<pair<int,int > >g[10000];
int chk[10000];
int v[10000];
int ijk[10000];
int val[1000];
int G[1000][1000];
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&b,&a,&c),a){
		for(int i=0;i<10000;i++){
			g[i].clear();
			chk[i]=0;
		}
		map<string,int> m;
		scanf("%s%s",str1,str2);
		string S=str1;
		string T=str2;
		m[S]=0;
		m[T]=1;
		int n=2;
		for(int i=0;i<b;i++){
			int d;
			scanf("%s%s%d",str1,str2,&d);
			string p=str1;
			string q=str2;
			int P,Q;
			if(m.count(str1)){
				P=m[str1];
			}else{
				P=n;
				m[str1]=n++;
			}
			if(m.count(str2)){
				Q=m[str2];
			}else{
				Q=n;
				m[str2]=n++;
			}
			g[P].push_back(make_pair(Q,d));
			g[Q].push_back(make_pair(P,d));
		}
		for(int i=0;i<a;i++){
			scanf("%s",str1);
			if(m.count(str1)){
				chk[m[str1]]=1;
			}else{
				m[str1]=n;
				chk[n++]=1;
			}
		}
		chk[0]=1;
		int vs=0;
		for(int i=0;i<n;i++){
			if(chk[i]){
				val[vs++]=i;
			}
		}
		if(!chk[1]){
			val[vs++]=1;
		}
		for(int i=0;i<vs;i++)
			for(int j=0;j<vs;j++)
				G[i][j]=999999999;
		for(int i=0;i<vs;i++)G[i][i]=0;
		for(int I=0;I<vs;I++){
			int i=val[I];
			priority_queue<pair<int,int> >Q;
			for(int j=0;j<n;j++){
				v[j]=0;
				ijk[j]=999999999;
			}
			ijk[i]=0;
			Q.push(make_pair(0,i));
			while(Q.size()){
				int at=Q.top().second;
				int cost=-Q.top().first;
				Q.pop();
				if(v[at])continue;
				v[at]=1;
				for(int j=0;j<g[at].size();j++){
					if(!v[g[at][j].first]&&ijk[g[at][j].first]>cost+g[at][j].second){
						ijk[g[at][j].first]=cost+g[at][j].second;
						Q.push(make_pair(-ijk[g[at][j].first],g[at][j].first));
					}
				}
			}
			for(int j=0;j<vs;j++){
				if(c*10>=ijk[val[j]]){
					G[I][j]=G[j][I]=ijk[val[j]];
				}
			}
		}
		for(int k=0;k<vs;k++)
			for(int i=0;i<vs;i++)
				for(int j=0;j<vs;j++)
					G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
		for(int i=0;i<vs;i++){
			if(val[i]==1){
				if(G[0][i]==999999999)printf("-1\n");
				else printf("%d\n",G[0][i]);
				break;
			}
		}
	}
}

Measured memory_bytes: 5256
x, y = map(int, input().split())
ans = 0
if abs(x) == abs(y):
    ans = 1
elif abs(x) < abs(y):
    ans = abs(y) - abs(x)
    if y < 0:
        ans += 1
    if x < 0:
        ans += 1
else:
    if y == 0:
        ans = abs(x) + abs(y)
    else:
        ans = abs(x) - abs(y)
    if x > 0:
        ans += 1
    if y > 0:
        ans += 1

print(ans)


Measured memory_bytes: 9160
#include <stdio.h>

#define N 1000000

int divide(int, int *);
void shellsort(int *, int);
void insertionsort(int *, int, int, int *);

int main() {
    int Arrlength, Array[N]; 

    scanf("%d", &Arrlength);
    for(int i=0; i<Arrlength; ++i) {
        scanf("%d", (Array+i));
        //printf("%d\n", *(Array+i));
    }

    shellsort(Array, Arrlength);
    return 0;
}

int divide(int length, int *G) {
    //const int limitlen = 5;
    //length = limitlen;
    int i, divide = 0;
    for(i=0; 3*divide < length; ++i) {
        *(G+i) = divide = 3*divide + 1;
        //printf("%d : %d\n", i+1, *(G+i));
    }
    return i;
}

void shellsort(int *Array, int length) {
    int cnt = 0, m = 0;
    int G[9];
    int *Gtail, *p;
    m = divide(length, G);
    p = Gtail = &G[m-1];
    
    printf("%d\n", m);
    //printf("*Gtail = %d\n", *Gtail);
    
    for(int i=0; i<m; ++i) {
        if(i) printf(" ");
        printf("%d", *(p-i));
    }
    printf("\n");
    for(int i=0; i<m; ++i) {
        insertionsort(Array, length, *(Gtail-i), &cnt);
    }
    printf("%d\n", cnt);
    for(int i=0; i<length; ++i) {
        printf("%d\n", *(Array+i));
    }
    
}

void insertionsort(int *Array, int length, int divide, int *cnt) {
    int i, j, v;
    for(i=divide; i<length; ++i) {
        v = Array[i];
        j = i - divide;
        while(j>=0 && Array[j] > v) {
            Array[j+divide] = Array[j];
            j = j - divide;
            *cnt += 1;
        }
        Array[j+divide] = v;
    }
}


Measured memory_bytes: 6644
//AtCoder Dp Contest - A
//the_annoying_

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

/*  RECURSIVE IMPLEMENTATION GIVING TLE :(
long long int solve(long long int i,vector<long long int> c,long long int size,long long int cost)
{
    if(i>=size-1)
    {
        return cost;
    }
    else
    {
        if(i+1>=size)
        {
            return cost;
        }
        else if(i+2>=size && i+1==size-1)
        {
            return solve(i+1,c,size,cost+abs(c[i]-c[i+1]));
        }
        else
        {
            return min(solve(i+1,c,size,cost+abs(c[i]-c[i+1])),solve(i+2,c,size,cost+abs(c[i]-c[i+2])));
        }
    }
}
*/
int main()
{
    long long int n,k;
    cin >> n >> k;
    vector<long long int> v(n+1);
    for(long long int i=1;i<=n;i++)
    {
        cin >> v[i];
    }
    long long int dp[n+1];
    memset(dp,10001,sizeof(dp));
    dp[0]=0;
    dp[1]=0;
    dp[2]=abs(v[2]-v[1]);
    for(long long int i=3;i<=n;i++)
    {
        for(long long int j=i-k;j<i;j++)
        {
            if(j>=1)
            {
                dp[i]=min(dp[i],dp[j]+abs(v[i]-v[j]));
            }
        }
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 1792
def Rot(vec):
    new=[]
    new+=[vec[0]/2-vec[1]*3**(1/2)/2]
    new+=[vec[0]*3**(1/2)/2+vec[1]/2]
    return(new)

def Add(L):
    dist=[(L[1][0]-L[0][0])/3,(L[1][1]-L[0][1])/3]
    vec1=Rot(dist)
    p1=[2/3*L[0][0]+1/3*L[1][0],2/3*L[0][1]+1/3*L[1][1]]
    p2=[p1[0]+vec1[0],p1[1]+vec1[1]]
    p3=[2/3*L[1][0]+1/3*L[0][0],2/3*L[1][1]+1/3*L[0][1]]
    return([L[0],p1,p2,p3,L[1]])

def Koch(L,n):
    l=len(L)
    if n==0:
        Out=L
    elif n==1:
        if l==2:
            Out=Add(L)
        else:
            L1=L[0:l//2+1]
            L2=L[l//2:l]

            Out=Koch(L1,n)[:-1]+Koch(L2,n)
    else:
        Out=(Koch(Koch(L,n-1),1))

    return(Out)

n=int(input())
L=Koch([[0,0],[100,0]],n)
l=len(L)
for i in range(l):
    print(L[i][0],L[i][1])



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

int main(){
    long long n, m;
    cin >> n >> m;
    vector<long long> ans(n, 0);

    for(long long i = 0; i < m; i++){
        long long a, b;
        cin >> a >> b;
        ans[a-1]++;
        ans[b-1]++;
    }

    for(long long i = 0; i < n; i++){
        printf("%lld\n", ans[i]);
    }
    return 0;
}

Measured memory_bytes: 3724
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();
        int sum = sc.nextInt();
        boolean flg = false;

        for (int x = 0; x <= count; x++) {
            for (int y = 0; y <= count; y++) {
                if (x + y == count && 2 * x + 4 * y == sum) {
                    flg = true;
                    break;
                }
            }
        }
        if (flg) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}

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

using namespace std;
using ll = long long;

int main() {
    int n; scanf("%d", &n);
    ll ans = 0;

    for (ll i = 1; i <= n; i++) {
        ans += (i * (n - i + 1));
    }

    for (int i = 1; i < n; i++) {
        ll u, v; scanf("%lld %lld", &u, &v);
        if (u > v) swap(u, v);
        ans -= (u * (n - v + 1));
    }

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

Measured memory_bytes: 3700
s=chomp(readline())
if length(s)<26
	for i='a':'z'
		c=0
		for t=s
			c+=t==i
		end
		if c==0
			println(s,i)
			exit()
		end
	end
else
	for j=25:-1:1
		if s[j]<s[j+1]
			c=s[j+1]
			for k=j+1:26
				if s[j]<s[k]<c
					c=s[k]
				end
			end
			println(s[1:j-1],c)
			exit()
		end
	end
	println(-1)
end


Measured memory_bytes: 110604
n = int(input())
num_of_sug = []
sug = []
for i in range(n):
    m = int(input())
    num_of_sug += [m]
    sug += [[tuple(map(int, input().split())) for _ in range(m)]]

ans = 0

for i in range(2 ** n):
    liar = []
    honest = []
    for j in range(n):
        if ((i >> j) & 1):
            if j + 1 in liar:
                break
            elif j + 1 not in honest:
                honest += [j + 1]
            sug_tmp = sug[j]

            for sug_ in sug_tmp:
                if sug_[1] == 1:
                    if sug_[0] in liar:
                        break
                    elif sug_[0] not in honest:
                        honest += [sug_[0]]
                else:
                    if sug_[0] in honest:
                        break
                    elif sug_[0] not in liar:
                        liar += [sug_[0]]
            else:
                continue
            break
        else:
            if j + 1 in honest:
                break
            elif j + 1 not in liar:
                liar += [j + 1]
    else:
        if ans < len(honest):
            ans = len(honest)
print(ans)


Measured memory_bytes: 8900
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


void solve(){
    int n,i;
    cin >> n >> i;
    cout << n+1-i << endl;
}

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		long HP = sc.nextLong();
		int N = sc.nextInt();
		
		long sumA = 0;
		
		for(int i=0; i<N; i++) {
			sumA += sc.nextInt();
		}

		if(sumA >= HP)
			System.out.print("Yes");
		else
			System.out.print("No");

		sc.close();

	}

}

Measured memory_bytes: 48736
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
map <string,int> a;
int main()
{
	a["SUN"]=0;
	a["MON"]=1;
	a["TUE"]=2;
	a["WED"]=3;
	a["THU"]=4;
	a["FRI"]=5;
	a["SAT"]=6;
	string s;
	cin>>s;
	cout<<7-a[s];
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    vector<int> S(100, 0);

    int N2 = N;
    int d = 0;
    for (int i = 0; i < 100; i++) {
        if ( N != 0 ) {
            S[i] = abs(N) % 2;
            N = (N - S[i]) / (-2);
        } else {
            d = i - 1;
            break;
        }
    }

    for (int i = max(d, 0); i >= 0; i--) {
        cout << S[i];
    }

    return 0;
}

Measured memory_bytes: 256
n,x = map(int, input().split())
city = list(map(int, input().split()))

def gcd(x, y):
    if x > y:
        x,y = y,x
    return gcd(y%x, x) if x else y

city.append(x)
city.sort()

dist = []
for i in range(len(city)-1):
    dist.append(abs(city[i]-city[i+1]))

if len(dist) < 2:
    min_dist = dist[0]
else:
    min_dist = 0
    for i in range(len(dist)-1):
        if min_dist == 0:
            min_dist = gcd(dist[i], dist[i+1])
        else:
            min_dist = min(min_dist, gcd(dist[i], dist[i+1]))

print(min_dist)


Measured memory_bytes: 14480