akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>
#include <chrono>
#include <set>


#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

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

ll pow(ll a, ll b) {
	vector<ll> d = vector<ll>((ll)(log(b)) + 2);
	d[0] = a;
	rep(i, 1, d.size()) d[i] = d[i - 1] * d[i - 1];
	ll ret = 1;
	rep(i, 0, log(b) + 1) {
		if (b & 1 << i) ret *= d[i];
	}
	return ret;
}

ll H, W,index;
vector<string> S;
vector<vector<ll>> group;
vector<vector<ll>> visit;

void rec(ll row, ll col) {
	visit[row][col] = 1;
	if (S[row][col] == '.') group[index][0]++;
	else group[index][1]++;
	rep(i, -1, 2) {
		rep(j, -1, 2) {
			if (i != 0 && j != 0)continue;

			if (0 <= row + i && row + i < H && 0 <= col + j && col + j < W) {
				if (S[row][col] != S[row + i][col + j] && visit[row + i][col + j] < 0) rec(row + i, col + j);
			}
		}
	}
}


//C
int main(void) {
	cin >> H >> W;
	group = vector<vector<ll>>(H * W, vector<ll>(2, 0));
	visit = vector<vector<ll>>(H, vector<ll>(W,-1));
	S = vector<string>(H);

	rep(i, 0, H) cin >> S[i];

	rep(i, 0, H) {
		rep(j, 0, W) {
			if (visit[i][j]) {
				rec(i, j);
				index++;
			}	
		}
	}

	ll ans = 0;
	rep(i, 0, H* W) {
		ans += group[i][0] * group[i][1];
	}

	cout << ans << endl;
}

Measured memory_bytes: 28032
def examA():
    S = SI()
    if S=="AAA" or S=="BBB":
        print("No")
    else:
        print("Yes")
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examA()

"""

"""

Measured memory_bytes: 5232
module.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8"))},function(e,r){e.exports=function(e){var r=e.split("\n"),t=Number(r[0]),n=Number(r[1]),o=Number(r[2]),u=Number(r[3]),i=Number(r[4]),f=Number(r[5]),l=Math.min(n,o,u,i,f),c=5+(Math.ceil(t/l)-1);console.log(c)}},function(e,r){e.exports=require("fs")}]);

Measured memory_bytes: 7372
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll>pll;

int main() {
	int a,b,c;
    cin>>a>>b>>c;

    if(a+b<c){
        cout<<a+b+b+1<<endl;
    }
    else{
        cout<<b+c<<endl;
    }
	
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <iomanip>
#include <functional>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define PI 3.14159265358979323846264338327950L
using namespace std;

typedef long long ll;
typedef long double ld;

long long myGcd(long long a, long long b)
{
	if (a % b == 0)return b;
	return myGcd(b, a % b);
}

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

long long myLcm(long long a, long long b)
{
	return a * b / myGcd(a, b);
}

int myLcm(int a, int b)
{
	return a * b / myGcd(a, b);
}


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

	string T;
	cin >> T;

	REP(i, T.size())
	{
		if (T[i] == '?')
		{
			T[i] = 'D';
		}
	}
	int PD = 0;
	REP(i, T.size())
	{
		if (T[i] == 'D')
		{
			PD++;
		}
		else if (T[i] == 'P' && i + 1 < T.size())
		{
			if (T[i + 1] == 'D')
			{
				PD++;
			}
		}
	}

	cout << T << endl;

	return 0;
}

Measured memory_bytes: 3772
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

S = input()
N = len(S)

for l in range(N):
	for r in range(l, N):
		if S[:l] + S[r:] == "keyence":
			print("YES")
			break
	else:
		continue
	break
else:
	print("NO")


Measured memory_bytes: 5160
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
//max=({});
//条件式が真ならwhileの中身を回し続ける

bool flag[1050000];

int main() {
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	string ans;
	rep(i, n) {
		ans += s[i];
		ans += t[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    int a, b;
    cin>>a>>b;
    co(a*b);
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using edge = struct {int to; ll cost;};

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 29)


void solve() {
    ll a, b, k;
    cin >> a >> b>> k;
    ll takahasi, aoki;
    takahasi = max(0ll, a-k);
    aoki = max(0ll, b - max(0ll, k - a));
    cout << takahasi << " " << aoki << "\n";
}

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

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

#define ll long long 
#define pb push_back
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()

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

	int N; cin >> N;
	ll A[N];
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	ll p = 0, ans = 0;
	for (int i = 0; i < N; ++i) {
		if (A[i] < p) {
			ans += p - A[i];
		}
		p = max(p, A[i]);
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 5188
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


int main()	{
	int n;
	cin >> n;
	vector< vector<int> > freq_max(n);
	for (int i = 0; i < n; i++)	{
		for (int j = 0; j < 10; j++)	{
			int tmp;
			cin >> tmp;
			freq_max[i].push_back(tmp);
		}	
	}
	
	vector< vector<int> > profits(n);

	for (int i = 0; i < n; i++)	{
		for (int j = 0; j < 11; j++)	{
			int tmp;
			cin >> tmp;
			profits[i].push_back(tmp);	
		}
	}

	long long acc = -1e9; 
	for (int i = 1; i < 1024; i++)	{
		int temp = 0;
		for (int j = 0; j < n; j++)	{
			int temp1 = 0;
			for (int k = 0; k < 10; k++)	{
				if ((i>>k&1) && (freq_max[j][k] == 1)) temp1++; 
			}
			temp += profits[j][temp1];
		}
		if (acc < temp) acc = temp;
	}	
	cout << acc << endl;
	return 0;
}


Measured memory_bytes: 3620
S = input()
p = [1] * (len(S) - 1)
sumlst = [0] * len(S)
ans = 0
def dfs(i):
    global ans
    if i == (len(S) - 1):
        tmp = ''
        if p[0] == 1:
            tmp += S[0] + '+' + S[1]
        else:
            tmp += S[0] + S[1]
        for i in range(1, len(p)):
            if p[i] == 1:
                tmp += '+' + S[i + 1]
            else:
                tmp += S[i + 1]
        ans += eval(tmp)
        return

    p[i] = 1
    dfs(i + 1)
    p[i] = 0
    dfs(i + 1)
    return
if len(S) == 1:
    print(int(S))
    exit()
dfs(0)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e3+100,mod=924844033;
ll dp[N][N],pd[N*2][N+100];
ll fac[N];
int32_t main(){
    ll n,k;
    fac[0]=1;
    for (int i=1;i<N;i++){
        fac[i]=fac[i-1]*i%mod;
    }
    cin >> n >> k;
    for (int i=0;i<N;i++) pd[i][0]=1;
    for (int i=2;i<N*2;i++){
        for (int j=1;j<=i/2;j++){
            pd[i][j]=pd[i-2][j-1]+pd[i-1][j];
            pd[i][j]%=mod;
        }
    }
    dp[0][0]=1;
    for (int i=1;i<=min(n,2*k);i++){
        ll z=n-i+1;
        z=(z+k-1)/k;
        if (i>k) z++;
        for (int j=0;j<N;j++){
            for (int k=0;k<=z/2;k++){
                if (j>=k){
                    dp[i][j]+=dp[i-1][j-k]*pd[z][k]%mod;
                    dp[i][j]%=mod;
                }
            }
        }
    }
    ll ans=1;
    for (int i=1;i<=n;i++) ans*=i,ans%=mod;
    ll z=-1;
    for (int i=1;i<=n;i++){
        ans+=z*dp[min(2*k,n)][i]%mod*fac[n-i]%mod;
        ans+=mod;
        ans%=mod;
        z*=-1;
    }
    cout << ans << endl;

}


Measured memory_bytes: 105216
#include <bits/stdc++.h>
#define LL long long
using namespace std;
vector<vector<int> >g(300050);
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,m,u,v; cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i=0;i<g[1].size();i++)
    {
        int c=g[1][i];
        for(int j=0;j<g[c].size();j++)
        {
            if(g[c][j]==n)
            {
                cout<<"POSSIBLE";
                return 0;
            }
        }
    }
    cout<<"IMPOSSIBLE";
}


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int n = in();
    vint a = in(n);
    map<int, int> m;
    rep(i, n)
    {
        ++m[a[i]];
        ++m[a[i] - 1];
        ++m[a[i] + 1];
    }
    int ans = 0;
    for (auto x : m)
    {
        ans = max(ans, x.second);
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 5120
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int array[1000],top;

void push(int);
int pop(void);

int main()
{
  int x,y,i=0;
  char array_main[100];

  top=0;

  while(scanf(" %s",array_main)!=EOF){
    /*if(array_main[0] == NULL || array_main[1] == NULL) exit(1);*/
    if(array_main[0] == '+'){
      x=pop();
      y=pop();
      /*printf("%d %d\n",x,y);*/
      if((x+y) < -1000000000 || (x+y) > 1000000000) exit(1);
      push(x+y);
    }
    else if(array_main[0] == '-'){
      x=pop();
      y=pop();
      if((y-x) < -1000000000 || (y-x) > 1000000000) exit(1);
      push(y-x);
    }
    else if(array_main[0] == '*'){
      x=pop();
      y=pop();
      if((x*y) < -1000000000 || (x*y) > 1000000000) exit(1);
      push(x*y);
    }
    else if(array_main[0]>='0' || array_main[0]<='9'){
      /*if(array_main[0]<'0' || array_main[0]>'9') exit(2);*/
      push(atoi(array_main));
    }
  }

    printf("%d\n",pop());
  
    return 0;
  
}

void push(int x)
{
  array[++top]=x;
}

int pop()
{
  top--;
  return array[top+1];
}



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

int main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string str; cin >> str;
	for(int i = str.size() - 1; i >= 0; i--) {
		if(i - 5 + 1 < 0) {
			cout << "NO" << endl;
			return 0;
		}
		string t = str.substr(i - 5 + 1, 5);
		if(t == "dream" || t == "erase") {
			i = i - 5 + 1;
			continue;
		}

		if(i - 6 + 1 < 0) {
			cout << "NO" << endl;
			return 0;
		}
		t = str.substr(i - 6 + 1, 6);
		if(t == "eraser") {
			i = i - 6 + 1;
			continue;
		}

		if(i - 7 + 1 < 0) {
			cout << "NO" << endl;
			return 0;
		}
		t = str.substr(i - 7 + 1, 7);
		if(t == "dreamer") {
			i = i - 7 + 1;
			continue;
		}
		cout << "NO" << endl;
		return 0;
	}

	cout << "YES" << endl;
}

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

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007
#define endl "\n"

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

    // cout<<fixed<<setprecision(15);

    string s;
    cin>>s;

    set<char> s1;

    map<char,ll> hm;

    for(ll i = 0 ; i < 4 ; i++)
    {
        s1.insert(s[i]);
        hm[s[i]]++;
    }

    if(s1.size() == 2)
    {
        char c1 = *s1.begin();
        char c2 = *s1.rbegin();
        if(hm[c1] == 2 && hm[c2] == 2)
        {
            cout<<"Yes"<<endl;    
        }
        else
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }

}

Measured memory_bytes: 256
#include<stdio.h>
main(){
    int a,b,c,d,e,f;
    double x,y;
while(scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f)!=EOF){

x=(double)(b*f-c*e)/(b*d-a*e);
y=(double)(c*d-a*f)/(b*d-a*e);

printf("%.3lf ",x+0.00005);
printf("%.3lf\n",y+0.00005);
}
return 0;
}

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

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

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

typedef long long ll;

#define MAX_N 10000

struct Edge {
    int to;
    int weight;
    Edge(int t, int w)
        : to(t)
        , weight(w)
    {
    }
};
using Graph = vector<vector<int>>;
using Graph_e = vector<vector<Edge>>;

vector<int> dx = { 1, 0, -1, 0 };
vector<int> dy = { 0, 1, 0, -1 };
typedef pair<int, int> P;

template <typename T>
T GCD(T x, T y)
{
    return (y ? GCD<T>(y, x % y) : x);
}

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a.at(i);
    // N-1個の最大公約数の最大値を求めればいい

    //left[i]はa.at(0)からa.at(i-1)(i番目)までの最大公約数
    vector<int> left(N + 1, 0);
    rep(i, N)
    {
        left.at(i + 1) = GCD<int>(left.at(i), a.at(i));
    }
    vector<int> right(N + 1, 0);
    rep(i, N)
    {
        right.at(i + 1) = GCD<int>(right.at(i), a.at(N - 1 - i));
    }

    int max = -INF_32;

    for (int i = 0; i < N; i++) {
        chmax(max, GCD<int>(left.at(i), right.at(N - i - 1)));
    }

    cout
        << max << endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(long long i=I;i<A;i+=B)
#define rep(I,A,B) for(long long j=I;j<=A;j+=B)
#define repp(I,A,B) for(long long j=I;j>=A;j-=B)
#define str(A) for(long long k=0;A[k]!='\0';k++)
#define pb push_back
#define mp make_pair
#define pii pair<long long,long long>
vector <int> adj[100001];
bool visit[100001];
const int mod = 1000000007;
ll arr[100001];
ll dp[100001];
ll n,k;
ll min(ll a,ll b){
	return a>b?b:a;
}
ll func(ll i)
{
	if(i<0)
		return 1e15;
	if(dp[i]==1e15)
	{
		rep(1,k,1)
			dp[i]=min(dp[i],func(i-j)+abs(arr[i]-arr[i-j]));
	}
	return dp[i];
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll i;
	cin>>n>>k;
	FOR(0,n,1)
	{
		cin>>arr[i];
	}
	FOR(0,n,1)
	{
		dp[i]=1e15;
	}
	dp[0]=0;
	cout<<func(n-1);
	return 0;
}

Measured memory_bytes: 7296
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
using mpint = mp::cpp_int;  // 多倍長整数（任意精度）

/*
 * 定数
 */
const long double PI = (acos(-1));
const long double EPS = 1e-10;
const long long INF = 1e18;

/*
 * データ変換 
 */
/* char -> int */
int ctoi(char c) { return (int)(c - '0'); }

/*
 * 数学的な計算
 */
/* 階乗 */
int factorial(int n) {
  int ret = 1;
  for (int i = 1; i < n + 1; ++i) {
    ret = ret * i;
  }
  return ret;
}

/* 最大公約数 */
template <typename T>
T gcd(T x, T y) { return x % y == 0 ? y : gcd(y, x % y); }

/* 最小公倍数 */
template <typename T>
T lcm(T a, T b) { return a * b / gcd(a, b); }

/* n個の整数の最小公倍数 */
template <typename T>
T lcm_n(vector<T> &numbers) {
  T l;
  l = numbers[0];
  for (int i = 1; i < numbers.size(); ++i) {
    l = lcm(l, numbers[i]);
  }
  return l;
}

/*
 * DP向け
 */
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}


/**
 * @param N 素因数分解する整数
 * @param result N = 2^3 * 3^2の場合、{{2, 3}, {3, 2}}のような形式のvectorが生成される
 * @brief 2, 3,..., √Nまでの整数をNで割っていき、割り切れる数と割った回数を保存することで、素因数分解を行う。
 *        O(√N)
*/
void prime_factorize(ll N, vector<pair<ll, ll>> &result) {
  for (ll a = 2; a * a <= N; ++a) {
    if (N % a != 0) continue;
    ll ex = 0;  // 指数

    // 割れる限り割り続ける
    while (N % a == 0) {
      ++ex;
      N /= a;
    }

    result.emplace_back(pair<ll, ll>{a, ex});
  }

  // 最後に残った数
  if (N != 1) result.emplace_back(pair<ll, ll>{N, 1});
}

ll type_num(ll v) {
  ll i = 0;
  while (1) {
    if (i * (i + 1) <= 2 * v && 2 * v < (i + 1) * (i + 2)) break;
    ++i;
  }
  return i;
}

int main() {
  ll N;
  cin >> N;
  vector<pair<ll, ll>> result;

  prime_factorize(N, result);
  ll ans = 0;

  for (auto v : result) {
    ans += type_num(v.second);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys


def solve(N: int, A: int):
    print(N**2-A)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
// 2014/05/30 Tazoe

#include <iostream>
using namespace std;

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

	int a_max = 0;
	int v_max = -1;

	for(int i=0; i<n; i++){
		int a, v;
		cin >> a >> v;

		if(v>v_max || (v==v_max && a<a_max)){
			a_max = a;
			v_max = v;
		}
	}

	cout << a_max << ' ' << v_max << endl;

	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define N 100005
inline int read()
{
    int x=0,t=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-') t=-1,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return x*t;
}
char s[N];
int n,k,w;
int main()
{
	n=read(),k=read();
	scanf("%s",s+1);
	for(int i=2;i<=n;i++)
	{
		if(s[i]!=s[i-1])
		{
			if(!w)w=1,k--;
			if(k==-1)break;
			s[i]^=30;
		}
		else w=0;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='L'&&s[i-1]=='L') ans++;
		if(s[i]=='R'&&s[i+1]=='R') ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll INF=1000000010;
const ll MOD=1000000007;
const ll LINF=4000000000000000000;
const long double EPS=1e-9;
typedef pair<int,int> P;
int main(){
    ll n;cin>>n;
    ll s[100];
    s[0]=1;
    int en;
    for(int i=1;i<100;i++){
        s[i]=s[i-1]*(-2);
        if(abs(s[i])>1000*INF){
            en=i;
            break;
        }
    }
    string ans="";
    bool f=false;
    for(int i=0;i<en;i++){
        if(n%s[i+1]){
            ans.push_back('1');
            n-=s[i];
        }else{
            ans.push_back('0');
        }
        if(n==0)break;
    }
    reverse(all(ans));
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
typedef vector<vector<pii>> vvpii;

void dfs(vvpii &g, vi &col, int v)
{
    for (auto i : g[v])
    {
        int u = i.first;
        int w = i.second;
        if (col[u] == -1)
        {
            col[u] = col[v] ^ w;
            dfs(g, col, u);
        }
    }
}

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

    vvpii g(n);
    for (int i = 0; i < n - 1; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        w %= 2;
        g[u].push_back(make_pair(v, w));
        g[v].push_back(make_pair(u, w));
    }

    vi col(n);
    fill(col.begin(), col.end(), -1);
    col[0] = 0;
    dfs(g, col, 0);

    for (int i = 0; i < n; i++)
    {
        cout << col[i] << endl;
    }

    return 0;
}

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


int main()
{


     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
    
    int t,s;
    cin>>t>>s;
    if(s>=t)
      cout<<"unsafe"<<endl;
    else
      cout<<"safe"<<endl;
return 0;

}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = int(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = int(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) begin(x), end(x)
using namespace std;
template <class T, class U> inline void chmin(T & a, U const & b) { a = min<T>(a, b); }

int solve(int n, vector<int> const & v) {
    map<int, int> f, g;
    REP (i, n) {
        (i % 2 == 0 ? f : g)[v[i]] += 1;
    }
    vector<pair<int, int> > a, b;
    for (auto it : f) a.emplace_back(it.second, it.first);
    for (auto it : g) b.emplace_back(it.second, it.first);
    a.emplace_back(0, 0);
    b.emplace_back(0, 0);
    sort(ALL(a));
    sort(ALL(b));
    reverse(ALL(a));
    reverse(ALL(b));
    a.resize(2);
    b.resize(2);
    int cnt = n;
    for (auto it1 : a) {
        int k1, a1; tie(k1, a1) = it1;
        for (auto it2 : b) {
            int k2, b2; tie(k2, b2) = it2;
            if (a1 != b2) {
                chmin(cnt, n - k1 - k2);
            }
        }
    }
    return cnt;
}

int main() {
    int n; cin >> n;
    vector<int> v(n);
    REP (i, n) cin >> v[i];
    cout << solve(n, v) << endl;
    return 0;
}


Measured memory_bytes: 6520
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)
#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define PRINT_CASENL  printf("Case %d:\n",tc++)
#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
typedef long long ll;
typedef long long int lln;
ll INF=1<<28;
//typedef long long lld;
const double pi=acos(-1.0);
int fx[]={1,-1,0,0}; //direction array
int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
const long double EPS=1e-7;
//#define INF 10000
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}

bool cmp(int a, int b)
{
    return a<b;
}

struct compare
{
  bool operator()(const int& l, const int& r)
  {
      return l>r;
  }
};
ll inf=1e18;
ll dp[200000];
int h[200000];
int n,k;
ll fun(int pos)
{
    if(pos==n-1)
        return 0;
    if(pos>=n)
        return inf;
    if(dp[pos]!=-1)
        return dp[pos];
    ll ans=INT_MAX;
    for(int i=1;i<=k;i++){
    ans=min(ans,abs(h[pos]-h[pos+i])+fun(pos+i));
    }
    return dp[pos]=ans;
}
int main()
{
//    READ;
    sf2(n,k);
    for(int i=0;i<n;i++)
    {
        sf(h[i]);
    }
    mem(dp,-1);
    cout<<fun(0)<<endl;
    return 0;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
long long *A;

int main() {
  int i, n;

  cin >> n;
  A = (long long*)malloc(sizeof(long long) * n);
  for(i = 0; i < n; i++)
    cin >> A[i];

  sort(A, A+n, greater<long long>());
  int idx = 1;
  long long ans = A[0];
  for(i = 1; i < n-1; i++) {
    ans += A[idx];
    if(i % 2 == 0) idx++;
  }
  
  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 5280
from sys import stdin
N = int(stdin.readline().rstrip())
K = int(stdin.readline().rstrip())
X = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 0
for i in X:
    if i < K - i:
        ans += 2 * i
    else:
        ans += 2 * (K - i)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
#define lb long double
#define ull unsigned long long int
#define pb push_back
#define vi vector < int >
# define vs vector < string >
# define vb vector < bool >

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >


# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
using namespace std  ;
 void solve()
{
int n;
cin>>n;
int ar[n];
for(int i=0;i<n;i++)
    cin>>ar[i];
    int flag=1;

    for(int i=0;i<n;i++)
    {
        if(ar[i]%2==0)
        {
            if((ar[i]%3==0) ||(ar[i]%5==0))
            {
                continue;
            }
            else
                flag=0;
        }

    }
    if(flag==1)
        cout<<"APPROVED\n";
    else
        cout<<"DENIED\n";
}

int main(){
//{fast
//int t;
//cin>>t;
//while(t--)
//{
solve();
//}

}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
ll x[N], y[N], v[N], f[N], g[N];
int main(){
#ifdef local
    freopen("test.in","r",stdin);
#endif
    ll n, c;
    scanf("%lld%lld",&n,&c);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld%lld",&x[i],&v[i]);
        y[n - i + 1] = c - x[i];
    }
    ll sum1 = 0, sum2 = 0;
    ll tmp1 = 0, tmp2 = 0;
    ll ans = 0;
    for(int i = 1; i <= n; i++)
    {
        sum1 = sum1 + v[i];
        sum2 = sum2 + v[n - i + 1];
        tmp1 = max(tmp1, sum1 - x[i]);
        tmp2 = max(tmp2, sum2 - y[i]);
        f[i] = tmp1, g[i] = tmp2;
        ans = max(ans, max(tmp1, tmp2));
    }
    for(int i = 1; i <= n; i++)
    {
        ans = max(f[i] - x[i] + g[n - i], ans);
        ans = max(g[i] - y[i] + f[n - i], ans);
    }
    return !printf("%lld",ans);
}

Measured memory_bytes: 4096
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222





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



  ll a, b;
  cin >> a >> b;
  a--;
  ll num1, num2;
  FOR(i, 1, 60) {
    num1 = (a % (1LL << (i + 1))) + 1;
    num1 = max(0LL, num1 - (1LL << i));
    num2 = (b % (1LL << (i + 1))) + 1;
    num2 = max(0LL, num2 - (1LL << i));
    ans += ((num1 + num2) % 2)*(1LL << i);
  }
  a % 4 == 1 || a % 4 == 2 ? num1 = 1 : num1 = 0;
  b % 4 == 1 || b % 4 == 2? num2 = 1 : num2 = 0;
  ans += (num1 + num2) % 2;

  cout << ans << endl;



  return 0;
}

Measured memory_bytes: 256
// abc085 B
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
  int n, a;
  vector<int> v;
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(),v.end());
  n = 0;
  a = 0;
  for (int x : v){
    if(a == x) continue;
    a = x;
    n++;
  }
  cout << n << endl;
  
  return 0;
}

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

const ll INF = 1000000007;

int main() {
  ll N, K;
  cin >> N >> K;
  ll ans = 0;
  for (ll i = K; i <= N+1; i++) {
    ans += (N*(N+1)/2)%INF;
    ans %= INF;
    ans -= ((N-i)*(N-i+1)/2)%INF;
    if (ans < 0) ans += INF;
    ans %= INF;
    ans -= (i*(i-1)/2)%INF;
    if (ans < 0) ans += INF;
    ans %= INF;
    ans++;
    ans %= INF;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3620
#include<stdio.h>
int main(void)
{
    int n,a[10000],b[10000],c[10000],i;
	while(1){
	    scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
		    scanf("%d %d %d",&a[i],&b[i],&c[i]);
		}
		for(i=0;i<n;i++){
		    if(a[i]==100||b[i]==100||c[i]==100) printf("A\n");
			else if((a[i]+b[i])/2>=90||(a[i]+b[i]+c[i])/3>=80) printf("A\n");
			else if((a[i]+b[i]+c[i])/3>=70||(a[i]+b[i]+c[i])/3>=50&&a[i]>=80||b[i]>=80) printf("B\n");
			else printf("C\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2604
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            String str = sc.next();
            if(str.equals("0")) break;
            char[] a = new char[str.length()];
            int sum = 0;
            for(int i=0;i<str.length();i++){
                a[i] = str.charAt(i);
                int b = a[i] - '0';
                sum +=b;
            }
            System.out.println(sum);
        }
        sc.close();
    }
}


Measured memory_bytes: 26208
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n, _ := strconv.Atoi(nextLine())
	aArr := make([]int, n)
	for i, v := range strings.Split(nextLine(), " ") {
		a, _ := strconv.Atoi(v)
		aArr[i] = a
	}

	aliceScore := 0
	bobScore := 0

	sort.Sort(sort.Reverse(sort.IntSlice(aArr)))

	for i, v := range aArr {
		if i%2 == 0 {
			aliceScore += v
			continue
		}
		bobScore += v
	}

	res := aliceScore - bobScore

	fmt.Printf("%d\n", res)
}


Measured memory_bytes: 640
A,B,C,D = gets.chomp.split.map(&:to_i)

if A % D == 0
  TA = A / D
else
  TA = A / D + 1
end

if C % B == 0
  AO = C / B
else
  AO = C / B + 1
end

if TA >= AO
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 14300
a = int(input())
list1 = [a]
count = 1
while True:
  if a % 2 == 0:
    a = int(a / 2)
    if a in list1:
      count += 1
      break
    list1.append(a)  
  else:
    a = int(a*3 + 1)
    if a in list1:
      count += 1
      break
    list1.append(a)
  count += 1
print(count)

Measured memory_bytes: 3060
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [0 for _ in range(n)]
p = 1
i = 0
while True:
    p = a[p - 1]
    if b[p - 1] > 0 or p == 1:
        break
    else:
        i += 1
        b[p - 1] = i
bp = b[p - 1]
if k <= bp:
    print(b.index(k) + 1)
else:
    l = bp + (k - bp) % (i + 1 - bp)
    print(b.index(l) + 1)


Measured memory_bytes: 32300
#coding:utf-8
a,b,K = list(map(int,input().split()))
k = 0

def op(m,n):
    if m%2==1:
        m-=1
    n += m/2
    m =  m/2
    #print (m,n)
    return int(m),int(n)

while(1):
    if k == K:
        break
    k+=1
    a,b = op(a,b)
    if k == K:
        break
    k+=1
    b,a = op(b,a)
print (a,b)


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

#define rep(i,k,n) for(int i=(k); i != int(n); ++i)
#define sz(x) x.size()
#define all(x) x.begin(), x.end()

#define dbg(x) cout << #x << '=' << x << '\n'
#define dbg2(x, y) cout << #x << '=' << x << ' ' << #y << '=' << y << '\n' 

#define input() (*istream_iterator<int>(cin))
#define strin() (*istream_iterator<string>(cin))
#define output(x) cout << x << '\n' 

int main(){
    ios::sync_with_stdio(false);
    int n = input();
    lli sum = 0;
    for(int i = 1; i <= n; ++i){
        if(i%3 != 0 and i%5 != 0) sum += i;
    }
    cout << sum;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

void solve() {
	long long x, k, d;
	cin >> x >> k >> d;
	if (x < 0) {
		x = -x;
	}

	long long needed = x / d;

	long long ans = 1e18;

	if (needed <= k) {
		long long reach = x - needed * d;
		long long left = (k - needed);

		for (long long i = -10; i <= 10; ++i) {
			if (abs(i) <= left && (left - abs(i)) % 2 == 0) {
				ans = min(ans, abs(reach + i * d));
			}
		}

	} else {
		long long reach = x - k * d;
		ans = abs(reach);
	}

	cout << ans << endl;
}

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

	int t;
	//cin >> t;
	t = 1;

	for (int tt = 0; tt < t; ++tt) {
		solve();
	}



	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>

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

int main(){
  string S;
  cin >> S;
  
  if(S=="Sunny") cout << "Cloudy" << endl;
  else if(S=="Cloudy") cout << "Rainy" << endl;
  else if(S=="Rainy") cout << "Sunny" << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;


int main(){
	int a, b;
	cin >> a >> b;
	if (a <= 8 && b <= 8) cout << "Yay!" << endl;
	else cout << ":(" << endl;
	return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define debug(x) cout<<#x<<"="<<x<<endl
using namespace std;
const int maxn = 8009;

int n,m,mr;
int a[maxn][maxn];
char str[10];

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

int calc(int x)
{
	return x/m+bool(x%m);
}

int main()
{
//	freopen("data.txt","r",stdin);
//	freopen("mine.txt","w",stdout);
	n=read();m=read();
	for(int i=1;i<=n;i++)
	{
		int x=read(),y=read();scanf("%s",str+1);
		int opt=calc(x)+calc(y);
		x%=m;y%=m;
		if(str[1]=='B')
		{
			if(x) x=m-x;if(y) y=m-y;
			if(opt&1) y+=m;
			a[x][y]++;a[x+m][y]--;a[x][y+m]--;a[x+m][y+m]++;
			for(int p=-2;p<=2;p++)
				for(int q=-2;q<=2;q++)
					if(abs(p)+abs(q)==2)
					{
						if(x+p*m>=0&&y+q*m>=0)
						{
							a[x+p*m][y+q*m]++;
							a[x+m+p*m][y+q*m]--;
							a[x+p*m][y+m+q*m]--;
							a[x+m+p*m][y+m+q*m]++;
						}
					}
		}
		else
		{
			if(x) x=m-x;if(y) y=m-y;
			if(!(opt&1)) y+=m;
			a[x][y]++;a[x+m][y]--;a[x][y+m]--;a[x+m][y+m]++;
			for(int p=-2;p<=2;p++)
				for(int q=-2;q<=2;q++)
					if(abs(p)+abs(q)==2)
					{
						if(x+p*m>=0&&y+q*m>=0)
						{
							a[x+p*m][y+q*m]++;
							a[x+m+p*m][y+q*m]--;
							a[x+p*m][y+m+q*m]--;
							a[x+m+p*m][y+m+q*m]++;
						}
					}
		}
	}
	mr=maxn-9;
	int ans=0;
	for(int i=0;i<=mr;i++)
	{
		for(int j=0;j<=mr;j++)
		{
			if(i>=1) a[i][j]+=a[i-1][j];
			if(j>=1) a[i][j]+=a[i][j-1];
			if(i>=1&&j>=1) a[i][j]-=a[i-1][j-1];
		//	printf("%d ",a[i][j]);
			ans=max(ans,a[i][j]);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 250624
#include <iostream>

using namespace std;

int main() {

  int a,b,c,d;

  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;

  cout << (a+b+c+d)/60 << "\n" << (a+b+c+d)%60 << endl;

  return 0;

}

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

int solve() {
    string S;
    cin >> S;
    int m = S.size();
    for ( int i = 0; i < 26; i++ ) {
        char c = 'a' + i;
        int mm = 0, b = -1;
        for ( int j = 0; j < S.size(); j++ ) {
            if ( S[j] == c ) {
                mm = max(mm, j - b - 1);
                b = j;
            }
        }
        if ( b >= 0 ) {
            mm = max(mm, (int)S.size() - b - 1);
            m = min(m, mm);
        }
    }
    return m;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n,w=map(int,input().split())
knap=[[] for i in range(4)]
w0,v=map(int,input().split())
knap[0].append(v)
for i in range(n-1):
    W,v=map(int,input().split())
    knap[W-w0].append(v)
for i in range(4):
    knap[i].sort(reverse=1)
    knap[i]=[0]+knap[i]
for i in range(4):
    for j in range(1,len(knap[i])):
        knap[i][j]+=knap[i][j-1]
ans=0
for a in range(len(knap[0])):
    for b in range(len(knap[1])):
        for c in range(len(knap[2])):
            for d in range(len(knap[3])):
                if w0*a+(w0+1)*b+(w0+2)*c+(w0+3)*d<=w:
                    ans=max(ans,knap[0][a]+knap[1][b]+knap[2][c]+knap[3][d])
print(ans)

Measured memory_bytes: 3064
N,Y=map(int,input().split())
max_ykichi=Y//10000
flag=0
for i in range(max_ykichi+1):
    max_1you=(Y-i*10000)//5000
    for j in range(max_1you+1):
        if (N-i-j)*1000+j*5000+i*10000==Y:
            print(i,j,N-i-j)
            flag=1
            break
    if flag==1:
        break
else:
    print(-1,-1,-1)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
bool custom1 (pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first);
}
bool custom2(pair<int, int> a, pair<int, int> b) {
  return (a.second < b.second);
}

const int MAX = 200005;
const long long MOD = 1000000007;
const long long MODMOD = 998244353;

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

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> pre(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;b--;
    int s = min(a, b);
    int t = max(a, b);
    pre[s]++;
    pre[t]--;
  }
  bool yes = true;

  for(int i=0;i<n;i++) {
    if(i==0) continue;
    else pre[i] = pre[i-1] + pre[i];
  }
  for(int i=0;i<n-1;i++) {
    if(pre[i] % 2 != 0) {
      yes = false;
      break;
    }
  }
  if(yes) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 768
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

typedef long long ll;
const double PI = 3.1415926535897932384626433;
const int MOD = 1e9+7;
const int INF = 1e9;
#define rep(i, n) for(int i=0;i<(n);++i)

//prototype declaration

//gloval variable

int isATGC(char s){
    if(s=='A' || s=='T' || s=='G' || s=='C') return 1;
    else return -1;
}


int main(void){
    char str[100];
    scanf("%s", str);
    int count = 0;
    int max = 0;
    rep(i, strlen(str)){
        if(isATGC(str[i])==1){
            count++;
        }else{
            if(count>0){
                if(count > max) max = count;
                count = 0;
            }
        }
    }
    if(count > max) max = count;
    printf("%d\n", max);
    return 0;
}


Measured memory_bytes: 1700
#include<iostream>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    int iLength,arrPad[3][105],nCandy,iMax=0;
    register int i,j;
    cin>>iLength;
    for(i=1;i<=2;++i){
        for(j=1;j<=iLength;++j){
            cin>>nCandy;
            arrPad[i][j]=arrPad[i][j-1]+nCandy;
        }
    }        
    for(i=1;i<=iLength;i++){
        iMax=max(iMax,arrPad[1][i]+arrPad[2][iLength]-arrPad[2][i-1]);
    }
    cout<<iMax<<endl;
    return 0;
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int count1 = 0, count2 = 0;
            string input;

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                string[] arr = input.Split(',');
                int a = int.Parse(arr[0]);
                int b = int.Parse(arr[1]);
                int c = int.Parse(arr[2]);

                if (a * a + b * b == c * c) count1++;
                if (a == b) count2++;
            }
            Console.WriteLine(count1 + "\n" + count2);
        }
    }
}

Measured memory_bytes: 9016
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<algorithm>
#include<cstdio>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int bm = 3010;
ll BIT[bm];
void add(int A, ll B) {
	while (A <= bm) {
		BIT[A] = max(BIT[A], B);
		A += A & -A;
	}
}
ll query(int A) {
	ll kotae = 0;
	while (A > 0) {
		kotae = max(BIT[A], kotae);
		A -= A & -A;
	}
	return kotae;
}

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

ll V[200000], tmp[200000];

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


	int R = getint(), C = getint(), K = getint();

	rep(i, K) {
		ll r = getint(), c = getint(), v = getint();
		V[i] = v << 30 | r << 12 | c;
	}

	const int b = 12;
	int kazu[1 << b] = {}, kazu2[1 << b] = {};
	rep(i, K) kazu[V[i] & ((1 << b) - 1)]++;
	rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
	for (int i = K - 1; i >= 0; i--) tmp[--kazu[V[i] & ((1 << b) - 1)]] = V[i];
	rep(i, K) kazu2[tmp[i] >> b & ((1 << b) - 1)]++;
	rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
	for (int i = K - 1; i >= 0; i--) V[--kazu2[tmp[i] >> b & ((1 << b) - 1)]] = tmp[i];

	int mae = -1;
	ll A[4] = {};
	ll L[3001];
	int l = 0;
	rep(k, K) {
		int v = V[k] >> 30;
		int i = V[k] >> 12 & 4095;
		int j = V[k] & 4095;
		if (mae != i) {
			mae = i;
			A[0] = 0;
			A[1] = 0;
			A[2] = 0;
			A[3] = 0;
			rep(a, l) add(L[a] & 4095, L[a] >> 12);
			l = 0;
		}
		ll kari = query(j);
		A[0] = kari;
		chmax(A[3], kari);
		chmax(A[2], kari);
		chmax(A[1], kari);
		chmax(A[3], A[2] + v);
		chmax(A[2], A[1] + v);
		chmax(A[1], A[0] + v);
		L[l++] = A[3] << 12 | j;
	}

	rep(a, l) add(L[a] & 4095, L[a] >> 12);
	ll kotae = query(C);

	printf("%lld\n", kotae);

	Would you please return 0;
}

Measured memory_bytes: 6496