akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
	ll m=0;
	vector<P> v;
	ll a;
	ll sub[4] = {1,2,4,8};	//2lあたりの値段に変換
	rep(i,4){
		cin >> a;
		//v.push_back(P(sub[i], (a*8)/sub[i]));
		v.push_back(P((a*8)/sub[i], sub[i]));
	}
	sort(v.begin(), v.end());
/*
	rep(i,4){
		cout << v[i].first << " " << v[i].second << endl;
	}
*/
	ll n;
	cin >> n;
	n*=4;

	while(n>0){
		rep(i,4){
			if (n>=v[i].second){
				ll sub = n/v[i].second;
				n -= sub * v[i].second;
				m += sub * v[i].second * v[i].first;
			}
		}
	}

	cout << m/8 << endl;
	return 0;
}




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

int main(void)
{
    string N, N1, N2, N3, N4;

    cin >> N;
    N1 = N.substr(0, 1);
    N2 = N.substr(1, 1);
    N3 = N.substr(2, 1);
    N4 = N.substr(3, 1);

    if ((N1 == N2 && N2 == N3) || (N2 == N3 && N3 == N4))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string A; cin>>A; int z=A.size();
  long long ans=0, a=0, b=0;
  for(int i=0; i<z; i++){
    if(A[i]=='B'){
      a+=i;
      b++;
    }
  }
  ans=(z-b+z-1)*b/2-a;
  cout<<ans<<endl;
}

Measured memory_bytes: 640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include "bits/stdc++.h"

using namespace std;
#define int long long


class AHappyBirthday {
public:
    void solve(std::istream &in, std::ostream &out) {
      int a, b;
      in >> a >> b;
      out << (a <= 8 && b <= 8 ? "Yay!" : ":(") << endl;
    }
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
  AHappyBirthday solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int k,a,b,x,i;
   cin>>k;
   cin>>a>>b;
   for(i=1;i<=b;i++){
   x=k*i;
   if(x>=a && x<=b){
         cout<<"OK"<<endl;
          return 0;
   }
          //else{
         //          cout<<"NG"<<endl;
         // return 0;
         // }
   }
   cout<<"NG"<<endl;
}


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

inline void ioThings() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#define debug(x) cerr << #x << ": <" << (x) << ">\n"
#else
#define debug(x)
#endif
}

#define rep(i, n) for (int i = 0; i < n; i++)
#define dotc()    int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)     (int)x.size()
#define eb        emplace_back
#define pb        push_back
#define mp(x, y)  make_pair(x, y);
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define fi        first
#define se        second
#define mod       1000000007

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

int main() {
  ioThings();

  string s;
  cin >> s;
  s[1] = s[1] == 'R' ? 'B' : 'R';
  cout << s;

  return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
	__INIT() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}__init;


int main(void) {
	ll x, a;
	cin >> x >> a;
	if (x < a) cout << 0 << endl;
	else cout << 10 << endl;
	return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
int main(void){
    int n,k;
    int x[9<<14];
    
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%d",&x[i]);
    }
    int min=300000000;
    for(int j=0;j<n-k+1;j++){
        min=fmin(x[j+k-1]-x[j]+fmin(abs(x[j]),abs(x[j+k-1])),min);
    }
    printf("%d",min);
}

Measured memory_bytes: 2512
import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        int b[] = new int[n];
        int sum[] = new int[n];
        long ans = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            sum[i] = a[i] + b[i];
            ans += a[i];
        }
        Arrays.sort(sum);
        sc.close();
        for (int i = n - 2; 0 <= i; i -= 2) {
            ans -= sum[i];
        }
        System.out.println(ans);
    }

}


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

using namespace std;

typedef long long int ll;

void solve()
{
	string s, s1;
	cin >> s >> s1;
	string s2 = s1.substr(0,(int)s.size());
	if(s == s2) cout << "Yes";
	else cout << "No";
}

int main()
{
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}



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

struct dot{
    double x;
    double y;
};

void koch(struct dot d1, struct dot d2, int n){
    if(n == 0){
        return;
    }

    struct dot s;
    s.x = d1.x * 2 / 3 + d2.x * 1 / 3;
    s.y = d1.y * 2 / 3 + d2.y * 1 / 3;

    struct dot t;
    t.x = d1.x * 1 / 3 + d2.x * 2 / 3;
    t.y = d1.y * 1 / 3 + d2.y * 2 / 3;

    struct dot u;
    u.x = ((d2.x - d1.x) - sqrt(3) * (d2.y - d1.y)) / 6 + d1.x * 2 / 3 + d2.x * 1 / 3;
    u.y = (sqrt(3) * (d2.x - d1.x) + (d2.y - d1.y)) / 6 + d1.y * 2 / 3 + d2.y * 1 / 3;

    koch(d1, s, n - 1);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(s, u, n - 1);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(u, t, n - 1);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(t, d2, n - 1);
}

int main(void){
    int N;
    scanf("%d", &N);

    struct dot p1;
    p1.x = 0.0;
    p1.y = 0.0;
    struct dot p2;
    p2.x = 100.0;
    p2.y = 0.0;
        
    printf("%.8f %.8f\n", p1.x, p1.y);
    koch(p1, p2, N);
    printf("%.8f %.8f\n", p2.x, p2.y);

    return 0;
}



Measured memory_bytes: 2732
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
vector<string> bit;


void subBin(string str, int n)
{
    if (n == 0){
        bit.push_back(str);
    }
    if (n > 0) {
        subBin(str + "0", n - 1);
        subBin(str + "1", n - 1);
    }
}

string toBin(int n){
    if(n == 1)return "1";
    else if(n == 0)return "0";

    return toBin(n/2)  + to_string(n%2);
}
int main(){
    double n, m;
    cin >> n >> m;

    double sec = 1900*m + 100*(n-m);

    double ans = 0;
    double good = pow(0.5, m);
    double fail = 1.0 - good;

    rep(i, 10000){
        ans += (i+1)*sec*good*pow(fail, i);
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np
 
def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W
 
# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

N = i_inpl()
A = l_inpl()
d = defaultdict(int)

for Ai in A:
    d[Ai] += 1

k = len(d)

if k % 2 == 0:
    print(k-1)
else:
    print(k)

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

const int bB = 6;
const int B = 1 << bB;

int up(int x) {
	return (x + (1 << bB) - 1) >> bB;
}

int down(int x) {
	return x >> bB;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q;
	cin >> n >> q;
	const int H = up(n);
	vector<int> bv(H, INT_MAX), v(n, INT_MAX);
	while (q--) {
		int com, x, y;
		cin >> com >> x >> y;
		if (com == 0) {
			v[x] = y;
			int p = down(x);
			bv[p] = INT_MAX;
			for (int i = p << bB; i < n && i < (p << bB) + B; i++) {
				bv[p] = min(bv[p], v[i]);
			}
		}
		else {
			y++;
			int res = INT_MAX;
			for (int i = x; i < y && i < (up(x) << bB); i++) {
				res = min(res, v[i]);
			}
			if (up(x) <= down(y)) {
				for (int i = up(x); i < down(y); i++) {
					res = min(res, bv[i]);
				}
				for (int i = down(y) << bB; i < y; i++) {
					res = min(res, v[i]);
				}
			}
			printf("%d\n", res);
		}
	}
	return 0;
}



Measured memory_bytes: 3212
'use strict'

const main = (input) => {
    input = input.split('\n')
    const N = parseInt(input[0])
    const D = parseInt(input[1].split(' ')[0])
    const X = parseInt(input[1].split(' ')[1])
    const As = input.slice(2, N + 2).map(i => parseInt(i))
    const counts = As.map((v, i) => {
        let count = 0
        for(let j = 0; ; j++){
            if(v * j + 1 <= D){
                count++
            }else{
                return count
            }
        }
    })
    console.log(counts.reduce((p, c) => p + c) + X)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 7372
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        String T = sc.next();

        char[] Sc = S.toCharArray();
        char[] Tc = T.toCharArray();

        String ans = "";
        for(int i=0; i<N; i++) {
            ans += Sc[i];
            ans += Tc[i];
        }

        System.out.println(ans);

    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()

int main() {
    int N;
    cin >> N;
    int count = 0;
    string s;
    cin >> s;
    rep(i, s.size()) {
        if (s[i] == 'W') {
            count++;
        }
    }
    int ans = 0;
    rep(i, s.size()-count) {
        if (s[i] == 'W') {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3744
#include<iostream>

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

int main(){
  int a,b;
  std::cin >> a;
  std::cin >> b;
  std::cout << gcd(a,b) << '\n';
}

Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>

using namespace std;
 
typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no { cout << -1; return; }

void solve() {
    int n; cin >> n;
    cout << (n % 10 == 7 || n / 10 % 10 == 7 || n / 100 == 7 ? "Yes" : "No");
}
 
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}


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

using namespace std;

typedef long long ll;
#define mems(p) memset(p,-1,sizeof(p))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\n"

const int mxN = 1e5;
const ll MOD = 1e9 + 7;

void fast()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}

int main() {
	fast();
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		int ans = 0;
		for (int x = 1; 2 * x * x <= n; ++x)
		{
			for (int y = x; y * y <= n; ++y) {
				int yplusx = x + y;
				// z(z+yplusx) = n - x^2 - y^2 - xy
				int tmp = i - x*x - y*y - x*y;
				// z^2 +(yplusx)z - tmp = 0
				int a = 1, b = yplusx, c = -tmp;
				int temp = b*b - 4*a*c;
				//cout << "i: " << i << "x: " <<x <<" y: " << y <<" tmp: " <<temp << nl;
				if (temp < 0) continue;
				int root = sqrt(temp);
				if (root*root == temp && (root - b) % 2 == 0 && (root-b)/2 >= y) {
					int z = (root-b)/2;
					if (x == y && y == (root-b)/2) ++ans;
					else if (x!=y && y !=z && z != x) ans += 6;
					else ans += 3;
				}
			}
		}
		cout << ans << nl;
	}
}

Measured memory_bytes: 3592
N = int(input())
Ai_list = [number for number in map(int, input().split())]
Ai_And_i_list = {}
for i, Ai in enumerate(Ai_list):
    Ai_And_i_list[Ai] = i + 1
sorted_list = sorted(Ai_And_i_list.items())
for key, value in sorted_list:
    print(value)

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

using namespace std;
#define FOR(i,bg,ed) for(int i=bg;i<ed;i++)
#define REP(i,n) FOR(i,0,n)
template<typename T>
bool chmax(T& l,T r){
    bool ret = l<r;
    if(l<r)l=r;
    return ret;
}
template<typename T>
bool chmin(T& l,T r){
    bool ret = l>r;
    if(l>r)l=r;
    return ret;
}
typedef long long LL;
typedef vector<LL> V;
string s;
const LL inf = 1e14;
const int empty = 1e9;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> p(n+2,-1);
    REP(i,m){
        int c,d;
        cin>>c>>d;
        chmax(p[c],d);
    }
    LL res= n+1;
    int bg = empty;
    int ed = -1;
    REP(i,n+1){
        if(p[i+1]>=i+1){
            chmin(bg,i+1);
            chmax(ed,p[i+1]);
        }
        if(bg!=empty&&ed<=i+1){
            res+=2*(i+1-bg);
            ed=-1;
            bg = empty;
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3156
#include <stdio.h>
#include <stdlib.h>
int main(void){

    int n,i,j,ans,z;
    int w[100];
    int sum1[100];
    int sum3[100];
    int sum=0;

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

    for(i=0;i<n;i++){
        sum+=w[i];
    }

    for(i=0;i<n;i++){
        sum3[i]=0;
        for(j=i;j<n;j++){
            sum3[i]+=w[j];
        }
        sum1[i]=sum-sum3[i];

    }

    ans=sum;


    for(i=0;i<n;i++){
        z=abs(sum1[i]-sum3[i]);
        if(z<ans){
            ans=z;
        }
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head &&head, Tail &&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

void Main() {
  Cin(int, n);
  Cin(int, t, a);
  using pid = pair<int, double>;
  vector<pid> vp(n);
  for (int i = 0; i < n; ++i) {
    Cin(double, d);
    vp[i] = {i + 1, d};
  }

  for (auto &e : vp) e.second = t - e.second * 0.006;
  for (auto &e : vp) e.second = abs(e.second - a);

  sort(all(vp), [](pid a, pid b) { return a.second < b.second; });

  cout << vp[0].first << endl;
  return;
}

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

Measured memory_bytes: 384
#include <iostream>
#include <cstdint>

using namespace std;

int main()
{
  while(true){
    unsigned int n;
    cin >> n;

    if(n == 0) break;

    unsigned int min_val = UINT32_MAX;
    unsigned int max_val = 0;
    unsigned int count = 0;
    for(unsigned int i = 0; i < n; i++){
      unsigned int val;
      cin >> val;
      min_val = min(val, min_val);
      max_val = max(val, max_val);
      count += val;
    }
    cout << (count - min_val - max_val) / (n -2) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3072
#include <iostream>
using namespace std;
void ABC100(void);
void ABC101(void);
void ABC102(void);
void ABC103(void);
void ABC104(void);
void ABC105(void);
void ABC106(void);
void ABC107(void);
void ABC108(void);
void ABC109(void);

int main(void){
    ABC103();
}

void ABC103(){
    int a,b,c,min,max;
    cin>>a>>b>>c;
    min=a;
    max=a;
    if(b<min)min=b;
    if(c<min)min=c;
    if(b>max)max=b;
    if(c>max)max=c;
    cout<<max-min<<endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 3000005
#define ll long long
#define mod 1000000009
int n, m, k, ans;
int A[20], B[20], C[20];
int bel[N], sum[N], siz[N];
int fac[N], inv[N];
int Getbel(int x)
{
	if (!bel[x])
		return x;
	return bel[x] = Getbel(bel[x]);
}
int ksm(int a, int k)
{
	if (!k)
		return 1;
	int p = ksm(a, k / 2);
	if (k & 1)
		return (ll)p * p % mod * a % mod;
	return (ll)p * p % mod;
}
int main()
{
	fac[0] = 1;
	for (int i = 1; i <= N - 5; i++)
		fac[i] = (ll)fac[i - 1] * i % mod;
	inv[N - 5] = ksm(fac[N - 5], mod - 2);
	for (int i = N - 5; i >= 1; i--)
		inv[i - 1] = (ll)inv[i] * i % mod;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++)
	{
		scanf("%d%d%d", &A[i], &B[i], &C[i]);
		k += C[i];
	}
	for (int i = 0; i < (1 << k); i++)
	{
		sum[1] = n * 3;
		sum[2] = sum[3] = 0;
		int w = 0;
		for (int j = 1; j <= m; j++)
		{
			bel[A[j]] = bel[B[j]] = 0;
			siz[A[j]] = siz[B[j]] = 1;
		}
		int flg = 0, bit = 0;
		for (int j = 1; j <= m; j++)
		{
			if (C[j] == 1 && i & (1 << w))
				bit++;
			if (C[j] == 0 || (i & (1 << w)))
			{
				int x = Getbel(A[j]), y = Getbel(B[j]);
				if (x != y)
				{
					bel[x] = y;
					sum[siz[y]]--;
					sum[siz[x]]--;
					siz[y] += siz[x];
					if (siz[y] > 3)
					{
						flg = 1;
						break;
					}
					sum[siz[y]]++;
				}
			}
			w += C[j];
		}
		if (!flg)
		{
			int x = sum[1], y = sum[2];
			if (x >= y)
			{
				int now = fac[x];
				now = (ll)now * ksm(inv[3], (x - y) / 3) % mod * inv[(x - y) / 3] % mod;
				if (bit & 1)
					ans = (ans - now) % mod;
				else
					ans = (ans + now) % mod;
			}
		}
	}
	if (ans < 0)ans += mod;
	printf("%d\n", ans);
}



Measured memory_bytes: 26960
#include <stdio.h>
int main(void){
	int a,b;
	scanf("%d %d",&a,&b);
	int x = b-a;
	int i;
	int t=0;
	for(i=0;i<x;i++){
		t+=i;
	}
	printf("%d",t-a);
	return 0;
}

Measured memory_bytes: 128
#include <iostream> 
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define MAX 1000001
ll prime[MAX];
#define FAST           ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007

ll rec(vector<vector<ll> >& dp,vector<ll>& arr,int n,int i,int k,int w)
{
  ll ans=0;
  if(i>=n)
    return 0;

  if(dp[i][k]!=-1)
    return dp[i][k];


  if(k!=0)
  ans=max(rec(dp,arr,n,i+1,w,w),arr[i]+rec(dp,arr,n,i+1,k-1,w));
  else
  ans=max(rec(dp,arr,n,i+1,k,w),rec(dp,arr,n,i+1,w,w));

  return dp[i][k]=ans;

}

//ll t[400008];
// void build(vector<ll>& a, int v, int tl, int tr) {
//     if (tl == tr) {
//         t[v] = a[tl];
//     } else {
//         int tm = (tl + tr) / 2;
//         build(a, v*2, tl, tm);
//         build(a, v*2+1, tm+1, tr);
//         t[v] = max(t[v*2] ,t[v*2+1]);
//     }
// }

// ll maxi(int v, int tl, int tr, int l, int r) {
//     if (l > r) 
//         return 0;
//     if (l == tl && r == tr) {
//         return t[v];
//     }
//     int tm = (tl + tr) / 2;
//     return max(maxi(v*2, tl, tm, l, min(r, tm)) ,maxi(v*2+1, tm+1, tr, max(l, tm+1), r));
// }



// void update(int v, int tl, int tr, int pos, ll new_val) {
//     if (tl == tr) {
//         t[v] = new_val;
//     } else {
//         int tm = (tl + tr) / 2;
//         if (pos <= tm)
//             update(v*2, tl, tm, pos, new_val);
//         else
//             update(v*2+1, tm+1, tr, pos, new_val);
//         t[v] = max(t[v*2] ,t[v*2+1]);
//     }
// }


struct hash_pair {
   template <class T1, class T2>
   size_t operator()(const pair<T1, T2>& p) const{
      auto hash1 = hash<T1>{}(p.first);
      auto hash2 = hash<T2>{}(p.second);
      return hash1 ^ hash2;
   }
};

bool issafe(int x,int y,int h,int w,vector<vector<char> >& m)
{
  return x>=1 && x<=h && y>=1 && y<=w && m[x][y]!='#'; 
}

int main() { 

int h,w,ch,dh,cw,dw;
cin>>h>>w>>ch>>cw>>dh>>dw;

vector<vector<int> >dist(h+1,vector<int>(w+1,INT_MAX));
vector<vector<char> >m(h+1,vector<char>(w+1,'.'));

for(int i=1;i<=h;i++)
  for(int j=1;j<=w;j++)
    cin>>m[i][j];


dist[ch][cw]=0;
deque<pair<int,int> > q;
q.push_back({ch,cw});
int dirx[]={0,1,0,-1};
int diry[]={1,0,-1,0};

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

  for(int i=0;i<4;i++)
    if(issafe(temp.first+dirx[i],temp.second+diry[i],h,w,m))
    {
      if(dist[temp.first+dirx[i]][temp.second+diry[i]]>dist[temp.first][temp.second])
        {
          dist[temp.first+dirx[i]][temp.second+diry[i]]=dist[temp.first][temp.second];
          q.push_front({temp.first+dirx[i],temp.second+diry[i]});
        }
    }

  for(int i=-2;i<=2;i++)
    for(int j=-2;j<=2;j++)
    {
      if(issafe(temp.first+i,temp.second+j,h,w,m))
      {
         if(dist[temp.first+i][temp.second+j]>dist[temp.first][temp.second]+1)
        {
          dist[temp.first+i][temp.second+j]=dist[temp.first][temp.second]+1;
          q.push_back({temp.first+i,temp.second+j});
        }
      }
    }


}

cout<<(dist[dh][dw]!=INT_MAX?dist[dh][dw]:-1);

return 0;

}


Measured memory_bytes: 8680
from collections import *
N,K,L = map(int,input().split())

def root(x):
  while 0<=p[x]:
    x = p[x]
  return x

def unite(x,y):
  x = root(x)
  y = root(y)
  if x==y:
    return
  if x>y:
    x,y=y,x
  p[x]+=p[y]
  p[y]=x

def g(x):
  global p
  p=N*[-1]
  for _ in range(x):
    a,b = map(int,input().split())
    unite(a-1,b-1)
  return [root(n) for n in range(N)]

z = [*zip(g(K),g(L))]
C = Counter(z)
print(*[C[t] for t in z])

Measured memory_bytes: 54460
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int INF=1000000000;
const int MOD=1000000007;

int main()
{
 int x;
 cin >> x;
 if(x>=2000){
   cout << 1;
 }else{
   if((int)(x/100)-1==(int)((x-1)/105)) cout << 1;
   else cout << 0;
 }
  return 0;
}

Measured memory_bytes: 256
/*
 * Author: FreeIdea
 * Created Time:  2011/8/24 15:54:06
 * File Name: C.cpp
 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
const int maxint = -1u>>1;
template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}
template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}

const double eps = 1e-9;

int sgn(double x) {
    return (x > eps) - (x < -eps);
}

struct point {
    double x, y;
    point(double _x = 0, double _y = 0) : x(_x), y(_y) {}
    double len() const {
        return sqrt(x * x + y * y);
    }
    void input() {
        scanf("%lf%lf", &x, &y);
    }
};

double operator * (const point &p1, const point &p2) {
    return p1.x * p2.y - p2.x * p1.y;
}

double operator ^ (const point &p1, const point &p2) {
    return p1.x * p2.x + p1.y * p2.y;
}

point operator - (const point &p1, const point &p2) {
    return point(p1.x - p2.x, p1.y - p2.y);
}

double d;

point p, v, o;

int main() {
    while(scanf("%lf", &d) == 1) {
        if(sgn(d) == 0) break;
        p.input();
        v.input();
        o = point(0.0, 0.0);
        if(sgn((p - o) * v)) {
            printf("impossible\n");
        }
        else {
            if(sgn((p - o) ^ v) <= 0) {
                double dis = (p - o).len();
                if(sgn(dis - d) <= 0) {
                    printf("%.7f\n", dis);
                }
                else {
                    printf("impossible\n");
                }
            }
            else {
                double dis = 2.0 - (p - o).len();
                if(sgn(dis - d) <= 0) {
                    printf("%.7f\n", dis);
                }
                else {
                    printf("impossible\n");
                }
            }
        }
    }        
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define Endl endl
typedef long long int lli;
void solve(){
  int N;
  cin>>N;
  int ans = 0;
  while(N%1000!=0)
    ans++,N++;
  cout<<ans<<endl;
}
int main(){
  int t;
  // cin>>t;
  t =1;
  while(t--){
    solve();
  }
}


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

int main(){

  int N , Q;
  string S;

  cin >> N >> Q ;
  cin >> S;

  vector<int> sum(N + 1 , 0);
  vector<int> l(Q), r(Q);

  for(int i = 0 ; i < Q ; i++){
    cin >> l[i] >> r[i];
  }

  for(int i = 0 ; i < N ; i++){
    if(S[ i - 1 ] == 'A' && S[ i ] == 'C'){
      sum[ i + 1 ] = sum[ i ] + 1;
    } else {
      sum[i + 1 ] = sum[ i ];
    }
  }

  for(int i = 0 ; i < Q ; i++){
    int ans = sum[r[i]] - sum[l[i] - 1 + 1];
    cout << ans << endl;
  }

}

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

int main(){
  string a;
  cin >> a;
  for(int i = 0;i < 3;i++){
    if(a[i] == '1'){
      cout << 9;
    }else{
      cout << 1;
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

A,B,C=MAP()

if A<=C<=B or B<=C<=A:
    Yes()
else:
    No()


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i];
    if(i == SZ(s)-1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

int cntdots(string s) {
  int res = 0;
  REP(i, SZ(s)) {
    if(s[i] == '.') res++;
    else break;
  }
  return res;
}

void solve(vector<string> &s, const vi cnt) {
  int n = SZ(s);
  FOR(i, 1, n) {
    int nowcnt = cntdots(s[i]);
    nowcnt--;
    RREP(j, i-1) {
      if(s[j][nowcnt] == '+') {
        FOR(k, j+1, i) {
          s[k][nowcnt] = '|';
        }
        break;
      } else if('a' <= s[j][nowcnt] && s[j][nowcnt] <= 'z') {
        break;
      }
    }
    s[i][nowcnt] = '+';
  }
}

void removedots(vector<string> &s, const vi &cnt) {
  int n = SZ(s);
  REP(i, n) {
    REP(j, SZ(s[i])) {
      if(s[i][j] == '.') s[i][j] = ' ';
    }
  }
}


int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  while(1) {
    int n; cin>>n;
    if(n==0) return 0;
    vector<string> s(n);
    REP(i, n) cin >> s[i];
    vi cnt(n);
    REP(i, n) {
      cnt[i] = cntdots(s[i]);
    }
    solve(s, cnt);
    removedots(s, cnt);
    REP(i, n) {
      cout << s[i] << endl;
    }
  }
}



Measured memory_bytes: 3796
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<math.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 5000005

int t,n,q,x,y;
int a[5000005],b[5000005],tree[5000005];
int cur[1000005],r[5000005];
bool vis[1000005];
int ans[500005];
vector < pair< pair<int,int>,int > > v;

//Query
int read(int idx)
{
    int sum=0;
    while(idx>0)
    {
        sum+=tree[idx];
        idx -= (idx & -idx);
    }
    return sum;
}

//Update
void update(int idx,int val)
{
    while(idx<=n)
    {
        tree[idx]+=val;
        idx += (idx & -idx);
    }
}

int main()
{
    //freopen("input.txt","r",stdin);

    memset(cur,INF,sizeof(cur));
    scanf("%d",&n);
    scanf("%d",&q);
    //Initialize the tree
    a[0]=tree[0]=0;
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);

    for(int i=n;i>0;i--)
    {
        r[i]=cur[a[i]];
        cur[a[i]]=i;
    }

    for(int i=1;i<=n;i++)
    {
        if(!vis[a[i]])
        {
            b[i]=b[i-1]+1;
            vis[a[i]]=true;
        }
        else
            b[i]=b[i-1];
        tree[i]=b[i]-b[i-(i & -i)];
    }

    //Get and Sort Queries
    
    for(int i=0;i<q;i++)
    {
        scanf("%d%d",&x,&y);
        v.pb(mp(mp(x,y),i));
    }
    sort(v.begin(),v.end());

    //Query and Update
    int pos=0;
    for(int i=1;i<=n;i++)
    {
        while((v[pos].X).X==i)
        {
            ans[(v[pos].Y)]=read((v[pos].X).Y);
            pos++;
        }
        update(i,-1); //Unmark
        update(r[i],1);  //Mark
    }
    for(int i=0;i<q;i++)
        cout<<ans[i]<<"\n";
}

Measured memory_bytes: 23948
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  cin >> N;
  int count = 0;
  for (int i = 0; i < 4; i++) {
    if (N.at(i) == '2'){
      count++;
    }
  }
  cout << count << endl;
}



Measured memory_bytes: 3552
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	double a, b, c, d, e, f;
	while (scan.hasNext()) {
	    a = scan.nextDouble();
	    b = scan.nextDouble();
	    c = scan.nextDouble();
	    d = scan.nextDouble();
	    e = scan.nextDouble();
	    f = scan.nextDouble();
	    solveSimultaneousEquation(a, b, c, d, e, f);
	    scan.nextLine();
	}
    }
    static void solveSimultaneousEquation (double a, double b, double c, double d, double e, double f) {
	double dx = d / a;
	double cx = c * dx - f;
	double dy = b * dx - e;
	double y = cx / dy;
	double x = (c - b * y) / a;
	System.out.println(String.format("%.3f", x) + " " + String.format("%.3f", y));
    }
}

Measured memory_bytes: 28292
N = int(input())
A, B = map(int, input().split())
P = list(map(int, input().split()))
P1 = 0
P2 = 0
P3 = 0
for pi in P:
    if pi <= A:
        P1 += 1
    elif pi <= B:
        P2 += 1
    else:
        P3 += 1

print(min(min(P1, P2), P3))


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

int main() {
	int h, w, d;
	cin >> h >> w >> d;
	int a[h][w];
	pair<int, int> ps[h * w + 1];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
			ps[a[i][j]] = {i, j};
		}
	}
	int dist[h * w + 1]{};
	for (int i = d + 1; i < h * w + 1; i++) {
		auto now = ps[i - d];
		auto next = ps[i];
		dist[i] = dist[i - d] + abs(now.first - next.first) + abs(now.second - next.second);
	}
	int q;
	cin >> q;
	for (int times = 0; times < q; times++) {
		int l, r;
		cin >> l >> r;
		cout << dist[r] - dist[l] << endl;
	}
	return 0;
}

Measured memory_bytes: 2560
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        while (true) {
            int m = Integer.parseInt(sc.next())
               ,f = Integer.parseInt(sc.next())
               ,r = Integer.parseInt(sc.next());
            if (m == -1 && f == -1 && r == -1)
                break;    
            else if (m == -1 || f == -1 || m + f < 30)
                pw.println("F");
            else if (m + f >= 80)
                pw.println("A");
            else if (m + f >= 65)
                pw.println("B");
            else if (m + f >= 50 || r >= 50)
                pw.println("C");
            else
                pw.println("D");
        }
        pw.flush();
    }
}


Measured memory_bytes: 26192
#include<bits/stdc++.h>
using namespace std;
int main(){
  	int n;
  	cin>>n;
  	n = n%10;
  	switch(n){
      case 2:
      case 4:
      case 5:
      case 7:
      case 9:
        cout<<"hon";
        break;
      case 0:
      case 1:
      case 6:
      case 8:
        cout<<"pon";
        break;
      default:
        cout<<"bon";
    }
	return 0;
}

Measured memory_bytes: 3592
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int c = sc.nextInt();
        int [] b = new int [m];
        for(int i = 0; i < m; i++) {
            b[i] = sc.nextInt();
        }
        
        int ans = 0;
        for(int j = 0; j < n; j++) {
            int score = c;
            for(int i = 0; i < m; i++) {
                score += (sc.nextInt() * b[i]);
            }
            if(score > 0) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 24404
#include <bits/stdc++.h>
 
using namespace std;
 
#define PB(x)	push_back(x)
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define MP(x)	make_pair(x);
    
#define debug(x) 		cerr << #x << '=' << x << endl;
#define debug2(x, y)	cerr << #x << '=' << x << ' ' << #y << '=' << y << endl;
#define debugn(_a)		cerr << #_a << ": "; for (auto _x: _a) cerr << _x << ' '; cerr << endl;
#define debugm(a) 		cerr << #a << ":\n"; \
						for (auto v: a) { for(auto x: v) cout << x << ' '; cerr << "\n"; }
 
#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long
 
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vii;
typedef vector<string> vs;
typedef unsigned long long ull;
 
const int INF  = LONG_LONG_MAX;
const int NINF = LONG_LONG_MIN;
const int mmod = 998244353;

const int N = 100009;

vi adj[N];
int32_t main()
{
	FAST_IO;
	
	int n, a, b;
	cin >> n >> a >> b;
	
	for (int i = 0; i < n-1; i++) {
		int u, v;
		cin >> u >> v;
		
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	
	vi dist_b(n+1, -1);
	vi used(n+1, false);
	queue<int> q;
	q.push(b);
	dist_b[b] = 0;
	used[b] = true;
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		for (int u: adj[v]) {
			if (!used[u]) {
				dist_b[u] = dist_b[v] + 1;
				used[u] = true;
				q.push(u);
			}
		}
	}
	
//	debugn(dist_b);
	for (int i = 0; i <= n; i++) used[i] = false;
	vi dist_a(n+1, -1);
	q.push(a);
	dist_a[a] = 0;
	used[a] = true;
	int ans = 0;
	int ans_v = a;
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		for (int u: adj[v]) {
			if (!used[u] && dist_a[v]+1 < dist_b[u]) {
				dist_a[u] = dist_a[v] + 1;
				if (ans < dist_b[u]) {
					ans = dist_b[u];
					ans_v = u;
				}
				used[u] = true;
				q.push(u);
			}
		}
	}
	ans = max(ans, dist_b[a]);
	if (dist_a[ans_v] != dist_b[ans_v])
		ans--;
//	debugn(dist_a);
	cout << ans << endl;
}


// g++ -Wall -Wextra -Wshadow -fsanitize=undefined 


Measured memory_bytes: 8832
#include<cstdio>
#include<algorithm>
using namespace std;
const long long MAXN=1e6+5;
long long N,K,Ans;
long long A[MAXN];

int main(){
	
	scanf("%lld%lld",&N,&K);
	
	for(long long i=1;i<=N;i++){
		scanf("%lld",&A[i]);
	}
	
	sort(A+1,A+N+1);
	
	if(N>K){
		for(long long i=1;i<=N-K;i++){
			Ans=Ans+A[i];
		}
	}
	
	printf("%lld\n",Ans);
	
	return 0;
	
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007ll
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define M 4000
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 

ll dp[200005];

const ll MAXN = 200005;
ll n, t[4*MAXN];

void buildma(ll v, ll tl, ll tr) 
{
    if (tl == tr) 
        t[v] = tl;
    else 
    {
        ll tm = (tl + tr) / 2;
        buildma(v*2, tl, tm);
        buildma(v*2+1, tm+1, tr);
        t[v] = max(t[2*v],t[(2*v)+1]);
    }
}

ll ma(ll v, ll tl, ll tr, ll l, ll r) 
{
    if (l > r) 
        return -C;
    if (l == tl && r == tr) 
        return t[v];
    ll tm = (tl + tr) / 2;
    return max(ma(v*2, tl, tm, l, min(r, tm)),ma(v*2+1, tm+1, tr, max(l, tm+1), r));
}

void updatema(ll v, ll tl, ll tr, ll pos, ll new_val) 
{
    if (tl == tr) 
        t[v] = max(new_val,t[v]);
    else 
    {
        ll tm = (tl + tr) / 2;
        if (pos <= tm)
            updatema(v*2, tl, tm, pos, new_val);
        else
            updatema(v*2+1, tm+1, tr, pos, new_val);
        t[v] = max(t[v*2],t[v*2+1]);
    }
}

int main() 
{
    FAST;
    ll n,x,y;
    cin>>n;
    ve<ll> a(n);
    ve<pair<ll,ll>> b(n);
    for(int i=0;i<n;i++)
    {
        cin>>x>>y;
        a[i]=x;
        b[i]={x,x+y};
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    dp[n]=1;
    buildma(1,0,n);
    for(int i=n-1;i>=0;i--)
    {
        x=b[i].second;
        y=(lb(a.begin(),a.end(),x)-a.begin());
        y--;
        y=ma(1,0,n,i,y);
        updatema(1,0,n,i,y);
        dp[i]=(dp[i+1]+dp[y+1])%B;
    }
    cout<<dp[0];
    subt;
    return 0;
}

Measured memory_bytes: 12672
import           Control.Monad
import           Data.Array.ST
import           Data.Array.Unboxed    (UArray)
import qualified Data.Array.Unboxed    as U
import qualified Data.ByteString.Char8 as BS
import           Data.Char
import           Data.List

getAsInt :: IO [Int]
getAsInt =  unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

getAsIntArray1Dr :: Int -> IO (UArray Int Int)
getAsIntArray1Dr n = U.listArray (1,n) <$> getAsInt

main :: IO ()
main = do
  [n,k] <- map read . words <$> getLine :: IO [Int]
  hs <- getAsIntArray1Dr n
  let solve = solve2
  print $ solve hs n k U.! n

-- 貰うDP
solve1 :: UArray Int Int -> Int -> Int -> UArray Int Int
solve1 hs n k = runSTUArray $ do
  dp <- newArray (1,n) 0
  forM_ [1..n] $ \x ->
    minimum <$> forM [(max (x-k) 1)..(x-1)] (\y -> liftM2 (+) (readArray dp y) (return . abs $ hs U.! x - hs U.! y)) >>=  writeArray dp x
  return dp

-- 配るDP
solve2 :: UArray Int Int -> Int -> Int -> UArray Int Int
solve2 hs n k = runSTUArray $ do
  dp <- newArray (1,n) maxBound
  writeArray dp 1 0
  forM_ [1..n] $ \x ->
    forM [(x+1)..(min (x+k) n)] $ \y -> liftM2 (+) (readArray dp x) (return . abs $ hs U.! x - hs U.! y) >>= \a -> readArray dp y >>= writeArray dp y . min a
  return dp


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

using namespace std;
typedef pair<int,int> P;
char g[55][55];
int h,w;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

bool bfs(int i, int j) {
  queue<P> q;
  for(int k = 0; k < 4; k++) {
    int nx = i + dx[k];
    int ny = j + dy[k];
    if(nx >= 0 && nx < h && ny >= 0 && ny < w && g[nx][ny] == '#'){
       g[nx][ny] = '.';
      q.push(P(nx,ny));
    }
   
  }
  if(q.empty()) return false;
  
  while(!q.empty()) {
  
    P p = q.front();
    q.pop();
    for(int k = 0; k < 4; k++) {
      int nx = p.first + dx[k];
    int ny = p.second + dy[k];
    if(nx >= 0 && nx < h && ny >= 0 && ny < w && g[nx][ny] == '#'){
      g[nx][ny] = '.';
      q.push(P(nx,ny));
    }
    }
  }
  return true; 
}

int main() {
  cin >> h >> w;
  for(int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for(int j = 0; j < s.size(); j++) {
      g[i][j] = s[j];
    }
  }


  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      if(g[i][j] == '#') {
	g[i][j] = '.';
	if(!bfs(i,j)){
	  cout << "No" << endl;
	  return 0;
	}
      }
    }
  }
 
  cout << "Yes" << endl;
   
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 100000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
const int SIZE = 1<<24;
int N;
ll D,end,ind;
ll X[40],Y[40];
vector<P> v[2];
void rec(int x,ll s,ll k){
	if(x==end){
		v[ind].pb(P(s,k));
		return;
	}
	rec(x+1,s+X[x],k-Y[x]);
	rec(x+1,s-X[x],k+Y[x]);
	rec(x+1,s,k);
}
int main(){
	scanf("%d %lld",&N,&D);
	for(int i=0;i<N;i++)scanf("%lld %lld",&X[i],&Y[i]);
	ll ans = 0ll;
	int half = N/2;
	int rem = N - half;
	ind = 0,end = half;
	rec(0,0ll,0ll);
	ind = 1,end = N;
	rec(half,0ll,0ll);
	sort(v[0].begin(),v[0].end());
	reverse(all(v[0]));
	sort(v[1].begin(),v[1].end());
	int l=0,r=0;
	deque<int> deq;
	for(int i=0;i<v[0].size();i++){
		P lb = P(-D-v[0][i].fi,-LLINF);
		P rb = P(D-v[0][i].fi,LLINF);
		while(r<v[1].size()&&v[1][r]<=rb){
			while(!deq.empty()&&v[1][deq.back()].sec<=v[1][r].sec)deq.pop_back();
			deq.push_back(r++);
		}
		while(l<v[1].size()&&v[1][l]<lb){
			if(!deq.empty()&&deq.front()==l)deq.pop_front();
			l++;
		}
		//cout << l << ' ' << r << endl;
		if(!deq.empty()){
			ans = max(ans,v[0][i].sec+v[1][deq.front()].sec);
			//cout << v[0][i].sec+v[1][deq.front()].sec << endl;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 489860
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String a = sc.next();
		String b = sc.next();        
        int n = a.length();
        int m = b.length();
        String an[] = a.split("");
        String bm[] = b.split("");
        int i,y,z;
        if(n > m){
          System.out.println("GREATER");
          System.exit(0);
        }else if(m > n){
          System.out.println("LESS");
          System.exit(0);          
        }
        for(i = 0; i < n; i++){
			if(Integer.parseInt(an[i]) > Integer.parseInt(bm[i])){
         	 	System.out.println("GREATER");
         	 	System.exit(0);              
            }else if(Integer.parseInt(an[i]) < Integer.parseInt(bm[i])){
             	System.out.println("LESS");
         		System.exit(0);     
            }
        }
        
      	System.out.println("EQUAL");
 
    }
}

Measured memory_bytes: 35620
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Bounding
            var line = ReadLine();
            int n = line[0];
            int x = line[1];

            var l = ReadLine();
            int d = 0;
            int count = 1;

            for(int i = 0; i < n; i++)
            {
                d = d + l[i];

                if (d > x)
                {
                    break;
                }
                else
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}


Measured memory_bytes: 11220
import itertools
n,m=map(int,input().split())
graph=[[False for h in range(n)] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1;b-=1
    graph[a][b]=True
    graph[b][a]=True
l=[i for i in range(1,n)]
ans=0
if n==2:
    print(m)
    exit()
for v in itertools.permutations(l):
    flag=1
    if graph[0][v[0]]==False:continue
    else:
        c=v[0]
        for j in v[1:]:
            if graph[c][j]==False:
                flag=0
                break
            c=j
        ans+=flag
print(ans)


Measured memory_bytes: 39664
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int N, M, s, t;
double ex[600], res;
vector<int>v[600];

int main() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> s >> t;
		v[s - 1].push_back(t - 1);
	}
	for (int i = N - 2; i >= 0; i--) {
		for (int j : v[i]) {
			ex[i] += ex[j];
		}
		ex[i] /= v[i].size();
		ex[i] += 1;
	}
	res = ex[0];
	for (int i = 0; i < N - 1; i++) {
		if (v[i].size() == 1)continue;
		double EX[600];
		for (int j = i + 1; j < N; j++) {
			EX[j] = ex[j];
		}
		EX[i] = 0;
		double mx = 0;
		for (int j : v[i]) {
			EX[i] += EX[j];
			mx = max(mx, EX[j]);
		}
		EX[i] -= mx;
		EX[i] /= v[i].size() - 1;
		EX[i] += 1;
		for (int j = i - 1; j >= 0; j--) {
			EX[j] = 0;
			for (int k : v[j]) {
				EX[j] += EX[k];
			}
			EX[j] /= v[j].size();
			EX[j] += 1;
		}
		res = min(res, EX[0]);
	}
	printf("%.10f\n", res);
}


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

int main(){
  int N; 
  cin >> N;
  vector<int> cards(N);
  for(int i = 0; i < N; i++){
    cin >> cards.at(i);
  }
  sort(cards.begin(), cards.end());
  reverse(cards.begin(), cards.end());
  int diff = 0;
  for(int i = 0; i < N / 2; i++){
  	diff += cards.at(i * 2) - cards.at(i * 2 + 1);
  }
  if(N % 2 == 1) diff += cards.at(N - 1);
  cout << diff;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long a , b , k , i , p , c  ;
int main() {
  cin >> a >> b ;
  c = __gcd ( a , b ) ; 
  k = sqrt ( c ) ;
  for ( i = 2 ; i <= k ; i++ )
    if ( c % i == 0 ) {
      while ( c % i == 0 )
        c /= i ;
        p ++ ;
    }
    if ( c != 1 ) p+=1 ;
    cout << p + 1 ;
  return 0 ;
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> ii;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vii;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<vector<ld>> vvld;
typedef vector<bool> vbl;
typedef vector<vbl> mbl;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(s) (s).begin(), (s).end()
const ll MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int k;
    cin >> k;
    long long ans = 0;
    queue<long long> q;
    for (int i = 1; i <= 9; i++)
        q.push(i);
    for (int i = 0; i < k; i++)
    {
        ll x = q.front();
        if (i == k - 1)
            cout << x << endl;
        q.pop();
        if (x % 10 != 0)
            q.push(10 * x + x % 10 - 1);
        q.push(10 * x + x % 10);
        if (x % 10 != 9)
            q.push(10 * x + x % 10 + 1);
    }
    return 0;
}

Measured memory_bytes: 4748