akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

using namespace std;
string s[1000];
int main(){
	int h,w,i,j,a[30]={0};
	cin >> h >> w;
	for(i=0;i<h;i++){
		cin >>s[i];
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			a[s[i][j]-'a']++;
		}
	}
	
	int c = 0, d = 0;
	for(i=0;i<26;i++){
		if(a[i]%2){
			c++;
			a[i]--;
		}
		if(a[i]%4==2){
			d++;
		}
	}
	
	if(c!=h*w%2 || d > h%2*(w/2)+w%2*(h/2) || (h%2*(w/2)+w%2*(h/2)-d)%2==1){
		cout  << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int n,a,b,c;

int main(int argc, char const *argv[])
{
	long n,m;
	cin >> n >> m;
	long student[50][2];
	long chkpnt[50][2];

	REP(i,n){
		long x,y;
		cin >> x >> y;
		student[i][0] = x;
		student[i][1] = y;
	}

	REP(i,m){
		long x,y;
		cin >> x >> y;
		chkpnt[i][0] = x;
		chkpnt[i][1] = y;
	}

	REP(i,n){
		long min_dist = 800000000;
		long _student = 0;
		REP(j,m){
			long dist = 0;
			dist = abs(chkpnt[j][0] - student[i][0]) + abs(chkpnt[j][1] - student[i][1]);
			if(dist < min_dist){
				min_dist = dist;
				_student = j+1;
			}
		}
		cout << _student << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#if 0
f[i+1][j] = max( dp[i][j-k*weight[i+1]]+k*value[i+1] , dp[i-1][j])
					||
dp[j] = max( dp[j] , dp[j-weight[i]]+value[i] );							
#endif

#include <iostream>  
using namespace std;  
 
  
const int MAX_NUM = 100;  
const int MAX_WEIGHT = 10000;  

  
int weight[MAX_NUM];  
int value[MAX_NUM];  
 
int dp[MAX_WEIGHT];  
  

void Solve( int n, int w )  
{     
	for( int i=1; i<=n; i++ )  
	{  
		for( int j=1; j<=w; j++ )  
		{   
			if (weight[i] <= j){
				dp[j] = max(dp[j],dp[j-weight[i]]+value[i]);
			}        	         
		}  
	}  
	cout << dp[w] << endl;  
}  

int main()  
{    
	int n, w;  
	cin >> n >> w;        
	for( int i=1; i<=n; i++ )  
	{  
		cin >> value[i] >> weight[i];  
	}  
	Solve( n, w );  
 
	return 0;  
}  

Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int a;

int main(void){
	scanf("%d",&n);
	scanf("%d",&a);
	n%=500;
	printf("%s\n",n<=a?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
typedef long long ll;
const ll MOD=(ll)1e9+7;
ll qpow(ll a,ll b){return b?((b&1)?a*qpow(a*a%MOD,b>>1)%MOD:qpow(a*a%MOD,b>>1))%MOD:1;}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n,k;
    cin>>n>>k;
    cout<<qpow(k,n)<<endl;
}


Measured memory_bytes: 3176
#include<bits/stdc++.h>
using namespace std; 
#define mod 1000000007
#define N 100005
#define ll long long
#define ull unsigned long long
#define loop1(i, j, k, step) for (int i=j; i<k; i+=step)
#define loop(i, j, k) for (int i=j; i<k; i++) 
#define rloop1(i, j, k, step) for (int i=j; i>=k; i-=step)
#define rloop(i, j, k) for(int i=j; i>=k; i--)
#define rep(i, k) for(int i = (0); i < (k); i++ )
#define rrep(i, k) for(int i = k-1; i >= 0; i-- )

#define forall(it, l) for(auto it=l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define pop pop_back
#define F first
#define S second
#define sz(x) (int)(x).size()
#define endl "\n"
#define Max (int)INT_MAX
#define Min (int)INT_MIN
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;


void solve()
{ 
	ll a,b;
	cin>>a;
	string s;
	cin>>s;
	b=(s[0]-'0')*100 + (s[2]-'0')*10 + (s[3]-'0')*1;
	cout<<a*b/100<<endl;
}
int  main() 
{
	fast_io;
    int t=1;
    //cin>>t;
    while(t--)
    	solve();
	return 0; 
}

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

using namespace std;
int const N=1e5+5;
int freq[N];
int main()
{
    int num,sub;
    cin>>num>>sub;
    int AC=0,WA=0;
map <int,int> mp;
    for(int i=0;i<sub;i++)
    {
        int x;string s;
        cin>>x>>s;
        if(!mp[x])
        {
            if(s=="AC")
            {
                AC++;
                mp[x]=true;
            }
            else freq[x]++;

        }
    }
    for(int i=1;i<=num;i++)
    {
        if(mp[i])
            WA+=freq[i];
    }
    cout<<AC<<" "<<WA;

}


Measured memory_bytes: 5248
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int a[n],i,j,m;
    long s=0;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[i]>a[j])
            {
                m=a[i];
                a[i]=a[j];
                a[j]=m;
            }
        }
    }
    for(i=0;i<n;i++)
    {
        s=s+a[i];
    }
    printf("%d %d %ld\n",a[0],a[n-1],s);
    return 0;
}


Measured memory_bytes: 2100
function Main(input){
    var str = 'abcdefghijklmnopqrstuvwxyz';
    var arr =[];

    for(var i = 0, len = str.length; i < len; i++){
        if(input.indexOf(str[i]) < 0){
            arr.push(str[i]);
            continue;
        }
    }
    if(arr.length === 0){
        console.log('None');
    }else{
        arr.sort();
        console.log(arr[0]);
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {

  int a,b;
  cin >> a >> b;
  
  int x = b-a;
  int sum = 0;
  
  rep(i,x) sum += i;
  
  cout << sum-a << endl;
  
  
}


Measured memory_bytes: 256
#coding:utf-8
import bisect
n = int(input())
a = list(map(int, input().split()))
num = list(range(1, n+1))
dic = {key: val for key, val in zip(num, a)}
#print(dic)

result = sorted(dic.items(), key=lambda x:x[1])

ans = [i[0] for i in result] 
print(*ans)


Measured memory_bytes: 27808
#include "bits/stdc++.h"
using namespace std;

int main() {
	string S,T;
	cin >> S >>T; 
	int ans = 0;
	for (int n = 0;n< S.size();++n) {
		if (S[n] == T[n]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3652
using System;
using System.IO;
using System.Linq;

namespace Sort_II
{
    class Counting_Sort
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var B = new int[A.Length];
            var k = 10000;

            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            CountingSort(A, B, k);
            for (int i = 0; i < B.Length-1; i++)
                Console.Write(B[i] + " ");
            Console.WriteLine(B.Last());

            Console.Out.Flush();
        }

        static public void CountingSort(int[] A, int[] B, int k)
        {
            var C = new int[k+1];

            for (int i = 0; i < A.Length; i++)
                C[A[i]]++;

            for (int i = 1; i <= k; i++)
                C[i] += C[i - 1];

            for (int i = A.Length-1; i >= 0; i--)
            {
                C[A[i]]--;
                B[C[A[i]]] = A[i];
            }
        }
    }
}

Measured memory_bytes: 208720
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define Test(tt) cout << "Case #" << tt << ": "

using namespace std;

const int MAXN = (1 << 18);

int value[MAXN + 1], weight[MAXN + 1];
vector<pair<int, int>> qry[MAXN + 1];

vector<pair<ll, ll>> sums[20][2];
ll sol[MAXN + 1];

ll pref_mx[1 << 10];

void dfs(int nod, int lvl, int n) {

	if(nod > n) return;

	if(sums[lvl - 1][0].size() > sums[lvl - 1][1].size()) {
		swap(sums[lvl - 1][0], sums[lvl - 1][1]);
	}

	int sza = (int)sums[lvl - 1][0].size(), szb = (int)sums[lvl - 1][0].size();
	int a = 0, b = 0;
	while(a < sza || b < szb) {
		if(b == szb || (a < sza && sums[lvl - 1][0][a].second + weight[nod] <= sums[lvl - 1][0][b].second)) {
			sums[lvl][0].push_back({sums[lvl - 1][0][a].first + value[nod], 
									sums[lvl - 1][0][a].second + weight[nod]});
			a++;
		}
		else {
			sums[lvl][0].push_back(sums[lvl - 1][0][b]);
			b++;
		}
	}
	sums[lvl][1] = sums[lvl - 1][1];

	pref_mx[0] = sums[lvl][1][0].first;
	for(int i = 1; i < (int)sums[lvl][1].size(); i++) {
		pref_mx[i] = max(pref_mx[i - 1], sums[lvl][1][i].first);
	}

	for(auto it : qry[nod]) {
		int j = (int)sums[lvl][1].size() - 1;
		for(int i = 0; i < (int)sums[lvl][0].size(); i++) {
			while(j >= 0 && sums[lvl][0][i].second + sums[lvl][1][j].second > it.first) {
				j--;
			}
			if(j >= 0) {
				sol[it.second] = max(sol[it.second], sums[lvl][0][i].first + pref_mx[j]);
			}
		}
	}

	/*for(int i = 0; i < 2; i++) {
		for(auto it : sums[lvl][i]) {
			cerr << it.first << " " << it.second << "  ";
		}
		cerr << "\n";
	}
	cerr << "\n\n";*/
	
	dfs(2 * nod, lvl + 1, n);
	dfs(2 * nod + 1, lvl + 1, n);

	sums[lvl][0].clear();
	sums[lvl][1].clear();
}

int main() {
#ifdef HOME
    ifstream cin("B.in");
    ofstream cout("B.out");
#endif
   	int	i, n, q;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n;
    for(i = 1; i <= n; i++) {
    	cin >> value[i] >> weight[i];
    }
    cin >> q;
    for(i = 1; i <= q; i++) {
    	int nod, l;
    	cin >> nod >> l;
    	qry[nod].push_back({l, i});
    }

    sums[0][0].push_back({0, 0});
    sums[0][1].push_back({0, 0});

    dfs(1, 1, n);

    for(i = 1; i <= q; i++) {
    	cout << sol[i] << "\n";
    }
	
    return 0;
}

Measured memory_bytes: 15796
#include <stdio.h>
#define N 500000
#define INFTY 1000000001

void merge(int *, int, int, int);
void mergeSort(int *, int, int);

int count = 0;

int main(){
  int n = 0;
  int i = 0;
  int S[N];

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d",&S[i]);
  }

  mergeSort(S, 0, n);

  for(i = 0; i < n; i++){
    
    printf("%d",S[i]);
    if(i == n-1)printf("\n");
    else printf(" ");
    
  }

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

void merge(int *A, int left, int mid, int right){
  int n1 = 0, n2 = 0;
  int i = 0, j = 0, k = 0;
  int L[(N/2)+1], R[(N/2)+1];

  n1 = mid - left;
  n2 = right - mid;

  /*L[], R[]*/
  for(i = 0; i < n1; i++){
    L[i] = A[left + i];
  }

  for(i = 0; i < n2; i++){
    R[i] = A[mid + i];
  }

  /* 番兵 */
  L[n1] = INFTY;
  R[n2] = INFTY;

  i = 0;
  j = 0;

  for(k = left; k < right; k++){
    
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
      count++;
    }
    
    else{
      A[k] = R[j];
      j++;
      count++;
    }
    
  }

}

void mergeSort(int *A, int left, int right){
  int mid = 0;
  
  if(left+1 < right){
    
    mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
    
  }

}



Measured memory_bytes: 5672
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int id; };
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

vector<vector<edge>> g;
vector<int> ans;

void dfs(int v, int c = -1, int p = -1) {
  int k = 1;
  REP(i, g[v].size()) {
    int u = g[v][i].to, ei = g[v][i].id;
    if (u == p) continue;
    if (k == c) k++;
    ans[ei] = k;
    k++;
    dfs(u, ans[ei], v);
  }
}

int main() {
  IOS;
  int n; cin >> n;
  g.resize(n);
  ans.resize(n);
  REP(i,n-1) {
    int a,b;
    cin >> a >> b;
    a--; b--;
    g[a].push_back({b, i});
    g[b].push_back({a, i});
  }

  dfs(0);

  int mx = 0;
  REP(i,n) chmax(mx, (int)g[i].size());

  COUT(mx);
  REP(i,n-1) COUT(ans[i]);
  return 0;
}


Measured memory_bytes: 11088
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int>d(k);
  vector<bool>num(n,true);
  
  for(int i=0;i<k;i++){
    cin>>d[i];
    vector<int>tr(d[i]);
    for(int j=0;j<d[i];j++){
      cin>>tr[j];
      num[tr[j]-1]=false;
    }
  }
  int co=0;
  for(int i=0;i<n;i++){
    if(num[i]==true)co++;
  }
  cout<<co<<endl;
}
  

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <tuple>

using namespace std;

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define cina(s, n, a) for(int i = s; i < n; i++) cin >> a[i]
#define couta(n, a) for(int i = 0; i < n; i++) cout << a[i] << ' '
#define copy(s, n, a, b) for(int i = s; i < n; i++) b[i] = a[i]
#define yesno(ok) cout << (ok ? "YES" : "NO")
#define mod(a, b) (b + (a % b)) % b
#define MOD  (ll)1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

void solve(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    if(s[k - 1] < 'a') s[k - 1] += 32;
    cout << s;
}

int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int q = 1;
    //cin >> q;
    for(int i = 1; i <= q; i++){
        solve();
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i=0; i<n; i++){
        cin >> h.at(i);
    }
    
    sort(h.begin(), h.end());
    int ans = h.at(n-1);
    for(int i=0; i<n-k+1; i++){
        ans = min(h.at(i+k-1)-h.at(i), ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 764
/*
 * Author:  heyuhhh
 * Created Time:  2020/5/5 18:42:19
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;

void run() {
    int n, m; cin >> n >> m;
    vector <int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];   
    }
    vector <int> d(n);
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        --a, --b;
        if (h[a] >= h[b]) ++d[b];
        if (h[a] <= h[b]) ++d[a];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (d[i] == 0) ++ans;   
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll X, Y;
    cin >> X >> Y;
    ll ans = 0;
    ll cur = X;
    while (cur <= Y) {
        ++ans;
        cur *= 2;
    }
    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

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

using namespace std;

const int Mo = 1e9+7;

int n, m;
vector<int> v;

inline long long quickm(long long a, int p) // a^p%Mo
{
    long long res = 1;
    while(p)
    {
        if(p&1) res = res*a%Mo;
        a = a*a%Mo;
        p >>= 1;
    }
    return res;
}

inline long long mul_inverse(long long x)
{
    return quickm(x, Mo-2);
}

inline void Prime_factorization(int x, vector<int> &v)
{
    for(int i = 2, cnt; i <= x; ++i)
    {
        if(x%i) continue;
        cnt = 0;
        while(x%i == 0)
        {
            x /= i;
            cnt++;
        }
        v.emplace_back(cnt);
    }
    if(x > 1) v.emplace_back(x);
}

inline long long comb(int a, int b) // C_a^b
{
    if(b == 0) return 1;
    long long p = 1, q = 1;
    for(int i = 1; i <= b; ++i)
    {
        p = p*a%Mo; a--;
        q = q*i%Mo;
    }
    return p*mul_inverse(q)%Mo;
}

int main()
{
    cin >> n >> m;
    Prime_factorization(m, v);
    long long ans = 1;
    for(int i : v)
        ans = ans*comb(i+n-1, min(i, n-1))%Mo;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef enum {false, true} bool;

int main(void)
{
    int N, M;
    int x[101], y[101];
    int i, j;
    char c;
    bool flag = true;
    
    scanf("%d %d %d %d", &N, &M, &x[0], &y[0]);
    
    
    for(i=1; i<=N; i++)
    {
        scanf("%d%c", &x[i], &c);
    }
    
    for(i=1; i<=M; i++)
    {
        scanf("%d%c", &y[i], &c);
    }
    
    for(i=0; i<=N; i++)
    {
        for(j=0; j<=M; j++)
        {
            if(x[i]>=y[j])
            {
                flag = false;
                break;
            }
        }
        if(!flag)
            break;
    }
    
    
    if(!flag)
        printf("War\n");
    else
        printf("No War\n");
    
    //system("pause");
    
    return 0;
}


Measured memory_bytes: 128
def gcd(a, b)
  a, b = b, a if a < b
  _mod = a % b
  if _mod.zero?
    b
  else
    gcd(b, _mod)
  end
end

def lcm(a, b)
  a * b / gcd(a, b)
end

def mod_until_one(a, m)
  dot = -1
  count = 0
  while dot != 1
    dot = 1 if dot == -1
    dot = (a * dot) % m
    count += 1
  end
  count
end

def electro_fly(fly_data)
  count1, count2, count3 = (0..4).step(2).map{ |i| fly_data[i,2] }.map{ |d| mod_until_one(*d) }
  lcm(lcm(count1, count2), count3)
end

loop do
  fly_data = gets.chomp.split.map(&:to_i)
  break if fly_data.all?(&:zero?)
  puts electro_fly(fly_data)
end

Measured memory_bytes: 6128
#pragma comment(linker,"/STACK:36777216")

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <limits>
#include <ctime>
#include <cassert>
#include <map>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <stack>
#include <queue>
#include <numeric>
#include <iterator>
#include <bitset>
#include <unordered_map>
#include <unordered_set>

using namespace std;
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())
#define ten(n) ((int)1e##n)
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;


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

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
ll mod_pow(ll a, ll n, ll mod) {
	ll ret = 1;
	ll p = a % mod;
	while (n) {
		if (n & 1) ret = ret * p % mod;
		p = p * p % mod;
		n >>= 1;
	}
	return ret;
}
template<class T> T extgcd(T a, T b, T& x, T& y) { for (T u = y = 1, v = x = 0; a;) { T q = b / a; swap(x -= q * u, u); swap(y -= q * v, v); swap(b -= q * a, a); } return b; }
template<class T> T mod_inv(T a, T m) { T x, y; extgcd(a, m, x, y); return (m + x % m) % m; }

const int MOD = ten(9) + 7;

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

    ll ret = 0;
    ll l = 1;
    vector<Pll> vp;
    while (l <= n){
        ll k = n / l;
        ll r = n / k;
        //[l,r]
        vp.emplace_back(l, r - l + 1);
        l = r + 1;
    }

    vector<ll> pv(sz(vp)), cr(sz(vp));
    pv[0] = 1;
    FOR(i,k) {
        int idx = -1;
        ll sm = 0;
        for(int j = sz(vp) - 1; j >= 0; j--) {
            ll base = vp[j].first;
            while (idx < sz(vp) - 1 && vp[idx+1].first * base <= n) {
                idx++;
                sm += pv[idx];
            }
            sm %= MOD;
            cr[j] = vp[j].second * sm % MOD;
        }
        swap(pv, cr);
        cr.clear();
    }
    ll ans = 0;
    FOR(i, sz(vp)) ans += pv[i];
    cout << ans % MOD << endl;

	return 0;
}


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

using namespace std;

const int ms = 100;
long long arr[ms];

long long fillarr(int n)
{
    arr[0] = 2;
    arr[1] = 1;

    for(int i = 2; i <= n; ++i)
    {
        arr[i] = arr[i - 1] + arr[i - 2];
    }

    return arr[n];
}

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

    cout << fillarr(n);

}


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

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

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

Measured memory_bytes: 1156
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
from fractions import gcd

NN = 202020
MOD = 10**9+7
INF = float("inf")

n, d, a = map(int, input().split())

monsters = []
for i in range(n):
    x, h = map(int, input().split())
    monsters.append((x, h))

monsters.sort()

attack = 0
que = deque([])
attack_num = 0

for monster in monsters:
    xx, hh = monster
    while que and que[0][0] < xx - d:
        attack -= que[0][1]
        que.popleft()

    # print("a", x, h, attack, que)

    if hh - attack <= 0:
        continue

    a_times = (hh - attack - 1) // a + 1
    attack_num += a_times
    attack += a_times * a
    que.append((xx + d, a_times * a))

    # print("b", attack, attack_num, que)

print(attack_num)

Measured memory_bytes: 97620
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

bool is_prime(const unsigned n) {
  switch(n) {
  case 0: // fall-through
  case 1: return false;
  case 2: // fall-through
  case 3: return true;
  } // n > 3 が保証された
  if(n % 2 == 0) return false;
  if(n % 3 == 0) return false;
  if(n % 6 != 1 && n % 6 != 5) return false;
  for(unsigned i=5; i*i<=n; i+=6) {
    if(n % i     == 0) return false; // 6n-1
    if(n % (i+2) == 0) return false; // 6n+1
  }
  return true;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int q; cin >> q;
  vector<int> cnt(100001);
  for(int i=1; i<=100000; i++) {
    cnt[i] = cnt[i-1];
    if(is_prime(i) && is_prime((i+1)/2)) cnt[i]++;
  }
  rep(_, q) {
    int l, r; cin >> l >> r;
    cout << cnt[r]-cnt[l-1] << endk;
  }
  return 0;
}


Measured memory_bytes: 3724
#include "bits/stdc++.h"
//#include "atcoder/all"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
//using namespace atcoder;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	sort(a.rbegin(), a.rend());
	ll ans = 0;
	rep(i,n){
		if(i%2 == 0) ans += a[i];
		else ans -= a[i];
	}
	cout << ans << endl;
	return 0;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

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

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

template <typename Monoid>
struct SegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;

    int size = 1;
    vector<Monoid> node;

    const F f;
    const Monoid e;

    SegmentTree(int n, const F f, const Monoid &e) : f(f), e(e) {
        while (size < n) size <<= 1;
        node.assign(2 * size, e);

        for (int i = size - 2; i >= 0; i--) {
            node[i] = f(node[2 * i + 1], node[2 * i + 2]);
        }
    }

    SegmentTree(vector<Monoid> vec, const F f, const Monoid &e) : f(f), e(e) {
        int n = (int)vec.size();
        while (size < n) size <<= 1;
        node.assign(2 * size, e);

        for (int i = 0; i < n; i++) {
            node[i + size - 1] = vec[i];
        }

        for (int i = n - 2; i >= 0; i--) {
            node[i] = f(node[2 * i + 1], node[2 * i + 2]);
        }
    }

    inline void set(int i, const Monoid &x) { node[i + size - 1] = x; }

    inline void update(int i, const Monoid &x) {
        i += (size - 1);

        node[i] = x;

        while (i > 0) {
            i = (i - 1) / 2;
            node[i] = f(node[2 * i + 1], node[2 * i + 2]);
        }
    }

    Monoid query(int a, int b, int i = 0, int l = 0, int r = -1) {
        if (r < 0) r = size;

        if (r <= a || b <= l) return e;

        if (a <= l && r <= b) return node[i];

        Monoid xl = query(a, b, 2 * i + 1, l, (l + r) / 2);
        Monoid xr = query(a, b, 2 * i + 2, (r + l) / 2, r);

        return f(xl, xr);
    }
};

int main() {
    int N, Q;
    string S;
    cin >> N >> S >> Q;
    SegmentTree<int> seg(
        N, [](int a, int b) { return a | b; }, 0);

    REP(i, N) {
        seg.update(i, 1 << (S[i] - 'a'));
    }

    REP(i, Q) {
        int t;
        cin >> t;
        if (t == 1) {
            int i;
            char c;
            cin >> i >> c;
            seg.update(i - 1, 1 << (c - 'a'));
        } else {
            int l, r;
            cin >> l >> r;
            int res = seg.query(l - 1, r);
            cout << bitset<32>(res).count() << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4996
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=200010;
int a[N],b[N],id[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline bool cmp(const int &x,const int &y) {return a[x]<a[y];}
int main() {
    int n,A=1<<30,B=0,C=1<<30,D=0;
    cin>>n;
    for(int i=1;i<=n;i++) {
	a[i]=gi(),b[i]=gi(),id[i]=i;
	if(a[i]>b[i]) swap(a[i],b[i]);
    }
    for(int i=1;i<=n;i++) {
	A=min(A,a[i]),B=max(B,a[i]);
	C=min(C,b[i]),D=max(D,b[i]);
    }
    long long ans=1LL*(B-A)*(D-C);
    A=max(B,D)-min(A,C);
    sort(id+1,id+1+n,cmp);
    a[0]=C=1<<30,D=a[id[n]];
    for(int i=1;i<=n;i++) {
	C=min(C,b[id[i]]),D=max(D,b[id[i]]);;
	ans=min(ans,1LL*A*(D-min(C,a[id[i+1]])));
    }
    cout<<ans;
    return 0;
}

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


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (int i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (int i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

using namespace std;
inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; } 
inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;

int main () {               
    char c;
    cin >> c;
    if (c == 'A') cout << 'T';
    else if (c == 'T') cout << 'A';
    else if (c == 'C') cout << 'G';
    else cout << 'C';
    return Accepted;
}

// B...a D....

Measured memory_bytes: 18688
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int a, b;
    cin >> a >> b;
    a--; b--;
    int s[3];
    s[a] = 1;
    s[b] = 1;
    rep(i, 3){
        if (s[i] != 1) cout << (i+1) << endl;
    }
    return 0;
}

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

int main(){
    int T[101][101],r,c;
    
    cin >> r >> c;
    for(int i=0; i<r; i++)
        for(int j=0; j<c; j++) cin>>T[i][j];
    
    for(int i=0; i<=r; i++) T[i][c]=0;
    for(int j=0; j<=c; j++) T[r][j]=0;
    
    for(int i=0; i<r; i++){
        for(int j=0; j<c; j++){
            T[i][c] += T[i][j];
            T[r][j] += T[i][j];
            T[r][c] += T[i][j];
        }
    }
    
    for( int i=0; i<=r; i++){
        for( int j=0; j<=c; j++){
            if(j) cout << " ";
            cout << T[i][j];
        }
        cout << endl;
    }
    return 0;
    
}


    
    


Measured memory_bytes: 3140
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t m1,d1,m2,d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if(m1 != m2){
        cout << "1" << endl;
    }else{
        cout << "0" << endl;
    }
}


Measured memory_bytes: 256
use std::vec::Vec;

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

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

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
  let n: usize = read();
  
  if n % 2 == 0 {
     println!("{}", 0.5);
  } else {
    let ans = (n/2 + 1) as f64 / n as f64;
    println!("{}", ans);
  }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define pb push_back
#define mkp make_pair
#define llu unsigned long long int
#define ll long long
#define ld long double
#define foi(a,n) for(int i = a; i < n; i++)
#define foj(a,n) for(int j = a; j < n; j++)
#define foin(a,n) for(int i = n; i >= a; i--)
#define fojn(a,n) for(int j = n; j >= a; j--)
#define isp2(x) x&&(!(x&(x-1)))
#define ee 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define cases long long t;cin>>t;while(t--)

using namespace std;

int n, k;
int a[100002], w[1000];
ll dp[100001][100];

ll go(int x, int i){
	if(i == n-1 && w[i] <= x){
		return a[i];
	}
	if(x == 0 || i == n - 1){
		return 0;
	}
	if(dp[x][i] != -1){
		return dp[x][i];
	}
	if(w[i] <= x){
		return dp[x][i] = max((ll)a[i] + (ll)go(x - w[i], i+1), (ll)go(x, i+1));
	}
	return dp[x][i] = (ll)go(x, i+1);
}
		

int main() {
    ll q, m, x, y, d; 
    string s, h;
	cin >> n >> k; 
	foi(0, n) {
		cin >> w[i] >> a[i];
	}
	foi(0, 100001){
		foj(0, 100){
			dp[i][j] = -1;
		}
	}
	
	cout << go(k, 0);

}




Measured memory_bytes: 81764
n = int(input())
s = []

for i in range(n):
    s.append(input())

word_buf = {}

for i in s:
    if i in word_buf.keys():
        word_buf[i] += 1
    else:
        word_buf[i] = 1

max_cnt = max(word_buf.values())
max_word = [i[0] for i in word_buf.items() if i[1] == max_cnt]
max_word.sort()

for i in max_word:
    print(i)

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

int main(){
  int A,B;
  cin >> A >> B;
  cout << (A-1)*(B-1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int count = 0;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A') {
      count = i;
      break;
    }
  }
  reverse(s.begin(), s.end());
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'Z') {
      count = s.size() - count - i;
      break;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int Coin = sc.nextInt();

		//入力したコインを500で割る
		int coin500 = Coin / 500;
		//入力したコインを5で割る
		int coin5 = (Coin % 500) / 5;

		//結果
		int Coinsum = coin500 * 1000 + coin5 * 5;
		System.out.println(Coinsum);

		sc.close();

	}

}


Measured memory_bytes: 35448
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define bit(k) (1LL<<(k))
typedef long long ll;

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

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

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

/*------------------------------------/
for library*/

/*------------------------------------*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    char a,b;
    cin>>a>>b;
    if(a == b){
        cout<<"="<<endl;
    }else if(a > b){
        cout<<">"<<endl;
    }else{
        cout<<"<"<<endl;
    }
}

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

using namespace std;

const int N = 2e5 + 5;
const int M = 1e6 + 9;
const long long INF = 1e9 + 7;
const int SM = 1e3 + 4;
const double EPS = 3e-16;
const int K = 25;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int n, K; cin >> n >> K;
    
    vector<int> a(n), dp(n, INF);
    for(auto &i : a) cin >> i;
    
    
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    for(int i = 2; i < n; i++){
        for(int k = 0; k <= K; k++){
            if(i - k >= 0) dp[i] = min(dp[i], dp[i - k] + abs(a[i] - a[i - k]));
            else break;
        }
    }
    
    cout << dp[n - 1];
    return 0;
}

Measured memory_bytes: 1024
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;

void main() {
    int n, k;
    scan(n, k);

    auto w = new int[][][](2, k, k);

    foreach (i ; 0 .. n) {
        int xi, yi;
        char ci;
        scan(xi, yi, ci);

        if (ci == 'B') yi += k;

        int e = (xi / k % 2 + yi / k % 2) % 2;
        w[e][xi % k][yi % k]++;
    }

    foreach (e ; 0 .. 2) {
        foreach (i ; 0 .. k) {
            foreach (j ; 1 .. k) {
                w[e][i][j] += w[e][i][j-1];
            }
        }

        foreach (j ; 0 .. k) {
            foreach (i ; 1 .. k) {
                w[e][i][j] += w[e][i-1][j];
            }
        }
    }

    int ans;

    foreach (i ; 0 .. k) {
        foreach (j ; 0 .. k) {
            int t = w[0][k-1][k-1] - w[0][k-1][j] - w[0][i][k-1] + 2*w[0][i][j];
            int s = w[1][i][k-1] + w[1][k-1][j] - 2*w[1][i][j];

            ans = max(ans, t + s);
            ans = max(ans, n - t - s);
        }
    }

    writeln(ans);
}




void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 11132
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
	int N, A, dummy;
	dummy = scanf("%d %d", &N, &A);

	vector<int> vi;
	map<int, long long> mi[51];

	int tmp1;
	int last = 0;
	for (int i = 0; i < N; i++) {
		dummy = scanf("%d", &tmp1);
		if (tmp1 - A != 0) {
			vi.push_back(tmp1 - A);
		} else {
			last++;
		}
	}

	N -= last;

	mi[0][0]++;

	for (int i = 1; i <= N; i++) {
		auto itr = mi[i - 1].begin();
		auto end = mi[i - 1].end();
		for (; itr != end; itr++) {
			mi[i][itr->first] += itr->second;
			mi[i][itr->first + vi[i - 1]] += itr->second;
		}
	}
	
	long long ans = mi[N][0];

	ans = ans << last;

	printf("%lld\n", ans - 1);
	
	return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#define mod 1000000007
typedef long long ll;
using namespace std;

class UnionFind {
public:
    vector <ll> par; 
    vector <ll> siz; 


    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL); 
        for (ll i = 0; i < sz_; ++i) par[i] = i; 
    }

    
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]]; 
        }
        return x;
    }

  
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;

        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { 
        return root(x) == root(y);
    }

    ll size(ll x) { 
        return siz[root(x)];
    }
};

int frenum[100005]; // 直接友達関係の数
int bro[100005]; // 同じ連結成分でブロック関係にあるが直接友達ではない人の数
// int fre[100005];
// int bro[100005];

int main(){
  int n,m,k; cin >> n >> m >> k;
  UnionFind tree(n);
  vector<set<int>> fre(n); // 人iと直接友達関係の人を記録
  for(int i=0;i<m;i++){
    int a,b; cin >> a >> b;
    a--; b--;
    frenum[a]++;
    frenum[b]++;
    tree.merge(a,b);
    fre[a].insert(b);
    fre[b].insert(a);
  }
  for(int i=0;i<k;i++){
    int c,d; cin >> c >> d;
    c--; d--;
    if(tree.issame(c,d)){
      // 連結成分内でブロック関係にあり、かつ直接友達でなければ重複することなく引くことができる
      // 直接友達でもあったならばここでは引く必要がない
      if(!(fre[c].count(d))) bro[c]++;
      if(!(fre[d].count(c))) bro[d]++;
    }
  }
  for(int i=0;i<n;i++){
    ll ans = tree.size(i) - frenum[i] - bro[i] - 1;
    if(i > 0) cout << " ";
    cout << ans;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 17280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s; s += s[0] + s[1] + s[2];
    vector<int> t;
    t = {1, 1};
    for (int i = 2; i <= n; i++) {
        if (t[i - 1]) {
            if (s[i - 1] == 'o') t.push_back(t[i - 2]);
            else t.push_back(!t[i - 2]);
        } else {
            if (s[i - 1] == 'o') t.push_back(!t[i - 2]);
            else t.push_back(t[i - 2]);
        }
    }
    if (t[0] == t[n] && ((s[0] == 'o') ^ t[0]) == (t[1] != t[n - 1])) {
        for (int i = 0; i < n; i++) {
            if (t[i]) cout << 'S';
            else cout << 'W';
        }
        return 0;
    }
    t = {1, 0};
    for (int i = 2; i <= n; i++) {
        if (t[i - 1]) {
            if (s[i - 1] == 'o') t.push_back(t[i - 2]);
            else t.push_back(!t[i - 2]);
        } else {
            if (s[i - 1] == 'o') t.push_back(!t[i - 2]);
            else t.push_back(t[i - 2]);
        }
    }
    if (t[0] == t[n] && ((s[0] == 'o') ^ t[0]) == (t[1] != t[n - 1])) {
        for (int i = 0; i < n; i++) {
            if (t[i]) cout << 'S';
            else cout << 'W';
        }
        return 0;
    }
    t = {0, 1};
    for (int i = 2; i <= n; i++) {
        if (t[i - 1]) {
            if (s[i - 1] == 'o') t.push_back(t[i - 2]);
            else t.push_back(!t[i - 2]);
        } else {
            if (s[i - 1] == 'o') t.push_back(!t[i - 2]);
            else t.push_back(t[i - 2]);
        }
    }
    if (t[0] == t[n] && ((s[0] == 'o') ^ t[0]) == (t[1] != t[n - 1])) {
        for (int i = 0; i < n; i++) {
            if (t[i]) cout << 'S';
            else cout << 'W';
        }
        return 0;
    }
    t = {0, 0};
    for (int i = 2; i <= n; i++) {
        if (t[i - 1]) {
            if (s[i - 1] == 'o') t.push_back(t[i - 2]);
            else t.push_back(!t[i - 2]);
        } else {
            if (s[i - 1] == 'o') t.push_back(!t[i - 2]);
            else t.push_back(t[i - 2]);
        }
    }
    if (t[0] == t[n] && ((s[0] == 'o') ^ t[0]) == (t[1] != t[n - 1])) {
        for (int i = 0; i < n; i++) {
            if (t[i]) cout << 'S';
            else cout << 'W';
        }
        return 0;
    }
    cout << -1;
}


Measured memory_bytes: 1020
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,T,c,t,i;
    cin>>n>>T;
    int ans=1001;
    for (i=0;i<n;i++)
    {
        cin>>c>>t;
        if (t<=T)
            ans=min(ans,c);
    }
    if (ans==1001)
        cout<<"TLE\n";
    else
        cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fst first
#define snd second
const ll mod = 1000000007;
const ll INF = mod * mod;

int main(){
	ll n;
	ll a[100010];
	bool m[100010];
	ll dp[100010][3];

	cin >> n;
	m[0] = 0;
	cin >> a[0];
	for (int i = 1; i < n; i++) {
		char c;
		cin >> c;
		if (c == '+')m[i] = false;
		else m[i] = true;
		cin >> a[i];
	}
	dp[0][0] = a[0]; dp[0][1] = -INF; dp[0][2] = -INF;
	for (int i = 1; i < n; i++) {
		if (m[i]) {
			dp[i][0] = -INF;
			dp[i][1] = -a[i] + max(dp[i - 1][1], dp[i - 1][0]);
			if (dp[i - 1][1] != -INF || dp[i - 1][2] != -INF) {
				dp[i][2] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
			}
			else {
				dp[i][2] = -INF;
			}
		}
		else {
			dp[i][0] = a[i] + max(dp[i - 1][0], dp[i - 1][1]);
			dp[i][1] = -a[i] + dp[i-1][1];
			if (dp[i - 1][2] != -INF) {
				dp[i][2] = a[i] + dp[i - 1][2];
			}
			else {
				dp[i][2] = -INF;
			}
		}
	}
	ll ans = dp[n - 1][2];
	ans = max(ans, dp[n - 1][1]);
	ans = max(ans, dp[n - 1][0]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3456