akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < static_cast<int>(b); i++)
#define FORR(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) FOR (i, 0, n)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
template <typename T>
void print(const vector<vector<T>> matrix);
template <typename T>
void print(const vector<T> vec);
template <typename Arg>
void print(const Arg arg);
template <typename Head, typename... Args>
void print(const Head head, const Args... args);
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
typedef pair<long long, long long> P;

int N;
int idx(int n) { return n >= 0 ? n : n + N; }
bool isGood(vector<vector<char>> mat, int a) {
    rep (i, N) {
        rep (j, i) {
            if (mat[idx(i - a)][idx(j)] != mat[idx(j - a)][idx(i)])
                return false;
        }
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    int ans = 0;
    vector<vector<char>> mat(N, vector<char>(N));

    rep (i, N)
        rep (j, N)
            cin >> mat[i][j];

    rep (i, N)
        if (isGood(mat, i)) ans++;

    print(ans * N);
}

//---------------------------------------------
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    repall (i, vec)
        cout << i << ' ';
    cout << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}


Measured memory_bytes: 512
Option Strict On
Public Class Main
    Public Shared Sub Main(ByVal args() As String)
        Dim H, N As Integer
        Dim arr(2) As String
        arr = Split(Console.ReadLine())
        H = Integer.Parse(arr(0)) : N = Integer.Parse(arr(1))
        Dim A() As Integer = Array.ConvertAll(Of String, Integer) _
            (Split(Console.ReadLine()), AddressOf Integer.Parse)
        Array.Sort(A)
        Dim accum As Integer = 0
        Dim flg As Boolean = False
        For Each Ai As Integer In A
            accum += Ai
            If H <= accum Then
                flg = True
                Exit For
            End If
        Next
        Console.WriteLine(If(flg, "Yes", "No"))
    End Sub
End Class


Measured memory_bytes: 25652
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Long() + add;
        }
        return Array;
    }
}
class Program {
    static Scanner cin = new Scanner();
    static void Main() {
        long N = cin.Long();
        long X = cin.Long();

        Console.WriteLine(burger(N, X));
        Console.ReadLine();
    }

    static long burger(long n, long x) {
        if (x == 1) return 0;
        if (n == 1) {
            if (x == 1) return 0;
            else if (x == 2) return 1;
            else if (x == 3) return 2;
            else return 3;
        }
        else if(x <= Math.Pow(2, n + 1) - 2) {
            return burger(n - 1, x - 1);
        }else if(x == Math.Pow(2, n + 1) - 1) {
            return burger(n - 1, (long)Math.Pow(2, n + 1) - 3) + 1;
        }
        else if(x <= Math.Pow(2, n + 2) - 4){
            return burger(n - 1, (long)Math.Pow(2, n + 1) - 3) + 1 + burger(n - 1, x - (long)Math.Pow(2, n + 1) + 1);
        }
        else {
            return 2 * burger(n - 1, (long)Math.Pow(2, n + 1) - 3) + 1;
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define all(n)      (n).begin(), (n).end()
#define ll long long
#define ull unsigned long long int
void solve() {
    ll n,d; cin >> n >> d;
    ll x,y;
    d *= d;
    vector<pair<ll,ll>> v;
    for(ll i = 0; i < n; i++){
        cin >> x >> y;

        v.push_back({x,y});
       
    }
    ll cnt = 0;
    for(auto i = 0; i < v.size(); i++){
         ll a = v[i].first,b = v[i].second;
        a = abs(a),b= abs(b);
        ll dist = ((a*a)+(b*b));
        if(dist <= d){
           cnt++;
        }
    }    
    cout << cnt << endl;
}
int main(){
    // ios::sync_with_stdio(0);
    // cin.tie(0);
    //Starts here , 
                
    // int T; cin >> T;
    // while(T--){
        solve();
    // }
    return 0;
            
}

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

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

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

ll n;
ll p[100];
ll conv[3];

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    ll ans = 0;

    for(int i = 0; i < n-2; i++){
        conv[0] = p[i];
        conv[1] = p[i+1];
        conv[2] = p[i+2];
        sort(conv,conv+3);
        if(conv[1] == p[i+1])   ++ans;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import math
def main():
  n,time = list(map(int,input().split()))
  ct = [map(int, input().split()) for _ in range(n)]
  c,t = [list(i) for i in zip(*ct)]
  cost=1001
  for i in range(0,n):
    if t[i]<=time and c[i]<cost:
      cost=c[i]
  if cost==1001:
    print("TLE")
  else:
    print(cost)
main()

Measured memory_bytes: 9136
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
int main(){

    int n;
    cin>>n;
    while(n--){
        int gates[10];
        int jucky[10];
        for(int i = 0; i < 9; i++)
            cin>>gates[i];
        for(int i = 0; i < 9; i++)
            cin>>jucky[i];
        sort(jucky,jucky+9);

        int jwin=0;
        int gwin=0;
        do{
            int jsum=0;
            int gsum=0;
            for(int j = 0; j < 9; j++){
                if(gates[j]<jucky[j]){
                    jsum+=jucky[j]+gates[j];
                }
                else
                    gsum+=jucky[j]+gates[j];
            }
            if(jsum>gsum)
                jwin++;
            else if(jsum<gsum)
                gwin++;
        }while(next_permutation(jucky,jucky+9));
        double res=(double)(gwin)/(jwin+gwin);
        printf("%.5f\n",res);
        printf("%.5f\n",1-res);
    }

    return 0;
}

Measured memory_bytes: 904
#!/usr/bin/env ruby

# Generated by AtcoderGreedy on 2018-06-10
# ABC099 B

# my lib

module Enumerable
  # work just like String#split,
  # except this method does not use regex match
  # but check whether yield succeeds or not.
  def split
    current = nil
    ret = []
    each do |elem|
      if yield elem
        if current
          ret << current
          current = nil
        end
      elsif current
        current << elem
      else
        current = [elem]
      end
    end
    ret << current if current
    ret
  end
end

class Array
  # truncate tail, opposite of drop
  def clip(amount = 1)
    if amount < 0
      raise ArgumentError, "amount == #{amount}, cannot be negative!"
    end
    take_amount = size - amount
    take_amount < 0 ? [] : take(take_amount)
  end
end

def n_choose_k(n, k)
  return 0 unless (0..n).cover? k
  result = 1
  1.upto(k) do |d|
    result *= n
    result /= d
    n -= 1
  end
  result
end

# end of lib

# Your code here

a, b = gets.chomp.split(' ').map(&:to_i)

c = b - a

b_height = (1..c).reduce(&:+)
snow = b_height - b

puts snow


Measured memory_bytes: 1788
# coding: utf-8
# Your code here!
H,W = [int(i) for i in input().split()]
c=[[int(i) for i in input().split()] for _ in range(10)] 
A=[[int(i) for i in input().split()] for _ in range(H)]


dist = c
n=10
#n: 頂点数
for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j] = min(dist[i][j], dist[i][k]+ dist[k][j])


ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] != -1:
            ans += dist[A[i][j]][1]
print(ans)     



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

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

  int cnt = 0;
  for (int i=0; i<n; i++) {
    int min_j = i;
    for (int j=i; j<n; j++) {
      if (a[j] < a[min_j]) min_j = j;
    }
    if (i != min_j) {
      int temp = a[i];
      a[i] = a[min_j];
      a[min_j] = temp;
      cnt++;
    }
  }

  for (int i=0; i<n-1; i++) cout << a[i] << " ";
  cout << a[n-1] << endl;
  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
 
int main() {
    int n, c, k, ans = 1;
    cin >> n >> c >> k;

    int t[n];
    rep(i, n) {
        cin >> t[i];
    }
    sort(t, t+n);
 
    int firstIndex = 0;
    int firstTime = t[0];
    for(int i = 1; i < n; i++) {
        if(firstIndex + c <= i || firstTime + k < t[i]) {
            firstIndex = i;
            firstTime = t[i];
            ans++;
        }
    }

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;

int main(){
    
    int N,K;cin>>N>>K;
    string S;cin>>S;
    int cnt=0;
    for(int i=1;i<N;i++){
        if(S[i]==S[i-1]) cnt++;
    }
    
    cnt+=2*K;
    if(cnt>=N) cnt=N-1;
    
    cout<<cnt<<endl;
}


Measured memory_bytes: 512
from collections import Counter
n = int(input())
a = []
ans = []
if n == 1:
    print(1)
    exit()
for _ in range(n):
    x, y = map(int, input().split())
    a.append([x, y])
a.sort()
for i in range(n):
    for j in range(i + 1, n):
        p = a[i][0] - a[j][0]
        q = a[i][1] - a[j][1]
        ans.append(str(p) + " " + str(q))
print(n - max(Counter(ans).values()))

Measured memory_bytes: 3436
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

s = input().strip()

for i, c in enumerate(s):
    if i % 2 == 0:
        if c == "L":
            print("No")
            sys.exit()
    else:
        if c == "R":
            print("No")
            sys.exit()

print("Yes")

Measured memory_bytes: 38384
N,M=map(int,input().split())
hen=[[] for i in range(0,N)]
for i in range(0,M):
    a,b=map(int,input().split())
    hen[a-1].append(b-1)
    hen[b-1].append(a-1)

def onestrokepath(start,visited=[]):
    flag=0
    count=0
    for next in hen[start]:
        if not next in visited:
            flag=1
            count+=onestrokepath(next,visited+[next])
    if flag==0:
        check=[i for i in range(0,N)]
        visited.sort()
        if check==visited:
            return 1
        else:
            return 0
    return count

print(onestrokepath(0,[0]))


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#define p 1000000007
using namespace std;
int n,m,cnt;
int fir[1010],nxt[2020],to[2020],dep[2020];
int fa[2020],num[2020],edg[2020];
long long X;
struct evol{ int x,y,v;}a[101010];
bool cmp(evol u,evol v){ return u.v<v.v;}
void add(int x,int y,int z)
{
	nxt[++cnt]=fir[x];fir[x]=cnt;
	to[cnt]=y;num[cnt]=z;
}
void dfs(int x)
{
	dep[x]=dep[fa[x]]+1;
	for(int i=fir[x];i;i=nxt[i])
	if(to[i]!=fa[x]) edg[to[i]]=num[i],fa[to[i]]=x,dfs(to[i]);
}
int find(int x){ return fa[x]==x?x:fa[x]=find(fa[x]);}
long long ksm(long long x,int t)
{
	long long res=1;
	for(;t;t>>=1,x=x*x%p) if(t&1) res=res*x%p;
	return res;
}
int main()
{
	scanf("%d%d%lld",&n,&m,&X);
	for(int i=1;i<=m;i++)
	scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].v);
	sort(a+1,a+m+1,cmp);
	long long sum=0;
	int equ=0,up=0;
	for(int i=1;i<=n;i++) fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		int x=a[i].x,y=a[i].y;
		if(find(x)!=find(y))
		{
			fa[fa[x]]=fa[y],sum+=a[i].v;
			add(x,y,a[i].v),add(y,x,a[i].v);
		}
	}
	if(sum>X) puts("0");
	else
	{
		fa[1]=0;dfs(1);
		for(int i=1;i<=m;i++)
		{
			int x=a[i].x,y=a[i].y,ma=0;
			if(dep[x]<dep[y]) swap(x,y);
			while(dep[x]>dep[y]) ma=max(ma,edg[x]),x=fa[x];
			while(x!=y) ma=max(ma,max(edg[x],edg[y])),x=fa[x],y=fa[y];
			if(sum-ma+a[i].v==X) equ++;
			else if(sum-ma+a[i].v>X) up++;
		}
	//	cout<<sum<<" "<<equ<<endl;
		if(sum<X) printf("%lld\n",2LL*(ksm(2,equ)-1)%p*ksm(2,up)%p);
		else printf("%lld\n",(ksm(2,equ)-2)*ksm(2,up)%p);
	}
	return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4 5
0 1 2
0 2 1
1 2 1
1 3 1
2 3 2

output:
3
"""

import sys
from collections import deque


def graph_bfs(source, target, parent):
    visited = [False] * v_num
    queue = deque()
    queue.appendleft(source)
    visited[source] = True

    while queue:
        current = queue.popleft()
        for adj, cp in adj_table[current].items():
            if cp and not visited[adj]:
                queue.append(adj)
                visited[adj] = True
                parent[adj] = current

    return True if visited[target] else False


def graphFordFulkerson(source, sink):
    parent = [-1] * v_num
    max_flow = 0

    while graph_bfs(source, sink, parent):
        path_flow = float('inf')

        bk_1 = sink
        while bk_1 is not source:
            parent_bk_1 = parent[bk_1]
            assert parent_bk_1 != -1
            path_flow = min(path_flow, adj_table[parent_bk_1][bk_1])
            bk_1 = parent[bk_1]

        max_flow += path_flow

        bk_2 = sink
        while bk_2 is not source:
            parent_bk_2 = parent[bk_2]
            assert parent_bk_2 != -1
            # adj_table[parent_bk_2].setdefault(bk_2, 0)
            adj_table[bk_2].setdefault(parent_bk_2, 0)

            # print(bk_2, parent_bk_2, path_flow, bk_1, parent[bk_1], parent, adj_table)
            adj_table[parent_bk_2][bk_2] -= path_flow
            adj_table[bk_2][parent_bk_2] += path_flow
            bk_2 = parent[bk_2]

    return max_flow


def generate_adj_table(_edges):
    for edge in _edges:
        source, target, cp = map(int, edge)
        init_adj_table[source][target] = cp

    return init_adj_table


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    v_num, e_num = map(int, _input[0].split())
    edges = map(lambda x: x.split(), _input[1:])

    init_adj_table = [dict() for _ in range(v_num)]
    adj_table = generate_adj_table(edges)
    ans = graphFordFulkerson(source=0, sink=v_num - 1)
    print(ans)

Measured memory_bytes: 8164
import itertools


num_person = int(input())

testimony = []
for i in range(0, num_person):
    honest = set()
    dishonest = set()
    num_test = int(input())
    for _ in range(0, num_test):
        target, test = map(int, input().split())
        target -= 1
        if test:
            honest.add(target)
        else:
            dishonest.add(target)
    testimony.append((honest, dishonest))

ans = [0]
for t in itertools.product((1, 0), repeat=num_person):
    honest = {i for i in range(0, num_person) if t[i]}
    dishonest = {i for i in range(0, num_person) if not t[i]}
    for i in range(0, num_person):
        if t[i]:
            honest.add(i)
            honest = honest.union(testimony[i][0])
            dishonest = dishonest.union(testimony[i][1])
    if honest.intersection(dishonest):
        continue
    else:
        ans.append(sum(t))

print(max(ans))
exit(0)


Measured memory_bytes: 3496
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
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 vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll 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 T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
	ll ans[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	ll k; cin >> k; k--;
	cout << ans[k] << endl;
}

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

int main(void){
    int n;
    cin >> n;
    vector<ll> a(n);
    int minus_cnt = 0;
    ll abs_sum = 0;
    ll abs_min = INF;
    rep(i,n) {
        cin >> a[i];
        if (a[i] < 0LL) minus_cnt++;
        abs_min = min(abs_min, abs(a[i]));
        abs_sum += abs(a[i]);
    }
    if (minus_cnt % 2 == 0) {
        cout << abs_sum << endl;
    } else {
        cout << abs_sum - abs_min*2 << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long int a, b, c, k; cin >> a >> b >> c >> k;
	long long int ans;
	if(k%2==0){
		ans = a-b;
	}else{
		ans = b-a;
	}
	cout << ans << endl;
	return 0;
}

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

int N;
vector<int> p;
//bool visited[10010];
//bool is_loop[10010];
bool dijkstra_visited[100100];
//int v[10010];

struct edge {
	int to;
	int cost;
	edge(int t_, int c_) {
		to = t_;
		cost = c_;
	}
};

struct status {
	int amt;
	int v;
	status(int a_, int v_) {
		amt = a_;
		v = v_;
	}
	bool operator<(const status &obj) const {
		return this->amt > obj.amt;
	}
};

vector<vector<edge> > e;

/*
bool loop(int n) {
	if(visited[n])
		return is_loop[n];
	visited[n] = true;
	is_loop[n] = true;
	if(p[n] == 0)
		return is_loop[n] = false;
	return is_loop[n] = loop(n + p[n]);
}
// */

int main() {
	cin >> N;
	p.resize(N);
	for(int i = 0; i < N; i++) {
		cin >> p[i];
	}
	/*
	for(int i = 0; i < N; i++) {
		loop(i);
	}
	// */
	e.resize(N);
	for(int i = 0; i < N; i++) {
		if(p[i] == 0) {
			for(int j = 0; j < 6; j++) {
		//		if(!is_loop[i+j+1]) {
				if(i+j+1 < N) {
					e[i].push_back(edge(i+j+1, 1));
				}
		//		}
			}
		}
		else {
	//		if(!is_loop[i]) {
				e[i].push_back(edge(i+p[i], 0));
	//		}
		}
	}

	priority_queue<status> q;
	q.push(status(0,0));
	int res = 1e9;
	while(!q.empty()) {
		status cur = q.top();
		q.pop();
		if(dijkstra_visited[cur.v])
			continue;
		dijkstra_visited[cur.v] = true;
//		v[cur.v] = cur.amt;
		if(cur.v == N-1) {
			res = cur.amt;
			break;
		}
		for(int i = 0; i < e[cur.v].size(); i++) {
			if(!dijkstra_visited[e[cur.v][i].to]) {
				q.push(status(cur.amt + e[cur.v][i].cost, e[cur.v][i].to));
			}
		}
	}
//	for(int i = 0; i < N; i++)
//		cout << "i:" << i << " " << v[i] << endl;
	cout << res << endl;
}

Measured memory_bytes: 8624
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
using namespace std;
typedef pair<int, int>p;
p mov[200005];
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,q;
	string s;
	cin >> n >> q >> s;
	string t, d;
	for (int i = 0; i < q; i++) {
		cin >> t >> d;
		mov[i].first = t[0];
		mov[i].second = ((d[0] == 'L') ? -1 : 1);
	}
	long long ub = n;
	long long lb = -1;
	while (ub - lb > 1) {
		long long mid = (ub + lb) / 2;
		long long tmp = mid;
		int judge = 0;
		for (int i = 0; i < q; i++) {
			if (mov[i].first == s[tmp]) {
				tmp += mov[i].second;
			}
			if ( tmp == -1) { judge = 1; break; }
		}
		if (judge)lb = mid;
		else ub = mid;
	}
	long long ans = lb + 1;
	ub = n;
	lb = -1;
	while (ub - lb >1) {
		long long mid = (ub + lb) / 2;
		long long tmp = mid;
		int judge = 0;
		for (int i = 0; i < q; i++) {
			if (mov[i].first == s[tmp]) {
				tmp += mov[i].second;
			}
			if (tmp == n) { judge = 1; break; }
		}
		if (judge)ub = mid;
		else lb = mid;
	}
	ans += (n - ub);
	cout << max((long long)0, n - ans);
}

Measured memory_bytes: 2196
# -*- coding: utf-8 -*-
import heapq
import math
import sys

N = int(input())
t, x, y = 0, 0, 0
flag = True
for n in range(N):
    tmp = input()
    nt, nx, ny = [int(a) for a in tmp.split()]
    dt, dx, dy = nt - t, nx - x, ny - y
    d = abs(dx) + abs(dy)
    if d <= dt and d % 2 == dt % 2:
        continue
    else:
        flag = False
if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <memory>
#include <algorithm>

typedef long long ll;

using namespace std;

class DReplacing {
public:
  void solve(std::istream &in, std::ostream &out) {
    map<ll, ll> m;
    ll n; in >> n;
    ll tot = 0;
    for (int i = 0; i < n; ++i) {
      ll a;
      in >> a;
      if (m.find(a) == m.end()) m[a] = 0;
      m[a] += 1;
      tot += a;
    }
    ll Q;
    in >> Q;
    for (int i = 0; i < Q; ++i) {
      ll b, c; in >> b >> c;
      if (m.find(b) == m.end()) {
        out << tot << endl;
        continue;
      }
      if (m.find(c) == m.end()) m[c] = 0;
      tot += (c - b) * m[b];
      out << tot << endl;
      m[c] += m[b];
      m.erase(b);
    }
  }
};


int main() {
	DReplacing solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 7104
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
	char suit;
	int value;
};

struct Card L[MAX/2+2],R[MAX/2+2];

void merge(struct Card A[],int n,int left,int mid,int right){
 int i,j,k;
	int n1=mid-left; 
	int n2=right-mid;
	for(i=0;i<n1;i++)L[i]=A[left+i];
	for(i=0;i<n2;i++)R[i]=A[mid+i];
	L[n1].value=R[n2].value=SENTINEL;
	i=j=0;
	for(k=left;k<right;k++){
		if(L[i].value<=R[j].value){
		A[k]=L[i++];
		}else{
		A[k]=R[j++];
		}
	}
}

void mergeSort(struct Card A[],int n,int left,int right){
	int mid;
	if(left+1<right){
		mid=(left+right)/2;
		mergeSort(A,n,left,mid);
		mergeSort(A,n,mid,right);
		merge(A,n,left,mid,right);
	}
}

int partition(struct Card A[],int n,int p,int r){
 int i,j;
	struct Card t,x;
  x=A[r];
  i=p-1;
	for(j=p;j<r;j++){
		if(A[j].value<=x.value){
		 i++;
		 t=A[i]; A[i]=A[j]; A[j]=t;
		}
	}
t=A[i+1]; A[i+1]=A[r]; A[r]=t;
return i+1;
}

void quickSort(struct Card A[],int n,int p,int r){

	int q;
	if(p<r){
	
		q=partition(A,n,p,r);
		quickSort(A,n,p,q-1);
		quickSort(A,n,q+1,r);
	}
}

int main(){
	int n,i,v;
	struct Card A[MAX],B[MAX];
	char S[10];
	int stable=1;

	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%s %d",S,&v);
		A[i].suit=B[i].suit=S[0];
		A[i].value=B[i].value=v;
		}
	
	mergeSort(A,n,0,n);
	quickSort(B,n,0,n-1);
	
	for(i=0;i<n;i++){
		if(A[i].suit!=B[i].suit)stable=0;
	}
	
	if(stable==1)printf("Stable\n");
	else printf("Not stable\n");
	for(i=0;i<n;i++){
		printf("%c %d\n",B[i].suit,B[i].value);
	}
	return 0;
}


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

#define rep(i, n) for(int i=0; i < (int)n; i++)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;

int main(void) {
  int n, m, l;
  cin >> n >> m >> l;

  ll A[n][m], B[m][l], C[n][l];

  rep(i, n) rep(j, l) C[i][j] = 0;

  rep(i, n) rep(j, m) cin >> A[i][j];
  rep(i, m) rep(j, l) cin >> B[i][j];

  rep(i, n) rep(j, l) rep(k, m) C[i][j] += A[i][k] * B[k][j];

  rep(i, n) {
    rep(j, l) {
      cout << C[i][j];
      if(j != l-1) cout << " ";
    }
    cout << endl;
  }
}



Measured memory_bytes: 3300
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
#define ll  long long 
  vector<ll>dp(100000);
  vector<vector<ll>>e(100000,vector<ll>(0));
int main(){
  ll a,d;cin>>a;
  string c;
  vector<map<char,ll>>b(a);
  rep(i,a){
    cin>>c;
    rep(o,c.size()){
      if(b[i].count(c[o]))b[i][c[o]]++;
      else b[i][c[o]]=1;
    }
}
for(char i='a';i<='z';i++){
  d=INT_MAX;
  rep(o,a){
    if(b[o].count(i))d=min(d,b[o][i]);
    else {
      d=0;
      break;
    }
  }
  rep(o,d)cout<<i;
}
  }


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

#define int long long
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; i++)
#define MOD (int)(1e9+7)
using namespace std;
typedef pair<int, int> P;
struct edge {
    int to, cost;
};

class dijkstra {
private:
    int V;
    int d[100002];
    priority_queue<P, vector<P>, greater<>> que;

public:
    dijkstra(int v, int s, vector<edge> G[]) {
        V = v;
        update(s, G);
    }

    void update(int s, vector<edge> G[]) {
        fill(d, d + V + 1, 100000000000ll);
        d[s] = 0;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (d[v] < p.first)
                continue;
            rep(i, G[v].size()) {
                edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to], e.to));
                }
            }
        }
    }

    int find(int e) {
        return d[e];
    }
};

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

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

bool prime(int a) {
    if (a == 1)
        return false;
    for (int i = 2; i * i <= a; i++) {
        if (a % i == 0)
            return false;
    }
    return true;
}

class Union_Find {
private:
    vector<int> t, s;

public:
    Union_Find(int max_length) {
        rep(i, max_length + 1) {
            t.push_back(i);
            s.push_back(1);
        }
    }

    void Union(int x, int y) {
        if (same(x, y))
            return;
        int tx = Find(x), ty = Find(y);
        if (s[tx] < s[ty]) {
            s[ty] += s[tx];
            t[tx] = ty;
        } else if (s[tx] > s[ty]) {
            s[tx] += s[ty];
            t[ty] = tx;
        } else if (tx > ty) {
            t[tx] = ty;
            s[ty] += s[tx];
        } else {
            t[ty] = tx;
            s[tx] += s[ty];
        }
    }

    int Find(int n) {
        if (t[n] == n)
            return n;
        else
            return t[n] = Find(t[n]);
    }

    bool same(int x, int y) {
        return Find(x) == Find(y);
    }

    int get_Size(int a) {
        return s[a];
    }
};

vector<int> primeFactorization(int n) {
    vector<int> re;
    int cnt = 2;
    while (n != 1) {
        if (n % cnt != 0) {
            cnt++;
            continue;
        }
        n /= cnt;
        re.push_back(cnt);
    }
    return re;
}

signed main() {
    int n,a,b;
    cin>>n>>a>>b;
    cout<<min(n*a,b)<<endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    S=input()
    T=input()
    if(set(T)-set(S)):
        print(-1)
        return
    n=len(S)
    C=[[] for _ in range(26)]
    for i,s in enumerate(S*2): C[ord(s)-97].append(i)
    from bisect import bisect_left
    ans=0
    for s in T:
        j=bisect_left(C[ord(s)-97],ans%n)
        ans+=C[ord(s)-97][j]-ans%n+1
    print(ans)
resolve()

Measured memory_bytes: 54568
import string
N = int(input())

char = string.ascii_lowercase
rev = {c: i for i,c in enumerate(char, start=1)}

name_rev = []

while 1:
    # print(f"N : {N}")
    M = N % 26
    name_rev.append(char[M -1])
    if N <= 26:
        break
    N = (N-1) // 26
print("".join(name_rev[::-1]))

# P = 0
# for i, c in enumerate(name_rev, start=0):
#     P += 26**i * rev[c]
# print(P)


Measured memory_bytes: 9924
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, A[88];

  std::cin >> N;

  for (int i = 0; i < N; i ++)
    std::cin >> A[i];

  long long C = 1000, a = A[0], b = A[0], c;

  c = C / a;
  C = C % a;

  for (int i = 1; i < N; i ++) {
    if (A[i] <= b) {
      C += 1LL * b * c;

      a = b = A[i];
      c = C / a;
      C = C % a;
    }
    else {
      b = A[i];
    }
  }

  C += 1LL * b * c;

  std::cout << C << std::endl;

  return 0;
}


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


int main(){
  ll x;
  cin >> x;
  ll ans = 1;
  ll now = x;
  while( now%360 != 0 ){
    now += x;
    now %= 360;
    ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3588
#入力
N=int(input())

ans= N / 1.08

if(ans % 1 !=0):
    ans= (ans //1)+1

#print("ans        =",ans)
#print("ans * 1.08 =",ans*1.08)

if((ans * 1.08)//1 == N):
    print(int(ans))
else:
    print(":(")

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

int main()
{

	int H, W;
	while (true)
	{
		cin >> H >> W;
		if (H == 0 && W == 0)
		{
			break;
		}
		for (int row = 0; row < H; row++)
		{
			for (int col = 0; col < W; col++)
			{
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> v(n+2);
  v.at(0) = 0;
  int sum = 0;
  rep(i, n){
    int in;
    cin >> in;
    v.at(i+1) = in;
    sum += abs(v.at(i+1) - v.at(i));
  }
  v.at(n+1) = 0;
  sum += abs(v.at(n+1)-v.at(n));
  rep2(i, 1, n+1){
    int d1 = abs(v.at(i-1) - v.at(i+1));
    int d2 = abs(v.at(i-1) - v.at(i)) + abs(v.at(i) - v.at(i+1));
    cout << sum - (d2 - d1) << endl;
  }
  return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m;
char a[1055][1055];
ll dp[1099][1099];


int main(){
	ll mod=1000000007;
	cin >> n >> m;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			cin >> a[i][j];
		}
	}
	for (int i=1; i<=n; i++){
		for (int j=1; j<=m; j++){
			if(i==1 && j==1)dp[i][j]=1;
			else{
				if(a[i][j]=='.')dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
			}
		}
	}
	cout << dp[n][m]%mod << endl;
}//m

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

using namespace std;

typedef unsigned long long int ulli;

int main(){
	/*
	freopen("input.txt","r",stdin);
	freopen("input.txt","w",stdout);
	*/
	int n;
	cin >> n;
	vector<int> v(n);
	string answer = "APPROVED";
	for(int i = 0; i < n; i++){
		cin >> v[i];
		if(v[i] % 2 == 0){
			if(v[i] % 3 != 0 && v[i] % 5 != 0){answer = "DENIED";}
		}
	}
	cout << answer;
} 

Measured memory_bytes: 256
H,N = map(int, input().split())
A = []
B = []
for _ in range(N):
    a,b = map(int, input().split())
    A.append(a)
    B.append(b)

dp = [10**9]*(H+1)
dp[0] = 0
for i in range(N):
    for j in range(H+1):
        if j < A[i]:
            dp[j] = min(dp[j], B[i])
        else:
            dp[j] = min(dp[j], B[i]+dp[j-A[i]])

print(dp[H])

Measured memory_bytes: 42348
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

ll h, w;

int main(){
	// freopen("input.txt", "r", stdin);
	// freopen(fname".in", "r", stdin);
	// freopen(fname".out", "w", stdout);
	cin >> h >> w;
	if(h % 3 == 0 || w % 3 == 0){
		printf("0\n");
		return 0;
	}
	ll ans = min(w, h);
	for(int i = 1; i < h; ++i){
		ll a = i * w;
		ll b = (h - i) * (w / 2);
		ll c = (h - i) * (w - w / 2);
		ll mx = max(a, max(b, c));
		ll mn = min(a, min(b, c));
		ans = min(ans, mx - mn);
	}
	for(int i = 1; i < w; ++i){
		ll a = i * h;
		ll b = (w - i) * (h / 2);
		ll c = (w - i) * (h - h / 2);
		ll mx = max(a, max(b, c));
		ll mn = min(a, min(b, c));
		ans = min(ans, mx - mn);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k,x,y;
	cin>>k>>x;
	int a[201];
	y=x-k+1;
	for(int i=y;i<=x+k-1;i++)
	{
		a[i]=i;
		cout<<a[i]<<" ";
	}
	return 0;
}

Measured memory_bytes: 256
from collections import Counter 
from collections import defaultdict
from collections import deque
import math
import itertools
import heapq
import sys
sys.setrecursionlimit(10**6)

#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
input_list = lambda : list(map(int,input().split()))

a,b=input_list()
ans=0
if a>12:
    ans=b
if 13>a and a>5:
    ans=b//2

print(ans)

Measured memory_bytes: 3316
W,H,N=list(map(int,input().split()))
l=[[0]*W for i in range(H)]
for i in range(N):
   x,y,a= map(int,input().split())
   if a == 1:
      for j in range(x):
         for k in range(H):
            l[k][j] = 1
   elif a == 2:
      for j in range(x,W):
         for k in range(H):
            l[k][j] = 1
   elif a == 3:
      for j in range(0,y):
         l[j] = [1]*W
   elif a == 4:
      for j in range(y,H):
         l[j] = [1]*W
ans=W*H
for i in range(H):
   ans-=l[i].count(1)
print(ans)

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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep2(i, a, b) for(int i = a; i <= b; ++i)
#define ll long long
#define eb emplace_back
#define all(c) (c).begin(), (c).end()
#define vi vector<int>

int main() {
	int n, m;
	vector<ll>a;
	vector<ll>b;
	vector<ll>c;
	ll x;
	cin >> n >> m;
	rep(i, n) {
		cin >> x;
		a.eb(x);
	}
	rep(i, m) {
		cin >> x;
		b.eb(x);
	}
	c = convolution(a, b);
	rep(i, n + m - 1) {
		cout << c[i];
		if (i < (n + m - 2))cout << " ";
		else cout << endl;
	}
	return 0;
}


Measured memory_bytes: 27404
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int N,M,Q;
    cin >> N >> M >> Q;
    int l,r;
    int sum[N + 1][N + 1] = {};
    REP(i,M){
        cin >> l >> r;
        sum[l][r]++;
    }
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
            sum[i][j] += sum[i - 1][j];
            sum[i][j] += sum[i][j - 1];
            sum[i][j] -= sum[i - 1][j - 1];
        }
    }
    int p,q;
    REP(i,Q){
        cin >> p >> q;
        cout << sum[q][q] - sum[p - 1][q] - sum[q][p - 1] + sum[p - 1][p - 1] << endl; 
    }
}

Measured memory_bytes: 1920
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;



int main()
{
    int64_t H, W, N;
    std::cin >> H >> W >> N;

    struct Point {
        int64_t x;
        int64_t y;
        bool operator<(const Point& d) const {
            return x == d.x ? y < d.y : x < d.x;
        }
    };

    std::map<Point, size_t> C;

    // 枠は [1, H-2]まで
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t ay, bx;
        std::cin >> ay >> bx;

        for (int64_t xx = std::max<int64_t>(1, bx-2); xx <= std::min<int64_t>(bx, W-2); ++xx) {
            for (int64_t yy = std::max<int64_t>(1, ay-2); yy <= std::min<int64_t>(ay, H-2); ++yy) {
                C[{xx, yy}] = C[{xx, yy}] + 1;
            }
        }
    }

    std::vector<int64_t> ans(10);

    ans[0] = (H-2) * (W-2);

    for (auto c: C) {
        ans[c.second]++;
        ans[0]--;
    }

    for (auto a: ans) {
        std::cout << a << std::endl;
    }

    return 0;
}


Measured memory_bytes: 56448
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

int main(){
    int n, m, s;
    while(cin >> n >> m >> s, n||m||s){
        int dp[21][11][200] = {0};
        rep(i,n + 1) dp[i][0][0] = 1;
        range(k,1,n + 1){ //?????¨?????????????????§???
            range(i,1,m + 1){//?????£???????´???°
                range(j,1,s + 1){//???
                    dp[k][i][j] += dp[k - 1][i][j];
                    if(j - k >= 0) dp[k][i][j] += dp[k - 1][i - 1][j - k];

                    //cout << k << ' ' << i<<' '<<j<< endl;
                    //debug(dp[k][i][j])
                }
            }
        }
        cout << dp[n][m][s] << endl;
    }
}

Measured memory_bytes: 3260
class SegmentTree:
    def __init__(self, initial_values, f=max, zero=0):
        self.__f, self.__z, self.__size = f, zero, len(initial_values)
        self.__n = 1 << ((self.__size - 1).bit_length())
        self.__dat = [zero] * (2 * self.__n)
        zi = self.__get_leaf(0)
        for i, v in enumerate(initial_values): self.__dat[zi + i] = v
        for i in range(zi-1, -1, -1): self.__dat[i] = self.__f(*self.__get_children(i))
    
    def update(self, index, value):
        i = self.__get_leaf(index)
        if self.__dat[i] == value: return
        self.__dat[i] = value
        while i:
            i = self.__get_parent(i)
            self.__dat[i] = self.__f(*self.__get_children(i))
    
    def query(self, from_inclusive, to_exclusive):
        ans = self.__z
        if to_exclusive <= from_inclusive: return ans
        l, r = self.__get_leaf(from_inclusive), self.__get_leaf(to_exclusive) - 1
        while r - l > 1:
            if self.__is_right(l): ans = self.__f(ans, self.__dat[l])
            if self.__is_left(r): ans, r = self.__f(ans, self.__dat[r]), r-1
            l, r = l//2, self.__get_parent(r)
        ans = self.__f(ans, self.__dat[l])
        if l != r: ans = self.__f(ans, self.__dat[r])
        return ans

    def __get_leaf(self, i): return self.__n + i - 1
    def __get_parent(self, i): return (i-1)//2
    def __get_children(self, i): return (self.__dat[2*i+1], self.__dat[2*i+2])
    def __is_left(self, i): return i&1 == 1
    def __is_right(self, i): return i&1 == 0

N = int(input())
S = input()
g = lambda c: 1 << (ord(c)-ord('a'))
tree = SegmentTree([g(c) for c in S], lambda x,y:x|y)
Q = int(input())
for _ in range(Q):
    t, a, b = input().split()
    if t == '1': tree.update(int(a)-1, g(b))
    else: print(bin(tree.query(int(a)-1, int(b))).count('1'))

Measured memory_bytes: 88088
#include<iostream>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++)
#define MAX 100
#define INFTY (1<<21)
int G[MAX][MAX], n;

void prim(){
    int D[MAX], V[MAX], P[MAX], sum = 0;
    rep(i, n) { D[i] = INFTY; V[i] = 0; }
    D[0] = 0;

    while(1){
	int u, minv = INFTY;
	rep(i, n) if ( !V[i] && minv > D[i]) { 
	    minv = D[i], u = i; 
	}
	if ( minv == INFTY ) break;
	V[u] = 1;
	if ( u ) sum += G[u][P[u]];
	rep(v, n){
	    if ( !V[v] && G[u][v] < D[v] ){
		D[v] = G[u][v];
		P[v] = u;
	    }
	}
    }

    cout << sum<< endl;
}

main(){
    int m, s, t, c;
    char ch;
    while( cin >> n >> m && n ){
	rep(i, n) rep(j, n) G[i][j] = INFTY;
	rep(i, m) {
	    cin >> s >> ch >> t >> ch >> c; 
	    G[s][t] = G[t][s] = c/100-1;
	}
	prim();
    }
}

Measured memory_bytes: 0
#include <algorithm>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define ENDL '\n'
#define FOR(i, n) for (int i = 0; i < n; i++)
#define FOR_EACH(i, v) for (auto&& i : v)

int H;
int W;
vector<string> S(H);

int bombSearch(int row, int center)
{
	int ret = 0;
	if (S[row][center] == '#') {
		ret++;
	}
	if (center && S[row][center - 1] == '#') {
		ret++;
	}
	if (center != W - 1 && S[row][center + 1] == '#') {
		ret++;
	}
	return ret;
}

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

	cin >> H >> W;
	S.clear();
	FOR(i, H) {
		string str;
		cin >> str;
		S.push_back(str);
	}

	FOR(i, H) {
		FOR(j, W) {
			if (S[i][j] == '#') {
				continue;
			}

			char bombNum = '0';
			if (i) {
				bombNum += bombSearch(i - 1, j);
			}
			bombNum += bombSearch(i, j);
			if (i != H - 1) {
				bombNum += bombSearch(i + 1, j);
			}

			S[i][j] = bombNum;
		}
		cout << S[i] << ENDL;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> p;

int main() {
  int64_t H,W,N;
  cin>>H>>W>>N;
  vector<pair<int,int>> p;
  for(int i=0;i<N;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    for(int j=-1;j<=1;j++){
      for(int k=-1;k<=1;k++){
        if(0<a+k&&a+k<H-1&&0<b+j&&b+j<W-1){
          p.push_back(make_pair(a+k,b+j));
        }
      }
    }
    
  }
  sort(p.begin(), p.end());
  int a=1;
  vector<int64_t> q(10);
  q.at(0)=(H-2)*(W-2);
  for(int i=1;i<p.size();i++){
    if(p.at(i-1)==p.at(i)){
      a++;
    }
    else{
      q.at(0)--;
      q.at(a)++;
      a=1;
    }
    if(i==p.size()-1){
      q.at(0)--;
      q.at(a)++;
      a=1;
    }
  }
  for(int i=0;i<10;i++){
    cout<<q.at(i)<<endl;
  }
    
  
  
}




Measured memory_bytes: 10604
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
const ld EPS = 1e-6;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
const char nl = '\n';

template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> void ckmin(T& a, T b) { a = min(a, b); }
template <class T> void ckmax(T& a, T b) { a = max(a, b); }

// (Integer/Long).bitCount(x)
int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }

void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) { cerr << h; if (sizeof...(t)) cerr << ", "; DBG(t...); }

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
void setIO(string s = "") {
	unsyncIO();
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
}

// Binary Exponentiation
ll pow(ll b, ll e, ll m = 0LL, ll ans = 1LL) { while (e) { if (e & 1LL) { ans *= b; if (m) ans %= m; } b *= b, e >>= 1LL; if (m) b %= m; } return ans; }



void solve(int tcn) {
	int n, ans = 0;
	cin >> n;
	int a[n];
	F0R(i, n)
		cin >> a[i];
	F0R(i, n) {
		if (a[i] % 2 == 1 && i % 2 == 0)
			++ans;
	}
	cout << ans << nl;
}

int main() {
    setIO();

    int t = 1; //cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve(i);
	}
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<map>
using namespace std;
using ll = long long;

int main(){
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll cnt=0;
        while(n%i==0){
            n/=i;
            cnt++;
        }
        for(ll j=1;;j++){
            if(cnt>=j){
                cnt-=j;
                ans++;
            }else break;
        }
    }
    if(n!=1) ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 3616