akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int N; cin >> N;
  vector<string> S(N);
  rep(i,N) cin >> S[i];
  map<string,int> mp;
  rep(i,N){
    mp[S[i]]++;
  }
  int maxi = 1;
  for(auto m:mp){
    maxi = max(maxi,m.second);
  }
  for(auto m:mp){
    if(m.second == maxi){
      cout << m.first << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 26752
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
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;
}
int main(){
    ll n;cin >> n;
    vl v(100010,0);
    ll ans=1;
    v[0]=3;
    rep(i,n){
        ll a;cin >> a;
        a++;
        if(v[a]-v[a-1]==-3){
            ans*=3;
            ans%=MOD;
            v[a]++;
            continue;
        }
        if(v[a]-v[a-1]==-2){
            ans*=2;
            ans%=MOD;
            v[a]++;
            continue;
        }
        if(v[a]-v[a-1]==-1){
            v[a]++;
            continue;
        }
        cout << 0 <<endl;
        return 0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>

using namespace std;
typedef long long ll;
#define pl pair<ll,ll>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second

int main(){
	ll a,b;
	cin>>a>>b;
	vector<ll> v(14);
	FOR(i,2,14){
		v[i]=i-1;
	}
	v[1]=13;
	if(v[a]>v[b]){
		cout<<"Alice"<<endl;
	}else if(a==b){
		cout<<"Draw"<<endl;
	}else{
		cout<<"Bob"<<endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pi 3.1415926536
#define pb push_back
#define N 1000000007
#define M 998244353
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,i,m,j,x,y,k;
    cin>>n>>m;
    x = n*m/(__gcd(n,m));
    cout<<x;
}

Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

bool greater_(pair<string, int>& a, pair<string, int>& b)
{
	return a.second > b.second;
}

int main()
{
	int N;
	map<string, int> S;

	cin >> N;

	rep(i, N)
	{
		string s;
		cin >> s;

		S[s]++;
	}

	vector<pair<string, int>> V(S.begin(), S.end());
	sort(V.begin(), V.end(), greater_);

	vector<string> s;

	auto v = V.begin();
	int max = v->second;

	while (v != V.end())
	{
		if (v->second != max) break;

		s.emplace_back(v->first);
		v++;
	}

	sort(s.begin(), s.end());

	rep(i, s.size())
		cout << s[i] << endl;

	return 0;
}

Measured memory_bytes: 30068
import java.lang.Math

fun main(args: Array<String>)
{
    val n = readLine()!!.toInt()
    val p = mutableListOf<Pair<Double, Double>>()
    for (i in 0 until n) {
        val (x, y) = readLine()!!.split(" ").map{it.toDouble()}
        p.add(Pair<Double, Double>(x, y))
    }

    val dist = mutableListOf<Double>()
    for (i in 0 until n-1) {
        for (k in i+1 until n) {
            val dx = p[i].first - p[k].first
            val dy = p[i].second - p[k].second
            val d = Math.sqrt(dx * dx + dy * dy)
            dist.add(d)
        }
    }

    var sum = 0.0
    for (i in 0..dist.lastIndex) sum += dist[i]

    println(sum * 2.0 / n.toDouble())
}


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


void solve(long long A, long long B){
    printf("%lld\n",A*B);
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

int main(void) {
 
    int N,K;
    string D[10];
    cin >> N >> K;
    for(int i=0;i<K;i++)
    {
        cin >> D[i];
    }

    int ans;
    for(int i=N;i<=10*N;i++)
    {
        ans = i;
        string tmp = to_string(ans);
        int chk = 0;
        for(int j=0;j<K;j++)
        {
            if (tmp.find(D[j]) != std::string::npos)
            {
                chk++;
                break;
            }
        }
        if (chk == 0) break;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
using namespace std;
#include<algorithm>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define Max(a,b) max(a,b)
#define Min(a,b) min(a,b)
#define INF 1e9
#define LINF 1e17
#define ll long long
#define MOD (int)(1e9+7)

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



int main(){
    
    int a,b,c;
    
    cin>>a>>b>>c;
    if((10*b+c)%4==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
        
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N, K;
  cin >> N >> K;
  char pr = ' ';
  int gr = 0;
  for (int i = 0; i < N; i ++) {
    char c;
    cin >> c;
    if (pr != c) gr ++;
    pr = c;
  }
  int m_gr = max(1, gr - K * 2);
  cout << N - m_gr << endl;
}

Measured memory_bytes: 3592
N=int(input())
for h in range(1,3501):
    for w in range(1,3501):
        if (4*h*w-N*(h+w))>0 and N*h*w%(4*h*w-N*(h+w))==0  :print(h,w,N*h*w//(4*h*w-N*(h+w)));exit()

Measured memory_bytes: 9196
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int n,k,a[200000];
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=k;i<n;i++)
        cout<<(a[i]>a[i-k]?"Yes":"No")<<endl;
}


Measured memory_bytes: 5184
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  string s;
  cin>>s;
  int y = stoi(s.substr(0,4)),m=stoi(s.substr(5,2)),d=stoi(s.substr(8,2));
  if(y<2019){
    cout<<"Heisei\n";
  }
  else if(y==2019 && m<=4){
    cout<<"Heisei\n";
  }
  else cout<<"TBD\n";
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
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;}
const int MOD = 1000000007;

int main() {
    string s;
    cin >> s;
    bool c = false;
  	REP(i, s.size()) {
        if (!c) {
            if (s[i] == 'C') {
                c = true;
            }
        } else {
            if (s[i] == 'F') {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;    
}



Measured memory_bytes: 256
function main(input){
    var tmp = input.split(" ");
    var x = Number(tmp[0]);
    var a = Number(tmp[1]);
    var b = Number(tmp[2]);

    if(Math.abs(x-a) < Math.abs(x-b))
        console.log("A");
    else
        console.log("B");
}

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

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
const int64_t INF=9999999999999999;
int main() {
 string S;
 cin>>S;
 int count0=0;
 for(int i=0;i<S.size();i++){
    if(S[i]=='0'){count0++;}
 }
 int count1=S.size()-count0;
 cout<<min(count1,count0)*2<<endl;
 return 0;}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    int a[n];
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    double b;
    for(i=0; i<n; i++)
    {
        b+=(1.0/a[i]);
    }
    cout<<1/b<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long long LL;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL N;
	VLL X, L;
	cin >> N;
	X.resize(N);
	L.resize(N);
	for (LL n = 0; n < N; n++) {
		cin >> X[n] >> L[n];
	}
	vector<pll> tasks(N);
	for (LL n = 0; n < N; n++) {
		tasks[n] = pll(X[n] - L[n], X[n] + L[n]);
	}
	sort(tasks.begin(), tasks.end(), [](pll a, pll b) {
		return a.second < b.second;
	});
	LL start = -1e10;
	LL ans = 0;
	for (LL n = 0; n < N; n++)
	{
		if (start <= tasks[n].first) {
			start = tasks[n].second;
			ans++;
		}
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3456
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<float.h>
using namespace std;


int main() {
    int  a;
    cin >> a;
    int b = (a - a / 100*100) / 10;
    int c = a % 10;
        a = a / 100;
    cout << a+b+c << endl;
  
    return 0;
}

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

const int inf = 1e5;
int dp[101][101];

signed main () {
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    string t1, t2;
    for (int i = 0; i < a; ++i) {
        t1 += '1';
        t2 += '0';
    }
    for (int i = 0; i < w - a; ++i) {
        t1 += '0';
        t2 += '1';
    }
    for (int i = 0; i < b; ++i)
        cout << t1 << '\n';
    for (int i = 0; i < h - b; ++i) 
        cout << t2 << '\n';
}


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

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

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  i64 n;
  cin >> n;
  vi64 v(5);
  rep(i, 5) cin >> v[i];
  sort(all(v));
  i64 mn = v[0];
  i64 ans = (n + (mn - 1)) / mn + 4;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
string s;
int main()
{
	cin>>s;
	int k;
	scanf("%d",&k);
	int cnt=1,flag=1,cnt1=1;
	int len=s.length();
	s+='!';
	ll ans=0;
	for(int i=0;i<len;i++)
	{
		if(s[i]==s[i+1])
		{
			cnt++;
			if(flag==1)
				cnt1++;
		}
		else
		{
			ans+=cnt/2;
			flag=0;
			if(i!=len-1)
				cnt=1;
		}
	}
	if(cnt==len)
	{
		ans=1;
		ans*=len;
		ans*=k;;
		ans/=2;
	}
	else
	{
	ans=k*ans;
	if(cnt%2&&cnt1%2&&s[len-1]==s[0])
	{
		ans+=k-1;
	}
	}
	printf("%lld\n",ans);
	//system("pause");
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////



int main(){
    int n,x,y;
    cin >> n >> x >> y;
    x--;y--;
    
    ll ans[n-1] = {};

    rep(i,0,n-1){
	rep(j,i+1,n){
	    if(i <= x && y <= j){
		ans[j-i-1 - (y-x) + 1]++;
	    }else if(i <= x && x < j &&  j <= y){
		ans[min(j-i-1,x-i+1+(y-j)-1 )]++;
		
	    }else if(x <= i &&  y <= j ){
		ans[min(j-i-1,i-x+1+(j-y) -1 )]++;
		
	    }else if(x <= i && j <= y){
		ans[min(j-i-1,i-x+1+(y-j) -1 )]++;
	    }else{
		ans[j-i-1]++;
	    }
	}
    }
    rep(i,0,n-1)P(ans[i]);
    return  0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:16777216")
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>  
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <bitset>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(A,value) memset(A,value,sizeof(A))

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
const double PI=acos(-1.0);

typedef long long Int;
typedef long long LL;
typedef unsigned long long UINT;
typedef vector <int> VI;
typedef pair <int, int> PII;
typedef pair <double, double> PDD;

const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 6007;
const int MAX2 = 12007;
const int LEN = 21;
const int BASE = 1000000000;

const int ADD = 6002;

int n, MOD;
Int R[MAX][MAX2];

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

  R[0][ADD] = 1;
  
  FOR (i,1,n*3+1)
    FOR (j,0,MAX2)
    {
      FOR (k,1,4)
      {
        int jj = j;
        if (k == 1) ++ jj;
        if (k == 2) -- jj;
        if (i >= k && jj >= 0 && jj < MAX2)
        {
          Int d = 1;
          if (k > 1) d *= (i-1);
          if (k > 2) d *= (i-2);
          R[i][j] = (R[i][j] + R[i-k][jj] * d) % MOD;
        }
      }
    }

  Int res = 0;
  FOR (i,0,ADD+1)
    res = (res + R[n*3][i]) % MOD;

  cout << res << endl;

  
  
  return 0;
}


Measured memory_bytes: 563328
s = list(input())
t = list(input())

s.sort()

#リストを逆順に並び替え
t.sort(reverse=True)

#要素を、１つの文字列にする。
s = ''.join(s)
t = ''.join(t)

#print(s)
#print(t)

if s < t :
	print('Yes')
else:
	print('No')


Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String B = scan.next();
        char[] d = B.toCharArray();
        boolean answer = true;
        int count_upper = 0;
        int count_c = 0;
        int count_c_range = 0;
        for (int i = 0; i < d.length; i++) {
            if (d[i] == 'C') {
                count_c += 1;
            }
            if (i == 0) {
                if (d[i] != 'A') {
                    answer = false;
                    break;
                }
            }
            if (2 <= i && i <= d.length - 2) {
                if (d[i] == 'C') {
                    count_c_range += 1;
                }
            }
            if (0 <= d[i] - 'A' && d[i] - 'A' <= 25) {
                count_upper += 1;
            }
        }
        if (count_c_range != 1 || count_c_range != count_c) {
            answer = false;
        }
        if (count_upper != 2) {
            answer = false;
        }
        System.out.println(answer ? "AC" : "WA");
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <queue>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

int main()
{
    int x,y,z;
    cin >> x >> y >> z;

    int sumSpace = z;
    int sitPeopleNum = 0;
    while (true)
    {
        sumSpace += y + z;
        if (sumSpace > x)
        {
            break;
        }
        sitPeopleNum++;
    }
    
    cout << sitPeopleNum << endl;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 61)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, k, a[202020], d[202020];
void solve(){
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	for(int i = 0; i < k; i++){
		fill(d,d+202020, 0);
		for(int j = 0; j < n; j++){
			d[max(0, j-a[j])]++;
			d[min(n, j+a[j]+1)]--;
		}
		for(int j = 0; j < n; j++){
			a[j] = d[j];
			d[j+1] += d[j];
		}
		
		bool ok = 1;
		for(int j = 0; j < n; j++){
			if(a[j] != n) ok = 0;
		}
		if(ok) break;
	}
	for(int i = 0; i < n; i++){
		cout << a[i] << " ";
	}
	cout << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 5152
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sparsh Sanchorawala
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CDiceAndCoin solver = new CDiceAndCoin();
        solver.solve(1, in, out);
        out.close();
    }

    static class CDiceAndCoin {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            int n = s.nextInt(), k = s.nextInt();
            double num = 0;
            for (int i = 1; i <= n; i++) {
                int c = 0;
                int curr = i;
                while (curr < k) {
                    c++;
                    curr *= 2;
                }
                num += 1 / Math.pow(2, c);
            }
            w.println(num / n);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 33216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;


int main() {
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a, a + n);
    reverse(a, a + n);
    int ans = 0;
    for (int i = 0; i < k; i++) {
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


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

namespace ABC126_1
{
    class B
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var s1 = int.Parse(s.Substring(0, 2));
            var s2 = int.Parse(s.Substring(2, 2));

            if ((1 <= s1 && s1 <= 12) && (1 <= s2 && s2 <= 12)) Console.WriteLine("AMBIGUOUS");
            else if ((1 <= s1 && s1 <= 12) && (s2 == 0 || 12 < s2)) Console.WriteLine("MMYY");
            else if ((s1 == 0 || 12 < s1) && (1 <= s2 && s2 <= 12)) Console.WriteLine("YYMM");
            else Console.WriteLine("NA");
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define prime 1000000007
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
signed main(void) {
    int N;
    cin >> N;
    cout << N << ':' << ' ';
    vector<P> Primes;
    for(int i = 2; i <= sqrt(N); i++) {
        if(N % i == 0) {
            int count = 0;
            while(N % i == 0) {
                N /= i;
                count++;
            }
            Primes.push_back(make_pair(count, i));
        }
    }
    if(N > 1) Primes.push_back(make_pair(1, N));
    rep(i, Primes.size()) {
        P p = Primes[i];
        if(i < Primes.size() - 1) {
            rep(j, p.F) cout << p.S << ' ';
        } else {
            rep(j, p.F - 1) cout << p.S << ' ';
            cout << p.S << endl;
        }
    }
}



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

#define int long long

const int INI = 1e15;
const int INF = 1e9;

int dp[51][51][51][51][2][4];
int N, M;
vector<int> A, B;
vector<int> cuma, cumb;

int dfs(int a, int b, int c, int d, int t, int r) {
  // cout << a << " " << b << " " << c << " " << d << " " << t << endl;
  if ( dp[a][b][c][d][t][r] != INI ) return dp[a][b][c][d][t][r];

  if ( a == N && b == M && c == N && d == M ) return 0;
  if ( a == c && b == d && r >= 3 ) return 0;  

  int ret = 0;  
  if ( !t ) {
    ret = -INF;    
    if ( a < N ) {
      if ( A[a] == -1 ) ret = max(ret, dfs(a+1, b, c, b, !t, 0));
      else ret = max(ret, dfs(a+1, b, c, d, !t, 0));		     
    }
    int suma = cuma[a] - cuma[c], sumb = cumb[b] - cumb[d];    
    ret = max(ret, dfs(a, b, a, b, !t, r+1) + suma-sumb);    
  } else {
    ret = INF;
    if ( b < M ) {
      if ( B[b] == -1 ) ret = min(ret, dfs(a, b+1, a, d, !t, 0));
      else ret = min(ret, dfs(a, b+1, c, d, !t, 0));		     
    }
    int suma = cuma[a] - cuma[c], sumb = cumb[b] - cumb[d];    
    ret = min(ret, dfs(a, b, a, b, !t, r+1) + suma-sumb);    
  }

  return dp[a][b][c][d][t][r] = ret;  
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  fill_n(*****dp, 51*51*51*51*2*4, INI);
  cin >> N >> M;
  A = cuma = vector<int>(N+1, 0);  
  for ( int i = 0; i < N; i++ ) {
    cin >> A[i];
    if ( A[i] >= 0 ) cuma[i+1] = A[i];
    cuma[i+1] += cuma[i];    
  }
  B = cumb = vector<int> (M+1, 0);
  for ( int i = 0; i < M; i++ ) {
    cin >> B[i];
    if ( B[i] >= 0 ) cumb[i+1] = B[i];
    cumb[i+1] += cumb[i];    
  }

  cout << dfs(0, 0, 0, 0, 0, 0) << endl;  
  
  return 0;
}



Measured memory_bytes: 426048
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  ll K, X;
  cin >> K >> X;

  if(500*K >= X) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int s[100001]={0};
int main()
{
	char ss[100000];
	cin>>ss;
	int i;
	int sum=0;
	for (i=strlen(ss)-1;i>0;--i)
	    if (ss[i]!=ss[i-1]) sum++;
	cout<<sum;
	return 0;
}

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

#define INCANT cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define out(a) cout << a << endl
#define PRINT(V) for (auto v : (V)) cout << v << " "

const int MOD = 1000000007;
const double PI = acos(-1.0);

ll N, M, X;
vector<vector<ll>> A(12, vector<ll>(12));
vector<ll> C(12);
ll dfs(vector<int> b, int depth){
    if(depth==N){
        ll sumC = 0;
        vector<ll> sumA(M,0);
        rep(i, N){
            if(b.at(i)){
                sumC += C.at(i);
                rep(j, M) sumA.at(j) += A.at(i).at(j);
            }
        }
        rep(j, M){
            if(sumA.at(j) < X) return -1;
        }
        return sumC;
    }
    depth += 1;
    b.push_back(0);
    ll ret1 = dfs(b, depth);
    b.pop_back();
    b.push_back(1);
    ll ret2 = dfs(b, depth);
    if(ret1==-1 && ret2==-1) return -1;
    else if(ret1==-1 || ret2==-1) return max(ret1, ret2);
    else return min(ret1, ret2);
}
void solve() {
    cin >> N >> M >> X;
    rep(i, N){
        cin >> C.at(i);
        rep(j, M) cin >> A.at(i).at(j);
    }
    vector<int> b;
    int depth=0;
    ll ans = dfs(b, depth);
    out(ans);
}
int main() {
    INCANT;
    solve();
    return 0;
}




Measured memory_bytes: 3664
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string HEX = "0123456789ABCDEF";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),std::greater<int>())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

int main(void) {
    int n,b;
    vector<long> a;
    cin >> n;
    REP(i,n){
        cin >> b;
        a.push_back(b);
    }
    long t = 0;
    long c = 0;
    b = 0;
    SORT(a);
    REP(i,n){
        if (a[i] > c) {
            if (b >= c) {
                t += b - c;
            } else {
                t += b;
            }
            c = a[i];
            b = 1;
        } else {
            b++;
        }
    }
    if (b >= c) {
        t += b - c;
    } else {
        t += b;
    }
    cout << t;
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
using ll = long long;
const ll INF = LLONG_MAX - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;

class fact {
public:
	int fmod = 1e9+7;
	vector<int> fac, inv;
	fact (int n, int Mod = 1e9+7) {
		fmod = Mod;
		fac = vector<int>(n,0);
		inv = vector<int>(n,0);
		fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
		for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
	}
	ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
	ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}

int dp[200005], ma[200005];

bool solve() {
	int n,k; cin >> n >> k;
	string s; cin >> s;
	int tmp = 1;
	vector<int> seq;
	for (int i = 1; i < s.size(); i++) {
		if (s[i] != s[i-1]) {
			seq.pb(tmp);
			tmp = 1;
		} else {
			tmp++;
		}
	} seq.pb(tmp);
	bool flag = (s[0] == '1');
	for (int i = 1; i < seq.size(); i++) {
		seq[i] += seq[i-1];
	}
	int ans = 0;
	for (int i = 0; i < seq.size(); i++) {
		bool one = (flag != i%2);
		int tmp = 0;
		int K;
		if (one) {
			K = min((int)seq.size()-1,i+2*k);
			// cout << i << " " << K << endl;
			if (i == 0) {
				tmp = seq[K];
			} else {
				tmp = seq[K] - seq[i-1];
			}
		} else {
			K = min((int)seq.size()-1,i+2*k-1);
			// cout << i << " " << K << endl;
			if (i == 0) {
				tmp = seq[K];
			} else {
				tmp = seq[K] - seq[i-1];
			}
		}
		chmax(ans,tmp);
	}
	cout << ans << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}


Measured memory_bytes: 1528
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;

int permod(int n,int k,long long int p)
{
    long long int val=1;
    for(int i=n-k+1;i<=n;i++)
    {
        val*=i%p;
        val%=p;
    }
    return val;
}

long long int ans(int k,long long int p,vector<vector<int>>& graph,int now,int from)
{
    long long int val=1;
    if(graph[now].size()>k-1)
    {
        return 0;
    }
    else
    {
        if(from==-1)
        {
            val*=permod(k,graph[now].size()+1,p);
            val%=p;
        }
        else
        {
            val*=permod(k-2,graph[now].size()-1,p);
            val%=p;
        }

        for(int i:graph[now])
        {
            if(i!=from)
            {
                val*=ans(k,p,graph,i,now);
                val%=p;
            }
        }
        return val;
    }
}

int main()
{
    int n,k;
    long long int p=1000000007;
    int temp1,temp2;
    cin>>n>>k;
    vector<vector<int>> tree(n);
    for(int i=0;i<n-1;i++)
    {
        cin>>temp1>>temp2;
        tree[temp1-1].push_back(temp2-1);
        tree[temp2-1].push_back(temp1-1);
    }

    cout<<ans(k,p,tree,0,-1)<<endl;
}

Measured memory_bytes: 11648
N = int(input())
A = []
for i in range(N):
    A.append(input())
M = int(input())
B = []
for j in range(M):
    B.append(input())

count = 0
ans = 0

for k in set(A):
    count = A.count(k)-B.count(k)
    if count >= 0 and ans <= count:
        ans = count

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define MOD 1000000007
#define INT long long int
#define REP(i,n) for(int(i)=0;(i)<(n);(i)++) 
using namespace std;
const long long INF = numeric_limits<long long>::max();
#include <map>
#include <fstream>

int main()
{   
    string S;
    cin>>S;
    // ifstream ifs("in.txt");
    // while(getline(ifs,S));
    map<char, INT> counter;
    INT N = S.size();
    REP(i,N){
        counter[S[i]]++;
    }
    INT ans = N*(N-1)/2+1;
    for (pair<char,INT> cnt:counter){
        INT minus =(cnt.second*(cnt.second-1))/2; 
        ans -= minus;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 640
N = int(input())
S = input()

kv = {'R':[],'G':[],'B':[]}
for i in range(N):
    kv[S[i]].append(i)

a = sorted([[len(kv['R']),'R'],[len(kv['G']),'G'],[len(kv['B']),'B']], key=lambda x:-x[0])
a1, a2, a3 = a[0][1],a[1][1],a[2][1]

ans = a[0][0]*a[1][0]*a[2][0]
set_a3 = set(kv[a3])
for one in kv[a1]:
    for t in kv[a2]:
        ans-=3-len(set([2*t-one,2*one-t,(t+one)/2])-set_a3)
print(ans)

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

using namespace std;

using ll = long long int;
using vi = vector<int>;
#define f(n) for(int i = 0; i < n; i++)
#define fj(n) for(int j = 0; j < n; j++)
#define fk(n) for(int k = 0; k < n; k++)
#define ci(n) cin >> n;
#define ic(n) int n; cin >> n;
#define lc(n) int n; cin >> n;
#define all(a) a.begin(), a.end()
#define pri(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n";
#define sc(a, n) int a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define scl(a, n) ll a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define pb push_back
#define eb emplace_back
#define int long long
const int inf = 2e9;


void solve(int ci)
{
    ic(a) ic(v) ic(b) ic(w) ic(t)
    if(a == b)
    {
        cout << "YES";
        return;
    }
    if(w >= v)
    {
        cout << "NO";
        return;
    }
    if(abs(a - b) <= t * (v - w)) cout << "YES";
    else cout << "NO";

}

signed main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    //cin >> t;
    f(t) solve(i + 1);
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <stack>
#include <set>
using namespace std;
#define N 200010
#define WHITE 0
#define BLACK 1
int dfs(int n , vector<int> G[]){
    int i, j, vertex, neighbor, color[N];
    stack<int> S;

    int max_size = 0;

    for(i=0; i<n; i++) color[i] = WHITE;

    for(i=0; i<n; i++){
        if(color[i] == WHITE){
            int size = 0;
            S.push(i);
            while(!S.empty()){
                vertex = S.top();
                S.pop();
                if(color[vertex] == BLACK) continue;
                size++;
                color[vertex] = BLACK;

                for(j=0; j<(int)G[vertex].size(); j++){
                    neighbor = G[vertex][j];
                    if(color[neighbor] == WHITE) S.push(neighbor);
                }
            }
            if(max_size <= size) max_size = size;
        }
    }

    return max_size;

}
int main()
{
    int i, n, m, s, t;
    vector<int> G[N];  // グラフを表現する隣接リスト

    cin >> n >> m;
    // 隣接リストを作成
    for (i = 0; i < m; i++) {
        cin >> s >> t;
        s--; t--;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    cout << dfs(n, G) << endl;

    return 0;


}

Measured memory_bytes: 15608
module Main (main) where

import qualified Data.ByteString.Char8 as C8
import Data.Bool
import Data.Maybe

main :: IO ()
main = do
  [a,b,c] <- readInts
  print . showAnswer $ solve (a,b,c)

type Input  = (Int, Int, Int)
type Output = Bool

solve :: Input -> Output
solve (a,b,c) = a+b >= c

showAnswer :: Output -> Answer
showAnswer = YesNo

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

data Answer
  = YesNo Bool
  | YESNO Bool
  | AB Bool
  | Number Int
  | String String
  | Compare Ordering
  | Compare2 Ordering

instance Show Answer where
  show (YesNo b)    = bool "No" "Yes" b
  show (YESNO b)    = bool "NO" "YES" b
  show (AB b)       = bool "B"  "A" b
  show (Number i)   = show i
  show (String s)   = s
  show (Compare o)  = ordering "<" "=" ">" o
  show (Compare2 o) = ordering "Right" "Balanced" "Left" o

ordering :: a -> a -> a -> Ordering -> a
ordering lt eq gt o = case o of
  LT -> lt
  EQ -> eq
  GT -> gt

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

/*
 * Notice that any number X which divides all the elements of the array
 * also divides the sum of the array. Moreover, the sum is constant
 * after any number of operations. Therefore, the answer is one of the
 * factor of the sum.
 *
 * We check every divisor of the sum, and find the highest one which can
 * be the answer.
 * 
 * For checking if X is valid, I found A[i] % X for all A[i], pushed
 * them into an array, sorted them, and then tried to reduce the left
 * ones and increase the ones on the right to minimise the number of
 * operations required.
 */

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    while (cin >> n >> k) {
        int sum = 0; VI A(n);
        FOR(i,0,n) {
            cin >> A[i]; sum += A[i];
        }
        int f = 1; VI F;
        for (; f*f <= sum; f++) {
            if (sum%f == 0) {
                F.push_back(f); F.push_back(sum/f);
            }
        }
        int ans = 1;
        FOR_ALL(f,F) {
            VI R(n);
            FOR(i,0,n)
                R[i] = A[i]%*f;
            sort(ALL(R));
            int need = 0; 
            FOR(i,0,R.size()) {
                int x = R[i];
                while (x && R.size() > 1) {
                    const int y = min(x,*f-R.back());
                    R.back() += y;
                    if (R.back() == *f)
                        R.pop_back();
                    x -= y;
                }
                if (x == 0)
                    need += R[i];
                else
                    need = k+1;
            }
            if (need <= k)
                ans = max(ans,*f);
        }
        cout << ans << endl;
    } 
    return 0;
}


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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

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

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

char last1(char C1,char C2){
    if(C1=='R' && C2=='B' || C1=='B' && C2=='R')return 'G';
    else if(C1=='G' && C2=='B' || C1=='B' && C2=='G')return 'R';
    else return 'B';
}

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n;
    string s;

    cin>>n>>s;
    vector<int>idxR;
    vector<int>idxG;
    vector<int>idxB;
    map<char,vector<int>> idx;

    rep(i,n){
        idx[s[i]].eb(i);

        switch (s[i]){
        case 'R':
            idxR.eb(i);
            break;

        case 'G':
            idxG.eb(i);
            break;

        case 'B':
            idxB.eb(i);
            break;

        default:
            break;
        }
    }

    ll rgb=0;

    rep(i,n){
        rep1(j,i+1,n){
            if(s[i] == s[j])continue;

            vector<int>idxN = idx[last1(s[i],s[j])];
            rgb += idxN.end() - upper_bound(all(idxN),j);
        }
    }

    ll DDDrgb=0;
    ll DDD=0;
    bool fin=false;
    for(int d=1;2*d<n;++d){

        int st=0,mid=st+d,ed=mid+d;
        for(st=0;ed<n;++st,++mid,++ed){
            ++DDD;
            if(! ( (s[st]==s[mid]) || (s[st]==s[ed]) || (s[ed]==s[mid]) ))++DDDrgb;
        }
    
    }

    //db3(rgb,DDD,DDDrgb);ln;
    cout<<rgb - DDDrgb <<endl;

    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 3676