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

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var tree = new List<int>[N];
        for (int i = 0; i < tree.Length; i++)
        {
            tree[i] = new List<int>();
        }

        for (int i = 0; i < N - 1; i++)
        {
            var ab = ReadLine().Split(' ');
            var a = int.Parse(ab[0])-1;
            var b = int.Parse(ab[1])-1;
            tree[a].Add(b);
            tree[b].Add(a);
        }
        var c = ReadLine().Split(' ').Select(int.Parse).ToArray();
        Array.Sort(c);
        var M = 0;
        for (int i = 0; i < c.Length - 1; i++)
        {
            M += c[i];
        }

        var d = new int[N];
        var q = new Queue<int>();
        q.Enqueue(0);
        var k = N - 1;
        while (q.Count != 0)
        {
            var v = q.Dequeue();
            d[v] = c[k];
            k--;
            foreach (var e in tree[v])
            {
                if (d[e] == 0)
                {
                    q.Enqueue(e);
                }
            }
        }

        WriteLine(M);
        WriteLine(string.Join(" ", d));
    }
}


Measured memory_bytes: 20028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define agewari(a, b) ((ll)a + ((ll)b - 1)) / b
const int MOD = 1000000007;
const long long INF = 1LL << 60;
using Graph = vector<vector<ll>>;

int main()
{
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> BA; //sortのためBが先
    rep(i, m)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        BA.emplace_back(b, a);
    }
    sort(BA.begin(), BA.end());

    ll now = -1;
    ll ans = 0;
    rep(i, m)
    {
        ll b = BA[i].first;
        ll a = BA[i].second;
        if (now <= a)
        {
            ans++;
            now = b;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 5368
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
 
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  
  int N; 
  cin >> N;
  int array[N];
  
  for(int i=0; i<N; i++){
    cin >> array[i];
  }
  
  int max =0;
  int number = 0;
  for(int i=0; i<N; i++){
    if(max<=array[i]) 
    {max = array[i];
    number = i;}
    else max = max;
  }
  int max2 =0;
  for(int i=0; i<N; i++){
    if(max2<=array[i] && i != number) 
    max2 = array[i];
    else ;
  }
  for(int i=0; i<N; i++){
    if( i == number) 
    cout << max2 <<endl;
    else 
    cout << max <<endl;
  }
}

Measured memory_bytes: 2432
package main

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

var stdin = bufio.NewScanner(os.Stdin)

func main() {
	n := func() int { stdin.Scan(); i, _ := strconv.Atoi(stdin.Text()); return i }()
	arrA := scanArrayInt()
	arrB := scanArrayInt()
	arrC := scanArrayInt()
	oldindex := 0
	sum := 0
	for i := 0; i < n; i++ {
		sum += arrB[arrA[i]-1]
		if arrA[i] == oldindex+1 && i != 0 {
			sum += arrC[oldindex-1]
		}
		oldindex = arrA[i]
	}
	fmt.Println(sum)
}
func scanArrayInt() []int {
	var ret = []int{}
	stdin.Scan()
	for _, s := range strings.Split(stdin.Text(), " ") {
		i, _ := strconv.Atoi(s)
		ret = append(ret, i)
	}
	return ret
}


Measured memory_bytes: 640
fun main(args: Array<String>) {
    val w = readLine()!!
    var wNum = 0
    while (true) {
        val list = readLine()!!.split(" ")
        if (list[0] == "END_OF_TEXT") break
        val wList = list.filter { it.toLowerCase() == w }
        wNum += wList.size
    }
    println(wNum)
}


Measured memory_bytes: 32100
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

vector<vector<int>> edges;
int loop_start;
int linear_size;
int loop_size;
vector<int> visited;
vector<int> ords;

void detect_cycle(int cur, int k) {
    if (visited[cur] >= 0) {
        loop_start = cur;
        linear_size = visited[cur];
        loop_size = k - visited[cur];
        return;
    }

    visited[cur] = k;
    k++;
    ords.push_back(cur);
    detect_cycle(edges[cur][0], k);
}

int main(void) {
    int N;
    ll K;
    cin >> N >> K;

    edges.resize(N);
    for (int i = 0; i < N; i++) {
        int t;
        cin >> t;
        t--;
        edges[i].push_back(t);
    }

    visited.resize(N, -1);
    detect_cycle(0, 0);

    if (linear_size >= K) {
        cout << ords[K] + 1 << endl;
    } else {
        cout << ords[linear_size + ((K - linear_size) % loop_size)] + 1 << endl;
    }

    return 0;
}


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

int main(){
  string s; cin>>s;
  if(s=="SUN")cout<<7<<endl;
  if(s=="MON")cout<<6<<endl;
  if(s=="TUE")cout<<5<<endl;
  if(s=="WED")cout<<4<<endl;
  if(s=="THU")cout<<3<<endl;
  if(s=="FRI")cout<<2<<endl;
  if(s=="SAT")cout<<1<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int sx = scan.nextInt();
        int sy = scan.nextInt();
        int tx = scan.nextInt();
        int ty = scan.nextInt();

        StringBuilder sb = new StringBuilder();

        sb.append('U');
        search(sb, sx, sy + 1, tx - 1, ty);
        sb.append('R');

        sb.append('D');
        search(sb, tx, ty - 1, sx + 1, sy);
        sb.append('L');

        sb.append('L');
        search(sb, sx - 1, sy, tx, ty + 1);
        sb.append('D');

        sb.append('R');
        search(sb, tx + 1, ty, sx, sy - 1);
        sb.append('U');

        System.out.println(sb.toString());
    }

    public static void search(StringBuilder sb, int x1, int y1, int x2, int y2) {
        if (y1 < y2) {
            for (int i = 0; i < y2 - y1; ++i) {
                sb.append('U');
            }
        } else {
            for (int i = 0; i < y1 - y2; ++i) {
                sb.append('D');
            }
        }

        if (x1 < x2) {
            for (int i = 0; i < x2 - x1; ++i) {
                sb.append('R');
            }
        } else {
            for (int i = 0; i < x1 - x2; ++i) {
                sb.append('L');
            }
        }
    }

}

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

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

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000000000;

int main(){
  cout << setprecision(10);
  int A,B;
  cin >> A >> B;
  if(A+B>=10){
    cout << "error" << endl;
  } else {
    cout << A+B << endl;
  }
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    double sum = 0;
    int minsum = 0;
    int X[n];
    for(int i = 0; i < n; i++){
        cin >> X[i];
    }
    for(int i = 0; i < n; i++){
        sum += X[i];
    }
    double y = round(sum / n);
    for(int i = 0; i < n; i++){
        minsum += (X[i] - y) * (X[i] - y);
    }
    cout << minsum << endl;
    return 0;
}




Measured memory_bytes: 256
//#include <ext/pb_ds/assoc_container.hpp> 
 //#include <ext/pb_ds/tree_policy.hpp>
// #include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e17;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power(((((a)%mod)*((a)%mod))%mod),b/2)%mod;
    else return (((a)%mod)*(power(((((a)%mod)*((a)%mod))%mod),b/2)%mod))%mod;
}
inline ll inverse(ll a,ll md) {
  a %= md;
  if (a < 0) a += md;
  ll b = md, u = 0, v = 1;
  while (a) {
    ll t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}
  
  
 //using namespace __gnu_pbds;
 //#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k)  returns iterator to kth element starting from 0;
//order_of_key(k) returns count of elements strictly smaller than k;
//erase,insert same as normal set
// mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count()); for randomized solution
const int ce=1e9+7;
ll fast_mod(ll input)
{
    return input < ce ? input : input%ce;
}
#define pi acos(-1)

int32_t main()
{
    IOS

    
    map<int,int> m1;
    int n;
    cin>>n;
    int ans=0;
    int a[n+1];
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        a[i]=x;
        m1[x-i]++;
    }
    for(int i=1;i<=n;i++)
    {
        ans+=m1[-(a[i]+i)];
    }
    cout<<ans;

    
}       


Measured memory_bytes: 27916
N,A,B = map(int,input().split())
S =list(input())

check = 0
b_check = 0


for i in S:
  if check>=A+B:
    print('No')
  elif i == 'a':
    print('Yes')
    check += 1
  elif i == 'b' and b_check < B:
    print('Yes')
    check+=1
    b_check+=1
  else:
    print('No')
  

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

int solve();

int main()
{
	printf("%d\n", solve());

	return 0;
}

int solve()
{
	int h, w, n;
	scanf("%d%d%d", &h, &w, &n);
	std::vector<std::pair<int, int>> yx;
	for (int i = 0; i < n; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		yx.push_back({y, x});
	}
	std::sort(yx.begin(), yx.end(),
		[](const auto& a, const auto& b)
		{
			if (a.first != b.first) return a.first < b.first;
			else return a.second < b.second;
		}
	);
	
	int min_x{1 << 30}, shift{};
	for (int i = 0; i < n; i++)
	{
		if (yx[i].first + shift < yx[i].second)
			min_x = std::min(min_x, yx[i].second);
		else if (yx[i].first + shift == yx[i].second)
			shift++;
	}
	if (min_x == 1 << 30) return h;
	return min_x - 1;
}


Measured memory_bytes: 3444
(D, G) = gets.split.map(&:to_i)
N = 1000
dp = Array.new(N+1, 0)

1.upto(D) do |i|
  pi, c = gets.split.map(&:to_i)
  N.downto(0) do |j|
    d = []
    d << dp[j]
    pi.times do |k|
      d << i * k * 100 + dp[j-k] if j - k >= 0
    end
    d << i * pi * 100 + c + dp[j-pi] if j - pi >= 0
    dp[j] = d.max
  end
end

dp.each_with_index do |s, idx|
  if s >= G
    puts idx
    break
  end
end

Measured memory_bytes: 3324
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;





int main()
{
    int n;
    int a = 0, b = 0, c = 0, d = 0;
    cin >> n;
    while (n--) {
        string p;
        cin >> p;
        if (p == "AC")a++;
        if (p == "WA")b++;
        if (p == "TLE")c++;
        if (p == "RE")d++;

    }
    cout << "AC x  " << a << endl;
    cout << "WA x " << b << endl;
    cout << "TLE x " << c << endl;
    cout << "RE x " << d << endl;


    return 0;

}

Measured memory_bytes: 3632
#include <stdio.h>          // printf(), scanf(), fgets()
#include <stdlib.h>         // strtol(), exit()
#include <stdbool.h>

typedef struct token_tbl
{
	char kind;
	int value;
} token_t;

struct token_stream_tbl
{
	bool full;
	token_t buffer;
} ts;

token_t token;
const char *s;

void
cleanup(int ecode)
{
	exit(ecode);
}

void
ts_get()
{
	char *nextp = NULL;

	if (ts.full)
	{
		ts.full = false;
		token = ts.buffer;
		return;
	}

	switch (*s)
	{
	case '(':
	case ')':
	case '+':
	case '-':
	case '*':
	case '/':
	case '=':
	case '\n':
	case '\0':
		token.kind = *s;
		s++;
		return;

	default:
		token.kind = '9';
		token.value = strtol(s, &nextp, 10);
		s = nextp;
		return;
	}
}

void
ts_unget()
{
	ts.full = true;
	ts.buffer = token;
}

int expression();

int
primary()
{
	ts_get();
	switch(token.kind)
	{
	case '(':
	  {
		int d = expression();
		ts_get();
		if(token.kind != ')')
		{
			fprintf(stderr, "'(' expected\n");
			cleanup(1);
		}

		return (d);
	  }

	case '-':
		return (-primary());

	case '9':
		return (token.value);

	default:
		fprintf(stderr, "primary expected\n");
		cleanup(1);
		return 0;
	}
}

int
term()
{
	int left = primary();
	while(true)
	{
		ts_get();
		switch(token.kind)
		{
		case '*':
			left *= primary();
			break;

		case '/':
		  {
			int d = primary();
			if(d == 0)
			{
				fprintf(stderr, "divide by zero\n");
				cleanup(1);
			}

			left /= d;
			break;
		  }

		default:
			ts_unget();
			return(left);
		}
	}
}

int
expression()
{
	int left = term();
	while(true)
	{
		ts_get();
		switch(token.kind)
		{
		case '+':
			left += term();
			break;

		case '-':
			left -= term();
			break;

		default:
			ts_unget();
			return(left);
		}
	}
}

int
main(int argc, char **argv)
{
	char line[101];
	int n;

	scanf("%d\n", &n);
	while (n--)
	{
		fgets(line, sizeof(line), stdin);
		ts.full = false;
		s = line;
		printf("%d\n", expression());
	}

	return 0;
}

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

#define SIZE 100000

using ull  = unsigned long long;
using Pull = std::pair< ull, ull >;

ull N, M;
Pull a[SIZE];

void solve() {
    ull ans = 0, idx = 0;
    std::sort(a, a+N);
    while (M > 0 && idx < N) {
        if (M > a[idx].second) {
            M -= a[idx].second;
            ans += a[idx].first * a[idx].second;
        } else {
            ans += a[idx].first * M;
            M = 0;
        }
        ++idx;
    }
    std::cout << ans << std::endl;
}

int main() {
    std::cin >> N >> M;
    for (ull i=0; i<N; ++i) std::cin >> a[i].first >> a[i].second;
    solve();
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define N 100000
using namespace std;
int p[N],q[N],r[N],s[2*N];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x,y,a,b,c,temp;
    cin>>x>>y>>a>>b>>c;
    for(int i=0;i<a;i++)cin>>p[i];
    for(int i=0;i<b;i++)cin>>q[i];
    for(int i=0;i<c;i++)cin>>r[i];
    sort(p,p+a);
    sort(q,q+b);
    sort(r,r+c);
    copy(p+a-x,p+a,s);
    copy(q+b-y,q+b,s+x);
    sort(s,s+x+y);
    int i=0;
    for(int j=c-1;j>=0;j--){
        if(s[i]>=r[j])break;
        s[i++] = r[j];
    }
    long long ans=0LL;
    for(int i=0;i<(x+y);i++)ans+=s[i];
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define INF (1e9 + 10)
#define MAX_N (500010)

void mergeSort( int A[], int left, int right );
void merge( int A[], int left, int mid, int right );

int num_compare = 0;

int main()
{
    int n;
    int A[MAX_N];
    
    scanf("%d", &n);

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

    for ( int i = 0; i < n; i++ ) {
	printf("%d%c", A[i], (i == n-1) ? '\n' : ' ');
    }

    printf("%d\n", num_compare);

    return 0;
}



void mergeSort( int A[], int left, int right )
{
    if ( left + 1 < right ) {	// ????´????2??\???????????´???
	int mid = ( left + right ) >> 1;
	mergeSort( A, left, mid );
	mergeSort( A, mid, right );	
	merge( A, left, mid, right );
    }
    
    return;
}




void merge( int A[], int left, int mid, int right )
{
    int num_left  = mid - left;
    int num_right = right - mid;
    int *L = (int *)malloc( (1 + num_left)  * sizeof(int) );
    int *R = (int *)malloc( (1 + num_right) * sizeof(int) );
    int i_left = 0;
    int i_right = 0;

    memcpy(L, &A[left], sizeof(int) * num_left);
    memcpy(R, &A[mid],  sizeof(int) * num_right);
    L[num_left] = R[num_right] = INF;

    for ( int k = left; k < right; k++ ) {
	if ( L[i_left] < R[i_right] ) {
	    A[k] = L[i_left];
	    i_left++;
	}
	else {
	    A[k] = R[i_right];
	    i_right++;
	}
	num_compare++;
    }
    
    free(L);
    free(R);

    return;
}

Measured memory_bytes: 4924
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)

using namespace std;

int main()
{
	int n; cin >> n;
	string s; cin >> s;

	vector <int> left(n, 0);
	vector <int> right(n, 0);
	{
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (s[i] == '#') count++;
			left[i] = count;
		}
	}
	{
		int count = 0;
		for (int i = n - 1; 0 <= i; i--) {
			if (s[i] == '.') count++;
			right[i] = count;
		}
	}

	int ans = INT_MAX;
	for (int i = 0; i < n - 1; i++) {
		ans = min(ans, left[i] + right[i + 1]);
	}
	ans = min(ans, right[0]);
	ans = min(ans, left[n - 1]);

	cout << ans << endl;
}

Measured memory_bytes: 2180
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {

	
	public static void main(String[] args) {
		FastScanner scanner=new FastScanner();
		int n=scanner.nextInt(),k=scanner.nextInt();
		int a[]=scanner.readArray(n);
		
		boolean dp[]=new boolean[k+1];
//		Arrays.fill(dp, true);
//		dp[0]=false;
		
		for(int stones=0;stones<=k;stones++) {
			for(int j:a)
				if(j<=stones&&!dp[stones-j]) dp[stones]=true;
		}
		if(dp[k]) System.out.println("First");
		else System.out.println("Second");
	
		
		

	}
	static class FastScanner{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDoubel() {
			return Double.parseDouble(next());
		}
		int [] readArray(int n) {
			int a[]=new int[n];
			for(int i=0;i<n;i++) a[i]=nextInt();
			return a;
		}
		
		
	}

}



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

int main(){
  vector<int64_t> vec(100000,0);
  int64_t N, K;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    int a,b;
    cin >> a >> b;
    vec[a] += b;
  }
  
  for(int i = 0; true; i++){
    K -= vec[i];
    if(K <= 0){
      cout << i << endl;
     return 0;
    }
  }
  
}

Measured memory_bytes: 1024
// inputに入力データ全体が入る
function Main(input) {

  var inp = input.split('\n');
  var N = inp[0];
  var tmp = inp[1].split(' ');
  var tmp2 = inp[2].split(' ');

  // 二次元配列
  var A = new Array;
  A[0] = new Array;
  A[1] = new Array;

  for (var j = 0; j < N; j++) {
    A[0][j] = parseInt(tmp[j]);
    A[1][j] = parseInt(tmp2[j]);
  }


  var maxVal = 0;
  for (var tmp = 0; tmp <= N - 1; tmp++) {
    var sum = 0;
    for (var l = 0; l <= N - 1 - tmp; l++) {
      sum += A[0][l];
    }
    for (var m = N - 1 - tmp; m <= N - 1; m++) {
      sum += A[1][m];
    }
    if (sum > maxVal) maxVal = sum;
  }
  console.log('%d', maxVal);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import java.util.Scanner;

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

        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();

        System.out.println(solve(A, B, C, K));

        sc.close();
    }

    static int solve(int A, int B, int C, int K) {
        int result = 0;

        int posCount = Math.min(A, K);
        result += posCount;
        K -= posCount;

        int zeroCount = Math.min(B, K);
        K -= zeroCount;

        result -= K;

        return result;
    }
}

Measured memory_bytes: 35620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define OUT(x) cout << (x) << endl;
#define REP(i, n) for (int i=0; i<n; ++i)

int main(){
    int A, B, C, D;
    cin >> A >> B  >> C >> D;

    int ans=0;
    if(A <= C && C <= B) {
        ans = B-C;
    }
    if(C <=A && A <= D){
        ans = D-A;
    }
    if(A <= C && D <= B){
        ans = D-C;
    }
    if(C <=A && B<=D){
        ans = B-A;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define MAXN 100005
using namespace std;

int n,a[MAXN],b[MAXN];
int ans,mx,x;
vector<pair<int,int> > v,r;

inline void max(int &a,int b){if (a<b) a=b;return ;}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if (i&1) ++a[x];
		else ++b[x];
	}
	for (int i=1;i<=100000;i++)
		if (a[i]) v.push_back(mp(a[i],i));
	for (int i=1;i<=100000;i++)
		if (b[i]) r.push_back(mp(b[i],i));
	sort(v.begin(),v.end(),greater<pair<int,int> >());
	sort(r.begin(),r.end(),greater<pair<int,int> >());
	if (v[0].second==r[0].second)
	{
		int k=max(v[0].first+r[1].first,v[1].first+r[0].first);
		printf("%d\n",n-k);
		return 0;
	}
	printf("%d\n",n-v[0].first-r[0].first);
	return 0;
}

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

int main() {
  int N,A;
  cin >> N >> A;
  //N%500=<Aの時yes
  if (N % 500 <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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



int main()
{
    int w,h,x,y,r;
    cin >> w >> h >> x >> y >> r;
    if ((x <= w-r) && (x >= r) && (y <= h-r) && (y >= r) )
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
   return 0;


}



Measured memory_bytes: 3100
#include <iostream>
#include <string>

using namespace std;

main(){
	int i, j;
	for(i = 0; i < 9; i++){
		for(j = 0; j < 9; j++){
			cout << (i + 1) << "x" << (j + 1) << "=" << ((j + 1) * (i + 1)) << endl;
		}
	}
}

Measured memory_bytes: 1116
#include <bits/stdc++.h>
#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(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#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 show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n;
  cin >> n;
  vi x(n);
  rep(i,n) cin >> x[i];
  
  int ans = INF;
  srep(p,1,101) {
    int tmp = 0;
    rep(i,n) {
      tmp += (x[i]-p)*(x[i]-p);
    }
    ans = min(ans, tmp);
  }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	ll m;
	ll lcm=1;
	cin>>n>>m;
    vector<ll>arr(n);
	for(int i=0; i<n; i++)
	 cin>>arr[i];
	for(int i=0; i<n; i++){
		lcm=(lcm*arr[i])/(__gcd(lcm,arr[i]));
	}
	int flag=0;
	for(int i=0; i<n-1; i++){
		ll num1=arr[i];
		ll num2=arr[i+1];
		int cnt1=0,cnt2=0;
		while(num1%2==0){
			num1/=2;
			cnt1++;
		}
		while(num2%2==0){
			num2/=2;
			cnt2++;
		}
		if(cnt1!=cnt2){
			flag=1;
			break;
		}
	}
	if(flag)
	 cout<<"0";
	else{
		ll ans=(2*m/lcm+1)/2;
		cout<<ans;
	
	}
	return 0;
	
}

Measured memory_bytes: 3980
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
#define ll long long int
#define mod 1000000007
using namespace std;


ll fermat(ll base, ll exp)
{
	ll result = 1;
	while(exp > 0)
	{
		if(exp % 2 == 1)
			result = ((result % mod) * (base % mod)) % mod;
		base = ((base % mod) * (base % mod)) % mod;
		exp /= 2;
	}
	return result;
}

ll binomialCoeff(ll n, ll k)  
{  
    ll res = 1;  

    if ( k > n - k )  
        k = n - k;  

    for (ll i = 0; i < k; ++i)  
    {  
        res = ((res % mod) * ((n - i) % mod)) % mod;
        ll invVal = fermat(i + 1, mod - 2);          
        res = ((res % mod) * (invVal % mod)) % mod;  
    }    
    return res;  
}

ll fastExp(ll base, ll exp)
{
	ll result = 1;
	while(exp > 0)
	{
		if(exp % 2 == 1)
			result = ((result % mod) * (base % mod)) % mod;
		base = ((base % mod) * (base % mod)) % mod;
		exp /= 2;
	}
	return result;
}


int main()
{
    ll n, a, b;

    cin >> n >> a >> b;

    int i;
    ll val1 = binomialCoeff(n, a);
    ll val2 = binomialCoeff(n, b);
    ll Ans = fastExp(2, n);

    // cout << Ans << endl;
    // cout << val1 << endl;
    // cout << val2 << endl;

    ll finalAns = (Ans - val1 - val2 + 2 * mod - 1) % mod;
    cout << finalAns << endl;
}

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

int main() {
  int N,M;cin>>N>>M;
  vector<int> A(M);
  int X=0;
  for(int i=0;i<M;i++){
    cin>>A.at(i);
    X+=A.at(i);
  }
  if(N>=X) cout<<N-X<<endl;
  else cout<<-1<<endl;
  
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
#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()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    char s[n][n];
    rep(i,n){
        rep(j,n){
            cin >> s[i][j];
        }
    }

    int ans = 0;
    char t[n][n];
    
    rep(i,n){
        rep(j,n){
            rep(k,n){
                t[j][k] = s[j][(k + i)%n];
            }
        }
        int flag = 1;
        rep(j,n){
            rep(k,n){
                if(t[j][k] != t[k][j]){
                    flag = 0;
                    break;
                }
            }
        }
        ans += (n - i) * flag;
    }

    srep(i,1,n){
        rep(j,n){
            rep(k,n){
                t[j][k] = s[(j + i)%n][k];
            }
        }
        int flag = 1;
        rep(j,n){
            rep(k,n){
                if(t[j][k] != t[k][j]){
                    flag = 0;
                    break;
                }
            }
        }
        ans += (n - i) * flag;
    }

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


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  string s;
  cin>>s;

  if(s[s.size()-1]=='s'){
    cout<<s<<"es"<<endl;
  }
  else{
    cout<<s<<"s"<<endl;
  }
  return 0;
}


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

int main(){

int x,y,a,b;
  cin >> x >> y >> a>> b;
  double q =(double)x*y/2;
  if(x==a*2&&y==b*2){cout << q << " " << 1 ;}
  else{cout  << q << " " << 0 ;}
}

Measured memory_bytes: 256
///******* In the name of Allah *******///

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

//long int ar[90013],br[100013];
//long int gcd(long int a, long int b)
//{
//    if(b==0)
//        return a;
//    return gcd(b,a%b);
//}
//long int sieve(long long int a)
//{
//    //long long int i,j,k = 0;
//    memset(ar,0,sizeof(ar));
//    ar[1] = 1;
//    for(i=2; i<=90013; i++)
//    {
//        if(ar[i]==0)
//        {
//            k++;
//            br[k] = i;
//            for(j=i+i; j<=90013; j+=i)
//            {
//                ar[j] = 1;
//            }
//        }
//    }
//    return br[a];
//}

void Ok()
{
    long int a,b,c,d,h,t,i = 0,j = 0,k = 0,l,m,n;
    long int ans_1,ans_2,ans_3,cnt = 0,Max,Min,flag = 1,temp,sum = 0;
    double aa,bb,cc,dd,ee,ff,gg;
    //char aaa[10013],bbb[10013],ccc[113],ddd;
    string spc,in;

    scanf("%ld",&a);
    aa = a;
    bb = 2 * 3.1416 * aa;
    printf("%0.2lf",bb);

    return;
}

int main()
{
    Ok();

    return 0;
}


Measured memory_bytes: 3816
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i;

	          int A,B;
	          cin >> A >> B;
	          if(A==1) A=14;
	          if(B==1) B=14;
	          if(A>B) cout << "Alice" << endl;
	          else if(A<B) cout << "Bob" << endl;
	          else cout << "Draw" << endl;

	          return 0;
}


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

class Disjoint{
private:
    vector<int> S;
    vector<int> rank;
    int find(int x){
        if (x == S[x]) {
            return x;
        }
        return x = find(S[x]);
    }
public:
    Disjoint(int n) {
        for (int i = 0; i < n; i++) {
            S.push_back(i);
            rank.push_back(0);
        }
    }
    void unite(int x, int y){
        int x_p = find(x);
        int y_p = find(y);
        if (rank[x_p] == rank[y_p]) {
            S[x_p] = y_p;
            rank[y_p]++;
            return;
        }
        if (rank[x_p] < rank[y_p]) {
            S[x_p] = y_p;
        } else {
            S[y_p] = x_p;
        }
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    Disjoint D(n);

    for (int i = 0; i < q; i++) {
        int command, x, y;
        cin >> command >> x >> y;
        if (command == 0) {
            D.unite(x, y);
        } else {
            cout << D.same(x, y) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3256
using System;
using System.Linq;

namespace AtCoder.Problems
{
    public class ProblemA
    {
        public static void Main(string[] args)
        {
            var s = new SolveA();
            s.Solve();
        }

        public class Scanner
        {
            private string[] _s;
            private int _i;
            private readonly char[] _separators = new char[] {' '};

            public Scanner()
            {
                _s = new string[0];
                _i = 0;
            }

            public string Next()
            {
                if (_i < _s.Length) return _s[_i++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();
                _s = st.Split(_separators, StringSplitOptions.RemoveEmptyEntries);
                if (_s.Length == 0) return Next();
                _i = 0;
                return _s[_i++];
            }

            public int NextInt() => int.Parse(Next());
            public long NextLong() => long.Parse(Next());
            public ulong NextULong() => ulong.Parse(Next());
            public double NextDouble() => double.Parse(Next());

            public int[] GetIntArray(int n, int add = 0)
            {
                int[] array = new int[n];
                for (int i = 0; i < n; i++)
                {
                    array[i] = NextInt() + add;
                }
                return array;
            }

            public long[] GetLongArray(int n, long add = 0)
            {
                long[] array = new long[n];
                for (int i = 0; i < n; i++)
                {
                    array[i] = NextLong() + add;
                }
                return array;
            }

            public double[] GetDoubleArray(int n, double add = 0)
            {
                double[] array = new double[n];
                for (int i = 0; i < n; i++)
                {
                    array[i] = NextDouble() + add;
                }
                return array;
            }
        }
    }

    public class SolveA
    {
        public void Solve()
        {
            var cin = new ProblemA.Scanner();
            var s = cin.Next();

            var result = GetAnswer(s);
            Console.WriteLine(result);
        }

        public string GetAnswer(string s)
        {
            return s.Any(c => c == '7') ? "Yes" : "No";
        }
    }
}

Measured memory_bytes: 26164
// CPP program to find the minimum number of 
// characters to be replaced in string S2, such 
// that S1 is a substring of S2 
//Written by me
#include <bits/stdc++.h> 
using namespace std; 

// Function to find the minimum number of 
// characters to be replaced in string S2, such 
// that S1 is a substring of S2 
int minimumChar(string S1, string S2) 
{ 
	// Get the sizes of both strings 
	int n = S1.size(), m = S2.size(); 

	int ans = INT_MAX; 

	// Traverse the string S2 
	for (int i = 0; i < m - n + 1; i++) { 
		int minRemovedChar = 0; 

		// From every index in S2, check the number of 
		// mis-matching characters in substring of 
		// length of S1 
		for (int j = 0; j < n; j++) { 
			if (S1[j] != S2[i + j]) { 
				minRemovedChar++; 
			} 
		} 

		// Take minimum of prev and current mis-match 
		ans = min(minRemovedChar, ans); 
	} 

	// return answer 
	return ans; 
} 

// Driver Code 
int main() 
{ 
	string S1 = "abc"; 
	string S2 = "paxzk"; 
	cin>>S1>>S2;

	cout << minimumChar(S2, S1); 

	return 0; 
} 


Measured memory_bytes: 3624
#include <stdio.h>

int main(void){

    int a,b,c,flag = 0;

    scanf(" %d %d %d", &a, &b, &c);

    if(a == b && a != c){
        flag = 1;
    }

    if(a == c && a != b){
         flag = 1;
    }
    if(b == c && b != a){
         flag = 1;
    }

     if(flag == 1){
         printf("Yes\n");
     }else {
         printf("No\n");
     }

     return 0;

}

Measured memory_bytes: 128
let swap() =
  let s = ref "" in
  let f a b = if a <= b then print_endline (string_of_int a ^ " " ^ string_of_int b)
                 else print_endline (string_of_int b ^ " "^ string_of_int a)
  in
  while (s := read_line() ; !s <> "0 0")
  do
    Scanf.sscanf !s "%d %d" f;
  done ;;
  swap () ;;


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

struct Parser {
    using itr = string::const_iterator;
    itr now;
    int X;
    __int128_t ans;
    const struct ex {
        vector<char> _012;
        ex() {
            _012.resize(10);
            for(int i = 0; i < 10; ++i) {
                _012[i] = char('0' + i);
            }
        }
    } ex;
    // <expr> ::= <numb> [ +<numb> ]*
    // <numb> ::= [ 1-9 | X ] [ 0-9 | X ]*
    Parser(const string &s, const int X)
        : X(X)
    {
        now = s.begin();
        ans = expr(now);
    }
    // <expr> ::= <numb> [ +<numb> ]*
    __int128_t expr(itr &now) {
        __int128_t ret = numb(now);
        while(1) {
            if(*now == '+') {
                next(now, '+');
                ret += numb(now);
            } else {
                return ret;
            }
        }
    }
    // <numb> ::= [1-9][0-9]*
    __int128_t numb(itr &now) {
        __int128_t ret = 0;
        int digit = 0;
        bool top0 = true;
        while(1) {
            ret *= 10;
            if('0' <= *now and *now <= '9') {
                top0 = false;
                ret += (*now) - '0';
                next(now, ex._012);
                ++digit;
            } else if(*now == 'X') {
                if(X != 0) top0 = false;
                ret += X;
                next(now, 'X');
                ++digit;
            } else {
                if(top0 and digit > 1) throw "top0";
                return ret;
            }
        }
    }
    void next(itr &now, const char expected) {
        vector<char> req = {expected};
        next(now, req);
    }
    void next(itr &now, const vector<char> &expected) {
        for(char c: expected){
            if(*now == c){
                now++;
                return;
            }
        }
        // デバッグ用
        fprintf(stderr, "Expected: ");
        for(char c: expected) fprintf(stderr, "%c", c);
        fprintf(stderr, "\nGot: %c\n", *now);
        fprintf(stderr, "Rest: ");
        while(*now) fprintf(stderr, "%c", *now++);
    }
};

void solve(const string &s1, const string &s2, const int X) {
    if(X >= 10) {
        cout <<  "NA" << endl;
        return;
    }
    try {
        Parser parse1(s1, X);
        Parser parse2(s2, X);
        if(parse1.ans != parse2.ans) throw "mismatch";
        cout << X << endl;
    }
    catch(...) {
        solve(s1, s2, X + 1);
    }
}

int main(){
    string s;
    while(cin >> s) {
        int n = s.size();
        string s1, s2;
        for(int i = 0; i < n; ++i) {
            if(s[i] == '=') {
                s1 = s.substr(0, i);
                s2 = s.substr(i + 1);
                break;
            }
        }
        solve(s1, s2, 0);
    }
    return 0;
}



Measured memory_bytes: 3136
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>



using namespace std;


char grid[21][21];


int main()
{
	int N, M, in_x, in_y, l, now_x, now_y;
	char d;
	
	while (cin >> N)
	{
		if (N == 0) break;
		
		//gridの初期化
		for (int y=0; y<21; y++)
		{
			for (int x=0; x<21; x++)
			{
				grid[y][x] = '.';
			}
		}
		
		//宝石の位置の入力
		for (int i=0; i<N; i++)
		{
			cin >> in_x >> in_y;
			grid[in_y][in_x] = '#';
		}
		
		cin >> M;
		now_x = now_y = 10;
		for (int i=0; i<M; i++)
		{
			cin >> d >> l;
			for (int j=1; j<=l; j++)
			{
				if (d == 'N')
				{
					grid[now_y + j][now_x] = '.';
					if (j == l)
					{
						now_y += j;
					}
				} else if (d == 'E') {
					grid[now_y][now_x + j] = '.';
					if (j == l)
					{
						now_x += j;
					}
				} else if (d == 'S') {
					grid[now_y - j][now_x] = '.';
					if (j == l)
					{
						now_y -= j;
					}
				} else if (d == 'W') {
					grid[now_y][now_x - j] = '.';
					if (j == l)
					{
						now_x -= j;
					}
				}
			}
		}
		
		bool flag = false;	//宝石が一つでも残っていたらtrueになる
		for (int y=0; y<21; y++)
		{
			for (int x=0; x<21; x++)
			{
				if (grid[y][x] == '#')
				{
					flag = true;
				}
			}
		}
		if (flag)
		{
			cout << "No" << endl;
		} else {
			cout << "Yes" << endl;
		}
		/*
		//テスト出力
		for (int y=20; y>=0; y--)
		{
			for (int x=0; x<21; x++)
			{
				cout << grid[y][x];
			}
			cout << endl;
		}
		*/
	}
	
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <math.h>
#include <time.h>
#include <bitset>
#include <assert.h>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) x.begin(),x.end() 
#define PII pair <ll,ll>
#define N 100007
#define MOD 1000000007
#define INF 1000000000000000000
using namespace std;

ll v[N], w[N], dp[107][N];

int main() {
    int n, W;
    cin >> n >> W;
    for(int i = 1; i <= n; i++) {
        cin >> w[i] >> v[i];
    }
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= W; j++) {
            if(i == 0 || j == 0) {
                dp[i][j] = 0;
            }
            else if(w[i] <= j) {
                dp[i][j] = max(v[i] + dp[i-1][j-w[i]], dp[i-1][j]);
            }
            else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout << dp[n][W];
    return 0;
}

Measured memory_bytes: 82176
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 LN           PIC X(500).
01 N            PIC 9(3).
01 cur          PIC 9(10) VALUE 1.
01 i            PIC 9(18) VALUE 1.
01 j            PIC 9(18).
01 len          PIC 9(10). 
01 A            PIC 9(4) VALUE 1.
01 FLG          PIC 9(1) VALUE 1.

PROCEDURE DIVISION.
MAIN.
  ACCEPT N.
  ACCEPT LN.
  PERFORM N TIMES
      PERFORM VARYING j FROM cur BY 1 UNTIL LN(j:1) = SPACE
      END-PERFORM
      COMPUTE len = j - cur
      MOVE LN(cur:len) TO A
      IF FUNCTION MOD(A, 2) = ZERO AND FUNCTION MOD(A, 3) NOT = ZERO
          AND FUNCTION MOD(A, 5) NOT = ZERO THEN
          MOVE ZERO TO FLG
          EXIT PERFORM
      END-IF
      COMPUTE cur = j + 1
      ADD 1 TO i
  END-PERFORM.
  IF FLG = 1
      DISPLAY "APPROVED"
  ELSE
      DISPLAY "DENIED"
  END-IF.

MAIN-EXIT.
    STOP RUN.


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll, ll> lltpl;



/******************************************************************************************/


const ll MOD = 1e9 + 7;



template<typename T>
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);
}


char A[2005][2005];
char B[2005][2005];



int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> A[i][j];
		}
		
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> B[i][j];
		}

	}

	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			ans += (A[i][j] != B[i][j]);
		}

	}


	cout << ans << endl;




	return 0;
}



Measured memory_bytes: 10976
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll d,g;
  cin >> d >> g;

  vector<pair<ll,ll>> t(pow(2,d));
  vector<ll> p(d),c(d);

  rep(i,d)
  {
    cin >> p[i] >> c[i];
  }

  for(int bit = 0; bit < (1 << d); bit++)
  {
    ll ans_num = 0;
    ll point_sum = 0;
    for(int i = 0;i < d; i++)
    {
      if(bit & ( 1 << i))
      {
        ans_num += p[i];
        point_sum += 100 * ( i + 1) * p[i] + c[i];
      }
    }
    t[bit].first = ans_num;
    t[bit].second = point_sum;
  }

  ll bb = pow(2,d);
  for(int i = 0;i < bb; i++)
  {
    if(t[i].second >= g)
    {
      // 目標を達成しているのならそのまま
    }
    else
    {
      ll buf = g - t[i].second;
      for(int j = d-1;j >= 0;--j)
      {
        if(!(i & (1 << j))) // bitが立ってなかったら、まだ解いていない
        {
          ll nan = kiriage(buf,(j+1)*100);
          if(nan >= p[j])
          {
            buf -= (j + 1) * 100 * (p[j] - 1); //コンプリートしないパターンだからとき切らない
            t[i].first += p[j];
          }
          else
          {
            t[i].first += nan;   // 多くないからとき切っていい
            break;  // 抜け出せる
          }
        }
      }
    }
  }

  sort(all(t),[](auto a,auto b){
    return a.first < b.first;
  });

  cout << t[0].first << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


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

int main(){
	int w,h,x,y;
	char tile[100][100];
	bool use[100][100];
	bool flg;
	
	while(1){
	 cin>>h>>w;
	 if(w==0 && h==0){break;}
	 for(y=0;y<h;y++){
	  for(x=0;x<w;x++){
	   cin>>tile[x][y];
	   use[x][y]=false;
	  }
	 }
	 
	 x=0;y=0;flg=true;
	 do{
	  if(use[x][y]){cout<<"LOOP"<<endl;break;}
	  use[x][y]=true;
	  switch(tile[x][y]){
		case '.':
		flg=false;
		cout<<x<<" "<<y<<endl;
		break;

		case '>':
		x+=1;
		break;

		case '<':
		x-=1;
		break;

		case '^':
		y-=1;
		break;

		case 'v':
		y+=1;
		break;
	  }
	 }while(flg);
	}
}

Measured memory_bytes: 1180