akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define Rep(i, s, n) for (int i = (int)s; i < (int)n; i++)
typedef long long ll;

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

    string s;
    cin >> s;

    if (s[0] == s[1]) {
        if (s[2] == s[3] && s[0] != s[2]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if (s[0] == s[2]) {
        if (s[1] == s[3] && s[0] != s[1]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if (s[0] == s[3]) {
        if (s[1] == s[2] && s[0] != s[1]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define scan(n) scanf("%d",&n)
#define ls(n) scanf("%lld",&n)
#define print(n) printf("%d",n)
#define pln(n) printf("%d\n",n)
#define lpln(n) printf("%lld\n",n)
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rev(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define tc           ll t1; cin>>t1; while(t1--)
#define inp         ll n; cin>>n; ll arr[n]; rep(i,0,n) cin>>arr[i];
#define vect vector<ll>
#define sortv(v)       sort(v.begin(),v.end())
#define lower(v,n)    lower_bound(v.begin(),v.end(),n)-v.begin()
#define upper(v,n)    upper_bound(v.begin(),v.end(),n)-v.begin()
#define all(v)        v.begin(),v.end()
#define bitcount(n) __builtin_popcount(n)
#define ln <<endl
#define inf          1e12+5
#define ninf         LONG_MIN
#define fast()         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
const   ll mod=1e9+7;
const ll N=1e5+5;




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

          int n;
          cin >> n;
          ll a[n];
          rep(i,0,n)
          cin >> a[i];
          int ans=0;
          rep(i,0,n)
          rep(j,i,n)
          rep(k,j,n)
          {
            if(a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k]){
            std::vector<ll> v;
            v.pb(a[i]);
            v.pb(a[j]);
            v.pb(a[k]);
            sortv(v);
            if(v[2]<(v[0]+v[1]))
              ans++;
          }
          }
          cout<<ans;
          
 
           return 0; 

} 

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;


unsigned int uns(int N){
  if(N<0)return N*-1;
  return N;
}

int main(){
  int a,b;
  string S[100];
  cin>>a>>b;
  string df(100,'#');
  //白エリアの作成
  a--;
  LOOP(i,15){
    S[i*3]=df;
    int w=0;
    S[i*3+1]=df;
    while(a&&w<100){
      S[i*3+1][w]='#';
      w++;
      S[i*3+1][w]='.';
      w++;
      a--;
    }
    S[i*3+2]=df;
  }
  //黒
  string dff(100,'.');

  b--;
  LOOP(i,15){
    S[45+i*3]=dff;
    S[45+i*3+1]=dff;
    int w=0;
    while(b&&w<100){
      S[45+i*3+1][w]='.';
      w++;
      S[45+i*3+1][w]='#';
      w++;b--;
    }
    S[47+i*3]=dff;
  }
  cout << 90 << " " << 100 << endl;
  LOOP(i,100){
    cout << S[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
adjmax = [0] * n
for _ in range(m):
    a, b = map(int, input().split())
    adjmax[a - 1] = max(adjmax[a - 1], h[b - 1])
    adjmax[b - 1] = max(adjmax[b - 1], h[a - 1])
ans = 0
for i in range(n):
    if h[i] > adjmax[i]:
        ans += 1
print(ans)

Measured memory_bytes: 84876
from collections import deque

l = input().split()

st = deque()
for k in l:
    if k in "+*-":
        n2 = st.pop()
        n1 = st.pop()
        st.append(str(eval(n1 + k + n2)))
    else:
        st.append(k)

print(st[0])



Measured memory_bytes: 5964
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpi = vector<pi>;
using vvpi = vector<vpi>;
const ull MOD = 998244353;
#ifdef LOCAL
#include "../../pp.hpp"
#define debug pp::debug
#else
#define debug(args...)
#endif

enum State {
    Win,
    Lose
};

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

    int n, k; cin >> n >> k;
    vi a(n); for (int i = 0; i < n; ++i) cin >> a[i];

    vector<State> dp(k+1, Lose);
    for (int i = 0; i <= k; ++i) {
        for (int move : a) {
            if (move <= i && dp[i - move] == Lose) {
                dp[i] = Win;
                break;
            }
        }
    }
    if (dp[k] == Win) {
        cout << "First\n";
    } else {
        cout << "Second\n";
    }
}


Measured memory_bytes: 640
s=input()
odd=["R","U","D"]
even=["L","U","D"]
ans="Yes"

for i in range(len(s)):
    if  i%2==0:
        if s[i] not in odd:
            ans="No"
    else:
        if s[i] not in even:
            ans="No"

print(ans)

Measured memory_bytes: 9092
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<queue>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()
bool comparator(P a, P b) {
	return a.first / a.second < b.first / b.second;
}


int main() {
	int x[5];
	ll sum = 0;
	rep(i, 5) {
		cin >> x[i];
		if (x[i] == 0) {
			cout << i + 1 << endl;
			return 0;
		}
	}
	

}

Measured memory_bytes: 3132
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        Set<Character> set = new HashSet<>();
        for (int i = 0; i < s.length(); i++) {
            set.add(s.charAt(i));
        }
        int min = Integer.MAX_VALUE;
        for (int i = 0; i <= 'z' - 'a'; i++) {
            char c = (char) ('a' + i);
            if (!set.contains(c)) {
                continue;
            }

            StringBuilder sb = new StringBuilder(s);
            while (sb.length() >= 0) {
                int len = sb.length();
                boolean same = true;
                for (int k = 0; k < len; k++) {
                    if (sb.charAt(k) != c) {
                        same = false;
                        break;
                    }
                }
                if (same) {
                    min = Math.min(min, s.length() - len);
                    break;
                }

                for (int k = 1; k < len; k++) {
                    if (sb.charAt(k) == c) {
                        sb.setCharAt(k - 1, c);
                    }
                }
                sb.deleteCharAt(len - 1);
            }
        }
        System.out.println(min);
    }

}


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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int N;
    ll Ai;
    multimap<ll,ll,greater<ll>> A;
    vector<ll> B;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> Ai;
        auto ai = Ai;

        ll tmp = 1;
        while( ai > 0 ){ tmp <<= 1; ai >>= 1; }
        A.emplace(Ai, tmp-Ai);
    }
    int n=0;
    for(auto itr = A.begin(); itr!=A.end();itr++){
        if(itr->first == itr->second){
            B.push_back(itr->first);
            continue;
        }
        auto itr2 = A.find(itr->second);

        if(itr2 == A.end()){
            continue;
        }
        n++;
        A.erase(itr2);
    }
    if(B.size()>=2){
        for(int i=0;i<B.size()-1;i++){
            if(B.at(i) == B.at(i+1)){
                n++;
                i++;
            }
        }
    }

    cout<<n<<endl;

    return 0;
}

Measured memory_bytes: 14964
/*
Author: Babin Dutta
*/
 
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define inf 1e18
#define mm 998244353
 
ll power(ll x, ll y, ll p)
{
    ll res = 1;  
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;  
    }
    return res;
}
ll modInverse(ll A,ll M)
{
    return power(A,M-2,M);
}

void solve(){
	int a[5];
	f(i,5) cin>>a[i];
	f(i,5){
		if(a[i] == 0){
			cout<<i+1<<endl;
			return;
		}
	}
}
 
int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;

const int MAXN = 100000;
set<int> g[MAXN + 1];
int deg[MAXN + 1], del[MAXN + 1];

struct point {
    int v;
};

bool operator<(const point& first, const point& second) {
    if(deg[first.v] != deg[second.v])
        return deg[first.v] < deg[second.v];
    else
        return first.v < second.v;
}

int main() {
    //ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;
    if(n & 1) {
        cout << "First\n";
        return 0;
    }
    for(int i = 0; i < n - 1; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        g[a].insert(b);
        g[b].insert(a);
        deg[a]++;
        deg[b]++;
    }
    for(int i = 1; i <= n; i++) {
        int cnt = 0;
        for(auto x: g[i]) {
            if(deg[x] == 1)
                cnt++;
        }
        if(cnt >= 2) {
            cout << "First\n";
            return 0;
        }
    }
    set<point> s;
    for(int i = 1; i <= n; i++) {
        s.insert({ i });
    }
    while(!s.empty()) {
        auto it = s.begin();
        if(deg[it->v] > 1)
            break;
        int temp = it->v;
        int v = *g[it->v].begin();
        s.erase({ v });
        for(auto u: g[v]) {
            s.erase({ u });
            deg[u]--;
            if(deg[u] == 0)
                deg[u] = MAXN + 1;
            if(u != temp)
                s.insert({ u });
            g[u].erase(v);
        }
    }
    for(auto it: s) {
        int i = it.v;
        if(deg[i] == MAXN + 1) {
            cout << "First\n";
            return 0;
        }
    }
    cout << "Second\n";
    return 0;
}

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

using namespace std;

int main()
{
    int n, m; cin >> n >> m;
    vector<bool> a(n+1, false), b(n+1, false);
    string ans = "IMPOSSIBLE";
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        if (x == 1) a[y] = true;
        else if (y == 1) a[x] = true;
        else if (x == n) b[y] = true;
        else if (y == n) b[x] = true;
    }

    if (a[n]) ans = "POSSIBLE";
    else {
        for (int i = 1; i <= n; ++i) {
            if (a[i] && b[i]) {
                ans = "POSSIBLE";
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}



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

const int MAXN = 333;
int n;
ld mem[MAXN][MAXN][MAXN];// represents # of 1, 2, 3 sushis
int cnt[4];

ld dp(int a, int b, int c) { // E = 1+(N-(a+b+c))/N*E + a/N*dp + ...
  if (a<0 || b<0 || c<0) return 0;
  if (a+b+c==0) return 0;
  ld &ans = mem[a][b][c];
  if (ans > -0.5) return ans;
  ans = (n+a*dp(a-1,b,c)+b*dp(a+1,b-1,c)+c*dp(a,b+1,c-1))/(a+b+c);
  //cerr << a << " " << b << " " << c << " " << ans  <<endl;
  return ans;
}

int main(){
  cin.tie(0); ios_base::sync_with_stdio(0);
  cin >> n;
  cout << setprecision(10) << fixed;
  for(int i=0;i<n;i++) {
    int a; cin >> a;
    cnt[a]++;
  }
  for(int i=0;i<=n;i++) 
    for(int j=0;j<=n;j++) 
      for(int k=0;k<=n;k++) 
        mem[i][j][k] = -1;
  cout << dp(cnt[1], cnt[2], cnt[3]) <<endl;
}


Measured memory_bytes: 522368
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut s = read::<String>().chars().collect::<Vec<_>>();
    let mut from_left_r = vec![0; n + 1];
    for i in 1..n + 1 {
        from_left_r[i] = from_left_r[i - 1];
        if s[i - 1] == 'R' {
            from_left_r[i] += 1;
        }
    }

    let r_count = from_left_r[n];
    let ans = r_count - from_left_r[r_count];
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4324
import java.util.*;
import java.io.*;

/*
   AtCoder contest code
   coder : yoichidon
 */

public class Main {
    public static void main(String[] args) {
        //whenever Tak hold, Aok can hold and end the game.
        //Therefore, Tak's best strategy is "Always move"!

        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int N = sc.nextInt();
        LinkedList<Integer>[] block = new LinkedList[W];
        for(int w=0; w<W; w++) {
            block[w] = new LinkedList<>();
            block[w].add(H);
        }
        for(int n=0; n<N; n++) {
            int x = sc.nextInt()-1;
            int y = sc.nextInt()-1;
            block[y].add(x);
        }
        for(int w=0; w<W; w++) Collections.sort(block[w]);

        int ans = 1000000;
        int curX = 0;
        for(int w=0; w<W; w++){
            curX++;
            //System.err.println(curX+" "+w);
            while(block[w].peek()<curX) block[w].poll();
            //System.err.println(block[w].peek());
            ans = Math.min(ans, block[w].peek());

            while(w<W-1 && block[w+1].contains(curX)) curX++;
            if(curX >= block[w].peek()) break;
        }

        System.out.println(ans);


    }
}


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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if(a.at(a.size()-1) == b.at(0) && b.at(b.size()-1) == c.at(0))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

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

int main(){
    int A,V,B,W,T;
    cin >> A >> V >> B >> W >> T;
    
    //bool ans = false;
    
    int sokudo = abs(W - V);
    int kyori = abs(B - A);
    
    ////逃げる方が早いとき
    if( W >= V){
        cout << "NO" << endl;
        return 0;
    }
    
    int zikan = kyori/sokudo;
    if(kyori % sokudo !=0) zikan++;
    
    ////時間と比較
    if(T >= zikan){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 3672
from collections import deque

H, W = map(int, input().split())
S = [[i for i in input()] for j in range(H)]

dir = [[1,0], [-1,0], [0,1], [0,-1]]
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == "#": continue
        ls = deque([[i, j]])
        dp = [[float("inf") for k in range(W)] for l in range(H)]
        dp[i][j] = 0
        while len(ls) > 0:
            x, y = ls.popleft()

            for dx, dy in dir:
                if x+dx < 0 or H-1 < x+dx: continue
                if y+dy < 0 or W-1 < y+dy: continue
                if S[x+dx][y+dy] == "#" or dp[x+dx][y+dy] != float("inf"): continue
                if dp[x+dx][y+dy] > dp[x][y] + 1:
                    dp[x+dx][y+dy] = dp[x][y] + 1
                    ls.append([x+dx,y+dy])

        for h in range(H):
            for w in range(W):
                if dp[h][w] == float("inf"): continue
                ans = max(ans, dp[h][w])

print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	ll a,b;
	cin >> a >> b;
	if (a*b <= 0)cout << "Zero" << endl;
	else if(a<0&&b<0&&abs(a-b)%2==0) {
		cout << "Negative" << endl;
	}
	else cout << "Positive" << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.InputStream;

import java.io.PrintWriter;

import java.util.HashMap;

@SuppressWarnings("unchecked")
public class Main {
    public static void main(String[] args) throws IOException {
        PrintWriter out = new PrintWriter(System.out);

        final int N = nextInt();
        final int M = nextInt();

        long[] A = new long[N];

        for (int i = 0; i < N; i++) A[i] = nextInt();

        for (int i = 1; i < N; i++) A[i] += A[i - 1];

        HashMap<Long, Long> m = new HashMap<>();

        m.put(0L, 1L);

        for (int i = 0; i < N; i++) {
            if (m.containsKey(A[i] % M))
                m.put(A[i] % M, (long)m.get(A[i] % M) + 1);
            else m.put(A[i] % M, 1L);
        }

        long ans = 0;

        for (Long x : m.values())
            ans += x * (x - 1) / 2;

        out.println(ans);

        out.flush();
    }

    // FastScanner start
    static final InputStream in = System.in;
    static final byte[] buffer = new byte[1024];
    static int ptr = 0;
    static int buflen = 0;
    static boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    static int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    static boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    static String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    static long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    static int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    static double nextDouble() {
        return Double.parseDouble(next());
    }
    // FastScanner end
}


Measured memory_bytes: 31164
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    n, m, k = map(int, readline().rstrip().split())
    A = list(map(int, readline().rstrip().split()))
    B = list(map(int, readline().rstrip().split()))

    a, b = [0], [0]
    for i in range(n):
        a.append(a[i] + A[i])
    for i in range(m):
        b.append(b[i] + B[i])

    ans = 0
    j = m

    for i in range(n + 1):
        if a[i] > k:
            break
        while b[j] > k - a[i]:
            j -= 1
        ans = max(ans, i + j)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 47800
data=[]
score=[]

while true
  p,s=gets.chomp.split(",").map { |s| s.to_i }
  break if p==0&&s==0
  data.push([p,s,0])
  score.push(s)
end

score=score.uniq.sort.reverse
score.size.times{|i|
  data.size.times{|j|
    if data[j][1]==score[i] then
      data[j][2]=i+1
    end
  }
}

while q=gets
  q=q.chomp.to_i
  data.size.times{|i|
    if data[i][0]==q then
      p data[i][2]
      break
    end
  }
end



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

int main() {
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int cnt = 0;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if( 500*i + 100*j + 50*k == x){
          cnt++;
        }
      }
    }
  }
  cout << cnt << endl;
  return 0;
  
}

Measured memory_bytes: 256
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import decimal
import heapq
import collections
import itertools
from operator import mul

sys.setrecursionlimit(100001)


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

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

N = int(input())
s = input()

items_list = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            tmp = [str(i), str(j), str(k)]
            items_list.append(tmp)

ans = 0
for pin in items_list:
    cnt = 0
    for i in range(len(s)):
        if s[i] == pin[cnt]:
            cnt += 1
            if cnt == 3:
                ans += 1
                break

print(ans)

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

int main(){
	int m;
	cin>>m;
	rep(z,m){
		long long money;
		int time,n;
		cin>>money>>time>>n;
		vector<long long> ans;
		long long memory=money;
		rep(u,n){
			int tax,fee;
			long double percent;
			cin>>tax>>percent>>fee;
			long long nenri=0;
			money=memory;
			rep(i,time){
				if(tax==0){//???????????´???
					nenri+=(int)money*percent;
					money-=fee;
				}else{//???????????´???
					money=(long long)money*(1+percent)-fee;
				}
			}
			if(tax==0)money+=nenri;
			ans.push_back(money);
		}
		sort(ans.begin(),ans.end());
		cout<<ans[ans.size()-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1264
#include <bits/stdc++.h>
using namespace std;
 
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MOD = 1e9+7;
const double PI  = 3.14159265358;
const double EPS = 1e-8;

#define INT_MX 2147483647
#define INF ((int)1e9)
#define LLINF ((ll)1e18)
#define F first
#define S second
#define MP(x,y) make_pair(x,y)
#define sz(v) ((int)v.size())
#define rs(n) resize(n)
#define ALL(v) v.begin(),v.end()
#define reset(v) memset((v),0,sizeof(v))
#define EB emplace_back
#define PB push_back
#define PF push_front
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define vec vector
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

void solve(){
	int n, k;
	ll ans = 0;
	vec<int> v;
	
	cin >> n >> k;
	v.rs(n);
	rep(i, n) cin >> v[i];
	
	sort(ALL(v));
	rep(i, max(0, n - k)) ans += v[i];
	
	cout << ans << '\n';
}

int main(){
	int t = 1;
	
	while(t--){
		solve();
	}
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w",stdout);
    #endif

    string s,t;
    cin>>s>>t;
    vector<char> s1;
    vector<char> s2;

    for(auto i: s){
        s1.push_back(i);
    }

    for(int i = 0;  i< t.size() - 1; i++){
        s2.push_back(t[i]);

    }

    if(s1 == s2){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    


}

Measured memory_bytes: 3644
#include <iostream>
using namespace std;
int main (void) {
    string n;

    cin >> n;

    if ((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3])) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define fi first
#define sc second
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define msi map<string,int>
#define si set<int>
#define all(v) v.begin(),v.end()
#define sz(v)  int((v).size())
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define dep(i,a,b)    for(int i=a;i>=b;i--)
#define isinarr(i,n) ((i>=0)?((i<n)?1:0):0)
#define fastio  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define present(container, element) (container.find(element) != container.end())      //set,map etc.
#define cpresent(container, element) (find(all(container),element) != container.end())    //vector
#define hell 1000000007
#define PI 3.14159265
#define mp make_pair
#define inparr(a,n) rep(i,0,n)cin>>a[i];
#define strwspaces(s) getline(cin,s)
#define give(x,y) cout<<x<<" "<<y<<endl;
#define setp(n) cout<<fixed<<setprecision(n);
#define    endl '\n'
#define inp(n) int n;cin>>n;

using namespace std;

int i,j,k,l;

void solve()
{
    int x,n;
    cin>>x>>n;
    mii m;
    rep(i,0,n)
    {
      cin>>j;
      m[j]=1;
    }
    int l=0,diff=1;
    if(m[x]==0)
    {
      cout<<x<<endl;
      return ;
    }
    while(l==0)
    {
      int add=x+diff;
      int minus=x-diff;
      if(m[minus]==0)
      {
        cout<<minus<<endl;
        return ;
      }
      if(m[add]==0)
      {
        cout<<add<<endl;
        return ;
      }
      diff++;
    }
} 



signed main()
{
    fastio
    int t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

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

ll gcd(ll x, ll y)
{
  if (x % y == 0)
  {
    return y;
  }
  return gcd(y, x % y);
}

int main()
{
  ll A, B, C;
  cin >> A >> B >> C;
  if (A-B == B-C)
  {
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def r_sort(a) a.sort{|a,b|b<=>a} end

n = inp[0]
p = inp
f = false
c = 0
p.each.with_index do |d,i|
  if((p[i]-1)!=i)
    c+=1
  end
end
puts (c==0 or c==2)? "YES" : "NO"

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

int main()
{
  int A;
  int B;
  
  cin>>A;
  cin>>B;
  
  if (A>=13){
    cout<<B<<'\n';
  }
  else if(A>=6){
    cout<<(B/2)<<'\n';
  }
  else{
    cout<<0<<'\n';
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define int long long 
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back
#define S ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std; 
signed main()
{
    S;
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    while(b<=a && k)
    {
        b*=2;
        k--;
    }
    while(c<=b &&k)
    {
        c*=2;
        k--;
    }
    if(c>b && b>a)
    cout<<"Yes";
    else
    cout<<"No";
}
    

Measured memory_bytes: 3560
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;

int main(){
int n,m,l;
cin >> n >> m >> l;
int A[n][m] ;
int B[m][l] ;
long long C[n][l] ;

for(int i = 0; i<n; i++){
     for(int j = 0; j<l; j++){
          C[i][j] = 0;
     }
}

for(int i = 0; i<n; i++){
     for(int j = 0; j<m; j++){
               cin >> A[i][j];
     }
}
     for(int j = 0; j<m; j++){
          for(int k = 0; k<l; k++){
               cin >> B[j][k];
          }
     }
for(int i = 0; i<n; i++){
     for(int j = 0; j<l; j++){
          for(int k = 0; k<m; k++){
               C[i][j] += A[i][k] * B[k][j];
          }
     }
}
for(int i = 0; i<n; i++){
     for(int j = 0; j<l; j++){
          if(j == l-1){cout << C[i][j];
          }else{
               cout << C[i][j] << " ";
          }
     }cout << endl;
}
return 0;
}


Measured memory_bytes: 3164
#include "bits/stdc++.h"
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//adds two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set]
//(2)set.order_of_key(k)[count of elements strictly less than k]
#define ll long long
#define ld long double
#define vv vector
#define pp pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
typedef pair<ll, ll> pll;
typedef vv<bool> vbool;
typedef vv<ll> vll;
typedef vv<ld> vld;
typedef vv<pll> vpll;
#ifdef LOCAL
#include "prettyprint.hpp"
#define LG(args...)                           \
{                                             \
	string _s = #args;                        \
	replace(_s.begin(), _s.end(), ',', ' ');  \
	stringstream _ss(_s);                     \
	err(istream_iterator<string>(_ss), args); \
	cerr << endl;                             \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << "(" << *it << ":" << a << ") ";
	err(++it, args...);
}
#define fastio
#else
#define LG(...)
#define fastio                    \
	ios_base::sync_with_stdio(0); \
	cin.tie(0);
#define endl "\n"
#endif
//:::::::::::::::::::::::::::::::::::::::::::::
const ll INF = 9e18;
const ll MOD = 1e9 + 7;

int main(){
	fastio;
	string s;
	 cin>>s;
	ll mx = 0;
	for(ll i=0; i<3; i++){
		if(s[i]=='R'){
			ll c=0;
			while(s[i] =='R'){
				c++;
				i++;
			}
			mx = max(c,mx);
		}
	}
	cout<<mx;
}

Measured memory_bytes: 3636
N,M,K=map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
AA=[0]
BB=[0]
a,b=0,0
for i in range(N):
  a+=A[i]
  AA.append(a)
for i in range(M):
  b+=B[i]
  BB.append(b)
import bisect
cnt=0
for i in range(N+1):
  T=K-AA[i]
  if T>=0:
    d=bisect.bisect_right(BB,T)
    D=i+d-1
    cnt=max(cnt,D)
print(cnt)

Measured memory_bytes: 47536
#include<iostream>
using namespace std;
int main()
{
	long long n,sum=0;
	cin>>n;
	long long a[n+1];
	for(int i=1;i<=n;i++)
	{
		if(i%3==0||i%5==0)
		    a[i]=0;
		else
		    a[i]=i;
		sum+=a[i];
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3144
#include <iostream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
using namespace std;
int main(){
	string s;
	cin>>s;
	int len=s.length();
	int i,k,count=0;
	if(len%2==0){
		k=len/2;
	}else{
		k=len/2+1;
	}
	for(i=0;i<k;i++){
		if(s[i]!=s[len-i-1]){
			count++;
		}
	}
	cout<<count<<endl;
}

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

int main(){
   vector<int> A(3);
   for(int i = 0; i < 3; i++){
        cin >> A[i];
   }

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

   int ans = A[0] * A[1] / 2;

    cout << ans << endl;

	return 0;
}

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

using namespace std;

int main()
{
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	int ans=((a+9)/10+(b+9)/10+(c+9)/10+(d+9)/10+(e+9)/10);
	cout<<min({(ans-(a+9)/10)*10+a,(ans-(b+9)/10)*10+b,(ans-(c+9)/10)*10+c,(ans-(d+9)/10)*10+d,(ans-(e+9)/10)*10+e})<<endl;

	return 0;
}


Measured memory_bytes: 256
///Nahid Hasan Raju
#include <bits/stdc++.h>
#define ll long long
#define MS(ARRAY,VALUE) memset(ARRAY,VALUE,sizeof(ARRAY))
#define Fin freopen("input.txt","r",stdin)
using namespace std;

#define P(XX) cout<<XX<<endl
#define P1(XX) cerr<<"db1: "<<XX<<endl
#define P2(XX,YY) cerr<<"db2: "<<XX<<" "<<YY<<endl
#define P3(XX,YY,ZZ) cerr<<"db3: "<<XX<<" "<<YY<<" "<<ZZ<<endl
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define Fout freopen("output.txt","w",stdout)
#define rep(i,a,b) for(i=a;i<=b;i++)
#define EPS 0.00000001
#define INF INT_MAX
#define PI 2*acos(0.0)
#define set(XX,POS) XX|=(1<<POS)
#define reset(XX,POS) XX&=(~(1<<POS))
#define check(XX,POS) (bool)(XX&(1<<POS))
#define toggle(XX,POS) (XX^(1<<POS))
#define SORT(v) sort(v.begin(),v.end())
#define REVERSE(V) reverse(v.begin(),v.end())
#define VALID(X,Y,R,C) X>=0 && X<R && Y>=0 && Y<C
#define SIZE(ARRAY) sizeof(ARRAY)/sizeof(ARRAY[0])
#define RT printf("Run Time : %0.3lf seconds\n", clock()/(CLOCKS_PER_SEC*1.0))
#define pb push_back
#define pll pair<ll,ll>
#define pii pair<int,int>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree< pair<int,int> , null_type, less< pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> odrst;

#define MOD 1000000007ll
#define MX 2000006  ///200005

ll m, n;
ll a[MX], b[MX];
string s,s1;
map<ll,int>mp;

void func(ll p)
{

}
int main()
{
    int test=1, tc=0, i, j;
    #ifndef ONLINE_JUDGE
    //Fin;
    test=3;
    #endif
    ll k, ans, t, kk;
    //scanf("%d", &test);
    while(test--)
    {
        j=k=ans=0;
        cin>>n;
            for(i=1;i<=n;i++)
            {
                cin>>j;
                b[i]=j;
                a[i]=j+a[i-1];
            }
            for(i=1;i<=n;i++)
            {
                k=a[n]-a[i];
                k%=MOD;
                ans+=(k*b[i])%MOD;
            }
            ans%=MOD;

        P(ans);
        return 0;

        if(t)puts("YES");
        else puts("NO");

        printf("%lld\n", ans);
        for(i=0;i<ans;i++)
        {
            printf("%lld", b[i]);
        }
    }
    return 0;
}



Measured memory_bytes: 6676
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
int main() 
{
    int n,d,x,y;
    cin>>n>>d;
    int c=0;
    while(n--)
    {
        cin>>x>>y;
        double a,b;
        a=x;
        b=y;
        double r=sqrt((a*a)+(b*b));
        // cout<<r<<"\n";
        if(r<=(double)(d))
        c++;
    }
    cout<<c<<"\n";
}


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define MOD 1000000007

typedef pair<li, li> PI;

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

	map<pair<li, li>, li> m;

	for (li i = 1; i <= n; ++i) {
		stringstream ss;
		ss << i;
		string is = ss.str();
		m[ {is[0] - '0', is[is.size() - 1] - '0'}]++;
	}

	li res = 0;
	for (li head = 1; head < 10; ++head) {
		for (li tail = 1; tail < 10; ++tail) {
			res += m[ {head, tail}] * m[ {tail, head}];
		}
	}
	cout << res << endl;


	return 0;
}

Measured memory_bytes: 384
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  constexpr int Mod = 1'000'000'007;
  int N;
  cin >> N;
  vector<long long> A(N);
  for (auto& e : A) cin >> e;
  int ans = 0;
  for (int i = 0; i < 60; ++i) {
    array<long long, 2> count = {};
    for (const auto& e : A) ++count[(e >> i) & 1];
    ans += count[0] * count[1] % Mod * ((1LL << i) % Mod) % Mod;
    ans %= Mod;
  }
  cout << ans << endl;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<pair<int, int>> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i).first >> x.at(i).second;
    x.at(i).second++;
  }
  
  sort(x.begin(), x.end());
  
  vector<int> fr(n, 1e9 + 5), ba(n, 1e9 + 5);
  fr.at(0) = x.at(0).second;
  ba.at(n - 1) = x.at(n - 1).second;
  for (int i = 1; i < n; i++) fr.at(i) = min(fr.at(i - 1), x.at(i).second);
  for (int i = n - 2; i >= 0; i--) ba.at(i) = min(ba.at(i + 1), x.at(i).second);
  
  int ans = max(0, fr.at(n - 2) - x.at(n - 2).first) + x.back().second - x.back().first;
  ans = max(ans, x.front().second - x.front().first + max(0, ba.at(1) - x.back().first));
  for (int i = n - 2; i >= 1; i--) {
    ans = max(ans, max(0, fr.at(i) - x.at(i).first) + max(0, ba.at(i + 1) - x.back().first));
    ans = max(ans, max(0, min(fr.at(i - 1), ba.at(i + 1)) - x.back().first) + x.at(i).second - x.at(i).first);
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 1792
import java.util.*
import java.math.*
fun main(args: Array<String>) {

    var (N, M) = readLine()!!.split(" ").map { it.toInt() }
//    var N = readLine()!!.toInt()
//    val D = readLine()!!.split(" ").map { it.toLong() }
//    val A = readLine()!!.split(" ").map { it.toInt() }.toIntArray()

    if (N-M !in -1..1) {
        println(0)
        return
    }
    val mod = 1000000007
    fun factorial(n:Int,m:Int) :Long {
        var res = 1L
        for (i in 1..n) {
            res *= i
            res %= mod
        }
        for (i in 1..m) {
            res *= i
            res %= mod
        }
        return res
    }
    var ans  = factorial(N,M)
    if (N == M) ans *= 2
    println(ans%mod)
}


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

//----------------------------------------------------------------------------------
#define pb insert//                                                                 |
#define eb emplace_back//                                                           |
#define ff first//                                                                  |
#define ss second//                                                                 |
typedef long long int ll;//                                                         |
typedef long double ld;//                                                           |
#define all(a) a.begin(), a.end()//                                                 |
#define show(x) cerr << #x << " is " << x << "\n"//                                 |
#define show2(x, y) cerr << #x << " " << #y << " " << x << " " << y << "\n"//       |
typedef vector<ll> vl;//                                                            |
typedef vector<vl> vvl;//                                                           |
typedef pair<ll, ll> pp;//                                                          |
typedef vector<pp> vp;//                                                            |
typedef map<pp, ll> ipi;//                                                          |
typedef map<pp, char> ipc;//                                                        |
typedef map<ll, ll> ii;//                                                           |
typedef set<ll> sl;//                                                               |
typedef multiset<ll> msl;//                                                         |
typedef map<char, ll> ci;//                                                         |
typedef set<pair<ll, ll>> sp;//                                                     |
const ll mod = 1e9 + 7;//                                                           |
const ll N = 2e4 + 1;//                                                             |
//----------------------------------------------------------------------------------

ll fast_expo(ll x, ll y){
    
    ll res=1;
    while(y>0){
        if(y&1){
            res*=x;
        }
        x*=x;
        y>>=1;
    }
    return res;
}


//main func
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    
    ll t;cin>>t;
    string s="abcdefghijklmnopqrstuvwxyz";
    
    string ans="";
    while(t>0){
        t--;
        ans+=s[t%26];
        t/=26;
    }
    
    reverse(all(ans));
    cout<<ans<<"\n";
    
    
	return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#include <tr1/unordered_map>
#define ll long long
#define il inline
const ll inf = 1e9;

namespace io {

#define in(a) a = read()
#define out(a) write(a)
#define outn(a) out(a), putchar('\n')

#define I_int ll
inline I_int read() {
    I_int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}
char F[200];
inline void write(I_int x) {
    if (x == 0) return (void) (putchar('0'));
    I_int tmp = x > 0 ? x : -x;
    if (x < 0) putchar('-');
    int cnt = 0;
    while (tmp > 0) {
        F[cnt++] = tmp % 10 + '0';
        tmp /= 10;
    }
    while (cnt > 0) putchar(F[--cnt]);
}
#undef I_int

}
using namespace io;

using namespace std;

#define N 2000100

int v[N];
int n,m,len;
char s[N];
char c[N][2];

bool check(int x) {
    for(int i = 1; i <= m; ++i) {
        if(c[i][0]==s[x]) {if(c[i][1]=='L')--x;else++x;}
        if(x<1)return 1;
    }
    return 0;
}

bool check1(int x) {
    for(int i = 1; i <= m; ++i) {
        if(c[i][0]==s[x]) {if(c[i][1]=='L')--x;else++x;}
        if(x>n)return 1;
    }
    return 0;
}

int main() {
    in(n),in(m);scanf("%s",s+1);
    for(int i = 1; i <= n; ++i)v[i]=1;
    for(int i = 1; i <= m; ++i) {
        char s1[5],s2[5];
        scanf("%s%s",s1,s2);
        c[i][0]=s1[0],c[i][1]=s2[0];
    }
    int l = 1, r = n, ans = 0;
    while(l <= r) {
        int mid = (l + r) >> 1;
        if(check(mid)) l = mid + 1, ans = mid;
        else r = mid - 1;
    }
    for(int i = 1; i <= ans; ++i) v[i]=0;
    l=1,r=n,ans=n+1;
    while(l<=r) {
        int mid = (l + r) >> 1;
        if(check1(mid)) r = mid - 1, ans = mid;
        else l = mid + 1;
    }
    for(int i = n; i>=ans; --i) v[i]=0;
    ans=0;for(int i = 1; i <= n; ++i) ans += v[i];
    outn(ans);
}

/*
  AABCBDBA
0:11111111
1:10111120
2:01020202
3:01020200
*/

Measured memory_bytes: 6784
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main {
	static PrintWriter pw;
	static int n;

	static long gcd(long n, long m) {
		return (m == 0 ? n : gcd(m, n % m));
	}
	static int[] gcd2(int p, int q) {
	      if (q == 0)
	         return new int[] { p, 1, 0 };

	      int[] vals = gcd2(q, p % q);
	      int d = vals[0];
	      int a = vals[2];
	      int b = vals[1] - (p / q) * vals[2];
	      return new int[] { d, a, b };
	   }

	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc = new Scanner(System.in);
		pw = new PrintWriter(System.out);
		int a = sc.nextInt();
		int b = sc.nextInt();
		pw.println(b%a==0?a+b:b-a);
		pw.flush();
				}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


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

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

    ll N, L, T;
    cin >> N >> L >> T;
    vector<ll> X(N), W(N), A(N);
    for (int i = 0; i < N; ++i) {
        cin >> X.at(i) >> W.at(i);
        if (W.at(i) == 1) {
            A.at(i) = (X.at(i) + T) % L;
        } else {
            A.at(i) = ((X.at(i) - T) % L + L) % L;
        }
    }
    ll A0 = A.at(0);
    sort(A.begin(), A.end());
    ll pnt = 0;
    for (int i = 0; i < N; ++i) {
        if (W.at(0) == W.at(i)) continue;
        ll d = (W.at(0) == 1) ? X.at(i) - X.at(0) : L - (X.at(i) - X.at(0));
        if (2 * T < d) continue;
        if (W.at(0) == 1) {
            pnt += (2 * T - d) / L + 1;
            pnt %= N;
        } else {
            pnt -= (2 * T - d) / L + 1;
            pnt = (pnt % N + N) % N;
        }
    }
    ll X0;
    for (int i = 0; i < N; ++i) {
        if (A.at(i) == A0) {
            X0 = i;
            if (W.at(0) != 1) break;
        }
    }
    ll ofs = (X0 - pnt + N) % N;
    for (int i = 0; i < N; ++i) {
        cout << A.at(((ofs + i)) % N) << endl;
    }

    return 0;
}

Measured memory_bytes: 3584