akhauriyash/Code-Regression huggingface dataset:
#line 1 "main.cpp"

#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_B"

#line 2 "/Users/kodamankod/Desktop/Programming/Library/container/fenwick_tree.cpp"

#line 2 "/Users/kodamankod/Desktop/Programming/Library/other/bit_operation.cpp"

#include <cstddef>
#include <cstdint>

constexpr size_t count_zero_right(const uint64_t x) {
  return x == 0 ? 64 : __builtin_ctzll(x);
}

constexpr size_t count_zero_left(const uint64_t x) {
  return x == 0 ? 64 : __builtin_clzll(x);
}

constexpr size_t bit_width(const uint64_t x) { 
  return 64 - count_zero_left(x);
}

constexpr uint64_t most_significant_bit(const uint64_t x) {
  return x == 0 ? 0 : uint64_t(1) << (bit_width(x) - 1);
}

constexpr uint64_t least_significant_bit(const uint64_t x) {
  return x & (-x);
}

constexpr uint64_t next_power_of_two(const uint64_t x) {
  return x == 0 ? 0 : most_significant_bit(2 * x - 1);
}

constexpr uint32_t bit_reverse_32(uint32_t x) {
  constexpr uint32_t b16 = 0b00000000000000001111111111111111;
  constexpr uint32_t  b8 = 0b00000000111111110000000011111111;
  constexpr uint32_t  b4 = 0b00001111000011110000111100001111;
  constexpr uint32_t  b2 = 0b00110011001100110011001100110011;
  constexpr uint32_t  b1 = 0b01010101010101010101010101010101;
  x = ((x >> 16) & b16) | ((x & b16) << 16);
  x = ((x >>  8) &  b8) | ((x &  b8) <<  8);
  x = ((x >>  4) &  b4) | ((x &  b4) <<  4);
  x = ((x >>  2) &  b2) | ((x &  b2) <<  2);
  x = ((x >>  1) &  b1) | ((x &  b1) <<  1);
  return x;
}
#line 5 "/Users/kodamankod/Desktop/Programming/Library/container/fenwick_tree.cpp"
#include <vector>

template <class T>
class fenwick_tree {
public:
  using value_type = T;
  using size_type = size_t;

private:
  std::vector<value_type> M_tree;

public:
  fenwick_tree() = default;
  explicit fenwick_tree(size_type size) { initialize(size); }

  void initialize(size_type size) {
    M_tree.assign(size + 1, value_type{});
  }

  void add(size_type index, const value_type& x) {
    ++index;
    while (index <= size()) {
      M_tree[index] += x;
      index += least_significant_bit(index);
    }
  }

  value_type get(size_type index) const {
    ++index;
    value_type res{};
    while (index > 0) {
      res += M_tree[index];
      index -= least_significant_bit(index);
    }
    return res;
  }
  value_type fold(size_type l, size_type r) const {
    if (l == 0 && r == 0) return value_type{};
    if (l == 0) return get(r - 1);
    return get(r - 1) - get(l - 1);
  }

  size_type size() const {
    return M_tree.size() - 1;
  }

};
#line 5 "main.cpp"

#line 8 "main.cpp"
#include <iostream>

int main() {
  size_t N, Q;
  std::cin >> N >> Q;
  fenwick_tree<uint32_t> seg(N);
  while (Q--) {
    char type;
    std::cin >> type;
    if (type == '0') {
      size_t x;
      uint32_t y;
      std::cin >> x >> y;
      seg.add(x - 1, y);
    }
    else {
      size_t x, y;
      std::cin >> x >> y;
      std::cout << seg.fold(x - 1, y) << '\n';
    }
  }
  return 0;
}



Measured memory_bytes: 3116
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 4e18;

void print_dfs(const vector<vector<int>> &G, int n, int p = -1) {
    cout << n + 1 << " " << endl;
    REP(i, G[n].size()) {
        if (G[n][i] != p) print_dfs(G, G[n][i], n);
    }
}

int main() {
    int n, m; cin >> n >> m;
    vector<vector<int>> G(n), outG(n);
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<bool> visited(n, false);
    stack<pair<int,int>> sta;
    int count = 0;
    sta.push({0,-1});
    while (!sta.empty()) {
        pair<int,int> p = sta.top(); sta.pop();
        if (visited[p.first]) continue;
        count++;
        visited[p.first] = true;
        if (p.second != -1) {
            outG[p.first].push_back(p.second);
            outG[p.second].push_back(p.first);
            for (int v : G[p.first]) {
                if (!visited[v]) {
                    sta.push({v,p.first});
                    break;
                }
            }
        }
        else {
            int c = 0;
            for (int v : G[p.first]) {
                if (!visited[v]) {
                    sta.push({v,p.first});
                    if (c == 1) break;
                    c++;
                }
            }
        }
    }
    int root;
    REP(i, n) {
        if (outG[i].size() == 1) {
            root = i;
            break;
        }
    }
    /*REP(i, n) {
        cout << i << " -> ";
        REP(j, outG[i].size()) {
            cout << outG[i][j] << " ";
        }
        cout << endl;
    }*/
    cout << count << endl;
    print_dfs(outG,root);
    getchar(); getchar();
}

Measured memory_bytes: 16512
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<ll> s(A+2), t(B+2), X(Q), s_rev(A+2), t_rev(B+2);
    s[A] = 1e12;
    t[B] = 1e12;
    s[A+1] = -1e12;
    t[B+1] = -1e12;
    s_rev[A] = 1e12;
    t_rev[B] = 1e12;
    s_rev[A+1] = -1e12;
    t_rev[B+1] = -1e12;

    REP(i, A) {
        cin >> s[i];
        s_rev[i] = -s[i];
    }
    REP(i, B) {
        cin >> t[i];
        t_rev[i] = -t[i];
    }
    REP(i, Q) cin >> X[i];

    sort(ALL(s));
    sort(ALL(t));

    sort(ALL(s_rev));
    sort(ALL(t_rev));

    REP(i, Q) {
        ll s1, s2, t1, t2, x = X[i];
        s1 = -*lower_bound(s_rev.begin(), s_rev.end(), -x);
        t1 = -*lower_bound(t_rev.begin(), t_rev.end(), -x);

        s2 = *lower_bound(s.begin(), s.end(), x);
        t2 = *lower_bound(t.begin(), t.end(), x);

        vector<ll> candidates(8);
        // cerr << "s1 = " << s1 << " t1 = " << t1 << " s2 = " << s2 << " t2 = " << t2 << endl;
        candidates[0] = abs(x - s1) + abs(s1 - t1); // x -> s1 -> t1;
        candidates[1] = abs(x - s1) + abs(s1 - t2); // x -> s1 -> t2;
        candidates[2] = abs(x - s2) + abs(s2 - t1); // x -> s2 -> t1;
        candidates[3] = abs(x - s2) + abs(s2 - t2); // x -> s2 -> t2;

        candidates[4] = abs(x - t1) + abs(t1 - s1); // x -> s1 -> t1;
        candidates[5] = abs(x - t1) + abs(t1 - s2); // x -> s1 -> t2;
        candidates[6] = abs(x - t2) + abs(t2 - s1); // x -> s2 -> t1;
        candidates[7] = abs(x - t2) + abs(t2 - s2); // x -> s2 -> t2;

        ll ans = 1e18;
        int arg = -1;
        REP(i, 8) {
            if (ans > candidates[i]) {
                ans = candidates[i];
                arg = i;
            }
        }
        // cerr << "arg = " << arg << endl;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 5248
#include <stdio.h>
#define MAXN 1000001
#define NIL -1

struct Node{
  int p, l, r;
};

struct Node rootTree[MAXN];


int getDepth(int u)// book P190
{
  int d = 0;
  while (rootTree[u].p != NIL){
    u = rootTree[u].p;
    d++;
  }
  return d;
}

void print(int N){
  int i, j, c, d;
  
  for ( i = 0; i <N; i++ ){
    d = getDepth(i);

    printf("node %d: parent = %d, depth = %d, ",i,rootTree[i].p, d);

    if ( rootTree[i].p == NIL ) printf("root, ");
    else if ( rootTree[i].l == NIL ) printf("leaf, ");
    else printf("internal node, ");
    
    printf("[");
    
    // printChildern(i)  book 191
    c = rootTree[i].l;
    j =0;
    while (c != NIL){
      if (j) printf(", ");
      printf("%d", c);
      c = rootTree[c].r;
      j=1;
    }

    
    printf("]\n");

    }
}

int main(void)
{
  int n,i,j,k, v,c,l;
  scanf("%d", &n);   // n nodes
  
  // init rootTree
  for ( i = 0; i < n; i++ ) {
    rootTree[i].p=NIL;
    rootTree[i].l=NIL;
    rootTree[i].r=NIL;
  }

  //input v for current node
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &v, &k);  //id,k
    for (j = 0; j < k; j++){// input k childeren
      scanf("%d", &c);
      if ( j == 0 ) rootTree[v].l = c; // WA error  v is not i
      else rootTree[l].r = c;
      l = c;
      rootTree[c].p = v;
    }
  }
  print(n);
  
  return 0;
}


Measured memory_bytes: 2868
#include <bits/stdc++.h>
#include<iostream>
#include <vector>
using namespace std;
int main() {
    int N; string S;
    cin >> N >> S;
    int64_t r = 0, g = 0, b = 0;
    for (auto c : S) {
        if (c == 'R') {
            r++;
        } else if (c == 'G') {
            g++;
        } else {
            b++;
        }
    }

    int64_t all = r * g * b;
    int64_t sub = 0;
    for (int i=0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            if(S[i] == S[j]) {
                continue;
            }

            int k = j*2-i;
            if (k >= N || S[k] == S[i] || S[k] == S[j]) {
                continue;
            }

            sub++;
        }
    }

    cout << all - sub << endl;

    return 0;
}

Measured memory_bytes: 3608
// C++ includes
#include <bits/stdc++.h>
// 俳句
using namespace std;

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b)  for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

int main(void){
    ll a;
    str s;
    cin >> s;
    if((s[0]==s[1])&&(s[0]==s[2])&&(s[0]==s[3])){
        cout << "No" << endl;
    }else if((s[0]==s[1] && s[2]==s[3]) ||
     (s[0]==s[2] && s[1]==s[3]) || 
     (s[0]==s[3] && s[1]==s[2])){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int main() {
	string a,b,c; cin >> a >> b >> c;
	bool ok = true;
	if(a[a.size()-1]!=b[0]) ok = false;
	if(b[b.size()-1]!=c[0]) ok = false;
	if(ok) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#include <cctype>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)

#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i = 0; i < b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}



int main() {
//	int i, j, k;

	int N, M, K;

	cin >> N;
	vector<int> A(N);
	for (auto& x : A) {
		cin >> x;
	}
	for (auto x : A) {
		if (x % 2 == 0) {
			if (x % 3 != 0 && x % 5 != 0) {
				cout << "DENIED";
				return 0;
			}
		}

	}
	cout << "APPROVED";

	return 0;
}

Measured memory_bytes: 256
if __name__ == '__main__':
	N, W = map(int, input().split())
	items = []
	for i in range(N):
		items.append(list(map(int, input().split())))

	dp = [0] * (W + 1)
	
	for item in items:
		v, w = item
		for i in range(W - w + 1):
			if dp[i + w] < dp[i] + v:
				dp[i + w] = dp[i] + v
	print(max(dp))



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

int main(){
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    cin >> n;
    cout << a[n-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

double a,b,h,m;
cin>> a>>b>>h>>m;

double j;

double x;

x = (abs(30*(h+(m/60)) - 6*m)*(M_PI))/180;

j=sqrt(a*a+b*b-2*a*b*cos(x));

cout<<setprecision(15)<<j;
return 0;
}



Measured memory_bytes: 4140
use std::io::*;
use std::str::*;

fn read<T: FromStr>(s: &mut StdinLock) -> T {
    let s = s.by_ref().bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}


struct TargetMap 
{
	height: i32,
	width:  i32,
	hsum : Vec::<i32>,
	wsum : Vec::<i32>,
	pt: Vec::<(i32,i32)>,
	hmax: i32,
	wmax: i32,
	hidx: Vec::<i32>,
	widx: Vec::<i32>,
}

impl TargetMap {


	fn read(&mut self, s : &mut StdinLock) {
		self.height = read::<i32>(s);
		self.width = read::<i32>(s);
		self.hsum = vec![0; self.width as usize];
		self.wsum = vec![0; self.height as usize];
		self.pt = Vec::<(i32,i32)>::new();
		let m =  read::<usize>(s);
	
		for _i in 0..m {
			let ph =  read::<i32>(s)-1;
			let pw =  read::<i32>(s)-1;
			self.hsum[pw as usize] += 1;
			if self.hsum[pw as usize] > self.hmax {
				self.hmax = self.hsum[pw as usize];
			}
			self.wsum[ph as usize] += 1;
			if self.wsum[ph as usize] > self.wmax {
				self.wmax = self.wsum[ph as usize];
			}
			self.pt.push((ph,pw));
		
		}
		self.pt.sort();
		for w in 0..self.width {
			if self.hsum[w as usize] == self.hmax {
				self.hidx.push(w);
			}
		}
		for h in 0..self.height {
			if self.wsum[h as usize] == self.wmax {
				self.widx.push(h);
			}
		}
		

	}

	fn solve(&mut self) -> i32 {
	//	println!("solve");
		let mut maxb:i32 = 0;
		for ih in 0 .. self.widx.len() {
			let h = self.widx[ih] as usize;
			if  self.wsum[h] != self.wmax {
				continue;
			}
			for iw in 0 .. self.hidx.len() {
				let w = self.hidx[iw] as usize;
				if self.hsum[w] != self.hmax {
					continue;
				}
				let mut nb = self.hsum[w] + self.wsum[h];
				if let Ok(_n) = self.pt.binary_search(&(h as i32,w as i32)) {
					nb -= 1;
				} else if self.hmax + self.wmax == nb {
					maxb = nb;
					break;
				}
				if nb > maxb {
					maxb = nb;
				}
			}
		}

		return maxb;
	}
}


fn main() {
    let s = stdin();
    let mut s = s.lock();
    let s = &mut s;

	let mut m = TargetMap {
		height : 0,
		width : 0,
		hsum : Vec::<i32>::new(),
		wsum : Vec::<i32>::new(),
   	    pt: Vec::<(i32,i32)>::new(),
		hmax : 0,
		wmax : 0,
		hidx: Vec::<i32>::new(),
		widx: Vec::<i32>::new(),
	};

	m.read(s);
	
   println!("{}", m.solve());

	
}



Measured memory_bytes: 10028
#include <stdio.h>
#include <string.h>

int main(void)
{
	int n, e, w, s, u, d;
	int m;
	char str[20];
	int i;
	int sum;
	int buf;
	
	while (1){
		n = 5;
		e = 3;
		w = 4;
		s = 2;
		u = 1;
		d = 6;
		
		scanf("%d", &m);
		if (m == 0){
			break;
		}
		
		sum = u;
		for (i = 0; i < m; i++){
			scanf("%s", str);
			
			if (strcmp(str, "North") == 0){
				buf = u;
				u = s;
				s = d;
				d = n;
				n = buf;
			}
			else if (strcmp(str, "East") == 0){
				buf = u;
				u = w;
				w = d;
				d = e;
				e = buf;
			}
			else if (strcmp(str, "West") == 0){
				buf = u;
				u = e;
				e = d;
				d = w;
				w = buf;
			}
			else if (strcmp(str, "South") == 0){
				buf = u;
				u = n;
				n = d;
				d = s;
				s = buf;
			}
			else if (strcmp(str, "Right") == 0){
				buf = s;
				s = e;
				e = n;
				n = w;
				w = buf;
			}
			else if (strcmp(str, "Left") == 0){
				buf = s;
				s = w;
				w = n;
				n = e;
				e = buf;
			}
			
			sum += u;
		}
		printf("%d\n", sum);
	}
	
	return (0);
}

Measured memory_bytes: 604
#include <cstdio>
#define W 1
#define B 2
int board[101][101];
int main(int argc, const char * argv[]) {
   
    int a,b;
    
    scanf("%d %d",&a,&b);
    a--;b--;
    
    for(int i=1;i<=100;i++){
        for(int j=1;j<=50;j++){
            board[i][j]=W;
        }
    }
    
    for(int i=1;i<=100;i++){
        for(int j=51;j<=100;j++){
            board[i][j]=B;
        }
    }
    
    int row = 1;
    int col = 1;
    for(int i=1;i<=b;i++){
        board[row][col] = B;
        
        if(col>=49){
            col = 1;
            row += 2;
            continue;
        }
        col+=2;
    }
    row = 1;
    col = 52;
    
    for(int i=1;i<=a;i++){
        board[row][col] = W;
        if(col>=100){
            row += 2;
            col = 52;
            continue;
        }
        col+=2;
    }
    
    printf("100 100\n");
    
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            if(board[i][j]==W) printf(".");
            else printf("#");
        }
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

int main()
{
  Bint A;
  string B;

  cin >> A >> B;

  string B0(B.begin(), B.end()-3);
  string B1(B.end()-2, B.end()-1);
  string B2(B.end()-1, B.end());


  Bint r0 = A*Bint(B0);
  Bint r1 = A*Bint(B1);
  Bint r2 = A*Bint(B2);
  Bint ret = r2;

  ret = r1+ret/10;
  ret = r0+ret/10;

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 3692
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=parseInt.(x)

function main()
    n = parseInt(readline())
    a = parseMap(split(readline()))

    ans = 0
    for i in 1:n
        while mod(a[i],2) == 0
            a[i] /= 2
            ans += 1
        end
    end

    println(ans)
end

main()


Measured memory_bytes: 174036
N = int(input())
t0 = 0
x0 = 0
y0 = 0
ans = True

for i in range(N):
    next = input().split()
    t = int(next[0])
    x = int(next[1])
    y = int(next[2])
    time = t - t0
    range = abs(x - x0) + abs(y - y0)

    if time < range:
        ans = False
        break

    if time % 2 == 0:
       if range % 2 != 0:
          ans = False
          break
    else:
       if range % 2 == 0 or range == 0:
          ans = False
          break

    t0 = t
    y0 = y
    x0 = x



if ans == True:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
import math

def main():
  A, B, H, M = map(int, input().split())
  A_angle_from_12 = 30*H + M/2
  A_angle = 90 + A_angle_from_12
  B_angle_from_12 = 6*M
  B_angle = 90 + B_angle_from_12
  
  A_x = A * math.cos(math.radians(A_angle))
  A_y = A * math.sin(math.radians(A_angle))
  B_x = B * math.cos(math.radians(B_angle))
  B_y = B * math.sin(math.radians(B_angle))

  res = math.sqrt((A_x - B_x)**2 + (A_y - B_y)**2)
  print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9592
#include <stdio.h>
#include <algorithm>
#include <cmath>

#define MAX_N 100000

using namespace std;

int N;

int dp[MAX_N];

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

	int input[N];

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

	dp[0] = 0;
	dp[1] = abs(input[0]-input[1]);
	for(i = 2; i<N; i++) {
		dp[i] = min(dp[i-2]+abs(input[i-2]-input[i]), dp[i-1]+abs(input[i-1]-input[i]));
	}

	printf(" %d", dp[N-1]);

	return 0;
}

Measured memory_bytes: 896
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
using ll = long long;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define INF 1e9+7
#define rep(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288

int main(){
    int n;
    cin>>n;
    vector<int>h(n);
    rep(i,n)cin>>h[i];
    vector<int>dp(n);
    
    rep(i,n)dp[i]=INF;
    dp[0]=0;
    rep(i,n){
        if(i==0)continue;
        dp[i]=min(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
        if(i==1)continue;
        dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
    int a,b;

    cin >> a >> b;

    if(a < b){
        for(int i = 0;i < b;i++)
            cout << a;
    }else{
        for(int i = 0;i < a;i++)
            cout << b;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a[1001],b[1001],c[6],d,q,i,j,k,n,x;
	for(q=0;;q++){
		x=1;
		scanf("%d%d",&k,&n);
		if(k==0 && n==0){break;}
		for(i=1;i<=k;i++){scanf("%d",&a[i]);}
		for(i=1;i<=n;i++){scanf("%d",&b[i]);}
		for(i=1;;i++){
			x=x+b[i];
			if(x>=k){break;}
			x=x+a[x];
			if(x>=k){break;}
		}
		c[q]=i;
	}
	for(i=0;i<q;i++){
		printf("%d\n",c[i]);
	}
	return 0;
}


Measured memory_bytes: 2044
#include <iostream> // {{{
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>
#include <cstdio> // }}}

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

using namespace std;

const int N = 101;

int main() {
    int n;
    int t[N],v[N];
    double x[40002]={0};
    cin >> n;
    rep(i,n) cin >> t[i];
    rep(i,n) cin >> v[i];
    const int xs = accumulate(t, t+n, 0) * 2;

    x[0] = 0;
    int k=1;
    for (int i=0; i<n; i++) {
        for (int j=1; j<=t[i]*2; j++) {
            if (j==1&&k!=1) x[k-1] = min(v[i-1],v[i]);
            x[k] = v[i];
            k++;
        }
    }
    x[xs]=0;

    for (int i=1; i<=xs; i++) {
        x[i] = min((double)x[i], x[i-1]+0.5);
    }
    for (int i=xs-1; i>=0; i--) {
        x[i] = min((double)x[i], x[i+1]+0.5);
    }

    double sum = 0;
    for (int i=0; i<xs; i++) {
        sum += (x[i] + x[i+1]);
    }
    sum /= 4.0;
    printf("%.9f\n", sum);
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007

int main()
{
    void solution();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    solution();

    return 0;
}

void solution()
{
    int n = 0;
    cin >> n;
    int a = 0, b = 0;
    int nowa = 0, nowb = 0;
    int count = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> a >> b;
        if (a == b)
        {
            count++;
        }
        else
        {
            count = 0;
        }

        if (count >= 3)
        {
            cout << "Yes";
            return;
        }
    }
    cout << "No";
}

Measured memory_bytes: 3644
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<ll>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int64_t gcd(int64_t a, int64_t b) {return b?gcd(b, a%b):a;}
int64_t lcm(int64_t a, int64_t b) {return a/gcd(a,b)*b;}
int64_t extgcd(int64_t a, int64_t b, int64_t &x, int64_t &y) { // ax+by=gcd(a, b)の解を与える
    int64_t d = a;
    if(b) {
        d = extgcd(b, a%b, y, x);
        y -= (a/b)*x;
    } else {
        x = 1; y = 0;
    }
    return d;
}

//Range Minimum Query
struct segment {
    int n;
    vector<int64_t> dat;
    // n_は範囲
    segment(int n_) { // nはn_以上の2^?
        n = 1<<(32-__builtin_clz(n_));
        if(n == 2*n_) n >>= 1;
        dat.assign(2*n-1, 0);
    }
    //更新の手順
    int64_t theorem(int i) {
        int64_t chld = dat[i*2+1];
        int64_t chrd = dat[i*2+2];
        return gcd(chld, chrd);
    }
    //初期化(初期状態はINT64_MAX)
    void init(const vector<int64_t> &vec) {
        int num = vec.size();
        rep(i, num) {
            dat[i+n-1] = vec[i];
        }
        rep(i, n-1) {
            dat[n-2-i] = theorem(n-2-i);
        }
    }
    // k番目の値をaに変更
    void update(int k, int64_t a) {
        // 葉の節点
        k += n-1;
        dat[k] = a;
        // 登りながら更新
        while(k>0) {
            k = (k-1)/2;
            dat[k] = theorem(k);
        }
    }
    // [a, b)の最小値
    int64_t query(int a, int b) {
        assert(a<b);
        return query_(a, b, 0, 0, n);
    }
    //kは節点の番号, [l, r)に節点が対応
    // (a, b, 0, 0, .n)で呼ぶ
    int64_t query_(int a, int b, int k, int l, int r) {
        if(a>=r || l>=b) return 0;
        if(a<=l && r<=b) return dat[k];
        else {
            int chl = k*2+1;
            int chr = k*2+2;
            int64_t vl = query_(a, b, chl, l, (l+r)/2);
            int64_t vr = query_(a, b, chr, (l+r)/2, r);
            return gcd(vr, vl);
        }
    }
};

int main() {
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) {
        cin >> a[i];
    }

    segment seg(n);
    seg.init(a);
    ll ans = 0;
    rep(i, n) {
        seg.update(i, 0);
        ans = max(ans, seg.query(0, n+1));
        seg.update(i, a[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int d;
    cin >> d;
    vi  c(26);
    REP(i, 26) cin >> c[i];
    vvl s(d, vl(26));
    int mx = 0;
    int mx_c = 0;
    REP(i, d) REP(j, 26) {
        cin >> s[i][j];
        if (chmax(mx, (int)s[i][j])) mx_c = j + 1;
    }

    vi last(26);
    ll ans = 0;
    vi a(d);
    REP(i, d) {
        ll ans2 = -LINF;
        ll ans_i = -1;
        REP(x, 26) {
            ll tmp = s[i][x];
            REP(j, 26) {
                if (x != j) tmp -= c[j] * ((i + 1) - last[j]);
            }
            if (chmax(ans2, tmp)) ans_i = x;
        }
        last[ans_i] = i + 1;
        ans += ans2;
        // cout << ans_i + 1 << endl;
        a[i] = ans_i + 1;
    }
    mt19937 mt{ random_device{}() };
    uniform_int_distribution<int> dist_d(1, d);
    uniform_int_distribution<int> dist_c(1, 26);
    REP(_, 200000) {
        vi lst(26);
        ll ans_n = 0;
        int x = dist_d(mt);
        int y = (_ % 10 == 0 ? mx_c : dist_c(mt));
        REP(i, d) {
            int t = a[i];
            if (x - 1 == i) t = y;
            ans_n += s[i][t - 1];
            lst[t - 1] = i + 1;
            REP(j, 26) if (t - 1 != j) ans_n -= c[j] * ((i + 1) - lst[j]);
        }

        if (ans_n > ans) {
            a[x - 1] = y;
            ans = ans_n;
        }
    }
    printlnv(a);
    // cout << ans << endl;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
#define _K ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ld long double
#define ll long long
#define ull unsigned ll
#define pb push_back
#define eps 1e-7
#define pi acos(-1)
#define F first
#define S second
#define X real()
#define Y imag()
#define cross(a,b) (conj(a)*(b)).X
#define dot(a,b) (conj(a)*(b)).Y
const int mod = 1e9+7 ;
typedef complex <ld> point ;
typedef vector <point> polygon ;
typedef tuple <int , int , int> line ;
//====================================
ll n , m ;
ll grid[1005][1005] ;
int main()
{
	_K
	cin >> n >> m ;
	char a[n][m] ;
	for (int i = 0 ; i < n ;  i++)
		for (int j = 0 ; j < m ; j++)
			cin >> a[i][j] ;
	grid[0][0] = 1 ;
	for (int i =0 ; i < n ; i++){
		for (int j =0 ; j < m ; j++)
		{
			if (a[i][j] == '#')
				continue ;
			if (i)
				grid[i][j] += grid[i-1][j] ;
			if (j)
				grid[i][j] += grid[i][j-1] ;

			grid[i][j] %= mod ;
		}
	}
	cout << grid[n-1][m-1] ;

	return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <ostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>

using namespace std;

int main()
{
    int n;
    int a[200010];
    int max;
    int ans = 0;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    max = a[0];

    for (int i = 0; i < n; i++) {
        if (max >= a[i]) {
            ans++;
            max = a[i];
        }
    }

    cout << ans << endl;

}


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

int main(void) {
	long int N, X, m[100] = { 0 };
	int ans = 0;
	int sum=0;
	cin >> N >> X ;
	for (int i = 0;i < N;i++) {
		cin >> m[i];
		sum += m[i];
		ans++;
	}
	sort(m,m+N);
	while (sum +m[0] <= X) {
		sum += m[0];
		ans++;
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
    ll n, m, l;
    cin >> n >> m >> l;
    ll res = m*l/gcd(m, l);
    rep(i, n-2) {
        ll a;
        cin >> a;
        res = res*a/gcd(res, a);
    }
    cout << res << endl;
}


Measured memory_bytes: 3112
package main

import (
	"fmt"
)

func main() {
	var a, b, k int
	fmt.Scanf("%d %d %d", &a, &b, &k)

	if a >= k {
		a -= k
	} else {
		k -= a
		a = 0
		if b >= k {
			b -= k
		} else {
			b = 0
		}
	}

	fmt.Printf("%d %d\n", a, b)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


int n, m;

void solve()
{
    cin >> n >> m;
    nout((n==m) ? "Yes" : "No");
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

class Program
{
    static readonly int H = 2, W = 4;
    Dictionary<int, int> Dic = new Dictionary<int, int>();

    void Solve()
    {
        BFS();
        string s;
        while (!string.IsNullOrEmpty(s = Console.ReadLine()))
        {
            int mask = 0;
            var A = Array.ConvertAll(s.Split(), int.Parse).ToArray();
            for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) Set(i, j, A[i * W + j], ref mask);
            Console.WriteLine(Dic[mask]);
        }
    }

    void BFS()
    {
        int mask = 0;
        for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) Set(i, j, i * W + j, ref mask);
        var que = new Queue<int>();
        que.Enqueue(mask);
        que.Enqueue(0);
        que.Enqueue(0);
        Dic[mask] = 0;

        while (que.Count > 0)
        {
            mask = que.Dequeue();
            int i = que.Dequeue();
            int j = que.Dequeue();
            for (int d = 0; d < di.Length; d++)
            {
                int ni = i + di[d], nj = j + dj[d];
                if (IsInside(ni, nj))
                {
                    int next = mask;
                    Set(i, j, Get(ni, nj, next), ref next);
                    Set(ni, nj, 0, ref next);
                    if (!Dic.ContainsKey(next))
                    {
                        Dic[next] = Dic[mask] + 1;
                        que.Enqueue(next);
                        que.Enqueue(ni);
                        que.Enqueue(nj);
                    }
                }
            }
        }
    }

    int Get(int i, int j, int mask)
    {
        return (mask >> (3 * (i * W + j))) & 7;
    }
    void Set(int i, int j, int num, ref int mask)
    {
        mask &= ~(7 << (3 * (i * W + j)));
        mask |= num << (3 * (i * W + j));
    }

    static readonly int[] di = { 0, 0, -1, 1 };
    static readonly int[] dj = { -1, 1, 0, 0 };
    bool IsInside(int i, int j)
    {
        return i >= 0 && i < H && j >= 0 && j < W;
    }

    static void Main()
    {
        new Program().Solve();
    }
}

Measured memory_bytes: 22080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

set<int> p[128];

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

    int u;
    cin >> u;
    string s;
    cin >> s;

    for (int i = 0; i < s.length(); i++) {
        p[s[i] - '0'].insert(i);
    }

    int ans = 0;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            for (int k = 0; k < 10; k++) {
                auto p1 = p[i].upper_bound(-1);
                if (p1 == p[i].end())
                    continue;
                auto p2 = p[j].upper_bound(*p1);
                if (p2 == p[j].end())
                    continue;
                auto p3 = p[k].upper_bound(*p2);
                if (p3 == p[k].end())
                    continue;
                ans++;
            }
        }
    }
    cout << ans << endl;
}

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

int main(){
  long long a,b,c;
  cin >> a >> b >> c;
  if(a%2==0||b%2==0||c%2==0)cout << 0 << endl;
  else cout << min(a,min(b,c))*(a+b+c-max(a,max(b,c))-min(a,min(b,c)))<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define int long long
#define elif else if
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
signed main(){
  int n, k;
  cin >> n >> k;
  int h[n];
  rep(i, 0, n){
    cin >> h[i];
  }
  sort(h, h + n);
  rep(i, 0, k){
    h[n - 1 - i] = 0;
  }
  int sm = 0;
  rep(i, 0, n){
    sm += h[i];
  }
  cout << sm << "\n";
}
 

Measured memory_bytes: 5192
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

ans = []
for i, a in enumerate(A, start=1):
    ans.extend([i] * a)
ans.sort()

for i, w in enumerate(range(0, H * W, W)):
    print(*ans[w: w + W][::(-1)**i])


Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;


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

  int a, b;
  cin >> a >> b;

  int d = b - a;
  int l = ((1 + d) * d) / 2;
  cout << l - b << endl;
  
  return 0;
}


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

using namespace std; 
 
map<char, int> c2i;
map<int, char> i2c;
string str;
 
void init()
{
    for (char ch = 'a'; ch <= 'z'; ch++) {
	c2i[ch] = ch - 'a';
	i2c[ch - 'a'] = ch;
    }
}
 
bool serch(string s)
{
    string str;
    stringstream ss(s);
    while (ss >> str) {
        if (str == "this" || str == "that") {
            return 1;
        }
    }
    return 0;
}
 
char F(char ch, int a, int b)
{
    int num = (a * c2i[ch] + b) % 26; 
    return i2c[num];
}
 
int main()
{
    int n;
    init(); 
    cin >> n;
    cin.ignore();
    while (n--) {
	getline(cin, str);
 
	for (int i = 0; i < 26; i++) {
	    for (int j = 0; j < 26; j++) {
		string next;
		for (int k = 0; k < (int)str.size(); k++) {
		    if (islower(str[k])) {
                        next += F(str[k], i, j);
		    } else {
                        next += str[k];
                    }
                }
		if (serch(next)) {
		    cout << next << endl;
                    goto END;
		}
	    }
	}
        END:;
    }
    return 0;
}

Measured memory_bytes: 3004
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int N, K;
  cin >> N >> K;
  
  if (K >= N) {
    cout << 0 << endl;
    return 0;
  }
  
  vector<ll> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  
  sort(H.begin(), H.end());
  
  ll ans = 0LL;
  for (int i = 0; i < N - K; i++) {
    ans += H.at(i);
  }
  
  cout << ans << endl;
  
  return 0;
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if((a==b || a==c || b==c ) && !(a==b && a==c)){
  cout << "Yes" << endl;
  }
  else{
  cout << "No" << endl;
  }
}  

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

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in(),W=in();
	vll v(N),w(N);
	REP(i,N){
		v[i]=in(),w[i]=in();
	}
	vvll dp(N+1,vll(W+1,0));

	REP(i,N){
		REP(j,W+1){
			chmax(dp[i+1][j],dp[i][j]);
			if(j+w[i]<=W) chmax(dp[i+1][j+w[i]],dp[i][j]+v[i]);
		}
	}

	out(dp[N][W]);
	return 0;
}



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

using namespace std;

int main(void){
	unsigned int N;
	scanf("%d", &N);
	unsigned int A[N], order[N];

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

	for(int i=0; i<N; i++){
		printf("%d ", order[i]);
	
	}

	return 0;
}


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

#define M_PI 3.141592653589793

int main(void) {

	int i, n;
	int num;

	scanf("%d", &n);

	for (i = 1; i <= n; i++) {
		if (i % 3 == 0) {
			printf(" %d", i);
		}
		else {
			num = i;
			while (1) {
				if (num % 10 == 3) {
					printf(" %d", i);
					break;
				}
				num = num / 10;
				if (num == 0) {
					break;
				}
			}
		}
	}
	printf("\n");

	return 0;

}

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

int main(){

string s; cin>>s;
  int sum = 0 , n = s.length();
  for(int i=0; i<n; i++)
  {
    sum += (s[i]-'0');
  }
  
  if(sum%9) cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;

}


Measured memory_bytes: 3692
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair

int read()
{
    int v = 0, f = 1;
    char c = getchar();
    while (c < 48 || 57 < c) {if (c == '-') f = -1; c = getchar();}
    while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
    return v * f;
}

const int N = 2e3 + 10;
const int INF = 2e9;

int n, a[N], vis[N];
VI V[N], E[N];

bool cmp(int i, int j)
{
    return a[i] < a[j];
}

VI merge(const VI &a, const VI &b)
{
    int i = 0, j = 0;
    VI re;
    while (i < a.size() && j < b.size())
        if (a[i] > b[j])
            re.push_back(a[i++]);
        else
            re.push_back(b[j++]);
    while (i < a.size())
        re.push_back(a[i++]);
    while (j < b.size())
        re.push_back(b[j++]);
    return re;
}

void dfs(int u)
{
    vis[u] = 1;
    V[u].push_back(INF);
    for (int e = 0; e < E[u].size(); e++)
    {
        int v = E[u][e];
        if (vis[v]) continue;
        dfs(v);
        V[u] = merge(V[u], V[v]);
    }
    V[u][0] = a[u];
}

int main()
{
    n = read();
    for (int i = 1; i <= n; i++) a[i] = read();
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++)
            if (__gcd(a[i], a[j]) > 1)
            {
                E[i].push_back(j);
                E[j].push_back(i);
            }
    for (int i = 1; i <= n; i++)
        E[0].push_back(i);
    for (int i = 0; i <= n; i++)
        sort(E[i].begin(), E[i].end(), cmp);
    dfs(0);
    for (int i = 1; i <= n; i++)
        printf("%d ", V[0][i]);
    puts("");
}


Measured memory_bytes: 27136
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e10+10;

/*----------------------------------------------*/

signed main(){
  int n,k;
  cin>>n>>k;
  vi x(n);
  rep(i,n) cin>>x[i];
  int ans=INF;
  rep(i,n-k+1){
    int l=i,r=i+k-1;
    chmin(ans,abs(x[l])+abs(x[l]-x[r]));
    chmin(ans,abs(x[r])+abs(x[l]-x[r]));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second

int main(){
    int N;
    cin >> N;
    vector<pair<double, string>> xu(N);
    for(int i = 0; i < N; i++) cin >> xu[i].fi >> xu[i].se;
    double sum = 0;
    for(int i = 0; i < N; i++){
        if(xu[i].se == "BTC") sum += xu[i].fi * 380000.0;
        else sum += xu[i].fi;
    }
    cout << sum << setprecision(8) << endl;
}


Measured memory_bytes: 3824
n=int(input())
p=[2]
for i in range(3,n+1,2):
    for j in range(3,int(i**0.5)+1,2):
        if i%j==0:break
    else:p.append(i)
l=[0]*len(p)
for i in range(1,n+1):
    while i!=1:
        for j,k in enumerate(p):
            if i%k==0:
                l[j]+=1
                i//=k
ans=1
for i in l:ans=ans*(i+1)%(10**9+7)
print(ans)

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int t[105];

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>n;
	c=0;
	for(i=0;i<n;i++){
		cin>>t[i];
		c+=t[i];
	}
	cin>>m;
	for(i=0;i<m;i++){
		cin>>a>>b;
		cout<<c-t[a-1]+b<<endl;
	}
}

Measured memory_bytes: 256
import java.io.*;

public class Main {
    public static void main(String[] args) {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        try {
            String[] str = br.readLine().split(" ");
            int a = Integer.parseInt(str[0]);
            int b = Integer.parseInt(str[1]);
            System.out.println(a * b + " " + (a + b) * 2);
        } catch(IOException e) {
            e.printStackTrace();
        }
    }
}

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

using namespace std;

int main() {
	int n, m;
	string A[105];
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++) {
		string str;
		cin >> str;
		A[i] = str;
	}
	sort(A, A + n);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cout << A[i][j];
	putchar('\n');
	return 0;
}

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.sync_with_stdio(false); cin.tie(0);
	cin.exceptions(cin.failbit);

	ll n; cin >> n;
	string s = to_string(n);

	fill(s.begin(), s.end(), '9');

	int maxsum = 0;
	for (int i = 0; i < s.length(); i++) {
		for (char d = '0'; d <= '9'; d++) {
			s[i] = d;
			if (stoll(s) <= n) {
				int sum = 0;
				for (char c : s) sum += c - '0';
				maxsum = max(maxsum, sum);
			}
		}
	}
	cout << maxsum << endl;
}


Measured memory_bytes: 256