akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return sorted 約数s 1 <= x <= n
vector<ll> divv(ll n) {
  vector<ll> v;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.push_back(i);
      if(i*i != n) v.push_back(n/i);
    }
  }
  sort(ALL(v));
  return v;
}

int main() {
    ll n,m,l;
    // string s;
    cin>>n>>m;
    vector<ll> v[20];
    rep(i,m){
        ll a;
        cin>>a;
        rep(j,a){
            ll s;
            cin>>s;
            v[i+1].push_back(s);
        }
    }
    ll p[20];
    rep(i,m){
        ll a;
        cin>>a;
        p[i+1]=a;
    }

    ll u = pow(2, n);
    ll ans = 0;
    rep(i, u) {
        ll tt = i;
        unordered_map<ll,ll> mm;
        rep(j, n){
            if(tt%2==1) mm[j+1] = 1;
            tt /= 2;
        }
        bool b = true;
        rep(j, m){
            ll sum = 0;
            for(auto it:v[j+1]) {
                if(mm[it] == 1) sum ++;
            }
            if(p[j+1] == (sum % 2) ) continue;
            else {b = false;break;}
        }
        if (b) ans++;
    }
    pr(ans);
    return 0;
}

Measured memory_bytes: 1016
#include<bits/stdc++.h>
#define fi first
#define se second
#define show(x) cerr<<#x<<"="<<x<<"\n"
typedef long long ll;
using namespace std;
//const ll MOD=(ll)1e9+7;
//const ll inf=(ll)1e14;
const int dy[]={1,0,-1};
const int dx[]={1,0,-1};
double d;

double check(double mid){
  double x=mid;
  double y=sqrt(d*d-x*x);
  return x+y;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1=freopen("in","r",stdin);
  //stream2=freopen("out","w",stdout);
  if(stream1==NULL)return 0;
  //if(stream2==NULL)return 0;
#endif
  cin>>d;
  cout<<max<double>(d*sqrt(2),(double)((int)d+1))<<endl;
#ifdef LOCAL_DEFINE
  cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}







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

#define st first
#define nd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;

int main(){
	setIO();
	string s; cin>>s;
	if(s.back()=='2'||s.back()=='4'||s.back()=='5'||s.back()=='7'||s.back()=='9') cout<<"hon\n";
	else if(s.back()=='3') cout<<"bon\n";
	else cout<<"pon\n";
}

Measured memory_bytes: 3640
N = int(input())
DP = [0]+[10**7]*(N)
li = [1] + [6**i for i in range(1,7)] + [9**i for i in range(1,6)]
for i in range(N+1):
    if(i in li):
        DP[i]=1
    else:
        for j in li:
            if(i-j>=0):
                DP[i]=min(DP[i],DP[i-j]+1)
print(DP[N])


Measured memory_bytes: 4596
#include <stdio.h>

int main(void) {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);

  if (a == b && a != c) {
    printf("%d\n", c);
  } else if (b == c && b != a) {
    printf("%d\n", a);
  } else if (c == a && c != b) {
    printf("%d\n", b);
  }
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int a[10];
    cin>>a[0]>>a[1]>>a[2];
    int s=abs(a[1]-a[0])+abs(a[2]-a[1]);
    do
    {
        s=min(s,abs(a[1]-a[0])+abs(a[2]-a[1]));
    }while(next_permutation(a,a+3));
    cout<<s;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int d, n;
	cin >> d >> n;
	if (n % 100 == 0)n = n + 1;
	if (d == 1) n = n * 100;
	if (d == 2) n = n * 10000;
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define ft first
#define sd second
#define flag bool fl=true

#define mod 1000003
#define N 100001
#define MX 1000000001
#define MXX 1000000000000000001

#define pb push_back
#define For(i, a, b) for(int i=a;i<=b;i++)
#define T int t, qq=0; cin>>t; while(qq++<t)
#define fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define scarr(array, size) for(int i=0;i<size;i++) cin>>array[i]

#define deg(rad) (rad*180.0)/pi
#define pi acos(-1)
#define log(n) (int)log2(n)
#define logg(a)(b) log(b)/log(a)


/*
//----------useful_functions----------

long long extended_euclid(ll a, ll b, ll &x, ll &y){//ax+by=c
    if(b==0)
    {
        x=1, y=0;
        return a;
    }

    ll x1, y1;
    ll d=extended_euclid(b, a%b, x1, y1);
    x=y1;
    y=x1-y1*(a/b);
    return d;
}
long long bigMod(ll a, ll b){//(a^b)%mod
    ll ans=1;
    while(b)
    {
        if(b%2==1) ans=(ans*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return ans%mod;
}
long long modInverse(ll a, ll b){//a*x=1 mod b
    ll x, y;
    ll gcd=extended_euclid(a, b, x, y);

    if(gcd==1) return ((x%b)+b)%b;
    else return 1;
}
long long nCr(ll n, ll r){//n<=1e6
    //declare globally-> ll fact[1000001];
    fact[1]=1;
    for(ll i=2;i<1000001;i++)
        fact[i]=(i*fact[i-1])%mod;

    return (fact[n]*modInverse(fact[r], mod)*modInverse(fact[n-r], mod))%mod;
}
long long josephus(ll n, ll k){//k'th person is killed out of n in the circle
    if(n==1) return 1;
    else return (josephus(n-1, k)+k-1)%n+1;
}
vector<int> sieve(ll n){//get primes up to n<=1e6 and the numbers can be handled up to 1e12
    bool fl[n+1];
    vector<int> primes;
    for(int i=0;i<=n;i++) fl[i]=false;

    for(int i=3;i*i<=n;i+=2)
        for(int j=i+i;j<=n;j+=i)
            fl[j]=true;

    primes.pb(2);
    for(int i=3;i<=n;i+=2) if(!fl[i]) primes.pb(i);
    return primes;
}

*/

int main()
{
    int n, x, y;
    cin>>n>>x>>y;
    int ans[n+1]= {};

    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            ans[min(j-i, abs(x-i)+1+abs(j-y))]++;

//        cout<<"Case "<<qq<<": ";
    for(int i=1; i<n; i++)
        cout<<ans[i]<<endl;
}


Measured memory_bytes: 3628
#include <stdio.h>
 
long long fibo(int n){
  long x[86];
  int i;
  
  x[0] = 2;
  x[1] = 1;
  
  if(n == 1) return 1;
  else
    for(i=2; i<=n; i++){
      x[i] = x[i-1] + x[i-2];
    }
  
  return x[i-1];
}
int main(void){
  int x;
  
  scanf("%d", &x);
  
  printf("%lld", fibo(x));
  
  return 0;
   
}


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

Measured memory_bytes: 8252
from heapq import heappush, heappop


class Edge:
    __slots__ = ('src', 'dest', 'capacity', 'flow')

    def __init__(self, v, w, capacity):
        self.src = v
        self.dest = w
        self.capacity = capacity
        self.flow = 0

    def other(self, v):
        if v == self.src:
            return self.dest
        else:
            return self.src

    def residual_capacity(self, v):
        if v == self.src:
            return self.capacity - self.flow
        else:
            return self.flow

    def add_flow(self, v, f):
        if v == self.src:
            self.flow += f
        else:
            self.flow -= f


class Network:
    def __init__(self, v):
        self.v = v
        self._edges = [[] for _ in range(v)]

    def add(self, edge):
        self._edges[edge.src].append(edge)
        self._edges[edge.dest].append(edge)

    def adj(self, v):
        return self._edges[v]


def max_flow(network, s, t):
    def augment_path():
        marked = [False] * network.v
        edge_to = [None] * network.v
        n = 0
        heap = [(-10**6, s, n, None)]
        while heap:
            cap, v, _, e = heappop(heap)
            edge_to[v] = e
            if v == t:
                return (-cap, edge_to)
            if not marked[v]:
                marked[v] = True
                for ne in network.adj(v):
                    n += 1
                    w = ne.other(v)
                    c = ne.residual_capacity(v)
                    if not marked[w] and c > 0:
                        heappush(heap, (max(-c, cap), w, n, ne))

        return (0, [])

    while True:
        cap, path = augment_path()
        if cap == 0:
            break
        v = t
        e = path[t]
        while e is not None:
            v = e.other(v)
            e.add_flow(v, cap)
            e = path[v]

    return sum(e.flow for e in network.adj(s) if e.src == s)


def run():
    v, e = [int(i) for i in input().split()]
    s, t = 0, v-1
    net = Network(v)

    for _ in range(e):
        v, w, c = [int(i) for i in input().split()]
        net.add(Edge(v, w, c))

    print(max_flow(net, s, t))


if __name__ == '__main__':
    run()



Measured memory_bytes: 5884
n=int(input())
import  functools
import operator
prod=functools.partial(functools.reduce, operator.mul)
a=list(map(int,input().split()))
a.sort(reverse=True)
if a[0]*a[1]>10**18 and a[-1]!=0:
    print(-1)
    exit()
if a[-1]==0:
    print(0)
    exit()
    
ans=prod(a)

if ans>10**18:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 82880
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = Long.parseLong(sc.next());
        long ans = 0;
        ans = (x / 11) * 2;
        if (x % 11 != 0) {
            if (x % 11 <= 6) {
                ans++;
            } else {
                ans += 2;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21972
N , T = map(int, input().split())
t = [int(i) for i in input().split()]

X = T

for i in range(1,N):
    if t[i] - t[i-1] >= T:
        X += T
    else:
        X += T - (T - (t[i] - t[i-1]))

print(X)

Measured memory_bytes: 25200
#include<stdio.h>
int main(void){
    int n[101]={0},a,kai=0,i;
    while(scanf("%d",&a)!=EOF)n[a]++;
    for(i=0;i<101;i++)if(kai<n[i])kai=n[i];
    for(i=0;i<101;i++)if(kai==n[i])printf("%d\n",i);
    return 0;
}

Measured memory_bytes: 596
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int X = sc.nextInt();
      int A = sc.nextInt();

      if(X<A){
        System.out.println(0);
      }else{
        System.out.println(10);
      }
          
                   }
}


Measured memory_bytes: 23124
use std::io::*;
use std::str::FromStr;

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

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i32 = read();
    let y: i32 = read();
    let mut ans = None;

    'outer: for i in 0..n + 1 {
        for j in 0..n + 1 - i {
            let k = n - i - j;

            if 10000 * i + 5000 * j + 1000 * k == y {
                ans = Some((i, j, k));

                break 'outer;
            }
        }
    }

    let (x, y, z) = ans.unwrap_or((-1, -1, -1));
    println!("{} {} {}", x, y, z)
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n , m;
    cin>>n>>m;
    int sum=0;
    int temp;
    for(int i=0; i<m; i++){
    	cin >>temp;
    	sum+=temp;
    	if(sum>n){
    		cout << -1;
    		return 0;
    	}
    }
	cout << n-sum;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
using namespace std;

int main(){
    int n=0,m=0,p=0,Asum=0,Nsum=0;
    cin >> n;
    m=n;
    double ans=0;
    vector<double> gu(n);
    while(n>0){
        int tmp;cin>>tmp;
        gu[m-n]=tmp;
        n--;
    }
    sort(gu.begin(),gu.end());
    ans = gu[0];
    for(int i=1; i<m; i++){
        ans = (ans+gu[i])/2.0;
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    ll ans = A * X + B * Y;
    ans = min(ans, 2 * C * X + max(0ll, (Y - X) * B));
    ans = min(ans, 2 * C * Y + max(0ll, (X - Y) * A));
    cout << ans << endl;
}


Measured memory_bytes: 256
n, x = map(int, input().split())
a = [int(i) for i in input().split()]

a.sort()
temp_x = x
for i in range(n):
  temp_x += -a[i]
  if i == n-1 and temp_x > 0:
    ans = n-1
  elif temp_x > 0:
    continue
  elif temp_x == 0:
    ans = i+1
  else:
    ans = i
    break

print(ans)

Measured memory_bytes: 38256
N, K = map(int, input().split())

S = [ tuple( map(int, input().split()) ) for i in range(K)]
#print(S)

Ans = [0 for i in range(N)]
Ans[0] = 1
a = [0 for i in range(N)]
a[1] = -1
for i in range(1, N):
  for s in S:
    if i-1 + s[0] <= N-1:
      a[i-1 + s[0]] += Ans[i-1]
      a[i-1 + s[0]] %= 998244353
    if i + s[1] <= N-1:
      a[i + s[1]] -= Ans[i-1]
      a[i + s[1]] %= 998244353
  Ans[i] = (Ans[i-1] + a[i]) % 998244353
  
  #print(i, Ans[i])

print(Ans[N-1])

Measured memory_bytes: 24664
#include <iostream>
#include <vector>
#include <iostream>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <list>
#include <stack>
#include <climits>
#include <unordered_set>
#include <unordered_map>
#define m7 1000000007
#define m9 1000000009
#define ll long long
#define pii pair<int,int>
#define F first
#define S second

using namespace std;
int maxlen;
int main()
{
	int h, w;
	cin >> h >> w;
	vector<vector<int> > V(h, vector<int>(w, 0));
	vector<string> T(h);
	for (int i = 0; i < h; i++) {
		cin >> T[i];
	}
	V[0][0] = 1;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (T[i][j] == '#')
				continue;
			if (i + 1 < h)
				V[i + 1][j] = ( V[i+1][j] + V[i][j]) %m7;
			if (j + 1 < w)
				V[i][j + 1] = (V[i][j] + V[i][j + 1]) % m7;
		}
	}
	cout << V[h - 1][w - 1];
	return 0;
}

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

int dp[1005][1005];
int main(){
	int q;
	cin >> q;
	rep(i,q) {
		string s, t;
		cin >> s >> t;
		int N = s.size();
		int M = t.size();
		rep(i, N) {
			rep(j, M) {
				if (s[i] == t[j]) {
					dp[i + 1][j + 1] = dp[i][j] + 1;
				} else {
					dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
				}
			}
		}
		cout << dp[N][M] << endl;
	}
	
    return 0;
}



Measured memory_bytes: 7084
N,M = map(int,input().split())
PS = [list(input().split()) for _ in range(M)]
l = [False]*N
k = [False]*N
for p,s in PS:
  p=int(p)
  if s=='AC':
    k[p-1]=True
pena = 0
for p,s in PS:
  p = int(p)
  if s=='AC':
    if not l[p-1]:
      l[p-1]=True
  if s=='WA':
    if (not l[p-1])and(k[p-1]):
      pena+=1
      
ans = sum(l)
print(ans,pena)

Measured memory_bytes: 28488
import java.util.Scanner;

public class Main
{

  public static void main(String[] args)
  {
    try (Scanner scanner = new Scanner(System.in))
    {
      while (scanner.hasNextLine())
      {
        scanner.nextLine();
        String[] data = scanner.nextLine().split(" ");
        System.out.println(solver(data));
      }
    }
  }

  private static int solver(String[] data)
  {
    int count = 0;
    int maxCount = 0;

    for (int i = 0; i < data.length; i++)
    {
      if (Integer.valueOf(data[i]) == 1)
      {
          count++;
      }
      else
      {
        maxCount = Math.max(maxCount, count);
        count = 0;
      }
    }
    return Math.max(maxCount, count)+1;

  }

}



Measured memory_bytes: 26072
from collections import Counter

#tmp_list = [1, 1, 1, 1, 0, 1, 1]


n=int(input())
a=[int(i) for i in input().split()]
b=[i-1 for i in a]
c=[i+1 for i in a]
d=a+b+c

counter = Counter(d)

print(counter.most_common()[0][1])


Measured memory_bytes: 32956
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;


int main(){
    while(1){
        int a,l;
        cin >> a >> l;
        if(l==0) break;

        vector<int> num(l);
        vector<int> res(21, -1);
        res[0] = a;
        for(int i=1; i<=20; i++){
            for(int j=0; j<l; j++){
                num[j] = a%10;
                a/=10;
            }
            sort(num.begin(), num.end());
            int big=0,small=0;
            for(int j=0; j<l; j++){
                big+=num[j]*pow(10,j);
                small+=num[l-1-j]*pow(10,j);
            }
            a=big-small;
            auto itr = find(res.begin(), res.end(), a);
            if(itr!=res.end()){
                int idx = distance(res.begin(), itr);
                cout << idx << " " << a << " " << i-idx << endl;
                break;
            }else{
                res[i] = a;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3244
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 998244353;
const long long inf = 1ll << 61;
const double eps = 0.000000000001;
typedef pair<int, int> P;
typedef pair<P, int>PP;
struct edge { int from,to, cost;};
edge es[5005];
edge res[5005];
int d[2505];
int df[2505];
int V, E;
void bel(int s) {
	rep(i, V)d[i] = inf;
	d[s] = 0;
	while (1) {
		bool upd = false;
		rep(i, E) {
			edge e = res[i];
			if (d[e.from] != inf&&d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				upd = true;
			}
		}
		if (!upd)break;
	}
}

bool findloop(int s, int t) {
	fill(df, df + V, inf);
	df[s] = 0;
	rep(i, 2 * V) {
		rep(j, E) {
			edge e = es[j];
			if (df[e.from] != inf&&df[e.to] > df[e.from] + e.cost) {
				df[e.to] = df[e.from] + e.cost;
				if (i >= V - 1 && e.to == t)return true;
			}
		}
	}
	return false;
}

signed main() {
	int p;
	cin >> V >> E >> p;
	rep(i, E) {
		int a, b, c; cin >> a >> b >> c;
		a--; b--; c -= p;
		es[i] = { a,b,-c };
	}
	if (findloop(0, V - 1))cout << -1 << endl;
	else {
		cout << max(0ll, -df[V - 1]) << endl;
	}
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;

constexpr int INF       = 1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

typedef int64_t ll;

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

#define SPRE(x) setprecision(x) // 精度を指定

int main()
{
	cin.tie(0);
    ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	vector<int> a;
	for(int i = 0; i < N; ++i){
		int t;
		cin >> t;
		a.push_back(t);
	}
	sort(a.begin(), a.end());
	set<int> need;
	ll sum = 0;
	int k = a.size() - 1;
	while(k >= 0 && a[k] >= K)
		need.insert(k--);
	for(int i = k; i >= 0; --i){
		sum += a[i];
		if(sum >= K) {
			for(int j = i; j <= k; ++j)
				need.insert(j);
			k = i;
			sum -= a[i];
		}
	}

	/* cerr << "need::"; */
	/* for(auto t : need) */
	/* 	cout << t << ','; */
	/* cerr << '\n'; */

	cout << a.size() - need.size() << '\n';



}



Measured memory_bytes: 512
def main():
    N, M = map(int, input().split())
    X = list(map(int, input().split()))

    if N >= M:
        print(0)
        exit()
    sort_X = sorted(X)
    diff = []
    for i in range(M-1):
        diff.append(sort_X[i+1]-sort_X[i])

    sort_diff = sorted(diff)

    ans = 0
    for i in range(len(sort_diff) - (N - 1)):
        ans += sort_diff[i]

    print(ans)
    

main()

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

#define ll long long int
#define ld long double
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back

using namespace std;
typedef pair<int, int> pii;

bool hasGCD[1000001] = {false};

bool decompose(int n) {
    bool found = true;
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) {
            if (hasGCD[i]) found = false;
            hasGCD[i] = true;
            while (n % i == 0) n /= i;
        }
    }
    if (n != 1) {
        if (hasGCD[n]) found = false;
        hasGCD[n] = true;
    }

    return found;
}

int main() {
    fastIO;
    int n;
    cin >> n;
    int a[n];
    for (int &i : a) cin >> i;

    bool isPairwise = true;
    for (int i = 0; i < n; i++) {
        isPairwise = isPairwise && decompose(a[i]);
    }
    if (isPairwise) {
        cout << "pairwise coprime";
        return 0;
    }

    int gcd = a[0];
    for (int i = 0; i < n; i++) {
        gcd = __gcd(gcd, a[i]);
    }
    if (gcd == 1) cout << "setwise coprime";
    else cout << "not coprime";


}


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

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

int n;
vector<int> a;
vector<vector<int>> g;
vector<int> vec;
vector<int> ans;

void dfs(int v, int p) {
    int pos = lower_bound(all(vec), a[v]) - vec.begin();
    int bf = vec[pos];
    vec[pos] = a[v];
    ans[v] = lower_bound(all(vec), INF) - vec.begin(); 
    for(int nv: g[v]) {
        if(nv == p) continue;
        dfs(nv, v);
    }
    vec[pos] = bf;
}

void solve() {
	cin >> n;
    a.resize(n);
    rep(i, n) {
        cin >> a[i];
    }
    g.assign(n, vector<int>());
    rep(i, n - 1) {
        int u, v; cin >> u >> v; --u, --v;
        g[u].pb(v);
        g[v].pb(u);
    }
    vec.assign(n, INF);
    ans.resize(n);
    //vector<int> v(n, INF);
    dfs(0, -1);
    rep(i, n) {
        cout << ans[i] << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 30380
s = input()
for i in range(len(s)//2):
  if s[2* i] == 'L' or s[2 * i +1] == 'R':
    print('No')
    exit()
if len(s) % 2 == 1:
  if s[-1] == 'L':
    print('No')
    exit()
print('Yes')    

Measured memory_bytes: 3060
#coding:utf-8
import sys
 
 
def main():
    list1  = list(map(int, input().split(' '))) 
    a, b, k = list1
  
    if a > k:
        a = a - k
      
    elif a + b >= k:
        b = b - (k - a)
        a = 0
        
    else:
        a = 0
        b = 0
        
    print(a, b)
    
    
  
    return 0
 
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
// ------------------------------------
// Date:2018/ 2/23
// Problem:ABC 048 BoxesAndCandies c.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()

using ll = long long;

#define MOD 1000000007

int N;
int x;

int main()
{
  ll cnt = 0ll;
  cin >> N >> x;
  vector<int> a(N);
  REP(i,N) {
    cin >> a[i];
  }
  
  REP(i,N-1) {
    if (a[i] + a[i+1] > x) {
      if (a[i] > x) {
        cnt += a[i+1];
        a[i+1] = 0;
        cnt += a[i] - x;
        a[i] = x;
      } else {
        cnt += a[i+1] - (x-a[i]);
        a[i+1] = x - a[i];
      }
    }
  }
  cout << cnt << endl;
  return 0;
}



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

int main(){
	
	string s, t, sol = "";
	int n;
	
	cin >> n;
	cin >> s >> t;
	
	for (int i = 0; i < n; i++){
		sol+= s[i];
		sol+= t[i];
	}
	
	cout << sol;
	
}


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

int k, m, n;
ll t[1 << 17], d[1 << 17];
vector<int> v(4);

int main()
{
    for (int i = 0; i < 6; i++)
    {
        cin >> m;
        v[m - 1]++;
    }
    sort(v.begin(), v.end());
    int a[4] = {1, 1, 2, 2};
    bool flag = 0;
    for (int i = 0; i < 4; i++)
    {
        if (v[i] != a[i])
            flag = 1;
    }
    if (!flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

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

using namespace std;

string s;
string::iterator it;

int solve(){
  int res = 0;
  ++it;
  if(*it == '['){
    vector<int> v;
    while(*it == '['){
      v.push_back(solve());
      ++it;
    }
    sort(v.begin(),v.end());
    for(int i = 0 ; i <= (int)v.size()/2 ; i++){
      res += v[i];
    }
  }else{
    while(isdigit(*it)){
      res *= 10;
      res += (*it - '0');
      ++it;
    }
    (res /= 2)++;
  }
  return res;
}

int main(){
  int N;
  cin >> N;
  while(N--){
    cin >> s;
    it = s.begin();
    cout << solve() << endl;
  }
  return 0;
}

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

using namespace std;

long long inf=1000000007;

int main(){
	int n;
	cin>>n;
	vector<int> stick(n);
	for(int i=0;i<n;i++) cin>>stick.at(i);
	sort(stick.begin(),stick.end());

	int ans=0;

	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			int l=j,r=n-1;
			while(l<r){
				int mid=ceil((double)(l+r)/2);

				if(stick.at(mid)<stick.at(i)+stick.at(j)){
					l=mid;
				}else{
					r=mid-1;
				}
			}

			int R=r;

			l=j+1;
			r=n;
			while(l<r){
				int mid=(l+r)/2;

				if(stick.at(mid)>stick.at(j)-stick.at(i)){
					r=mid;
				}else{
					l=mid+1;
				}
			}

			int L=l;

			ans+=max(0,R-L+1);
		}
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int N,X,T;
	cin>>N>>X>>T;
	if (N%X==0){
		cout<<N/X*T<<endl;
	}else{
		cout<<N/X*T+T<<endl;
	}

	return 0;
}

Measured memory_bytes: 3188
use std::io::*;
use std::str::FromStr;
use std::collections::*;

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



fn main() {
    let N: isize = read();
    let mut D = Vec::new();
    for _ in 0..N {
        let d: isize = read();
        D.push(d);
    }
    let mut ans: isize = 0;
    for n1 in 0..N {
        for n2 in n1+1..N {
            ans += D[n1 as usize]*D[n2 as usize];
        }
    }

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

Measured memory_bytes: 2084
import java.util.*;
import static java.lang.Math.*;

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

		// 入力
		int n = sc.nextInt();// N
		int a = sc.nextInt();// A
		int b = sc.nextInt();// B


		// 各桁の数の和がa以上b以下ならカウントアップ
		int Num = 0;
		for(int i = 1; i <= n; i++){
			if(a <= sumEach(i) && sumEach(i) <= b){
				Num = Num + i;
			}
		}

		// 出力
		System.out.println(Num);
	}

	// 各桁の数の和を算出
	static int sumEach(int n){
		
		String s = String.valueOf(n);

		int sum = 0;
		for(int i = 0; i < s.length(); i++){
			sum = sum + Integer.parseInt(s.substring(i, i + 1));
		}
		return sum;
	}

}




Measured memory_bytes: 26428
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=200010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int A[MAXN];

bool check(int ted){
	for (int i=1; i<=ted; i++) if (A[i]+A[2*ted+1-i]<m) return 0;
	return 1;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>m;
	for (int i=1; i<=2*n; i++) cin>>A[i];
	sort(A+1, A+2*n+1);
	reverse(A+1, A+2*n+1);
	int dwn=0, up=n+1;
	while (up-dwn>1){
		int mid=(dwn+up)>>1;
		if (check(mid)) dwn=mid;
		else up=mid;
	}
	debug(dwn)
	for (int i=1; i<=dwn; i++) ans=max(ans, A[i]+A[2*dwn+1-i]-m);
	for (int i=2*dwn+1, j=2*n; i<j; i++, j--) ans=max(ans, A[i]+A[j]);
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int x,y;
  cin >> x >> y;
  int ans=MAX*2;
  if(x<=y) {
    ans=min(ans,y-x);
    ans=min(ans,abs(-y-x)+1);
  } else {
    ans=min(ans,x-y+2);
    ans=min(ans,abs(-x-y)+1);
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<" ";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n;
    cin>>n;
    vector<ll> a(100000);
    ll tmp;
    for(ll i=0; i<n; i++) {
        cin>>tmp;
        a[tmp]=a[tmp]+1;
    }
    ll ans=0;

    for(ll i=0; i<99998; i++) {
        if (ans < (a[i]+a[i+1]+a[i+2])){
            ans = a[i]+a[i+1]+a[i+2];
        }
    }

    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	string s;cin>>s;
	int n=s.size();
	int A[n+1]={};
	rep(i,0,n) if(s[i]=='<') A[i+1]=A[i]+1;
	for(int i=n-1;i>=0;i--) if(s[i]=='>') A[i]=max(A[i],A[i+1]+1);
	//print(A,n+1);
	long sum=0;
	rep(i,0,n+1) sum+=A[i];
	cout<<sum<<endl;
}

Measured memory_bytes: 2820
# A=gets.to_i
# B=gets.split.map(&:to_i)
# C=N.times.map{gets.to_i}
# D=N.times.map{gets.split.map(&:to_i)}
# S=gets.chomp

P,Q,R=gets.split.map(&:to_i)
puts P+Q+R-[P,Q,R].max

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int D[11];
int main(){
    int x[4];
    scanf("%d %d %d %d", x, x + 1, x + 2, x + 3);
    for(int i = 0; i < 4; i++){
        D[x[i]]++;
    }
    if(D[1] == 1 && D[9] == 1 && D[7] == 1 && D[4] == 1)    puts("YES");
    else puts("NO");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A,B, x,num=0,q,w,e,r,t,target;
  cin >> A>>B;

  for(int i=A; i<=B; i++){
    target = i;
    q=target%10; 
    target/=10;
    w=target%10; 
    target/=10;
    e=target%10; 
    target/=10;
    r=target%10; 
    target/=10;
    t=target%10; 

    if(q==t &&w==r){
      num+=1;
    }
  }
  cout << num << endl;
  
}

Measured memory_bytes: 256
n = map(int, input())
d_list = list(map(int, input().split()))

sum = 0
for i in range(len(d_list)):
    for j in range(len(d_list)):
        if i == j:
            continue
        elif i > j:
            continue
        else:
            sum += d_list[i] * d_list[j]
            
print(sum)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

class UnionFind{
public:
    //親の番号を格納する。親だった場合はー（その集合のサイズ）
    vector<int> parents;

    //作る時はparentsを-1で初期化する
    //こうすることで全部ばらばらになる
    UnionFind(int n){
        parents = vector<int>(n, -1);
    }

    //Aがどのグループにいるか調べる
    int root(int A){
        if(parents[A]<0) return A;
        return parents[A] = root(parents[A]);
    }

    //自分のいるグループの大きさを調べる
    int size(int A){
        return -parents[root(A)];
    }

    //AとBをくっつける
    bool connect(int A, int B){
        //AとBを直接ではなく親同士をくっつける
        A=root(A);
        B=root(B);
        if(A==B){
            return false;
        }

        //大きい方（A)に小さい方（B)をくっつけたい
        if(size(A)<size(B)) swap(A, B);

        parents[A] += parents[B];
        parents[B] = A;

        return true;
    }
};

int main(){
    int N, K, L; cin >> N >> K >> L;
    UnionFind road(N), rail(N);

    for(int i=0; i<K; ++i){
        int p, q; cin >> p >> q;
        --p; --q;
        road.connect(p, q);
    }

    for(int i=0; i<L; ++i){
        int p, q; cin >> p >> q;
        --p; --q;
        rail.connect(p, q);
    }

    map<pair<int, int>, int> mp;

    for(int i=0; i<N; ++i){
        mp[make_pair(road.root(i), rail.root(i))]++;
    }

    for(int i=0; i<N; ++i){
        if(i) cout << " ";
        cout << mp[make_pair(road.root(i), rail.root(i))];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 13568
n=int(input())
s=input()
st='abcdefghijklmnopqrstuvwxyz'
ans=0
for i in range(1,n-1):
    ll=[0]*26
    rl=[0]*26
    for j in range(i):
        ll[st.index(s[j])]+=1
    for j in range(i,n):
        rl[st.index(s[j])]+=1
    cnt=0
    for j in range(26):
        cnt+=1 if ll[j]>0 and rl[j]>0 else 0
    ans=max(ans,cnt)
print(ans)

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

struct XorShift
{
    using result_type = uint32_t;
    result_type w = 123456789, x = 362436069, y = 521288629, z = 88675123;
    XorShift(result_type seed = time(nullptr))
    {
        w = seed;
        x = w << 13;
        y = (w >> 9) ^ (x << 6);
        z = y >> 7;
    }
    static const result_type min() { return 0; }
    static const result_type max() { return 0x7FFFFFFF; }
    result_type operator()()
    {
        result_type t = x ^ (x << 11);
        x = y;
        y = z;
        z = w;
        return w = (w ^ (w >> 19) ^ (t ^ (t >> 8)));
    }
    result_type rand()
    {
        result_type t = x ^ (x << 11);
        x = y;
        y = z;
        z = w;
        return w = (w ^ (w >> 19) ^ (t ^ (t >> 8)));
    }
    // [min,max] の整数値乱数
    result_type randInt(result_type min = 0, result_type max = 0x7FFFFFFF)
    {
        return rand() % (max - min + 1) + min;
    }
    // [min,max] の浮動小数点乱数
    double randDouble(double min = 0, double max = 1)
    {
        return (double)(rand() % 0xFFFF) / 0xFFFF * (max - min) + min;
    }
    // 変数をデフォルト値に設定する
    void SetDefault()
    {
        w = 123456789;
        x = 362436069;
        y = 521288629;
        z = 88675123;
    }
};
 
class RollingHash
{
    int n;
    XorShift rnd;
    static const uint64_t moda = (uint64_t)1e9 + 7;
    static const uint64_t modb = (uint64_t)1e9 + 9;
    // static const uint64_t b1 = (uint64_t)17, b2 = (uint64_t)19;
    uint64_t b1 = (uint64_t)rnd.randInt(2, 114514), b2 = (uint64_t)rnd.randInt(2, 114514);
    std::vector<uint64_t> a, b, p, q;

public:
    RollingHash(const std::string &str) : n((int)str.size()), a(n + 1, 0), b(n + 1, 0), p(n + 1, 1), q(n + 1, 1)
    {
        for (int i = 0; i < n; i++)
        {
            a[i + 1] = (a[i] * b1 + uint64_t(str[i])) % moda;
            b[i + 1] = (b[i] * b2 + uint64_t(str[i])) % modb;
            p[i + 1] = p[i] * b1 % moda;
            q[i + 1] = q[i] * b2 % modb;
        }
    }
    // [l, r) のハッシュ値を取得
    std::pair<uint64_t, uint64_t> query(int l, int r)
    {
        assert(0 <= l && l <= r && r <= n);
        uint64_t h1 = (p[r - l] * a[l] - a[r] + moda) % moda;
        uint64_t h2 = (q[r - l] * b[l] - b[r] + modb) % modb;
        return std::make_pair(h1, h2);
    }
};
 
using u64 = uint64_t;
using P = pair<u64, u64>;
 
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    RollingHash rh(s);
    set<P> st;
    int l = 0, r = 1;
    for (int i = 0; i < m; i++)
    {
        string q;
        cin >> q;
        if (q == "L++")
        {
            l++;
        }
        else if (q == "L--")
        {
            l--;
        }
        else if (q == "R++")
        {
            r++;
        }
        else
        {
            r--;
        }
        st.insert(rh.query(l, r));
    }
    cout << st.size() << endl;
}


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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> health(n);
    for(int i = 0; i < n; i++){
        cin >> health[i];
    }
    
    sort(health.begin(), health.end());
    long long int sum = 0;
    for(int i = 0; i < n - k; i++){
        sum+= health[i];
    }
    cout << sum;
}

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

using namespace std;

//#define int long long

using ll = long long;
using pii =  pair<int, int>;

const int IINF =  0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9+7;

#define for_(i, a, b) for(int i = (a);i < (b);++i)
#define rfor_(i, a, b) for(int i = (b)-1;i >= (a);--i)

#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))

#define endl '\n'

const int limit = 200005;

int N, Q;
string s;
char t[limit], d[limit];


int g[limit], ng[limit];
int solve0() {
  rep(i, N)g[i] = 1;

  rep(i, Q) {
    rep(j, N) ng[j] = 0;
    rep(j, N) {
      if(s[j] == t[i]) {
        if(d[i] == 'L' && j>0) ng[j-1] += g[j];
        else if(d[i] == 'R' && j+1<N) ng[j+1] += g[j];
      } else ng[j] += g[j];
    }
    rep(j, N) g[j] = ng[j];
  }

  int ans = 0;
  rep(i, N) ans += g[i];
  return ans;
}

int emu(int k) {
  int idx = k;
  rep(i, Q) {
    if(s[idx] == t[i]) idx += (d[i] == 'L' ? -1 : 1);
    if(idx<0 || N<=idx) break;
  }
  return idx;
}

int solve1() {
  int ans = 0, ng, ok;

  ng = -1;
  ok = N;
  while(abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if(emu(mid)>=0) ok = mid;
    else ng = mid;
  }
  ans += ng+1;

  ng = -1;
  ok = N;
  while(abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if(emu(mid)>=N) ok = mid;
    else ng = mid;
  }
  ans += N-ok;

  return N-ans;
}

int solve2() {
  int l = 0, r = N-1;
  rrep(i, Q) {
    if(s[l] == t[i] && d[i] == 'L')++l;
    if(l>0) {
      if(s[l-1] == t[i] && d[i] == 'R')--l;
    }
    if(s[r] == t[i] && d[i] == 'R')--r;
    if(r+1<N) {
      if(s[r+1] == t[i] && d[i] == 'L')++r;
    }
    if(r<l) return 0;
  }
  return r-l+1;
}

signed main() {
  cin.tie(0);cout.tie(0);
  ios_base::sync_with_stdio(false);

  cin >> N >> Q;
  cin >> s;
  rep(i, Q) cin >> t[i] >> d[i];

  //cout << solve0() << endl;
  //cout << solve1() << endl;
  cout << solve2() << endl;

  return 0;
}


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

int main()
{
  char a,b,c,d;
  cin >> a >> b  >> c >> d;
  if((b==c)&&(a==b || c==d))
  {
    cout << "Yes" << endl;
  }
  
  else
  {
    cout << "No" << endl;
  }
}
  

Measured memory_bytes: 256
dy = [1, 0, -1, 1, -1, 1, 0, -1]
dx = [1, 1, 1, 0, 0, -1, -1, -1]

def resolve():
	h, w = map(int, input().split())
	m = [[0]*w for _ in range(h)]
	s = [list(input()) for _ in range(h)]
	for i in range(h):
		for j in range(w):
			if s[i][j] == '#':
				m[i][j] = '#'
				continue
			for k in range(8):
				ny = i + dy[k]
				nx = j + dx[k]
				if 0 <= ny < h and 0 <= nx < w and s[ny][nx] == '#':
					m[i][j] += 1
	for seq in m:
		print("".join([str(i) for i in seq]))
resolve()

Measured memory_bytes: 40560
#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++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int w,a,b; cin >> w >> a >> b;
    if(a+w <= b) cout << b-a-w << endl;
    else if(b+w <= a) cout << a-b-w << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3572