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

int main() {
	long long n;
	cin>>n;
	long long res=1e18;
    for(int i=1;i<=sqrt(n);i++){
        if(n%i==0){
            long long x=n/i;
            res=min(res,(long long)i+x-2);
            
        }
    }
    cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
int N,M;
main(){
    cin>>N>>M;
    int a[M],b[M],c[N]={0};
    for(int i=0;i<M;i++) cin>>a[i]>>b[i];
    for(int i=0;i<M;i++){
        c[a[i]-1]++;
        c[b[i]-1]++;
    }
    for(int i=0;i<N;i++){
        cout<<c[i]<<endl;
    }
}


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

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

int main(){
    cin>>n;
    int ans=0;
    REP(i,n){
        cin>>a;
        ans^=a&1;
    }
    cout<<(ans?"NO":"YES")<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
 
int main()
{
    string s;
    string p;
    cin>>s;
    cin>>p;
    for(int i = 0; i < s.length(); i++){
        for(int j = 0; j < p.length(); j++){
            if(s[ (i + j) % s.length()] == p[j]){
                if(j==(p.length() -1)){
                cout<<"Yes"<<endl;
                return 0;
            }
            }else{
                break;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3184
#include<iostream>

using namespace std;


int main() {
	string S, T;
	int A, B;
	string U;

	cin >> S >> T;
	cin >> A >> B;
	cin >> U;

	if (U == S) {
		cout << A - 1 <<" "<<B<< endl;
	}
	else {
		cout << A <<" "<< B - 1 << endl;
	}

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,Y;
  cin >> N >> Y;
  int x,y,z;
  for(x=0;x<=N;x++){
    for(y=0;y<=N-x;y++){
      z=N-x-y;
      if(10000*x+5000*y+z*1000==Y){
        cout << x << " " << y << " " << z << endl;
        goto a;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  a:
  return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a_list = []
b_list = []

for i in range(m):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)

import heapq


class Dijkstra:

    def __init__(self, rote_map, start_point, goal_point=None):
        self.rote_map = rote_map
        self.start_point = start_point
        self.goal_point = goal_point

    def execute(self):
        num_of_city = len(self.rote_map)
        dist = [float("inf") for _ in range(num_of_city)]
        prev = [float("inf") for _ in range(num_of_city)]

        dist[self.start_point] = 0
        heap_q = []
        heapq.heappush(heap_q, (0, self.start_point))
        route_count = [0 for _ in range(num_of_city)]
        route_count[self.start_point] = 1
        while len(heap_q) != 0:
            prev_cost, src = heapq.heappop(heap_q)

            if dist[src] < prev_cost:
                continue

            for dest, cost in self.rote_map[src].items():
                if cost != float("inf") and dist[dest] > dist[src] + cost:
                    dist[dest] = dist[src] + cost
                    heapq.heappush(heap_q, (dist[dest], dest))
                    prev[dest] = src
                if dist[dest] == dist[src] + cost:
                    route_count[dest] += route_count[src]

        if self.goal_point is not None:
            return self._get_path(self.goal_point, prev)
        else:
            return dist, route_count

    def _get_path(self, goal, prev):
        path = [goal]
        dest = goal

        while prev[dest] != float("inf"):
            path.append(prev[dest])
            dest = prev[dest]

        return list(reversed(path))


count = 0
for j in range(m):
    items = [dict() for _ in range(n)]
    for i in range(m):
        a, b = a_list[i] - 1, b_list[i] - 1
        if i == j:
            continue
        items[a][b] = 1
        items[b][a] = 1
    di = Dijkstra(items, a_list[0] - 1).execute()
    if len([True for d in di[0] if d == float("inf")]) >= 1:
        count += 1
print(count)


Measured memory_bytes: 3316
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define repi(i, n, iv) for (int i = iv; i < n; i++)
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

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

    ll A, B, V, W, T;
    cin >> A >> V >> B >> W >> T;

    ll M = V - W;
    if (M <= 0)
    {
        cout << "NO" << endl;
        return 0;
    }

    if (abs(B - A) <= M * T)
    {
        cout << "YES" << endl;
    }
    else
    {

        cout << "NO" << endl;
    }
}


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


int main(){
    int n, a, b;
    cin >> n >> a >> b;
    int ans=0;
    for(int i=0; i<=n; i++){
        int count=0,temp=i;
        while(temp != 0){
            count += temp % 10;
            temp /= 10;
        }
        if(a <= count && count <= b){
            ans += i;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3604
#include<stdio.h>

int main(){
    int i;
    int n;
    int count=0;
    int a,b,c,d;
    while(~scanf("%d", &n)){
        count=0;
        a=0,b=0,c=0,d=0;
        for(a=0;a<=9;a++)
            for(b=0;b<=9;b++)
                for(c=0;c<=9;c++)
                    for(d=0;d<=9;d++)
                        if(a+b+c+d==n)
                            count++;
        printf("%d\n", count);
    }
    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <algorithm>


int main() {

    int N;
    std::cin >> N;

    std::vector<int> X;
    for (int i=0; i<N; i++) {
        int b;
        std::cin >> b;
        X.push_back(b);
    }

    std::vector<int> X_sorted(X);
    std::sort(X_sorted.begin(), X_sorted.end());

    const int pos_median = (N + 1) / 2 - 1;
    const int median_original = X_sorted.at(pos_median);

    for (int i=0; i<N; i++) {

        const int value_to_be_deleted = X.at(i);
        int pos = pos_median;

        if (value_to_be_deleted <= median_original) pos++;

        std::cout << X_sorted.at(pos) << std::endl;
    }

    return 0;

}


Measured memory_bytes: 3828
sx,sy,tx,ty=map(int,input().split())
print('U'*(ty-sy)+'R'*(tx-sx)+'D'*(ty-sy)+'L'*(tx-sx)+'LU'+'U'*(ty-sy)+'R'*(tx-sx)+'RDRD'+'D'*(ty-sy)+'L'*(tx-sx)+'LU')


Measured memory_bytes: 3060
#!/usr/bin/env python3
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))

if n == k:
    ans = 1 
elif (n-1)%(k-1)==0:
    ans = (n-1)//(k-1)
else:
    ans = (n-1)//(k-1) + 1 
print(ans)


Measured memory_bytes: 20364
#include <iostream>
#include <deque>
#include <algorithm>
#include <set>
using namespace std;

int main()
{
    int n, K; cin>>n>>K;
    deque<int> v(n);
    for(auto& e: v) cin>>e;

    int res=0;
    for(int i=0; i<=K; ++i) {
        for(int j=0; j<=K; ++j) {
            auto d=v;
            int s=0, x=0;
            multiset<int> f;
            for(int k=0; k<i and !d.empty(); ++k) {
                s+=d.front();
                if (d.front()<0) f.insert(d.front());
                d.pop_front();
                ++x;
            }
            for(int k=0; k<j and !d.empty(); ++k) {
                s+=d.back();
                if (d.back()<0) f.insert(d.back());
                d.pop_back();
                ++x;
            }
            while (x<K and !f.empty()) {
                s-=*begin(f);
                f.erase(begin(f));
                ++x;
            }
            if (x<=K) res=max(res, s);
        }
    }
    cout<<res<<endl;
}


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

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> X(1e5 + 10, 0);
	for (int i = 0; i < N; ++i) {
		int x;
		cin >> x;
		++X[x];
	}

	vector<vector<int>> memo(M, vector<int>(2, 0));
	for (int i = 0; i < X.size(); ++i) {
		memo[i % M][0] += X[i] % 2;
		memo[i % M][1] += X[i] / 2;
	}

	int ans = 0;
	for (int i = 0; 2 * i <= M; ++i) {
		if (i == 0 || 2 * i == M) {
			ans += memo[i][0] / 2 + memo[i][1];
			continue;
		}

		int a = i, b = M - i;
		if (memo[a][0] < memo[b][0]) {
			swap(memo[a][0], memo[b][0]);
			swap(memo[a][1], memo[b][1]);
		}
		ans += memo[b][0];
		memo[a][0] -= memo[b][0];
		ans += min(memo[a][0], memo[b][1] * 2) + memo[a][1] + max(memo[b][1] * 2 - memo[a][0], 0) / 2;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6144
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll n; cin>>n;
	ll m; cin>>m;
	vector<ll> s(m);
	vector<ll> c(m);
	REP(i,m){
		cin>>s[i];
		s[i]--;
		cin>>c[i];
	}
	vector<ll> num(n,-1);
	REP(i,m){
		if(num[s[i]]!=c[i] && num[s[i]]!=-1){
			cout<<-1<<endl;
			return 0;
		}
		num[s[i]]=c[i];
	}
	if(num[0]==0){
		if(n==1){
			cout<<0<<endl;
			return 0;
		}else{
			cout<<-1<<endl;
			return 0;
		}
	}
	REP(i,n){
		if(num[i]==-1){
			if(i==0 && i!=n-1){
				cout<<1;
			}else{
				cout<<0;
			}
		}else{
			cout<<num[i];
		}
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim S As String = NextString()
        WriteLine(New String() {"WA", "AC"}(B2I(Judge(S))))
    End Sub

    Function Judge(S As String) As Boolean
        Dim flg As Boolean

        For i As Integer = 0 To S.Length - 1
            If i = 0 Then
                If S(i) <> "A" Then Return False
            ElseIf 2 <= i And i < S.Length - 1 And S(i) = "C" And Not flg Then
                flg = True
            ElseIf S(i) <> StrConv(S(i), vbLowerCase) Then
                Return False
            End If
        Next
        If Not flg Then Return False
        Return True
    End Function

    Function B2I(ok As Boolean) As Integer
        If ok Then Return 1
        Return 0
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


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


int main() {
    int n;
    cin >> n;
    vector<string> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }

    for (int i = 1; i < n; i++) {
        if (vec.at(i).at(0) != vec.at(i-1).at(vec.at(i-1).size()-1)) {
            cout << "No" << endl;
            return 0;
        }

        for (int j = 0; j < i; j++) {
            if (vec.at(i) == vec.at(j)) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
        
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
A,B,C=map(int,input().split())
counter=0

for i in range(100000000):
    
    if A%2!=0 or B%2!=0 or C%2!=0:
        print(counter)
        break
    if A==B and B==C:
        print('-1')
        break
    
    AA=B/2+C/2
    BB=A/2+C/2
    CC=A/2+B/2
    counter=counter+1
    if AA%2!=0 or BB%2!=0 or CC%2!=0:
        print(counter)
        break
    A=AA
    B=BB
    C=CC

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

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        int ans = 0;
        for(int i=0; i<n; i++){
            h[i] = sc.nextInt();
            if(h[i] >= k) ans++;
        }
        System.out.println(ans);

    }



    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext())
                throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }

}



Measured memory_bytes: 21676
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
vector<int>pre, in, post;
int n, pos;
void rec(int l, int r) {
	if (!(l < r))return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));
	rec(l, m);
	rec(m + 1, r);
	post.push_back(root);
}
void solve() {
	pos = 0;
	rec(0, pre.size());
	for (int i = 0; i < n; i++) {
		if (i)cout << " ";
		cout << post[i];
	}
	cout << endl;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	rep(i, 0, n) {
		int x; cin >> x;
		pre.push_back(x);
	}
	rep(i, 0, n) {
		int x; cin >> x;
		in.push_back(x);
	}
	solve();
	return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int A, B;
  cin >> A >> B;
  if(B % A == 0){
    cout << A + B <<endl;
  } else {
    cout << B - A <<endl;
  }
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    string s; cin >> s;
    int flag = 0;
    rep(i,s.size()){
        if(flag==0){
            if(s[i]=='C')flag++;
        }
        if(flag==1){
            if(s[i]=='F')flag++;
        }
    }


    if(flag==2)yn;
    return 0;
}
 
 


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n,m,d;
    cin >> n >> m >> d;
    string s[n];
    int a[n][m];
    for(int i=0;i<n;i++)
        cin >> s[i];
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++){
            if(s[i][j]=='.') a[i][j]=0;
            else a[i][j]=1;
        }
    int co=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<1+m-d;j++){
            int q=0;
            for(int k=0;k<d;k++)
                if(a[i][j+k]==1) q++;
            if(q==0) co++;
        }
    for(int i=0;i<1+n-d;i++)
        for(int j=0;j<m;j++){
            int q=0;
            for(int k=0;k<d;k++)
                if(a[i+k][j]==1) q++;
            if(q==0) co++;
        }
    cout << co << endl;

    return 0;
}



Measured memory_bytes: 3260
from itertools import accumulate

N, M, K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))

acc1 = list(accumulate(A))
acc2 = list(accumulate(B))

def is_ok(a, b):
    if acc1[a] + acc2[b] <= K:  return 1
    return 0

def binary_search(i, left, right):
    while (abs(right - left) > 1):
        mid = (left + right) // 2
        if is_ok(i, mid):  right = mid
        else:  left = mid
    return right

ans = 0
for i in range(N):
    ret = binary_search(i, M, -1)
    if ret == -1:  
      if acc1[i] <= K:  ans = max(i + 1, ans)
    else:
      ans = max(ans,  i + ret + 2)
      
acc1, acc2 = acc2, acc1
N, M = M, N
      
for i in range(N):
    ret = binary_search(i, M, -1)
    if ret == -1:  
      if acc1[i] <= K:  ans = max(i + 1, ans)
    else:
      ans = max(ans,  i + ret + 2)
      
print(ans)

Measured memory_bytes: 127536
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define mset(a,x) memset(a,x,sizeof(a))
#define FASTIO cin.tie(0),ios::sync_with_stdio(0)


bool dp[5005][5005];
int n, k;

bool valid(int c, vi& a) {
    if (c >= n) return false;
    
    FOR(s, max(0, k - a[c]), k) {
        if (dp[n - 1][s])
            return true; // 消してok
    }
    return false;
}

int main() {
    cin >> n >> k;
    vector<int> a(n);
    for (auto&& i : a) scanf("%d", &i);
    sort(ALL(a));

    int lb = -1, ub = n + 1;
    while (ub - lb > 1) {
        int mid = (lb + ub) / 2;
        vector<int> b;
        rep(i, n) if (mid != i) b.emplace_back(a[i]);

        mset(dp, 0);
        dp[0][0] = 1;
        rep(i, n - 1) {
            rep(s, k + 1) {
                if (s - b[i] >= 0)
                    dp[i + 1][s] |= dp[i][s] | dp[i][s - b[i]];
                else
                    dp[i + 1][s] |= dp[i][s];
            }
        }

        if (valid(mid, a)) ub = mid;
        else lb = mid;
    }

    cout << min(ub, n) << endl;

    return 0;
}

Measured memory_bytes: 24832
h,n = map(int,input().split())
len = h + 10005
inf = 1000000000
res = inf
dp = [inf] * len
dp[0] = 0
for i in range(n):
    a,b = map(int,input().split())
    for j in range(len):
        if j >= a:
            dp[j] = min(dp[j],dp[j-a] + b)
        if j >= h:
            res = min(res,dp[j])
print(res)


Measured memory_bytes: 45660
#include<stdio.h>
int main(){
  char c[9],i;
  int d[]={0,1,2,3,4,5,6,7,8,0,3,6,1,4,7,2,5,8,0,4,8,2,4,6};
  while(scanf(" %c",&c[0]),c[0]-'0'){
    for(i=1;i<9;i++){
      scanf(" %c",&c[i]);
    }
    for(i=0;i<8;i++){
      if(c[d[i*3+0]]==c[d[i*3+1]]&&c[d[i*3+1]]==c[d[i*3+2]]&&c[d[i*3+0]]-'+'){
	printf("%c\n",c[d[i*3]]);
	break;
      }
    }
      if(i==8)printf("NA\n");
  }
  return 0;
}

Measured memory_bytes: 552
h, w = map(int,input().split())
MOD = 10**9+7
grid = []
grid.append('#' * (w+2))
for _ in range(h):
    grid.append('#' + input().rstrip() + '#')
grid.append('#' * (w+2))
            
dp=[[0] * (w+2) for _ in range(h+2)]
dp[1][1] = 1
for i in range(1, h+1):
    for j in range(1, w+1):
        if grid[i][j] == "#":
            continue
        if i == 1 and j == 1:
            continue
        dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD
print(dp[h][w] % MOD)  

Measured memory_bytes: 51696
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

const int MOD = 11;

int main() {
	string in;

	while ( cin >> in, in != "0" ) {
		int len = in.size();
		VVI dp( len, VI( MOD, 0 ) );
		
		int ans = 0;
		dp[0][in[0] - '0'] = in[0] - '0' ? 1 : 0;
		for ( int i = 1; i < len; ++i ) {
			int x = in[i] - '0';
			for ( int j = 0; j < MOD; ++j ) {
				dp[i][( j * 10 + x ) % MOD] += dp[i - 1][j];
			}
			if ( x ) { ++dp[i][x]; }
			ans += dp[i][0];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 8132
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ll X,K=-INF;
  cin >> X;
  Rep(i,1,X+1){
    Rep(j,1,400){
      Rep(k,2,10){
        if(i==pow(j,k)){
          K=max(K,i);
        }
      }
    }
  }
  cout << K << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n];
        int[]b = new int[n];
        List<Pair> list = new ArrayList<>();
        for (int i = 0 ;i < n ; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            Pair pair = new Pair();
            pair.from = a[i];
            pair.end = b[i];
            list.add(pair);
        }

        Collections.sort(list);

        long ans = 0;
        for (int i = 0 ; i < n ; i++) {
            int j = list.get(i).end;
            int coin = list.get(i).from;
            if (m > j) {
                ans += (long) coin * j;
                m -= j;
            } else {
                ans += (long) coin * m;
                m = 0;
                break;
            }
        }

        System.out.println(ans);
    }

}

class Pair implements Comparable {
    int from;
    int end;
    @Override
    public int compareTo(Object other) {
        Pair otherpair = (Pair) other;
        return from - otherpair.from;
    }
}

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

int main() {
  int N, K, T, dS, C;
  cin >> N >> K;
  vector<int> d(K);
  vector<int> A(0);
  dS = 0; // お菓子を持っているのべ人数
  C = 0; // お菓子を持っていない人カウント
  
  for (int i = 0; i < K; i++) {
    cin >> d.at(i);
    dS = dS + d.at(i);
    for (int j = 0; j < d.at(i); j++) {
      cin >> T;
      A.push_back(T);
    }
  }
  
  sort(A.begin(), A.end());
  A.erase(unique(A.begin(), A.end()), A.end());
  
  for (int i = 1; i <= N; i++) {
    if (binary_search(A.begin(), A.end(), i)) {
    }
    else {
      C = C + 1;
    }
  }
        
  cout << C;
  
}

Measured memory_bytes: 3624
# ENV[Z = 'RUBY_THREAD_VM_STACK_SIZE'] || exec( { Z => '50000000' },'ruby',$0)
# readlines.map(&:chomp!).map { |e| e.split.map(&:to_i) }
# gets.split.map(&:to_i)
n = gets.to_i

t = []
x = []
y = []

n.times do ||
  line = gets.split.map(&:to_i)
  t << line[0]
  x << line[1]
  y << line[2]
end

current_time = 0
current_pos = [0,0]
flag = true
t.each_with_index do |time, index|
  move_time = time - current_time
  move_distance = ((current_pos[0] - x[index]) + (current_pos[1] - y[index])).abs
  if move_time % 2 == 0 && move_distance % 2 == 0 && move_distance <= time
  elsif move_time % 2 == 1 && move_distance % 2 == 1 && move_distance <= time
  else 
    flag = false
  end
end

puts flag ? "Yes" : "No"


Measured memory_bytes: 4296
#include<iostream>
#include<unordered_map>
#include<algorithm>
#include<vector>
#include<string>
#include<string.h>
#include<unordered_set>

using namespace std;




vector<int> prime_sieve(int n)
{
    int* arr = new int[n+1];
    
    int i, p;
    for (i = 0; i <= n; ++i) {
        arr[i] = i;
    }
    for (i = 2; i <= n; ++i) {
        if (arr[i] != 0) {
            for (p = arr[i] * arr[i]; p <= n; p += arr[i]) {
                arr[p] = 0;
            }
        }
    }
    vector<int> primes;
    for (i = 2; i <= n; ++i) {
        if (arr[i] != 0) {
            primes.push_back(arr[i]);
        }
    }
    return primes;
}

int min(int a, int b)
{
    return a < b ? a : b;
}


int main()
{
    int n;
    cin >> n;
    if (n < 1200) {
        cout << "ABC";
    }
    else {
        cout << "ARC";
    }

    
}

    


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod=1000000007;
constexpr ll INF=(1ll<<60);
constexpr double pi=3.14159265358979323846;
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(a>b){a=b;return 1;} return 0;}

int main(){
    ll n;cin>>n;
    string s;cin>>s;
    deque<ll> white,red;

    bool allred=true,allwhite=true;
    rep(i,(ll)(s.size())){
        if(s[i]=='W') allred=false;
        if(s[i]=='R') allwhite=false;
    }
    if(allred || allwhite){
        cout<<0<<endl;
        return 0;
    }

    ll ans=0;

    rep(i,(ll)(s.size())){
        if(s[i]=='W'){
            white.push_back(i);
        }else{
            red.push_back(i);
        }
    }

    while(1){//交換
        ll noww=white.front();
        ll nowr=red.back();

        white.pop_front();
        red.pop_back();

        if(noww>=nowr) break;

        white.push_back(nowr);
        red.push_front(noww);
        ans++;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 5260
#include <iostream>
#include <string>
#include <cctype>
#include <cmath>
#include <stdio.h>
#define MAXSIZE 101
#define PI 3.141592653589
using namespace std;
int main(){
  int n;
  std::cin >> n;

  int x[1000]={0},y[1000]={0};

  for(int i=0;i<n;i++){
    std::cin >> x[i];
  }
  for(int i=0;i<n;i++){
    std::cin >> y[i];
  }

  double d1=0,d2before=0,d3before=0,d3max=0;
  for(int i=0;i<n;i++){
    d1+=fabs(1.0*x[i]-y[i]);
    d2before+=(x[i]-y[i])*(x[i]-y[i]);
    d3before+=pow(fabs(1.0*x[i]-y[i]),3);
    if(fabs(x[i]-y[i])>d3max)d3max=fabs(x[i]-y[i]);
  }
  printf("%.8f\n",d1);
  printf("%.8f\n",pow(d2before,0.5));
  printf("%.8f\n",pow(d3before,1.0/3));
  printf("%.8f\n",d3max );



}

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

using namespace std;

#define pb push_back
#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) FOR(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 vector<int> vi;
typedef vector<vi> vvi;

const double eps = 1e-10;
const int MOD = 1000000007;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, s.size()) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);
  int n, a; cin >> n >> a;
  int ma = a;
  vi x(n);
  REP(i, n) {
    cin >> x[i];
    ma = max(ma, x[i]);
  }

  vector<vector<vector<ll>>> dp(n+1);
  REP(j, n+1) {
    dp[j].resize(n+1);
    REP(k, n+1) {
      dp[j][k].resize(n*ma+1);
    }
  }

  REP(j, n+1) {
    REP(k, n+1) {
      REP(s, n*ma+1) {
        if(j == 0 && k == 0 && s == 0) dp[j][k][s] = 1;
        else if(j >= 1 && s < x[j-1]) dp[j][k][s] = dp[j-1][k][s];
        else if(j >= 1 && k >= 1 && s >= x[j-1]) dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]];
        else dp[j][k][s] = 0;
      }
    }
  }

  ll ans = 0;
  FOR(k, 1, n+1) {
    ans += dp[n][k][k*a];
  }
  cout << ans << endl;
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 26;
const double EPS = 1e-10;

int main() {
    string S;
    int K;
    cin >> S >> K;
    vector<int> T(S.size());
    for (int i = 0; i < S.size(); i++) {
        T[i] = S[i] - 'a';
    }
    for (int i = 0; i < S.size(); i++) {
        if (i == S.size() - 1) {
            T[i] = (T[i] + K % 26) % 26;
            continue;
        }
        if(T[i]==0){
            continue;
        }
        int need = 26 - T[i];
        if (need <= K) {
            T[i] = 0;
            K -= need;
        } else {
            continue;
        }
    }
    dump(T);
    string ans;
    for (int i = 0; i < T.size(); i++) {
        char c = 'a' + T[i];
        ans.push_back(c);
    }

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

Measured memory_bytes: 1152
#include<iostream>
using namespace std;
long long ans=0;
int gcd(int x,int y)
{
    if(y==0) return x;
    return gcd(y,x%y);
}
int main()
{
    int i,j,k,n;
    cin>>n;
    for(i=1;i<=n;i++)
     for(j=1;j<=n;j++)
      for(k=1;k<=n;k++)
       ans+=gcd(gcd(i,j),k);
    cout<<ans;
}


Measured memory_bytes: 3672
n,m,x,y=map(int,input().split())
xt=list(map(int,input().split()))
yt=list(map(int,input().split()))
xt.sort()
yt.sort()
if max(x,xt[len(xt)-1])<min(y,yt[0]):
  print("No War")
else:
  print("War")

Measured memory_bytes: 3060
N, K, Q = list(map(int, input().split()))
A = []
for _ in range(Q):
    A += [int(input())]
score = [0] + [0] * N
for a in A:
    score[a] += 1

### K - (全部の正解数 - 自分の正解数) > 0
for i in range(1, N + 1):
    if K - (Q - score[i]) > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 8600
#include <stdio.h>
#include <math.h>
int main(void){
  long long a, b, div = 1, e;
  int c, d, copyc, copyd;
  int n;
  scanf("%lld %lld %d %d", &a, &b, &c, &d);
  n = (int)(c > d ? sqrtl(d) : sqrtl(c));
  copyc = c;copyd = d;
  for(int i = 2; i <= n + 1000; i++){
    if(copyc % i == 0 && copyd % i == 0){
      copyc /= i;
      copyd /= i;
      div *= i;
      i--;
    }
  }
  e = (long long)copyc * (long long)copyd * (long long)div;
  //printf("%lld %lld %d %d %lld ",a, b, c, d, e);
  printf("%lld\n", b - a + 1 - (b / (long long)c - (a - 1) / (long long)c) - (b / (long long)d - (a - 1) / (long long)d) + (b / e - (a - 1) / e));
  return 0;
}

Measured memory_bytes: 128
N=input()
n=int(input())
for i in range(n):
    s=input()
    s=s.rstrip().split(" ")
    if s[0]=="replace":
        N=N[:int(s[1])]+s[3]+N[int(s[2])+1:]
    elif s[0]=="reverse":
        a=""
        for j in range(int(s[2])-int(s[1])+1):
            a=a+N[int(s[2])-j]
        N=N[:int(s[1])]+a+N[int(s[2])+1:]
    elif s[0]=="print":
        print(N[int(s[1]):int(s[2])+1])


Measured memory_bytes: 5616
import math
a,b,c,d=map(int,input().split())
count=b-a+1

A=a-1
l=c*d//math.gcd(c,d)
acou=(A//c)+(A//d)-int((A//l))
bcou=(b//c)+(b//d)-int((b//l))

print(count-(bcou-acou))

Measured memory_bytes: 9092
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
    int n, k, c;
    string s;
    cin >> n >> k >> c;
    cin >> s;

    vector<int> dp(n+1, 0);
    vector<int> f(k+1, 0), b(k+1, 0);

    dp[0] = 0;
    for(int i=1; i<=n; i++)
    {
        dp[i] = dp[i-1];
        if(s[i-1] == 'o')
        {
            if(i-c-1 >= 1)
                dp[i] = dp[i-c-1] + 1;
            else
                dp[i] = 1;
            if(dp[i] <= k)
            {
                if(f[dp[i]] == 0)
                    f[dp[i]] = i;
            }
            else
                break;
        }
    }

    // for(int i=1; i<=n; i++)
    // {
    //     cout << dp[i] << " ";
    // }
    // cout << endl;

    dp.clear();
    dp.resize(n+2, 0);

    dp[n+1] = k+1;
    for(int i=n; i>=1; i--)
    {
        dp[i] = dp[i+1];
        if(s[i-1] == 'o')
        {
            if(i+c+1 <= n)
                dp[i] = dp[i+c+1] - 1;
            else
                dp[i] = k;
            if(dp[i] >= 1)
            {
                if(b[dp[i]] == 0)
                    b[dp[i]] = i;
            }
            else
            {
                break;
            }
        }
    }
    // for(int i=1; i<=n; i++)
    // {
    //     cout << dp[i] << " ";
    // }
    // cout << endl;

    for(int i=1; i<=k; i++)
    {
        if(f[i] == b[i])
        {
            cout << f[i] << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 6788
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define fast ios_base::sync_with_stdio(false)
#define cintie cin.tie(NULL)
int main()
{
	ll r;
	cin>>r;
	cout<<fixed<<setprecision(30)<<2*M_PI*r<<endl;
}


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

int main(){
    int N;
    cin >> N;
    int A[N];
    for ( int i = 0; i < N; i++ ) cin >> A[i];
    
    for ( int j = 0; j < N; j++ ){
        cout << A[j];
        if ( j < N - 1) cout << " ";
        else cout << endl;
    }
    
    for ( int i = 1; i < N; i++){
        int v, j;
        v = A[i];
        j = i - 1;
        while ( j >= 0 and A[j] > v){
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        
        for ( int j = 0; j < N; j++ ){
            cout << A[j];   
            if ( j < N - 1) cout << " ";
            else cout << endl;
        }
    }
   
    return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< long long > vll;
typedef pair< int,int > ii;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define mp  make_pair
#define mod 1000000007
#define mod2 998244353
#define all(c) c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c),x) != c.end())
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
#define fo(i,n) for(ll i=0;i<n;i++)
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define nl "\n"
ll gcd (ll a, ll b) {
    if (b == 0)
        return a;
    else
        return gcd (b, a % b);
}

unsigned long long factorial[1000004]; 
    /*factorial[0] = 1; 
    for (int i = 1; i <= n; i++) {
        factorial[i] = (factorial[i - 1] * i) % mod3; 
    }*/




unsigned long long power(unsigned long long x, 
                         int y, int p) 
{ 
    unsigned long long res = 1; // Initialize result 
  
    x = x % p; // Update x if it is more than or 
    // equal to p 
  
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 



  
// Returns n^(-1) mod p 
unsigned long long modInverse(unsigned long long n, int p) 
{ 
    return power(n, p - 2, p); 
} 
unsigned long long nc(unsigned long long n, 
                                 int r, int p) 
{ 
    // Base case 
    if (r == 0) 
        return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
 
  
    return (factorial[n]* modInverse(factorial[r], p) % p * modInverse(factorial[n - r], p) % p) % p; 
} 
//pair<ll,ll> a,b;
ll di(pair<ll,ll> a,pair<ll,ll> b){
    return (abs(a.first-b.first) + abs(a.second - b.second));
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /* factorial[0] = 1; 
    for (int i = 1; i <= 2001; i++) {
        factorial[i] = (factorial[i - 1] * i) % mod; 
    }*/

    int n;
    cin>>n;
    pair<ll,ll> a,b;
    ll x,y;
    cin>>x>>y;
    ll mi,ma,mi1,ma1;
    mi = (x+y);
    mi1 = x-y;
    cin>>x>>y;
    ma = (x+y);
    ma1 = x-y;
    if(mi>ma){
        swap(mi,ma);
    }
    if(mi1>ma1){
        swap(mi1,ma1);
    }
    
    
    for(int i=1;i<=(n-2);i++){
        cin>>x>>y;
        if((x+y)<mi){
            mi = (x+y);
        }
        if((x+y)>ma){
            ma= (x+y);
        }
        if((x-y)<mi1){
            mi1 = (x-y);
        }
        if((x-y)>ma1){
            ma1= (x-y);
        }
    }
    cout<<max(abs(ma-mi),abs(ma1-mi1))<<nl;
  
    


	return 0;
}


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

int main(){
	int n, m;
	cin >> n >> m;
	int maxL = 1;
	int minR = n;
	
	rep(i, m){
		int l;
		int r;
		cin >> l >> r;
		maxL = max(maxL, l);
		minR = min(minR, r);
	}
	int ans = minR - maxL + 1;
	ans = max(ans, 0);

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
 
using namespace std;
int main() {
    // your code goes here
    int a='a', A='A', sa=a-A;
    string S;
    int f=0;
    while(cin>>S){
        if(f++){cout<<" ";}
         
        for(int i=0; i<S.length(); i++){
            if(S[i]>=A && S[i]<=A+25){
                S[i]+=sa;
            }else if(S[i]>=a && S[i]<=a+25){
                S[i]-=sa;
            }
        }
        cout<<S;
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
#define ll long long
#define fo(i,a,b) for(ll i=a;i<=b;i++)
#define mo 1000000007
#define N 300005
using namespace std;
char s[N];
int tov[9][2]={{3,1},{4,2},{5,2},{6,0},{7,1},{8,2},{3,3},{4,4},{5,5}};
ll dp[N+3][9],n;
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	dp[0][0]=1;
	fo(i,1,n)
	{
		fo(j,0,8)
		{
			if(s[i]!='1')dp[i][tov[j][0]]=(dp[i][tov[j][0]]+dp[i-1][j])%mo;
			if(s[i]!='0')dp[i][tov[j][1]]=(dp[i][tov[j][1]]+dp[i-1][j])%mo;
		}
	}
	ll ans=(dp[n][1]+dp[n][2]+dp[n][5]+dp[n][8])%mo;
	printf("%lld",ans);
}

Measured memory_bytes: 25180
#include <stdio.h>

int main(void)
{
	char str[16];
	int i, j;

	while (scanf("%s", str) != EOF){
		for (i = 0; i < 10; i++){
			for (j = 0; j < 10 - i - 1; j++){
				str[j] = (((str[j] - '0') + (str[j + 1] - '0')) % 10) + '0';
			}
		}

		printf("%d\n", str[0] - '0');
	}

	return (0);
}

Measured memory_bytes: 540
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N = z()
X = zz()
orig_X = X[:]
index = list(range(N))
# print(X, index)
X, index = zip(*sorted(zip(X, index)))

# print(X, index)
small_median = X[N//2 - 1]
big_median = X[N//2]

# print("small_median", small_median)
# print('big_median', big_median)
for i in range(N):
    if(orig_X[i] > small_median):
        pass
        print(small_median)
    else:
        pass
        print(big_median)


Measured memory_bytes: 73264
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
max = max(A)
max2 = sorted(A)[-2]
if max == max2:
    for i in A:
        print(max)
else:
    for i in A:
        if i == max:
            print(max2)
        else:
            print(max)

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

int main() {
    int N=0,A=0,B=0;
    cin >> N;
    if(N==1){
        cout << "Hello World" << endl;
        return 0;
    }
    cin >> A >> B;
    cout << A+B << endl;
    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
 int main(){
  priority_queue<ll int> pq;
  int n,m;
  cin >> n >> m;
  REP(i, n){
    ll int t;
    cin >> t;
    pq.push(t);
  }
  REP(i, m){
    ll int top = pq.top();
    // cout << "top :" << top << endl;
    pq.pop();
    pq.push(top / 2);
  }
  ll int ans = 0;
  REP(i, n){
    ans += (pq.top());
    pq.pop();
  }
  cout << ans << endl;
 }

Measured memory_bytes: 1400
/*Saidur Rahman Sajol:A weirdo*/
  /*Dept. of CSE,IUBAT(162)*/
/*---------------------------*/

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

#define ll             long long
#define l              long
#define ul             unsigned long
#define ull            unsigned long long
ull minimum(ull a,ull b){
  return (a<b)?a:b;
}
ull maximum(ull a,ull b){
  return (a>b)?a:b;
}

int main() {
   string s;
   cin>>s;
   int len=s.length();
   int clock=0;
   for(int i=0;i<len;++i){
	   if(s[i]=='1') ++clock;
   }
   cout<<clock<<endl;
  return 0;
}


Measured memory_bytes: 256