akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<math.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < n; i++)

const ll INF = 1LL << 60;


signed main() {

	ll max = 0;
	ll H, W;
	cin >> H >> W;

	vector<vector<ll>>hako(H + 1, vector<ll>(W + 1));
	
	char s[21][21];
	rep(i, H) { rep(j, W)cin >> s[i][j]; }

	ll points = 0;
	rep(i, H) {
		rep(j, W) {
			if (s[i][j] == '.') {
				hako[i][j] = 1;
				points++;
			}
			else {
				hako[i][j] = 0;
			}
		}
	}
	ll cc = H * W;
	vector<vector<ll>>G(cc);
	rep(i, H) {
		rep(j, W) {
			if (hako[i][j] == 0)continue;
			if (j < W - 1) {
				if (hako[i][j + 1] == 1) {
					G[i * W + j].push_back(i * W + j + 1);
					G[i * W + j + 1].push_back(i * W + j);
				}
			}
			if (i < H - 1) {
				if (hako[i + 1][j] == 1) {
					G[i * W + j].push_back(i * W + j + W);
					G[i * W + j + W].push_back(i * W + j);
				}
			}
		}
	}
	for (ll x = 0; x < cc; x++) {
		vector<ll>dist(cc, -1);

		queue<ll>que;

		if (hako[x / W][x % W] == 0)continue;

		dist[x] = 0;

		que.push(x);
		while (!que.empty()) {
			int a = que.front();
			que.pop();
			for (int i : G[a]) {
				if (dist[i] != -1) continue;
				dist[i] = dist[a] + 1;
				if (max < dist[i])max = dist[i];
				que.push(i);
			}
		}
	}

	cout << max;

}


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

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

	vector<int> dp(3);

	for (int day = 0; day < n; day++) {
		vector<int> new_dp(3, 0);
		vector<int> c(3);
		for (int i = 0; i < 3; i++) {
			scanf("%d", &c[i]);
		}

		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (i != j) {
					new_dp[j] = max(new_dp[j], dp[i] + c[j]);
				}
			}
		}
		dp = new_dp;
	}
	printf("%d\n", max({dp[0], dp[1], dp[2]}));
}

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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n =  sc.nextInt();
        String s = sc.next();

        if (n % 2 == 1) {
            System.out.println("No");
        } else {
            if (s.substring(0, n/2).equals(s.substring(n/2, n)))
                System.out.println("Yes");
            else
                System.out.println("No");
        }
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 21332
# frozen_string_literal: true

n, m = gets.split.map(&:to_i)

uf = [*0..n]
rank = Array.new(n + 1) { 0 }

def root(uf, i)
  uf[i] == i ? i : (uf[i] = root uf, uf[i])
end

m.times do
  x, y = gets.split.map(&:to_i)
  x = root uf, x
  y = root uf, y

  next if x == y

  if rank[x] > rank[y]
    uf[y] = x
  else
    uf[x] = y
    rank[y] += 1 if rank[x] == rank[y]
  end
end

puts 1.upto(n).count { |i| root(uf, i) == i }

Measured memory_bytes: 4220
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cmath>
#include <stack>
typedef long long ll;
#define INF 0x3f3f3f3f

using namespace std;
int main(int argc, char *argv[]) {
	int K;
	cin >> K;
	int odd, even;
	odd = K / 2 + K % 2;
	even = K / 2;
	cout << odd * even << endl;
}

Measured memory_bytes: 256
n = gets.to_i
bubble_sort = gets.split()
selection_sort = Array.new(bubble_sort)
start = 1
flag = 1

while flag == 1
  flag = 0
  (start..n-1).reverse_each do |i|
    if bubble_sort[i][1].to_i < bubble_sort[i-1][1].to_i
      bubble_sort[i], bubble_sort[i-1] = bubble_sort[i-1], bubble_sort[i]
      flag = 1
    end
  end
  start += 1
end

puts bubble_sort.join(" ")
puts "Stable"

min_index = 0

n.times do |i|
  min_index = i
  (i..n-1).each do |j|
    min_index = j if selection_sort[min_index][1].to_i > selection_sort[j][1].to_i
  end
  selection_sort[i], selection_sort[min_index] = selection_sort[min_index], selection_sort[i]
end

puts selection_sort.join(" ")
puts selection_sort == bubble_sort ? "Stable" : "Not stable"



Measured memory_bytes: 6884
import sys, math
from itertools import combinations
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    x = ii()
    a = x//11
    b = x%11
    if b > 6:
        print(2*a+2)
    elif b > 0:
        print(2*a+1)
    else:
        print(2*a)

if __name__ == '__main__':
    main()

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

using ll = long long;

int main(){
  int K;
  vector<int> N = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cin >> K;

  cout << N[K] << endl;
}

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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  
  int ans =0;
  
  for(int i=0; i<=A; i++){
    for(int j=0; j<=B; j++){
      for(int k=0; k<=C; k++){
        int a = 500*i + 100*j + 50*k;
        if(a==X)ans++;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3636
#pragma GCC optimize("O3")
#include <atcoder/all>
using namespace atcoder;
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

using mint = modint998244353;

ostream& operator<<(ostream& out, mint m){
  out << m.val();
  return out;
}

vector<mint> sum;
vector<mint> evinv;
vector<mint> mno;
vector<int> sumzw;

int n,k,nn;

void mnoz(int v, mint x){
  mno[v] *= x;
  evinv[v] *= x;
  sum[v] *= x;
}

void touch(int nr){
  if(mno[nr] != 1){
    mnoz(nr * 2, mno[nr]);
    mnoz(nr * 2 + 1, mno[nr]);
  }
  mno[nr] = 1;
}

void licz(int nr){
  sumzw[nr] = sumzw[nr * 2] + sumzw[nr*2+1];
  sum[nr] = sum[nr * 2] + sum[nr * 2 + 1];
  evinv[nr] = evinv[nr * 2] + evinv[nr * 2 + 1] + sumzw[nr * 2] * sum[nr * 2 + 1];
}

void add(int x){
  function<void(int,int,int)> rec = [&](int nr,int po,int ko){
    if(po + 1 == ko){
      sum[nr]++;
      sumzw[nr]--;
      return;
    }
    touch(nr);
    int m = (po + ko) / 2;
    if(x < m)rec(nr * 2, po ,m);
    else rec(nr * 2+1, m, ko);
    licz(nr);
  };
  rec(1,0,nn);
}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> k;
  nn = 1;while(nn <= n)nn *= 2;
  sum.resize(nn*2);
  evinv.resize(nn*2);
  mno.resize(nn*2, 1);
  sumzw.resize(nn*2);
  R(i,n){
    sumzw[i + nn] = 1;
  }
  for(int i = nn-1; i; i--){
    sumzw[i] = sumzw[i*2] + sumzw[i*2+1];
  }
  vector<int> p(n);
  R(i,n){
    cin >> p[i];
    p[i]--;
  }
  R(i,k)add(p[i]);
  debug(sum, mno, evinv, sumzw);
  mint kinv = mint(1) / k;
  mint res = 0;
  R(i,n-k){
    res += evinv[1] * kinv;
    res += mint(k-1) / 2;
    mnoz(1,(k-1) * kinv);
    add(p[i+k]);
  } 
  res += mint(k) * (k - 1) / 4;
  debug(res * 4);
  cout << res << "\n";
}


Measured memory_bytes: 15120
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int main(void)
{
	char c[5] = "RYGB";
	int n, m, k;
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i++, putchar('\n'))
		for (int j = 1; j <= m; j++)
			putchar(c[2 * ((i + j + m) / k & 1) + ((i - j + m) / k & 1)]);
	
	return 0;
}

Measured memory_bytes: 512
import java.util.*;
import java.util.ArrayDeque;
import java.util.Queue;
import java.math.RoundingMode;
import java.math.BigDecimal;



public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	   	int a = sc.nextInt();
	   	int b = sc.nextInt();
	   	int c = sc.nextInt();
	   	int d = sc.nextInt();
	   	while(a>0&&c>0) {
	   		a=a-d;
	   		c=c-b;
	   	}
	   	if(a<=0&&c<=0) {
	   		System.out.println("Yes");
	   	}
	   	else if(a<=0&&c>0) {
	   		System.out.println("No");
	   	}
	   	else if(c<=0&&a>0) {
	   		System.out.println("Yes");
	   	}
	 }
}

Measured memory_bytes: 35808
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String W=sc.next();
		int count=0;
		String line="";
		while(!(line=sc.next()).equals("END_OF_TEXT")) {
			for(String s:line.split(" ")) {
				if(s.equalsIgnoreCase(W)) {
					count++;
				}
			}
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 26144
import math

n = int(input())
s = input()
d = 0
for i in range(1, math.ceil(n / 2)):
    for j in range(i, n - i):
        if s[j - i] != s[j] and s[j] != s[j + i] and s[j - i] != s[j + i]:
            d += 1
print(s.count('R') * s.count('G') * s.count('B') - d)


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

double polygon_area(vector<pair<int, int>> v) {
	// O(n)
	double ret = 0.0;
	v.emplace_back(make_pair(v[0].first, v[0].second));
	for (int unsigned i = 0; i < v.size() - 1; i++) {
		ret += v[i].first*v[i + 1].second - v[i].second*v[i + 1].first;
	}
	return abs(ret) / 2;
}

int main() {
	int n;
	cin >> n;
	vector<pair<int,int>> v;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		v.emplace_back(make_pair(x, y));
	}
	printf("%.1f\n", polygon_area(v));
	return 0;
}

Measured memory_bytes: 3240
n =int(input())
B = list(map(int,input().split()))

A=[0]*n
i=0
A[i]=B[i]
while 1 :
    i+=1
    if i>=n-1:
        break
    A[i]=min(B[i],B[i-1])
A[i]=B[i-1]

# print(B)
# print(A)
print( sum(A) )

Measured memory_bytes: 9056
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

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

  cout << max({0,b-(a+W),a-(b+W)}) <<"\n";

}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int r,c;
  while(cin>>r>>c&&r&&c){
    int fld[r][c];
    for(int i=0;i<r;i++)for(int j=0;j<c;j++)cin>>fld[i][j];
    int ans=-1;
    for(int i=0;i<(1<<r);i++){
      int cnt[c],res=0;
      memset(cnt,0,sizeof(cnt));
      for(int j=0;j<r;j++){
        if(i>>j&1){
          for(int k=0;k<c;k++)if(fld[j][k]==1)cnt[k]++;
        }else{
          for(int k=0;k<c;k++)if(fld[j][k]==0)cnt[k]++;
        }
      }
      for(int j=0;j<c;j++)res+=max(cnt[j],r-cnt[j]);
      ans=max(ans,res);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1592
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
fn rec(n: usize, i: usize, j: usize, k: usize, memo: &mut Vec<Vec<Vec<f64>>>) -> f64 {
    if memo[i][j][k] < 0. {
        memo[i][j][k] = 0.;
        let c = (i + j + k) as f64;
        if i != 0 {
            memo[i][j][k] += rec(n, i - 1, j, k, memo) * i as f64 / c;
        }
        if j != 0 {
            memo[i][j][k] += rec(n, i + 1, j - 1, k, memo) * j as f64 / c;
        }
        if k != 0 {
            memo[i][j][k] += rec(n, i, j + 1, k - 1, memo) * k as f64 / c;
        }
        if i != 0 || j != 0 || k != 0 {
            memo[i][j][k] += n as f64 / c;
        }
    }
    memo[i][j][k]
}
fn main() {
    input! { n, a: [usize; n] };
    let mut dp = vec![vec![vec![-1.; n + 1]; n + 1]; n + 1];
    dp[0][0][0] = 0.;
    let mut c = vec![0; 4];
    for &aa in &a {
        c[aa] += 1;
    }
    println!("{}", rec(n, c[1], c[2], c[3], &mut dp));
}


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

int main()
{
		char day[5];

		cin >> day[0] >> day[1] >> day[2];

		if (day[0] == 'M')cout << 6 << endl;
		if (day[0] == 'T' && day[1] == 'U')cout << 5 << endl;
		if (day[0] == 'W')cout << 4 << endl;
		if (day[0] == 'T' && day[1] == 'H')cout << 3 << endl;
		if (day[0] == 'F')cout << 2 << endl;
		if (day[0] == 'S' && day[1] == 'A')cout << 1 << endl;
		if (day[0] == 'S' && day[1] == 'U')cout << 7 << endl;
		return 0;
	
}



Measured memory_bytes: 256
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
nn = 0
while l = $stdin.gets do
  if lc == 0
    nn = l.chomp.to_i
  else
    inputs = l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# body
if $debugFlag
  p nn
  p inputs
end

inputs.sort!
res = []

for i in 1..inputs.size-2 do
  if inputs[i] > 0
    res << "#{inputs[0]} #{inputs[i]}"
    inputs[0] -= inputs[i]
  else
    res << "#{inputs[-1]} #{inputs[i]}"
    inputs[-1] -= inputs[i]
  end
end

res << "#{inputs[-1]} #{inputs[0]}"
puts inputs[-1] - inputs[0]
res.each do |r_i|
  puts r_i
end


Measured memory_bytes: 19712
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <functional>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef long double ld;
#define fastio 	ios::sync_with_stdio(false);cin.tie(NULL)
#define printvector(vec) for(auto &v: vec){cout<<v<<" | ";}cout<<"\n";
template<typename T> ostream& operator<<(ostream &s,vector<T> vec){for(auto &v: vec){s<<v<<" ";}s<<"\n";return s;}
template<typename T> void print(T v){cout<<v<<" ";}
template<typename T, typename... Args> void print(T first, Args... args){cout<<first<<" ";print(args...);}

/*int main(){
	int x,a,b;
	cin>>x>>a>>b;
	x-=a;
	x=x%b;
	cout<<x;
}*/
map<tuple<ll,int,int,int,int>, ll> memo;
ll ways(ll x, vector<int> &val, vector<int> &coins, int pos){
	//cout<<x<<"\n";
	if(x < 0) return 0;
	if(x == 0) return 1;
	auto tp = make_tuple(x, coins[0], coins[1], coins[2], pos);
	if(memo.count(tp)){
		//cout<<"\nmemo "<<memo[tp]<<"\n";
		return memo[tp];
	}
	ll ans = 0;
	for(int i=pos; i<val.size(); ++i){
		if(coins[i] > 0){
			coins[i]--;
			ans += ways(x - val[i], val, coins, i);
			coins[i]++;
		}
	}
	//auto tp = make_tuple(x, coins[0], coins[1], coins[2]);
	return (memo[tp] = ans);
}

int main(){
	int a,b,c,x;
	cin>>a>>b>>c>>x;
	vector<int> coins {a,b,c};
	vector<int> val {500,100,50};
	//memset(memo, -1, sizeof memo);
	//cout<<val<<coins;
	cout<<ways(x, val, coins,0);
}

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

const int MAX_N=2e5+10;

int P[MAX_N],N,cnt[MAX_N],ans=0,K;
set <int> s;

int main(){
	scanf("%d%d",&N,&K);
	for(int i=0;i<N;i++) scanf("%d",&P[i]);
	for(int i=0;i<N;i++) cnt[i]=0;
	cnt[0]=0;
	for(int i=1;i<N;i++){
		if(P[i]>P[i-1]) cnt[i]=cnt[i-1]+1;
		else cnt[i]=0;
		if(cnt[i]>=K-1) ans=1; 
	}
	for(int i=0;i<K;i++) s.insert(P[i]);
	if(cnt[K-1]!=K-1) ans++;
	for(int i=K;i<N;i++){
		s.insert(P[i]);
		if(*s.begin()!=P[i-K]||*s.rbegin()!=P[i])
			if(cnt[i]<K-1) ans++;
		s.erase(P[i-K]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 11136
import java.util.*;

public class Main {
    static int[] numbers = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n, s;

        while (true) {
            n = sc.nextInt();
            s = sc.nextInt();

            if (n == 0 && s == 0) break;

            System.out.println(dfs(n, s, 0, 0, 0));
        }
    }

    private static int dfs(int n, int s, int i, int count, int sum) {
        if (count == n) {
            if (sum == s) return 1;
            else return 0;
        }
        if (i == 10) return 0;
        if (sum > s) return 0;

        return dfs(n, s, i+1, count, sum) + dfs(n, s, i+1, count+1, sum+numbers[i]);
    }
}

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

int main(){
    unsigned long N, Q;
    cin >> N >> Q;

    vector<unsigned long> A(N), AS(N + 2), S(N), X, a;
    for(auto& i : A)cin >> i;
    partial_sum(A.rbegin(), A.rend(), S.begin());
    for(unsigned long i{0}; i < N; ++i)AS[i + 2] = A[i] + AS[i];
    for(unsigned long i{0}; i * 2 < N; ++i)a.push_back(S[i] + AS[N - i * 2 - 1]);
    for(unsigned long i{1}; i * 2 < N; ++i)X.push_back(A[N - i - 1] + A[N - i * 2 - 1]);

    reverse(a.begin(), a.end());
    reverse(X.begin(), X.end());

    auto beg = begin(X), edn = end(X);
    for(long long i{0}, x; i < Q; ++i){
        cin >> x;
        cout << a[lower_bound(beg, edn, x * 2) - beg] << endl;
    }
    return 0;
}

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int n,k;
  cin >> n;
  int a[n] = {};
  int maxA = 0;
  priority_queue<int, vector<int>, greater<int> > queue;
  for(int i=0;i<n;i++){
    cin >> a[i];
    queue.push(a[i]);
    if(maxA<a[i]) maxA=a[i];
  }
  bool isMultiple[maxA+1] = {};
  int count = 0;
  int prevX = 0;
  bool isCounted = false;

  while(!queue.empty()){
    int x = queue.top();
    queue.pop();
    if(prevX == x && isCounted){
      count--;
    }
    prevX = x;
    int y = x;
    isCounted = false;
    while(y<=maxA){
      if(x==y&&!isMultiple[y]){
        count++;
        isCounted = true;
      }
   	  isMultiple[y] = true;
      y += x;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 5756
def degit(num):
    count = 0
    while num > 0:
        num //= 10
        count += 1
    return count

a = []
b = []
count = 0

while True:
    try:
        buff = input().split()
        a.append(int(buff[0]))
        b.append(int(buff[1]))
        count += 1
    except:
        break

for i in range(count):
    print(degit(a[i]+b[i]))


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

ll mod = 1e9 + 7;
ll dp[201][100001];

int main()
{
    ll n, x;
    cin >> n >> x;
    vector<ll> s(n);
    rep(i, n) cin >> s[i];
    sort(s.rbegin(), s.rend());

    dp[0][x] = 1;
    for (int i=0; i<n; ++i) {
        for (int j=0; j<=x; ++j) {
            if (dp[i][j] == 0) continue;

            dp[i+1][j%s[i]] += dp[i][j];
            dp[i+1][j%s[i]] %= mod;

            dp[i+1][j] += dp[i][j] * (n - i - 1);
            dp[i+1][j] %= mod;
        }
    }

    ll ans = 0;
    rep(i, x+1) {
        ans += dp[n][i] * i;
        ans %= mod;
    }

    cout << ans << endl;
}


Measured memory_bytes: 154240
// AtCoder Problem A [Frogs-1]

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

int n;
int dpp[100005] = {0};
int minimumCostDpBu(int *h, int n)
{
    memset(dpp, -1, 100);

    dpp[0] = 0;
    dpp[1] = abs(h[1] - h[0]);

    for (int i = 2; i < n; ++i)
    {
        int left, right;
        right = abs(h[i] - h[i - 1]) + dpp[i - 1];
        left = abs(h[i] - h[i - 2]) + dpp[i - 2];
        dpp[i] = min(left, right);
    }
    return dpp[n - 1];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    int h[n];
    for (int i = 0; i < n; i++)
        cin >> h[i];
    cout << minimumCostDpBu(h, n) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main() {
	int n, m, l;
	int	A[101][101], B[101][101];
	long C[101][101]={ {} };
	cin >> n >> m >> l;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> A[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < l; j++) {
			cin >> B[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			for (int k = 0; k < m; k++) {
				C[i][j] += A[i][k] * B[k][j];
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			if (j == 0)
				cout << C[i][j];
			else cout << ' ' << C[i][j];
		}
		cout << endl;
	}
}


Measured memory_bytes: 3204
// header {{{
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <queue>
#include <map>
#include <list>
#include <stack>
#include <tuple>
#include <cstdio>
#include <cmath>
using namespace std;

#define kita            cout << "kita\n"
#define print2(i, n)    cout << (i) << ": " << (n) << endl
#define print3(i, j, n)     cout << "(" << (i) << ", " << (j) << ") : " << (n) << endl
#define print4(i, j, n, m)  cout << "(" << (i) << ", " << (j) << ") : " << (n) << ", " << (m) << endl
#define print_mat(mat, h, w) for(int i=0;i<(h);i++){for(int j=0;j<(w);j++){cout << mat[i][j] << " ";}cout << endl;}

#define EPS (1e-10)
#define EQ(a, b) (fabs((a)-(b)) < eps)

typedef long long ll;
typedef unsigned long long ull;
// }}}
// number {{{
#define SIZE 100005
#define MOD  1000000007LL

// べき乗
// verified AOJ NTL_1_B
ll pow(ll a, ll b) {
    if(b == 0) return 1;
    ll aa = pow(a, b/2);
    return aa*aa%MOD*(b%2 == 1 ? a : 1)%MOD;
}

ll fact[SIZE] = {1, 1};
ll finv[SIZE] = {1, 1};

void fact_init() {
    // fact
    for(ll i=2;i<SIZE;i++){
        fact[i] = fact[i-1]*i%MOD;
    }

    // finv
    finv[SIZE-1] = pow(fact[SIZE-1], MOD-2);
    for(ll i=SIZE-1;i>=3;i--){
        finv[i-1] = finv[i]*i%MOD;
    }
}

ll comb(int n, int r) {
    if(r > n) return 0;
    return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD;
}

ll gcd(ll x, ll y) {
    return y ? gcd(y, x%y) : x;
}
//}}}

int main() {
    fact_init();
    int n;

    cin >> n;

    vector<int> pos(n, -1);

    int l, r;

    for(int i=0;i<n+1;i++){
        int aa;
        cin >> aa;
        aa--;
        if(pos[aa] != -1){
            l = pos[aa];
            r = i;
        }
        pos[aa] = i;
    }

    for(int k=1;k<=n+1;k++){
        ll ans = comb(n+1, k) - comb(l+n-r, k-1);
        if(ans < 0){
            ans += MOD;
        }
        printf("%lld\n", ans);
        // cout << comb(n+1, k) << endl;
    }

    return 0;
}


Measured memory_bytes: 3200
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . ___
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         佛祖保佑       永无BUG
*/
//use readint!
#include<map>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<stdio.h>
#include<fstream>
#include<assert.h>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<string.h>
#define mp make_pair
#define ll long long
using namespace std;
const int INF=1e9;
inline int pt(int a[],int l,int r){
	int p,i,j;
	p=a[l];
	i=l;
	j=r+1;
	for(;;){
		while(a[++i]<p) if(i>=r) break;
		while(a[--j]>p) if(j<=l) break;
		if(i>=j) break;
		else swap(a[i],a[j]);
	}
	if(j==l) return j;
	swap(a[l],a[j]);
	return j;
}
inline void q_sort(int a[],int l,int r){
	int q;
	if(r>l){
		q=pt(a,l,r);
		q_sort(a,l,q-1);
		q_sort(a,q+1,r);
	}
}
inline int readint(){
    int x=0;
    int f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') ch=getchar();
	if(ch=='-'){
		f=-1;
		ch=getchar();
	}
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
char c[55][55];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int n,m;
int main(){
	cin>>n>>m;
	int i,j,k;
	for(i=0;i<n;i++) for(j=0;j<m;j++) cin>>c[i][j];
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			if(c[i][j]=='.') continue;
			bool ok=0;
			for(k=0;k<4;k++){
				if(i+dx[k]<n&&i+dx[k]>-1&&j+dy[k]<m&&j+dy[k]>-1){
					if(c[i][j]=='#'&&c[i+dx[k]][j+dy[k]]=='#') ok=1;
				}
			}
			if(!ok){
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

class line
{
public:
    long long a;
    long long b;

    line()
    {
        ;
    }

    line(long long A, long long B)
    {
        a = A;
        b = B;
    }

    long long eval(long long x)
    {
        return a*x + b;
    }
};

vector<line> L;

void insert(line k)
{
    if(L.size() <= 1) L.push_back(k);
    else
    {
        line l1 = L[L.size()-2];
        line l2 = L[L.size()-1];
        if((l2.b - l1.b) > (l2.b - k.b)*(l1.a - l2.a)/(k.a - l2.a))
        {
            L.pop_back();
            insert(k);
        }
        else L.push_back(k);
    }
}

long long b_search(long long x, long long a, long long b)
{
    if(a == b) return L[a].eval(x);
    long long m = (a+b)/2;
    if((L[m+1].b - L[m].b) < x*(L[m].a - L[m+1].a)) return b_search(x, m+1, b);
    else return b_search(x, a, m);
}

int main()
{
    long long N, C;
    cin >> N >> C;

    long long h[N+1];
    for(long long i = 1; i <= N; i++) cin >> h[i];

    long long DP[N+1];
    DP[1] = 0;
    insert(line(-2*h[1], h[1]*h[1]));
    for(long long i = 2; i <= N; i++)
    {
        DP[i] = C + h[i]*h[i] + b_search(h[i], 0, L.size()-1);
        insert(line(-2*h[i], DP[i] + h[i]*h[i]));
    }
    cout << DP[N] << '\n';
    return 0;

    //DP[1] = 0;
    //DP[i] = C + h[i]^2 + min{1 <= j < i; (-2*h[j])*h[i] + (DP[j] + h[j]^2)}
}

Measured memory_bytes: 9200
# -*- coding: utf-8 -*-
"""
AtCoder A
"""
import math
# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column

# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
from operator import itemgetter

def main():
    N = int(input())
    S=[]
    P=[]
    for i in range(N):
        s, p = str(input()).split()
        # list(map(int,input().split()))
        S.append([s,int(p)])
        P.append(p)
    # out=sorted(S,key=itemgetter(0,-1),re)
    # print(out)
    indx=sorted(range(len(S)), key=lambda k: S[k])
    # indx=sorted(range(len(S)), key=lambda k,i: S[k][0], S[i][1])
    # print(indx)
    # print(indx)
    prei=S[indx[0]][0]
    tmp=[]
    out=[]
    for i in indx:
        if prei!=S[i][0]:
            if tmp:
                tlist=sorted(range(len(tmp)), key=lambda k: tmp[k])
                tlist.reverse()
                for t in tlist:
                    out.append([prei,tmp[t]])
                tmp=[]
            prei=S[i][0]
        tmp+=[S[i][1]]
        prei=S[i][0]

    tlist=sorted(range(len(tmp)), key=lambda k: tmp[k])
    tlist.reverse()
    for t in tlist:
        out.append([prei,tmp[t]])
    # print(out)
    for o in out:
        print(S.index(o)+1)
    # S.sort()




    # print(math.floor((A*3+B)/2))
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 38768
//%:pragma GCC optimize("Ofast")
//%:pragma GCC target("sse3","sse2","sse")
//%:pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
//%:pragma GCC target("f16c")
//%:pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
//%:pragma GCC diagnostic error "-fwhole-program"
//%:pragma GCC diagnostic error "-fcse-skip-blocks"
//%:pragma GCC diagnostic error "-funsafe-loop-optimizations"
//%:pragma GCC diagnostic error "-std=c++14"

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>

using namespace std;

#define Whats(x) cout<<#x<<" is "<<x<<endl
#define Divhe() cout<<">>>>>>>>>>>>>>>"<<endl
#define Divshe() cout<<"<<<<<<<<<<<<<<<"<<endl
#define Oops() cout<<"!!!!!!!!!!!!!!!"<<endl

/*
-<Unlimited Blade Works>-
*/

const int N=5200;
const int MOD=1e9+7;

int Mul(int a,int b)
{
	unsigned long long x=(long long)a*b;
	unsigned xh=(unsigned)(x>>32),xl=(unsigned)x,d,m;
	asm
		(
		 "divl %4;\n\t"
		 :"=a"(d),"=d"(m)
		 :"d"(xh),"a"(xl),"r"(MOD)
		);
	return m;
}

int U(int x,int y)
{
	return ((x+=y)>=MOD)?(x-MOD):x;
}

void SU(int& x,int y)
{
	((x+=y)>=MOD)?(x-=MOD):0;
}

int D(int x,int y)
{
	return ((x-=y)<0)?(x+MOD):x;
}

void SD(int& x,int y)
{
	((x-=y)<0)?(x+=MOD):0;
}

int n;
vector<int> G[N];

int sz[N],dp[N][N],cm[N];

void Dfs(int u,int fa=0)
{
	sz[u]=dp[u][1]=1;
	for(int v:G[u])if(v!=fa)
	{
		Dfs(v,u);
		int sm=0;
		for(int i=2;i<=sz[v];i+=2)
			SD(sm,Mul(dp[v][i],cm[i]));
		int rec=sz[u];
		for(int i=(sz[u]+=sz[v]);i>=1;--i)
		{
			int& t=dp[u][i];
			t=Mul(t,sm);
			for(int j=max(1,i-sz[v]),k=min(i,rec);j<=k;++j)
				SU(t,Mul(dp[u][j],dp[v][i-j]));
		}
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1,u,v;i<n;++i)
	{
		scanf("%d%d",&u,&v);
		G[u].emplace_back(v);
		G[v].emplace_back(u);
	}

	cm[0]=1;
	for(int i=2;i<=n;i+=2)
		cm[i]=Mul(cm[i-2],i-1);

	Dfs(1);

	int ans=0;
	for(int i=2;i<=n;i+=2)
		SU(ans,Mul(dp[1][i],cm[i]));
	printf("%d",ans);
	return 0;
}


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

using namespace std;


void solve() {
    int x, y;
    cin >> x >> y;
    int res = max({x+y,x-y, x*y});
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)


int main(){
    int q;
    cin >> q;
    set<ll> st;
    map<ll,int> mp;
    ll sm = 0;
    ll mid = 0;
    ll s = 0;
    int p = 1;
    int cnt = -1;
    rep(zz,q){
        int sss;
        cin >> sss;
        if(sss==1){
            cnt++;
            ll a,b;
            cin >> a >> b;
            sm += b;
            st.insert(a);
            mp[a]++;
            if(zz==0){
                mid = a;
            }else{
                if(mid<=a){
                    if(cnt%2==1){
                        s += a-mid;
                        
                    }else{
                        s += a-mid;
                        auto itr = st.lower_bound(mid);
                        if(p+1>mp[mid]){
                            ll pp = mid;
                            p = 1;
                            itr++;
                            mid = *itr;
                            s -= mid-pp;
                        }else{
                            p++;
                        }
                    }
                }else{
                    s += mid-a;
                    if(cnt%2==0){
                    }else{
                        if(p-1==0){
                            auto itr = st.lower_bound(mid);
                            itr--;
                            mid = *itr;
                            p = mp[mid];
                        }else{
                            p--;
                        }
                    }

                }
            }
        }else{
            cout << mid << " " << s+sm << endl;
        }
    }
    return 0;
}

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

  int main() {
    string S;
    cin >> S;
    if (S == "AAA") {
    cout << "No" << endl;
    }
    else if (S == "BBB") {
    cout << "No" << endl;
    }
    else {
      cout << "Yes" << endl;
    }
 }





Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	static double xa,ya,xb,yb,xc,yc,xd,yd;
	static String strArray[];

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;


		while((str=br.readLine()) != null){
			strArray = str.split(",");
			initialize();

			double jac = closs(xa, ya, xc, yc, xd, yd);
			double jca = closs(xc, yc, xa, ya, xb, yb);
			double jbd = closs(xb, yb, xd, yd, xa, ya);
			double jdb = closs(xd, yd, xb, yb, xc, yc);

			if((jac>0 && jca>0 && jbd>0 && jdb>0) || (jac<0 && jca<0 && jbd<0 && jdb<0)){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}

		}

	}

	static double closs(double x1, double y1, double x2, double y2, double xp, double yp){
		return ( (y2-y1)*xp + (x1-x2)*yp + x2*y1 - x1*y2);
	}

	private static void initialize() {
		xa = Double.parseDouble(strArray[0]);
		ya = Double.parseDouble(strArray[1]);
		xb = Double.parseDouble(strArray[2]);
		yb = Double.parseDouble(strArray[3]);
		xc = Double.parseDouble(strArray[4]);
		yc = Double.parseDouble(strArray[5]);
		xd = Double.parseDouble(strArray[6]);
		yd = Double.parseDouble(strArray[7]);
	}
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

ll dp[100005];

int main()
{
    fastio();

    ll h,n;
    cin>>h>>n;
    vector<ll>a(n),b(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
    }

    // dp[j] -> min cost with total damage j
    for(int j=0;j<=100003;j++)
        dp[j] = INF;
    dp[0] = 0;
    for(int i=0;i<n;i++)
    {
        for(int j=a[i];j<=100003;j++)
        {
            dp[j] = min( dp[j], dp[j-a[i]] + b[i] );
        }
    }

    ll ans = INF;
    for(int j=h;j<=100003;j++)
        ans = min( ans, dp[j] );
    cout<<ans,nl;


    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;
typedef pair<ll,ll> P;


int main(){
    string s,t;cin>>s>>t;
    ll cn=0;
    rep(i,0,s.size()){
        if(s[i]!=t[i])cn++;
    }
    cout<<cn<<endl;
}

    









Measured memory_bytes: 3844
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    n,k,c = map(int,input().split())
    s = input()

    R = [-1] * k
    L = [-1] * k
    day = INF
    cnt = 0
    for i in range(n):
        if s[i] == 'o':
            if day > c:
                L[cnt] = i
                cnt += 1
                if cnt == k:
                    break
                day = 1
            else:
                day += 1
        else:
            day += 1
    
    day = INF
    cnt = k - 1
    for i in range(n - 1,-1,-1):
        if s[i] == 'o':
            if day > c:
                R[cnt] = i
                cnt -= 1
                if cnt < 0:
                    break
                day = 1
            else:
                day += 1
        else:
            day += 1
    
    ans = []
    for j in range(k):
        if R[j] == L[j]:
            ans.append(R[j] + 1)

    print(*ans,sep = '\n')

if __name__ =='__main__':
    main()  

Measured memory_bytes: 31720
import java.math.BigDecimal;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		BigDecimal n = sc.nextBigDecimal();
		BigDecimal m = sc.nextBigDecimal();
		
		System.out.println(n.multiply(m).setScale(0, BigDecimal.ROUND_DOWN));
	}

}



Measured memory_bytes: 37360
S = list(str(input()))
s = [i for i in range(2*len(S)-1) if i % 2 == 1]
ans = 0
for i in range(1 << len(s)):
    L = [S[(i+1)//2] if i % 2 == 0 else "" for i in range(2*len(S)-1)]
    output = []
    for j in range(len(s)):
        if ((i >> j) & 1) == 1:
            output.append(s[j])
    for i in range(len(L)):
        if i in output:
            L[i] = "+"
    ans += eval("".join(L))
print(ans)

Measured memory_bytes: 3064
# https://atcoder.jp/contests/abc127/tasks/abc127_d
import itertools as it

N, M = map(int, input().split())
A = [int(s) for s in input().split()]
A.sort()

pairs = [tuple(int(s) for s in input().split()) for _ in range(M)]
pairs.sort(key=lambda tup: tup[1], reverse=True)

iterable = it.chain.from_iterable([it.repeat(v, times=count) for (count, v) in pairs])
# print(list(iterable))

res = sum(A)
for (old, new_) in zip(A, iterable):
    if old <= new_:
        res += new_ - old
    else:
        break

print(res)


Measured memory_bytes: 27920
// https://atcoder.jp/contests/

#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

ll sx, sy, tx, ty;
string p;

void move(string &p, char d, int c)
{
  REP(i, c)
  {
    p += d;
  }
}

int main()
{
  p = "";
  cin >> sx >> sy >> tx >> ty;

  move(p, 'U', ty - sy);
  move(p, 'R', tx - sx);
  move(p, 'D', ty - sy);
  move(p, 'L', tx - sx);

  p += 'L';
  move(p, 'U', ty - sy + 1);
  move(p, 'R', tx - sx + 1);
  p += "DR";
  move(p, 'D', ty - sy + 1);
  move(p, 'L', tx - sx + 1);
  p += 'U';

  cout << p << '\n';

  return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn.readLine

object Main extends App {

  val s = readLine().toCharArray
  val t = readLine().toCharArray

  var matchCount = 0

  for (i <- 0 to s.length - t.length) {
    var cnt = 0
    for (j <- 0 until t.length)
      if (s(i + j) == t(j)) cnt += 1
    if (matchCount < cnt) matchCount = cnt
  }
  println(t.length - matchCount)
}


Measured memory_bytes: 54608
import heapq
t = 1
def max(a,b):
	if a > b:
		return a
	return b
def min(a,b):
	if a < b:
		return a
	return b

while t > 0:
	t -= 1
	n,k = map(int,input().split())
	# n = int(input())
	# a = list(map(int,input().strip().split()))[0:n]
	# b = list(map(int,input().strip().split()))[0:n]
	# c = list(map(int,input().strip().split()))[0:n-1]
	s = input()
	i = 0
	ans = 0
	c = 0
	d = 0
	while(i < n):
		j = i
		# c += 1
		if s[i] == 'R':
			c += 1
		else:
			d += 1
		while j+1 < n and s[j+1] == s[i]:
			j += 1
		l = j-i+1
		ans += (l-1)
		i = j+1
	c = min(c,d)
	# print()
	if s[0] == s[n-1]:
		if k < c:
			# print("a")
			ans += 2*k
		else:
			# print("b")
			ans += 2*(c)
	else:
		if k < c:
			# print("a")
			ans += 2*k
		else:
			ans += 2*(c-1)
			ans += 1
		# ans += 1
		# ans += 1
	print(ans)


Measured memory_bytes: 73120
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int n,l,r,t;
long long s,dis[1000005],ans;
struct node
{
	long long len,num;
}q[1000005];
bool cmp(node t1,node t2)
{
	return t1.len<t2.len;
}
int main()
{
	scanf("%d%lld",&n,&s);
	for (int i=1;i<=n; i++)
		scanf("%lld%lld",&q[i].len,&q[i].num);
	sort(q+1,q+1+n,cmp);
	l=1,r=n,t=2;
	while (q[l].len<s && q[r].len>s)
	{
		if (q[l].num<q[r].num) q[r].num+=q[l].num,dis[r]+=dis[l]+((t!=0)?(q[r].len-q[l].len):0),t=0,l++;
		else q[l].num+=q[r].num,dis[l]+=dis[r]+((t!=1)?(q[r].len-q[l].len):0),t=1,r--;
	}
	if (q[l].len>s) ans=dis[r]+q[r].len-s;else ans=dis[l]+s-q[l].len;
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
  long long n,m;
  cin >> n >> m;
  vector<long long int> a(m);
  for(auto& x:a)
    cin >> x;
  vector<long long int> dp(n+1);
  for(auto& x:dp)
    x=-1;
  dp.at(0) = 1;
  dp.at(1) = 1;
  for(auto& x:a)
    dp.at(x) = 0;
  
  for(auto i=2;i<=n;i++){
    if(dp.at(i)==0)
      continue;
    else
      dp.at(i) = dp.at(i-1)%(1000000007) + dp.at(i-2)%(1000000007);
  }
  cout << dp.at(n)%1000000007 << endl;
}
  

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static List<int>[] li;
	static bool[] b;
	static int[] h;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		int n=s[0],m=n-1;
		li=new List<int>[n+1];
		b=new bool[n+1];
		h=new int[n+1];
		for(int i=1;i<=n;i++){li[i]=new List<int>();}
		for(int i=0;i<m;i++){
			var e=sc.Ia;
			li[e[0]].Add(e[1]);
			li[e[1]].Add(e[0]);
		}
		Console.WriteLine("{0}",Fu(1)!=0?"Alice":"Bob");
	}
	static int Fu(int a){
		b[a]=true;
		int g=0;
		for(int i=0;i<li[a].Count;i++){
			if(!b[li[a][i]]){g^=Fu(li[a][i])+1;}
		}
		return g;
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 35468
s = gets.chomp
h = {}
s.each_char { |c| h[c] = 1 }

[*'a'..'z'].each do |c|
  (puts s + c; exit) unless h.key?(c)
end

tmp = "\0"
idx = 0

s.reverse.each_char do |c|
  break if tmp > c

  idx += 1
  tmp = c
end

(puts -1; exit) if idx == 26

size = s.size
c = s[size - 1 - idx]
chr = s[(size - idx)..-1].chars.sort.detect { |e| c < e }

puts s[0...(size - 1 - idx)] + chr

Measured memory_bytes: 1788