akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll memo[100005];
vector<int>vec[100005];
ll solve(int idx)
{
    if(vec[idx].size()==0) return 0;
    if(memo[idx]!=-1) return memo[idx];
    ll ret=1;
    for(int i=0;i<vec[idx].size();i++)
    {
        ret=max(ret,1+solve(vec[idx][i]));
    }
    
    return memo[idx]=ret;
}
int main()
{
    memset(memo,-1,sizeof(memo));
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        vec[u].push_back(v);
    }
    ll ans=1;
    for(int i=1;i<=100000;i++)
    {
        ans=max(ans,solve(i));
    }
    
    
    printf("%lld\n",ans);
}


Measured memory_bytes: 8576
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)



        
def main(): #startline--------------------------------------------
    n = int(input())
    abc = [list(map(int,input().split())) for i in range(n)]

    dp = [[0]*3 for i in range(n+1)]
    for i in range(n):
        for j in range(3):
            for k in range(3):
                if j == k:continue
                dp[i+1][j] = max(dp[i+1][j],dp[i][k]+abc[i][j])

    print(max(dp[n]))
if __name__ == "__main__":
    main() #endline===============================================
    

Measured memory_bytes: 95320
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin >>n;
  int a;
  int cnta=0;
  double cntb=0;
  rep(i,n){
    cin >> a;
    if(a%4==0){
      cnta++;
    }
    else if(a%2==0){
      cntb+=0.5;
    }
  }
  if((n/2)<=cnta+cntb){
    cout << "Yes" <<endl;
    return 0;
  }
  cout << "No" <<endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
m = a = r = c = h = 0
for i in range(n):
    temp = input()[0]
    if temp == "M":
        m += 1
    if temp == "A":
        a += 1
    if temp == "C":
        c += 1
    if temp == "R":
        r += 1
    if temp == "H":
        h += 1

sum = m*a*r + m*a*c + m*a*h + + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h

print(sum)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  string a,b,c;
  cin>>a>>b>>c;
  printf("%c%c%c\n",a[0]-('a'-'A'),b[0]-('a'-'A'),c[0]-('a'-'A'));
}
	


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

//variable
double a = 0 ; //length a
double b = 0 ; //length b
double c = 0 ; //length c
double D = 0 ; //degree
double R = 0 ; //radian
double S = 0 ; //area of triangle
double L = 0 ; //length of the lap
double h = 0 ; //height

int main()
{
    cin >> a >> b >> D ;

    R = D * M_PI / 180.0 ;
    c = sqrt( pow( a ,2 ) + pow( b ,2 ) - ( ( 2 * a * b ) * cos( R ) ) ) ;
    L = a + b + c ;
    h = b * sin( R ) ;
    S = ( 1.0 / 2.0 ) * a * h ;

    cout << fixed << setprecision(5) << S << endl << L << endl << h << endl ;
    return 0 ;
}

Measured memory_bytes: 3660
N, M =list(map(int, input().split()))
H = [0] + list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(M)]

is_good = [1 for i in range(N+1)]
for i in range(M):
  a,b = AB[i]
  if H[a] >= H[b]:
    is_good[b] = 0
  if H[a] <= H[b]:
    is_good[a] = 0

cnt = 0
for i in range(1, N+1):
  if is_good[i] == 1:
    cnt+=1
print(cnt)

Measured memory_bytes: 31940
#include <iostream>

using namespace std;

int main(void)
{
    int r, c;
    int **tbl;

    cin >> r >> c;

    tbl = new int*[r+1];
    for (int i=0; i<=r; i++)
        tbl[i] = new int[c+1];
    
    for (int i=0; i<r; i++) {
        for (int j=0; j<c; j++) {
            cin >> tbl[i][j];
            tbl[r][j] += tbl[i][j];
            tbl[i][c] += tbl[i][j];
            tbl[r][c] += tbl[i][j];
         }
     }

     for (int i=0; i<=r; i++) {
        for (int j=0; j<c; j++) {
            cout << tbl[i][j] << " ";
        }
        cout << tbl[i][c] << endl;;
     }
}


Measured memory_bytes: 3104
/*
lakshaygpt28
Lakshay Gupta
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
using vll = vector < ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;


#ifndef ONLINE_JUDGE
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif

#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

ll a[N], b[N];

int main() {
    fast_io();
    ll n;
    cin >> n;
    for (ll i = 0; i <= n; i++) {
        cin >> a[i];
    }
    for (ll i = 0; i < n; i++) {
        cin >> b[i];
    }
    ll ans = 0;
    for (ll i = n - 1; i >= 0; i--) {
        ll x = min(b[i], a[i + 1]);
        b[i] -= x;
        ll y = min(b[i], a[i]);
        a[i] -= y;
        ans += (x + y);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N,K;
	cin >> N >> K;
	if(K == 1) cout << 0 << endl;
	else cout << N-K << endl;
}


Measured memory_bytes: 256
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

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

int main()
{
    string a[2];
    rep(i, 2)
    {
        cin >> a[i];
    }

    rep(i, 2)
    {
        if (!(a[i][0] == a[(i + 1) % 2][2] && a[i][1] == a[(i + 1) % 2][1] &&
              a[i][2] == a[(i + 1) % 2][0]))
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

ll mx = 0;
vector<ll> a;
vector<ll> res;
void sieve(){
    for(auto e : a){
        if(res[e]) continue;
        for(ll i = e * 2; i <= mx; i += e){
            if(!res[i]) res[i] = e;
        }
    }
}


int main(){
    ll n; cin >> n;
    map<ll, ll> ma;
    vector<ll> b;
    a.resize(n);
    rep(i,n) {
        cin >> a[i];
        mx = max(mx, a[i]);
        ma[a[i]]++;
    }
    for(auto p : ma){
        if(p.second != 1) continue;
        b.push_back(p.first);
    }
    sort(ALL(a));
    res.assign(mx+1, 0);
    /*
    for(auto e : a) cout << e << " ";
    cout << endl;
    for(auto e : b) cout << e << " ";
    cout << endl;
    */
    sieve();
    ll cnt = 0;
    for(auto e : b){
        if(!res[e]) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 26560
#include<bits/stdc++.h>
#define MOD 1000000007
#define md 998244353
#define INF LLONG_MAX
#define F first
#define S second
#define sz(x) (long long)x.size()
#define vi vector<int>
#define vll vector<long long>
#define vpl vector<pair<long long,long long> >
#define vpi vector<pair<int,int> >
#define pb push_back
#define debug(x) cerr<<#x<<"= "<<x<<endl
#define all(v) v.begin(),v.end()
#define TT ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define endl '\n'
#define MAXN 200005
typedef long long ll;
typedef long double ld;
using namespace std;
vi adj[MAXN];
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n;
    cin>>n;
    for(ll i=2;i<=n;i++){
        ll x;cin>>x;
        adj[x].pb(i);
    }
    for(ll i=1;i<=n;i++){
        cout<<(sz(adj[i]))<<endl;
    }



    return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

ll mod=1e9+7;
ll dp1[100010],dp2[100010];


int main()
{
    string l;
    cin>>l;
    m0(dp1);//kakutei
    m0(dp2);//mikakutei
    dp2[0]=1;
    for (int i = 0; i < l.size(); i++)
    {
        if(l[i]=='0')
        {
            dp1[i+1]=dp1[i]*3;
            dp2[i+1]=dp2[i];

        }
        else //1
        {
            dp1[i+1]=dp1[i]*3+dp2[i];
            dp2[i+1]=dp2[i]*2;
        }
        dp1[i+1]%=mod;
        dp2[i+1]%=mod;
    }
    cout<<(dp1[l.size()]+dp2[l.size()])%mod<<endl;

    return 0;
}

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

int main()
{
    int n;
    long long k;
    cin>>n>>k;
    vector<int>arr;
    vector<int>frr;
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        arr.push_back(a);
    }
     for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        frr.push_back(a);
    }

    sort(arr.begin(),arr.end());
    reverse(arr.begin(),arr.end());
    sort(frr.begin(),frr.end());

    long long lower = -1;
    long long upper = 1000000000000;

    while(lower+1<upper)
    {
        long long team_score = (lower+upper)/2;
        long long t = 0;
        for(int i=0;i<n;i++)
        {
            long long ai = team_score/frr[i];
            long long train = max(0LL,arr[i]-ai);
            t+=train;
        }
        if(t<=k)upper = team_score;
        else lower = team_score;
    }

    cout<<upper<<endl;

}


Measured memory_bytes: 2548
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <utility>
#include <string>
#include <queue>

using namespace std;

typedef unsigned long long ll;

ll n, k, a[200000], f[200000],r[200000];

bool possible(ll t) {
	ll s = 0;
	for (ll i = 0; i < n; i++) {
		if (a[i] * f[i] > t) {
			s += a[i] - (t / f[i]);
		}
	}
	return s <= k;
}

int main() {	
	cin >> n >> k;
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (ll i = 0; i < n; i++) {
		cin >> f[i];
	}
	sort(a, a+n);
	sort(f, f + n,greater<>());
	for (ll i = 0; i < n; i++) {
		r[i] = f[i] * a[i];
	}
	ll r = 0, l = 10000000000000000000;
	while (r != l) {
		ll m = (r + l) / 2;
		if (possible(m)) l = m;
		else r = m + 1;
	}
	cout << r << endl;
}

Measured memory_bytes: 4992
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10 ** 9 +7

n = int(readline())
a = np.array(read().split(),np.int32)

q=np.minimum.accumulate(a)

answer = np.count_nonzero(a<=q)

print(answer)

Measured memory_bytes: 22764
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n1,m1,n2,m2;
	cin>>n1>>m1;
	cin>>n2>>m2;
	vector<int>v{4,6,9,11};
	vector<int>x{1,3,5,7,8,12,10};
	int count=0;
	for(int i=0;i<v.size();i++){
		if(v.at(i)==n1){
			count=1;
		}
	}
	for(int i=0;i<x.size();i++){
		if(x.at(i)==n1){
			count=2;
		}
	}
	if(count==0 && m1==28){
		cout<<1<<"\n";
		
	}else if(count==1){
		if(m1==30){
			cout<<1<<"\n";
		}else{
			cout<<0<<"\n";
		}
	}else if(count==2){
		if(m1==31){
			cout<<1<<"\n";
		}else{
			cout<<0<<"\n";
		}
	}else{
		cout<<0<<"\n";
	}
	



	


 
	
	
	
	
	return 0;
}

Measured memory_bytes: 3596
#!/usr/bin/env run-cargo-script

#![allow(unused_imports)]

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::fmt;
use std::io::{self, BufWriter, Read, StdinLock, Write};
use std::ops::{Add, Div, Mul, Sub};
use std::str::{self, FromStr};

fn solve(m: u32) -> u32 {
    48 - m
}

fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock().bytes());
    println!("{}", solve(sc.next()));
}

struct Scanner<R: Read> {
    buf: Vec<u8>,
    bytes: io::Bytes<R>,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(bytes: io::Bytes<R>) -> Self {
        Scanner {
            buf: Vec::with_capacity(1024),
            bytes: bytes,
        }
    }

    fn next<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: fmt::Debug,
    {
        let buf = &mut self.buf;
        buf.clear();
        self.bytes
            .by_ref()
            .map(Result::unwrap)
            .skip_while(|&c| c == ' ' as u8 || c == '\n' as u8)
            .take_while(|&c| !(c == ' ' as u8 || c == '\n' as u8))
            .foreach(|c| buf.push(c));
        str::from_utf8(&buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        <T as FromStr>::Err: fmt::Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<T1: FromStr, T2: FromStr>(&mut self, n: usize) -> Vec<(T1, T2)>
    where
        <T1 as FromStr>::Err: fmt::Debug,
        <T2 as FromStr>::Err: fmt::Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<T1: FromStr, T2: FromStr, T3: FromStr>(&mut self, n: usize) -> Vec<(T1, T2, T3)>
    where
        <T1 as FromStr>::Err: fmt::Debug,
        <T2 as FromStr>::Err: fmt::Debug,
        <T3 as FromStr>::Err: fmt::Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        <T as FromStr>::Err: fmt::Debug,
    {
        (0..m).map(|_| self.vec(n)).collect()
    }

    fn strings_as_mat<T, F: FnMut(u8) -> T>(&mut self, h: usize, mut f: F) -> Vec<Vec<T>> {
        (0..h)
            .map(|_| {
                self.bytes
                    .by_ref()
                    .map(Result::unwrap)
                    .skip_while(|&c| c == ' ' as u8 || c == '\n' as u8)
                    .take_while(|&c| !(c == ' ' as u8 || c == '\n' as u8))
                    .map(&mut f)
                    .collect()
            })
            .collect()
    }
}

trait Foreach {
    type Item;
    fn foreach<F: FnMut(Self::Item)>(self, f: F);
}

impl<T, I: Iterator<Item = T>> Foreach for I {
    type Item = T;

    fn foreach<F: FnMut(T)>(self, mut f: F) {
        self.fold((), move |(), x| f(x));
    }
}


Measured memory_bytes: 4352
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n,k,a[100001];
ll count_t[50];

string a_s[100001];
ll riso[50];

int main() {
    
    std::cin >> n>>k;
    string k_s;
    std::stringstream ss;
    ss << std::bitset<50>(k);
    k_s = ss.str();
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        std::stringstream ss;
        ss << std::bitset<50>(a[i]);
        a_s[i] = ss.str();
        // std::cout <<ss.str() << std::endl;
        for (int j = 0; j < 50; j++) {
            // std::cout << i<<" "<<j << std::endl;
            // std::cout << a_s[i][49-j] << std::endl;
            if(a_s[i][49-j] == '1'){
                count_t[j]++;
            }
        }
    }
    
    for (int i = 0; i < 50; i++) {
        if( count_t[i] <= (n-1)/2 ){
            riso[i] = 1;
        }else{
            riso[i] = 0;
        }
        // std::cout << count_t[i]<<"riso "<<i<<" "<<riso[i] << std::endl;
    }
    
    // for (int i = 49; i >= 0; i--) {
    //     std::cout << riso[i];
    // }
    // // std::cout << std::endl;
    
    // std::cout << "kは" << std::endl;
    
    // for (int i = 0; i < 50; i++) {
    //     std::cout << k_s[i];
    // }
    // std::cout << std::endl;
    
    // K以下チェック
    for (int i = 49; i >= 0; i--) {
        // std::cout << "k以下 "<<i << std::endl;
        if(k_s[49-i] == '0' && riso[i] == 0){
            continue;
        }else if(k_s[49-i] == '1' && riso[i] == 1){
            continue;
        }else if(k_s[49-i] == '1' && riso[i] == 0){
            break;
        }else if(k_s[49-i] == '0' && riso[i] == 1){
            riso[i] = 0;
            // std::cout << "i"<<i << std::endl;
        }
    }
    
    // for (int i = 49; i >= 0; i--) {
    //     std::cout << riso[i];
    // }
    // std::cout << std::endl;

    
    ll result = 0;
    for (int i = 0; i < 50; i++) {
        if(riso[i] == 0){
            result += count_t[i] * (ll)pow(2,i);
        }else{
            result += (n - count_t[i])* (ll)pow(2,i);
        }
        // std::cout << "count_t " <<count_t[i]  << std::endl;
        // std::cout << i<<" "<<result << std::endl;
    }
    std::cout << result << std::endl;
    
}

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

int main(){
    int N;
    int cc, t, res;
    scanf("%d", &N);
    res=N;

    for(int i=0; i<=N; i++){
        cc = 0;
        t = i;
        while(t>0){
            cc+=t%6;
            t=t/6;
        }
        t=N-i;
        while(t>0){
            cc+=t%9;
            t=t/9;
        }
        if(res>cc){
            res=cc;
        }
    }
    printf("%d", res);
    return 0;
}


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

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Integer[] input = new Integer[N];
		for (int i = 0; i < N; i++) {
			input[i] = sc.nextInt();
		}
		Arrays.asList(input).sort((x, y) -> x - y);
		int tmp = input[0];
		boolean res = true;
		for (int i = 1; i < N; i++) {
			if (tmp == input[i]) {
				res = false;
				break;
			}
			tmp = input[i];
		}
		if (res) {
			System.out.print("YES");
		} else {
			System.out.print("NO");
		}
	}
}

Measured memory_bytes: 94164
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define se second
#define fi first
#define mp make_pair
#define pii pair<int,int>
const int N=150005;
int ne[N],tot,fi[N],zz[N],n,x,y,mid,sl[N];
void jb(int x,int y,int z){
	ne[++tot]=fi[x];
	fi[x]=tot;
	zz[tot]=y;
	sl[tot]=z;
}
int cmp1(pii x,pii y){
	return x.se<y.se;
}
int cmp2(pii x,pii y){
	return x.fi>y.fi;
}
int cmp3(pii x,pii y){
	return x.fi<y.fi;
}
int cmp4(pii x,pii y){
	return x.se>y.se;
}
vector<pii> dfs(int x){
	vector<pii> ans;
	if (!fi[x]){
		ans.push_back(mp(0,0));
		return ans;
	}
	vector<pii> ls=dfs(zz[fi[x]]),rs=dfs(zz[ne[fi[x]]]);
	int v1=sl[fi[x]],v2=sl[ne[fi[x]]];
	if (ls.size()>rs.size())swap(ls,rs),swap(v1,v2);
	sort(ls.begin(),ls.end(),cmp1);
	sort(rs.begin(),rs.end(),cmp2);
	int now=0;
	for (pii i:ls){
		while (now<(int)rs.size()&&i.se+rs[now].fi+v1+v2>mid)now++;
		if (now<(int)rs.size())ans.push_back(mp(i.fi+v1,rs[now].se+v2));
	}
	sort(ls.begin(),ls.end(),cmp3);
	sort(rs.begin(),rs.end(),cmp4);
	now=0;
	for (pii i:ls){
		while (now<(int)rs.size()&&i.fi+rs[now].se+v1+v2>mid)now++;
		if (now<(int)rs.size())ans.push_back(mp(rs[now].fi+v2,i.se+v1));
	}
	sort(ans.begin(),ans.end());
	vector<pii >Ans;
	if (ans.size())Ans.push_back(ans[0]);
	for (int i=1;i<ans.size();i++)
		if (Ans[Ans.size()-1].se>ans[i].se)Ans.push_back(ans[i]);
	return Ans;
}
signed main(){
	scanf("%lld",&n);
	for (int i=2;i<=n;i++){
		scanf("%lld%lld",&x,&y);
		jb(x,i,y);
	}
	int l=0,r=1e12;
	while (l<r){
		mid=(l+r)/2;
		vector<pii> f=dfs(1);
		if (!f.empty())r=mid;
		else l=mid+1;
	}
	printf("%lld\n",l);
}


Measured memory_bytes: 17920
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}
ll dx[2]={1,0};
ll dy[2]={0,1};

int main(){
    IOS;
    make(string,s);
    ll n=s.length();
    ll ans=0;
    ll c=0;
    for(ll i=0;i<n;i++){
        if(s[i]=='B') c++;
        else ans+=c;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3764
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
//#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}

void func(void)
{
//DEBUG_OUT("----\n");
    int H, W;
    cin >> H >> W;
    vector<string> S(H+2);
    S[0] = ""; S[H+1] = "";
    for(int i=0; i<W+2; i++){
        S[0] += "."; S[H+1] += ".";
    }
    for(int i=1; i<=H; i++){
        string s;
        cin >> s;
        S[i] = "." + s + ".";
    }

    vector<string> ans(H);
    for(int i=0; i<H; i++){
        ans[i] = "";
        for(int j=0; j<W; j++){
            ans[i] += "#";
        }
    }

    for(int h=1; h<H+1; h++){
        for(int w=1; w<W+1; w++){
            if(S[h][w] == '.'){
                int bombs = 0;
                if(S[h-1][w-1] == '#') bombs++;
                if(S[h-1][w-0] == '#') bombs++;
                if(S[h-1][w+1] == '#') bombs++;
                if(S[h-0][w-1] == '#') bombs++;
                //if(S[h-0][w-0] == '#') bombs++;
                if(S[h-0][w+1] == '#') bombs++;
                if(S[h+1][w-1] == '#') bombs++;
                if(S[h+1][w-0] == '#') bombs++;
                if(S[h+1][w+1] == '#') bombs++;
                ans[h-1][w-1] = '0'+bombs;
            }
        }
    }

    DEBUG_OUT("----\n");

    for(int i=0; i<H; i++){
        cout << ans[i] << endl;
    }

    return;
}



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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;

    vector<vector<int>> reward(m);
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        if (a < m) reward[a].push_back(b);
    }

    int ans = 0;
    priority_queue<int> pq;
    for (int i = 0; i < m; ++i) {
        for (int b : reward[i]) {
            pq.push(b);
        }
        if (!pq.empty()) {
            ans += pq.top();
            pq.pop();
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5632
N=int(input())
S=input()
whites=[0]*(N+1)
whites[0]=1
curwhi=1
for k,i in enumerate(S):
    if i==".":
        curwhi+=1
    whites[k+1]=curwhi
curmin=1000000
allwhi=whites[N]
for k,w in enumerate(whites):#k個目まで白
    new=k+1+allwhi-2*w
    curmin=min(new,curmin)
print(curmin)

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

int main() {
	int N;
	long long A, B, count = 0, MIN = 1145141919810364364;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A >> B;
		count += A;
		if (A > B) MIN = min(MIN, B);
	}
	cout << max((long long)0, count - MIN);
}

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

class Procon {
    public Procon () { }
    static void Main (string[] agrs) {
        new Procon ().Do ();
    }

    Scanner cin;

    public void Do () {
        cin = new Scanner ();

        int N = cin.nextInt ();

        Dictionary<string, long> dict = new Dictionary<string, long> ();

        for (int i = 0; i < N; i++) {
            string s = cin.nextString ();

            var c = s.ToCharArray ();

            Array.Sort (c);

            string s2 = new String (c);
            if (dict.ContainsKey (s2)) {
                dict[s2]++;
            } else {
                dict[s2] = 1;
            }
        }

        long[] num = dict.Values.ToArray ();

        long ans = 0;
        for (int i = 0; i < num.Length; i++) {
            ans += (num[i] * (num[i] - 1)) / 2;
        }
        Console.WriteLine (ans);
    }
}

class Scanner {
    string[] s;
    int i;
    int max_i;

    public Scanner () {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString () {
        if (i >= s.Length) {
            s = Console.ReadLine ().Split (' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0) {
                return "";
            }
            return s[i++];
        } else {
            return s[i++];
        }
    }

    public int nextInt () {
        return int.Parse (nextString ());
    }

    public long nextLong () {
        return long.Parse (nextString ());
    }

    public double nextDouble () {
        return double.Parse (nextString ());
    }

    public string[] arrayString () {
        return Console.ReadLine ().Split (' ');
    }

    public int[] arrayInt () {
        string[] str = Console.ReadLine ().Split (' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++) {
            array[i] = int.Parse (str[i]);
        }
        return array;
    }

    public long[] arrayLong () {
        string[] str = Console.ReadLine ().Split (' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++) {
            array[i] = long.Parse (str[i]);
        }
        return array;
    }

    public double[] arrayDouble () {
        string[] str = Console.ReadLine ().Split (' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++) {
            array[i] = double.Parse (str[i]);
        }
        return array;
    }
}

Measured memory_bytes: 30660
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	string S;
	while(cin >> S) {
		int cnt[128] = {};
		for(char c : S) {
			++ cnt[c];
		}
		bool ans =
			(cnt['N'] != 0) == (cnt['S'] != 0) &&
			(cnt['E'] != 0) == (cnt['W'] != 0);
		puts(ans ? "Yes" : "No");
	}
	return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<cstdio>
int main()
{
    int r;
    scanf("%d",&r);
    if(r < 1200)
        printf("ABC\n");
    else if(r>=1200 && r<2800)
        printf("ARC\n");
    else if(r >= 2800)
        printf("AGC\n");
    return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
txy = [LIST() for _ in range(N)]
txy.insert(0, [0, 0, 0])

for i in range(1, N+1):
	dt = txy[i][0] - txy[i-1][0]
	dx = abs(txy[i][1] - txy[i-1][1])
	dy = abs(txy[i][2] - txy[i-1][2])
	if dt%2 == (dx+dy)%2 and dt >= dx+dy:
		continue
	else:
		print("No")
		break
else:
	print("Yes")

Measured memory_bytes: 29408
#include<bits/stdc++.h>
#define N 101
using namespace std;
typedef long long ll;
ll n,p[N],q[N],r[N],b[N];
bool s[N];
 
ll func(int x){
  ll R=1,B=1;
  if(r[x]) R=func(r[x]);
  if(b[x]) B=func(b[x]);
  ll k=__gcd(R*p[x],B*q[x]);
  ll a=(R*p[x])/k,e=(B*q[x])/k;
  return (R*e)+(B*a);
}
 
int main(){
  while(cin>>n,n){
    memset(s,0,sizeof(s));
    for(int i=1;i<=n;i++){
      cin>>p[i]>>q[i]>>r[i]>>b[i];
      ll res=__gcd(p[i],q[i]);
      p[i]/=res,q[i]/=res;
      s[r[i]]=s[b[i]]=true;
    }
    for(int i=1;i<=n;i++)
      if(!s[i])cout<<func(i)<<endl;
  }
  return 0;
}

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int a, b;
    cin >> a >> b;
    if (a > b)
    {
        rep(i, a)
        {
            cout << b;
        }
    }
    else
    {
        rep(i, b)
        {
            cout << a;
        }
    }
    ed;
    return 0;
}

Measured memory_bytes: 256
#ifndef __clang__
#include <bits/stdc++.h>
#endif
using namespace std;
const long long MOD = static_cast<int>(1e9) + 7;
//{{{TEMPLATE_BEGIN
#include <unistd.h>
using namespace std::rel_ops;
typedef long long lint;
typedef unsigned long long ulint;
typedef long double ldouble;
typedef vector<int> vint;
#define rep(i, n)                                                              \
    for (int i = 0, i##_len = static_cast<int>(n); i < i##_len; i++)
#define all(c) begin(c), end(c)
#define perm(c)                                                                \
    sort(all(c));                                                              \
for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))
#define uniquenize(v) (v).erase(unique(all(v)), end(v))
#define cauto const auto &
#define memset(x, y) memset(x, y, sizeof(x))
#define popcount __builtin_popcount
#define gcd __gcd
inline lint bit(int x) {
    return 1LL << x;
}
template <class T>
inline int size(const T &a) {
    return (int)a.size();
}
template <class T>
inline bool chmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}
template <class T>
inline int clamp(T v, T lo, T hi) {
    return (v > hi) - (v < lo);
}
template <class T>
inline bool chmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}
template <class T>
inline pair<vector<T>, char> operator*(const vector<T> &v, const char &c) {
    return make_pair(v, c);
}
template <class T>
inline istream &operator>>(istream &is, vector<T> &v) {
#ifdef ZEROKUGI
    if (v.empty()) {
        cerr << "Error L" << __LINE__ << ": vector size is zero." << endl;
        exit(EXIT_FAILURE);
    }
#endif
    for (auto &x : v)
        is >> x;
    return is;
}
template <class T>
inline ostream &operator<<(ostream &os, const pair<vector<T>, char> &v) {
    bool t = 0;
    for (const T &x : v.first) {
        if (t)
            os << v.second;
        os << x;
        t = 1;
    }
    return os;
}
template <class T>
inline ostream &operator<<(ostream &os, vector<T> &v) {
    return os << v * ' ';
}
struct before_main {
    before_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} __before_main;
//}}}TEMPLATE_END

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int ans = 0;

    int d = min(b, c);
    b -= d;
    c -= d;

    int e = min(a, c);
    a -= e;
    c -= e;

    if(c > 0) e++;
    cout << 2 * d + e + b << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	// Code for C - Back and Forth
	var sx, sy, tx, ty int
	fmt.Scan(&sx, &sy, &tx, &ty)

	var ans string
	ans += strings.Repeat("U", ty-sy)
	ans += strings.Repeat("R", tx-sx)
	ans += strings.Repeat("D", ty-sy)
	ans += strings.Repeat("L", tx-sx+1)
	ans += strings.Repeat("U", ty-sy+1)
	ans += strings.Repeat("R", tx-sx+1)
	ans += "D"
	ans += "R"
	ans += strings.Repeat("D", ty-sy+1)
	ans += strings.Repeat("L", tx-sx+1)
	ans += "U"
	fmt.Println(ans)
}


Measured memory_bytes: 1992
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct edge {
	int t;
	ll cost;
	edge(int _t, ll _cost) : t(_t)
		, cost(_cost) {
	}
};

int n, k;

void Solve() {
	cin >> n >> k;
	pair<ll, ll> p[100010];
	ll kind = 0;
	ll sum = 0;
	set<ll> s;
	for (size_t i = 0; i < n; i++)
	{
		cin >> p[i].second >> p[i].first;
		if (!s.count(p[i].second)) kind++;
		s.insert(p[i].second);
		sum += p[i].first;
	}
	sort(p, p + n);
	ll red[100010];
	set<ll> s2;
	ll kind2 = 0;
	ll fd[100010];
	int pi = 0;
	int fi = 0;
	fd[fi++] = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		if (!s2.count(p[i].second)) {
			kind2++;
			fd[fi++] = p[i].first + (kind2 * kind2 - (kind2 - 1) * (kind2 - 1));
			s2.insert(p[i].second);
		}
		else {
			red[pi++] = p[i].first;
		}
	}

	ll res = kind * kind + sum;
	for (size_t i = 0; i < n - k; i++)
	{
		ll fv = fd[fi - 1];
		if (pi > 0 & red[pi - 1] <= fv) {
			res -= red[--pi];
		}
		else { 
			res -= fv;
			fi--;
		}
	}
	cout << res << endl;
}
int main() {
	Solve();
	return 0;
}



Measured memory_bytes: 12288
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
#include <ctime>
#include <numeric>
using namespace std;
static const double EPS = 1e-6;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
const double pi=acos(-1);
int dx[]={0,1,0,-1,1,1,-1,-1},dy[]={1,0,-1,0,1,-1,1,-1};

main(){
  while(true){
    ll in[3]={0};
    rep(i,6){
      int t;
      cin>>t;
      in[i%3]+=t;
    }
    sort(in,in+3);
    if(in[2]==0)break;
    ll ans=0;
    rep(j,4){
      if(in[0]<j)break;
      ll tans=0;
      tans+=in[0]-j;
      tans+=(in[1]-tans)/3+(in[2]-tans)/3;
      ans=max(tans,ans);
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int R0, W0, C, R;
    while (cin >> R0 >> W0 >> C >> R, R0) {
        cout << max(0LL, (C * W0 - R0 + R - 1) / R) << endl;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}


Measured memory_bytes: 3168
#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        char s;
        cin >> s;
        if (s == 'Y') {
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int n,i,a[100];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i = n-1; i >= 0; i--){
        printf("%d",a[i]);
        if(i)printf(" ");
    }
    printf("\n");
 
return 0;
}

Measured memory_bytes: 1028
//////// Don't_be_late 
// https://atcoder.jp/contests/abc177/tasks/abc177_a
// date: 2020-08-29T21:00:28.777315
// memo: 

//<editor-fold desc="my macro">

#include<bits/stdc++.h>
#ifdef LOCAL
    #include<my/dump.h>
#else
    #define dump(...) 42 
    #define dumpi(x) 42 
#endif

typedef long long ll;
using namespace std;

#define repe(x, a) for(auto& (x) : (a))
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rep3(i, a, b) for(ll i=a, i##_len=(b);i<i##_len;i++)
#define _rep2(i, n) _rep3(i,0,n)
#define repd(...) _overload3(__VA_ARGS__,_repd3,_repd2,)(__VA_ARGS__)
#define _repd3(i, a, b) for(ll i=b-1, i##_len=(a);i>=i##_len;i--)
#define _repd2(i, n) _repd3(i,0,n)
#define loop(...) _overload3(__VA_ARGS__,,_loop2,_loop1)(__VA_ARGS__)
#define _loop2(i, a) for(ll i=a;; i++)
#define _loop1(i) _loop2(i,0)

#define all(x) x.begin(),x.end()
#define SIZE(x) ((ll)(x).size())

#define F first
#define S second
#define vec vector
#define umap unordered_map
#define uset unordered_set

ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define inrange(x,start,stop) ((start) <= (x) && (x) < (stop))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template <typename Cont, typename Func>
Cont fmap(const Cont &container, Func functor) {
    Cont result(container.size());
    std::transform(container.begin(), container.end(), result.begin(), functor);// [](int x){return x * 2;}
    return result;
}
template <typename Cont, typename Pred>
Cont filter(const Cont &container, Pred predicate) {
    Cont result;
    std::copy_if(container.begin(), container.end(), std::back_inserter(result), predicate);// [](int x){return x == 2;}
    return result;
}   

template<typename T, typename ...Args>
void ci(T& first, Args&... args) {
    ((cin >> first), ..., (cin >> args)); //C++17
}

template<char Sep, typename T, typename ...Args>
void print_seq(const T& first, const Args&... args) {
    ((cout << first), ..., (cout << Sep << args)); //C++17
}

void co(){ cout << endl; }
template<typename... Words>
void co(Words... words) {
    print_seq<' '>(words...);
    cout << endl;
}
#define coi(x) cout<<(x)<<" "

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define sankou(n,a,b) cout << ((n) ? (a) : (b) ) << endl

#define asrt(expr...) assert((expr))
//</editor-fold>

#define INF 1e19
#define MOD 1e9+7
#define MAXR 1e5

int solve() {
    ll D,T,S;
    ci(D,T,S);
//    co(D <= T * S );
    Yes(D <= T * S );
    return 0;

}

int main(){
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    
    solve();
    return 0;
}


Measured memory_bytes: 3520
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
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;}
const ll INF = 1LL<<60;
//const int dy[4] = {0, 1, 0, -1};
//const int dx[4] = {1, 0, -1, 0};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};

void solve(){
    ll n; cin >> n;
    if(n == 1){
        cout << 1 << endl;
        exit(0);
    }
    map<ll, ll> mp;
    for(ll i=2; i<=n; i++){
        ll nowi = i;
        for(ll p=2; p*p <= nowi; p++){
            if(nowi%p != 0) continue;
            ll num = 0;
            while(nowi%p == 0){
                num++;
                nowi /= p;
            }
            mp[p] += num;
        }
        if(nowi != 1) mp[nowi]++;
    }
    ll res = 1;
    for(auto x : mp){
        //cout << x.se << endl;
        res = res*(x.se + 1)%MOD;
    }
    cout << res << endl;
}

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

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define MAX 10000005
#define mod 1000000007
#define sp fixed<<setprecision(12)
using namespace std;
/*
vector<int> primes;
ll sumprime[MAX];
bool is_prime[MAX];
void sieve(){
    is_prime[0]=is_prime[1]=true;
    for(int i=4;i<MAX;i+=2){
        is_prime[i]=true;
    }
    for(int i=3;i*i<MAX;i+=2){
        if(!is_prime[i]){
            for(int j=i*i;j<MAX;j+=i){
                is_prime[j]=true;
            }
        }
    }
    for(int i=0;i<MAX;i++){
        if(!is_prime[i]){
            sumprime[i]=sumprime[i-1]+i;
        }else{
            sumprime[i]=sumprime[i-1];
        }
    }
}
*/


using namespace std;
int32_t main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    //double    pi=3.14159265358979323846;
    //sieve();
    int t=1;
    //cin>>t;
    while(t--){
        int n,w;
        cin>>n>>w;
        int weight[n];
        int value[n];
        for(int i=0;i<n;i++){
            cin>>weight[i]>>value[i];
        }
        int dp[n+1][w+1];
        for(int i=0;i<=w;i++){
            dp[0][i]=0;
        }
        for(int i=0;i<=n;i++){
            dp[i][0]=0;
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=w;j++){
                int include=INT_MIN;
                if(weight[i-1]<=j){
                    include=value[i-1]+dp[i-1][j-weight[i-1]];
                }
                int exclude=dp[i-1][j];
                dp[i][j]=max(include,exclude);
            }
        }
        cout<<dp[n][w]<<'\n';

    }
    
    
    
    
    
    return 0;
    
}

Measured memory_bytes: 82436