akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include"custom_header.h"
#else
#define openfile 
#endif
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define ll long long
#define ld long double
#define fo(i,v,e) for(v=i;v<e;v++)
#define rfo(i,v,e) for(v=i;v>e;v--)
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define vl vector<ll>
#define sz(x) (ll)x.size()
#define vvl vector<vl>
#define vpl vector<pll>
const ll mod = 1000000007;
void solve()
{
    string s;cin>>s;
    ll i,j,n,temp = 0;
    fo(0,i,3)
    {
        temp+=(s[i]=='S');
    }
    if(temp==0)
    {
        cout<<3<<endl;
    }
    else if (temp==1)
    {
        cout<<(s[1]=='S'?1:2)<<endl;
    }
    else
    {
        cout<<3-temp<<endl;
    }
    return;
}
int main()
{
    // openfile;fastio;
    ll T = 1; 
    // cin>>T;
    while(T--)
    {solve();}
}

Measured memory_bytes: 3628
#include<stdio.h>

#define min(lhs,rhs) ((lhs)<(rhs)?(lhs):(rhs))

#define max(lhs,rhs) ((lhs)>(rhs)?(lhs):(rhs))

static inline int gcd(int a,int b){
    int r,x = min(a,b),y = max(a,b);
    while(x){
        r = y;
        r %= x;
        y = x;
        x = r;
    }
    return y;
}

static inline int lcm(int a,int b){
    return a * (b / gcd(a,b));
}

int main(void){
    int x;
    scanf("%d",&x);
    printf("%d",lcm(360,x)/x);
}

Measured memory_bytes: 1728
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            long[] arr = cin.ReadLongArray(2);
            long a = arr[0];
            long b = arr[1];
            WriteLine(Lcm(a,b));

            


        }
        long Lcm(long a, long b)
        {
            return a * b / Gcd(a, b);
        }

        long Gcd(long a, long b)
        {
            if (a < b)
                return Gcd(b, a);
            long d = 0;
            do
            {
                d = a % b;
                a = b;
                b = d;
            } while (d != 0);
            return a;
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 11348
a,b,c=map(int,input().split())
k=int(input())
while k>0:
    k-=1
    if a>=b:
        b*=2
    elif b>=c:
        c*=2
    else:
        pass
if b>a and c>b:
    print("Yes")
else:
    print('No')

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

int main() {
  int n, k, s; cin >> n >> k >> s;
  vector<int> a(n,s/2+10);
  rep(i, k) {
    a[i] = s;
  }
  rep(i,n) {
    cout << a[i];
    if (i!=n-1) cout << " ";
    else cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3768
//#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <numeric>
//#include <omp.h>
#include<memory>
#include <cstdio>

using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long int ll;
const int MOD=1000000007;
int main(){
	int X, N;
  	int p;
  	int n;
  	int own = 0;
  	int flagp = 0;
  	int flagn = 0;
  	int P[101];
  	cin >> X >> N;
  	rep(i, N){
    	cin >> P[i];
      	if(X==P[i]){
          own = 1;
        }
    }
  
  	//X自身が解
  	if(own == 0){
   		cout << X << endl;
      	return 0;
    }
  	p = X;
  	n = X;
  	rep(i, 101){
        //cout << i << endl;
		p += 1;
        n -= 1;
      	flagn = 0;
      	flagp = 0;
      	rep(j, N){
        	if(n == P[j]){
            	flagn = 1;
            } else if (p == P[j]){
              	flagp = 1;
            }
        }
        //cout << n << " " << p << endl;
      	//cout << flagn << " " << flagp << " " << endl;
      	if(flagn == 0){
          	//cout << "huga" << endl;
          	cout << n << endl;
          	break;
        } else if(flagp == 0){
       		//cout << "hoge" << endl;
          	cout << p << endl;
          	break;
        } else {
          	//cerr << n << " " << flagn << ":" << p << " " << flagp << endl;
        }
    }
    return 0;
}

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

using namespace std;
#define ll long long
#define ld long double

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int n;
    cin >> n;
    bool flag = true;
    for(int i=0;i<n;i++) {
        int x;
        cin >> x;
        if(x % 2 == 0) {
            if(!(x % 3 == 0 || x % 5 == 0)) {
                flag = false;
                break;
            }
        }
    }
    cout << ((flag) ? "APPROVED\n" : "DENIED\n");
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		sc.close();

		System.out.println((a * b) + " " + ((a + b) * 2));
	}
}


Measured memory_bytes: 26300
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int gcd(int x, int y){int r;while((r=x%y)!=0)x=y,y=r;return y;}

int main(void){
    int i=0;
    int j=0;
    int n;
    scanf("%d",&n);
    int t[100000];
    int max=0;
    int scn=0;
    for(;i<n;i++){
        scanf("%d",&t[i]);
        if(t[i]>max)max=t[i];
    }
    for(;j<n;j++){
        if(abs(t[j]-max/2)<abs(scn-max/2))scn=t[j];
    }
    printf("%d %d\n",max,scn);
}

Measured memory_bytes: 2044
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<functional>

typedef long long ll;

int main() {
	ll x, y, count = 0;
	std::cin >> x >> y;
	while (x <= y) {
		x *= 2;
		count++;
	}
	std::cout << count << std::endl;
}

Measured memory_bytes: 256
x=n=int(input())
a=[]
while n%2==0:
    a.append(2)
    n=n//2
m=3
while m*m<=n:
    if n%m==0:
        a.append(m)
        n=n//m
    else:
        m+=2
if n!=1:
    a.append(n)
b=''
for i in range(len(a)):
    b=b+' '+str(a[i])
    i+=1
print(str(x)+':'+b)


Measured memory_bytes: 5600
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    ll n;
    cin >> n;
    ll ans = n-1;

    for(ll i = 2; i * i <= n; i++){
        if(n % i == 0){
            ans = min(ans,(i-1) + (n/i - 1));
        }
    }
    cout << ans << endl;

    return 0;
}

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

long long int max(long long int a,long long int b){
  if(a>=b) return a ;
  else return b ;
}

long long int min(long long int a,long long int b){
  if(a<=b) return a ;
  else return b ;
}

long long int sa(long long int a,long long int b){
  return max(a,b)-min(a,b) ;
}

int main(){
  int n ; cin >> n ;
  vector<long long int> a(n) ;
  long long int sum = 0 ;
  for(int i=0;i<n;i++){
    cin >> a.at(i) ;
    sum += a.at(i) ;
  }
  a.push_back(0) ;
  long long int l = 0 ;
  for(int i=0;i<n;i++){
    l += a.at(i) ;
    long long int next = l + a.at(i+1) ;
    if(sa(l,sum-l)<=sa(next,sum-next)) break ;
  }
  cout << sa(l,sum-l) << endl ;
}

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

int main(){
  string S;
  cin >> S;
  if(S=="SUN"){
    cout << 7 << endl;
  }
  else if(S=="MON"){
    cout << 6 << endl;
  }
  else if(S=="TUE"){
    cout << 5 << endl;
  }
  else if(S=="WED"){
    cout << 4 << endl;
  }
  else if(S=="THU"){
    cout << 3 << endl;
  }
  else if(S=="FRI"){
    cout << 2 << endl;
  }
  else{
    cout << 1 << endl;
  }
}

Measured memory_bytes: 3608
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,k;
  cin >> a >> b >> k;

  ll ans_a = max(0LL,a-k);
  k -= a - ans_a;
  ll ans_b = max(0LL,b-k);
  cout << ans_a<< " " << ans_b << endl;
}

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

int main(){
    while(true){
        int T;
        cin>>T;
        if(T==0) break;
        vector<int> t(T);
        for(int i=0;i<T;i++) cin>>t[i];
        int n;
        cin>>n;
        vector<int> d(n),m(n);
        for(int i=0;i<n;i++) cin>>d[i]>>m[i];

        vector<int> wake(101,23);
        for(int i=0;i<n;i++) wake[d[i]-1]=min(wake[d[i]-1],m[i]);
        vector<vector<int>> dp(102,vector<int>(T,1000));
        dp[0][0]=0;
        for(int i=0;i<=100;i++){
            for(int j=0;j<T;j++){
                if(t[j]<=wake[i]) dp[i+1][(j+1)%T]=min(dp[i+1][(j+1)%T],dp[i][j]);
                dp[i+1][1%T]=min(dp[i+1][1%T],dp[i][j]+1);
            }
        }
        cout<<*min_element(dp[101].begin(),dp[101].end())<<endl;
    }
    return 0;
}


Measured memory_bytes: 3044
n = int(input())

xy = []
a_list = []

for i in range(n):
    a = int(input())
    a_list.append(a)
    for j in range(a):
        x,y = map(int,input().split())
        xy.append([x,y])
        
#print(xy)
#print(a_list)

num = 2**n
hito = []
flag = True

for i in reversed(range(num)):
    #print(i)
    hito = []
    tmp = i
    while tmp != 0:
        if tmp % 2 == 1:
            hito.append(1)
        else:
            hito.append(0)
        tmp //= 2
    """
    if len(hito) == 2:
        hito.append(0)
    elif len(hito) == 1:
        hito.append(0)
        hito.append(0)
    elif len(hito) == 0:
        hito.append(0)
        hito.append(0)
        hito.append(0)
    """
    if len(hito) != n:
        for j in range(n-len(hito)):
            hito.append(0)
    
    hito = hito[::-1]
    #print(hito)
    
    number = 0
    flag = True
    #print(hito)
    
    for j in range(n):
        #print(j)
        for k in range(a_list[j]):
            #正しいことを言う人
            if hito[j] == 1:
                #print(number,hito[xy[number][0]] , xy[number][1])
                if hito[xy[number][0]-1] != xy[number][1]:
                    flag = False
            number += 1
    if flag == True:
        print(sum(hito))
        exit()
        
print(0)
exit()


Measured memory_bytes: 45020
using System;
using static System.Console;
using static System.Convert;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        for (var i = num; i > 0; i--)
        {
            if (Math.Sqrt(i) == (int)Math.Sqrt(i)) { WriteLine(i); break; }
        }
    }
}


Measured memory_bytes: 13268
#include<iostream> 
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main(){	
	int n;
	cin>>n;
	string s[n];
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	for(int i=1;i<n;i++){
		if(s[i][0]==s[i-1][s[i-1].size()-1]){
			for(int j=0;j<i;j++){
				if(s[i]==s[j]){
					cout<<"No";
					return 0;
				}
			}
		}
		else{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
    return 0;
} 

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
res = f_inf


def resolve():
    def dfs(remove):
        global res
        if len(remove) == m:
            return

        cnt = [0] * m
        ma = -f_inf
        target = None
        for i in range(n):
            for j in range(m):
                if A[i][j] not in remove:
                    cnt[A[i][j] - 1] += 1
                    if ma < cnt[A[i][j] - 1]:
                        ma = cnt[A[i][j] - 1]
                        target = A[i][j]
                    break

        remove.add(target)
        res = min(res, ma)
        dfs(remove)

    n, m = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(n)]

    dfs(set())
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 11200
#include <stdio.h>
#include <stdlib.h>

void printTree(int,int[]);

int main(int argc, char** argv) {
    int size;
    scanf("%d",&size);
    int array[size];
    for(int i = 0; i < size; i++)
        scanf("%d",&array[i]);
    printTree(size,array);
    return (EXIT_SUCCESS);
}

void printTree(int size, int array[size]){
    for(int i = 0; i < size; i++){
        printf("node %d: ", i+1);
        printf("key = %d, ", array[i]);
        if(i > 0)
            printf("parent key = %d, ", array[(i-1)/2]);
        if(2*i+1 < size)
            printf("left key = %d, ", array[2*i+1]);
        if(2*i+2 < size)
            printf("right key = %d, ", array[2*i+2]);
        printf("\n");
    }
}



Measured memory_bytes: 2052
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define mod 998244353
#define Mod1(x) (x>=mod?x-mod:x)
#define Mod2(x) (x<0?x+mod:x)
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
char s[maxn];
int a[2*maxn],b[2*maxn],cnt[2*maxn];
int n;
int calc(int len)
{
	int tot=0;
	for(int i=1;i<=len;i++)
		tot=(tot*2+a[i])%mod;
	for(int i=0;i<2*n;i+=len*2){
		for(int j=1;j<=len;j++)
			b[i+j]=a[j];
		for(int j=len+1;j<=2*len;j++)
			b[i+j]=!a[j-len];
	}
	// printf("%d :\n",len);
	// for(int i=1;i<=2*n;i++)
	// 	write(b[i]);
	// putchar('\n');
	int p=1;
	while(p<=2*n&&a[p]==b[p])++p;
	tot=Mod1(tot+(p>2*n||a[p]>b[p]));
	return tot;
}
int main()
{
	n=read();
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
		a[i]=(s[i]=='1'),a[i+n]=(s[i]!='1');
	for(int i=1;i<=n;i++)
		if(n%i==0&&((n/i)&1))cnt[i]=calc(i);
	// for(int i=1;i<=n;i++)
	// 	printf("%d %d\n",i,cnt[i]);
	for(int i=1;i<=n;i++)
		for(int j=2*i;j<=n;j+=i)
			if(n%j==0&&((n/j)&1))cnt[j]=Mod2(cnt[j]-cnt[i]);
	// for(int i=1;i<=n;i++)
	// 	printf("%d %d\n",i,cnt[i]);
	ll ans=0;
	for(int i=1;i<=n;i++)
		ans=(ans+2ll*i*cnt[i])%mod;
	writeln(ans);
	return 0;
}

Measured memory_bytes: 3584
function main(input) {
    var n = input[0]-0;
    var str = input[1];
    var a = str.split(" ").map(v=>v-0);
    var b = str.split(" ").map(v=>v-0).sort((a,b)=>a-b);
    var ans = 0;
    for(var i=0;i<n;i++){
        if(a[i]!=b[i]) ans++;
    }
    console.log(ans<=2?"YES":"NO");
    
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;

int main(){
	cin>>n;
	ll t=0,s=0;
	for(int i=0;i<n;i++){
		ll d,x;
		cin>>d>>x;
		t+=x;
		s+=d*x;
	}
	cout<<t-1+(s-1)/9<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    string a;
    cin >> a;
    ll n = a.size();
    map<ll, ll> x;

    rep(i, 0, a.size()){
        x[a[i]]++;
    }

    ll ans = n * (n - 1) / 2.0 + 1;
    fore(t, x){
        ll tmp = t.second * (t.second - 1) / 2;
        ans -= tmp;
    }

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


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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


Measured memory_bytes: 384
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
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 end

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

    ll a, b, c;
    in >> a >> b >> c;
    ll a_[11] = {};
    a_[a]++; a_[b]++; a_[c]++;
    if(a_[5] == 2 && a_[7] == 1){
        out << "YES" << endl;
    }else{
        out << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  ll k,x;cin >> k >> x;
  string ans = "Yes";
  if(500*k<x)ans = "No";
  cout << ans << endl;
}


Measured memory_bytes: 256
def func(n):
    if n % 4 == 0:
        return n
    if n % 4 == 1:
        return 1
    if n % 4 == 2:
        return n + 1
    if n % 4 == 3:
        return 0
      
      
A, B = map(int, input().split())
print(func(A - 1) ^ func(B))

Measured memory_bytes: 3060
import re
S = input().replace('?', '.')
T = input()
for i in range(len(S)-len(T), -1, -1):
    if re.match(S[i:i+len(T)], T):
        S = S.replace('.', 'a')
        print(S[:i]+T+S[i+len(T):])
        exit()
print('UNRESTORABLE')


Measured memory_bytes: 3188
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <cstdio> 
using namespace std; 
int main(){
	long long a,b,c;
	cin >> a >> b >> c;
	bool ans=0;
	if(a+b==c){
		ans = 1;
	}
	else if (b+c == a){
		ans = 1;
	}
	else if(a+c == b){
		ans = 1;
	}
	if(ans){
		cout << "Yes" <<endl;
	}
	else{
		cout << "No" <<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(i,e) for(ll i=0;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;


ll i;


int main(){
    ll N;
    cin>>N;
    V A(N),B(N);
    rep(i,N)cin>>A.at(i)>>B.at(i);

    vector<P> jun;
    rep(i,N)jun.push_back(P(B.at(i),A.at(i)));

    sort(jun.begin(),jun.end());
    ll time=0;
    bool ans=true;
    for(ll j=0;j<N;j++){
        time+=jun.at(j).second;
        if(time>jun.at(j).first){
            ans=false;
            break;
        }
    }

    if(ans)cout<<"Yes";
    else cout<<"No";
    cout<<endl;
    

    
    
}


Measured memory_bytes: 9584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define repe(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define INF 100000000

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

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
    }
    return b;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;
    
    ll N, x; cin >> N;
    vector<bitset<48> > a(N);
    
    rep(i, N) {
        cin >> x;
        a[i]=bitset<48>(x);
    }
    
    bitset<48> k = bitset<48>(0);

    rep(i, N) {
        k^= a[i];
    }

    rep(i, N) {
        string str = (k^a[i]).to_string();
        cout << stoi(str, 0, 2) << endl;
    }

}

Measured memory_bytes: 4400
using System;
using System.Collections.Generic;

namespace ITP1_5_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var list = new List<string[]>();
            string input;
            while ((input = Console.ReadLine()) != "0 0")
                list.Add(input.Split(' '));
            foreach (var l in list)
            {
                int height = int.Parse(l[0]);
                int width = int.Parse(l[1]);
                for (int i = 0; i < height; i++)
                {
                    for (int j = 0; j < width; j++)
                        Console.Write("#");
                    Console.WriteLine();                  
                }
                Console.WriteLine();
            }
            
        }
    }
}

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

int main(void){
    char c;
    cin >> c;

    if ('a' <= c && c <= 'z') cout << 'a';
    else cout << 'A';
    return 0;
}


Measured memory_bytes: 3632
n=int(input())
a=list(map(int,input().split()))

x=[0]*n
s=sum(a)
x0_total=0
for i in range(1,n-1,2):
    x0_total+=a[i]
x[0]=s-x0_total*2

for i in range(1,n):
    if i==n-1:
        x[n-1]=2*a[n-1]-x[0]
    else:
        x[i]=2*a[i-1]-x[i-1]

print(' '.join(map(str,x)))

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

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

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



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int hash[100010] = {};
    REP(i, n){
        int a;
        cin >> a;
        hash[a]++;
    }

    int even_cnt = 0;
    int num_cnt = 0;
    REP(i, 100001){
        if(hash[i] >= 3){
            if(hash[i] % 2 == 0) hash[i] = 2;
            else hash[i] = 1;
        }
        if(hash[i] == 2) even_cnt++;
        if(hash[i] > 0) num_cnt++;
    }

    cout << (even_cnt % 2 == 0 ? num_cnt : num_cnt - 1) << "\n";
    return 0;
}


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

int main() {

  long long int a,b;

  while( cin >> a >> b ) {

    long long int c,d;
    if ( a < b ) {
      c = b;
      d = a;
    }else {
      c = a;
      d = b;
    }

    while(true) {

      if ( c % d == 0 ) {
	break;
      }
      long long int k = c%d;
      c = d;
      d = k;

    }

    cout << d << " " << a/d*b << endl;

  }

  return 0;

}

Measured memory_bytes: 1152
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

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

    ll n,k,aa=0;
	cin >> n;
	ll ans[n+1];
	rep(i,n+1){
		ans[i] = 0;
	}
	vector<string> name(n);
	rep(i,n){
		cin >> name[i];	
		sort(name[i].begin(),name[i].end());
		// rep(j,i){
		// 	if(name[i+1]==name[j+1]){
		// 		ans[j+1]++;
		// 		//cout << i+1<< j+1;
		// 		break;
		// 	}
		// }
	}

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

	ll i=0;
	ll j=i+1;

	while(j<n){
		if(name[i]==name[j]){
			aa += (j-i);
			j++;
		}
		else{
			i=j;
			j=i+1;
		}
	}
	
	// rep(i,n){
	// 	ans[i] = (ans[i]+1)*(ans[i]-2)/2 + ans[i]+1;
	// 	aa += ans[i];
	// 	cout << name[i] << endl;
	// }
	
	cout << aa << endl;
	
}

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

//#define int long long
using ll = long long;
const int INF = 1<<29;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var)  std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(int i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(int i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

const int N_MAX = 50;

int N, K;

void solve() {
  int ans = N-K+1;
  printf("%d\n", ans);
}

void input() {
  scanf("%d%d", &N, &K);
}

signed main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,n2[100001],n_sum[100001];
    while(1){
    cin>>n>>k;
    if(n==0&&k==0)return 0;
    for(int i=0;i<n;i++){
        cin>>n2[i];
    }
    n_sum[0]=0;
    for(int i=1;i<=n;i++){
        n_sum[i]=n_sum[i-1]+n2[i-1];
    }
    int maxx=-10000001;
    for(int i=k-1;i<n;i++){
        int sum=0;
        sum=n_sum[i]-n_sum[i-k];
       // cout<<sum<<endl;
        maxx=max(maxx,sum);
    }
    cout<<maxx<<endl;
    }
}

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

#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define repinv(i, st, n) for (int i = ((n)-1); i >= (st); --i)
#define MEM(a, b) memset(a, b, sizeof(a));
#ifdef LOCAL
#define debug(x) std::cerr << #x << ": " << x << endl
#else
#define debug(x) 860111
#endif
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileIO(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)

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

//mt19937 mrand(random_device{}());
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod=1e9+7;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
pii operator+(const pii&x, const pii&y) { return mp(x.X+y.X, x.Y+y.Y);}
pii operator-(const pii&x, const pii&y) { return mp(x.X-y.X, x.Y-y.Y);}
//INT_MAX, ULLONG_MAX, LLONG_MAX or numeric_limits<int>::min()

inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}

//------------------------------------------------------------------------//
int T;
const int maxn = 2e5+7;
int n;

//f(a,b)[i] = true => a, b is ok to concat at i
vector<bool> f(string &a, string &b) {
    int la = a.size(), lb = b.size();
    vector<bool> ret(la+1, true);
    for (int i = 0; i < la; i++) {
        for (int j = i, k = 0; j < la && k < lb; j++, k++) {
            if (a[j] != '?' && b[k] != '?' && a[j] != b[k]) {
                ret[i] = false;
                break;
            }
        }
    }
    return ret;
}

int calc(string &a, string &b, string &c) {
    vector<bool> ab = f(a, b), bc = f(b, c), ac = f(a, c);
    int la = a.size(), lb = b.size(), lc = c.size(), ans = la+lb+lc;
    for (int i = 0; i <= la; i++) { //a b contact
        for (int j = 0; j <= max(la, lb); j++) { //b c contact
            if (ab[i] && (j >= lb || bc[j]) && (i + j >= la || ac[i+j])) { //ok-ness
                ans = min(ans, max(max(la, i + lb), i + j + lc)); //update
            }
        }
    }
    return ans;
}

void solve()
{
	string a[3];
	cin >> a[0] >> a[1] >> a[2];
	//sort(all(a), cmp);

	int per[] = {0, 1, 2};
  int best = INT_MAX;
	do {
		string a1 = a[per[0]];
		string a2 = a[per[1]];
		string a3 = a[per[2]];
    best = min(best, calc(a1, a2, a3));
	} while ( std::next_permutation(per,per+3) );
	cout << best << endl;
	//debug(best);
  return;
}


signed main()
{
  fastIO();
  T = 1;
  //cin >> T; //this
  while(T--) solve();
  return 0;
}

/*
??? aaa bbb 6
?aa b?? aab 4
abcd bc cde 5
*/


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC152A
{
	class Program
	{
		static void Main(string[] args)
		{
			int N, M;

			var word = Console.ReadLine().Split(' ');//全体をSpace区切りで文字列として認識

			N = int.Parse(word[0]);//文字列から数字を取り出す
			M = int.Parse(word[1]);//上意

			if(N==M) Console.WriteLine("Yes");
			else Console.WriteLine("No");

			Console.ReadKey();
		}
	}
}


Measured memory_bytes: 11092
import sys

input_data = []
input_pointer = 0

output_data = []

def input_scan():
    global input_data
    input_data = sys.stdin.readlines()
    input_data = [x[:-1] for x in input_data]

def next_line():
    global input_pointer
    global input_data
    if input_pointer < len(input_data):
        input_pointer += 1
        return input_data[input_pointer - 1]
    else:
        return ""

def append_output(string):
    global output_data
    output_data.append(string)

def print_output():
    global output_data
    output_data.append("")
    sys.stdout.write("\n".join(output_data))

# problem A
# a = int(input())
# append_output(str(a + a * a + a * a * a))
# print_output()

input_scan()
s = next_line()
t = next_line()
print(sum([1 for x, y in zip(list(s), list(t)) if x != y]))


Measured memory_bytes: 13988
use std::io;
use std::collections::HashMap;

fn read_line()  -> String {
    let mut buffer = String::new();
    io::stdin().read_line(&mut buffer).expect("Couldn't read line");
    buffer.trim().to_owned()
}

fn main() {
    let _size: usize = read_line().parse().unwrap();
    let input: String = read_line();
    let vec: Vec<i32> = input.split_whitespace()
        .map(|n| n.parse().unwrap())
        .collect();
    let mut counter: HashMap<i32, i32> = HashMap::new();
    let mut should_remove: i32 = 0;

    for n in vec.iter() {
        let num = counter.entry(*n).or_insert(0);
        *num += 1;
    }

    for (key, val) in counter.iter() {
        if key > val {
            should_remove += *val;
        } else if key < val {
            should_remove += *val - *key;
        }
    }

    print!("{}", should_remove);
}


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

//long long int nish[100005];

int main()
{
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
   
  int index;
  cin>>index;
  vector<long long int>nish1;
 for(int i=1;i<=9;i++)
    nish1.push_back(i);
  
  int count=9;
  int temp=index;



  int flag=0;
  for(int i=0;i<index && count<temp;i++)
  {
    vector<long long int>nish2;
    for(int j=0;j<nish1.size();j++)
    {
       int temp2=nish1[j]%10;
       if(temp2>0)
        nish2.push_back(nish1[j]*10+temp2-1);
       if(temp2!=9)
        nish2.push_back(nish1[j]*10+temp2+1);
        nish2.push_back(nish1[j]*10+temp2);
    }
    int total=count;
    
    count+=nish2.size();
    nish1.resize(nish2.size());
    for(int k=0;k<nish2.size();k++)
        nish1[k]=nish2[k];

    //cout<<nish1[2]<<endl;
    if(count>=temp)
    {
        //cout<<temp-total-1<<endl;
        sort(nish1.begin(),nish1.end());
        cout<<nish1[temp-total-1]<<endl;
        flag=1;
        break;
    }


  }
  if(!flag){
    //cout<<"sdfs"<<endl;
    cout<<nish1[index-1]<<endl;
  }
  return 0;
}
  


Measured memory_bytes: 2848
N, K = map(int, input().split())
h = [0] + list(map(int, input().split()))

dp = [10 ** 9] * (N + 1)
dp[1] = 0

for i in range(2, N + 1):
    for j in range(max(1,i-K), i):
        # print(i,j)
        dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]))

print(dp[-1])
# print(dp)


Measured memory_bytes: 85132
def main():
  import sys
  import numpy as np
  from scipy.sparse import csr_matrix
  from scipy.sparse.csgraph import floyd_warshall
  t=np.fromstring(sys.stdin.buffer.read(),'i',sep=' ')
  n,m,l=t[:3]
  t=t[3:]
  m*=3
  print('\n'.join(map(str,map(int,floyd_warshall(floyd_warshall(csr_matrix((t[2:m:3],(t[:m:3],t[1:m:3])),[n+1]*2),0)<=l)[t[m+1::2],t[m+2::2]].clip(0,n)%n-1))))
main()

Measured memory_bytes: 23176
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtcoderTemplateForCSharp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var n = int.Parse(s);
            var tmp_n = n;
            var sn = 0;
            for (int i = 0; i < s.Length; i++)
            {
                sn += tmp_n % 10;
                tmp_n /= 10;
            }

            if (n % sn == 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    long long T;
    int N;
    cin >> T >> N;
    
    if(T == 0){
        cout << 0 <<endl;
        return 0;
    }
    
    int i = 0;
    vector<int> vec;
    while(T!=0){
        
        vec.push_back(T%N);
        T = T / N;
        i++;
    }
    cout << vec.size()<<endl;
    
    
}


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

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) (x & -(x))
#define BIT(a,b) ((ll)((a)&(1<<(b)))==0 ? false : true)

const ll MAXN=1e5+10;

ll a[MAXN];

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

    ll n,u=1000000,t=0,x=0;
    cin>>n;

    for(ll i=0;i<n;i++)
    {
        cin>>a[i];

        u=min(u , a[i]);
    }

    for(ll i=0;i<n;i++)
    {
        if (a[i]!=u)
        {
            goto E;
        }
    }

    if (u==(n-1) || 2*u<=n)
    {
        cout<<"Yes";
        return 0;
    }
    else
    {
        cout<<"No";
        return 0;
    }

    E:;

    for(ll i=0;i<n;i++)
    {
        if (a[i]>u+1)
        {
            cout<<"No";
            return 0;
        }

        if (a[i]==u)
        {
            t++;
        }
        else
        {
            x++;
        }
    }

    if (x==1)
    {
        cout<<"No";
        return 0;
    }

    if (t<=u && (x/2)+t>=(u+1))
    {
        cout<<"Yes";
        return 0;
    }
    else
    {
        cout<<"No";
        return 0;
    }
}


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

const ll mod = 1e9 + 7;
int N, T;
int D[100010];

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

  cin >> N >> T;
  for (int i = 0; i < N; i++) {
    cin >> D[i];
  }
  sort(D, D + N);

  ll ans = 1;
  for (int i = 1; i < N; i++) {
    ans = (((D + i) - lower_bound(D, D + N, D[i] - T)) + 1) * ans % mod;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;
 
class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
 
    int n = sc.nextInt();
    double d = sc.nextDouble();
    int c = 0;
    for(int i = 0;i < n;i++){
      double x = sc.nextDouble();
      double y = sc.nextDouble();
      
      double x1 = Math.pow(x,2);
      double y1 = Math.pow(y,2);
      
      double ans = Math.sqrt(x1 + y1);
      if(ans <= d){
        c++;
      }
    }
      System.out.println(c);
  }
}

Measured memory_bytes: 63796
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int X = int.Parse(s[0]);
            int t = int.Parse(s[1]);
            if (X >= t) Console.WriteLine(X - t);
            else Console.WriteLine(0);
        }
    }
}


Measured memory_bytes: 11092
// Dmitry _kun_ Sayutin (2019)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // code here
    int n = input<int>();
    int q = input<int>();

    string s = input<string>();
    
    vector<pair<char, int>> in(q);
    for (int i = 0; i != q; ++i) {
        cin >> in[i].first;
        in[i].second = (input<char>() == 'R' ? +1 : -1);
    }

    auto sim = [&](int i) {
        for (auto el: in) {
            if (el.first == s[i])
                i += el.second;

            if (i == n)
                return +1;
            if (i == -1)
                return -1;
        }

        return 0;
    };
    
    int lo = 0;
    int hi = n + 1;

    while (hi - lo > 1) {
        int mi = lo + (hi - lo) / 2;

        if (sim(mi - 1) == -1)
            lo = mi;
        else
            hi = mi;
    }

    int ans = lo;

    lo = 0;
    hi = n + 1;
    while (hi - lo > 1) {
        int mi = lo + (hi - lo) / 2;

        if (sim(n - mi) == +1)
            lo = mi;
        else
            hi = mi;
    }

    ans += lo;
    cout << n - ans << "\n";
    
    return 0;
}


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

long long MOD = 1e9 + 7;


int main(){
    int H, W; cin >> H >> W;
    vector<vector<int>> map(H, vector<int>(W));
    for (int h = 0; h < H; h++) {
        string S; cin >> S;
        for (int c = 0; c < S.size(); c++) {
            if (S[c] == '.') map[h][c] = 1;
            else map[h][c] = 0;
        }
    }

    vector<vector<int>> row_sum(H, vector<int>(W));
    for (int h = 0; h < H; h++) {
        int cum = 0;
        for (int c = 0; c < W; c++) {
            if (map[h][c] == 0) {
                row_sum[h][c] = 0;
                cum = 0;
            } else {
                cum += 1;
                row_sum[h][c] = cum;
            }
        }
        cum = row_sum[h][W - 1];
        for (int c = W - 1; c >= 0; c--) {
            if (row_sum[h][c] == 0) {
                if (c - 1 >= 0) cum = row_sum[h][c - 1];
            } else {
                row_sum[h][c] = cum;
            }
        }
    }

    vector<vector<int>> col_sum(H, vector<int>(W));
    for (int c = 0; c < W; c++) {
        int cum = 0;
        for (int h = 0; h < H; h++) {
            if (map[h][c] == 0) {
                col_sum[h][c] = 0;
                cum = 0;
            } else {
                cum += 1;
                col_sum[h][c] = cum;
            }
        }
        cum = col_sum[H - 1][c];
        for (int h = H - 1; h >= 0; h--) {
            if (col_sum[h][c] == 0) {
                if (h - 1 >= 0) cum = col_sum[h - 1][c];
            } else {
                col_sum[h][c] = cum;
            }
        }
    }

    int ans = 0;
    for (int h = 0; h < H; h ++) for (int c = 0; c < W; c++) {
        int candidate = row_sum[h][c] + col_sum[h][c] - 1;
        if (ans < candidate) ans = candidate;
    }

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

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

int main(){
    int n;
    cin >> n;
    map<int,int> mp;
    for(int i=1; i<=n; i++){
        int p;
        cin >> p;
        mp[p]=i;
    }
    set<int> se;
    ll ans=0ll;
    for(int i=n; i>=1; i--){
        int idx=mp[i];
        se.insert(idx);
        vector<int> l(2,0);
        vector<int> r(2,n+1);
        auto it=se.find(idx);
        rp(j,2){
            if(it==se.begin()) break;
            --it;
            l[1-j]=*it;
        }
        it=se.find(idx);
        rp(j,2){
            ++it;
            if(it==se.end()) break;
            r[j]=*it;
        }
        ll c=(l[1]-l[0])*(r[0]-idx)+(r[1]-r[0])*(idx-l[1]);
        ans += (ll)i*c;
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	long long int n;
	cin>>n;
	long double d;
	cin>>d;
	long long count=0;
	while(n--)
	{

		long long x , y;
		cin>>x>>y;
		long double c=sqrt(x*x+y*y);

		if (c<=d)
			count++;
	}	
	cout<<count<<endl;

}

Measured memory_bytes: 3752
#include <cstdint>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a;
	vector<int> b;
	for (int i = 0; i < n+1; ++i) {
		int ai;
		cin >> ai;
		a.push_back(ai);
	}
	int64_t cnt = 0;
	for (int i = 0; i < n; ++i) {
		int bi;
		cin >> bi;
		int beat;
		beat = min(a[i], bi);
		cnt += beat;
		a[i] -= beat;
		bi -= beat;
		beat = min(a[i + 1], bi);
		cnt += beat;
		a[i + 1] -= beat;
		bi -= beat;
	}
	cout << cnt << endl;
	return 0;
}

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

using namespace std;
using ll = long long;

const int mx = 1e7 + 9;

ll f[mx];

void calc() {
    for (int i = 1; i < mx; i++) {
        for (int j = i; j < mx; j += i) f[j]++;
        f[i] *= i;
        f[i] += f[i - 1];
    }
}

int main() {
    calc();
    int n; scanf("%d", &n);
    printf("%lld\n", f[n]);
}


Measured memory_bytes: 81920
n = int(input())

src_t = 0
src_x = 0
src_y = 0
success = True

for i in range(n):
    t, x, y = map(int, input().split(' '))
    if success == True:
        dt = t - src_t
        dist = abs(x - src_x) + abs(y - src_y)
        if dist <= dt and dist % 2 == dt % 2:
            src_t = t
            src_x = x
            src_y = y
            continue
        else:
            success = False

if success:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064