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

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

typedef long long LL;

struct sindo{
  int x;
  int y;
  int count;
};

int main(){
  int w,h;
  while(1){
    cin >> w >> h;
    if(w==0) return 0;
    vector<vector<int>>
      tate(h,vector<int>(w-1,0)),
      yoko(h-1,vector<int>(w,0));
    for(int i=0;i<h;i++){
      for(int j=0;j<w-1;j++){
        cin >> tate[i][j];
      }
      if(i<h-1){
        for(int j=0;j<w;j++){
          cin >> yoko[i][j];
        }
      }
    }
    vector<vector<bool>> flag(h,vector<bool>(w,false));
    queue<struct sindo> bfs;
    bfs.push({0,0,1});
    flag[0][0]=true;
    struct sindo now;
    bool goal=false;
    while(!bfs.empty()){
      now=bfs.front();
      bfs.pop();
      if(now.x==w-1&&now.y==h-1){
        goal=true;
        cout << now.count << endl;
      }
      if(now.x>0&&tate[now.y][now.x-1]==0){
        if(!flag[now.y][now.x-1]){
          bfs.push({now.x-1,now.y,now.count+1});
          flag[now.y][now.x-1]=true;
        }
      }
      if(now.x<w-1&&tate[now.y][now.x]==0){
        if(!flag[now.y][now.x+1]){
          bfs.push({now.x+1,now.y,now.count+1});
          flag[now.y][now.x+1]=true;
        }
      }
      if(now.y>0&&yoko[now.y-1][now.x]==0){
        if(!flag[now.y-1][now.x]){
          bfs.push({now.x,now.y-1,now.count+1});
          flag[now.y-1][now.x]=true;
        }
      }
      if(now.y<h-1&&yoko[now.y][now.x]==0){
        if(!flag[now.y+1][now.x]){
          bfs.push({now.x,now.y+1,now.count+1});
          flag[now.y+1][now.x]=true;
        }
      }
    }
    if(!goal){
      cout << 0 << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3020
#include <vector>
#include <complex>
#include <cstdio>
#include <cassert>
#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 double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  if (abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0] + B / A * (m[1] - m[0]);
}

int main(){
	int T,x1,y1,x2,y2;
	for(scanf("%d",&T);T--;){
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		L A(P(x1,y1),P(x2,y2));
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		L B(P(x1,y1),P(x2,y2));
		P r=crosspoint(A,B);
		printf("%.9f %.9f\n",real(r),imag(r));
	}
}

Measured memory_bytes: 1080
l = list(map(int, input().split()))

sum = 0
a = b = c = 0

if l[0] > l[2]*2 or l[1] > l[2]*2:
    c1 = c2 = 0
    if l[0] > l[2]*2:
        c1 = 2 * l[3]
    if l[1] > l[2]*2:
        c2 = 2 * l[4]
    c = max([c1, c2])
elif l[0]+l[1] > l[2]*2:
    c += min([l[3], l[4]])*2
else:
    a = l[3]
    b = l[4]


if a+c/2 < l[3]:
    a += l[3]-(c/2+a)
if b+c/2 < l[4]:
    b += l[4]-(c/2+b)

sum = a*l[0] + b*l[1] + c*l[2]

print(int(sum))


Measured memory_bytes: 3064
n,m=map(int,input().split())
l=[]

for i in range(n):
  a,b=map(int,input().split())
  l.append([a,b])

l.sort()
c=0
for a,b in l:
  c+=min(b,m)*a
  m=max(m-b,0)

print(c)

Measured memory_bytes: 24260
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    int sum = 0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum = sum^a[i];
    }   
    for(int i=0;i<n;i++)
    {
        cout<<(a[i]^sum)<<endl;
    }
}

Measured memory_bytes: 4404
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>

using namespace std;
static const double eps = 1e-6;
static const int MAX_N = 100001;
static const int MAX_SUCCESS_N = 11;
double dp[MAX_N][MAX_SUCCESS_N];

void solve()
{
	double prob[MAX_SUCCESS_N];
	prob[1] = 1.0;
	for (int i = 2; i < MAX_SUCCESS_N; ++i)
	{
		prob[i] = prob[i - 1] * 0.5;
	}
	dp[1][1] = 1.0;
	double sum = 0;
	double ans[MAX_N];
	for (int i = 1; i < MAX_N; ++i)
	{
		for (int j = 1; j < MAX_SUCCESS_N; ++j)
		{
			if (dp[i][j] > 0)
			{
				sum += dp[i][j] * prob[j];
			}
			if (j == 1)
			{
				dp[i + 1][j + 1] += dp[i][j];
			}
			else
			{
				dp[i + 1][1] += dp[i][j] * (1 - prob[j]);
				dp[i + 1][j + 1] += dp[i][j] * prob[j];
			}
		}
		ans[i] = sum;
	}
	int n;
	while (cin >> n, n)
	{
		printf("%.3lf\n", ans[n]);
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 10564
#include <iostream>
using namespace std;
int main(){
	long long n, d, x, y, s=0;
	cin >> n >> d;
	for (int i=0; i<n; i++){
		cin >> x >> y;
		if (x*x+y*y<=d*d) s++;
    }
    cout << s <<endl;
    return 0;
}

Measured memory_bytes: 3512
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int h = int.Parse(input[0]);
		int w = int.Parse(input[1]);
    string[] strings = new string[h];
    for(int i = 0; i < h; i++) strings[i] = Console.ReadLine();
    long[,] matrix = new long[h-1,w-1];//行列
      
    for(int i = 0; i < h-1; i++)//それぞれの行
    {
    	for(int j = 0; j < w-1; j++)
      {
        int countMemo = 0;
        if(strings[i][j] == '#') countMemo++;
        if(strings[i][j+1] == '#') countMemo++;
        if(strings[i+1][j] == '#') countMemo++;
        if(strings[i+1][j+1] == '#') countMemo++;
        if(countMemo % 2 == 0) matrix[i,j] = 1;
      }
    }

		Console.WriteLine(LargestRectangleArea(matrix));
	}

  static long LargestRectangleArea(long[,] uses)
  {//長方形上で1の書かれたマスだけを用いた長方形の最大面積をO(HW)で返す
    int h = uses.GetLength(0);
    int w = uses.GetLength(1);
    long answer = Math.Max(h+1,w);
    long[] heights = new long[w];
    for(int i = 0; i < h; i++)
    {
      for(int j = 0; j < w; j++)
      {
        if(uses[i,j] == 1) heights[j]++;
        else heights[j] = 0;
      }
      answer = Math.Max(answer,LargestRectangle(heights));
    }

    return answer;
  }

  static long LargestRectangle(long[] lengths)
  {//x軸に接する底辺1、高さlengthsの長方形を繋げた時、最大長方形の面積をO(n)で返す
    if(lengths.Length == 0) return 0;
    long answer = 2*(lengths[0]+1);
    int n = lengths.Length;
    var rectangleStack = new Stack<long[]>();//x座標と高さ
    rectangleStack.Push(new long[2]{0,lengths[0]});
    long[] topMemo = new long[2];
    
    for(int i = 1; i < n; i++)
    {
      if(rectangleStack.Count() > 0) topMemo = rectangleStack.Peek();
      
      if(topMemo[1] < lengths[i]) rectangleStack.Push(new long[2]{i,lengths[i]});
      else if(topMemo[1] > lengths[i])
      {
        long memo = 0;
        while(rectangleStack.Count() > 0)
        {
          if(rectangleStack.Peek()[1] > lengths[i])
          {
            answer = Math.Max(answer, (rectangleStack.Peek()[1]+1)*(i+1-rectangleStack.Peek()[0]));
            memo = rectangleStack.Peek()[0];
            
            if(rectangleStack.Count() == 1)
            {
              rectangleStack.Pop();
              rectangleStack.Push(new long[2]{memo, lengths[i]});
              break;
            }
            else rectangleStack.Pop();
          }else
          {
            rectangleStack.Push(new long[2]{memo, lengths[i]});
            break;
          }
        }
      }

      if(i == n-1 && rectangleStack.Count() > 0)
      {
        while(rectangleStack.Count() > 0)
        {
          answer = Math.Max(answer, (rectangleStack.Peek()[1]+1)*(i-rectangleStack.Peek()[0]+2));
          rectangleStack.Pop();
        }
      }
    }

    return answer;
  }
  
}

Measured memory_bytes: 61376
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int L = A + B;
  int R = C + D;
  
  if (L > R){
    cout << "Left" << endl; 
  }
  else if (L < R){
    cout << "Right" << endl;
  }
  else{
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 10000
#define NIL -1

typedef struct{
  int parent, left, right;
}Node;

Node g_node[MAX];
int g_n, g_d[MAX], g_h[MAX];

void setDepth(int u, int d);
int setHeight(int u);
int getSibling(int u);
void print(int u);

int main(){
  int i, v, l, r, root = 0;

  scanf("%d",&g_n);

  for(i = 0; i < g_n; i++){
    g_node[i].parent = NIL;
  }

  for(i = 0; i < g_n; i++){
    scanf("%d %d %d",&v,&l,&r);
    g_node[v].left = l;
    g_node[v].right = r;
    if(l != NIL) g_node[l].parent = v;
    if(r != NIL) g_node[r].parent = v;
  }

  for(i = 0; i < g_n; i++){
    if(g_node[i].parent == NIL) root = i;
  }

  setDepth(root, 0);
  setHeight(root);

  for(i = 0; i < g_n; i++){
    print(i);
  }
  
  return 0;
}

void setDepth(int u, int d){
  if(u == NIL) return;
  g_d[u] = d;
  setDepth(g_node[u].left, d + 1);
  setDepth(g_node[u].right, d + 1);
}

int setHeight(int u){
  int h1 = 0, h2 = 0;
  if(g_node[u].left != NIL) h1 = setHeight(g_node[u].left) + 1;
  if(g_node[u].right != NIL) h2 = setHeight(g_node[u].right) + 1;

  if(h1 > h2){
    g_h[u] = h1;
    return h1;
  }
  else{
    g_h[u] = h2;
    return h2;
  }
}

int getSibling(int u){

  if(g_node[u].parent == NIL) return NIL;
  if(g_node[g_node[u].parent].left != u && g_node[g_node[u].parent].left != NIL)
    return g_node[g_node[u].parent].left;
  if(g_node[g_node[u].parent].right != u && g_node[g_node[u].parent].right != NIL)
    return g_node[g_node[u].parent].right;
  return NIL;
}

void print(int u){
  int deg = 0;
  
  printf("node %d: ",u);
  printf("parent = %d, ", g_node[u].parent);
  printf("sibling = %d, ", getSibling(u));

  if(g_node[u].left != NIL) deg++;
  if(g_node[u].right != NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",g_d[u]);
  printf("height = %d, ",g_h[u]);

  if(g_node[u].parent == NIL){
    printf("root\n");
  }else if(g_node[u].left == NIL && g_node[u].right == NIL){
    printf("leaf\n");
  }else{
    printf("internal node\n");
  }
}






Measured memory_bytes: 2048
#include <stdio.h>
#define MAX 100000

int A[MAX],n;

int partition(int p,int r){
  int x,i,j,t;
  x = A[r];
  i = p - 1;
  for(j = p;j < r; j++){
    if(A[j] <= x){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  return i+1;
}

int main(){
  int i,q;

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

  q = partition(0,n-1);

  for(i = 0;i < n; i++){
    if(i)printf(" ");
    if(i == q) printf("[");
    printf("%d",A[i]);
    if(i == q)printf("]");
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 2116
N = int(input())
H = list(map(int, input().split()))
ans = 0
ph = 0
cnt = 0
for h in H:
    if h<=ph:
        cnt += 1
    else:
        ans = max(cnt, ans)
        cnt = 0
    ph = h
ans = max(cnt, ans)
print(ans)


Measured memory_bytes: 14252
//chandigarh university
//shivamkr21
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,d;
  cin>>n>>d;
  int ar[n][d];
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<d;j++)
    {
      cin>>ar[i][j];
    }
  }
  cout<<fixed;
  double sum=0;
  int c=0;
  for(int i=0;i<n-1;i++)
  {
    for(int j=i+1;j<n;j++)
    {
      sum=0;
      for(int k=0;k<d;k++)
      {
        sum=sum+((double)(ar[i][k]-ar[j][k])*(double)(ar[i][k]-ar[j][k]));
      }
      //cout<<sum<<" ";
      sum=(double)sqrt(sum);
      //cout<<sum<<" \n";
      if(floor(sum)==sum)
      {
        c++;
      }
      else
      {
        //cout<<i<<" "<<j<<endl;
      }
    }
  }
  cout<<c<<endl;
  return 0;
}


Measured memory_bytes: 256
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 55;
int n,m,q,cnt=0,ans;
int a[MAXN],b[MAXN],c[MAXN],d[MAXN];

void rec(int pos, int pre, vi &v){
  if(v.size()==n){
    cnt++;
    int score = 0;
    for(int i=1;i<=q;i++){
      if(v[b[i]]-v[a[i]]==c[i])score+=d[i];
    }
    ans = max(ans,score);
    return;
  }
  for(int i=pre;i<=m;i++){
    v.pb(i);
    rec(pos+1,i,v);
    v.pop_back();
  }
}

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

  cin >> n >> m >> q;
  vi v;
  // cout << cnt << endl;
  for(int i=1;i<=q;i++){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--;
    b[i]--;
  }

  rec(0,1,v);
  cout << ans << endl;

return 0;
}
///....


Measured memory_bytes: 3660
void main() {
	auto ip = readAs!(long[]), X = ip[0], Y = ip[1], A = ip[2], B = ip[3], C = ip[4];
	auto p = readAs!(long[]);
	auto q = readAs!(long[]);
	auto r = readAs!(long[]);
	p.sort!"a > b"(); q.sort!"a > b"(); r.sort!"a > b"();
	p = p[0..X]; q = q[0..Y];
	long[] arr = r ~ p ~ q;
	arr.sort!"a > b"();
	arr[0..X+Y].sum.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 16240
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
typedef long long ll;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while(c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
int n;
char s[100005];
void init(){
    n = read();
    scanf("%s", s);

}
void solve(){
    int ans = 0;
    for (int i = 0; i < n; ){
        int j = i;
        while (j < n && s[i] == s[j])
            ++j;
        ++ans;
        i = j;
    }
    printf("%d\n", ans);
}
int main(){
    init();
    solve();
    return 0;
}

Measured memory_bytes: 384
program prob1
    implicit none
    character(len=4)::S
    integer::i
    read(*,*) S

    do i = 1,3
        if(S(i:i) .eq. S(i+1:i+1))then
            write(*,*) "Bad"
            stop
        end if
    end do
    write(*,*) "Good"
    stop
end program prob1

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const Int MAX = 222;
const Int INF = 1e15;
Int dL[MAX][MAX];
Int dS[MAX][MAX];

signed main(){
  Int n,m;
  while(cin>>n>>m,n){
    for(Int i=0;i<MAX;i++)
      for(Int j=0;j<MAX;j++)
        dL[i][j]=dS[i][j]=(i==j?0:INF);

    for(Int i=0;i<m;i++){
      Int x,y,t;
      char s;
      cin>>x>>y>>t>>s;
      x--;y--;
      if(s=='L'){
        chmin(dL[x][y],t);
        chmin(dL[y][x],t);
      }
      if(s=='S'){
        chmin(dS[x][y],t);
        chmin(dS[y][x],t);
      }
    }

    for(Int k=0;k<n;k++)
      for(Int i=0;i<n;i++)
        for(Int j=0;j<n;j++)
          chmin(dL[i][j],dL[i][k]+dL[k][j]);

    for(Int k=0;k<n;k++)
      for(Int i=0;i<n;i++)
        for(Int j=0;j<n;j++)
          chmin(dS[i][j],dS[i][k]+dS[k][j]);

    Int r;
    cin>>r;
    vector<Int> zs(r);
    for(Int i=0;i<r;i++) cin>>zs[i],zs[i]--;

    vector<Int> dp(n,INF);
    dp[zs[0]]=0;

    for(Int t=0;t+1<r;t++){
      Int u=zs[t],v=zs[t+1];

      vector<Int> nx(n,INF);
      for(Int i=0;i<n;i++){
        // only land
        chmin(nx[i],dp[i]+dL[u][v]);
        // with sea
        for(Int j=0;j<n;j++)
          chmin(nx[j],dp[i]+dL[u][i]+dS[i][j]+dL[j][v]);
      }

      swap(dp,nx);
    }

    cout<<*min_element(dp.begin(),dp.end())<<endl;
  }
  return 0;
}



Measured memory_bytes: 3788
import java.io.PrintWriter;
import java.util.*;

public class Main {
		public static void main(String[] args) {
			Scanner stdin = new Scanner(System.in);
			PrintWriter out = new PrintWriter(System.out);
			
			int r = Integer.parseInt(stdin.next());
			
			out.println(3*r*r);
			
			out.flush();
	}
}




Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

int main(){
	fast;	
	int n,k;
	cin>>n>>k;
	ll res=k;
	for(int i=1;i<n;i++) res*=k-1;
	cout<<res;
	
}
	


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
S = 1
for i in range(N):
    S *= A[i]
from fractions import gcd
g = 0
for i in range(N):
    g = gcd(g,A[i])
l = S//g
ans = 0
for i in range(N):
    ans += (l-1)%A[i]
print(ans)

Measured memory_bytes: 5284
#include<iostream>
#include<algorithm>


using namespace std;

int main(){
    int n,a[100],ans = 99999999;
    cin >> n;
    for(int i=0;i<n;i++)cin >> a[i];
    for(int i=-100;i<=100;i++){
        int sum=0;
        for(int j=0;j<n;j++){
            sum += (a[j]-i)*(a[j]-i);
        }
        ans = min(ans,sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
sum=0
for i in range(n-1):
    if i%2==0:
        sum-=a[i]
    else:
        sum+=a[i]
sum+=a[n-1]
ans[-1]=sum
for j in range(0,n-1)[::-1]:
    ans[j]+=(2*a[j]-ans[j+1])
for k in range(n):
    ans[k]=str(ans[k])
print(" ".join(ans))
    

Measured memory_bytes: 21856
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int[] h=new int[n+k];
    for(int i=0;i<n;i++){
      h[i]=sc.nextInt();
    }
    int[] dp=new int[n+k];
    Arrays.fill(dp,Integer.MAX_VALUE);
    dp[0]=0;
    for(int i=0;i<n-1;i++){
      for(int j=1;j<=k;j++){
        dp[i+j]=Math.min(dp[i]+Math.abs(h[i+j]-h[i]),dp[i+j]);
      }
    }
    System.out.println(dp[n-1]);
  }
}

Measured memory_bytes: 50976
<?php
$N=(int)trim(fgets(STDIN));
$Ab=$As=explode(' ',trim(fgets(STDIN)));

for($i=0;$i<$N;$i++)
  for($j=$N-1;$i<$j;$j--)
    if($Ab[$j][1]<$Ab[$j-1][1])
      list($Ab[$j],$Ab[$j-1])=[$Ab[$j-1],$Ab[$j]];

for($i=0;$i<$N;$i++){
  $mini=$i;
  for($j=$i;$j<$N;$j++)
    if($As[$j][1]<$As[$mini][1]) $mini=$j;
  if($i==$mini) continue;
  list($As[$i],$As[$mini])=[$As[$mini],$As[$i]];
}

$diff=0;
for($i=0;$i<$N;$i++){
  if($Ab[$i]!=$As[$i]){$diff=1;break;}
}

$sAb=implode(' ',$Ab);
echo $sAb,PHP_EOL,'Stable',PHP_EOL;
if($diff) echo implode(' ',$As),PHP_EOL,'Not stable',PHP_EOL;
else echo $sAb,PHP_EOL,'Stable',PHP_EOL;

Measured memory_bytes: 15472
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int H,W; cin >> H >> W;
    vector<vector<int>> A(H, vector<int>(W)), B(H, vector<int>(W)), C(H, vector<int>(W));
    rep(i,H) rep(j,W) cin >> A[i][j];
    rep(i,H) rep(j,W) cin >> B[i][j];

    rep(i,H) rep(j,W) C[i][j] = abs(A[i][j] - B[i][j]);

    vector<vector<bitset<26000>>> dp(H+1, vector<bitset<26000>>(W+1));
    dp[0][1][13000] = 1;
    rep(i,H) {
        rep(j,W) {
            dp[i+1][j+1] |= (dp[i+1][j] << C[i][j]) | (dp[i+1][j] >> C[i][j]);
            dp[i+1][j+1] |= (dp[i][j+1] << C[i][j]) | (dp[i][j+1] >> C[i][j]);
        } 
    }

    rep(i,13000) {
        if (dp[H][W].test(13000+i)) {
            cout << i << endl;
            return 0;
        }
        if (dp[H][W].test(13000-i)) {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 21632
#include<bits/stdc++.h>
using namespace std;
int flag[101],flag1[101];
int main()
{
   int a,b,n,t,r,c=0,i,j;
   cin>>a>>b;
   if(a==b)
    cout<<"Yes"<<"\n";
   else
    cout<<"No"<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define LL long long
using namespace std;

int main() {
    int r , g , b, n;
    cin >> r >> g >> b >> n;
    int ans = 0;
    for(int i = 0; i * r <= n; i++)
    {
        for(int j = 0; i * r + j * g <= n; j++)
        {
            if((n - r*i - j * g) % b == 0)
                ans++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int cmp(const void *i,const void *j){
	return *(int*)j-*(int*)i;
}
int main(){
	int N,K;
	cin >> N;
	cin >> K;
	int h[N];
	for(int i=0;i<N;i++){
		cin >> h[i];
	}
	qsort(h,N,sizeof(int),cmp);
	long long int sum=0;
	for(int i=K;i<N;i++){
		sum+=h[i];
	}
	cout << sum << endl;
	return 0;
}




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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

struct PrimeList
{
    PrimeList()
    {
        mPrimeList.clear();
    }

    //! nまでの整数リストを構築
    void init(int n)
    {
        vector<bool> isPrime(n, true);
        isPrime[0] = isPrime[1] = false;
        for (int i = 2; i <= n; ++i)
        {
            if (!isPrime[i])
                continue;
            mPrimeList.push_back(i);
            for (int j = i * 2; j <= n; j += i)
                isPrime[j] = false;
        }
    }
    //! i番目の素数を取得
    int get(int i)
    {
        return mPrimeList[i];
    }
    vector<int> mPrimeList;
};

int P[105] = {0};

int main()
{
    int N;
    cin >> N;
    PrimeList pl;
    pl.init(N);

    FOR(i, N + 1, 2)
    {
        int n = i;
        int j = 0;
        while (n > 1)
        {
            if (n % pl.get(j) == 0)
            {
                P[pl.get(j)]++;
                n /= pl.get(j);
                continue;
            }
            ++j;
        }
    }

    int sum = 0;
    //! a^74で構成される数
    REP(i, N + 1)
    {
        if (P[i] >= 74)
            sum++;
    }
    //! a^2*b^24で構成される数
    REP(i, N + 1)
    {
        REP(j, N + 1)
        {
            if (i == j)
                continue;
            if (P[i] >= 2 && P[j] >= 24)
                sum++;
        }
    }
    //! a^4*b^14で構成される数
    REP(i, N + 1)
    {
        REP(j, N + 1)
        {
            if (i == j)
                continue;
            if (P[i] >= 4 && P[j] >= 14)
                sum++;
        }
    }
    //! a^2*b^4*c^4で構成される数
    REP(i, N + 1)
    {
        REP(j, N + 1)
        {
            FOR(k, N + 1, j + 1)
            {
                if (j == i || k == i)
                    continue;
                if (P[i] >= 2 && P[j] >= 4 && P[k] >= 4)
                    sum++;
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++)cin >> a[i];
  sort(a,a+n);
  int b=1,c=0;
  for(int i=1;i<n;i++){
    if(a[i]!=a[i-1]){
      if(b%2==1)c++;
      b=1;
    }
    else b++;
  }
  if(b%2==1)c++;
  cout << c;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, K;
  cin >> N >> K;
  REP(i, 35) {
    if (N <= POW(K, i) - 1) {
      cout << i << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self, N:int):
        """N: 大きさ
        size: 連結成分の大きさ
        """
        self.par = [i for i in range(N)]
        self.size = [1]*N
        self.rank = [1]*N
        
    def root(self, x:int)->int:
        """根を求める"""
        if self.par[x] == x: # if root
            return x
        else:
            self.par[x] = self.root(self.par[x]) # 経路圧縮
            return self.par[x]
        
    def is_same(self, x:int, y:int)->bool:
        """x と y が同じ集合に属するか否か"""
        return self.root(x)==self.root(y)
    
    def unite(self, x:int, y:int):
        """y を x の属する集合に併合"""
        root_x = self.root(x)
        root_y = self.root(y)
        if root_x == root_y: return
        if self.rank[root_x] == self.rank[root_y]:
            self.rank[root_x] += 1
        elif self.rank[root_x]<self.rank[root_y]:
            root_x,root_y = root_y,root_x
        # 短いほう(y)を長いほう(x)にくっつける
        self.par[root_y] = root_x
        self.size[root_x] += self.size[root_y]
        self.size[root_y] = 0 # もういらない
        
    def get_size(self, x:int)->int:
        """xの属するグループのサイズ"""
        return self.size[self.root(x)]

H,W = map(int, input().split())
grid = [input() for _ in range(H)]
uf = UnionFind(H*W)
for h in range(H):
    for w in range(W):
        for i,j in zip([0,0,1,-1], [1,-1,0,0]):
            if not (0 <= h+i < H and 0 <= w+j < W): 
                continue
            if grid[h][w]=="#" and grid[h+i][w+j]=="#":
                uf.unite(h*W + w, (h+i)*W + w+j) 
                
        #print([uf.root(n) for n in range(H*W)])

ans = "Yes"
for h in range(H):
    for w in range(W):
        if grid[h][w]=="#":
            if uf.get_size(h*W + w)<2:
                ans = "No"
print(ans)

Measured memory_bytes: 3192
#include <stdio.h>
int main(int argc, const char *argv[])
{
  char b, c[100];
  c['A'] = 'T';
  c['T'] = 'A';
  c['G'] = 'C';
  c['C'] = 'G';
  scanf("%c", &b);
  printf("%c\n", c[b]);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
 
ll gcd(ll x, ll y) {
	if(y==0) return x;
	return gcd(y,x%y);	
}

ll lcm(ll x, ll y) {
	ll z=gcd(x,y);
	return x/z*y;
}

int main()
{
	int n,cnt=0,ans=0;
	cin >> n;
	int a[2][n];
	rep(i,2){
		rep(j,n) cin >> a[i][j];
	}
	rep(i,n){
		for(int j=0;j<=i;j++) cnt+=a[0][j];
		for(int j=i;j<n;j++) cnt+=a[1][j];
		ans=max(ans,cnt);
		cnt=0;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //AtCoder
#include <iostream> //Codeforces
#include <vector> //Codeforces

#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Vc vector<char>
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl

using namespace std;
/****************************** START ******************************/

signed main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << max(a*c,max(a*d,max(b*c,b*d)));
}

Measured memory_bytes: 3616
n=int(input())
a=list(map(int,input().split()))
a=[-(i+1)+j for i,j in enumerate(a)]
a.sort()
if len(a)%2==0:
    tmp=len(a)//2
    b=(a[tmp]+a[tmp-1])//2
else:
    tmp=len(a)//2
    b=a[tmp]
print(sum(map(lambda x:abs(x-b),a)))

Measured memory_bytes: 26128
N = int(input())
A = list(map(int,input().split()))

A_plus = []
A_zero = []
A_minus = []

a_abs_min = 10**10

for a in A:
    if a > 0:
        A_plus.append(a)
    elif a == 0:
        A_zero.append(a)
    else:
        A_minus.append(a)
        
    if abs(a) < a_abs_min:
        a_abs_min = abs(a)
        
if len(A_minus)%2 == 0:
    ans = sum(A_plus)-sum(A_minus)
else:
    ans = sum(A_plus)-sum(A_minus) - 2*a_abs_min
print(ans)

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

int main() {
  int n;
  cin >> n;
  vector<int> b(n-1);
  for(int i;i < n-1;i++){
    cin >> b.at(i);
  }
  
  if(n == 2){
    cout << b.at(0)*2 << endl;
    return 0;
  }
  
  vector<int> a(n);
  for(int j = 0;j < n-1;j++){
    if(j == 0){
      a.at(0) = b.at(j);
      a.at(1) = min(b.at(j),b.at(j+1));
    }else if(j < n-2){
      a.at(j+1) = min(b.at(j),b.at(j+1));
    }else{
      a.at(j+1) = b.at(j);
    }
  }
  int ans = 0;
  for(int x: a){
    ans += x;
  }
  
  cout << ans << endl; 

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static boolean win(StringBuilder a, StringBuilder b){
		StringBuilder c = new StringBuilder(a);
		StringBuilder d = new StringBuilder(b);
		for(int i=0; i<c.length(); i++){
			if(c.charAt(i) == '?') c.setCharAt(i, 'a');
		}
		for(int i=0; i<d.length(); i++){
			if(d.charAt(i) == '?') d.setCharAt(i, 'z');
		}
		for(int i=0; i<c.length() && i<d.length(); i++){
			if(c.charAt(i) != d.charAt(i)){
				return c.charAt(i) < d.charAt(i);
			}
		}
		return c.length() <= d.length();
	}
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int a[] = new int[n];
		for(int i=0; i<n; i++) a[i] = sc.nextInt();
		long ans = (long)1e11;
		for(int i=0; i<(1<<n); i++){
			int cnt = 0;
			long cst = 0, cur = 0;
			for(int j=0; j<n; j++){
				if((i >> j) % 2 == 1){
					if(cur < a[j]) cur = a[j];
					else{
						cst += cur - a[j] + 1;
						cur++;
					}
					cnt++;
				}
				else{
					if(cur < a[j]){
						cur = a[j];
						cnt++;
					}
				}
			}
			if(cnt >= k) ans = Math.min(ans,  cst);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22996
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

int w, h, n;
int l, r, u, d;

const int MAX = 100;

void init()
{
	cin >> w >> h >> n;

	l = d = 0;
	r = w;
	u = h;

}

int main()
{
	init();

	REP(i, n)
	{
		int x, y, a;
		cin >> x >> y >> a;

		switch (a)
		{
		case 1:
			chmax(l, x);
			break;
		case 2:
			chmin(r, x);
			break;
		case 3:
			chmax(d, y);
			break;
		case 4:
			chmin(u, y);
			break;
		}
	}

	//cout << "l : " << l << ", r : " << r << endl;
	//cout << "u : " << u << ", d : " << d << endl;

	if (d >= u || l >= r)
	{
		cout << 0 << endl;
	}

	else
	{
		cout << (r - l)* (u - d) << endl;

	}

}


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


int main()
{
	int s, w;
	cin >> s >> w;

	if (w >= s) {
		cout << "unsafe" << endl;
	}
	else {
		cout << "safe" << endl;
	}

	return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
 
typedef long long ll;
 
 
int main(){
	string s;
	cin >> s;
	bool f = true;
	for(int i=0;i<s.size();++i){
		if(i%2 == 0){
			if(!(s[i] == 'R' || s[i] == 'U' || s[i] == 'D' )){
				f = false;
				break;
			}
		}else{
			if(!(s[i] == 'L' || s[i] == 'U' || s[i] == 'D' )){
				f = false;
				break;
			}
		}
	}
	
	if(f) cout << "Yes" <<endl;
	else cout << "No" <<endl;
	
	return 0;
}



Measured memory_bytes: 256
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define rev(a) (a).rbegin(), (a).rend()
#define all2(a, b) (a).begin(), (a).begin() + (b)

int main()
{
        int X, Y, A, B, C;
        cin >> X >> Y >> A >> B >> C;
        vector<int> q(A), p(B), r(C);
        rep(i, A) cin >> q[i];
        rep(i, B) cin >> p[i];
        rep(i, C) cin >> r[i];

        sort(rev(q));
        sort(rev(p));
        sort(rev(r));

        ll ans = 0;
        vector<int> vec;
        rep(i, X) vec.push_back(q[i]);
        rep(i, Y) vec.push_back(p[i]);
        rep(i, C) vec.push_back(r[i]);

        sort(rev(vec));
        rep(i, X + Y) ans += vec[i];

        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


bool check(ll i){
  string str = to_string(i);
  rep(i,str.size()){
    if(str[i] != str[str.size()-1-i]) return false;
  }
  return true;
}


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

  ll A , B ; cin >> A >> B ; 
  ll ans = 0;

  for(ll i = A ; i<= B ;i++)
    if(check(i)) ans ++ ;

  cout << ans << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define trav(v, x) for (auto v : x)
#define re(x, y, z) for (int x=y; x<z; ++x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;


int main() {
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    if (x / d >= k) cout << x - k * d << endl; 
    else {
        ll t = x / d;
        ll r = x - t * d;
        ll res = k - t;
        if (res % 2 == 0) cout << r << endl;
        else cout << abs(r - d) << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;

#define ll long long
#define pal pair<long,long>
#define pad pair<double,double>
#define PB push_back
#define MP make_pair
#define F first
#define S second

const ll MOD = 1e9+7;
const ll INF = 1e18;
const double EPS = 1e-8;

long long pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
	ll h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    cout << (h2-h1)*60+m2-m1-k << endl;
    return 0;
}

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

int main(void) {
    long n;
    cin >> n;
    vector<vector<long>> f(n, vector<long>(10));
    for(auto &l: f)
        for(auto &e: l)
            cin >> e;
    vector<vector<long>> p(n, vector<long>(11));
    for(auto &l: p)
        for(auto &e: l)
            cin >> e;

    long r = -1e13;
    for(long i=1; i<1<<10; i++) {
        long rr = 0;
        for(long j=0; j<n; j++) {
            long c = 0;
            for(long k=0; k<10; k++)
                if((f[j][k]) && ((i>>k)&1))
                    c++;
            rr += p[j][c];
        }
        r = max(r, rr);
    }

    cout << r << endl;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

map<int, int> in;
map<int, int> ni;
vi score;
int id, num;
int q;

int main()
{
  while(~scanf("%d,%d", &id, &num) && id || num){
    in[id] = num;
    score.pb(num);
  }

  sort(ALL(score));
  score.erase(unique(ALL(score)), score.end());

  rep(i, score.size()) ni[score[i]] = score.size() - i;

  while(cin >> q) cout << ni[in[q]] << endl;

  return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    ll ans = 0;
    rep(i,1011) {
        if ( (floor(ans * 0.08) == a) && (floor(ans * 0.1) == b) ) break;
        ++ans;
    }
    if (ans == 1011) cout << "-1" << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main() {
	int n;
	scanf("%d",&n);
	char str[4+1];
	int ctr[4] = {0};
	for (int i = 0; i < n; i++)
	{
		scanf("%s",&str);
		if (str[0] == 'A')
		{
			ctr[0]++;
		}
		else if (str[0] == 'W')
		{
			ctr[1]++;
		}
		else if (str[0] == 'T')
		{
			ctr[2]++;
		}
		else if (str[0] == 'R')
		{
			ctr[3]++;
		}
	}
	printf("AC x %d\n",ctr[0]);
	printf("WA x %d\n",ctr[1]);
	printf("TLE x %d\n",ctr[2]);
	printf("RE x %d\n",ctr[3]);
	return 0;
}

Measured memory_bytes: 1700
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

const int MAXR = 51;
const int MAXC = 51;
const int INF = 1<<28;
const int di[] = {0,1,0,-1};
const int dj[] = {1,0,-1,0};
int R, C, M;
char G[MAXR][MAXC];
int P[3][MAXR][MAXC];
vector<int> V[MAXR][MAXC];

vector<pair<int,int> > bfs(int r, int c, int gr, int gc) {
  queue<pair<int,int> > que;
  int vis[MAXR][MAXC];
  pair<int,int> path[MAXR][MAXC];
  fill(vis[0],vis[MAXR],INF);
  que.push(make_pair(r,c));
  vis[r][c] = 0;
  path[r][c] = make_pair(-1,-1);
  while(!que.empty()) {
    r = que.front().first;
    c = que.front().second;
    que.pop();
    for(int i = 0; i < 4; ++i) {
      int nr = r + di[i];
      int nc = c + dj[i];
      if(nr < 0 || nr >= R) continue;
      if(nc < 0 || nc >= C) continue;
      if(G[nr][nc] == '#') continue;
      if(vis[nr][nc] != INF) continue;
      vis[nr][nc] = vis[r][c] + 1;
      path[nr][nc] = make_pair(r,c);
      if(nr == gr && nc == gc) {
	vector<pair<int,int> > v;
	pair<int,int> p = make_pair(nr,nc);
	while(p.first != -1) {
	  v.push_back(p);
	  p = path[p.first][p.second];
	}
	reverse(v.begin(), v.end());
	return v;
      }
      que.push(make_pair(nr,nc));
    }
  }
  return vector<pair<int,int> >();
}

int main() {
  while(cin >> R >> C >> M) {
    for(int i = 0; i < R; ++i) {
      for(int j = 0; j < C; ++j) {
	cin >> G[i][j];
      }
    }
    for(int k = 0; k < 3; ++k) {
      for(int i = 0; i < R; ++i) {
	for(int j = 0; j < C; ++j) {
	  cin >> P[k][i][j];
	}
      }
    }

    fill(V[0],V[MAXR],vector<int>());
    int r, c, t;
    r = c = -1;
    t = 0;
    while(M--) {
      int nr, nc;
      cin >> nr >> nc;
      if(r == -1) {
	V[nr][nc].push_back(0);
      } else {
	vector<pair<int,int> > v = bfs(r,c,nr,nc);
	/*
	for(int i = 0; i < v.size(); ++i) {
	  cout << v[i].first << ", " << v[i].second << endl;
	}
	cout << endl;
	*/
	for(int i = 1; i < v.size(); ++i) {
	  V[v[i].first][v[i].second].push_back(++t);
	}
      }
      r = nr;
      c = nc;
    }
    int res = 0;
    for(int i = 0; i < R; ++i) {
      for(int j = 0; j < C; ++j) {
	vector<int> &v = V[i][j];
	if(v.size() == 0) continue;
	res += P[1][i][j] + P[2][i][j];
	for(int k = 1; k < v.size(); ++k) {
	  int d = v[k] - v[k-1];
	  res += min(d*P[0][i][j], P[1][i][j]+P[2][i][j]);
	}
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 6500
import heapq
from collections import defaultdict

N = int(input())
towns = [[] for _ in range(N)]
for i in range(N):
    x,y = map(int, input().split())
    towns[i] = (i, x, y)

# x,yが小さい順に並び替える
tx = sorted(towns, key=lambda x: x[1])
ty = sorted(towns, key=lambda x: x[2])

# 辺を作ってheapqに突っ込む
q = []
for i in range(1,N):
    heapq.heappush(q, (tx[i][1]-tx[i-1][1], tx[i][0], tx[i-1][0]))
    heapq.heappush(q, (ty[i][2]-ty[i-1][2], ty[i][0], ty[i-1][0]))

class UnionFind:
    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.rank = [0] * N # 最初はそれぞれのノードが誰ともUnionをつくってないから木の深さが０
        self.count = 0 # unite回数
    
    # 根を返す
    def root(self, a):
        if self.parent[a] == a:
            return a
        else:
            # 親を見に行く
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]
    
    # 同じUnionに属するかどうか
    def is_same(self, a, b):
        return self.root(a) == self.root(b)
    
    # 同じUnionにする
    def unite(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb:
            return 
        if self.rank[ra] < self.rank[rb]:
            self.parent[ra] = rb
        else:
            self.parent[rb] = ra
            if self.rank[ra] == self.rank[rb]:
                self.rank[ra] += 1
        self.count += 1

uf = UnionFind(N)
ans = 0
while q:
    cost, a, b = heapq.heappop(q)
    if not uf.is_same(a,b):
        uf.unite(a,b)
        ans += cost

print(ans)

Measured memory_bytes: 50732
using System;

namespace A___Signboard
{
    class Program
    {
        static void Main (string[] args)
        {
            var s = Console.ReadLine ();
            var a = "CODEFESTIVAL2016";
            var count = 0;
            for (var i = 0; i < 16; i++)
            {
                if (s[i] != a[i])
                    count++;
            }
            Console.WriteLine (count);
        }
    }
}

Measured memory_bytes: 11092