akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <algorithm>
#include <queue>
using namespace std;
int main() {
	int N, H, W; 
	cin >> N >> H >> W; 
	int ans = 0; 
	for(int i = 0; i < N; i++){
		int a, b; 
		cin >> a >> b; 
		if(a >= H && b >= W){ans ++;}
	}
	cout << ans << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < n; i++)
#define INF INT_MAX
#define fcout cout << fixed << setprecision(15) // 15桁まで表示
#define en '\n'
using str = string;
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using puu = pair<ui, ui>;
using P = pair<int, int>;
using vi = vector<int>;
int gcd(int a, int b) {
  return b ? gcd(b, a % b) : a;
};
int lcm(int a, int b) {
  return a / gcd(a, b) * b;
};
int floor(int a, int b) {
  return (a + b - 1) / b;
};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
};
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
};
const ll mod = 1000000007;
const double PI = acos(-1.0);
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);
  int n, m;
  ll k;
  cin >> n >> m >> k;
  vector<ll> a(n+1), b(m+1);
  rep(i, n) cin >> a[i+1];
  rep(i, m) cin >> b[i+1];
  int now = m;
  int ans = 0;
  REP(i, 1, n + 1) a[i] += a[i - 1];
  REP(i, 1, m+1) b[i] += b[i - 1];
  rep(i,n+1){
    for (int j = now; j >= 0;j--){
      now = j;
      if (a[i] + b[j] <= k) {
        break;
      }
    }
    if (a[i]+b[now]>k)
      break;
    else
      chmax(ans, i + now);
  }
  cout << ans << en;
}

Measured memory_bytes: 6352
import sys
from bisect import bisect_left

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    ll = list(map(int, input().split()))
    ll.sort()
    ans = 0
    for j, l1 in enumerate(ll[:-1]):
        for i, l0 in enumerate(ll[:j]):
            ans += bisect_left(ll, l0 + l1) - (j + 1)
    print(ans)

main()


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define INF 1152921504606846976


int main() {
    i64 N, K; cin >> N >> K;
    vector<i64> Pos;
    vector<i64> Neg;
    i64 x;
    REP(i, N) {
        cin >> x;
        if (x >= 0) Pos.pb(x);
        else Neg.pb(-1 * x);
    }
    reverse(Neg.begin(), Neg.end());

    i64 min_t = INF;
    REP(k, K + 1) {
        if (Pos.size() < k || Neg.size() < (K - k)) continue;
        i64 pos_t = (k == 0) ? 0 : Pos[k - 1];
        i64 neg_t = (k == K) ? 0 : Neg[K - k - 1];
        chmin(min_t, pos_t + neg_t + min(pos_t, neg_t));
    }
    cout << min_t << endl;

    return 0;
}

Measured memory_bytes: 1656
use proconio::{input, marker::Chars};
use std::collections::VecDeque;

fn main() {
    input! {
        h: usize,
        w: usize,
        ss: [Chars; h],
    }

    let dir = vec![
        (0, -1),
        (0, 1),
        (-1, 0),
        (1, 0),
    ];

    let mut visited = vec![vec![false; w]; h];
    let mut queue = VecDeque::new();

    queue.push_back((0, 0, 1));

    let mut cost = None;

    while let Some((x, y, c)) = queue.pop_front() {
        let (x, y) = (x as usize, y as usize);
        if ss[x][y] == '#' {
            continue;
        }
        if visited[x][y] {
            continue;
        }
        visited[x][y] = true;
        if x == h - 1 && y == w - 1 {
            cost = Some(c);
        }

        for &(dx, dy) in dir.iter() {
            let (x, y) = (x as i32 + dx, y as i32 + dy);
            if x >= 0 && x < h as i32 && y >= 0 && y < w as i32 {
                queue.push_back((x, y, c + 1));
            }
        }
    }

    if let Some(cost) = cost {
        let mut count_white = 0;
        for ss in ss {
            for s in ss {
                match s {
                    '.' => count_white += 1,
                    _ => {},
                }
            }
        }
        let ans = count_white - cost;
        println!("{}", ans);
    } else {
        println!("-1");
    }
}


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


using namespace std;


const int MAXN = 8 + 3;







int h, w, num;
string s[MAXN];


int main() {
    cin >> h >> w;
    for (int i = 0; i < h; i++)
        cin >> s[i];
    int pt = 0, ans = 0, exp = 0;
    for (int i = 0; i < h; i++) {
        bool b = false;
        while (pt < w && s[i][pt] == '#')
            pt++, ans++, b = true;
        if (b)
            pt--;
        exp += count(s[i].begin(), s[i].end(), '#');
    }
    
    if (ans == h + w - 1 && ans == exp)
        cout << "Possible";
    else
        cout << "Impossible";
    return 0;
}

Measured memory_bytes: 256
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 minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

	s := readString()
	b := []byte(s)
	if len(b) == 2 {
		if b[0] == b[1] {
			println(1, 2)
		} else {
			println(-1, -1)
		}
		return
	}
	for i := 0; i+2 < len(b); i++ {
		x := b[i]
		y := b[i+1]
		z := b[i+2]
		if x == y || y == z || z == x {
			println(i+1, i+3)
			return
		}
	}
	println(-1, -1)
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
  int n;
  string c;
  cin >> n;

  int cnt = 0;
  bool x = true;
  
  while(n--){
    cin >> c;
    if(c == "A"){
      cnt++;
    }else {
      cnt--;
      if(cnt < 0){
	x = false;
      }
    }
  }
  if(cnt != 0 || x == false){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 3156
// 2011/01/05 Tazoe

#include <iostream>
#include <string>
using namespace std;

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

	for(int i=0; i<n; i++){
		int ots = 0;
		int sco = 0;
		int ba1 = 0, ba2 = 0, ba3 = 0;

		while(ots<3){
			string eve;
			cin >> eve;

			if(eve=="HIT"){
				sco += ba3;
				ba3 = ba2;
				ba2 = ba1;
				ba1 = 1;
			}
			else if(eve=="HOMERUN"){
				sco += (ba3+ba2+ba1+1);
				ba3 = ba2 = ba1 = 0;
			}
			else if(eve=="OUT"){
				ots++;
			}
		}

		cout << sco << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
  int n, lcm=1, ans=0;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  cout << accumulate(all(a), 0LL) - n;
} 

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int a, b, c;
  int x = 0;
 cin >> a >> b >> c;
for(int i=a; i<=b; i++){
  if(c%a == 0)
  x++;
  a++;
}
 cout << x << endl;
  return 0;
}

Measured memory_bytes: 3120
#include <iostream>

using namespace std;

int main(){
  int N;

  cin >> N;
  for(;N<1000;N++){
    if(N%111==0||N%222==0||N%333==0||N%444==0||N%555==0||N%666==0||N%777==0||N%888==0||N%999==0){
      break;
    }
  }

  cout << N<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <limits.h>

#define ll long long

using namespace std;

int main(){

    int n;
    cin >> n;

    vector<pair<int,int>> v;

    for(int i = 0; i < n; i++){
        int a,b;
        cin >> a >> b;

        v.push_back(make_pair(b,a));
    }

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

    int stime = 0;
    bool result = true;

    for(int i = 0; i < n; i++){
        stime = stime + v[i].second;
        if(stime > v[i].first){
            result  = false;
            break;
        }
    }

    if(result){
        cout << "Yes" << endl;
    }else cout << "No" << endl;



    return 0;
}       

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

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

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n;
    cin >> n;
    vector<vector<int>> graph(n);

    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        graph[a - 1].push_back(b - 1);
        graph[b - 1].push_back(a - 1);
    }

    int dist0[n], dist1[n];
    rep(i, n) {
        dist0[i] = mod;
        dist1[i] = mod;
    }
    dist0[0] = 0;
    dist1[n - 1] = 0;

    queue<int> q0;
    q0.push(0);
    while (!q0.empty()) {
        int point = q0.front();
        q0.pop();
        rep(i, graph[point].size()) {
            int next = graph[point][i];
            if (dist0[next] != mod) {
                continue;
            }
            q0.push(next);
            dist0[next] = dist0[point] + 1;
        }
    }

    queue<int> q1;
    q1.push(n - 1);
    while (!q1.empty()) {
        int point = q1.front();
        q1.pop();
        rep(i, graph[point].size()) {
            int next = graph[point][i];
            if (dist1[next] != mod) {
                continue;
            }
            q1.push(next);
            dist1[next] = dist1[point] + 1;
        }
    }

    int num0 = 0, num1 = 0;

    rep(i, n) {
        if (dist0[i] <= dist1[i]) {
            num0++;
        } else {
            num1++;
        }
    }

    if (num0 > num1) {
        cout << "Fennec" << endl;
    } else {
        cout << "Snuke" << endl;
    }

    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 6528
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    n,k = map(int, input().split())
    a_list = list(map(int, input().split()))
    print(ceil((n-1)/(k-1)))

if __name__ == "__main__":
    main()

Measured memory_bytes: 14324
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007

long long modpow(long long n, long long a, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main()
{
    long long N;
    cin >> N;
    long long ans = modpow(N, 10, modulo) - modpow(N, 9, modulo) * 2 + modpow(N, 8, modulo);
    ans %= modulo;
    ans = (ans + modulo) % modulo;
    cout << ans << endl;
}

Measured memory_bytes: 3432
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	deque<int> a;
	for(int i = 0, j; i < n; ++i)
	{
		scanf("%d", &j);
		if(i % 2)
		{
			a.push_front(j);
		}
		else
		{
			a.push_back(j);
		}
	}
	if(n % 2)
	{
		for(int i = n - 1; i >= 0; --i)
		{
			printf("%d ", a[i]);
		}
	}
	else
	{
		for(int i = 0; i < n; ++i)
		{
			printf("%d ", a[i]);
		}
	}
	printf("\n");
}

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

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  vector<ll> res(n);
  vector<ll> res2(n);
  rep(i,n){
    cin>>a[i];
    if(i>=a[i]) res[i-a[i]]++;
    if(i+a[i]<n) res2[i+a[i]]++;
  }
  ll ans=0;
  rep(i,n){
    ans+=res[i]*res2[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 7196
from itertools import product 
S = input()
N = len(S)

cand = ["","+"]

ans = 0
for i in product(cand,repeat=(N-1)):
    i = list(i)
    i.append("")
    e = "".join([a+b for a,b in zip(S,i)])
    ans += eval(e)
print(ans)










Measured memory_bytes: 3060
# coding=utf-8

if __name__ == '__main__':
    S = input()
    K = int(input())

    for elm in S:
        if elm != '1':
            ctr = S.index(elm)
            break
    else:
        ctr = -1

    if ctr == -1:
        print(1)
    else:
        if ctr+1 > K:
            print(1)
        else:
            print(S[ctr])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include<set>
#include <algorithm>
#define ll long long 
#include <string.h>
using namespace std;

int main()
{
	ll int n;
	cin>>n;
	ll int a[n],i,j;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	ll int b[n],c[n];
	for(i=0;i<n;i++)
	{
		b[i]=i+1+a[i];
	}
	for(i=0;i<n;i++)
	{
		c[i]=i+1-a[i];
	}
	ll int s=0;
	
	unordered_map<ll int, ll int> mp;
	for(i=0;i<n;i++)
	{
		mp[c[i]]++;
	}
	for(i=0;i<n;i++)
	{
		s+=mp[b[i]];
	}
	cout<<s<<endl;
	
} 







Measured memory_bytes: 23104
s = input()
ans = 0
for i in range(len(s)):
    le = 0
    if 'A' not in s[i] and 'C' not in s[i] and 'G' not in s[i] and 'T' not in s[i]:
        continue
    else:
        le = 1
        for j in range(1, len(s)-i):
            if 'A' not in s[i+j] and 'C' not in s[i+j] and 'G' not in s[i+j] and 'T' not in s[i+j]:
                break
            else:
                le += 1
    ans = max(ans,le)
print(ans)
            

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

namespace AGC028A
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            long[] lengths = Input.LongArray();
            long N = lengths[0];
            long M = lengths[1];

            string S = Input.String();
            string T = Input.String();

            long gcd = Gcd(N, M);
            long lcm = N * M / gcd;

            long ln = lcm / N;
            long lm = lcm / M;

            char[] ans = new char[N];
            for (int i = 0; i < N; i++)
            {
                ans[i] = S[i];
            }

            for (int i = 0; i < M; i++)
            {
                if (i * lm % ln == 0)
                {
                    if (ans[i * lm / ln] != T[i])
                    {
                        Console.WriteLine(-1);
                        return;
                    }
                }
            }
            Console.WriteLine(lcm);
        }

        public static long Gcd(long a, long b)
        {
            return b > 0 ? Gcd(b, a % b) : a;
        }
    }
    internal static class Input
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] IntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] LongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] DoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
    }
}

Measured memory_bytes: 13920
N,Y=map(int,input().split())
c=0
for i in range(Y//10000+1):
  for j in range(N-i+1):
    if 10000*i+5000*j+1000*(N-i-j)==Y:
      if c==0:
        print(i,j,(N-i-j))
        c=1
if c==0:
  print(-1,-1,-1)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

const lint MOD = pow(10, 9) + 7;

/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/


int main() {
	int N, K;
	cin >> N >> K;
	if (K == 1) {
		cout << 0 << endl;
	}
	else {
		cout << N - K << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  while(h!=0){
    int i,j;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if((i%2 ==0 && j%2 == 0) || (i%2 ==1 && j%2 ==1))
	  cout << "#";
	else cout << ".";
      }
      cout << endl;
    }
    cout << endl;
    cin >> h >> w;
  }
  return 0;
}



Measured memory_bytes: 3112
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2003,p=1000000007;
int f[2][N],i,j,k,n,m,X,Y,K,an;
bool l;
char c;

inline char getc()
{
	#define VV 10000000
	static char s[VV],*l=s,*r=s;
	if (l==r)
		l=s,r=s+fread(s,1,VV,stdin);
	return l==r?0:*l++;
}

int read(){ int z=0; do c=getc(); while (c<'0'||c>'9'); while (c>='0'&&c<='9') z*=10,z+=c-'0',c=getc(); return z; }

void plus(int &a,int b){ a+=b,a-=a<p?0:p; }
int minus(int a,int b){ a-=b,a+=a<0?p:0; return a; }

int main()
{
	n=read(),m=read(),K=read();
	if (!n||!m)
	{
		puts("1");
		return 0;
	}
	--m,--K;
	X=(n+m)/K;
	f[0][0]=1;
	for (i=1;i<=X;++i)
	{
		l=!l;
		Y=min(n,i*K);
		for (j=1;j<=Y;++j)
			plus(f[!l][j],f[!l][j-1]);
		for (j=0;j<=Y;++j)
		{
			f[l][j]=minus(f[!l][j],j<K+1?0:f[!l][j-K-1]);
			if (j&&i*K-j<=m&&j%K==n%K&&(i*K-j)%K==m%K)
				plus(an,minus(f[l][j],minus(f[!l][j],f[!l][j-1])));
		}
	}
	printf("%d\n",an);
	return 0;
}

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

int main() {

    int h,n,x;
    
    scanf("%d%d", &h, &n);
    int r = 0;
    for(int i=0; i<n; i++) {
        scanf("%d", &x);
        r += x;
    }

    if (r >= h) printf("Yes\n"); else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
x.append(X)
y.append(Y)
x.sort()
y.sort()

if x[-1]<y[0]:
    print('No War')
else:
    print('War')


Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
ll int MOD=998244353;
#define INF 2*1e9
#define N 310000
 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

int n;
vector<int> v[N];
int depth(int a){
    if(!v[a].size()) return 0;
    vector<int> w;
    rep(i,v[a].size()){
        w.pb(depth(v[a][i]));
    }
    sort(w.begin(),w.end());
    int ans=0;
    rep(i,w.size()){
        ans=max(ans,w[i]+(int)w.size()-i);
    }
    return ans;
}
main(){
    cin>>n;
    rep2(i,2,n){
        int a;
        cin>>a;
        v[a].push_back(i);
    }
    cout<<depth(1);
    return 0;
}


Measured memory_bytes: 18432
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<map>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const int mod=1000000007;
const llint big=1e18+10;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-9;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}//a>b
class in_t{public:
	int a;in_t(){cin>>a;}
	operator int() {return a;}
};
class lin_t{public:
	llint a;lin_t(){cin>>a;}
	operator llint() {return a;}
};
class ld_t{public:
	long double a;ld_t(){cin>>a;}
	operator long double() {return a;}
};
int main(void){
	string str;cin>>str;
	int a;
	if(str.front()==str.back()){a=1;}else{a=0;}
	if((str.size()+a)%2==0){cout<<"Second"<<endl;}
	else{cout<<"First"<<endl;}
	return 0;
}


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

int main()
{
  // char str[4] = {""};
  string str;
  int ans;
  while (true) {
    ans = 0;

    cin >> str;

    if (str == "0") return 0;
    rep(i, str.size()) {
      ans += (int)str[i] - '0';
    }

    cout << ans << endl;
  }
  return 0;
}
// int main(){
//   string number;
//   cin >> number;
//   rep(i, number.size()) {
//     cout << number[i];
//   }
//   cout << endl;
// }


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int a,b,t;
    cin>>a>>b>>t;
    int c = (t+0.5)/a;
    cout<<b*c<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
const int MOD = 1e9+7;
 
int gcd(int a, int b){
   if (a%b == 0)  return(b);
   else return(gcd(b, a%b));
}
 
 
int main() {
	int A,B,C;
  	cin >> A >>B >>C;
	int g = gcd(A,B);
  	if(C%g == 0)cout << "YES" << endl;
  	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
using namespace std;
typedef long long li;
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define MOD 998244353
#define chmin(a,b) (a>(b)?a=(b),1:0)
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
void print(vector<li> v){
  for(int x:v)printf("%d ",x); printf("\n");
} 
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }


int main(){
  int n,s; cin >>n >>s;
  vector<int> a(n); rep(i,n) cin >> a[i];
  li cnt =0;
  rep(i,n) if(a[i]==s) (cnt+=(i+1)*(n-i))%=MOD;
  if(df)print(cnt);
  vector<li> dp(s+1,0);
  dp[0]=1; dp[s]=cnt;
  rep(i,n){
    if(df)printf("i:%d\n",i);
    if(a[i]>=s)continue;
    int b=a[i];
    (dp[s]+=dp[s-b]*(n-i)%MOD)%=MOD;
    for(int k=s-b-1;k>=0;k--){
      (dp[k+b]+=dp[k])%=MOD;
    }
    dp[a[i]]+=i;
    if(df)print(dp);
  }

  print(dp[s]);
}


Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int M=stdIn.nextInt();
		int a[]=new int[N];
		int b[]=new int[N];
		int z=0,y=0,x=0,n=0,m=0,fin=0;
		while(z<M){
			y=stdIn.nextInt();
			x=stdIn.nextInt();
			if(y==1){
				a[n]=x;
				n++;
			}
			if(x==N){
				b[m]=y;
				m++;
			}
			z++;
		}z=0;y=0;x=0;
		int c[]=new int[n];
		int d[]=new int[m];
		while(z<n||y<m){
			if(z<n){
				c[z]=a[z];
				z++;
			}
			if(y<m){
				d[y]=b[y];
				y++;
			}
		}z=0;y=0;
		Arrays.sort(c);
		Arrays.sort(d);
		while(z<n){
			while(y<m){
				if(c[z]==d[y]){
					fin=1;
					break;
				}
				if(c[z]<d[y]){
					break;
				}
				y++;
			}
			if(fin==1)
				break;
			z++;
		}
		if(fin==1)
			System.out.println("POSSIBLE");
		else
			System.out.println("IMPOSSIBLE");
	}
}


Measured memory_bytes: 96268
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int h[n];
	for(int i=0;i<n;i++)
	{
		cin>>h[i];
	}
	int dp[n];
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for(int i=2;i<n;i++)
	{
		dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i]));
		//cout<<dp[i];
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include <iostream>
#include <stack>
#include <string>

using namespace std;

int main(){
  string str;
 
  while ( 1 ){
    string s = "yes";
    getline( cin, str );
    if ( str[0] == '.' ) break;
    stack<char> sta;
    for ( int i = 0; str[i] != '\0'; i++ ){
      if ( str[i] == '(' || str[i] == '[' ){
          sta.push( str[i] );
      }else if ( str[i] == ')' ){
          if ( sta.empty() ){
              s = "no";
              break;
          }else if ( sta.top() == '(' ){
              sta.pop();
        }else{
            s = "no";
            break;
        }
      }else if ( str[i] == ']' ){
          if ( sta.empty() ){
                s = "no";
              break;
          }else if ( sta.top() == '[' ){
          sta.pop();
        }else{
	  s = "no";
	  break;
	}
      }
    }
    if ( !sta.empty() ) s = "no";
    cout << s << endl;
  }
}

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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    long long s = 0;
    cin >> n;
    for(int i=1; i<=n; i++) {
        if(i%3 == 0 || i%5 == 0) {
            continue;
        }
        s += i;
    }
    cout << s;
    return 0;
}


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

vector<vector<int>> graph[2];
vector<bool> use[2];

void dfs(int n, int xy, vector<ll> &cnt, ll &nEdge){
    cnt[xy]++;
    use[xy][n] = true;
    for(auto v:graph[xy][n]){
        // cout << (xy==0?"x : ":"y : ") << n << " -> " << (xy^1==0?"x : ":"y : ") << v << endl;
        nEdge++;
        if(!use[xy^1][v]){
            dfs(v, xy^1, cnt, nEdge);
        }
    }
}

int main(){
    int N;  cin >> N;
    int M = 1e5;
    graph[0].resize(M+1, vector<int>());
    graph[1].resize(M+1, vector<int>());
    use[0].resize(M+1, true);
    use[1].resize(M+1, true);

    for(int i=0; i<N; i++){
        int x, y;
        cin >> x >> y;
        graph[0][x].push_back(y);
        graph[1][y].push_back(x);
        use[0][x] = false;
        use[1][y] = false;
    }

    ll ans = 0;
    for(int i=0; i<2; i++){
        for(int x=1; x<=M; x++){
            if(use[i][x]) continue;
            vector<ll> cnt(2,0);
            ll nEdge = 0;
            // cout << "-----------------------" << endl;
            dfs(x, i, cnt, nEdge);
            nEdge/=2;
            // cout << i << " " << x << " " << cnt[0] << " " << cnt[1] << " " << nEdge << " " << endl;
            ans += cnt[0]*cnt[1] - nEdge;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 12928
#include<stdio.h>
#include<stdlib.h>
#define MAX 10000
#define MIN -1
 
typedef struct {
  int p,l,r;
}Node;
 
Node node[MAX];
 
int n,height[MAX],depth[MAX];
 
int Height(int);
int Sibling(int);
void Depth(int,int);
void Print(int);
 
int Height(int u) {
  int h1 = 0 , h2 = 0;
 
  if( node[u].l != MIN ) {
    h1 = Height(node[u].l) + 1;
  }
  if( node[u].r != MIN ) {
    h2 = Height(node[u].r) + 1;
  }
 
  if( h1 > h2 ) return height[u] = h1;
  else return height[u] = h2;
}
 
int Sibling(int u) {
  if( node[u].p == MIN ) return MIN;
  if( node[node[u].p].r != u && node[node[u].p].r != MIN ) return node[node[u].p].r;
  if( node[node[u].p].l != u && node[node[u].p].l != MIN ) return node[node[u].p].l;
 
  return MIN;
}
 
void Depth( int u, int d ) {
  if( u == MIN ) return;
  depth[u] = d;
  Depth( node[u].l, d+1 );
  Depth( node[u].r, d+1 );
}
 
void Print(int u) {
  int suu = 0;
 
  printf("node %d: parent = %d, sibling = %d, ",u,node[u].p,Sibling(u));
  if( node[u].l != MIN ) suu++;
  if( node[u].r != MIN ) suu++;
 
  printf("degree = %d, depth = %d, height = %d, ",suu,depth[u],height[u]);
  if( node[u].p == MIN ) printf("root\n");
  else if( node[u].l == MIN && node[u].r == MIN ) printf("leaf\n");
  else printf("internal node\n");
} 
 
 
 
int main(){
  int i;
  int id,l,r,root = 0;
 
  scanf("%d",&n);
 
  for( i = 0 ; i < n ; i++ ) {
    node[i].p = MIN;
  }
 
  for( i = 0 ; i < n ; i++ ) {
    scanf("%d%d%d",&id,&l,&r);
    node[id].l = l;
    node[id].r = r;
    if( l != MIN ) node[l].p = id;
    if( r != MIN ) node[r].p = id;
  }
 
  for( i = 0 ; i < n ; i++) {
    if( node[i].p == MIN ) {
      root = i;
    }
  }
 
  Depth( root,0 );
  Height(root);
 
  i = 0;
  while( i < n ){
    Print(i);
    i++;
  }
 
  return 0;
}

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

int main() {
  int N, L;
  cin >> N >> L;
  vector<string> ans(N);

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

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

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

Measured memory_bytes: 3612
local n, k = io.read("*n", "*n")
local t = {}
for i = 1, n do
  t[i] = io.read("*n")
end
local dp = {}
local box = {}
local bzero = false
for i = 1, k do
  bzero = false
  for j = 1, n do
    box[j] = false
  end
  for j = 1, n do
    if t[j] < i then
      local v = dp[i - t[j]]
      if v == 0 then bzero = true
      else box[v] = true
      end
    elseif t[j] == i then
      bzero = true
    else
      break
    end
  end
  if not bzero then dp[i] = 0
  else
    for j = 1, n do
      if not box[j] then dp[i] = j break end
    end
  end
end
print(dp[k] == 0 and "Second" or "First")


Measured memory_bytes: 1536
s = input().split()
N = int(s[0])
K = int(s[1])
Q = int(s[2])

point = [K-Q for i in range(N)]


for i in range(Q):
    k = int(input())
    point[k-1] += 1

for i in range(N):
    if point[i] > 0:
        print("Yes")
    else:
        print("No")


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

typedef long l;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(t, c) for (auto&& t : c)
#define ALL(c) begin(c), end(c)
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define mp make_pair

const int DX[] = {1, 0, -1, 0, 1, 1, -1, -1}, DY[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

  int n;
  string s;

  cin >> n >> s;
  int res = INF;

  int W = 0;
  int E = 0;
  REP(i, n) {
    if (s[i] == 'E') {
      E++;
    }
  }
  REP(i, n) {
    int tmp;
    tmp = W + E;
    if (s[i] == 'W') {
      W++;
    } else {
      E--;
      tmp--;
    }
    res = min(res, tmp);
  }

  cout << res << endl;
}



Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

bool nums[1010101];
ll cnt[1010101];

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    for (int i = 0; i < n; i++) {
        cnt[a[i]]++;
        if (nums[a[i]]) continue;
        if (cnt[a[i]] > 1) continue;
        for (int j = 2 * a[i]; j < 1010101; j += a[i]) nums[j] = true;
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if (cnt[a[i]] == 1 && !nums[a[i]]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 13036
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int n,m,i,c[100005],a,b,v,k,t[100005];
set<int> g[100005];
vector<int>first_half;
vector<int>second_half;
vector<int>total;
int par[209],group[209];
int arra[150000];
vector<ll>points;
map<char,ll>vis_c;
map<string,ll>nibo;
vector<ll>req;
vector<ll>instru;
vector< pair <ll,ll> > vect;
map<ll,ll>snuke;
int main()
{
  ll i,j,k,l,p,q,r,s,t,u=0,v,w,x,y,z,n,m;
  cin>>n>>k;
  for(i=1;i<=k;i++)
  {
    cin>>m;
    for(j=1;j<=m;j++)
    {
       cin>>p;
       snuke[p]++;	
    }	
  }
  for(i=1;i<=n;i++)
  {
     if(snuke[i]==0)
       u++;	
  }
  cout<<u;
  	
}

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

int sunuke[101];

int main(void) {

    int N, K;
    cin >> N >> K;

    for (int i = 1; i <= K; i++) {
        int d;
        cin >> d;

        for (int j = 1; j <= d; j++) {
            int a;
            cin >> a;
            sunuke[a]++;
        }
    }

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        ans += (int)(sunuke[i] == 0);
    }

    cout << ans << endl;


    return 0;
}

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

int main() {
  int n;
  cin >> n;
  bool ans = false;
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      if(n == i * j) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
  int a,b,c,k;
  cin>>a>>b>>c;
  cin>>k;
  int x=0;
  while (b<=a){
    b*=2; x+=1;
  }
  while (c<=b){
    c*=2; x+=1;
  }
  if (x<=k) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

void Main()
{
  	int n, m;
  	cin >> n >> m;
  	ll ans = 1900*m + 100*(n-m);
  	rep(i,m) ans *= 2;
  	cout << ans << endl;
	return;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
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; }
using namespace std;

int N;
ll A[100010], B[100010];

int main() {
    cin >> N;
    rep(i, N+1) cin >> A[i];
    rep(i, N) cin >> B[i];

    ll ans = 0;
    rep(i, N) {
        ll now, next;
        // i番目の街
        if (A[i] <= B[i]) {
            B[i] -= A[i];
            now = A[i];
            A[i] = 0;
        } else {
            A[i] -= B[i];
            now = B[i];
            B[i] = 0;
        }

        // i+1番目の街
        if (A[i+1] <= B[i]) {
            B[i] -= A[i+1];
            next = A[i+1];
            A[i+1] = 0;
        } else {
            A[i+1] -= B[i];
            next = B[i];
            B[i] = 0;
        }
        ans += (now + next);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int main(){
    string X; cin>>X;
    int N=SZ(X);
    int ans=0,count=0,i=0;
    while(i<N){
        if(X[i]=='S') count++;
        else{
            if(count>0) count--;
            else ans++;
        }
        i++;
    }
    printf("%d\n",2*ans);
    return 0;
}

Measured memory_bytes: 640
import sys
from operator import itemgetter
from heapq import heapify, heapreplace

def read():
    return sys.stdin.readline().rstrip()

def main():
    n, m = map(int, read().split())
    a = [int(i) for i in read().split()]
    bc = sorted([[int(i) for i in read().split()] for _ in range(m)], key=itemgetter(1), reverse=True)
    heapify(a)
    for b, c in bc:
        for _ in range(b):
            if a[0] < c:
                heapreplace(a, c)
            else:
                break
    print(sum(a))

if __name__ == '__main__':
    main()

Measured memory_bytes: 27876
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

ll left(vector<ll> &vec, ll x) {
	return *(lower_bound(begin(vec), end(vec), x) - 1);
}
ll right(vector<ll> &vec, ll x) {
	return *lower_bound(begin(vec), end(vec), x);
}

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

	ll a, b, q;
	cin >> a >> b >> q;

	vector<ll> s(a + 1);
	s[0] = -1e18;
	for (int i = 1; i <= a; i++) cin >> s[i];
	s.push_back(1e18);

	vector<ll> t(b + 1);
	t[0] = -1e18;
	for (int i = 1; i <= b; i++) cin >> t[i];
	t.push_back(1e18);

	for (int i = 0; i < q; i++) {
		ll x;
		cin >> x;

		ll sl = left(s, x);
		ll sr = right(s, x);
		ll tl = left(t, x);
		ll tr = right(t, x);

		ll slCost = abs(x - sl);
		ll srCost = abs(x - sr);
		ll tlCost = abs(x - tl);
		ll trCost = abs(x - tr);

		vector<ll> scores;
		// 神社←, 寺←
		scores.push_back(max(slCost, tlCost));

		// 神社→, 寺→
		scores.push_back(max(srCost, trCost));

		// 神社←, 寺→
		scores.push_back(slCost + trCost + min(slCost, trCost));

		// 神社→, 寺←
		scores.push_back(srCost + tlCost + min(srCost, tlCost));

		sort(begin(scores), end(scores));
		cout << scores[0] << endl;
	}

	return 0;
}


Measured memory_bytes: 3696
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<string>
//#include<string>
//#include<sstream>
using namespace std;
long long a[1000],k=0;
using namespace std;
int N,M;
int main(){
	cin >> N >> M;
	for(int i=M/N;i>=1;i--)
	{
		if(M % i == 0)
		{
		    cout << i <<endl;
		    return 0;
		}
	}
	return 0;
}

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


int main(){
	int A,B,H,M;
	cin >> A >> B >> H >> M;
	double tmp;
	tmp = 6*M - (30 * H+M*0.5) ;
	if (tmp < 0) tmp *= -1;
	double ans;
	ans = sqrt(A * A + B * B - 2 * A * B * cos(tmp  * M_PI/ 180));
	cout << setprecision(13)<< ans << endl;
	return 0;
}


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

int main(){
    int a;
    cin >> a;
    int count = 0;
    int ans = 0;
    vint A(a);
    rep(i,a) cin >> A[i];
    rep(i,a-1){
        if(A[i] >= A[i+1]){
            count++;
            ans = max(ans,count);
        }
        else count = 0;
    }
    cout << ans << endl; 
}

Measured memory_bytes: 640
from sys import stdin
import math
n = int(stdin.readline())
a = list(map(int,stdin.readline().split()))
a.sort()
ans = 0
numset = set(a)
maxval = 10**6
dp = [0]*(maxval+1)
for i in range(n):
    if dp[a[i]] >= 1: continue
    if dp[a[i]] == 0 and (i == n-1 or a[i] != a[i+1]):
        ans += 1
    j = a[i]
    while j <= maxval:
        dp[j] += 1
        j += a[i]
print(ans)

Measured memory_bytes: 128004
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int c[n-1], s[n-1], f[n-1];
  for(int i = 0; i < n-1; i++) cin >> c[i] >> s[i] >> f[i];
  for(int i = 0; i < n-1; i++){
    int t = 0;
    for(int j = i; j < n-1; j++){
      if(t < s[j]) t = s[j];
      else if(t % f[j] == 0);
      else t += f[j] - (t % f[j]);
      t += c[j];
    }
    cout << t << endl;
  }
  cout << 0 << endl;
  return 0;
}



Measured memory_bytes: 256
public class Main {
    public static void main(String[] args){
        String s = new java.util.Scanner(System.in).next();
        if(s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;
int need1[22],need2[22];
int go[1100005][23];
int put[1100005];
int f[1100005];
int n,m,k;
const int Mod=1000000007;
int main(){
	scanf("%d%d%d",&n,&m,&k);
	while (k--){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		a--;
		b--;
		need1[a]|=(1<<b);
		need2[a]|=(1<<b)*c;
	}
	n--;
	for (int t=0;t<(1<<n);t++){
		for (int i=0;i<n;i++){
			go[t][i]=-1;
		}
		int id=0;
		for (int i=0;i<n;i++){
			if (t&(1<<i)){
				if (i>0 && !(t&(1<<(i-1)))){
					go[t][id]=t^(1<<i)^(1<<(i-1));
				}
				id++;
			}
		}
	}
	for (int t=0;t<(1<<n);t++){
		put[t]=-1;
		for (int i=n-1;i>=0;i--){
			if (t&(1<<i)){
				continue;
			}
			put[t]=t^(1<<i);
			break;
		}
	}
	f[0]=1;
	for (int i=0;i<m;i++){
		for (int t=0;t<(1<<n)-1;t++){
			f[put[t]]=(f[put[t]]+f[t])%Mod;
		}
		for (int id=0;id<n;id++){
			for (int t=(1<<n)-1;t>=0;t--){
				if (go[t][id]!=-1){
					f[go[t][id]]=(f[go[t][id]]+f[t])%Mod;
				}
			}
		}
		for (int t=0;t<(1<<n);t++){
			if ((t&need1[i])!=need2[i]){
				f[t]=0;
			}
		}
	}
	int ans=0;
	for (int t=0;t<(1<<n);t++){
		ans=(ans+f[t])%Mod;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 57728
#include<bits/stdc++.h>
constexpr int M = 1e9 + 7;
constexpr int MAXN = 2e5 + 5;
#define pii pair<int, int>
typedef long long LL;
typedef unsigned long long uLL;
using namespace std;
LL n, k, fac[MAXN], rev_fac[MAXN];
inline LL qpow(LL a, LL b) {
    LL res = 1;
    while (b) {
        if (b & 1) res = res * a % M;
        a = a * a % M;
        b >>= 1;
    }
    return res;
}
inline LL getC(LL m, LL n) {
    //if (!m) return 1;
    return rev_fac[n - m + 1] * qpow(fac[m], M - 2) % M;
}
int main(){
    LL res = 0;
    cin >> n >> k;
	fac[0] = rev_fac[n + 1] = 1;
    for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % M;
    for (int i = n; i >= 1; i--) rev_fac[i] = rev_fac[i + 1] * i % M;
    for (LL i = 0; i <= min(n - 1, k); i++) {
        res = (res + getC(i, n) * getC(n - i - 1, n - 1) % M * qpow(n, M - 2) % M) % M;
    }
    cout << res << endl;
	return 0;
}

Measured memory_bytes: 3328
N = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
D = defaultdict(int)
for e in A:
    D[e] += 1
ans = 0
for key,count in D.items():
    if key > count:
        ans += count
    else:
        ans += count - key
print(ans)

Measured memory_bytes: 18164