akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>

#define M 1999993
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5; //五进制 
  }
  return sum;
}

int h1(int key){ return key%M; }
int h2(int key){ return 1+key%(M-1); }

int find(char str[]){
	long long key = getKey(str);
	int i = 0;
	int r = 0;
	while(true){
		r = (h1(key)+i*h2(key))%M;
		if(H[r][0]=='\0'){
			return 0;
		}else if(strcmp(H[r],str)==0){
			return 1;
		}
		i++;
	}
	return 0;
}

int insert(char str[]){
	long long i = 0;
	long long key = getKey(str);
	while(true){
		int r = (h1(key)+i*h2(key))%M;
		if(H[r][0]=='\0'){
			strcpy(H[r], str);
			return 1;
		}else if(strcmp(H[r], str)==0){
			return 1;
		}else{
			i++;
		}
	}
	return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}


Measured memory_bytes: 30032
import java.util.Scanner;

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

        int n = scanner.nextInt();
        int k = scanner.nextInt();

        int digit = (int)(Math.log(n) / Math.log(k)) + 1;
        System.out.println(digit);
    }
}

Measured memory_bytes: 21844
#include<cstdio>
#include<algorithm>
using std::max;
const int N=1e5+3;
int i,n,k,a[N];
long long x,r,l[N],s[N];
int main()
{
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;++i)
	{
		scanf("%d",a+i);
		s[i]=s[i-1]+a[i];
		l[i]=l[i-1]+max(0,a[i]);
	}
	for(i=n;i>=k;x+=max(0,a[i--]))
		r=max(r,x+l[i-k]+max(0ll,s[i]-s[i-k]));
	printf("%lld",r);
}

Measured memory_bytes: 2176
def partition(A, l, r):
    """ partition A[l:r] using q(A[r]) and return q's index
    """
    q = A[r]
    sep_i = l # left elements of seq <= q < right ones
    for j in range(l, r):
        if A[j] <= q:
            # A[j] is left element
            
            # add A[j] to last of left, and replace first of right to last
            A[sep_i], A[j] = A[j],  A[sep_i]
            sep_i += 1 # update separator
        else:
            # A[j] is right element
            pass

    A[sep_i], A[r] = A[r], A[sep_i]
    
    return sep_i

n = int(input())
A = list(map(int, input().split()))

q_i = partition(A, 0, n-1)

print(*A[:q_i],  '[' + str(A[q_i]) + ']', *A[q_i+1:])


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

int main() {
    int n, x = 0; cin >> n;
    char s[101]; cin >> s;

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        x += (s[i] == 'I') * 2 - 1;
        ans = max(ans, x);
    }

    cout << ans << endl;
}



Measured memory_bytes: 3600
N, M = map(int, input().split())
students = [list(map(int, input().split())) for _ in range(N)]
checkpoints = [list(map(int, input().split())) for _ in range(M)]
for s in students:
    ans = 10**9
    for i, c in enumerate(checkpoints):
        dis = abs(c[0] - s[0]) + abs(c[1] - s[1])
        if ans > dis:
            ans = dis
            ansi = i
    print(ansi + 1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005;
const ll INF=1LL<<60;
const long double eps=1e-13;

int par[MAX],size[MAX];

void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        size[i]=1;
    }
}

int root(int a){
    if(par[a]==a) return a;
    else return par[a]=root(par[a]);
}

void unite(int a,int b,bool turn){
    if(root(a)==root(b)) return;
    
    if(turn==0) if(root(a)>root(b)) swap(a,b);
    
    if(turn==1) if(root(a)<root(b)) swap(a,b);
    
    size[root(a)]+=size[root(b)];
    par[root(b)]=root(a);
}

bool check(int a,int b){
    return root(a)==root(b);
}


int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    int N;cin>>N;
    vector<long double> A(N+2,INF),B(N+2,INF);
    vector<ll> a(N+2,0),b(N+2);
    for(int i=0;i<N;i++){
        long double c;cin>>c;
        A[i+1]=log2(c)+1.0;
        B[i+1]=log2(c);
        a[i+1]++;
    }
    
    init(N+2);
    
    for(int i=1;i<=N;i++){
        a[i]+=a[i-1];
        
        if(A[i-1]-A[i]>-eps){
            if(A[i-1]-A[i]<=2.0-eps) unite(i-1,i,0);
            continue;
        }
        int now=i;
        while(1){
            while(A[now-1]-A[now]<=-eps){
                A[now-1]+=2.0;
                if(root(now-1)!=now-1) A[root(now-1)]+=2.0;
                a[i]+=2*(now-root(now-1));
            }
            if(A[now-1]-A[now]<=2.0+eps) unite(now-1,now,0);
            now=root(now-1);
            
            if(now==1) break;
        }
    }
    a[N+1]=a[N];
    
    init(N+2);
    
    for(int i=N;i>=1;i--){
        b[i]+=b[i+1];
        
        if(B[i+1]-B[i]>-eps){
            if(B[i+1]-B[i]<=2.0-eps) unite(i+1,i,1);
            continue;
        }
        int now=i;
        while(1){
            while(B[now+1]-B[now]<=-eps){
                B[now+1]+=2.0;
                if(root(now+1)!=now+1) B[root(now+1)]+=2.0;
                b[i]+=2*(root(now+1)-now);
            }
            if(B[now+1]-B[now]<=2.0+eps) unite(now+1,now,1);
            now=root(now+1);
            
            if(now==N) break;
        }
    }
    b[0]=b[1];
    
    ll ans=INF;
    
    for(int i=0;i<N+1;i++){
        ans=min(ans,a[i]+b[i+1]);
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 11264
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i32,
        r: i32,
    }
    
    let mut ans = 0;
    if n < 10 {
        ans = 100 * (10 - n);
    }
    ans += r;

    println!("{}", ans);
}


Measured memory_bytes: 4352
function main(s) {
	s = s.split("\n");
	t = s[0].split(" ").map(x => Number(x));
	console.log(Array(t[1]+3).join("#"));
	for (var i = 0; i < t[0]; i++) {
		console.log("#%s#", s[i+1]);
	}
	console.log(Array(t[1]+3).join("#"));
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 8188
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int INF=1e7;

int main(){
	int N,M;
	cin>>N>>M;
	int G[101][101];
	bool NS[101][101];
	rep1(i,N)rep1(j,N){
		G[i][j]=INF;
		NS[i][j]=false;
		}
	rep1(i,N)G[i][i]=0;
	rep1(i,M){
		int a,b,c;
		cin>>a>>b>>c;
		G[a][b]=c;
		G[b][a]=c;
	}
	int d[101][101];
	rep1(i,N)rep1(j,N)d[i][j]=G[i][j];
	rep1(k,N)rep1(i,N)rep1(j,N){
		if(d[i][j]>d[i][k]+d[k][j]){
			d[i][j]=d[i][k]+d[k][j];
			if(G[i][j]!=INF)NS[i][j]=true;
		}
	}
	int ans=0;
	rep1(i,N)rep1(j,N)if(NS[i][j])ans++;
	cout<<ans/2<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  ll cnt = 0;
  FOR(b, 1, n + 1) {
    int p = n / b;
    int r = n % b;
    cnt += (ll)p * max(0, b - k) + max(0, r - k + 1);
  }
  if(k == 0) cnt -= n;
  cout << cnt << endl;
  return 0;
}


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

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> A, B;
    for (int i = 0;i < n;i++) {
        ll input;
        cin >> input;
        A.push_back(input);
    }
    for (int i = 0;i < m;i++) {
        ll input;
        cin >> input;
        B.push_back(input);
    }

    vector<ll> a, b;
    a.push_back(0); b.push_back(0);

    for (int i = 0;i < n;i++) {
        a.push_back(a[i] + A[i]);
    }
    for (int i = 0;i < m;i++) {
        b.push_back(b[i] + B[i]);
    }

    ll j = m;
    ll ans = 0;
    for (int i = 0;i <= n;i++) {
        if (a[i] > k) break;
        while (b[j] > k - a[i]) {
            j--;
        }
        ans = max(ans, i + j);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11088
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
    int n,k;

    std::cin >> n >> k;
    std::vector<int> vec1(n);
    vec1.resize (n);

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

    std::sort(vec1.begin(),vec1.end());
    
    int a=0;
    for(int i=0;i<k;i++){
        a=a+vec1[i];
    }
    std::cout << a << std::endl;
    return 0;
}

Measured memory_bytes: 3632
//Program.cpp
//Problem Statement - 

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

//Author: Varun Goyal (@govarun)

#define f(i, n) for(int i=0;i<(n);++i)
#define fa(i, a, n) for(int i=(a);i<=(n);++i)
#define fd(i, a, n) for(int i=(a);i>=(n);--i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define popb pop_back
#define ull unsigned long long
#define debug if(GOVARUN) cerr
#define d0(x) debug <<#x<<" = "<<x<<' '
#define d1(x) debug <<"> "<<#x<<" = "<<x<<'\n'
#define d2(x, y) debug <<"> "<<#x<<" = "<<x<<' '<<#y<<" = "<<y<<'\n'
#define d3(x, y, z) debug <<"> "<<#x<<" = "<<x<<' '<<#y<<" = "<<y<<' '<<#z<<" = "<<z<<'\n'
#define endl '\n'
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector< pair<int, int> > vpii;
inline bool EQ(double a, double b) { 
return fabs(a-b) < 1e-9; }
inline int two(int n) { return 1 << n; }

const ll mod = 1e9 + 7;
const int maxn = 1e5 + 5;

void pre(){

    
}


void solve();

int main(){
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    #ifdef GOVARUN
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #else 
    #define GOVARUN 0
    #endif
    int TC = 1;
    // cin >> TC;
    while(TC--){    
        solve();
    }

    return 0;
}

void solve(){
    int n; cin >> n;
    int h[n]; 
    f (i, n) cin >> h[i];
    ll cost[n]; fill(cost);
    cost[0] = 0;
    if (n == 1)  cout << 0;
    else if (n == 2) cout << abs(h[1] - h[0]);
    else {
        cost[0] = 0;
        cost[1] = abs(h[1] - h[0]);
        fa (i, 2, n - 1) {
            cost[i] = min (cost[i - 1] + abs(h[i] - h[i - 1]), cost[i - 2] + abs(h[i] - h[i - 2])); 
        }
        cout << cost[n - 1]; 
    }
    
}

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

long sum[100010];
int main()
{
    int n, q; cin>>n>>q;
    string s; cin>>s;
    for(int i=1; i<n; ++i)
        sum[i+1]=sum[i]+(s[i]=='C' and s[i-1]=='A');

    while (q--) {
        int L, R; cin>>L>>R;
        cout<<sum[R]-sum[L]<<'\n';
    }
}


Measured memory_bytes: 1792
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 1};
int dy[] = {1, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int dp[2][110], A[2][110];
signed main() {
    int N; cin >> N;
    for(int i=0; i<2; i++) {
        for(int j=0; j<N; j++) {
            cin >> A[i][j];
        }
    }

    dp[0][0] = A[0][0];
    for(int i=0; i<2; i++) {
        for(int j=0; j<N; j++) {
            for(int k=0; k<2; k++) {
                int ni = i + dx[k], nj = j + dy[k];
                if(ni < 0 || ni >= 2 || nj < 0 || nj >= N) continue;
                chmax(dp[ni][nj], dp[i][j] + A[ni][nj]);
            }
        }
    }
    cout << dp[1][N-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <algorithm>

using namespace std;

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

    vector<pair<int, int>> interval;

    int a, b;

    for (int i = 0; i < m; i++)
    {
        cin >> a >> b;
        interval.push_back(make_pair(a, b));
    }

    sort(interval.begin(), interval.end());

    // for (auto itr : interval)
    // {
    //     cerr << "(" << itr.first << "," << itr.second << ")" << endl;
    // }

    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> tmp;
    int count = 0;
    for (int i = 0; i < m; i++)
    {
        auto &itr = interval[i];
        if (!tmp.empty())
        {
            auto &itr2 = tmp.top();

            // cerr << "compare ";
            // cerr << "(" << itr.first << "," << itr.second << ") vs ";
            // cerr << "(" << itr2.second << "," << itr2.first << ")" << endl;

            if (tmp.top().first <= itr.first)
            {

                count++;
                while (!tmp.empty())
                {
                    // auto &itr3 = tmp.top();
                    // cerr << "pop (" << itr3.first << "," << itr3.second << ")" << endl;

                    tmp.pop();
                }
            }
        }
        tmp.push(make_pair(itr.second, itr.first));
        // cerr << "push (" << itr.first << "," << itr.second << ")" << endl;
    }

    count++;

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1780
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


long long vh(long long H, long long W)
{
  long long dp = INF;
  
  for (int i = -500; i < 500; i ++) {
    long long W1 = W / 3 + i, W2 = W - W1;

    if (W1 < 0 || W2 < 0)
      continue;

    for (int j = -500; j < 500; j ++) {
      long long H1 = H / 2 + j, H2 = H - H1;

      if (H1 < 0 || H2 < 0)
        continue;

      std::vector<long long> A = {
        H  * W1,
        H1 * W2,
        H2 * W2
      };

      assert(A[0] + A[1] + A[2] == H * W);

      std::sort(ALL(A));

      dp = std::min(A[2] - A[0], dp);
    }
  }

  return dp;
}

long long vv(long long H, long long W)
{
  long long dp = INF;
  
  for (int i = -500; i < 500; i ++) {
    long long W1 = W / 3 + i, WW = W - W1;

    if (W1 < 0 || WW < 0)
      continue;

    for (int j = -500; j < 500; j ++) {
      long long W2 = WW / 2 - j, W3 = WW - W2;

      if (W2 < 0 || W3 < 0)
        continue;

      std::vector<long long> A = {
        H * W1,
        H * W2,
        H * W3
      };

      assert(A[0] + A[1] + A[2] == H * W);

      std::sort(ALL(A));

      dp = std::min(A[2] - A[0], dp);
    }
  }

  return dp;
}


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int H, W;

  std::cin >> H >> W;

  long long dp = INF;

  dp = std::min(dp, vh(H, W));
  dp = std::min(dp, vv(H, W));

  std::swap(H, W);

  dp = std::min(dp, vh(H, W));
  dp = std::min(dp, vv(H, W));

  std::cout << dp << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
using Graph = vector<vector<ll>>;
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);


int main(){
    ll d, n; cin >> d >> n;
    if(n == 100) n++;
    if(d == 0) cout << n << endl;
    else if(d == 1) cout << 100*n << endl;
    else if(d == 2) cout << 100*100*n << endl;
}


Measured memory_bytes: 3628
use std::io::*;
use std::str::FromStr;
use std::cmp;
use std::collections::HashMap;
use std::collections::HashSet;
use std::char;
use std::cmp::{min, max};
use itertools::Itertools;
use num_integer::div_floor;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn read_tuple2<T: FromStr, S: FromStr>() -> (T, S) {
    let a = read();
    let b = read();
    (a, b)
}

fn read_tuple3<T: FromStr, S: FromStr, R: FromStr >() -> (T, S, R) {
    let a = read();
    let b = read();
    let c = read();
    (a, b, c)
}

fn main() {
    let n:u64 = read();
    let alist:Vec<u64> = (0..n).map(|_|read()).collect();
    let counter = {
        let mut counter = HashMap::new();
        for a in alist {
            let ent =counter.entry(a).or_insert(0);
            *ent += 1;
        }
        counter
    };
    let twos = {
        let mut twos:Vec<u64> = counter.iter()
            .filter(|(key, val)|**val > 1)
            .map(|(key, val)|*key)
            .collect();
        twos.sort_by(|a, b|b.cmp(a));
        twos
    };
    let fst = *twos.get(0).unwrap_or(&0);
    let snd = if let Some(fst) = twos.get(0) {
        if *counter.get(fst).unwrap_or(&0) > 3 {
            *fst
        } else {
            *twos.get(1).unwrap_or(&0)
        }
    } else {
        0
    };
    println!("{}", fst * snd);


}



Measured memory_bytes: 6200
#include<iostream>
using namespace std;
int main(){

	int a, b, c;
	char op;
	cin >> a >> op >> b;

	while (op != '?' ){
		if (op == '+') c = a + b;
		if (op == '-') c = a - b;
		if (op == '*') c = a * b;
		if (op == '/') c = a / b;
		cout << c << endl;
		cin >> a >> op >> b;
	}
	return 0;
}


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

int main() {
    int N;
    long long K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i]--;
    }

    map<int, int> mp;
    int next = 0, cnt = 1;
    mp[next] = cnt;
    while (cnt <= K) {
        next = A[next];
        cnt++;
        if (mp[next] != 0) break;
        mp[next] = cnt;
    }

    if (cnt <= K) {
        K -= mp[next] - 1;
        K %= cnt - mp[next];
        for (int i = 0; i < K; i++) next = A[next];
    }
    next++;

    cout << next << endl;
}

Measured memory_bytes: 11348
import collections
import sys
sys.setrecursionlimit(10**6)
dd = collections.defaultdict(int)
def dfs(i,n):
    if(i<=n):
        k = [0,0,0]
        for j in range(len(str(i))):
            if(int(str(i)[j])==3):
                k[0]=1
            if(int(str(i)[j])==5):
                k[1]=1
            if(int(str(i)[j])==7):
                k[2]=1
        if 0 not in k:
            dd[i]=1
        dfs(int(str(i)+"3"),n)
        dfs(int(str(i)+"5"),n)
        dfs(int(str(i)+"7"),n)


def main():
    n = int(input())
    res = 0
    a = [3,5,7]
    for i in a:
        dfs(i,n)
    for key in dd.keys():
        res+=1
    print(res)
    

if __name__ == "__main__":
    main()

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

int main(){
    int H,W;
    
    while(1){
        cin >> H >> W;
        if(H==0 && W==0)break;

        for(int i=0;i<H ; i++){
            for(int j=0 ; j<W ; j++){
                if(j==0 || j== W-1 || i==0 || i== H-1 ){
                    cout <<"#";
                }else{
                    cout <<".";
                }
             }
             cout << "\n";
            }
            cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3088
n,m = map(int,input().split())
#ac,wa列を作成（pi問題がACならac[i]がTRUE、AC,WAに問わずwa[i]はwaの数）
ac, wa=[False]*n,[0]*n
for i in range(m):
  p,s = input().split()
  p=int(p)
  if s=='AC':
    ac[p-1]=True
  elif (s=='WA') and (ac[p-1]==False):
    wa[p-1]+=1

penalty, clear=0,0
for i,tf in enumerate(ac): #iはインデックス、tfはac[i]
  if tf:
    penalty += wa[i] #piがACされているとき、ペナルティ値を増やす
    clear += 1
print(clear, penalty)


Measured memory_bytes: 4596
# coding: utf-8
n, m = map(int, input().split())
matrixA = []
vectorB = []

for i in range(n):
    matrixA.append(list(map(int, input().split())))

for i in range(m):
    vectorB.append(int(input()))


for i in range(n):
    num = 0
    for j in range(m):
        num += matrixA[i][j] * vectorB[j]
    print(num)



Measured memory_bytes: 6012
#!/usr/bin/env python3
def main():
    A = []
    for i in range(3):
        A.append([int(x) for x in input().split()])
    N = int(input())
    bingo = [[False] * 3 for _ in range(3)]
    for n in range(N):
        B = int(input())
        for i in range(3):
            if B in A[i]:
                bingo[i][A[i].index(B)] = True
    for i in range(3):
        if bingo[i][0] == bingo[i][1] == bingo[i][2] is True:
            print('Yes')
            return
        if bingo[0][i] == bingo[1][i] == bingo[2][i] is True:
            print('Yes')
            return
    if bingo[0][0] == bingo[1][1] == bingo[2][2] is True:
        print('Yes')
        return
    if bingo[0][2] == bingo[1][1] == bingo[2][0] is True:
        print('Yes')
        return
    print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9260
N = int(input())
D, X = map(int, input().split(' '))

A = [int(input()) for i in range(N)]

for p in A:
    i = 0
    while True:
        date = 1 + p * i
        if date > D:
            break
        else:
            i += 1
            X += 1

print(X)

Measured memory_bytes: 2940
N, M = list(map(int, input().split()))
lines = [list(map(int, input().split())) for _ in range(M)]

graph = [[False] * N for _ in range(N)]
for a,b in lines:
    graph[a-1][b-1] = graph[b-1][a-1] = True

visited = [False for _ in range(N)]

def DFS(v):
    visited[v] = True
    for from_v in range(N):
        if not graph[v][from_v]:
            continue
        if visited[from_v]:
            continue
        DFS(from_v)
    
cnt = 0
for i in range(M):
    pass_a, pass_b = lines[i]
    pass_a -= 1
    pass_b -= 1
    graph[pass_a][pass_b] = graph[pass_b][pass_a] = False
    DFS(pass_a)
    
    cnt += 1 if False in visited else 0
    
    visited = [False for _ in range(N)]
    graph[pass_a][pass_b] = graph[pass_b][pass_a] = True

print(cnt)

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

int N;

int main()
{
    cin >> N;

    vector<vector<char>> S(N, vector<char>(N));
    string s;
    for (int i = 0; i < N; i++)
    {
        cin >> s;
        for (int j = 0; j < N; j++)
        {
            S[i][j] = s[j];
        }
    }

    int ans = 0;

    for (int a = 0; a < N; a++)
    {
        for (int b = 0; b < 1; b++)
        {
            bool badFlg = false;
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    if (S[(j+a)%N][(i+b)%N] != S[(i+a)%N][(j+b)%N])
                    {
                        badFlg = true;
                        break;
                    }
                }
                if (badFlg)
                    break;
            }
            if (!badFlg)
                ans++;
        }
    }

    cout << ans * N<< "\n";
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long w=sc.nextLong(),h=sc.nextLong();
		int x=sc.nextInt(),y=sc.nextInt();
		sc.close();
		System.out.printf("%.10f\n",(double)w*(double)h/2);
		if((double)x==(double)w/2 && (double)y==(double)h/2) System.out.println("1");
		else System.out.println("0");
	}
}

Measured memory_bytes: 23252
num, time = map(int,input().split())
list = [int(x) for x in input().split()]
ans = 0



for i in range(1,num):
    if list[i] - list[i-1] < time:
        ans += list[i] - list[i-1]
        
    else:
        ans += time
        
ans += time
print(ans)


Measured memory_bytes: 25196
package main

import "fmt"

func arrayNotContains(number int, solved []int) bool {
	for i := 0 ; i < len(solved); i++ {
		if solved[i] == number {
			return false
		}
	}
	return true
}


func main(){
	var n,m,ans,pen,num int
	fmt.Scan(&n,&m)
	//fmt.Println(n,k,m)
	check := make([]bool , n)
	penal := make([]int, n)
	var correct string
	for i := 0 ; i < m; i++ {
		fmt.Scan(&num,&correct)
		if correct == "AC" {
			check[num-1] = true
		} else if !check[num-1] {
			penal[num-1]++
		}
	}
	for i := 0 ; i < n; i++ {
		if check[i] {
			ans++
			pen += penal[i]
		}
	}
	fmt.Println(ans,pen)
}


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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
void yesOrNo(bool flg) {
  if (flg)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

bool f(ll A, ll B, ll C, ll r) {
  if (r == 0) {
    return A < B && B < C;
  } else {
    return f(A * 2, B, C, r - 1) || f(A, B * 2, C, r - 1) ||
           f(A, B, C * 2, r - 1);
  }
}

void solve(ll A, ll B, ll C, ll K) {
  bool result = f(A, B, C, K);

  yesOrNo(result);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll A;
  scanf("%lld", &A);
  ll B;
  scanf("%lld", &B);
  ll C;
  scanf("%lld", &C);
  ll K;
  scanf("%lld", &K);
  solve(A, B, C, K);
  return 0;
}


Measured memory_bytes: 3716
N,x,*as=$<.read.split.map(&:to_i)

ret = 0
1.upto(N-1) do |i|
    d = as[i-1] + as[i] - x
    if 0 < d
        as[i] -= [d,as[i]].min
        ret += d
    end
end

puts ret

Measured memory_bytes: 21704
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]
#define GI(name) int (name);scanf("%d",&(name))
#define GI2(name1,name2) int (name1),(name2);scanf("%d %d",&(name1),&(name2))
#define GI3(name1,name2,name3) int (name1),(name2),(name3);scanf("%d %d %d",&(name1),&(name2),&(name3))
#define GVI(name,size) vector<int> (name)(size);FOR(i,(size))scanf("%d",&(name)[i])
#define MOD 1000000007

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=n;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug_print(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug_print(Head head,Tail... tail){
    cerr<<to_string(head)<<" ";
    debug_print(tail...);
}

template<class... T>
void debug(T... args){
    cerr<<"["<<__LINE__<<"]: ";
    debug_print(args...);
}

void print(){
    cout<<endl;
}

template<class Head,class... Tail>
void print(Head head,Tail... tail){
    cout<<to_string(head);
    print(tail...);
}

int main(){
    string S;
    cin>>S;
    char last=S[0];
    int ans=0;
    FORIN(i,1,S.size()){
        if(last==S[i]){
            ans++;
            last=S[i]=='0'?'1':'0';
        }else{
            last=S[i];
        }
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 512
n,h=map(int,input().split())
alist=[]
blist=[]
for i in range(n):
  a,b=map(int,input().split())
  alist.append(a)
  blist.append(b)
a_max = max(alist)
t=0
for i in range(n):
  if blist[n-1-i]<a_max:
    del blist[n-1-i]
    del alist[n-1-i]
    t+=1
n = n-t
ab = [[alist[i],blist[i]] for i in range(n)]
ab.sort(key=lambda x: x[1], reverse=True)
damage = 0
count = 0
for i in range(n):
  damage += ab[i][1]
  count += 1
  if damage >= h:
    print(count)
    exit()
remain = h - damage
print(count + ((remain + a_max -1) // a_max))

Measured memory_bytes: 22680
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>

int main(void){
    std::string a,b;
    std::cin >> a >> b;
    if(a.size() > b.size()){
        std::cout << "GREATER";
        return 0;
    }
    else if(b.size() > a.size()){
        std::cout << "LESS";
        return 0;
    }
    else{

        for(int i = 0; i < a.size(); i++){
            if(a[i] > b[i]){
                std::cout << "GREATER";
                return 0;
            }
            else if(a[i] < b[i]){
                std::cout << "LESS";
                return 0;
            }
        }
    }
    std::cout << "EQUAL";
    return 0;
}




Measured memory_bytes: 256
#include<cstdio>
int e[110];
int main()
{
	int a,b,c,d;
	int ans=0;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	for(int i=a+1;i<=b;i++)
	{
		e[i]=e[i]+1;
	}
	for(int i=c+1;i<=d;i++)
	{
		e[i]++;
	}
	for(int i=0;i<=105;i++)
	{
		if(e[i] == 2)
			ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
from bisect import bisect_right
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
accu = 0
aa = [0]
for i in a:
    accu += i
    aa.append(accu)
accu = 0
bb = [0]
for i in b:
    accu += i
    bb.append(accu)
ans = 0
for i in range(n+1):
    if aa[i]>k:
        break
    tmp = i+bisect_right(bb, k-aa[i])-1
    ans = max(tmp, ans)
print(ans)

Measured memory_bytes: 47272
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>

using namespace std;

const int MOD = 1000000007;
const int MAX = 510000;
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[n-k]*finv[k]%MOD)%MOD;
}


int main()
{
  COMinit();
  
  int N;
  cin >> N;

  vector<string> S(N);
  for(int i=0; i<N; i++)
    cin >> S[i];

  for(int i=0; i<N; i++)
    sort(S[i].begin(), S[i].end());

  sort(S.begin(), S.end());
  
  long long count=0;
  long long sum=0;
  for(int i=0; i<N-1; i++)
    {
      //cout << count << endl;
      if(S[i]==S[i+1])
	{
	  count++;
	  sum += count;
	}
      else
	{
	  count = 0;
	}
    }    
  
  cout << sum  << endl;


  return 0;
}


Measured memory_bytes: 19200
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d;
	int x,y;
	cin>>a>>b>>c>>d;
	x=c-a;
	y=d-b;
	for(int i=0;i<x;i++){
		cout<<"R";
	}
	for(int i=0;i<y;i++){
		cout<<"U";
	}
	cout<<"L";
	for(int i=y;i>1;i--){
		cout<<"D";
	}
	for(int i=x-1;i>0;i--){
		cout<<"L";
	}
	cout<<"D";
	cout<<"D";
	for(int i=0;i<x+1;i++){
		cout<<"R";
	}
	for(int i=-1;i<y;i++){
		cout<<"U";
	}
	cout<<"L";
	cout<<"U";
	cout<<"LL";
	for(int i=y+1;i>2;i--){
		cout<<"D";
	}
	for(int i=x-2;i>-1;i--){
		cout<<"L";
	}
	cout<<"DD";
	cout<<"R"<<endl;
	return 0;
}

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

int main() {
  int n, m;
  cin>>n>>m;
  if (n%3==0||m%3==0||(n+m)%3==0) cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;

}


Measured memory_bytes: 256
import math
K = int(input())
N = 0

for a in range(1,K+1):
    for b in range(a,K+1):
        for c in range(b,K+1):
            g = math.gcd(a,b)
            g = math.gcd(g,c)
            if(a != 1 or b != 1 or c != 1 ):
                if(a != b or a != c):
                    if(a != K or b != K or c != K ):
                        if(a != b and a != c and b != c):
                            g *= 6
                        else:
                            g *= 3
            N += g

print(N)

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,c;
    cin >> n >> c;
    vector<ll> x(n);
    vector<ll> v(n);
    for(i = 0;i < n;++i){
        cin >> x.at(i) >> v.at(i);
    }
    vector<ll> rmawari(n+1,0);
    rmawari.at(1) = v.at(0) - x.at(0);
    for(i = 2;i <= n;++i){
        rmawari.at(i) = rmawari.at(i-1) + v.at(i-1) - (x.at(i-1) - x.at(i-2)); 
    }
    vector<ll> rmawarimax(n+1,0);
    for(i = 1;i <= n;++i){
        rmawarimax.at(i) = max(rmawarimax.at(i-1), rmawari.at(i));
    }
    vector<ll> lmawari(n+1,0);
    lmawari.at(1) = v.at(n-1) - (c - x.at(n-1));
    for(i = 2;i <= n;++i){
        lmawari.at(i) = lmawari.at(i-1) + v.at(n-i) - (x.at(n-i+1) - x.at(n-i));
    }
    vector<ll> lmawarimax(n+1,0);
    for(i = 1;i <= n;++i){
        lmawarimax.at(i) = max(lmawarimax.at(i-1), lmawari.at(i));
    }
    ll ans = 0;

    ans = max(ans, rmawarimax.at(n));
    ans = max(ans, lmawarimax.at(n));
    
    for(i = 1;i <= n;++i){
        ll tmp = rmawari.at(i) - x.at(i-1) + lmawarimax.at(n-i);
        ans = max(tmp,ans);
    }
    for(i = 1;i <= n;++i){
        ll tmp = lmawari.at(i) - (c - x.at(n-i)) + rmawarimax.at(n-i);
        ans = max(tmp,ans);
    }
    cout << ans << endl;

    return 0;
}

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

int main()
{
    long long x, fiveh, rem, five, total;
    cin >> x;


    fiveh=x/500;
    rem=x%500;
    five=rem/5;

    total=1000*fiveh+5*five;

    cout << total << endl;

    return 0;
}


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

int main(void){
    int A[3][3] = {{0},{0}};;
    for (int i=0; i<3; i++){
        for (int j=0; j<3; j++) cin >> A[i][j];
    }



    int N = 0;
    cin >> N;
    
    int b[100] = {0};
    for(int i=0; i<N; i++) cin >> b[i];

    bool Achk[3][3] = {{0},{0}};
    

    
    for(int i=0; i<N; i++) {
        for(int m=0; m<3; m++){
            for(int n=0; n<3; n++){
                if (b[i] == A[m][n]) Achk[m][n] = true;
            }
        }
    }
 
    if (Achk[0][0] == true && Achk[0][1] == true && Achk[0][2] == true){
        cout << "Yes"; 
    } else if (Achk[1][0] == true && Achk[1][1] == true &&  Achk[1][2] == true) {
        cout << "Yes";
    } else if (Achk[2][0] == true && Achk[2][1] == true && Achk[2][2] == true) {
        cout << "Yes";
    } else if (Achk[0][0] == true && Achk[1][0] == true && Achk[2][0] == true) {
        cout << "Yes";
    } else if (Achk[0][1] == true && Achk[1][1] == true && Achk[2][1] == true) {
        cout << "Yes";
    } else if (Achk[0][2] == true && Achk[1][2] == true && Achk[2][2] == true) {
        cout << "Yes";
    } else if (Achk[0][0] == true && Achk[1][1] == true && Achk[2][2] == true) {
        cout << "Yes";
    } else if (Achk[0][2] == true && Achk[1][1] == true && Achk[2][0] == true) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#pragma GCC optimize("O3")

#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cstring>
#include <numeric>
#include <set>
#include <queue>
#include <deque>
#include <array>
#include <string>
#include <cmath>
#include <random>
#include <ctime>
#include <map>
#include <functional>
#include <bitset>
#include <complex>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define pb push_back

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using ld = long double;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, W;
	cin >> n >> W;
	vi w(n), v(n);
	for (int i = 0; i < n; i++) {
		cin >> w[i] >> v[i];
	}
	vector<ll> dp(W + 1, 0);
	for (int i = 0; i < n; i++) {
		for (int j = W; j >= 0; j--) {
			if (j - w[i] >= 0 && (dp[j - w[i]] > 0 || j - w[i] == 0)) {
				dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
			}
		}
	}
	cout << *max_element(all(dp));
}


Measured memory_bytes: 1024
extern crate core;

use std::str::FromStr;
use std::fmt;
use std::cmp::{Ordering, max};
use std::fmt::{Display, Error, Formatter};
use std::ops::{Range, Add};

macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}

macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
macro_rules! repeat {
    ($count:expr; $($statement:tt)+) => {
        for _ in 0 .. $count {
            $($statement)*
        }
    };
}

macro_rules! yields {
    ($count:expr; $block:block) => {{
        let mut vec = Vec::with_capacity($count);
        for _ in 0 .. $count {
            vec.push($block);
        }
        vec
    }}
}
macro_rules! array {
    ($factor: expr; ) => {$factor};
    ($factor: expr; $dimension: expr) => {{
        let size = $dimension;
        let mut vec = Vec::with_capacity(size);
        for _ in 0 .. size {
            vec.push($factor)
        }
        vec
    }};
    ($factor:expr; $dimension:expr, $($r:expr),*) => {{
        let size = $dimension;
        let mut vec = Vec::with_capacity(size);
        for _ in 0 .. size{
            let factor = array!($factor; $($r),*);
            vec.push(factor)
        }
        vec
    }};
}
fn tabulate<F, R>(count: usize, mut generator: F) -> Vec<R> where F : FnMut(usize) -> R {
    let mut result = Vec::<R>::with_capacity(count);
    for f in 0..count {
        result.push(generator(f));
    }
    result
}
fn log3(n: i32) -> i32 {
    match n {
        1 => 0,
        _ if n % 3 == 0 => log3(n / 3) + 1,
        _ => log3(n / 3 + 1) + 1
    }
}
fn main() {
    let_all!(n: i32);
    println!("{}", log3(n))
}



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

namespace AOJ0008
{
    class Program
    {
        static void Main()
        {
            string line;
            while ((line = Console.ReadLine()) != null)
            {
                var n = int.Parse(line);

                var count = (from a in Enumerable.Range(0, 10)
                             from b in Enumerable.Range(0, 10)
                             from c in Enumerable.Range(0, 10)
                             from d in Enumerable.Range(0, 10)
                             where a + b + c + d == n
                             select 0)
                    .Count();

                Console.WriteLine(count);
            }
        }
    }
}

Measured memory_bytes: 6152
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
int main () {
    char c;
    cin >> c;
    char d = c + 1; 
    cout << d << endl;
}



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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> d(K);
    vector<int> sunuke(N, 0);
    vector<vector<int> > A(K, vector<int>(N));
    int i, j;
    
    for(i=0;i<K;i++){
        cin >> d.at(i);
        for(j=0;j<d.at(i);j++){
            cin >> A.at(i).at(j);
            sunuke.at(A.at(i).at(j)-1) += 1;
        }
    }
    int ans=0;
    for(i=0;i<N;i++){
        if(sunuke.at(i)==0)
            ans++;
    }
    cout << ans << endl;

}

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

using namespace std;

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

    vector< vector<int> > grid(2, vector<int> (m, 0));

    for(int i = 0; i < 2; i++){
        for(int j = 0; j < m; j++){
            scanf("%d", &grid[i][j]);
        }
    }

    vector< vector<int> > dp(2, vector<int> (m, 0));

    dp[0][0] = grid[0][0];
    dp[1][0] = dp[0][0] + grid[1][0];

    for(int i = 1; i < m; i++){
        dp[0][i] = dp[0][i - 1] + grid[0][i];
        dp[1][i] = max(dp[0][i], dp[1][i - 1]) + grid[1][i];
    }

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




}


Measured memory_bytes: 256