akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC137_D___Summer_Vacation
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = NM[0];
            var M = NM[1];

            var jobs = new List<int>[M + 1];
            for (int i = 0; i < M + 1; i++) jobs[i] = new List<int>();
            for (int i = 0; i < N; i++)
            {
                var ab = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                if (ab[0] <= M) jobs[ab[0]].Add(ab[1]);
            }

            var acceptablleJobs = new PriorityQueue<int>(false);
            long rewardSum = 0;
            for (int day = 1; day <= M; day++)
            {
                foreach (int r in jobs[day]) acceptablleJobs.Push(r);
                if (acceptablleJobs.Count() > 0) rewardSum += acceptablleJobs.Pop();
            }

            Console.WriteLine(rewardSum);
        }
    }
    class PriorityQueue<T> where T : IComparable<T>
    {
        private List<T> nodes;
        private Boolean isAsc;

        public PriorityQueue(Boolean _isAsc)
        {
            this.nodes = new List<T>();
            this.isAsc = _isAsc;
        }

        public int Count()
        {
            return this.nodes.Count;
        }
        public T Pop()
        {
            T returnNode = this.nodes[0];
            this.nodes[0] = this.nodes[nodes.Count - 1];
            this.nodes.RemoveAt(nodes.Count - 1);
            int root = 0;
            while (root * 2 + 1 < this.nodes.Count)
            {
                int child = root * 2 + 1;
                if (child + 1 < this.nodes.Count && compare(this.nodes[child + 1], this.nodes[child]) > 0) child += 1;
                if (compare(this.nodes[child], this.nodes[root]) > 0)
                {
                    swap(child, root);
                    root = child;
                }
                else
                {
                    break;
                }
            }
            return returnNode;
        }
        public T Top()
        {
            return this.nodes[0];
        }
        public void Push(T t)
        {
            this.nodes.Add(t);
            var addPosition = nodes.Count - 1;
            while (addPosition > 0)
            {
                var parent = (int)(addPosition - 1) / 2;
                if (compare(nodes[addPosition], nodes[parent]) > 0)
                {
                    swap(addPosition, parent);
                    addPosition = parent;
                }
                else
                {
                    break;
                }
            }
        }
        private int compare(T x, T y)
        {
            return this.isAsc ? y.CompareTo(x) : x.CompareTo(y);
        }
        private void swap(int x, int y)
        {
            T temp = nodes[x];
            nodes[x] = nodes[y];
            nodes[y] = temp;
        }
    }
}


Measured memory_bytes: 24968
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

int64_t gcd(int64_t x, int64_t y) {
    if (x == 0) {
        return y;
    }

    return gcd(y % x, x);
}

int64_t lcm(int64_t x, int64_t y) {
    auto g = gcd(x, y);

    return x * y / g;
}

main() {
    int64_t a, b, c, d;
    cin >> a >> b >> c >> d;

    auto l = lcm(c, d);

    auto n_c = b / c - (a - 1) / c;
    auto n_d = b / d - (a - 1) / d;
    auto n_l = b / l - (a - 1) / l;

    auto ans = b - a + 1 - n_c - n_d + n_l;

    cout << ans << endl;
}

Measured memory_bytes: 256
import re

s = input()
k = int(input())

if len(s) == 1:
    print(int(k / 2))
elif re.search(r'^(.)\1+$', s):
    print(int(k * len(s) / 2))
else:
    series = [1,]
    for i in range(0, len(s)-1):
        if s[i] == s[i+1]:
            series[-1] += 1
        else:
            series.append(1)
    # print(series)
    changeCharCount = 0
    for sameCharBlockLen in series:
        changeCharCount += int(sameCharBlockLen / 2)
    changeCharCount *= k
    if s[0] == s[-1]:
        if (series[0] % 2 == 1) and (series[-1] % 2 == 1):
            changeCharCount += (k - 1)
    print(changeCharCount)

Measured memory_bytes: 3316
import sys

h,w = [int(i) for i in input().split()]

sys.setrecursionlimit(100000)

s = [['#']*(w+2)] + [['#']+list(input())+['#'] for _ in range(h)] + [['#']*(w+2)]
#print(s)

cost = [[-1 if s[y][x] == '#' else float('inf') for x in range(w+2)] for y in range(h+2)]
cost[1][1] = 0
#print(cost)

move_que = [[1,1]]

def list_flatten(nested_list):
  flat_list = []
  fringe = [nested_list]
  
  while len(fringe) > 0:
    node = fringe.pop(0)
    if isinstance(node, list):
      fringe = node + fringe
    else:
      flat_list.append(node)

  return(flat_list)
      
def move(place):
  y,x = place
  if cost[y+1][x] != -1:
    if cost[y+1][x] > cost[y][x]+1:
      cost[y+1][x] = cost[y][x]+1
      move_que.append([y+1,x])       
      
  if cost[y-1][x] != -1:
    if cost[y-1][x] > cost[y][x]+1:
      cost[y-1][x] = cost[y][x]+1
      move_que.append([y-1,x])
  
  if cost[y][x+1] != -1:
    if cost[y][x+1] > cost[y][x]+1:
      cost[y][x+1] = cost[y][x]+1
      move_que.append([y,x+1])
  
  if cost[y][x-1] != -1:
    if cost[y][x-1] > cost[y][x]+1:
      cost[y][x-1] = cost[y][x]+1
      move_que.append([y,x-1])
  
while len(move_que) != 0:
  move(move_que[0])
  move_que = move_que[1:]

#print(cost)

if cost[h][w] == float('inf'):
  print(-1)
else:
  while_num = list_flatten(s).count('.')
  print(while_num - (cost[h][w]+1))


Measured memory_bytes: 3192
def main():
    n, m = map(int, input().split())
    mo = list(map(int, input().split()))
    dp = [float("inf") for i in range(n + 2)]
    dp[0] = 0
    for i in range(n + 1):
        for j in mo:
            if i + j <= n:
                temp_index = i + j
                dp[temp_index] = min(dp[temp_index], dp[i] + 1)
    print(dp[n])


if __name__ == '__main__':
    main()



Measured memory_bytes: 7492
class UnionFind:
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
        self.rank=[0]*n

    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]

    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)

        if x==y:
            return 

        if self.rank[x]<self.rank[y]:
            self.parents[y]+=self.parents[x]
            self.parents[x]=y
        else:
            self.parents[x]+=self.parents[y]
            self.parents[y]=x

            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1

    def are_same(self,x,y):
        return self.find(x)==self.find(y)

    def element_count(self,x):
        x=self.find(x)
        return -self.parents[x]

from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N,M,K=map(int,readline().split())
    #UnionFind
    t=UnionFind(N)
    fb=[set() for _ in range(N)]
    for _ in range(M):
        a,b=map(int,readline().split())
        t.union(a-1,b-1)
        if b-1 not in fb[a-1]:
            fb[a-1].add(b-1)
        if a-1 not in fb[b-1]:
            fb[b-1].add(a-1)
    
    for _ in range(K):
        c,d=map(int,readline().split())
        if t.are_same(c-1,d-1):
            if d-1 not in fb[c-1]:
                fb[c-1].add(d-1)
            if c-1 not in fb[d-1]:
                fb[d-1].add(c-1)

    res=[0]*N
    for i in range(N):
        res[i]=t.element_count(i)-1-len(fb[i])

    print(*res)

if __name__=="__main__":
    main()

Measured memory_bytes: 65308
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

int main() {
    ll n;
    cin >> n;
    ll a[n + 1];
    ll b[n];

    for(ll i = 0; i < n + 1; ++i) {
        cin >> a[i];
    }
    for(ll i = 0; i < n; ++i) {
        cin >> b[i];
    }

    ll beat = 0;
    for(ll i = 0; i < n; ++i) {
        // 上倒す
        if(a[i] >= b[i]) { // Aを倒しきれないので可能な限り倒す
            beat += b[i];
            a[i] -= b[i];
            b[i] -= b[i];
        } else { // Aを倒しきる
            beat += a[i];
            b[i] -= a[i];
            a[i] -= a[i];
        }
        // 斜め倒す
        if(a[i + 1] >= b[i]) { // 倒しきれない
            beat += b[i];
            a[i + 1] -= b[i];
            b[i] -= b[i];
        } else { // 倒しきる
            beat += a[i + 1];
            b[i] -= a[i + 1];
            a[i + 1] -= a[i + 1];
        }
    }
    /*
        cout << endl;
        rep(i, n + 1) { cout << a[i] << " "; }
        cout << endl;
        rep(i, n) { cout << b[i] << " "; }
        cout << endl;
        */
    cout << beat << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define shalaby ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);cerr.tie(0);

using namespace std;

inline int D()
{
    int t;
    scanf("%d",&t);
    return t;
}
inline ll llD()
{
    ll t;
    scanf("%lld",&t);
    return t;
}
ll mod=1e9+7;
const int OO=-1e6;
int xt[4]= {1,0,0,-1};
int yt[4]= {0,1,-1,0};
////////////////////////////////////////////////////////////////////////////////////

const int N = 1e6+1;
ll greatestPF[N];

int mem[100005][3],a[200005],b[105],n,m,k,frq[1000005];
bool valid(int x,int y)
{
    return x>-1 && y>-1 && x<n && y<m;
}
void init()
{
    memset(mem,-1,sizeof mem);
}
int sieve[N];
int main()
{

    sieve[0]= sieve[1] = 1;
	for (int i = 2; i < N; i++)
	{
		for (int j = i; j < N; j+=i)
		{
			if (sieve[j] == 0)sieve[j] = i;
			sieve[j] = min(i, sieve[j]);
		}
	}
    int T=1;
///   T=D();
    while(T-->0)
    {

        cin>>n;
        int g = 0;
	for (int i = 0; i < n; i++)cin >> a[i], g = __gcd(g, a[i]);
	for (int i = 0; i < n; i++)
	{
		while(a[i] != 1)
		{
			int cur = sieve[a[i]];
			frq[ cur ]++;
			while(a[i] % cur == 0)a[i]/=cur;
		}
	}
	int mx = 0;
	for (int i = 2; i < N; i++)mx = max(mx, frq[i]);
	///cout<<mx<<endl;
	if (mx <= 1)
	{
		cout <<"pairwise coprime\n";
	}else
	{
		if (g == 1)
		{
			cout <<"setwise coprime\n";
		}else
		cout <<"not coprime\n";
	}



    }
}


Measured memory_bytes: 15268
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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

int main() {
    int64_t K;
    cin >> K;

    queue<int64_t> q;
    rep(i, 9) {
        q.push(i+1);
    }

    int64_t n = 0;
    rep(i, K) {
        n = q.front();
        q.pop();
        auto mod = n % 10;
        if(mod != 0) {
            q.push(n*10 + mod - 1);
        }
        q.push(n*10+mod);
        if(mod !=9) {
            q.push(n*10+mod + 1);
        }
    }
    cout << n << endl;

    return 0;
}


Measured memory_bytes: 4664
#include <stdio.h>

int main(void) {
  int L,R,d;
  int count=0;
  scanf("%d%d%d",&L,&R,&d);

  for (int i=L; i <= R ;i++) {
    if (i % d  == 0) {
      count++;
    }
  }
  
  printf("%d",count);

}

Measured memory_bytes: 1720
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<std::vector<int>> p(N);
  for (int n = 0; n < N; ++n) {
    int K;
    std::cin >> K;
    p[n].resize(K);
    for (int k = 0; k < K; ++k) {
      std::cin >> p[n][k];
    }
  }

  std::vector<int> sum(M, 0);
  for (int n = 0; n < N; ++n) {
    for (int k = 0; k < p[n].size(); ++k) {
      ++sum[p[n][k] - 1];
    }
  }

  int count =
      std::count_if(sum.begin(), sum.end(), [N](int c) { return c == N; });
  std::cout << count << std::endl;
  return 0;
}


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

using namespace std;

int main() {
  int x, cur = 0;
  cin >> x;
  for (int i = 1; i <= 10000000; ++i) {
    cur = (cur * 10 + 7) % x;
    if (cur == 0) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << -1;
  return 0;
}


Measured memory_bytes: 3644
#include <iostream>

int main(void) {
  int A, B, X;
  std::cin >> A >> B >> X;
  if (A <= X) {
    if (B >= X - A) {
      std::cout << "YES" << std::endl;
    } else {
      std::cout << "NO" << std::endl;
    }
  } else {
    std::cout << "NO" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//ソートすればいいんですか？
//
int dp[3001];

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


	int N, T;
	cin >> N >> T;
	int AB[3000];
	rep(i, N) {
		int a, b;
		cin >> a >> b;
		AB[i] = (a << 12) + b;
	}
	sort(AB, AB + N);

	int saidai = 0;
	rep(i, N) {
		int a = AB[i] >> 12;
		int b = AB[i] & ((1 << 12) - 1);
		chmax(saidai, dp[T - 1] + b);
		for (int j = T - a - 1; j >= 0; j--) {
			chmax(dp[j + a], dp[j] + b);
		}
	}
	co(saidai);

	Would you please return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> X(N),Y(N),P(N);
    rep(i,N) cin >> X[i] >> Y[i] >> P[i];

    vector<vector<ll>> A(N, vector<ll>(1<<N,1e18));
    auto B = A;
    rep(mask,1<<N) {
        rep(i,N) {
            if (!(mask&(1<<i))) continue;
            rep(j,N) {
                chmin(A[j][mask],abs(X[i]-X[j])*P[j]);
                chmin(B[j][mask],abs(Y[i]-Y[j])*P[j]);
            }
        }
        rep(i,N) {
            chmin(A[i][mask],abs(X[i])*P[i]);
            chmin(B[i][mask],abs(Y[i])*P[i]);
        }
    }

    int M = 1;
    rep(i,N) M *= 3;
    vector<ll> ans(N+1,1e18);
    rep(z,M) {
        int mask = z;
        int x = 0;
        int y = 0;
        int cnt = N;
        rep(i,N) {
            x <<= 1;
            y <<= 1;
            int k = mask % 3;
            if (k==1) x++;
            else if (k==2) y++;
            else cnt--;
            mask /= 3;
        }
        ll val = 0;
        rep(i,N) {
            val += min(A[i][x],B[i][y]);
        }
        chmin(ans[cnt],val);
    }

    rep(i,N+1) print(ans[i]);
}

Measured memory_bytes: 10944
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
double dp[3010][3010];

void solve() {
	cin >> N;
	dp[0][0] = 1;
	rep(i, 0, N) {
		double p; cin >> p;
		rep(j, 0, N) {
			dp[i + 1][j + 1] += dp[i][j] * p;
			dp[i + 1][j] += dp[i][j] * (1 - p);
		}
	}
	double res = 0;
	rep(i, 0, N + 1) {
		if(i > N - i) res += dp[N][i];
	}
	cout << res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 70784
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep1(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define rep(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
#define mpi map<int,int>
#define N 200005
#define pql priority_queue<ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
using namespace std;
int main() {
	int n,m;
	cin>>n>>m;
	rep(i,0,m){
		int x;
		cin>>x;
		n-=x;
	}
	if(n>=0)cout<<n;
	else cout<<"-1";
	return 0;
}


Measured memory_bytes: 3640
# https://atcoder.jp/contests/abc093/tasks/arc094_a

A = list(map(int, input().split()))
A.sort()
ans = A[2] - A[1]
sa = A[2] - (A[0] + ans)

ans += sa // 2
if sa & 1:
    ans += 2
print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;

  cout << max(0, min(b, d) - max(a, c)) << endl;

  return 0;
}


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

struct Range{
    int l,r;
    bool contain(Range x){
        if(l<=r) return x.l<=x.r && l<=x.l && x.r<=r;
        else{
            if(x.l<=x.r) return l<=x.l || x.r<=r;
            else return l<=x.l && x.r<=r;
        }
    }
};

char dc[]="NESW";
int dx[]={-1,1,1,-1};
int dy[]={1,1,-1,-1};
int main(){
    int n,w,d;
    cin>>n>>w>>d;
    vector<int> x(n),y(n);
    vector<int> df(n);
    for(int i=0;i<n;i++){
        char f;
        cin>>x[i]>>y[i]>>f;
        for(int j=0;j<4;j++) if(dc[j]==f) df[i]=j;
        
    }
    auto crossPoint=[&](int px,int py,int dir){
        int ub=1000000;
        int lb=0;
        while(ub-lb>1){
            int mid=(ub+lb)/2;
            int tx=px+dx[dir]*mid;
            int ty=py+dy[dir]*mid;
            if(0<=tx && tx<=w && 0<=ty && ty<=d) lb=mid;
            else ub=mid;
        }
        return make_pair(px+dx[dir]*lb,py+dy[dir]*lb);
    };
    auto pos=[&](int x,int y){
        int sum=0;
        if(y==0) return x;
        sum+=w;
        if(x==w) return sum+y;
        sum+=d;
        if(y==d) return sum+w-x;
        sum+=w;
        return sum+d-y;
    };
    vector<Range> range(n);
    for(int i=0;i<n;i++){
        auto p=crossPoint(x[i],y[i],df[i]);
        int l=pos(p.first,p.second);
        p=crossPoint(x[i],y[i],(df[i]+1)%4);
        int r=pos(p.first,p.second);
        range[i]={r,l};
    }
    vector<int> reject(n,false);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i!=j && range[i].contain(range[j])){
                reject[i]=true;
            }
        }
    }

    {
        vector<Range> tmp;
        for(int i=0;i<n;i++){
            if(!reject[i]) tmp.push_back(range[i]);
        }
        range=tmp;
        n=range.size();
    }
    sort(range.begin(),range.end(),[](Range lhs,Range rhs){return lhs.l<rhs.l;});
    vector<int> kouho(n);
    for(int i=0;i<n;i++) kouho[i]=range[i].r;
    int res=n;
    for(int i=0;i<n;i++){
        Range p={kouho[i],kouho[i]};
        queue<Range> que;
        for(int j=0;j<n;j++){
            if(range[j].contain(p)){
                int prej=j;
                while(j<n && range[j].contain(p)){
                    j++;
                }
                for(int k=j;k<n;k++) que.push({range[k]});
                for(int k=0;k<prej;k++) que.push({range[k]});
                break;
            }
        }
        int cnt=1;
        while(!que.empty()){
            auto t=que.front(); que.pop();
            if(!t.contain(p)){
                cnt++;
                p={t.r,t.r};
            }
        }
        res=min(res,cnt);
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3196
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

constexpr int MAX_N = 30;

int ans;
int n, m;
int cover[30];
int used;
vector<vector<int>> edges;

void dfs(int idx, int sum) {
	if(sum >= ans) return;
	if(used == (1 << n) - 1) {
		ans = sum;
		return;
	}
	if(idx == n) return;

	dfs(idx + 1, sum);
	const int tmp = used;
	used |= cover[idx];
	dfs(idx + 1, sum + 1);
	used = tmp;
}

int solve() {
	used = 0;
	int cnt = 0;
	for(int i = 0; i < n; ++i) {
		if(edges[i].size() == 0) {
			used |= (1 << i);
			++cnt;
		}
		else if(edges[i].size() == 1) {
			const int neighbor = edges[i][0];
			if(used & (1 << neighbor)) continue;
			used |= cover[neighbor];
			++cnt;
		}
	}

	ans = n - __builtin_popcount(used) + cnt;
	dfs(0, cnt);
	return ans;
}

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

	while(cin >> n >> m && n) {
		memset(cover, 0, sizeof(cover));
		for(int i = 0; i < n; ++i) {
			cover[i] = (1 << i);
		}

		edges.assign(n, vector<int>());
		for(int i = 0; i < m; ++i) {
			int a, b;
			cin >> a >> b;
			cover[a] |= (1 << b);
			cover[b] |= (1 << a);
			edges[a].emplace_back(b);
			edges[b].emplace_back(a);
		}

		cout << solve() << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1220
#include <iostream>
#include <limits.h>
#include <vector>
#include <algorithm>

#define el endl
#define fd fixed

using namespace std;

int main() {
  int n, r, p, c;
  while (cin >> n >> r, n+r) {
    vector<int> yama;
    for (int i = n; i > 0; i--) yama.push_back(i);
    while (r--) {
      cin >> p >> c;
      rotate(yama.begin(), yama.begin()+p-1, yama.begin()+p-1+c);
    }
    cout << yama[0] << el;
  }
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

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

    string s, t;
    cin >> s >> t;
    int n = s.size();
    rep(i, n) {
        if (s == t) {
            cout << "Yes" << endl;
            return 0;
        }
        rotate(s.begin(), s.begin() + 1, s.end());
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3656
n = int(input())
arr = [input() for i in range(n)]
ans = [0,0,0,0]
for i in arr:
    if i == 'AC':
        ans[0] += 1
    elif i == 'WA':
        ans[1] += 1
    elif i == 'TLE':
        ans[2] += 1
    else:
        ans[3] += 1
print(f"AC x {ans[0]}")
print(f"WA x {ans[1]}")
print(f"TLE x {ans[2]}")
print(f"RE x {ans[3]}")


Measured memory_bytes: 16360
import java.util.Scanner;

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

	int N = scan.nextInt();

	int max = 0;
	int max_num = 1;
	for(int i = 1; i <= N; i++){
	    int tmp = i;
	    int count = 0;
	    while(true){
		if(tmp % 2 == 0){
		    count++;
		    tmp /= 2;
		}else{
		    break;
		}
	    }
	    if(count > max){
		max = count;
		max_num = i;
	    }
	}

	System.out.println(max_num);
    }
}


Measured memory_bytes: 23760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll a(n);
    rep(i, n){
        cin >> a[i];
    }
    ll ans = 0;
    rep(i, n){
        ans += a[i]/2;
        a[i] %= 2;
        if(i < n-1 && a[i] && a[i+1]){
            ans++;
            a[i]--;
            a[i+1]--;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

int main(){
	summon_tourist;

	int N, K; cin >> N >> K;
	int cnt[100] = {};
	REP(i, K){
		int d; cin >> d;
		REP(j, d){
			int a; cin >> a; a--;
			cnt[a]++;
		}
	}
	int ans = 0;
	REP(i, N){
		if(cnt[i] == 0) ans++;
	}
	cout << ans << ln;
}

Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll H, N;
    cin >> H >> N;
    ll total = 0;
    Rep (i, N) {
        ll A;
        cin >> A;
        total += A;
    }

    if (total >= H) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

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

using namespace std;

#define ll long long
#define pb push_back
#define fr first
#define sc second
#define ub upper_bound
#define lb lower_bound

const int mod=int(1e9+7),MAXN=int(2e5+1);

int niz[5];

int main()
{

    int a,b;
    for (int i=0; i<3; i++)
    {
        cin >> a >> b;
        niz[a]++; niz[b]++;
    }

    int cnt=0;

    for (int i=1; i<=4; i++)
    {
        if (niz[i]%2 == 1) cnt++;
    }

    if (cnt > 2) cout << "NO" << endl;
    else cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

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

    int A[N];
    for(int i = 0; i < N; i++){
        scanf("%d", &A[i]);
    }

    max = A[0];
    min = A[0];
    for(int i = 0; i < N; i++){
        if(max < A[i]){
            max = A[i];
        }
        if(min > A[i]){
            min = A[i];
        }
    }

    printf("%d\n", max - min);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
  
  int N, Y, i, j;
  scanf("%d%d",&N,&Y);

  for(i=0; i<=N; i++){
    for(j=0; j+i<=N; j++){
      
      if (10000*i + 5000*j + 1000*(N-i-j) == Y){
        printf("%d %d %d\n", i, j, N-i-j);
        return 0;
      }
    }
  }
  printf("-1 -1 -1\n");
  return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <climits>
#include <utility>

#define PRINT(STR) cout << STR << endl;
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define SPACE " "

typedef long long ll;

using namespace std;

int nextInt() { int n = -1; cin >> n; return n; }
double nextDouble() { double d = -1; cin >> d; return d; }
ll nextll() { ll n = -1; cin >> n; return n; }
string nextString() { string str; cin >> str; return str; }

int INF = 1LL << 25;
double EPS = 1e-9;

int numofbits(int bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

// BEGIN //////////////////////////////////////////////////////////////
int main() {
	while (true) {
		int n = nextInt();
		int s = nextInt();
		if (n + s == 0) break;
		int ans = 0;
		REP(i, 1 << 10) {
			if (numofbits(i) == n) {
				int sum = 0;
				REP(j, 10) {
					int t = 1 << j;
					if (i & t) {
						sum += j;
					}
				}
				if (sum == s) {
					ans++;
				}
			}
		}
		PRINT(ans);
	}

	return 0;
}
// END   //////////////////////////////////////////////////////////////

Measured memory_bytes: 1160
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,A;
  cin>>N>>A;
  if(N>=1&&N<=9&&A<=9&&A>=1)
    cout<<N*A<<endl;
  else
    cout<<-1<<endl;


}


Measured memory_bytes: 256
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)


n = int(input())
l = list(map(int, input().split()))
num = 0
for i in range(len(l)):
    num = gcd(num, l[i])

print(num)

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll ans = 0;
    while(true) {
        bool flag = true;
        iter(i, A) {
            if(i % 2) {
                flag = false;
                break;
            }
            i /= 2;
        }
        if(!flag) break;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3564
X, N = map(int, input().split())

if N == 0:
  print(X)
  exit()

P = list(map(int, input().split()))

result = 0

if X not in P:
  result = X
else:
  diff = 1
  flag = True
  while flag:
    if (X - diff) not in P:
      result = X - diff
      break
    if (X + diff) not in P:
      result = X + diff
      break
    diff += 1
    
print(result)

Measured memory_bytes: 61744
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int n;
  cin >> n;
  vector<ll> a(n + 1);
  rep (i, n) {
    int x; 
    cin >> x;
    a[i + 1] = x + a[i];
  }

  ll ans = INF;
  for (int i = 1; i < n; i++) {
    ll tmp = abs(a[i] - (a[n] - a[i]));
    ans = min(ans, tmp);
  }

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


Measured memory_bytes: 4820
def main():
    A, B, K = map(int, input().split())

    for i in range(K):
        if A % 2 == 1:
            A -= 1
        A = A // 2
        B += A
        A, B = B, A

    if K % 2 == 0:
        print(A, B)
    else:
        print(B, A)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int, int>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define MINF(a) memset(a, 0x3f, sizeof(a))
#define POW(n) (1LL << (n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;



void _main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << min(A, B) + min(C, D) << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i')) freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o')) freopen("output.txt", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
signed main(){
  ll r,g;
  cin >> r >> g;
  cout << g*2-r<<endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=sum(a)
for i in range(n):
    if a[i]+a[i+1]>=b[i]:
        if a[i]>=b[i]:
            a[i]-=b[i]
        else:
            a[i+1]=a[i+1]-b[i]+a[i]
            a[i]=0
    else:
        a[i]=0
        a[i+1]=0
print(ans-sum(a))


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

public class Main {
	static BufferedReader br;
	static StringTokenizer tokenizer;

	public static void main(String[] args) throws Exception {
		br = new BufferedReader(new InputStreamReader(System.in));
		int n = nextInt();
		int m = nextInt();
		int[] arr = new int[n];
		int[] dp = new int[n];
		for(int i = 0; i < n; i++) {
			arr[i] = nextInt();
			dp[i] = Integer.MAX_VALUE;
		}
		dp[0] = 0;
		for(int i = 0; i < n - 1; i++) {
			int max = Math.min(i + m, n - 1) - i;
			for(int k = 1; k <= max; k++) {
			dp[i + k] = Math.min(dp[i + k], Math.abs(arr[i] - arr[i + k]) + dp[i]);
			}
		}
		System.out.println(dp[n - 1]);
	}

	public static String next() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			String line = br.readLine();
			if (line == null)
				throw new IOException();
			tokenizer = new StringTokenizer(line);
		}
		return tokenizer.nextToken();
	}

	public static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
}


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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, m;
  while(cin >> n, n) {
    map<char, char> mp;
    rep(i, n) {
      char x, y;
      cin >> x >> y;
      mp[x] = y;
    }
    cin >> m;
    rep(i, m) {
      char c;
      cin >> c;
      cout << (mp.count(c) ? mp[c] : c);
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 3124
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException ‚There is no more input";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var X = one[0];
  var A = one[1];
  myout((X < A) ? 0 : 10);
}


Measured memory_bytes: 31064
N = int(input())
robots = [[int(x) for x in input().split()] for _ in range(N)]
robots = [(x - l,  x + l) for x, l in robots]
robots.sort(key=lambda x: x[1])
cur = float('-inf')
count = 0
for left, right in robots:
    if cur <= left:
        cur = right
        count += 1
print(count)

Measured memory_bytes: 34724
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define INF (2000000000)
using namespace std;

typedef vector<int> VI;
typedef vector<int>::iterator VII;
typedef vector<double> VD;
typedef vector<double>::iterator VDI;


int m[100], a[100], b[100];
VI zip;
int w[200];

int main()
{
	int n;
	while (scanf("%d", &n), n){
		zip.clear();
		memset(w, 0, sizeof(w));
		
		for (int i = 0; i < n; i++){
			scanf("%d %d %d", &m[i], &a[i], &b[i]);
			
			bool f;
			
			f = false;
			for (VII it = zip.begin(); it != zip.end(); it++){
				if (*it == a[i]){
					f = true;
					break;
				}
			}
			if (!f){
				zip.push_back(a[i]);
			}
			
			f = false;
			for (VII it = zip.begin(); it != zip.end(); it++){
				if (*it == b[i]){
					f = true;
					break;
				}
			}
			if (!f){
				zip.push_back(b[i]);
			}
		}
		
		sort(zip.begin(), zip.end());
		
		for (int i = 0; i < n; i++){
			int l = 0;
			int r = zip.size();
			
			while (1){
				int m = (l + r) / 2;
				
				if (a[i] == zip[m]){
					a[i] = m;
					break;
				}
				else if (a[i] < zip[m]) {
					r = m - 1;
				}
				else {
					l = m + 1;
				}
			}
			
			l = 0;
			r = zip.size();
			
			while (1){
				int m = (l + r) / 2;
				
				if (b[i] == zip[m]){
					b[i] = m;
					break;
				}
				else if (b[i] < zip[m]){
					r = m - 1;
				}
				else {
					l = m + 1;
				}
			}
		}
		
		for (int i = 0; i < n; i++){
			for (int j = a[i]; j < b[i]; j++){
				w[j] += m[i];
			}
		}
		
		bool f = false;
		for (int i = 0; i < 200; i++){
			if (w[i] > 150){
				f = true;
				break;
			}
		}
		
		printf(f ? "NG\n" : "OK\n");
	}
	
	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF -99999999
typedef pair<int, int> P;
int main(void)
{
  ll H,W;cin>>H>>W;
  ll sum = H+W;
  ll res = 0;
  
  if(H==1 || W==1){
    cout<<1<<endl;
    return 0;
  }
  
  if(H%2==0){
    H = H/2;
    res = H*W;
  }
  else if(W%2==0){
    W = W/2;
    res = H*W;
  }
  else{
    H =(H+1)/2;
    res = H*W;
    W = (W+1)/2;
    res -=W;
    res++;
  }

  cout<<res<<endl;

  return 0;
}

Measured memory_bytes: 256