akhauriyash/Code-Regression huggingface dataset:
# D - Disjoint Set of Common Divisors
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        if 2 not in a:
            a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            if f not in a:
                a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


inputNum = list(map(int, input().split()))

resultA = prime_factorize(inputNum[0])
resultB = prime_factorize(inputNum[1])

print(len(set(resultA) & set(resultB)) + 1)


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

int n;
string s;
string alpha[9] = {
	".,!? ",
	"abc",
	"def",
	"ghi",
	"jkl",
	"mno",
	"pqrs",
	"tuv",
	"wxyz",
};

int main(void){
	cin>>n;
	while(n--){
		char before = '0';
		int count = -1;
		cin>>s;
		for(int i=0;i<s.length();i++){
			if(s[i] == '0' && before != '0'){
				int idx = before - '1';
				cout<<alpha[idx][count%alpha[idx].length()];
				count = -1;
			}
			else if(s[i] != '0'){
				count++;
			}

			before = s[i];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 0
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    string s;
    cin>>s;
    string Y;
    for(int i=0;i<4;i++){Y.push_back(s[i]);}
    string M;
    for(int t=5;t<7;t++){M.push_back(s[t]);}
    string D;
    for(int h=8;h<10;h++){D.push_back(s[h]);}
    vector<ll> A={atoi(Y.c_str()),atoi(M.c_str()),atoi(D.c_str())};
    vector<ll> ans={2019,4,30};
    if(A<=ans){cout<<"Heisei"<<endl;}
    else{cout<<"TBD"<<endl;}
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = \t" << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<ll> A;
void input(){
    fast_io();
    cin >> N;
    A = fetch_vec<ll>(N);
}

int solve(){
    ll X = 0LL;
    ll S = A[0]+A[1];
    for (int i = 2; i < N; i++) X ^= A[i];
    ll D = (S-X)/2;
    if((S-X)%2){
        cout << -1 << endl;
        return 0;
    }
    ll a = D;
    if((X^A[0]^A[1])==0LL) {
        cout << 0 << endl;
        return 0;
    }

    if(a>=A[0] || a<0LL || D&X) {
        cout << -1 << endl;
        return 0;
    }
    int bit = 62;
    while(bit--){
        if((X>>bit)&1LL){
            if(A[0]>(a^(1LL<<bit)) ){
                a ^= (1LL<<bit);
            }
        }
    }
    ll x = A[0]-a;
    if(x>=A[0] || x<0) cout << -1 << endl;
    else cout << x << endl;
    return 0;
}

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

Measured memory_bytes: 3664
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int a,b;
    int ans = 0;
    cin >> a >> b;
    int diff = b-a;
    int sum = 0;
    for (int i = 1; i < diff; i++){
        sum += i;
    }
    ans = sum - a;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

unordered_map<int, int> x;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int table;
    cin >> table;
    
    int a;
    cin >> a;
    while (!cin.fail())
    {
        ++x[a];
        cin >> a;
    }
    
    for (int i = 1; i <= table; ++i)
        cout << x[i] << '\n';
}

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

int main() {
  int n,ans=0;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  for(int i=0;i<n;i++) cin >> a[i];
  for(int i=n-1;i>=0;i--) {
    int e=0;
    for(int j=(i+1)*2-1;j<n;j+=i+1) e=(e+b[j])%2;
    if(a[i]!=e) b[i]++;
  }
  for(int i=0;i<n;i++) if(b[i]==1) ans++;
  cout << ans << endl;
  for(int i=0;i<n;i++) if(b[i]==1) cout << i+1 << " ";
}

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

int main(){
    int N,K;
    cin >> N >> K;

    priority_queue<int> pque;

    for(int i=0;i<N;i++){
        int l;
        cin >>l;

        pque.push(l);
    }

    int sum = 0;
    for(int i=0;i<K;i++){
        sum += pque.top();
        pque.pop();
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
n, m = map(int,input().split())
if n == 1 and m == 0:
    print(0)
    exit()
cond = []
ans = [False] * n
for _ in range(m):
    cond.append(list(map(int,input().split())))
    if cond[-1][0] == 1 and cond[-1][1] == 0 and n != 1:
        print(-1)
        exit()

    elif ans[cond[-1][0]-1] is False:
        ans[cond[-1][0]-1] = cond[-1][1]
    elif ans[cond[-1][0]-1] == cond[-1][1]:
        continue
    else:
        print(-1)
        exit()

for i in range(len(ans)):
    if ans[i] is False:
        if i == 0:
            ans[i] = 1
        else:
            ans[i] = 0
print(*ans,sep="")

Measured memory_bytes: 3064
n=int(input())
A=list(map(int, input().split()))

num = [0] * (10**6+10)
A.sort()
for a in A:
    if num[a]==1:
        num[a] = -1
    elif num[a] ==0:
        num[a]+=1
        for i in range(2,(A[n-1]//a)+1):
            num[i*a]=-1

print(num.count(1))

Measured memory_bytes: 32340
#include <bits/stdc++.h>
#define mp make_pair
#define ft first
#define sd second
#define ue printf("what?\n");
#define pb push_back
#define oo 0x3F3F3F3F	
#define OO 3000000000000000000LL
#define EPS 0
#define maxn 200000
#define pi acos(-1)
#define mod 1000000007
#define mdc __gcd
#define N 600005
#define M 20
using namespace std;
typedef long long ll;
typedef vector<vector<ll> > mat;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	if(n % k == 0) printf("0\n");
	else printf("1\n");
}
	


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; ++i){
        cin >> p[i];
    }
    int r = 0;
    for(int i = 1; i <= n-2; ++i){
        if(p[i-1] < p[i] && p[i] < p[i+1]) r++;
        if(p[i-1] > p[i] && p[i] > p[i+1]) r++;
    }
    cout << r;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

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

	int k;
	cin >> k;
	int ans = 0, cur = 7 % k;
	for(int i = 1; i <= 5000000; i++) {
		if(cur == 0) {
			cout << i;
			return 0;
		}
		cur = (10 * cur + 7) % k;
	}
	cout << -1;

	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=1000010;
const ll mod=1e9+7;


int main(){
  int a,b,c,d,k;
  cin >> a >> b >> c >> d >> k;
  c -= a;
  d -= b;
  int ans = c*60+d-k;
  cout << ans << endl;
  return 0;
}

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

int main(){
string s;
cin >> s;
int n=s.size();
int ans=999;
int num=0;
int p=0;
for (int i=0;i<n-2;i++){
num = 100*(s.at(i)-'0')+10*(s.at(i+1)-'0')+(s.at(i+2)-'0');
if(num>753){
p=num-753;
}
else {
p=753-num;
}
ans=min(ans,p);
}
cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
char top[3]={0};
int main()
{
	int i,sum=700,len;
	scanf("%s",top);
	len=strlen(top);
	for(i=0;i<len;i++)
	{
		if(top[i]=='o')
		{
			sum+=100;
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using L = long long;

#define FOR(i, l, r) for(int i = l; i <= r; ++i)
#define REP(i, n) FOR(i, 0, n - 1)

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

	int n;
	cin >> n;
	array<int, 3> dp = {{0, 0, 0}}, prev_dp = dp;
	while(n --> 0) {
		array<int, 3> in;
		for(int &x : in)
			cin >> x;
		REP(i, 3)
			REP(j, 3)
				if(i != j)
					dp[i] = max(dp[i], prev_dp[j] + in[i]);
		prev_dp = dp;
	}
	cout << max(max(dp[0], dp[1]), dp[2]) << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,q;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    cin>>q;
    vector<int> m(q);
    for(int i=0;i<q;i++)cin>>m[i];
    set<int> st;
    for(int bit=0;bit<(1<<n);bit++){
        int sum=0;
        for(int i=0;i<n;i++){
            if(bit&(1<<i))sum+=a[i];
        }
        st.insert(sum);
    }
    for(int i=0;i<q;i++){
        if(st.count(m[i]))cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
  
#define IO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define f first
#define s second
#define pb push_back
#define all(a) a.begin(), a.end()
using namespace std;
  
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

template<typename T1, typename T2> inline void chkmax(T1 & x, T2 y) {if (x < y) x = y;}
template<typename T1, typename T2> inline void chkmin(T1 & x, T2 y) {if (x > y) x = y;}


int main() {
    IO;
    // freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    set<int> s;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        s.insert(x);
    }
    cout << s.size();
    return 0;
}

Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n,k; cin >> n >> k;
  if((n+1)/2 >= k) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  
}

Measured memory_bytes: 3580
/*Allah vorosha*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define n_p next_permutation
#define p_p prev_permutation
#define in insert
#define rev reverse
#define pf push_front
#define pob pop_back
#define uniq(v)			v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define all(x) (x).begin(),(x).end()
#define pof pop_front
#define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define scn scanf
#define prt printf
#define rep(i, a, n) for(int i = a; i < n; i++)
#define mod 1000000007
#define yes cout << "Yes\n"
#define no cout << "No\n";
#define take for(auto &it : a) cin >> it;
#define out cout << a << "\n";
#define l_b lower_bound
#define u_b upper_bound
#define f first
#define s second
#define Max 1005

using namespace std;

void solve() {
    int n;
    scanf("%d", &n);
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        ll num = (ll)n / i;
        num *= (num + 1);
        num /= 2;
        num *= i;
        ans += num;
    }
    printf("%lld\n", ans);
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	int A, B;
	cin >> A >> B;

	if(B%A == 0)
		cout << A+B << endl;
	else
		cout << B-A << endl;

	return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

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

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	rep (i, k) {
	  if (a >= b) {
		b *= 2;
		continue;
	  }
	  if (b >= c) {
		c *= 2;
		continue;
	  }
	}
	cout << ((a < b && b < c) ? "Yes" : "No") << endl;
    
    return 0;
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
typedef pair<ll,ll> P;
int main(){
  int n,m;
  cin>>n>>m;
  if(n+1>=m*2){
    cout<<"YES";
  }else{
      cout<<"NO";
    }
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var stations = Enumerable.Repeat(0, n - 1).Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();
        for (int i = 0; i < n; i++)
        {
            int time = 0;
            foreach (var station in stations.Skip(i))
            {
                time = Max(station[1], time);
                time = ((time + station[2] - 1) / station[2]) * station[2];
                time += station[0];
            }
            Console.WriteLine(time);
        }
    }
}


Measured memory_bytes: 13524
import math


mod=10**9+7

def ncr(n,r):
	res=1
	for i in range(1,r+1):
		res=(res*(n-r+i))%mod
		inv=pow(i,mod-2,mod)
		res=(res*inv)%mod
	return res

n,a,b=map(int,raw_input().split())
p=pow(2,n,mod)
p=(p-1+mod)%mod
p=(p-ncr(n,a)+mod)%mod
p=(p-ncr(n,b)+mod)%mod
print p



Measured memory_bytes: 30828
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
typedef long long ll;
typedef long double ld;
using namespace std;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;

const int N = 2e3 + 10;
int a[N];

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

  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1, k = j; j < n; j++) {
      while (k + 1 < n && a[i] + a[j] > a[k + 1]) ++k;
      cnt += k - j;
    }
  }
  cout << cnt << endl;


  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			String N = in.next();
			if(N.contains("9")) {
				out.println("Yes");
			}else {
				out.println("No");
			}
		}
	}
	
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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

Measured memory_bytes: 21076
package main

import (
	"bufio"
	"fmt"
	basicIO "io"
	"os"
	"strconv"
)

func main() {
	protagonist(os.Stdin, os.Stdout)
}

func protagonist(reader basicIO.Reader, writer basicIO.Writer) {
	io := NewIO(reader, writer)
	var N int
	var Q int
	var str string
//	N, _ = io.nextInt()
//	Q, _ = io.nextInt()
//	str = io.nextString()
	fmt.Scan(&N, &Q, &str)
	t := make([]byte, Q)
	d := make([]byte, Q)

	for i := 0; i < Q; i++ {
		t[i] = io.nextString()[0]
		d[i] = io.nextString()[0]
	}

	fl := FlowLeft(N, Q, str, t, d)
	fr := FlowRight(N, Q, str, t, d)
	io.PutInt(N - fr - fl)
}

func DriftToSection(n int, N int, Q int, str string, t []byte, d []byte) byte {
	for i := 0; i < Q; i++ {
		if str[n] == t[i] {
			if d[i] == 'L' {
				n--
			} else {
				n++
			}
			if n < 0 {
				return 'L'
			}
			if n >= N {
				return 'R'
			}
		}
	}
	return 'M'
}

func FlowLeft(N int, Q int, str string, t []byte, d []byte) int {
	l, r := 0, N-1
	tmp := DriftToSection(l, N, Q, str, t, d)
	if tmp == 'M' || tmp == 'R' {
		return 0
	} else if DriftToSection(r, N, Q, str, t, d) == 'L' {
		return N
	}

	for (r - l) > 1 {
		m := int((l + r) / 2)
		switch DriftToSection(m, N, Q, str, t, d) {
		case 'L':
			l = m
		case 'R':
			r = m
		case 'M':
			r = m
		}
	}
	return r
}
func FlowRight(N int, Q int, str string, t []byte, d []byte) int {
	l, r := 0, N-1
	tmp := DriftToSection(r, N, Q, str, t, d)
	if tmp == 'M' || tmp == 'L' {
		return 0
	} else if DriftToSection(l, N, Q, str, t, d) == 'R' {
		return N
	}

	for (r - l) > 1 {
		m := int((l + r) / 2)
		switch DriftToSection(m, N, Q, str, t, d) {
		case 'L':
			l = m
		case 'R':
			r = m
		case 'M':
			l = m
		}
	}
	return N - r
}

type IO struct {
	Scanner *bufio.Scanner
	Writer  basicIO.Writer
}

func NewIO(r basicIO.Reader, w basicIO.Writer) *IO {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	return &IO{
		Scanner: s,
		Writer:  w,
	}
}

func (io *IO) nextString() string {
	io.Scanner.Scan()
	return io.Scanner.Text()
}

func (io *IO) nextInt() (int, error) {
	io.Scanner.Scan()
	i, err := strconv.Atoi(io.Scanner.Text())
	return i, err
}

func (io *IO) PutInt(v int) {
	fmt.Fprintf(io.Writer, "%d\n", v)
}

func (io *IO) PutString(s string) {
	fmt.Fprintf(io.Writer, "%s\n", s)
}


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

int main(){

    int N;
    string S, T;
    string ans = "";

    cin >> N;
    cin >> S >> T;

    for(int i = 0; i < S.size(); i++){
        ans += S[i];
        ans += T[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstdint>
#include<unordered_map>
#include<sstream>
#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}

ll combination(ll n, ll r) {
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}

int main()
{
	int n, d;
	cin >> n >> d;
	vector<vi>x(n, vi(d));
	rep(i, n)rep(j, d)cin >> x[i][j];
	int count = 0;
	rep(i, n){
		FOR(j, i + 1, n) {
			int sum = 0;
			rep(k, d) {
				sum += pow(x[i][k] - x[j][k], 2);
			}
			bool ans = false;
			FOR(k, 1, sqrt(sum) + 1) {
				if (sum  == pow(k,2)) {
					ans = true;
					break;
				}
			}
			if (ans) {
				count++;
				//cout << sum << endl;
				//cout << i << " " << j << endl;
			}
		}
	}
	cout << count << endl;

}


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

int main(void) {
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> c(H);
  for (int i = 0; i < H; i++) {
    cin >> c[i];
  }

  int ans = 0;
  for (int i = 0; i < (1 << H); i++) {
    for (int j = 0; j < (1 << W); j++) {
      int cnt = 0;
      for (int k = 0; k < H; k++) {
        if (i & (1 << k)) continue;
        for (int l = 0; l < W; l++) {
          if (j & (1 << l)) continue;
          if (c[k][l] == '#') cnt++;
        }
      }
      if (cnt == K) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

ll dp[5005][5005];

int main(int argc, char* argv[]) {
  ll n;
  cin >> n;
  string s;
  cin >> s;

  rrep(i, n, 1) rrep(j, i, 0) {
    if (i - j == 1) {
      dp[i][j] = s[i] == s[j];
      continue;
    }

    if (i == n - 1) {
      dp[i][j] = s[i] == s[j];
      continue;
    }

    if (s[i] != s[j]) {
      dp[i][j] = 0;
      continue;
    }

    dp[i][j] = min<ll>(i - j, dp[i + 1][j + 1] + 1);
  }

  ll ans = 0;
  rep(i, 0, n) rep(j, 0, n) { chmax(ans, dp[i][j]); }

  put(ans);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 193920
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>

using namespace std;

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

typedef long long ll;

int cnt(int N) {
  int ret = 0;
  while(N % 100 == 0) {
    N /= 100;
    ret++;
  }
  return ret;
}
int main() {
  int D, N;
  cin >> D >> N;
  int c = 0;
  for (int i = 1; i < 300000000; i++) {
    int k = cnt(i);
    if (k == D) c++;
    if (c == N) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int dice[3][4] = {0};
	cin >> dice[0][1] >> dice[1][1] >>  dice[1][2] >> dice[1][0] >> dice[1][3] >> dice[2][1];
	char command[100];
	cin >> command;
	int length = strlen(command);
	for (int i = 0; i < length; i++)
	{
		switch (command[i])
		{
		case 'E':
		{
			int tmp = dice[0][1];
			dice[0][1] = dice[1][0];
			dice[1][0] = dice[2][1];
			dice[2][1] = dice[1][2];
			dice[1][2] = tmp;
			break;
		}
		case 'N':
		{
			int tmp = dice[0][1];
			dice[0][1] = dice[1][1];
			dice[1][1] = dice[2][1];
			dice[2][1] = dice[1][3];
			dice[1][3] = tmp;
			break;
		}
		case 'S':
		{
			int tmp = dice[0][1];
			dice[0][1] = dice[1][3];
			dice[1][3] = dice[2][1];
			dice[2][1] = dice[1][1];
			dice[1][1] = tmp;
			break;
		}
		case 'W':
		{
			int tmp = dice[0][1];
			dice[0][1] = dice[1][2];
			dice[1][2] = dice[2][1];
			dice[2][1] = dice[1][0];
			dice[1][0] = tmp;
			break;
		}
		}
	}
	cout << dice[0][1] << endl;
	return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    long long int n,x,t,i,h,j,a,b;
    cin>>n>>x>>t;
    if(n%x==0)
    {
        a=n/x;
    }
    else{
        a=(n/x)+1;
    }
    cout<<t*a<<endl;
}


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


int main(){
  int n,m,i;
  cin >> n;
  vector<string> s(n);
  map<string,int> mp;
  for(i=0;i<n;++i){
    cin >> s[i];
    mp[s[i]]++;
  }
  cin >> m;
  vector<string> t(m);
  for(i=0;i<m;++i){
    cin >> t[i];
    mp[t[i]]--;
  }
  int ans=0;
  for(auto p : mp){
    ans=max(ans,p.second);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll; ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
    ll n,k,ans=0; cin>>n>>k;
    while(n){
        ans++;
        n/=k;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll a,b,c;
	cin>>a>>b>>c;
	ll sum=a+b+c;
	if(sum>=22){
		cout << "bust";
	}
	else{
		cout << "win";
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

const int MAX = 510000;
const int MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  ll n,k;
  cin >> n >> k;
  COMinit();
  if(n<k)k=n-1;
  ll ans=0;
  rep(i,k+1){
    ans+=(COM(n,i)*COM(n-1,i))%mod;
    ans%=mod;
  }
  cout << ans << endl;
return 0;}

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

signed main() {
  int K;
  cin >> K;
  int ans = 0;
  for(int a=1; a<=K; a++)
  for(int b=1; b<=K; b++)
  for(int c=1; c<=K; c++) {
    ans += gcd(gcd(a,b), c);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
n = gets.to_i
as = gets.chomp.split.map(&:to_i)
ans_o = ans_e = 0
sum_o = sum_e = 0

0.upto(n-1) do |i|
  sum_e += as[i]
  sum_o += as[i]
  if i.even?
    if sum_e <= 0
      ans_e += sum_e.abs + 1
      sum_e += sum_e.abs + 1
    end
    if sum_o >= 0
      ans_o += sum_o.abs + 1
      sum_o -= sum_o.abs + 1
    end

  else

    if sum_e >= 0
      ans_e += sum_e.abs + 1
      sum_e -= sum_e.abs + 1
    end
    if sum_o <= 0
      ans_o += sum_o.abs + 1
      sum_o += sum_o.abs + 1
    end
  end
end

puts [ans_e,ans_o].min


Measured memory_bytes: 9612
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){
  
  int dx[] = {1,0,0,-1};
  int dy[] = {0,1,-1,0};
  int h,w;
  P S,G;
  cin >> h >> w >> S.first >> S.second >> G.first >> G.second;
  S.first--;S.second--;G.first--;G.second--;
  vector<string> s(h);
  rep(i,h)cin >> s[i];
  vector<vector<int>> d(h,vector<int> (w,-1));
  d[S.first][S.second] = 0;
  queue<P> que;
  que.push(S);
  queue<P> seen;
  while(!que.empty()){
    P o = que.front();que.pop();
    seen.push(o);
    rep(i,4){
      int nx = o.second+dx[i],ny = o.first+dy[i];
      if(nx < 0 || nx >= w || ny < 0 || ny >= h)continue;
      if(d[ny][nx] != -1)continue;
      if(s[ny][nx] == '#')continue;
      d[ny][nx] = d[o.first][o.second];
      que.push(make_pair(ny,nx));
    }
    if(que.empty()){
      while(!seen.empty()){
        P o = seen.front();
        bool ok = false;
        for(int i = -2;i <= 2;i++){
          for(int j = -2;j <= 2;j++){
            int ny = o.first+i,nx = o.second+j;
            if(ny < 0 || ny >= h || nx < 0 || nx >= w)continue;
            if(d[ny][nx] != -1)continue;
            if(s[ny][nx] == '#')continue;
            que.push(make_pair(ny,nx));
            d[ny][nx] = d[o.first][o.second]+1;
            ok = true;
            if(j == 2 && i == 2)seen.pop();
            if(ok)break;
          }
          if(ok)break;
        }
        if(!ok)seen.pop();
        if(ok)break;
      }
    }
  }
  cout << d[G.first][G.second] << "\n";






  return 0;
}

Measured memory_bytes: 9552
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int N = fs.nextInt();
        int Q = fs.nextInt();
        String s = fs.next();

        int[] cumSum = new int[N+1];
        for (int i = 0; i < N; ++i) {
            if (i != N-1 && s.charAt(i) == 'A' && s.charAt(i+1) == 'C')
                cumSum[i+1] = cumSum[i] + 1;
            else
                cumSum[i+1] = cumSum[i];
        }

        for (int i = 0; i < Q; ++i) {
            int l = fs.nextInt();
            int r = fs.nextInt();
            System.out.println(cumSum[r-1] - cumSum[l-1]);
        }
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

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

    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}

    public 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();
    }

    public 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();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 48752
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define MXN 100003

int n,
	a[MXN];
bool naive;

bool comp(int a, int b){
	return a>b;
}

int main(){

	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	std::sort(a+1,a+n+1,comp);
	
	int i,j;
	for(i=1;i<=n;i++)
		if(a[i]<i)
			break;
	i--;
	for(j=i;j<=n;j++)
		if(i>a[j])
			break;
	j--;
	//printf("i=%d a[i]=%d j=%d\n",i,a[i],j);
	if(((j-i)&1) || ((a[i]-i)&1))
		printf("First\n");
	else
		printf("Second\n");

	//system("pause");
	return 0;
}


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

using namespace std;
typedef long long ll;

#define endl "\n"
#define all(c) (c).begin(),(c).end()

signed main() {
	// freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	/* stuff you should look for
	 * int overflow, array bounds
	 * special cases (n=1?)
	 * do smth instead of nothing and stay organized
	 * WRITE STUFF DOWN
	 * also remember to clear global variables on multitest problems
	 * also remember to switch INT_MAX -> LLONG_MAX after fixing overflow bugs
	 * don't get used to greedy, DP might actually be the solution
	 */
	std::ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	vector<int> freq(n);
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		freq[--x]++;
	}
	priority_queue<int> pq;
	for (int i = 0; i < n; i++)
		pq.push(freq[i]);


	int s = n;
	for (int k = 1; k <= n; k++) {
		while (!pq.empty() and pq.top() > s/k) {
			int x = pq.top(); pq.pop();
			pq.push(x-1);
			s--;
		}
		cout << s/k << endl;
	}
	
	// you should actually read the stuff at the top
}


Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int a, b;
    cin >> a >> b;
    
  	if(b % a == 0)
  		cout << a + b << endl;
  	else
      	cout << b - a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 bool sortbysec(pair<long long int,long long int> a,pair<long long int,long long int> b)
 {
    if(a.second==b.second)
        return a.first<b.first;
    return a.second<b.second;
 }     
 int main()
{
   // #define long long int long long long long int
    long long int n,w,i,j,a,b,max1;
    cin >> n >> w;
    vector <pair<long long int,long long int>> g;
    for(i=0;i<n;i++)
    {
        cin >> a >> b;
        g.push_back(make_pair(a,b));
    }
   // sort(g.begin(),g.end(),sortbysec);
    long long int mat[n][100000+1];
    for(i=0;i<n;i++)
    {
        for(j=0;j<=100000;j++)
            mat[i][j]=-1;
    }
    mat[0][0]=0;mat[0][g[0].second]=g[0].first;
    for(i=1;i<n;i++)
    {
        for(j=0;j<=100000;j++)
        {
            if((j-g[i].second)>=0)
            {
                if(mat[i-1][j-g[i].second]>=0 && (mat[i-1][j-g[i].second]+g[i].first)<=w)
                    mat[i][j]=mat[i-1][j-g[i].second]+g[i].first;
            }
            if(mat[i][j]==-1)
            {
                if(mat[i-1][j]==-1)
                    mat[i][j]=-1;
                else
                    mat[i][j]=mat[i-1][j];
            }
            else
            {
                if(mat[i-1][j]!=-1)
                    mat[i][j]=min(mat[i][j],mat[i-1][j]);
            }
        }
    }
    max1=INT_MIN;
    for(i=0;i<n;i++)
    {
    for(j=0;j<=100000;j++)
    {
        if(mat[i][j]!=-1)
        max1=max(max1,j);
    }
    }
    cout << max1;
    

    
}

Measured memory_bytes: 78336
#include <iostream>
#include <vector>
#include <map>
#include <utility>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector
#define ll long long
#define mp make_pair

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

int main(void)
{
  ll h, w, n;
  cin >> h >> w >> n;
  vec<ll> ans(10, 0);
  ans[0] = (h - 2) * (w - 2);
  int a, b;
  map<pair<int, int>, int> m;
  rep(i, n) {
    cin >> a >> b;
    rep(j, 9) {
      int x = a + dx[j];
      int y = b + dy[j];
      if (x <= 1 || x >= h || y <= 1 || y >= w) continue;
      ans[m[mp(x, y)]]--;
      m[mp(x, y)]++;
      ans[m[mp(x, y)]]++;
    }
  }
  rep(i, 10) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 56448
#include<bits/stdc++.h>
using namespace std;
string a,b="keyence";
void solve()
{
    int i,j,k,tag=0,l=a.length();
    if (l>=7)
    {
        for (i=0;i<l-1;i++)
        {
            for (j=i;j<l;j++)
            {
                string tmp;
                for (k=0;k<i;k++)
                    tmp.push_back(a[k]);
                for (k=j;k<l;k++)
                    tmp.push_back(a[k]);
                if (tmp==b) {tag=1;break;}
            }
            if (tag) break;
        }
        if (tag) puts("YES");
        else puts("NO");
    }
    else puts("NO");
}
int main()
{
    while(cin>>a)
        solve();
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> range(m);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        range[i] = {b - 1, a};
    }
    sort(range.begin(), range.end());
    int ans = 0;
    int last = -1;
    for (int i = 0; i < m; ++i) {
        if (range[i].second > last) {
            ++ans;
            last = range[i].first;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var list = nextCharArray();
	var len = list.length;
	var R = 0;
	var L = 0;
	var check = new Array(len).fill(0);
	for(var i = 0; i < len; i++){
		if(list[i] == "R"){
			R++;
		}else{
			if(list[i - 1] == "R"){
				check[i - 1] = R;
				R = 0;
			}
		}
	}
	for(var i = len - 1; i >= 0; i--){
		if(list[i] == "L"){
			L++;
		}else{
			if(list[i + 1] == "L"){
				check[i + 1] = L;
				L = 0;
			}
		}
	}
	if(L != 0){
		check[0] = L;
	}
	if(R != 0){
		check[len - 1] = R;
	}
	for(var i = 0; i < len - 1; i++){
		if(list[i] == "R" && list[i + 1] == "L"){
			var sum = check[i] + check[i + 1];
			if((check[i] + check[i + 1]) % 2 == 0){
				check[i] = sum / 2;
				check[i + 1] = sum / 2;
			}else{
				var min = Math.floor(sum / 2);
				var max = Math.ceil(sum / 2);
				if(check[i] % 2 == 1){
					check[i] = max;
					check[i + 1] = min;
				}else{
					check[i] = min;
					check[i + 1] = max;
				}
			}
		}
	}
	myout(myconv(check, 8));
}


Measured memory_bytes: 38416