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

int main () {
    int N;
    
    scanf("%d",&N);
    
    int Xarr[N];
    int i;
    int count = 0;
    
    for (i=0; i<N; i++) {
        scanf("%d",&Xarr[i]); 
    }
    
    int stamina_min = 0;
    int stamina = 0;
    int P = Xarr[0];
    int Pmax = Xarr[0];

    for (i=1; i<N; i++) {
        if (Xarr[i] > Pmax) {
            Pmax = Xarr[i];
        }
        if (Xarr[i] < P) {
            P = Xarr[i];
        }
    }
    
    for (i=0; i<N; i++) {
        stamina_min += (Xarr[i]-P)*(Xarr[i]-P);    
    }
    
    while (P <= Pmax) {
        for (i=0; i<N; i++) {
            stamina += (Xarr[i]-P)*(Xarr[i]-P);    
        }
        if (stamina < stamina_min) {
            stamina_min = stamina;    
        }
        stamina = 0;
        P++;
    }
    
    printf("%d", stamina_min);
    
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

VI a;
bool is_satisfied(int key) {
    return abs(a[key] * 2 - a.back()) - abs(a[key - 1] * 2 - a.back()) < 0;
}

// TTTTFFFFのときのTの最大indexを求めたいならsearch_max=true
// FFFFTTTTのときのTの最小indexを求めたいならsearch_max=false
int binary_search(int min, int max, bool search_max) {
    min--;
    max++;
    while(max - min > 1) {
        int mid = (max + min) / 2;
        if(is_satisfied(mid)) min = mid;
        else max = mid;
    }
    return search_max ? min : max;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    a.resize(n);
    REP(i, n) cin >> a[i];
    sort(ALL(a));
    cout << a.back() << " " << a[binary_search(1, n - 1, true)] << endl;
      
    return 0;
}


Measured memory_bytes: 640
#import <bits/stdc++.h>
using namespace std;typedef int l;
#define rp(i,n) for(l i=0;i<n;++i)
l main(){l n;cin>>n;l v[99];for(char c='A';c<='C';++c)cin>>v[c];string s[220000];rp(i,n)cin>>s[i];char a[220000];rp(i,n){char x=s[i][0],y=s[i][1],M=(v[x]>=v[y]?x:y),m=x^y^M;if(v[x]==v[y]&&i+1<n&&(s[i+1][0]==x||s[i+1][1]==x))swap(M,m);if(v[M]==0){puts("No");return 0;}v[M]--,v[m]++;a[i]=m;}puts("Yes");rp(i,n)cout<<a[i]<<'\n';}

Measured memory_bytes: 10568
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
typedef pair<P,P>P2;
#define F first
#define S second
std::chrono::system_clock::time_point start;
std::chrono::system_clock::time_point owari;

signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	r(i,a){
		if(i)cout<<' ';
		if(i<b)cout<<c;
		else{
			if(c!=1000000000)cout<<c+1;
			else cout<<1;
		}
	}
	cout<<endl;
}


Measured memory_bytes: 1280
/// hi_im_manh :D
#include <bits/stdc++.h>
#define reset(a,n) memset(a,0,(n+1)*sizeof(int))
#define endl "\n"
#define llmin LLONG_MIN
#define llmax LLONG_MAX
#define intmax INT_MAX
#define intmin INT_MIN
#define ll long long
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define duckman "TASK"

#define input freopen(duckman".inp", "r", stdin);
#define output freopen(duckman".out", "w", stdout);

#define nmax 22000
using namespace std;

void max_self(ll &a, ll b) {
    a = max(a, b);
}
int main()
{
    fast;
//    input;
//    output;

    ll n, weight;
    cin >> n >> weight;
    vector<ll> dp(weight+1);
    for (int i = 0; i < n; ++i) {
        ll v, w;
        cin >> w >> v;
        for (ll weight_already = weight - w; weight_already >= 0; --weight_already) {
            max_self(dp[weight_already+w], dp[weight_already] + v);
        }
    }
    cout << dp[weight];
}

/*

*/


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n, d, x; cin >> n >> d >> x;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		int m; cin >> m;
		a.at(i) = d / m;
		if (d % m != 0) a.at(i)++;
	}
	int m = 0;
	for (int i = 0; i < n; i++) {
		m += a.at(i);
	}
	cout << m + x << endl;
}

Measured memory_bytes: 3576
n = int(input())
data = []
for _ in range(n):
  data.append( int(input()) )

data_s = sorted(data)

for d in data:
  if d == data_s[-1]:
    print(data_s[-2])
  else:
    print(data_s[-1])

# print(data)
# print(data_s)


Measured memory_bytes: 14112
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e5+5;

int dp[maxn], arr[maxn];

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	dp[1] = 0;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
		if (i != 1) dp[i] = 1e18;
		for (int j = i - 1; j >= max(1ll, i - k); j--) {
			dp[i] = min(dp[i], dp[j] + abs(arr[i] - arr[j]));
		}
	}
	
	cout << dp[n] << "\n";
}

Measured memory_bytes: 5196
n,m = map(int,input().split())
l = [list(map(int,input().split()))[1:]for i in range(m)]
p = list(map(int,input().split()))

form ="0"+str(n)+"b"
ans = 0
for i in range(2**n):
    ptn = format(i,form)
    light = True
    for j in range(m):
        s = sum(int(ptn[k-1])for k in l[j])
        if s%2 !=p[j]:
            light = False
    if light == True:
        ans += 1

print(ans)


Measured memory_bytes: 3064
use std::io::Read;

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

fn main() {
    let n: usize = read();
    let a: Vec<u32> = (0..n).map(|_| read()).collect();

    let mut w: Vec<(u32, usize)> = vec![(0, 0); n];
    for i in 0..n {
        w[i] = (a[i], i);
    }
    w.sort();
    for (_, i) in w {
        println!("{}", i + 1);
    }
}


Measured memory_bytes: 6908
'use strict';
(function(stdin) {
  // define function
  var f = function(a, b, c) {
    if (a < b && b <c) {
      return'Yes';
    }else{
      return'No';
    }
  };
  // declare variable
  var inputs = stdin.toString().trim().split('\n');
  var cols = inputs[0].split(' ');
  var a = parseInt(cols[0], 10);
  var b = parseInt(cols[1], 10);
  var c = parseInt(cols[2], 10);
  // main

  console.log(f(a, b, c));
  // display

}(require('fs').readFileSync('/dev/stdin', 'utf8')));
//

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

int main(){
	int n=0;
	while(cin>>n){
		if(n!=0){
			int a=0,b=0;
			while(n-->0){
				int x=0,y=0;
				cin>>x>>y;
				if(x>y){
					a+=x+y;
				}
				if(x==y){
					a+=x;
					b+=y;
				}
				if(x<y){
					b+=x+y;
				}
			}
			cout<<a<<' '<<b<<endl;
		}
	}
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N; cout << N * N * N << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

int main(){
    int N,M;
    int T[100];
    int P[100];
    int X[100];

    cin >> N;
    for(int i=0;i<N;i++) cin >> T[i];
    cin >> M;
    for(int i=0;i<M;i++) cin >> P[i] >> X[i];

    for(int i=0;i<M;i++){
        int sum=0;
        for(int j=0;j<N;j++){
            if(j==P[i]-1) sum+=X[i];
            else sum+=T[j];
        }
        cout << sum << endl;
    }

    return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

ll modPow(const ll a, const ll n, const ll p)
{
    if (n == 1) return a % p;
    if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
    ll num = modPow(a, n / 2, p);
    return (num * num) % p;
}

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;

    ll allComb = modPow(2, n, MOD);
    allComb = allComb != 0 ? allComb - 1 : MOD - 1;

    ll resA = 1;
    REP(i, a)
    {
        resA *= n - i;
        resA = resA % MOD;
    }
    ll resInvA = 1;
    REP(i, a)
    {
        resInvA *= i + 1;
        resInvA = resInvA % MOD;
    }
    resInvA = modPow(resInvA, MOD - 2, MOD);
    resA = (resA * resInvA) % MOD;

    ll resB = 1;
    REP(i, b)
    {
        resB *= n - i;
        resB = resB % MOD;
    }
    ll resInvB = 1;
    REP(i, b)
    {
        resInvB *= i + 1;
        resInvB = resInvB % MOD;
    }
    resInvB = modPow(resInvB, MOD - 2, MOD);
    resB = (resB * resInvB) % MOD;

    ll ans = allComb;
    ans = ans - resA < 0 ? ans - resA + MOD : ans - resA;
    ans = ans - resB < 0 ? ans - resB + MOD : ans - resB;

    cout << ans << endl;
}


Measured memory_bytes: 256
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let n=nin()
  if(n%2==0)out(n)
  else out(n*2)
}
main();

Measured memory_bytes: 7372
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main()
{
	int n;
	int a[100];
	int ans;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	ans = a[n-1] - a[0];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  long long a=1,b=1,c=1;
  for(int i =0;i<n;i++)
  {
    a = a*10;
    a = a%1000000007;
    b = b*9;
    b = b%1000000007;
    c = c*8;
    c = c%1000000007;
    //cout<<a<<b<<c<<'\n';
  }
  long long ans = a;
  ans = ans+c;
  ans = ans%1000000007;
  ans = ans-b;
  if(ans<0)
    ans = 1000000007-abs(ans);
  ans = ans-b;
  if(ans<0)
    ans = 1000000007-abs(ans);
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3616
S = input()

res_list = []

def my_recursion(res):
    if len(res) >= len(S):
        return ''

    my_recursion(res + '0')
    my_recursion(res + '+')
    if len(res) == len(S)-1:
        res_list.append(res)

    return res_list
# print(my_recursion(''))
# print(len(my_recursion('')))
res_list = my_recursion('')

temp_S_list = []

for item in res_list:
    temp_S = ''
    for i, j in enumerate(item):
        temp_S += S[i]+j
    temp_S += S[-1]
    S_done_eval = eval(temp_S.replace('0', ''))
    temp_S_list.append(S_done_eval)

print(sum(temp_S_list))

Measured memory_bytes: 3064
n, m = map(int, input().split())
X = list(map(int, input().split()))
X.sort()

if n >= m:
    print(0)
    exit()

sa = []

for i in range(1, m):
    sa.append(abs(X[i] - X[i - 1]))

sa.sort(reverse=True)
# print(sa)
# print((max(X) - min(X)))
print((max(X) - min(X)) - sum(sa[:n-1]))


Measured memory_bytes: 20460
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
long long int a[333],b[333],c[333],d[333];

int main(){
    int n,k;
    cin>>n>>k;
    int a[200200],p[200200];
    rep(i,0,200201)p[i]=0;
    rep(i,0,n){
        cin>>a[i];
        p[a[i]]++;
    }
    sort(p,p+n,greater<int>());
    
    int ans=0;
    rep(i,0,k)ans+=p[i];
    if(n-ans>=0)cout<<n-ans<<endl;
    else cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 1792
def main():
    l,r = map(int, input().split())
    
    ans = 10**8

    if r - l + 1 >= 2019:
        print(0)
        exit()

    for i in range(l,r):
        for j in range(i+1,r+1):
            tmp = (i*j) % 2019
            ans = min(ans, tmp)
            if ans == 0:
                break
        if ans == 0:
            break

    print(ans)
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 39408
N, Ma, Mb = gets.split.map(&:to_i)
M = Rational(Ma, Mb)
xr = []
N.times do
  xr << gets.split.map(&:to_i)
end
xr.sort!{|a, b| Rational(a[0], a[1]) <=> Rational(b[0], b[1])}

MEMO = {}
def dft(xr, i, a, b)
  ans = 0
  k = [i, a, b]
  mx = (b == 0) ? 0 : Rational(a, b)
  if MEMO.has_key?(k)
    return MEMO[k]
  end
  if mx == M 
    ans = 0
  elsif mx > M || i == N
    ans = 10000
  else
    a1 = a + xr[i][0]
    b1 = b + xr[i][1]
    ans = [dft(xr, i + 1, a, b), dft(xr, i + 1, a1, b1) + xr[i][2]].min
  end
  return MEMO[k] = ans
end 

ans = dft(xr, 0, 0, 0)
if ans >= 10000
  puts "-1"
else
  puts ans
end 

Measured memory_bytes: 34556
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;

int a[MAXN], b[MAXN];
int main() {
    int n;
    cin >> n;
    map<int, int> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        m[a[i]]++;
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
        m[b[i]]++;
    }
    for (auto it : m) {
        if (it.second > n) {
            cout << "No\n";
            return 0;
        }
    }
    reverse(b, b + n);
    int l = 0, r = n - 1;
    for (int i = 0; i < n; i++) {
        if (a[i] == b[i]) {
            if(a[i] != b[l] and a[l] != b[i]) {
                swap(b[l], b[i]);
                l ++;
            }
            else {
                swap(b[r], b[i]);
                r --;
            }
        }
    }
    cout << "Yes\n";
    for (int i = 0; i < n; i++) cout << b[i] << " ";
    cout << endl;
}


Measured memory_bytes: 14356
n = int(input())
import math
lim = math.ceil(math.sqrt(n))
l = [0]*n
for x in range(1, lim):
    for y in range(1, lim):
        for z in range(1, lim):
            i = (x+y+z)**2 - (x*y + y*z + z*x)
            if (0<i) and (i<n+1):
                l[i-1] += 1
for i in l:
    print(i)

Measured memory_bytes: 69076
#include<bits/stdc++.h>
#define mod (long)(1e9 + 7)
using namespace std;

long dp[10000][2][100];

long solve(int curr, int tight, int sum, string &s, int d) {
	if(curr == s.size()) {
		return (sum == 0);
	}
	if(dp[curr][tight][sum] != -1) return dp[curr][tight][sum];
	if(tight) {
		long res = 0;
		for(int i = 0; i <= (s[curr] - '0'); ++i) {
			res = (res + solve(curr + 1, tight & (i == (s[curr]-'0')), (sum + i) % d, s, d)) % mod;
		}
		return dp[curr][tight][sum] = res;
	}
	long res = 0;
	for(int i = 0; i < 10; ++i) {
		res = (res + solve(curr + 1, tight, (sum + i) % d, s, d)) % mod;
	}
	return dp[curr][tight][sum] = res;
}

int main() {
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	
	string k;
	int d;
	cin >> k >> d;
	memset(dp, -1, sizeof dp);
	cout << (solve(0, 1, 0, k, d) - 1 + mod) % mod;

	return 0;
}

Measured memory_bytes: 20172
from heapq import heappush, heappop

N = int(input())
a = [int(i) for i in input().split()]

b = [N] * N
c = [-1] * N

h = []
for i in range(N) :
    while len(h) > 0 and -h[0][0] > a[i] :
        b[h[0][1]] = i
        heappop(h)
    heappush(h, (-a[i], i))

h = []
for i in range(N - 1, -1, -1) :
    while len(h) > 0 and -h[0][0] > a[i] :
        c[h[0][1]] = i
        heappop(h)
    heappush(h, (-a[i], i))

ret = 0
for i in range(N) :
    ret += a[i] * (b[i] - i) * (i - c[i])
print(ret)

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

long h,w,white;
vector<bool> is_white;
vector<long> aaa;

void dfs(long a,long b) {
  aaa[a]=b;
  if(a+w<h*w) if(is_white[a+w]&&b+1<aaa[a+w]) dfs(a+w,b+1);
  if(a-w>=0) if(is_white[a-w]&&b+1<aaa[a-w]) dfs(a-w,b+1);
  if(a%w!=w-1) if(is_white[a+1]&&b+1<aaa[a+1]) dfs(a+1,b+1);
  if(a%w!=0) if(is_white[a-1]&&b+1<aaa[a-1]) dfs(a-1,b+1);
  return;
}

int main() {
  white=0;
  cin >> h >> w;
  for(int i=0;i<h;i++) {
    string s;
    cin >> s;
    for(int j=0;j<w;j++) {
      is_white.push_back(s[j]=='.');
      if(s[j]=='.') white++;
      aaa.push_back(99999);
    }
  }
  dfs(0,1);
  if(aaa[h*w-1]<99999) cout << white-aaa[h*w-1] << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {

fast();

{
  int n;
  cin>>n;
  cout<<n/3<<endl;

  
  
  

}
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    int n,y;
    cin >> n >> y;
    for(int i = 0; i*10000 <= y && i <= n; i++) {
        int rem = y - i*10000;
        for(int j = 0; j*5000 <= rem && j+i <= n; j++) {
            int rrem = rem - j*5000;
            int k = rrem/1000;
            if(i+j+k == n) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int n, ans; cin >> n;
    ans = 0;
    for (int i = 0; i < n; i++)
    {
        int li, ri;
        cin >> li >> ri;
        for (int j = li; j <= ri; j++) ans++;
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
void main()
{
    string s = rdStr;

    bool ok = true;
    foreach (i, x; s)
    {
        if (i & 1)
        {
            if (x != 'i') ok = false;
        }
        else
        {
            if (x != 'h') ok = false;
        }
    }

    if (s.length & 1) ok = false;

    writeln(ok ? "Yes" : "No");
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> X(M);
    for (int i = 0; i < M; i++) cin >> X[i];

    if (N >= M) cout << 0 << endl;
    else {
        sort(X.begin(), X.end());
        vector<int> L;
        for (int i = 1; i < M; i++) L.push_back(X[i] - X[i - 1]);
        sort(L.begin(), L.end());
        reverse(L.begin(), L.end());
        int ans = 0;
        for (int i = 0; i < N - 1; i++) ans += L[i];
        cout << X[M - 1] - X[0] - ans << endl;
    }
}

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

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  
  int n = 10 * g + b;
  if (n % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

int a, b;

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

  int add = b - 1;
  int aa = a - 1;
  cout << (add + aa - 1) / aa;
}


Measured memory_bytes: 3568
#include<stdio.h>
 
int main(void) {
 
    int N, K, d;
    int i = 0, time = 0, temp;
    int flag = 0;
    int Sunuke[100];
  	for(int i=0;i<100;i++){
    	Sunuke[i] = 0;
    }
 
    scanf("%d", &N);
    scanf("%d", &K);
 
    while (time < K) {
      scanf("%d", &d);
      for (i = 0; i < d; i++) {
        scanf("%d", &temp);
        Sunuke[(temp - 1)] = 1;
      }
      time++;
    }
 
    for (i = 0; i < N; i++) {
      if (Sunuke[i] != 1) {
        flag++;
      }
    }
    printf("%d\n", flag);
 
    return 0;
}


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

typedef long long ll;

int main () {

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

    for(int i=0; i<N; i++) {
	for(int j=0; j<N; j++) {
	    // 左上の位置
	    if( N-i < M or N-j < M ) continue;
	    bool f = true;
	    for(int k=0; k<M; k++) {
		for(int l=0; l<M; l++) {
		    if( a[i+k][j+l] != b[k][l] ) f = false;
		}
	    }
	    if(f){
		cout << "Yes" << endl;
		return 0;
	    }
	}
    }
    cout << "No" << endl;
    return 0;
}


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

int main(){
    int a, b;
    cin >> a >> b;
    cout << max(0, a-2*b) << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
def MixJuice():

    Num = list(map(int,input().split()))

    value = list(map(int,input().split()))

    value.sort()

    total = 0

    for i in range(Num[1]):
        total = total + value[i]

    print(total)

if __name__ == '__main__':
    MixJuice()



Measured memory_bytes: 9184
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*

fun main() {
    val jin = BufferedReader(InputStreamReader(System.`in`))
    val n = jin.readLine().toInt()
    val colors = jin.readLine()
    val white = LinkedList<Int>()
    for (j in 0 until n) {
        if (colors[j] == 'W') {
            white.add(j)
        }
    }
    var answer = 0
    for (j in n - 1 downTo 0) {
        if (colors[j] == 'R' && white.isNotEmpty() && white[0] < j) {
            white.removeFirst()
            answer++
        }
    }
    println(answer)
}

Measured memory_bytes: 45344
import itertools
N_ = input()
N = int(N_) 
n = len(list(N_)) #Nの桁数

#(方針) N<=10**9 だと3,5,7のみを使ってできる数は多くても3**9=2*10**4通りなので全探索
A = ['3','5','7']

ans = 0
if(n >= 3): #桁数が3以上なら
 for i in range(3,n+1):
  Comb = list(itertools.product(A, repeat=i)) #重複組み合わせ
  
  for j in range(len(Comb)):
   tmp = list(Comb[j])
   #print(tmp) #########
   judge = 1 #条件を満たす数: 1,満たさない数: 0
    
   #選んだ数がN以下かの判定
   tmp_num = ''
   for k in range(len(tmp)):
     tmp_num += tmp[k]
   tmp_num = int(tmp_num)
   if(tmp_num > N):
      judge = 0
   #print(tmp_num) #########
    
   #選んだ数が3,5,7を1回以上含むかの判定
   three,five,seven = 0,0,0
   for k in range(len(tmp)):
     if(tmp[k]=='3'): three += 1
     elif(tmp[k]=='5'): five += 1
     elif(tmp[k]=='7'): seven += 1
   if(three*five*seven == 0): #どれか1つでも0なら積は0
    judge = 0
   
   #条件をみたすならカウント+1 
   if(judge == 1): ans += 1

print(ans)

Measured memory_bytes: 6772
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>
#include <unordered_set>

int main() {
    int64_t N, K, Q;
    std::cin >> N >> K >> Q;
    int64_t P[N+1] = {0};

    int64_t A = 0;
    for (int i = 0; i < Q; ++i) {
        std::cin >> A;
        P[A] += 1;
    }

    const int64_t point = K - Q;
    for (int i = 1; i <= N; ++i) {
        if (0 < (point + P[i])) {
            std::cout << "Yes\n";
        } else {
            std::cout << "No\n";
        }
    }

    return 0;
}


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

#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)

using ll = long long;
#define INF 1e9

int main(){
  ll N;
  cin >> N;
  if(N==0 || N==2){
    cout << 0 << endl;
    return 0;
  }
  ll ans = 0;
  FOR(i, 1, N){
    if((N-i)%i ==0 && (N-i)/i > i){
      ans += (N-i)/i;
    }
    else if((N-i)/i <= i){
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>

using namespace std;


int main(void)
{
    int hm,wm,h,w;
    cin >> hm >> wm;
    cin >> h >> w;

    int white = hm * wm;
    white -= h*wm;
    white -= w*hm;
    white += h * w;

    printf("%d\n", white);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

const int MAX_H = 25;
const int MAX_W = 25;

int h, w;
int a[MAX_H][MAX_W];

int CalcTotalDist( int x, int y ) {
    int total_dist = 0;
    for ( int i=0; i<h; ++i ) {
	for ( int j=0; j<w; ++j ) {
	    int dist = min( abs( x - j ), abs( y - i ) );
	    total_dist += a[i][j] * dist;
	}
    }
    return total_dist;
    
}

main() {

    cin >> h >> w;

    for ( int i=0; i<h; ++i ) 
	for ( int j=0; j<w; ++j ) cin >> a[i][j];

    int res = 1<<30;
    for ( int cy=0; cy<h; ++cy ) {
	for ( int cx=0; cx<w; ++cx ) {
	    res = min( res, CalcTotalDist( cx, cy ) );
	}
    }
    cout << res << endl;
}



Measured memory_bytes: 3104
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

struct UnionFind {
  vector<int> data;
  UnionFind(int N) : data(N, -1) { }
  bool uni(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[x] > data[y]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool find(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

struct edge{
  int src, dst, cost;
  edge(int s, int d, int c) : src(s), dst(d), cost(c) {}
  edge() {}
  bool operator< (const edge& e) const {
    return cost < e.cost;
  }
};

int main(){
  int N;
  cin>>N;
  vector<edge> v(N - 1);
  REP(i, N - 1){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    v[i] = edge(a, b, c);
  }
  UnionFind uf(N);
  sort(v.begin(), v.end());
  ll ans = 0;
  REP(i, N - 1){
    ans += (ll)uf.size(v[i].src) * uf.size(v[i].dst) * v[i].cost;
    uf.uni(v[i].src, v[i].dst);
  }
  cout<<ans<<endl;
  return 0;
}

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

int main() {
int N, R;
 cin >> N ;
  vector<int> choku(N);
  for(int i = 0; i < N; i++){
  	cin >> choku[i];
  }
  int64_t inf = 100000000;
  int64_t ababba = inf;
  int64_t jj = 0;
  for(int i = 1; i <= 100; i++){
    jj = 0;
    for(int j = 0; j < N; j++){
      	jj += (i-choku[j])*(i-choku[j]);
    }
      	ababba = min(jj, ababba);
    
  }
  cout << ababba << endl;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;

	vl a(n), ai(n);
	FOR(i,0,n) cin >> a[i], a[i]--;
	FOR(i,0,n) ai[a[i]] = i;

	set<ll> indices = {-1LL,n};
	
	ll res = 0;
	FORD(x,0,n) {
		ll i = ai[x];
		auto it = indices.lower_bound(i);
		ll c = *it, b = *prev(it);
		
		ll cnt = 0;
		if (next(it) != end(indices)) {
			ll d = *next(it);
			cnt += (d-c)*(i-b);
		}
		if (prev(it) != begin(indices)) {
			ll a = *prev(prev(it));
			cnt += (b-a)*(c-i);
		}
		res += cnt*(x+1);
		indices.insert(i);
	}
	cout << res << endl;
}



Measured memory_bytes: 6528
import java.util.Scanner;

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

        int i = 1;
        int n = sc.nextInt();
        
        while(i <= n){
        	int x = i;
        	
        	if(x % 3 == 0){
        		System.out.print(" " + i);
        	}else{ 
        		while(x >=1){
        			if(x % 10 == 3){
        				System.out.print(" " + i);
        				break;
        			}
        			x /= 10;
        		}
        	}
        	i++;
        }
        System.out.println("");
        sc.close();
    }
}


Measured memory_bytes: 28804
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int[] menu = new int[5];
    for (int i=0; i<menu.length; i++) {
      menu[i] = sc.nextInt();
    }
    
    int max = 0;
    int flag = 0;
    for (int i=0; i<menu.length; i++) {
      int tmp = (int)(Math.ceil((double)menu[i]/10)*10);
      if (max < tmp-menu[i]) {
        flag = i;
        max = tmp-menu[i];
      }
    }
    
    int time = 0;
    for (int i=0; i<menu.length; i++) {
      if (i==flag) continue;
      
      time += (int)(Math.ceil((double)menu[i]/10)*10);
    }
    
    time += menu[flag];
    
    System.out.println(time);
  }
}


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

int main(){
    int n,m;
    cin >> n >> m;
    map<int,int> mp;
    ll ans=0;
    rep(i,n){
        int a;
        cin >> a;
        mp[a]++;
    }
    rep(i,m){
        int b,c;
        cin >> b >> c;
        int b_ori=b;
        vi save;
        for(auto &x:mp){
            if(c<=x.first) break;
            int temp=x.second-b;
            if(temp<=0){
                b-=x.second;
                save.push_back(x.first);
            }else{
                b=0;
                x.second=temp;
                break;
            }
        }
        for(int x:save){
            mp.erase(x);
        }
        mp[c]+=b_ori-b;
    }
    for(auto x:mp){
        ans+=(ll)x.first*x.second;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8376
n,p=map(int,input().split())
ans=[]
if n==1:
  print(p)
elif n>=40:
  print(1)
else:
  for i in range(int(p**(1/n))+1):
    if p%(i+1)**n==0:
      ans.append((i+1))
  print(max(ans))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
#include<cstdlib>
#include<cmath>
#include<deque>
#include <numeric>

typedef long long ll;

int gcd(int x, int y)
{
	int r;

	if (x == 0 || y == 0)  // 引数チェック
	{
	
	}

	// ユーグリッドの互除法
	while ((r = x % y) != 0) // yで割り切れるまでループ
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(int m, int n)
{
	// 引数に０がある場合は０を返す
	if ((0 == m) || (0 == n))
		return 0;

	return (ll)(((ll)m / (ll)gcd(m, n)) * (ll)n); // lcm = m * n / gcd(m,n)
}//lcm
int main() {
	int n, m;
	std::cin >> n >> m;

	std::string sts;
	std::string stt;
	std::cin >> sts;
	std::cin >> stt;

	ll l = lcm(n, m);
	int p = gcd(n, m);

	//std::cout << l <<" " << p  << std::endl;

	ll np = n / p;
	ll mp = m / p;

		int flgx = 0;
		ll j = 0;
		while ((np * j < n) && (mp * j  < m)) {
			if (sts[np * j] != stt[mp * j]) {
				//std::cout << j << " " << np * j  << " " << sts[np * j ]  << std::endl;
				//std::cout << j << " " << mp * j  << " " << stt[mp * j ] << std::endl;
				flgx = 1;
				break;
			}
			j++;
		}
		if (flgx == 1) {
			std::cout << "-1" << std::endl;
		}
		else
		{
			std::cout << l << std::endl;
		}


	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
using namespace std;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)

constexpr int MAX = 160 * 80 + 1;
bool dp[81][81][MAX];

int a[80][80], b[80][80], c[80][80];

int main() {
  int h, w;
  cin >> h >> w;
  rep(i, 0, h) rep(j, 0, w) cin >> a[i][j];
  rep(i, 0, h) rep(j, 0, w) cin >> b[i][j];
  rep(i, 0, h) rep(j, 0, w) c[i][j] = abs(a[i][j] - b[i][j]);

  dp[0][0][c[0][0]] = true;
  rep(i, 0, h) rep(j, 0, w) rep(k, 0, MAX) {
    if (i) {
      dp[i][j][k + c[i][j]] |= dp[i - 1][j][k];
      dp[i][j][abs(k - c[i][j])] |= dp[i - 1][j][k];
    }
    if (j) {
      dp[i][j][k + c[i][j]] |= dp[i][j - 1][k];
      dp[i][j][abs(k - c[i][j])] |= dp[i][j - 1][k];
    }
  }

  rep(i, 0, MAX) if (dp[h - 1][w - 1][i]) {
    cout << i << endl;
    return 0;
  }
}

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

int main () {
  int a,b;
  cin>>a>>b;
  if(a!=1 && b!=1 && a!=b){
    if(a>b){
      cout<<"Alice"<<endl;
    }
    if(a<b){
      cout<<"Bob"<<endl;
    }
  }
  if(a==b){
    cout<<"Draw"<<endl;
  }
  if(a==1 && a!=b){
    cout<<"Alice"<<endl;
  }
  if(b==1 && a!=b){
    cout<<"Bob"<<endl;
  }
  return 0;
}

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

int main(){
	int n,b,f,r,v;
	int s[5][4][11] = {0};
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> b >> f >> r >> v;
		s[b-1][f-1][r-1] += v;
	}
	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			for (int k = 0; k < 10; k++)
			{
				cout << " " << s[i][j][k];
			}
			cout << endl;
		}
		if (i < 3){
            for (int l = 0; l < 20; l++){
                cout << "#";
            }
            cout << endl;
        }
	}
}

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

int64_t simulate(uint64_t N, uint64_t Q, const std::string &s, const std::string &t, const std::string &d, int64_t i)
{
  for (uint64_t q = 0; q < Q; ++q) {
    if (s[i] == t[q]) {
      i += (d[q] == 'L') ? -1 : +1;
    }
    
    if (i < 0 || i >= N) { return i; }
  }
  return i;
}

int64_t search_left(uint64_t N, uint64_t Q, const std::string &s, const std::string &t, const std::string &d)
{
  int64_t left = 0, right = N;
  
  while (right - left > 1) {
    int64_t mid = (left + right) >> 1;
    int64_t ret = simulate(N, Q, s, t, d, mid);
    
    if (ret == -1) {
      left = mid;
    } else {
      right = mid;
    }
  }
  
  if (left == 0 && simulate(N, Q, s, t, d, 0) >= 0) {
    return -1;
  }
  
  if (simulate(N, Q, s, t, d, right) == -1) {
    return right;
  } else {
    return left;
  }
}

int64_t search_right(uint64_t N, uint64_t Q, const std::string &s, const std::string &t, const std::string &d)
{
  int64_t left = 0, right = N;
  
  while (right - left > 1) {
    int64_t mid = (left + right) >> 1;
    int64_t ret = simulate(N, Q, s, t, d, mid);
    
    if (ret == N) {
      right = mid;
    } else {
      left = mid;
    }
  }
  
  if (right == N && simulate(N, Q, s, t, d, N - 1) < N) {
    return N;
  }
  
  if (simulate(N, Q, s, t, d, left) == N) {
    return left;
  } else {
    return right;
  }
}

int main()
{
  uint64_t N, Q;
  std::cin >> N >> Q;

  std::string s;
  std::cin >> s;
  
  std::string t(Q, ' '), d(Q, ' ');
  for (uint64_t q = 0; q < Q; ++q) {
    std::cin >> t[q] >> d[q];
  }
  
  int64_t left = search_left(N, Q, s, t, d);
  
  int64_t right = search_right(N, Q, s, t, d);
  
  std::cout << (right - left - 1) << std::endl;
  
  return 0;
}

Measured memory_bytes: 900
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}

int gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}



int main() {
	int a,b,an=0;
	
	cin >> a>>b;
	for (int i = 1; i < a + 1; i++) {
		for (int j = 1; j < b + 1; j++) {
			if (j / 10 > 1 && j % 10 > 1 && (j / 10) * (j % 10) == i) {
				an++;
			}
		}
	}




	cout <<an<< endl;
	
}

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

using namespace std;

#define fo(i,CApiTaL_N) for(int i=0; i<CApiTaL_N; i++)
#define Fo(i,k,CApiTaL_N) for(int i=k; i<CApiTaL_N; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it=a.begin(); it!=a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

int t=1;
const int mxW=1e9, mxN=1e2, mxV=1e3;
int n,w;
vl wi(mxN+1),v(mxN+1),dp(mxV*mxN+1,1e15);
ll mxvi=1e5;

void test_case(){
    cin>>n>>w;
    Fo(i,1,n+1){
        cin>>wi[i]>>v[i];
    }
    dp[0]=0;
    Fo(j,1,n+1){
        for(int i=mxvi; i>=0; i--){
            if(i-v[j]<0)continue;
            dp[i]=min(dp[i],dp[i-v[j]]+wi[j]);
        }
    }
    ll mv=0;
    for(int i=mxvi; i>=0; i--){
        if(dp[i]<=w){
            mv=i;
            break;
        }
    }
    cout<<mv<<endl;
}

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

    // cin>>t;
    while(t--){
        test_case();
    }
    
    return 0;
}

Measured memory_bytes: 3888
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char c;
	cin >> c;
	
	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
	{
		cout << "vowel\n";
	} else {
		cout << "consonant\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<stdint.h>
using namespace std;
#define vi vector<int> 
#define pb push_back
#define w(t)   int t;cin>>t;while(t--) 
#define show(ar) for(int i=0;i<ar.size();i++) cout<<ar[i]<<" "; cout<<endl;
#define mod 1e9+7
#define ff first
#define ss second 
#define fio ios::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL);
#define all(x) (x.begin(),x.end())
#define inf 1e9+7


vi inp(int n)
{
	vi v; int x;
	for(int i=0;i<n;i++) {
		cin>>x; v.pb(x);
	}
	return v; 
}


int main()
{
	long long int a,b,c,k;
	cin>>a>>b>>c>>k;
	if(a>=k)
		cout<<k<<endl;
	else if(a+b>=k)
		cout<<a<<endl;
	else
	{
		cout<<a-(k-a-b)<<endl;
	}
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define PB push_back

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVi;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;

int main(){
	ios::sync_with_stdio(false);
    string w;
    cin>>w;
    map<char,int> m;
    for(int i=0;i<w.size();i++){
        m[w[i]]++;
    }
    for(int i=0;i<w.size();i++){
        if(m[w[i]]%2==0){
            continue;
        }
        else{
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;


    return 0;
}


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

using namespace std;

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::string s;
  std::cin >> s;
  int i = 0;
  for (auto const c: s) {
    i += (c == 'x');
  }
  std::cout << (i < 8 ? "YES" : "NO") << std::endl;
  return 0;
}


Measured memory_bytes: 256
import math

n = int(raw_input())
X = map(float, raw_input().split(" "))
Y = map(float, raw_input().split(" "))

print(sum([math.fabs(X[i] - Y[i]) for i in range(n)]))
print(math.sqrt(sum([math.fabs(X[i] - Y[i])**2 for i in range(n)])))
print(math.pow(sum([math.fabs(X[i] - Y[i])**3 for i in range(n)]), (1.0/3.0)))
print(max([math.fabs(X[i] - Y[i]) for i in range(n)]))

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

using namespace std;

int n, m;

char ch[200010];

int A[200010], B[200010];

int Do(int x) {
	for(int i = 1; i <= m; i++)
		if(ch[x] == A[i]) {
			x += B[i];
			if(x == 0 || x == n + 1) return x;
	}
	return x;
}

int main() {
scanf("%d%d", &n, &m);
	scanf("%s", ch + 1);
	for(int i = 1; i <= m; i++) {
		char X[3], Y[3];
		scanf("%s%s", X, Y);
		A[i] = X[0], B[i] = Y[0] == 'R' ? 1 : -1;
	}
	int ansL = 0;
	for(int l = 1, r = n; l <= r; ) {
		int md = (l + r) / 2;
		if(Do(md) == 0) ansL = md, l = md + 1; else r = md - 1;
	}
	int ansR = n + 1;
	for(int l = 1, r = n; l <= r; ) {
		int md = (l + r) / 2;
		if(Do(md) != n + 1) l = md + 1; else ansR = md, r = md - 1;
	}
	printf("%d\n", ansR - ansL - 1);
	return 0;
}

Measured memory_bytes: 2048
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<map>
#include<vector>
#include<string>
#define ll long long
#define For(i,x,y)  for(ll i=x;i<=y;++i)
#define FOr(i,x,y)  for(ll i=x;i>=y;--i)
using namespace std;
inline ll read(){   ll x=0,f=1;char ch=getchar();   while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}  while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}  return x*f; } 
inline void write(ll x){    if (x<0) putchar('-'),x=-x; if (x>=10) write(x/10);   putchar(x%10+'0');  } 
inline void writeln(ll x){ write(x);   puts("");   }
const ll N=400010;
ll n,sum[N],ans=1e18;
int main(){
	n=read();
	For(i,1,n)	sum[i]=sum[i-1]+read();
	For(i,1,n-1)	ans=min(ans,abs(sum[i]-(sum[n]-sum[i])));
	writeln(ans);
}

Measured memory_bytes: 1792
import itertools
ans_list = []
while True:
    n, x = [int(i) for i in input().split()]
    if n == 0 and x == 0:
        break
    count_list = []
    for v in itertools.combinations(range(1, n+1), 3):
        if sum(v) == x:
            count_list.append(v)
    ans_list.append(len(count_list))
for ans in ans_list:
    print(ans)


Measured memory_bytes: 5736
#include<bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
	int a, b;
	cin >> a >> b;
	for (int i = 0; i < 100000; ++i) {
		int xa = i * 0.08;
		int xb = i * 0.1;
		if (xa == a && xb == b) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		int ary[] = new int[3];

		Scanner sc = new Scanner(System.in);
		ary[0] = sc.nextInt();
		ary[1] = sc.nextInt();
		ary[2] = sc.nextInt();
		
		for (int i = 0; i < ary.length; i++) {
			if (ary[i] < 1 || ary[i] > 10000 || ary[0] > ary[1]) {
				System.err.println("Err!");
				return;
			}
		}
		
		int count = 0; // 約数の個数
		for (int i = ary[0]; i <= ary[1]; i++) {
			if (ary[2] % i == 0) {
				count++;
			}
		}
		System.out.println(count);

	}
}


Measured memory_bytes: 26376