akhauriyash/Code-Regression huggingface dataset:
class Node
  attr_reader :go, :come

  def initialize(id)
    @id = id
    @go = []
    @come = []
  end
end

class Arrow
  attr_reader :source, :sink, :label
  
  def initialize(source, sink, label)
    @source = source
    @sink = sink
    @label = label
    source.go << self
    source.come << self
  end
end

class Result
  attr_reader :target, :spell

  def initialize(target, spell)
    @target = target
    @spell = spell
  end
end

def advance(table, nodes, arrows)
  next_table = table
  nodes.each do |node|
    best = table[node]
    node.go.each do |arrow|
      result = table[arrow.sink]
      next unless result
      test = arrow.label + result.spell
      if !best || test < best.spell
        best = Result.new(arrow.sink, test)
      end
    end
    next_table[node] = best if best
  end
  next_table
end

def check(table, result)
  return false unless result

  used = {}
  loop do
    node = result.target
    return true unless node
    return false if used[node]
    used[node] = true
    result = table[node]
  end
end

def work(nodes, arrows, start, goal)
  table = {goal => Result.new(nil, '')}
  (nodes.size*6).times do
    table = advance(table, nodes, arrows)
  end
  result = table[start]
  puts check(table, result) ? result.spell : 'NO'
end

loop do
  n, a, s, g = STDIN.gets.split.map(&:to_i)
  break if n == 0

  nodes = (0...n).map{|i| Node.new(i)}

  arrows = (0...a).map do |i|
    x, y, lab = STDIN.gets.split
    x = x.to_i
    y = y.to_i
    Arrow.new(nodes[x], nodes[y], lab)
  end

  start = nodes[s]
  goal = nodes[g]

  work(nodes, arrows, start, goal)
end

Measured memory_bytes: 105628
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <limits.h>
using namespace std;
typedef long long ll;
const int inf=1<<30;
const int INF=INT_MAX;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  vector<pair<int, int>> v;
  cin >> n >> m;
  for(int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());
  int remain = m;
  ll yen = 0;
  for(int i = 0;; ++i) {
    if(remain <= 0) {
      break;
    }
    if(v[i].second <= remain) {
      remain -= v[i].second;
      yen += (ll)v[i].first * v[i].second;
    } else {
      yen += (ll)v[i].first * remain;
      remain = 0;
    }
  }
  cout << yen << endl;

  return 0;
}


Measured memory_bytes: 1400
S = input()
N = len(S)


subS1 = S[:int((N - 1) / 2)]
subS2 = S[int((N + 3) / 2) - 1:]

if subS1 == subS1[::-1] and subS2 == subS2[::-1] and S == S[::-1]:
    print("Yes")
else:
    print("No")


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

#define REP(i,n) for(ll i=0;i<(n);i++)
#define REAP(i,a,n) for(ll i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);

    ll n,m,k;
    cin >> n >> m >> k;

    vector<ll> suma(n+1);
    vector<ll> sumb(m+1);
    ll a,b;

    ll ai=-1,bi=0;
    ll ans = 0;
    bool flg=false;

    REP(i,n){
        cin >> a;
        suma[i]=a;
        if(i!=0){
            suma[i]+=suma[i-1];
        }
        if(suma[i]<=k){
            ans=max(ans,i);
            ai=i;
            flg=true;
        }
    }
    REP(i,m){
        cin >> b;
        sumb[i]=b;
        if(i!=0){
            sumb[i]+=sumb[i-1];
        }
        if(sumb[i]<=k){
            ans=max(ans, i);
            flg=true;
        }
    }

    while(ai>=0){
        ll ama=k-suma[ai];
        while(sumb[bi]<=ama&&bi<m){
            bi++;
        }
        ans = max(ans, ai+bi);
        ai--;
    }
    if(flg)cout << ans+1 << endl;
    else cout << 0 << endl;
}


Measured memory_bytes: 6340
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#define ll long long int
#define MOD 1000000007LL
using namespace std;
int main() {
    int n;
    cin>>n;
    ll ans=1;
    for(int i=1;i<=n;i++){
        ans*=i;
        if(ans>MOD){
            ans=ans%MOD;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
n, m = map(int, input().split())
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        A = [a[s][i:i+m] for s in range(j,j+m)]
        if A == b:
            print("Yes")
            sys.exit()
print("No")

Measured memory_bytes: 3064
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let a: usize = sc.read();
    let b: usize = sc.read();
    let mut result1 = "".to_string();
    for _ in 0..b {
        result1.push_str(&a.to_string());
    }
    let mut result2 = "".to_string();
    for _ in 0..a {
        result2.push_str(&b.to_string());
    }
    let result = if result1 <= result2 { result1 } else { result2 };
    println!("{}", result);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 8572
#include<iostream>
#include<vector>

using namespace std;

int main() {
	int n, l, r;
	cin >> n >> l >> r;
	while (1) {
		if (n == 0 && l == 0 && r == 0)break;
		vector<int>a(n);
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int ans = 0;

		for (int x = l; x <= r; x++) {
			for (int i = 0; i < n; i++) {
				if (x%a[i] == 0) {
					if (i % 2 == 0) {
						ans++;
						break;
					}
					else break;
				}
				if (i == n-1 && n % 2 == 0)ans++;
			}
		}
		cout << ans << endl;
		cin >> n >> l >> r;
	}
}


Measured memory_bytes: 3092
#include<stdio.h>
int main(){
  int n,m,i,s=0,d[200010],a=0;
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++)scanf("%d",&d[i]);
  for(i=0;i<m;i++)s+=d[i];
  for(a=s;i<n;i++){//printf("%d\n",a);
    s+=d[i]-d[i-m];
    if(a<s)a=s;
  }//printf("%d\n",a);
  printf("%lf\n",(a+m)/2.0);
  return 0;
}


Measured memory_bytes: 896
import java.util.Scanner;

public class Main {
  private static Scanner sc;

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

  private void solve() {
    int N = sc.nextInt();
    int[] a = new int[N + 2];
    for (int i = 0; i < N; i++) {
      a[i + 1] = sc.nextInt();
    }
    int sum = 0;
    for (int i = 0; i <= N; i++) {
      sum += Math.abs(a[i] - a[i + 1]);
    }

    for (int i = 0; i < N; i++) {
      System.out.println(sum - Math.abs(a[i] - a[i + 1]) - Math.abs(a[i + 2] - a[i + 1]) + Math.abs(a[i] - a[i + 2]));
    }
  }
}


Measured memory_bytes: 63720
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e16;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;

const ll MAX_V = 1e5;

struct edge { ll to, cost; };
typedef pair<ll, ll> P;
vector<edge> GA[MAX_V];
vector<edge> GB[MAX_V];
ll dA[MAX_V];
ll dB[MAX_V];

void dijkstra(ll start, ll vv, vector<edge> G[], ll d[]){
	priority_queue<P, vector<P>, greater<P>>que;
	fill(d, d + vv, INF);
	d[start] = 0;
	que.push(P(0, start));

	while (!que.empty()){
		P p = que.top(); que.pop();
		ll v = p.second;
		if (d[v] < p.first) continue;
		for (ll i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

bool comp_p(const pll& l, const pll& r){
	return l.second < r.second;
}

int main(){
	ll n, m, s, t;
	cin >> n >> m >> s >> t;
	s--;
	t--;
	vll U, V, A, B;
	ll i, j;
	for (i = 0; i < m; i++){
		ll u, v, a, b;
		cin >> u >> v >> a >> b;
		U.push_back(u);
		V.push_back(v);
		A.push_back(a);
		B.push_back(b);
		edge eva, evb, eua, eub;
		eva.to = v - 1;
		eva.cost = a;
		eua.to = u - 1;
		eua.cost = a;
		GA[u - 1].push_back(eva);
		GA[v - 1].push_back(eua);
		evb.to = v - 1;
		evb.cost = b;
		eub.to = u - 1;
		eub.cost = b;
		GB[u - 1].push_back(evb);
		GB[v - 1].push_back(eub);
	}
	dijkstra(s, n, GA, dA);
	dijkstra(t, n, GB, dB);

	vector<pll> X;
	for (i = 0; i < n; i++){
		ll x = dA[i] + dB[i];
		X.push_back(pll(i, x));
	}
	sort(X.begin(), X.end(), comp_p);

	ll w = 1e15;
	ll pos = 0;
	for (i = 0; i < n; i++){
		if (X[pos].first >= i){
			cout << w - X[pos].second << endl;
		}
		else{
			while (X[pos].first < i){
				pos++;
			}
			cout << w - X[pos].second << endl;
		}
	}
}

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

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

  int ans = 0;
  for (int i = 1; i <= N; i += 2) {
    int n = 0;
    for (int j = 1; j <= N; j++) {
      if (i % j == 0)
        n++;
    }
    if (n == 8)
      ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#define int long long
using namespace std;
const int maxn=5086;
const int mod=1000000007;
struct EDge
{
	int to,next;
}e[maxn<<1];
int head[maxn],cnt;
void add(int a,int b)
{
	e[++cnt].to=b,e[cnt].next=head[a],head[a]=cnt;
}
int n,dp[maxn][maxn],siz[maxn];
int g[maxn],tmp[maxn];
void dfs(int u,int fa)
{
	dp[u][1]=1,siz[u]=1;
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].to; 
		if(v==fa) continue;
		dfs(v,u);
		for(int j=0;j<=siz[u];++j)
		{
			for(int k=0;k<=siz[v];++k)
				tmp[j+k]=(tmp[j+k]+dp[u][j]*dp[v][k])%mod;
		}
		siz[u]+=siz[v];
		for(int i=0;i<=siz[u];++i)
			dp[u][i]=tmp[i],tmp[i]=0;
	}
	for(int i=2;i<=siz[u];i+=2)
		dp[u][0]=(dp[u][0]+dp[u][i]*g[i])%mod;
	if(u>1) dp[u][0]=mod-dp[u][0];
}
signed main()
{
	scanf("%lld",&n);
	for(int i=1,x,y;i<n;++i) 
	{
		scanf("%lld%lld",&x,&y);
		add(x,y),add(y,x);
	}
	g[0]=1; for(int i=2;i<maxn;i+=2) g[i]=g[i-2]*(i-1)%mod;
	int ans=0; dfs(1,0);
	printf("%lld\n",dp[1][0]);
	return 0;
}

Measured memory_bytes: 91876
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<pair<int, int>, int> PP;
const ll INFL = 1LL << 60;
const ll MOD = 1000000007;
const int INF = 1000000000;
const int MAX = 300000;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
//------------------------------------------------------------------------------------------------------------------------------

int main(void) {
    int N;
    ll M;
    cin >> N >> M;
    ll L = 1;
    int cnt = -1;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        a /= 2;
        L = LCM(L, a);
        int t = 1;
        while (true) {
            if (a % 2 == 1) {
                break;
            }
            a /= 2;
            t++;
        }
        if (cnt != -1 && t != cnt) {
            cout << 0 << endl;
            return 0;
        }
        cnt = t;
    }

    cout << ((M / L) + 1) / 2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int dp[50010];
//i????????????????°??????°
int n, m;
VI c;

int main(void) {
	scanf("%d%d", &n, &m);
	c.resize(m);
	for_each(ALL(c), [](int &e){scanf("%d", &e);});
	REP(i, 50010) dp[i] = INF;
	dp[0] = 0;
	FORE(e, c) REP(j, 50010) if (j + e < 50010) {
		dp[j + e] = min(dp[j] + 1, dp[j + e]);
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 3408
#include<bits/stdc++.h>
using namespace std;
 
int main () {
  int a,b;
  cin >>a>>b;
  if(a>12){
    cout<<b<<endl;
  }else if(a>5){
    cout<<b/2<<endl;
  }else{
    cout<<0<<endl;
  }
return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A, B, res;

		A = scanner.nextInt();
		B = scanner.nextInt();

		scanner.close();
		
		res = A*B;
		
		if(res%2 == 0){
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}
	}
}


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

using namespace std;

int main()
{
    int N, H;
    cin >> N >> H;
    int a[N], b[N];

    int max_A=0;
    for(int i=0;i<N;i++)
    {
        cin >> a[i] >> b[i];
        max_A=max(a[i], max_A);
    }
    sort(b, b+N, greater<int>());

   long long int sum=0, counter=0;
   long long int ans=0;
    for(int i=0;i<N;i++)
    {
        if(b[i]>max_A)
        {
            sum=sum+b[i];
            counter++;
            if(sum>=H)
            {
                break;
            }
        }

        else
        {
            break;
        }
    }
    ans=counter;
    H=H-sum;

    if(H>0)
    {
    if(H%max_A==0)
    {
        ans=ans+H/max_A;
    }

    else
    {
        ans=ans+(H/max_A)+1;
    }
    }
    cout << ans;
}


Measured memory_bytes: 4404
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	s := readString()
	b := []byte(s)
	k := readInt64()

	//n := 5000000000000000
	i := int64(0)
	for i < k {
		c := int(b[i] - '0')
		if c != 1 {
			println(c)
			return
		}
		i++
	}
	println(1)
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;

int dfs(string key);

map<string,int> mny;
map<string,vector<string> > rsp;

int main(){
	int n,m;
	string na;
	while(1){
		mny.clear();
		rsp.clear();
		cin >> n;
		if(n == 0) break;
		for(int i=0;i<n;i++){
			int mo;
			cin >> na >> mo;
			mny[na] = mo;
		}
		cin >> m;
		for(int i=0;i<m;i++){
			int k;
			cin >> na >> k;
			string str;
			for(int j=0;j<k;j++){
				cin >> str;
				rsp[na].push_back(str);
			}
		}
		cin >> na;
		cout << dfs(na) << endl;
	}
}

int dfs(string key){
	int rec=0;
	if(rsp[key].size()){
		int len = rsp[key].size();
		for(int i=0;i<len;i++){
			rec += dfs(rsp[key][i]);
		}
	}
	else {
		rec = mny[key];
	}
	if(mny[key] < rec) rec = mny[key];
	return rec;
}

Measured memory_bytes: 1232
import sys

sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, W = map(int, readline().split())
things = []
for i in range(N):
    weight, value = map(int, readline().split())
    things.append((weight, value))


def solve():
    dp = [0] * (W + 1)
    w0, v0 = things[0]
    for i in range(w0, W + 1):
        dp[i] = v0
    for i in range(1, N):
        dn = list(dp)
        weight, value = things[i]
        for j in range(weight, W + 1):
            dn[j] = max(dn[j], dp[j - weight] + value)
        dp = dn
    return dp[W]


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 118128
n = int(input())
L = list(input())
R = list(input())
mod = 1000000007
if n==1:print(3);exit()
ans = 3 if R[0]==L[0] else 6
for i in range(1,n):
    if L[i-1]==R[i-1]:
        if L[i]==R[i]:
            ans *=2
        else:
            ans *=2
    else:
        if L[i]!=L[i-1]:
            if L[i]==R[i]:
                continue
            else:
                ans *= 3
    ans %=mod
print(ans)

Measured memory_bytes: 61956
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
#include <map>
#include <cassert>
using namespace std;

const int maxn = 1e5 + 5;
int n, activity[maxn][3];
int happiness, choice[maxn][3];


int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> activity[i][0] >> activity[i][1] >> activity[i][2];
	for (int i = 1; i <= n; i++) {
		for(int j = 0; j < 3; j++) {
			for(int k = 0; k < 3; k++) {
				if(k != j){
					choice[i][j] = max(choice[i - 1][k] + activity[i][j], choice[i][j]);
				}
			}

		}
	}
	for (int i = 0; i < 3; i++) happiness = max(happiness, choice[n][i]);
	cout << happiness << endl;

	return 0;

}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------


int main(){
  int N;
  cin >> N;
  vector<int> p(N),q(N);
  for(int i=0; i<N; i++){
    cin >> p[i];
  }
  for(int i=0; i<N; i++){
    cin >> q[i];
  }
  vector<int> vec(N);
  for(int i=1; i<=N; i++){
    vec[i-1] = i;
  }
  int p_num,q_num;
  int cnt = 1;
  do{
    bool p_can=true,q_can=true;
    for(int i=0; i<N; i++){
      if(vec[i] != p[i]) p_can = false;
      if(vec[i] != q[i]) q_can = false;
    }
    if(p_can){
      p_num = cnt;
    }
    if(q_can){
      q_num = cnt;
    }
    cnt++;
  }while(next_permutation(vec.begin(),vec.end()));
  cout << abs(p_num-q_num) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iterator>
#include <list>
#include <algorithm>
#include <iostream>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <sstream>
#include <iomanip>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
using namespace std;

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

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

  int ans = 0;
  for (int i = 0; i + 2 < N; i++) {
    vector<int> s{p[i], p[i+1], p[i+2]};
    sort(s.begin(), s.end());
    if (s[1] == p[i+1])
      ++ans;
  }

  cout << ans << endl;

  return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
string S;
ll mo=1000000007;
ll dp[3030][3030];
int ma[3030];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>S;
	
	int CR=0,CL=0;
	int B[2]={};
	dp[0][0]=1;
	while(M--) {
		int L,R;
		cin>>L>>R;
		L--,R--;
		while(CL<L) {
			if(CL==CR) {
				B[S[CR]=='1']++;
				CR++;
			}
			FOR(i,3001) if(dp[CL][i]) {
				int T[2]={i,CL+1-i};
				if(i<B[0]) (dp[CL+1][i+1]+=dp[CL][i])%=mo;
				if(CL-i<B[1]) (dp[CL+1][i]+=dp[CL][i])%=mo;
			}
			CL++;
		}
		while(CR<=R) {
			B[S[CR]=='1']++;
			CR++;
		}
	}
	while(CL<N) {
		if(CL==CR) {
			B[S[CR]=='1']++;
			CR++;
		}
		FOR(i,3001) if(dp[CL][i]) {
			int T[2]={i,CL+1-i};
			if(i<B[0]) (dp[CL+1][i+1]+=dp[CL][i])%=mo;
			if(CL-i<B[1]) (dp[CL+1][i]+=dp[CL][i])%=mo;
		}
		CL++;
	}
	
	cout<<dp[CL][B[0]]<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 12800
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k  = sc.nextInt();
		int h[] = new int[n];
		int c = 0;
		
		for(int i = 0;i<n;i++) {
			h[i] = sc.nextInt();
		}
		
		for(int i = 0;i<n;i++) {
			if(h[i] >= k) {
				c++;
			}
		}
		
		System.out.println(c);

		sc.close();
	}
}



Measured memory_bytes: 49928
#include <iostream>
#include <vector>


using namespace std;
int N,M;
vector<int> s, c;

vector<int> z;

int main()
{

	cin >> N;
	cin >> M;

	s = c = vector<int>(M);

	for (int j = 0; j < M; j++) {
		cin >> s[j];
		s[j]--;
		cin >> c[j];
	}

	int ans = 0;

	z = vector<int>(N, -1);
	for (int j = 0; j < M && ans != -1; j++) {
		if (z[s[j]] != -1) {
			if (z[s[j]] != c[j]) {
				ans = -1;
			}
		}
		else if (s[j] == 0 && c[j] == 0 && N > 1) {
			ans = -1;
		}
		else {
			z[s[j]] = c[j];
		}
	}

	if (ans != -1) {
		for (int j = 0; j < N; j++) {
			ans *= 10;
			if (z[j] == -1) {
				if (j == 0 && N > 1) {
					ans += 1;
				}
			}
			else {
				ans += z[j];
			}
		}
	}



	cout << ans << endl;

	return 0;
}

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

int main() {
  int r;
  cin >> r;
  cout << r * r << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

void solve() {
	string s; cin >> s;
    int n = (int)s.size();
    cout << s.substr(0,n - 8) << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int a[3][100032];
long long ans=0;
int main(){
	cin>>n;
	for(int i=0;i<3;i++){
		for(int j=0;j<n;j++) cin>>a[i][j];
		sort(a[i],a[i]+n);
	}
	int i=0,k=0;
	for(int j=0;j<n;j++){
		while(a[0][i]<a[1][j]&&i<n) i++;
		while(a[1][j]>=a[2][k]&&k<n) k++;
		ans+=(long long)i*(n-k);
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll n,ans;
bool check(ll n){
  bool a,b,c;
  a=b=c=false;
  string s=to_string(n);
  for(auto si:s){
    if(si=='7')a=true;
    if(si=='5')b=true;
    if(si=='3')c=true;
  }
  return a&b&c;
}
void dfs(ll x){
  if(x>n)return;
  if(check(x))ans++;
  dfs(x*10+3);
  dfs(x*10+5);
  dfs(x*10+7);
}
main(){
  cin>>n;
  dfs(0);
  cout<<(ans)<<endl;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    char[] S = scanner.next().toCharArray();
    int c0 = 0;
    int c1 = 0;
    for (char c : S) {
      if (c == '0') c0++;
      else c1++;
    }
    System.out.println(Math.min(c0, c1) * 2);
  }
}


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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
typedef vector<vector<int>> VV;
#define INF (int)(1e9+1)
#define MAXX (int)1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (ll)(1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
//ceil(a/(double)b)=(a+b-1)/b
//printf("myco\n");//for debug
/*--------------------------------------------*/
int main(){
    int a,b,c;cin>>a>>b>>c;
    if(a<=c&&c<=b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
/*{{{*/
#include<bits/stdc++.h>
#define sz(X) ((int)(X).size())
#define all(X) (X).begin(), (X).end()
#define rep(I, A, B) for (int I = (A); I <= (B); ++I)
#define repr(I, A, B) for (int I = (A); I >= (B); --I)
#define fors(I, S) for (int I = 0; S[I]; ++I)
#define get_pos(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define mp make_pair
#define pb emplace_back
#define ms0(X) memset((X), 0, sizeof((X)))
#define ms1(X) memset((X), -1, sizeof((X)))
#define len(X) strlen(X)
#define in insert
#define cn count
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef set<int> si;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T, class U> void _W(const pair<T, U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
#define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
#define DEBUG(...)
#endif
int MOD = 1e9 + 7;
/*}}}*/
void solve() {
	int a, b;
	R(a, b);
	string a1, b1;
	rep(i, 0, b - 1)
	a1 += to_string(a);
	rep(i, 0, a - 1)
	b1 += to_string(b);
	W(min(a1, b1));
}

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

#define MULTITEST 0
#if MULTITEST
	CASET {
		solve();
	}
#else
	solve();
#endif
	return 0;
}


Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
string s;
int n,k;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n>>k;
	cin>>s;
	s[k-1]=s[k-1]-('A'-'a');
	cout<<s; 
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;

ll x[100002], cal[100002];
ll suml[100002], sumr[100002];
ll mal[100002], mar[100002];

int main() {
	ll n, c; cin >> n >> c;
	for (int i = 1; i <= n; i++) {
		cin >> x[i] >> cal[i];
	}
	for (int i = 1; i <= n; i++) suml[i] = suml[i - 1] + cal[i];
	for (int i = n; i >= 1; i--) sumr[i] = sumr[i + 1] + cal[i];
	for (int i = 1; i <= n; i++) mal[i] = max(mal[i - 1], suml[i] - x[i]);
	for (int i = n; i >= 1; i--) mar[i] = max(mar[i + 1], sumr[i] - (c - x[i]));
	ll ans = max(mal[n], mar[1]);
	for (int i = 1; i <= n; i++) ans = max(ans, mal[i] + mar[i + 1] - x[i]);
	for (int i = n; i >= 1; i--) ans = max(ans, mar[i] + mal[i - 1] - (c - x[i]));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
using namespace std;

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long M, std::vector<long long> A){
    long long sum = 0;
    for(int i = 0; i < A.size(); i++) {
        sum += A[i];
    }

    long long count = 0;
    for(int i = 0; i < A.size(); i++) {
        if((float)A[i] >= (float)sum / ((float)4*M)) {
            count++;
        }
    }

    if(count >= M)  {
        cout << YES << endl;
        return;
    }

    cout << NO << endl;
    return;
 }

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, std::move(A));
    return 0;
}


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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.length()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>())
#define REV(a) reverse(begin(a),end(a));

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////
	int a,b,h;
	cin >> a >> b >> h;
	cout << ((a+b)*h)/2 << endl;

	
//////////////////////////////////////////////
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;

    int num = 1;
    for (int i = 0; i < N;i++){
        if(num*2<num+K){
            num *= 2;
        }else{
            num += K;
        }
    }
    cout << num;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int N = 0;
    int result = 0;
    int str[256] = {};
    
    scanf("%d",&N);
    for (int j=0; j<N; j++) {
        scanf("%d",&str[j]);
    }
    
    int hikaku = str[0];
    result++;
    for (int i=1; i<N; i++) {
        if (hikaku <= str[i]) {
            result++;
            hikaku  = str[i];
        }
    }
    
    printf("%d",result);
    return 0;
}

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

int main() {
  ll Q, H, S, D, N;
  cin >> Q >> H >> S >> D >> N;
  ll ans = 0;
  
  //2Lの最安値V;
  ll V;
  V = min({8*Q, 4*H, 2*S, D, S+H*2, S+4*Q, S+2*Q+H, 3*H+2*Q, 2*H+4*Q,
          H+6*Q});
  ans += (N/2)*V;
  
  //1Lの最安値v
  ll v;
  v = min({4*Q, 2*H, S, H+2*Q});
  if (N % 2 == 1) {
    ans += v;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 384
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n, m;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k,a,b;
    cin >> k>>a>>b;
    for(int i=a;i<=b;i++){
        if(i%k==0)return cout<<"OK"<<"\n",0;
    }
    cout<<"NG"<<"\n";
}


Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<tuple>
using namespace std;
const int N=25;
const int MOD=1000000007;
int n,m;
int x[N*N],y[N*N];
long long ksm(long long a,long long b)
{
	long long res=1;
	while(b)
	{
		if(b&1) res=res*a%MOD;
		a=a*a%MOD,b>>=1;
	}
	return res;
}
long long fac[N*N],inv[N*N];
void init(int n=400)
{
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%MOD;
	inv[n]=ksm(fac[n],MOD-2);
	for(int i=n;i>=1;i--)
		inv[i-1]=inv[i]*i%MOD;
	return;
}
struct Union_Set
{
	int fa[N];
	void init()
	{
		for(int i=0;i<n;i++)
			fa[i]=i;
		return;
	}
	int getf(int v)
	{
		if(v==fa[v]) return v;
		fa[v]=getf(fa[v]);
		return fa[v];
	}
	void merge(int u,int v)
	{
		int f1=getf(u),f2=getf(v);
		if(f1!=f2) fa[f2]=f1;
		return;
	}
};
tuple<int,int,long long,long long> f[1<<N]; 
int main()
{
	init();
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		scanf("%d%d",&x[i],&y[i]);
		x[i]--,y[i]--;
	}
	for(int S=0;S<(1<<(n-1));S++)
	{
		Union_Set D;
		D.init();
		int b=n-1,num=m;
		for(int i=0;i<n-1;i++)
			if(S&(1<<i))
			{
				D.merge(x[i],y[i]);
				b--,num--;
			}
		for(int i=n-1;i<m;i++)
			if(D.getf(x[i])==D.getf(y[i])) num--;
		f[S]=make_tuple(num,b,0,0);
	}
	f[(1<<(n-1))-1]=make_tuple(0,0,1,0);
	for(int S=(1<<(n-1))-1-1;S>=0;S--)
		for(int i=0;i<n-1;i++)
			if(!(S&(1<<i)))
			{
				int T=S|(1<<i);
				int &n=get<0>(f[T]),&sn=get<0>(f[S]);
				int k=sn-n-1;
				long long &c=get<2>(f[T]),&sc=get<2>(f[S]);
				sc=(sc+fac[n+k]*inv[n]%MOD*c%MOD)%MOD;
				int &sb=get<1>(f[S]);
				long long &s=get<3>(f[T]),&st=get<3>(f[S]);
				st=((st+fac[n+k+1]%MOD*inv[n+1]%MOD*s%MOD)%MOD+sb*fac[n+k]%MOD*inv[n]%MOD*c%MOD)%MOD;
			}
	printf("%lld",get<3>(f[0]));
	return 0;
}


Measured memory_bytes: 16136
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    int K;
    cin>>s>>K;
    int n=s.size();
    int dp[110][2][5];
    //dp[i][j][k]:i桁目まで見た時にjで未満が確定して、0でない数字の個数がk個のものの個数
    for(int i=0;i<=n;i++){
        for(int j=0;j<2;j++){
            for(int k=0;k<5;k++)dp[i][j][k]=0;
        }
    }
    dp[0][0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<2;j++){
            for(int k=0;k<4;k++){
                int lim=j?9:s[i]-'0';
                for(int l=0;l<=lim;l++){
                    if(l!=0){
                        dp[i+1][j||l<lim][k+1]+=dp[i][j][k];
                    }else{
                        dp[i+1][j||l<lim][k]+=dp[i][j][k];
                    }
                }
            }
        }
    }
    cout<<dp[n][0][K]+dp[n][1][K]<<endl;
}

Measured memory_bytes: 256
X, Y = gets.split.map(&:to_i)
key = 0
X.times do |i|
	turu = X - i
	kame = X - turu
	if turu*2 + kame * 4 == Y
		key = 1
		puts "Yes"
		break
	end
end

if X*4 == Y
	key = 1
	puts "Yes"
end

if key == 0
	puts "No"
end

Measured memory_bytes: 14372
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

puts 2*Math::PI*gets.to_i

Measured memory_bytes: 14396
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

set<ll> edge;
void outp(ll c){
    auto ite = edge.end();
    --ite;
    ll a = *ite;
    cout<<a<<' ';
    edge.erase(a);
    auto ite2 = edge.upper_bound(c - a);
    --ite2;
    cout<<*ite2<<' ';
    edge.erase(ite2);
    cout<<c<<endl;
    return;
}

int main() {
    cin>>N>>K;
    if(K*2 > N + 1){
        cout<<-1<<endl;
    }else{
        vector<bool> used(N,false);
        reps(i,K,K + N * 2) edge.insert(i);
        Rreps(i, K + N * 3, K + N * 2){
            if(i&1){
                used.at(i - K - N * 2) = true;
                outp(i);
            }
        }
        Rreps(i, K + N * 3, K + N * 2){
            if(!used.at(i - K - N * 2)) outp(i);
        }
    }
}

Measured memory_bytes: 11648
#include<stdio.h>
#include<stdlib.h>
#define INFTY 1000000000

void merge(int*,int,int,int);
void mergeSort(int*,int,int);
int cnt=0;

int main(){
  int A[500000];
  int i,n;

  scanf("%d",&n);

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

  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i<n-1)
      printf(" ");
  }
  printf("\n%d\n",cnt);

  return 0;
}

void merge(int A[], int l, int m, int r){
  int n1,n2,i,j,k;
  int *L,*R;

  n1=m-l;
  n2=r-m;
  L=(int *)malloc(sizeof(int)*(n1+1));
  R=(int *)malloc(sizeof(int)*(n2+1));

  for(i=0;i<=n1-1;i++){
    L[i]=A[l+i];
  }
  for(i=0;i<=n2-1;i++){
    R[i]=A[m+i];
  }

  L[n1]=INFTY;
  R[n2]=INFTY;

  i=0;
  j=0;

  for(k=l;k<=r-1;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
      cnt++;
    }
    else{
      A[k]=R[j];
      j++;
      cnt++;
    }
  }
  free(L);
  free(R);
}

void mergeSort(int A[],int l,int r){
  int i,m;
  if(l+1<r){
    m=(l+r)/2;
    mergeSort(A,l,m);
    mergeSort(A,m,r);
    merge(A,l,m,r);
  }
}

Measured memory_bytes: 4476
use std::io;

fn main() {
    let (a, b) = input();

    if a > b {
        println!("a > b");
    } else if a < b {
        println!("a < b");
    } else {
        println!("a == b");
    }
}

fn input() -> (i32, i32) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();

    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();

    (a, b)
}




Measured memory_bytes: 5024
#include <bits/stdc++.h>
using namespace std;
const int maxn = 101;
multiset<string> sp;
int main() {
	int x, y, z;
	scanf("%d%d%d", &x, &y, &z);
	while(x--)
		sp.insert("a");
	while(y--)
		sp.insert("b");
	while(z--)
		sp.insert("c");
	while(sp.size() > 1) {
		string fir = *sp.begin();
		sp.erase(sp.begin());
		string las = *sp.rbegin();
		sp.erase(sp.find(las));
		sp.insert(fir + las);
	}
	puts(sp.begin() -> c_str());
	return 0;
}

Measured memory_bytes: 384
import bisect,collections,copy,heapq,itertools,math,string
import sys
def li(): return map(int,sys.stdin.readline().rstrip().split())
def lf(): return map(float,sys.stdin.readline().rstrip().split())
def ls(): return sys.stdin.readline().rstrip().split()

n, x = li()
p = list(li())
gcd = abs(x-p[0])
for i in range(n):
    gcd = math.gcd(gcd, abs(x-p[i]))

print(gcd)    

Measured memory_bytes: 21468
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
#define fst first
#define snd second
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

void solve(long long n, string S){
	vector<int> b(n+1);
	for (int i=0;i<n;i++) {
		assert(i<S.length());
		b[i+1]=b[i]+(S[i]=='#'?1:0);
	}
	int w=0;
	int ans=INT_MAX;
	for (int x=n;x>=0;x--) {
		// >=x is black. <x is white
		if (x<n&&S[x]=='.') ++w;
		chkmin(ans,w+b[x]);
	}
	printf("%d\n",ans);
}

int main(){	
	ios_base::sync_with_stdio(false); cin.tie(0);
	long long N;
	string S;
	cin >> N>>S;
	solve(N, S);
	return 0;
}



Measured memory_bytes: 1556
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll mod=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x*=2;
  return x;
}
mint choose (int n,int a) {
  mint x = 1,y =1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x /y;
}
int main(void){
    // Your code here!
    int n,a,b ; cin >> n >> a >> b;
    mint ans = f(n);
    ans -=1;
    ans -=choose(n,a);
    ans -=choose(n,b);
    cout << ans.x << endl;
}



Measured memory_bytes: 256