akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
ll gg=0;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y = LLONG_MAX ){ll res=1;while(y>0){if(y&1)res=(res*x);y=y>>1;x=(x*x);}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
void solve()
{
    ll n;cin>>n;
    ll aa=0;
    while(n)
    {
        aa=n%10;
        break;
        n/=10;
    }
    if(aa==2||aa==4||aa==5||aa==7||aa==9)
        cout<<"hon";
    else if(aa==6||aa==0||aa==1||aa==8)
        cout<<"pon";
    else if(aa==3)
        cout<<"bon";
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
        solve();
    return 0;
}

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define inn(x, y) int x,y;cin>>x>>y
#define innn(x, y, z) int x,y,z;cin>>x>>y>>z
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define outt(x,y) cout<<(x)<<" "<<(y)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;
#define errrr(x,y,z) cerr<<(x)<<" "<<(y)<<" "<<(z)<<endl;

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)
#define reppp(j, i, n) for (int j=i+1; j<n; j++)

#define lim5 200010
#define lim9 1000000010

#define deg(rad) (((rad)/2/M_PI)*360)
#define mid(min, max) ((min + max) / 2)

int main() {
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll cnt = 0;
	if (k < a) {
		cnt += k;
		k -= k;
	} else {
		cnt += a;
		k -= a;
	}
	if (!k) {
		out(cnt);
		return 0;
	}

	if (k < b) {
		k -= k;
	} else {
		k -= b;
	}
	if (!k) {
		out(cnt);
		return 0;
	}
	errr(cnt, k);

	if (k < c) {
		cnt -= k;
	} else {
		cnt -= c;
	}
	out(cnt);
	return 0;
}


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

int main() {
	string s, t;
	cin >> s >> t;
	int n = s.size();
	int m = t.size();
	int ans = -1;
	for (int i = 0; i <= n - m; i++) {
		int ct = 0;
		for (int j = i; j < i + m; j++) {
			if (s[j] != t[j - i]) {
				ct++;
			}
		}
		if (ans == -1 || ans > ct) {
			ans = ct;
		}
	}
	cout << ans;
	return 0;
}



















Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;



public class Main {
	public static void main(String[] args) throws IOException{
	    BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
	    int [] mountainsheight= new int[10];
        for (int i = 0; i < 10; i++) {
        	mountainsheight[i]=Integer.parseInt(br.readLine());
        }
        
        for (int i = 0; i < mountainsheight.length-1; i++) {
        	for (int j = i + 1; j < mountainsheight.length; j++) {
        		if (mountainsheight[i] < mountainsheight[j]) {
        			int temporary = mountainsheight[i];
        			mountainsheight[i] = mountainsheight[j];
        			mountainsheight[j] = temporary;
        		}
        	}
        }
        
        for (int i = 0; i < 3; i++) {
        	System.out.println(mountainsheight[i]);
        }
	}
}

Measured memory_bytes: 24444
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define deb(x) cerr << #x <<": " << x << '\n';
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;

int main(){
    ios;
    int x, y; cin >> x >> y;
    int sum = 0;
    if(x == 1 && y == 1) sum += 400000;
    
    if(x == 3) sum += 100000;
    if(x == 2) sum += 200000;
    if(x == 1) sum += 300000;
    
    if(y == 3) sum += 100000;
    if(y == 2) sum += 200000;
    if(y == 1) sum += 300000;
    cout << sum;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b;cin>>a>>b;
  if(a<b){
    cout<<0<<endl;
  }
  else {
    cout<<10<<endl;
  }
  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
using std::swap;

// priceをキーに降順でソート
//sort(fruits.begin(), fruits.end(),
//     [](const fruit& x, const fruit& y) { return x.price > y.price;});

int main() {
    long long int S;
    int r;
    std::cin >> r;
    S= 3*r*r;
    std::cout << S << std::endl;
    return 0;
}


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

int main() {
    
    int l , r ,d;
    int i = 0;
    int count = 0;
    cin >> l >> r >> d;
    for(i = l;i<=r;i++){
        if(i % d == 0){
            count++;
        }
    }

    cout << count << endl;

}

Measured memory_bytes: 3592
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    else:
        for i in range(H):
            str = ''
            for j in range(W):
                if (i + j) % 2 == 0:
                    str += '#'
                else:
                    str += '.'
            print(str)             
    print('')


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
int main(void){
   
   int n, k;
   cin >> n >> k;
   
   int a[n];
   for(int i = 0;i < n;i++){
       cin >> a[i];

       if(i >= k){
           if(a[i] > a[i - k]){
               cout << "Yes\n";
           }
           else{
               cout << "No\n";
           }
       }
   }
   
   return 0;
}


Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define ld long double
#define For(i,j,n) for(lli i=(lli)j; i<(lli)n; ++i)
#define DFor(i, n, j) for(lli i=(lli)n; i>=(lli)j; --i)
#define mod 1000000007
#define pb emplace_back
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)

int main(){
    fastio;
    
	lli n, k; cin >> n >> k;
	lli h[n+1];
	For(i, 1, n+1) cin >> h[i];
	
	lli dp[n+1]; dp[1] = 0;
	For(i, 2, n+1){
		lli lim = min(i-1,k);
		dp[i] = INT_MAX;
		For(j, 1, lim+1){
			dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]));
		}
	}
	
	/*For(i, 1, n+1) cout << dp[i] << " ";
	cout << endl;*/
	cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

lack = 0
count = 0
C = [0] * N
for i in range(N):
    if A[i] < B[i]:
        count = count + 1
        lack = lack + B[i] - A[i]
    else:
        C[i] = A[i] - B[i]

if lack == 0:
    print("0")
elif count == N:
    print("-1")
else:
    C = sorted(C, reverse = True)
    for i in range(N):
        if C[i] == 0:
            break
        if lack <= C[i]:
            count = count + 1
            lack = 0
            break
        else:
            lack = lack - C[i]
            count = count + 1
    if lack == 0:
        print(count)
    else:
        print("-1")



Measured memory_bytes: 19068
N=int(input())
l=[]
for i in range(2,N+1):
    for j in l:
        if i%j==0:
            break
    else:
        l.append(i)
a=1
for i in l:
    t=0
    s=1
    while i**s<=N:
        t+=N//i**s
        s+=1
    a=a*(t+1)%(10**9+7)
print(a)

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

int main() {
  int A,B,C,K,ans,sum; cin >> A >> B >> C >> K;
  ans = max(max(A,B),C);
  sum= A + B + C;
  for(int i=0; i<K; i++) ans *=2;
  
  cout << ans + sum - max(max(A,B),C)  << endl;
}

Measured memory_bytes: 3588
import java.util.*;

public class Main{
    Main(){
	Scanner sc = new Scanner(System.in);

	while(sc.hasNext()){
	    int n = sc.nextInt();
	    if(n == 0) break;
	    HashMap<String, String> map= new HashMap<String, String>();
	    for(int i = 0; i < n; i++)
		map.put(sc.next(), sc.next());

	    n = sc.nextInt();
	    for(int i = 0; i < n; i++){
		String str = sc.next();
		if(map.containsKey(str)) str = map.get(str);
		System.out.print(str);
	    }
	    System.out.println();
	}
    }

    public static void main(String[] args){
	new Main();
    }
}

Measured memory_bytes: 12000
import sys
from bisect import bisect_left
input = sys.stdin.readline

n = int(input())
s = list(map(int,input().split()))
q = int(input())
t = list(map(int,input().split()))

cnt = 0
for x in t:
    c = bisect_left(s,x)
    if s[c] == x:
        cnt += 1
#    big = n-1
#    small = 0
#    if x < s[0] or x > s[n-1]:
#        continue
#    while big > small + 1:
#        m = (small + big) // 2
#        if s[m] < x:
#            small = m
#        else:
#            big = m
#    if s[small] == x or s[big] == x:
#        cnt += 1
print (cnt)




Measured memory_bytes: 16196
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

void test(){
    for(ll N = 1; N <= 100; N++){
        ll cnt = 0;
        for(ll A = 1; A <= N; A++){
            for(ll B = 1; B <= N; B++){
                string sA = to_string(A);
                string sB = to_string(B);
                
                if(sA.back() == sB.front() && sA.front() == sB.back()){
                    cnt++;
                }
            }
        }
        cout << cnt << " ";
    }
}

map<pll,ll> mp;
template<class Type>
Type solve(Type res = Type()){
    // test();
    ll N; cin >> N;
    
    if(N < 10) return N;
    
    for(ll n = 1; n <= N; n++){
        ll r = n%10;
        
        ll l = n;
        while(l >= 10) l /= 10;
        
        mp[pll(l,r)]++;
    }
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            res += mp[pll(i,j)]*mp[pll(j,i)];
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 256
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(len(a)):
  if a[i] > x:
    ans += a[i] - x
    a[i] = x
for i in range(1, len(a)):
  if a[i] + a[i - 1] > x:
    ans += a[i] + a[i - 1] - x
    a[i] = x - a[i - 1]
print(ans)


Measured memory_bytes: 14540
#ifdef FAIRLY_LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <iostream>
#include <vector>
using namespace std;

int main() {
#ifdef FAIRLY_LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n, r;

    cin >> n >> r;

    if (n >= 10) {
        cout << r << '\n';
    } else {
        cout << r + 100 * (10 - n) << '\n';
    }
    return 0;
}

Measured memory_bytes: 384
import java.util.*;

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

		for(int i = 10; i > 0; i--){
            if(i * 1000 - n < 1000) {
                System.out.println(i * 1000 - n);
				return;
            }
        }
	}
}

Measured memory_bytes: 27016
from heapq import heappush, heappop
def dijkstra(graph:list, node:int, start:int) -> list:
    # graph[node] = [(cost, to)]
    inf = float('inf')
    dist = [inf]*node

    dist[start] = 0
    heap = [(0,start)]
    while heap:
        cost,thisNode = heappop(heap)
        for NextCost,NextNode in graph[thisNode]:
            dist_cand = dist[thisNode]+NextCost
            if dist_cand < dist[NextNode]:
                dist[NextNode] = dist_cand
                heappush(heap,(dist[NextNode],NextNode))
    return dist

N = int(input())

e = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    e[a].append((1,b))
    e[b].append((1,a))

c = list(map(int,input().split()))
c.sort()
print(sum(c)-c[-1])
d = dijkstra(e,N,0)
d = [(d[i],i) for i in range(N)]
d.sort()
d = [(d[i][0],d[i][1],c[-i-1]) for i in range(N)]
d.sort(key=lambda x:x[1])
ans = [str(d[i][2]) for i in range(N)]
print(' '.join(ans))

Measured memory_bytes: 63576
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():
    N = in_n()
    A = list(in_all())

    sort_ind = sorted(range(N), key=lambda i: A[i])

    cnt = 0
    for i in range(N):
        cnt += abs(i - sort_ind[i]) & 1

    print(cnt // 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 85208
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
    ll n,q;cin >> n >>q;
    UnionFind uf(n);
    while(q--){
        ll t;cin >> t;
        ll u,v;cin >> u >> v;
        if(t){
            cout << uf.same(u,v) <<endl;
        }
        else{  
            if(!uf.same(u,v))uf.merge(u,v);
        }
    }
}

Measured memory_bytes: 3844
#include <stdio.h>
#include <iostream>
#include <string>
 
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main(void)
{
  string S;
  int i = 0;
  int len = 0;
  int cnt = 0;
 
  cin >> S;
  
  if(S[0] != S[1]){
    len = 1;
  }
  else
  {
    len = 2;
  }
  cnt++;
  i += len;
  while(i < S.size()){
    if(len==1){
      if(S[i] != S[i+1]){
        len = 1;
      }else{
        len = 2;
      }
    }else{
      len = 1;
    }
    i += len;
    cnt++;
  }
  
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 640
int main(){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(x-r >= 0 && x+r<=W && y+r<=H && y-r >= 0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 584
n = int(input())
# s = [input().split(), i for i in range(n)]
# s.sort()
s = [[] for _ in range(n)]
for i in range(n):
    a,b = input().split()
    s[i].append(a)
    s[i].append(int(b))
    s[i].append(i+1)
s.sort(reverse=True,key=lambda x:(x[1]))
s.sort(key=lambda x:(x[0]))
for i in range(n):
    print(s[i][2])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=2e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int n;
int d[MAXn];
vector<int> e[MAXn];
int dp[MAXn],ans[MAXn];
void dfs(int x,int p){
    int l=0,r=n;
    while (l != r-1) {
        int mid = (l+r)>>1;
        if (dp[mid] < d[x]) l = mid;
        else r = mid;
    }
    int tmp = dp[r];
    dp[r] = d[x];
    ans[x] = max(ans[p],r);
    for (auto i:e[x]) {
        if (i == p) continue;
        dfs(i,x);
    }
    dp[r] = tmp;
}
int main(){
    IOS();
    cin >> n;
    REP (i,n) cin >> d[i];
    REP (i,n-1) {
        int u,v;
        cin >> u >> v;
        u--, v--;
        e[u].eb(v);
        e[v].eb(u);
    }
    REP (i,MAXn) dp[i] = INF;
    dfs(0,0);
    REP (i,n) cout << ans[i] << endl;
}


Measured memory_bytes: 31196
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline ll getint() {
	ll A = 0;
	if (ci - cn + 24 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	ll a[100000];
	ll goukei = 0;
	rep(i, N) {
		a[i] = getint();;
		goukei ^= a[i];
	}

	int M = 60;
	int r = 0;
	for (int i = M - 1; i >= 0; i--) {
		if (!(goukei >> i & 1)) {
			for (int j = r; j < N; j++) {
				if (a[j] >> i & 1) {
					swap(a[r], a[j]);
					for (int k = max(j, r + 1); k < N; k++) {
						if (a[k] >> i & 1) {
							a[k] ^= a[r];
						}
					}
					if (!(a[0] >> i & 1)) {
						a[0] ^= a[r];
					}
					r++;
					break;
				}
			}
		}
	}

	printf("%lld", a[0] + (a[0] ^ goukei));

	Would you please return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point {
public:
    double x, y;

    Point(double x = 0.0, double y = 0.0): x(x), y(y) {};

    Point operator + (Point &p) {return Point(x + p.x, y + p.y);}
    Point operator - (Point &p) {return Point(x - p.x, y - p.y);}
    Point operator * (double k) {return Point(x * k, y * k);}
    Point operator / (double k) {return Point(x / k, y / k);}

    double norm(void) {return x * x + y * y;}
    double abs(void) {return sqrt(norm());}

    bool operator == (const Point &p) const {
        return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
    }

    bool operator < (const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }

    double dot(Point a) {
        return x * a.x + y * a.y;
    }

    double cross(Point a) {
        return x * a.y - y * a.x;
    }
};

typedef Point Vector;

struct Segment {
    Point p1, p2;
};


static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw(Point p0, Point p1, Point p2) {
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    if (a.cross(b) > EPS) return COUNTER_CLOCKWISE;
    if (a.cross(b) < -EPS) return CLOCKWISE;
    if (a.dot(b) < -EPS) return ONLINE_BACK;
    if (a.norm() < b.norm()) return ONLINE_FRONT;
    return ON_SEGMENT;
}

bool intersect(Point p1, Point p2, Point p3, Point p4) {
    return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
            ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}


int main(void) {
    int x1, x2, x3, x4, y1, y2, y3, y4, q;
    scanf("%d", &q);

    for (int i = 0; i < q; i++) {
        scanf("%d %d %d %d %d %d %d %d",
                &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
        int ret = intersect(Point(x1, y1), Point(x2, y2),
                            Point(x3, y3), Point(x4, y4));
        printf("%d\n", ret);
    }

    return 0;
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N, T, ans = 0;
    cin >> N >> T;
    vector<Pint> AB(N);
    vector<vector<int>> dp(N + 3, vector<int> (6003,0));
    for (int i = 0; i < N; i++) {
        cin >> AB.at(i).first >> AB.at(i).second;
    }
    sort(ALL(AB));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < T; j++){
            dp.at(i + 1).at(j + AB.at(i).first) = max(dp.at(i).at(j) + AB.at(i).second,dp.at(i).at(j + AB.at(i).first));
            ans = max(ans, dp.at(i + 1).at(j + AB.at(i).first));
        }
        dp.at(i + 2) = dp.at(i + 1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 70784
def main():
    N = int(input())
    
    if N % 10 == 0:
        N -= 1
    else:
        first = 0
        M = N
        while True:
            d = M % 10
            M //= 10
            if M == 0:
                first = d
                break

        if N != (first + 1) * (10 ** (len(str(N)) - 1)) - 1:
            N = (first) * (10 ** (len(str(N)) - 1)) - 1

    ans = 0
    N = str(N)
    for d in N:
        ans += int(d)

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9136
###############################################################################

from bisect import bisect_left as binl

def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return map(int, input_tuple)


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


###############################################################################


def main():
    H, W = intin()
    h, w = intin()

    print(H * W - h * W - H * w + h * w)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
import java.util.Scanner

object Main {

  def solve(sc: => Scanner): Unit = {
    val A = Array.fill[Int](9)(0)
    A(0) = sc.nextInt
    A(1) = sc.nextInt
    A(4) = sc.nextInt
    A(2) = A(4) * 3 - A(0) - A(1)
    A(8) = A(4) * 3 - A(0) - A(4)
    A(7) = A(4) * 3 - A(1) - A(4)
    A(5) = A(4) * 3 - A(2) - A(8)
    A(3) = A(4) * 3 - A(5) - A(4)
    A(6) = A(4) * 3 - A(0) - A(3)
    for (i <- 0 until 3) {
      println(A(i * 3) + " " + A(i * 3 + 1) + " " + A(i * 3 + 2))
    }
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 27440
N = int(input())
A = list(map(int ,input().split()))

even = 0
odd = 0
for i in range(N):
    if A[i] % 2 == 0:
        even += 1
    else:
        odd += 1

if odd == N:
    ans = 3**N - 1
else:
    ans = 3**N - 2**even

print(ans)

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

int findSumOfDigits(int n) {
  int ret = 0;
  while (n > 0) {
    ret += n % 10;
    n /= 10;
  }
  return ret;
}

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int ret = 0;
  for (int i = 1; i <= N; i++) {
    int sum = findSumOfDigits(i);
    if (A <= sum && sum <= B) {
      ret += i;
    }
  }
  cout << ret << endl;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;

}

signed main() {
	ll r, d, x;

	cin >> r >> d >> x;

	REP(i, 10) {
		x = r * x - d;
		cout << x << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,-1,0,1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
    if(a>b){
        a = b; return true;
    }
    else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
    if(a<b){
        a = b; return true;
    }
    else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
    cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const ll mod = 1e9 + 7;
//const int mod = 998244353;

map<string,int> mp;
vs v(202020);

char rev(char c){
    return (char)(((c - '0') ^ 1) + '0');
}

int main(){
    string s; cin >> s;
    int n = s.size();
    rep(i,26) v[0].push_back('0');
    mp[v[0]] = 0;
    int dp;
    rep(i,n){
        v[i+1] = v[i];
        char c = v[i+1][s[i]-'a'];
        v[i+1][s[i]-'a'] = rev(v[i+1][s[i]-'a']);
        auto v_ = v[i+1];
        dp = inf;
        rep(j,26){
            v_[j] = rev(v_[j]);
            if(mp.find(v_) != mp.end()){
                chmin(dp, mp[v_] + 1);
            }
            v_[j] = rev(v_[j]);
        }
        if(mp.find(v[i+1]) != mp.end()){
            chmin(dp, mp[v[i+1]] + 1);
            chmin(mp[v[i+1]], dp);
        }else{
            mp[v[i+1]] = dp;
        }
    }
    cout << dp << "\n";
}

Measured memory_bytes: 44188
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    auto N = readln.chomp.to!int;
    auto a = readln.split.to!(int[]);
    auto y = a.filter!"a%2==0&&a%4".walkLength;
    auto z = a.filter!"a%4==0".walkLength;
    auto x = N-y-z;

    writeln(() {
        if (x == z + 1) return y == 0;
        else if (x > z + 1) return false;
        else return true;
    }() ? "Yes" : "No");
}



Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int y, m, d;
vector<string> ans;

void HtoR()
{
    if (y > 31 || (y == 31 && m >= 5)) {
        ans.push_back("? " + to_string(y - 30) + " " + to_string(m) + " " + to_string(d));
        //cout<<"? "<<y - 30<<" "<<m<<" "<<d<<endl;
    } else {
        ans.push_back("HEISEI " + to_string(y) + " " + to_string(m) + " " + to_string(d));
        //cout<<"HEISEI "<<y<<" "<<m<<" "<<d<<endl;
    }
}

int main()
{
    string g;
    while (cin>>g, g != "#") {
        cin>>y>>m>>d;
        if (g == "HEISEI") HtoR();
        else exit(1);
    }
    REPALL(i,ans) cout<<ans[i]<<endl;
}


Measured memory_bytes: 3284
from collections import deque

n, m = map(int, input().split())
graph=[[] for _ in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

d = [0] * (n + 1)
q=deque()
q.append(1)

while q:
    v = q.popleft()
    for j in graph[v]:
        if not d[j]:
            q.append(j)
            d[j] = v
print('Yes')
for x in range(2,n+1):
    print(d[x])

            

Measured memory_bytes: 33944
/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxn 200005
#define maxm 1000006
#define maxc 1000000007
#define pii pair <int,int>
#define Task ""
#define int long long
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
const int mod = 200003;
int n,id[maxn],cv[maxn],cur = 1;
long long ans;
vector <int> a;
using cd = complex<double>;
const double PI = acos(-1);
void fft(vector<cd> & a, bool invert) {
    int n = a.size();
    if (n == 1)
        return;

    vector<cd> a0(n / 2), a1(n / 2);
    for (int i = 0; 2 * i < n; i++) {
        a0[i] = a[2*i];
        a1[i] = a[2*i+1];
    }
    fft(a0, invert);
    fft(a1, invert);

    double ang = 2 * PI / n * (invert ? -1 : 1);
    cd w(1), wn(cos(ang), sin(ang));
    for (int i = 0; 2 * i < n; i++) {
        a[i] = a0[i] + w * a1[i];
        a[i + n/2] = a0[i] - w * a1[i];
        if (invert) {
            a[i] /= 2;
            a[i + n/2] /= 2;
        }
        w *= wn;
    }
}
vector<int> multiply(vector<int> const& a, vector<int> const& b) {
    vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
    int n = 1;
    while (n < a.size() + b.size())
        n <<= 1;
    fa.resize(n);
    fb.resize(n);

    fft(fa, false);
    fft(fb, false);
    for (int i = 0; i < n; i++)
        fa[i] *= fb[i];
    fft(fa, true);

    vector<int> result(n);
    for (int i = 0; i < n; i++)
        result[i] = round(fa[i].real());
    return result;
}
int Pow(int a,int b,int mod)
{
    int res = 1;
    for (;b;b >>= 1,a = 1ll*a*a%mod)
    {
        if (b & 1) res = 1ll*res*a%mod;
    }
    return res;
}
main()
{
    srand(time(NULL));
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie();
    if(fopen(".inp", "r")) freopen(".inp", "r", stdin);
    //freopen(Task".inp", "r",stdin);
    //freopen(Task".out", "w",stdout);
//    cout << Pow(2,100001,mod);
//    return 0;
    FOR(i,0,mod - 1)
    {
        id[i] = cur;
        cv[cur] = i;
        cur = 2ll*cur % mod;
    }
    a.resize(mod);
    cin >> n;
    FOR(i,1,n)
    {
        int x;
        cin >> x;
        if (!x) continue;
        ++a[cv[x]];
        ans -= 1ll * x * x % mod;
        //cout << cv[x] << '\n';
    }
    a = multiply(a,a);
    FOR(i,0,a.size() - 1)
    {
        if (a[i])
        {
            //cout << a[i] << ' ' << i << '\n';
            int ww = i % (mod - 1);
            ans += 1ll*a[i]*id[ww];
        }
    }
    ans >>= 1;
    cout << ans;
    return 0;
}


Measured memory_bytes: 41240
def examA():
    x, a,  b = LI()
    if abs(x-a)-abs(x-b)<0:
        ans = "A"
    else:
        ans = "B"
    print(ans)


import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examA()


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int a = read();
  string s = readString();
  if (a >= 3200)
    std::cout << s << std::endl;
  else
    std::cout << "red" << std::endl;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int num[15]={0,2,5,5,4,5,6,3,7,6},a[10],dp[114514];
int main(){
  ll n,m;
  cin>>n>>m;
  int mi=114514;
  for(int i=0;i<m;i++){
    cin>>a[i];
    mi=min(mi,num[a[i]]);
    dp[num[a[i]]]=1;
  }
  sort(a,a+m);
  for(int i=1;i<=n;i++){
    for(int j=0;j<m;j++){
      if(dp[i-num[a[j]]])dp[i]=max(dp[i],dp[i-num[a[j]]]+1);
    }
  }
  string ans="";
  for(int i=m-1;i>=0;i--){
    while(dp[n-num[a[i]]]==dp[n]-1&&(n-num[a[i]]>=mi||n-num[a[i]]==0)){
      ans+=to_string(a[i]);
      n-=num[a[i]];
      if(n==0){
          cout<<ans<<endl;
          return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
   
int F[102][102];
int xg,yg,w,h;
   
   
void DFS(int Y,int X,int c){
  //if(Y < 1 || X < 1)
    //return;
  if(F[Y][X] != c){
    return;
  }
   
  F[Y][X] = -1;
  DFS(Y+1,X  ,c);
  DFS(Y-1  ,X,c);
  DFS(Y,X+1  ,c);
  DFS(Y  ,X-1,c);
}
   
   
int main(){
  int xs,ys,n;
  while(1){
    cin >> w >> h;
    if(w == 0 && h == 0)
      break;
for(int i=0; i<102; i++){
      for(int j=0; j<102; j++){
        F[i][j] = 10;
      }
    }
       F[0][104] = 0;
    cin >> xs >> ys >> xg >> yg >> n;
   
   
    for(int i=0;i<n;i++){
      int c,d,x,y;
      cin >> c >> d >> x >> y;
      if(c == 0)
         c = 1919810;
      if(d == 0){
        for(int j=0;j<4;j++){
          F[x+j][y] = c;
          F[x+j][y+1] = c;
        }
      } else {
        for(int j=0;j<4;j++){
          F[x][y+j] = c;
          F[x+1][y+j] = c;
        }
      }
    }
  DFS(xs,ys,F[xs][ys]);
   
  if(F[xg][yg] == -1){
    cout << "OK" << endl;
  } else {
    cout << "NG" <<endl;
  }
  }
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n,m;
    cin>>n>>m;
    vector<pair<ll,ll>> v;
    rep(i,n){
        ll a;
        cin>>a;
        v.push_back({a,1});
    }
    rep(i,m){
        ll b,c;
        cin>>b>>c;
        v.push_back({c,b});
    }

    sort(all(v));
    reverse(all(v));
    ll ans=0,cnt=0;
    rep(i,v.size()){
        if(cnt+v[i].second>=n){
            ans+=(n-cnt)*v[i].first;
            cout<<ans<<endl;
            return 0;
        }

        ans+=v[i].first*v[i].second;
        cnt+=v[i].second;
    }
}


Measured memory_bytes: 7464
// khodaya khodet komak kon
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpl;

const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 2e5 + 10;
const ll INF = 1e18;
const ll LOG = 20;
ll n, Q;
str s;
vector<pair<char, ll>> Moves;

bool isval(ll x){
	ll pnt = x;
	for (auto u:Moves){
		if (s[pnt] == u.F){
			if (u.S == 'L') pnt--;
			else pnt ++;
		}
		if (pnt == s.size() - 1) return 0;
		if (pnt == 0) return 1;
	}
	return 0;
}


bool isval2(ll x){
	ll pnt = x;
	for (auto u:Moves){
		if (s[pnt] == u.F){
			if (u.S == 'L') pnt--;
			else pnt ++;
		}
		if (pnt == 0) return 0;
		if (pnt == s.size() - 1) return 1;
	}
	return 0;
}

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

	cin >> s;
	s = '.' + s;
	s = s + '.';
	for (int i = 1; i <= Q; i++){
		char c, v;
		cin >> c >> v;
		Moves.pb({c, v});
	}
	
	ll l, r;
	l = 0, r = s.size() - 1;;
	while (r - l > 1){
		ll mid = (r + l) / 2;
		if (isval(mid)) l = mid;
		else r = mid;
	}
	//cout << l << ' ' << r << '\n';
	ll ans = 0;
	ans += l;
	l = 0, r = s.size() - 1;
	while (r - l > 1){
		ll mid = (r + l) / 2;
		if (isval2(mid)) r = mid;
		else l = mid;
	}
	//cout << l << ' ' << r << '\n'; 
	ans += s.size() - 1 - r;
	cout << n - ans;
	
	
	return 0;
}






/*
     ,---,           ___                 ,--,
    '  .' \        ,--.'|_             ,--.'|                             ,--,
   /  ;    '.      |  | :,'            |  | :                           ,--.'|    ,---.        ,---,
  :  :       \     :  : ' :            :  : '                 .--.--.   |  |,    '   ,'\   ,-+-. /  |
  :  |   /\   \  .;__,'  /    ,--.--.  |  ' |     ,--.--.    /  /    '  `--'_   /   /   | ,--.'|'   |
  |  :  ' ;.   : |  |   |    /       \ '  | |    /       \  |  :  /`./  ,' ,'| .   ; ,. :|   |  ,"' |
  |  |  ;/  \   \:__,'| :   .--.  .-. ||  | :   .--.  .-. | |  :  ;_    '  | | '   | |: :|   | /  | |
  '  :  | \  \ ,'  '  : |__  \__\/: . .'  : |__  \__\/: . .  \  \    `. |  | : '   | .; :|   | |  | |
  |  |  '  '--'    |  | '.'| ," .--.; ||  | '.'| ," .--.; |   `----.   \'  : |_|   :    ||   | |  |/
  |  :  :          ;  :    ;/  /  ,.  |;  :    ;/  /  ,.  |  /  /`--'  /|  | '.'\   \  / |   | |--'
  |  | ,'          |  ,   /;  :   .'   \  ,   /;  :   .'   \'--'.     / ;  :    ;`----'  |   |/
  `--''             ---`-' |  ,     .-./---`-' |  ,     .-./  `--'---'  |  ,   /         '---'
                            `--`---'            `--`---'                 ---`-'
*/




Measured memory_bytes: 6916
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
	long long n,
		m = 0, a = 0, r = 0, c = 0, h = 0;
	string s;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> s;
		if      (s[0] == 'M') ++m;
		else if (s[0] == 'A') ++a;
		else if (s[0] == 'R') ++r;
		else if (s[0] == 'C') ++c;
		else if (s[0] == 'H') ++h;
	}
	vector<long long> v = { m,a,r,c,h };
	long long ans = 0;
	for (int bit = 0; bit < (1 << 5); ++bit) {
		int cnt = 0;
		for (int i = 0; i < 5; ++i) {
			if (bit & (1 << i)) ++cnt;
		}
		if (cnt == 3) {
			long long sum = 1;
			for (int i = 0; i < 5; ++i) {
				if (bit & (1 << i)) sum *= v[i];
			}
			ans += sum;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

int main() {

    int A,B;
    cin >> A >> B;
    if(B % A == 0){
        cout << A + B << endl;
        return 0;
    }
    cout << B - A << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// #include <boost/multi_array.hpp>
// #include <boost/optional.hpp>
// #include <boost/range/irange.hpp>
// #include <boost/range/algorithm.hpp>
// #include <boost/range/adaptors.hpp>

// namespace adaptor = boost::adaptors;

using ll = long long;
using i64 = int64_t;

void Main()
{
   int N, K;
   std::cin >> N;
   if (N / 100 >= 1 && N / 100 <= 12)
   {
      if (N % 100 >= 1 && N % 100 <= 12)
      {
         std::cout << "AMBIGUOUS" << std::endl;
         return;
      }
      std::cout << "MMYY" << std::endl;
      return;
   }
   else if (N % 100 >= 1 && N % 100 <= 12)
   {
      std::cout << "YYMM" << std::endl;
      return;
   }
   std::cout << "NA" << std::endl;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

ll n, a, b;
ll x[100000], ans = 0;

int main() {
	cin >> n >> a >> b;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}

	for (int i = 1; i < n; i++) {
		ans += min(a*(x[i] - x[i - 1]), b);
	}

	cout << ans << endl;
}

Measured memory_bytes: 1024
class Integer
    def factor
        (1..self**0.5).inject([]) {|a, i| a << i if self % i == 0; a}
    end
end

N = gets.to_i

p N.factor.inject(N) {|min, i|
    digits = [i, N/i].max.to_s.size
    min =  digits < min ? digits: min
}

Measured memory_bytes: 1916
#include <stdio.h>
int main (){
char s[100];
  scanf ("%s",s);
  int k=0;
  for (int i=0;s[i]!=0;i++){
  for (int j=i+1;s[j]!=0;j++){
    if (s[i]==s[j]){
  k++;
  }
  }
  }
  if (k>0) printf("no");
    else printf ("yes");;
return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

template<typename T> map<typename T::value_type, int> count(const T& t) {
  map<typename T::value_type, int> res;
  for (const auto& i : t) ++res[i];
  return res;
}

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}

template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  cin >> s;
  vector<int> cnt(26, numeric_limits<int>::max());
  for (auto& i : s) {
    auto c = count(i);
    for (int i = 0; i < 26; ++i) chmin(cnt[i], c[i + 'a']);
  }
  for (int i = 0; i < 26; ++i) cout << string(cnt[i], i + 'a');
  cout << endl;
}



Measured memory_bytes: 256