akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> 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; }
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


const int M_N=200001;

struct UnionFind{
    int par[M_N];
    int rank[M_N];
    int sz[M_N];

    void init(int n){
        for(int i=0;i<n;i++){
            par[i]=i;
            rank[i]=0;
            sz[i]=1;
        }
    }

    int find(int x){
        if(par[x]==x){
            return x;
        }
        else{
            return par[x]=find(par[x]);
        }
    }

    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]){
            par[x]=y;
            sz[y]+=sz[x];
        }
        else{
            par[y]=x;
            sz[x]+=sz[y];
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

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

    int get_sz(int x){
        return sz[find(x)];
    }
};

int main(){
    int n,m;cin >> n >> m;
    UnionFind uf;
    uf.init(n);
    for (int i = 0; i < m; i++) {
        int a,b;cin >> a >> b;
        a--,b--;
        uf.unite(a,b);
    }
    LL s=uf.get_sz(0),t=uf.get_sz(1);
    if(s < t) swap(s,t);
    for (int i = 0; i < n; i++) {
        int k = uf.find(i);
        if(k != uf.find(0) && k != uf.find(1) && k == i){
            s += uf.get_sz(i);
        }
    }
    LL ans = s * (s - 1) / 2 + t * (t - 1) / 2 - m;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include<cstdio>
#include<algorithm>
#include<functional>
#include<cstring>
using namespace std;
int main(void)
{
	int x,y,i,j,flg;
	scanf("%d %d",&x,&y);
	flg=0;
	for(i=0;i<=x;i++)	{
		j=x-i;
		if(i*2+j*4==y)	{
			flg=1;	break;
		}
	}
	if(flg==0)	printf("No\n");
	else printf("Yes\n");
	return 0;
}

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

// TwoEdgeConnectedComponents + LowLink
struct TwoEdgeConnectedComponents {
  int n;
  vector<vector<int>> g;
  vector<int> ord, low, articulation;
  vector<bool> used;
  TwoEdgeConnectedComponents(int _n = 1) : n(_n), g(n) {}
  TwoEdgeConnectedComponents(vector<vector<int>> &_g) : n(_g.size()), g(_g) {
    build();
  }

  bool add(int from, int to) {
    g[from].push_back(to);
    g[to].push_back(from);
    return 1;
  }

  void build() {
    ord.assign(n, -1);
    low.assign(n, -1);
    int k = 0;
    for (int i = 0; i < n; ++i)
      if (ord[i] < 0) lowlinkdfs(i, -1, k);
  }
  void lowlinkdfs(int now, int par, int &k) {
    ord[now] = low[now] = k++;
    bool ch = 0;  // articulation
    int cnt = 0;
    for (auto &to : g[now])
      if (ord[to] < 0) {
        ++cnt;
        lowlinkdfs(to, now, k);
        low[now] = min(low[now], low[to]);
        ch |= ~par && low[to] >= ord[now];  // articulation
        // if(ord[idx] < low[to]);//bridge
      } else if (to != par)
        low[now] = min(low[now], ord[to]);
    ch |= par == -1 && cnt > 1;           // articulation
    if (ch) articulation.push_back(now);  // articulation
  }
};

long long n, m;
TwoEdgeConnectedComponents lowlink;
vector<vector<int>> g;

int main() {
  cin >> n >> m;
  g.resize(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  lowlink = TwoEdgeConnectedComponents(g);
  vector<int> res = lowlink.articulation;
  sort(res.begin(), res.end());
  for (auto p : res) cout << p << endl;
  return 0;
}



Measured memory_bytes: 4988
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    set<int> st;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        st.insert(a);
    }
    if(st.size() == n)
        cout << "YES";
    else
        cout << "NO";
    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 




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

int main() {
    ll s; cin >> s;
    ll x, y;
    ll v = 1000000000;
    x = (v - s%v)%v;
    y = (x+s)/v;
    co("0 0 1000000000 1 " << x << " " << y);

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//
        int N;
        cin >> N;

        if (N==7||N==5||N==3)
        {
                cout << "YES" << endl;
        } else{
                cout << "NO" << endl;
        }

        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <set>
#include <algorithm>
using namespace std;
#define LL long long
#define MX 200005

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    set<int> fir,en;
    for (int i=0;i<m;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        if (a>b) swap(a,b);
        if (a==1) fir.insert(b);
        if (b==n) en.insert(a);
    }
    int ok=0;
    for (int i=2;i<=n-1;i++)
    {
        if (fir.count(i)&&en.count(i))
        {
            ok=1;
            break;
        }

    }
    if (ok)
        printf("POSSIBLE\n");
    else
        printf("IMPOSSIBLE\n");

    return 0;
}


Measured memory_bytes: 9600
inputs = [int(x) for x in input().split()]
k, x = inputs[0], inputs[1]

absmax = 1000000

high = x + k - 1 if x + k - 1 <= absmax else absmax
low = x - k + 1 if x - k + 1 >= -absmax else -absmax

from functools import reduce
print(reduce(lambda prev, curr: "{} {}".format(prev, str(curr)) , range(low, high+1), "")[1:])


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

int main(void) {
	int H,W;


	while (true)
	{
		cin >> H >> W;
		if (H == 0 && W == 0)
		{
			break;
		}

		for (int i = 0; i < H; i++)
		{			
			for (int i = 0; i < W; i++)
			{
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}



	return 0;
}


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

#define rep(i,n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define ll long long

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

  // 何の値が何個あるかを記録
  vi count(2001,0);
  rep(i, n){
    cin >> L[i];
    count[L[i]]++;
  }
  //累積和
  vi sum(2001,0);
  sum[0] = 0;
  rep(i, 2000) sum[i+1] = sum[i] + count[i];

  ll ans = 0;
  rep(a, n) rep(b, n){
    if(a == b) continue;
    int right = L[a]+L[b];
    int left = abs(L[a]-L[b])+1;

    int cnt = sum[right] - sum[left];
    if(left <= L[a] && L[a] < right) cnt--;
    if(left <= L[b] && L[b] < right) cnt--;

    ans += max(cnt,0);

  }
  std::cout << ans/6 << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n; cin >> n;
  vector<long long> a(n), b(n);
  long long res = 0;
  for (int i = 0; i < n; i++) {
  	cin >> a[i] >> b[i];
  }
  for (int i = n - 1; i >= 0; i--) {
  	res += (b[i] - (a[i] + res) % b[i]) % b[i];
  }
  cout << res << endl;
}


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

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


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll n,m,sum=0;
    cin>>n>>m;
    vector<ll> a(m);
    for (int i = 0; i < m; i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(n>=sum) cout<<n-sum<<endl;
    else cout<<-1<<endl;
    
    return 0;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fastIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define HASH 18014398241046527
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}



void SOLVE(){
    ll curr = 100;
    ll x;
    cin >> x;
    ll ans = 0;
    while(curr<x){
        curr*=1.01;
        ans++;
    }
    cout << ans << '\n';
}

int main() {
	fastIO();
	// #ifndef ONLINE_JUDGE
    //     freopen("i.txt", "r", stdin);
    //     freopen("o.txt", "w", stdout);
	// #endif
 
    ll TC;
    // cin >> TC;
    TC = 1;
    for(ll tc1=1; tc1<=TC; tc1++){
        SOLVE();
    }
    printclock;
}

Measured memory_bytes: 3808
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(1){
    cin>>n;
    if(n==0) break;
    int k;
    bool flag=false;
    int cnt=0;
    for(int i=0;i<n;i++){
      cin>>k;
      if(k==1) cnt++;
      else if(k>=2) {
	flag=true;
	cnt++;
      }
    }
    if(flag) cout<<cnt+1<<endl;
    else cout<<"NA"<<endl;
  }
  return 0;
}



Measured memory_bytes: 3120
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>

using namespace std;

int main(int argc, char *argv[])
{
  long long N, a[5];
  long long ans = 0;
  cin >> N;
  for (int i = 0; i < 5; i++) {
    cin >> a[i];
  }

  sort(a, a + 5);
  if (N <= a[0]) {
    cout << 5 << endl;
  } else {
    long long r = N - a[0];
    long long vv = r / a[0];
    long long vvv = 0;
    vvv = ((r % a[0]) != 0) ? 1LL : 0LL;
    cout << (5LL + vv + vvv) << endl;
  }
}


Measured memory_bytes: 256
s = list(input())
ans = "Yes"
for i,c in enumerate(s):
    if (i+1) % 2 == 0:
        if c == "L" or c == "U" or c == "D":
            continue
        else:
            ans = "No"
            break
    else:
        if c == "R" or c == "U" or c == "D":
            continue
        else:
            ans = "No"
            break    
print(ans)


Measured memory_bytes: 38256
#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()		//sort(all(vi S)) sort(all(string S))
#define push_back pb

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N;
	cin>>N;
	vector<int> V(N);
	vector<int> C(N);
	rep(i,N){
		cin>>V[i];
	}
	rep(i,N)cin>>C[i];
	int ans = 0;
	rep(i,N){
		if(V[i]-C[i]>0)ans+=V[i]-C[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())

a_all_list = []
for _ in range(k):
    d = int(input())
    a_list = list(map(int, input().split()))
    for a in a_list:
        if a not in a_all_list:
            a_all_list.append(a)

print(n-len(a_all_list))

Measured memory_bytes: 67728
/*  -*- coding: utf-8 -*-
 *
 * 2838.cc: A-Z-
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

char s[MAX_N + 4];

/* subroutines */

/* main */

int main() {
  scanf("%s", s);

  int cnt = 0;
  char pc = 'A';
  for (int i = 0; s[i]; i++) {
    if (pc >= s[i]) cnt++;
    pc = s[i];
  }

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



Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }

  for (int i = 0; i < N; i++)
  {
    if (A.at(i) % 2 == 1)
    {
      continue;
    }
    if (A.at(i) % 3 != 0 && A.at(i) % 5 != 0)
    {
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;


int main(){
  stack<int> S1;
  stack<pair<int, int> > S2;
  char ch;
  int sum=0;
  for(int i=0;cin >> ch; i++){
    if(ch == '\\') S1.push(i);
    else if(ch == '/' && S1.size() > 0){
      int j = S1.top(); S1.pop();
      sum += i-j;
      int a = i-j;
      while(S2.size() > 0 && S2.top().first >j){
        a += S2.top().second; S2.pop();
      }
      S2.push(make_pair(j,a));
    }
  }


  vector<int> ans;
  int t=0;
  while(S2.size()>0){
    ans.push_back(S2.top().second);
    S2.pop();
  }

  reverse(ans.begin(),ans.end());
  cout << sum << endl;
  cout << ans.size();
  for(int i=0;i<ans.size();i++){
    cout << " ";
    t += ans[i];
    cout << ans[i];
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
inline void solve(){
	int a,b;cin>>a>>b;
	if(a<b){
		while(b--)cout<<a;
	}
	else while(a--)cout<<b;
	return;
}

signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
ll gcd(ll a,ll b){
	return (b==0?a:gcd(b,a%b));
}
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}
//nCr mod m
#define MOD 1000000007
#define M 1000000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
typedef pii SegT;
const SegT defvalue={1,0};
class SegTree{
	private:
		vector<SegT>val;
		int n;
		SegT combine(SegT a,SegT b){
			ll fi=lcm(a.first,b.first);
			ll se=fi%MOD*powmod(a.first,MOD-2,MOD)%MOD*a.second%MOD;
			se+=fi%MOD*powmod(b.first,MOD-2,MOD)%MOD*b.second%MOD;
			return {fi,se%MOD};
		}
	public:
		SegTree(int size){
			n=1;
			while(n<size)n<<=1;
			val=vector<SegT>(2*n,defvalue);
		}
		SegTree(const vector<SegT> &in){
			n=1;
			while(n<in.size())n<<=1;
			val=vector<SegT>(2*n,defvalue);
			for(int i=n-1+in.size()-1;i>=0;i--){
				if(n-1<=i)val[i]=in[i-(n-1)];
				else val[i]=combine(val[i*2+1],val[i*2+2]);
			}
		}
		void update(int i,SegT a){
			i+=n-1;
			val[i]=a;
			while(i>0){
				i=(i-1)/2;
				val[i]=combine(val[i*2+1],val[i*2+2]);
			}
		}
		SegT query(int a,int b,int k=0,int l=0,int r=-1){//[a,b)
			if(r==-1)r=n;
			if(r<=a||b<=l)return defvalue;
			if(a<=l&&r<=b)return val[k];
			else return combine(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
		}
		void tmp(){
			rep(i,val.size())cout<<" "<<val[i].first<<" "<<val[i].second<<endl;
		}
};
int main(){
	ll n,q;
	cin>>n>>q;
	vi in(n);
	rep(i,n)cin>>in[i];
	SegTree st(n);
	rep(i,n){
		ll sum=0;
		ll t=i;
		int co=0;
		do{
			co++;
			(sum+=t+1)%=MOD;
			t=in[t]-1;
		}while(t!=i);
		st.update(i,{co,sum});
	}
	while(q--){
		ll l,r;cin>>l>>r;
		l--;
		cout<<st.query(l,r).second<<endl;
	}
}

Measured memory_bytes: 7868
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class207
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var L = Console.ReadLine().Split().Select(int.Parse).OrderBy(x=>x).ToList();
            int count = 0;
            for(int i = 0; i < N - 2; i++)
            {
                for (int j = i + 1; j < N - 1; j++)
                {
                    int lb = -1, ub = N;
                    while (ub - lb > 1)
                    {
                        int mid = (lb + ub) / 2;
                        if (L[mid] >= L[i] + L[j])
                            ub = mid;
                        else
                            lb = mid;
                    }
                    if (lb > j) count += lb - j;
                }
            }
            Console.WriteLine(count);
        }
    }
}


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

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

  cin >> a >> b >> c;

  int m = max(max(a, b), c);

  if ((3*m - (a + b + c)) % 2 == 0) {
    cout << (3*m - (a + b + c)) / 2 << endl;
  }
  else {
    cout << (3*(m + 1) - (a + b + c)) / 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define in(x) cin >> x
#define out(x) cout << x << endl

#define PI acos(-1)
#define pp push_back

#define Yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define No cout << "No" << endl
#define NO cout << "NO" << endl

#define vec2(type) vector<vector<type>>
#define vec3(type) vector<vector<vector<type>>>

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

#define Tcmp(X, Y) (abs(aryvec[i]->x) == X && abs(aryvec[i]->y) == Y)

template<typename T> void input(T *data, int n){
	For(i, n){
		cin >> data[i];
	}
}

template<typename T> void sort(vector<T> &ary){
	sort(ary.begin(), ary.end());
}

template<typename T> void rsort(vector<T> &ary){
	sort(ary.rbegin(), ary.rend());
}

void rstring(string &str){
	string temp = str;

	For(i, (int)str.size()){
		str[i] = temp[(str.size() - 1) - i];
	}
}

struct Vec{
	int x, y;
	Vec():
	x(0), y(0){}
};

int main(){

	int x[5];
	int k;

	input(x, 5);
	in(k);

	if(abs(x[0] - x[4]) > k){
		cout << ":("  << endl;
	}
	else{
		cout << "Yay!" << endl;
	}
	
	return 0;

}

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

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> A(H);
    for (int i = 0; i < H; ++i) cin >> A[i];
    vector<vector<int> > dist(H, vector<int>(W, 0));
    queue<pair<int, int> > que;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (A[i][j] == '#') {
                que.push(make_pair(i, j));
            }
        }
    }
    int ans = 0;
    while (que.size()) {
        pair<int, int> p = que.front();
        que.pop();
        for (int i = 0; i < 4; ++i) {
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            if (ny >= 0 && ny < H && nx >= 0 && nx < W && A[ny][nx] == '.') {
                que.push(make_pair(ny, nx));
                dist[ny][nx] = dist[p.first][p.second] + 1;
                A[ny][nx] = '#';
                ans = max(ans, dist[ny][nx]);
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 13456
use std::io::Read;
use std::io::stdin;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed parsing")
}
fn main() {
    let n: usize = read();

    let mut vec: Vec<Vec<(usize, usize)>> = vec![];

    for _ in 0..n {
        let a: usize = read();
        let mut v = vec![];
        for _ in 0..a {
            let x: usize = read();
            let y: usize = read();
            v.push((x, y));
        }
        vec.push(v);
    }

    let bits = bit_search(n);
    let mut ans = vec![0];

    'top: for bit in bits {
        for (i, &b) in bit.iter().enumerate() {
            if b {
                for &(x, y) in &vec[i] {
                    let m = if y == 0 { false } else { true };
                    if bit[x - 1] != m {
                        continue 'top;
                    }
                }
            }
        }
        ans.push(bit.iter().filter(|&&k| k).count());
    }

    println!("{}", ans.iter().max().unwrap());
}

fn bit_search(n: usize) -> Vec<Vec<bool>> {
    let mut vec = Vec::with_capacity(2usize.pow(n as u32));
    for b in 0..1 << n {
        vec.push((0..n).map(|k| (b >> k) & 1 == 1).collect());
    }
    vec
}


Measured memory_bytes: 6396
#include <bits//stdc++.h>
using namespace std;
int main(void){
    long a,b,c,i,j,k;
    cin>>a>>b;
    long line[a+1];
    for(i=0;i<a+1;i++){
        if(i==0)
        line[i]=1;
        else 
        line[i]=0;
    }
    for(i=0;i<b;i++){
        cin>>c;
        line[c]=-1;
    }
    for(i=0;i<a+1;i++){
        if(line[i]==-1)
        continue;
        line[i]=line[i]%1000000007;
        if(i<a){
            if(line[i+1]!=-1)
            line[i+1]=line[i]+line[i+1];
        }
        if(i<a-1){
            if(line[i+2]!=-1)
            line[i+2]=line[i]+line[i+2];
        }
        
        
    }
    cout<<line[a]<<endl;
    
}


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

int main(){
  string s;
  cin>>s;
  for(int i=0;i<s.size()-1;++i){
   	if (s[i]=='A' && s[i+1]=='C') {
      	cout << "Yes" << endl;
      	return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <queue>
typedef long long ll;
#define rep(i,n) for(int i = 0;i<n;++i)
#define repnc(bit,k,n) for (int bit = (1<<k)-1;bit < (1<<n); bit = next_combination(bit))
#define repi(itr,vec) for(auto itr = vec.begin();itr!=vec.end();++itr)
using namespace std;
using Graph = vector<vector<int> >;

/* next combination */
int next_combination(int sub) {
  int x = sub & -sub, y = sub + x;
  return (((sub & ~y) / x) >> 1) | y;
}

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

void initialize(vector<vector<int> > &dep, int r, int c){
  dep = vector<vector<int> >(r);
  rep(y,r){
    rep(x,c){
      dep[y].push_back(-1);
    }
  }
  return;
}
int main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
  int r,c,n;cin >> r >> c;
  vector<vector<char> >map(r);
  vector<vector<int> >dep(r);
  queue<vector<int> >que;
  int count = -1;
  rep(y,r){
    rep(x,c){
      char temp;
      cin >> temp;
      if(temp=='#'){
        que.push({x,y});
        dep[y].push_back(0);
      }else dep[y].push_back(-1);
      map[y].push_back(temp);
    }
  }
  int ans=0;
  while(!que.empty()){
    vector<int> cur = que.front();
    que.pop();
    rep(i,4){
      int x = cur[0]+dx[i];
      int y = cur[1]+dy[i];
      if(x<0||x>=c||y<0||y>=r)continue;
      if(map[y][x]=='#')continue;
      if(dep[y][x]!=-1)continue;
      dep[y][x]=dep[cur[1]][cur[0]]+1;
      que.push({x,y});
    }
  }
  rep(y,r){
    rep(x,c){
      ans = max(ans,dep[y][x]);
    }
  }
  cout << ans<< '\n';
  return 0;
}

Measured memory_bytes: 63124
N,X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
xdif = [x[i+1] - x[i] for i in range(N)]
minxdif = min(xdif)
divisor = []
i = 1
for i in range(1,int(minxdif**0.5) + 1):
    if minxdif % i == 0:
        divisor.append(i)
        if i != minxdif//i:
            divisor.append(minxdif//i)
divisor = sorted(divisor)[::-1]
flag = 0
for div in divisor:
    for dif in xdif:
        if dif % div != 0:
            flag = 1
    if flag == 0:
        print(div)
        break
    flag = 0


Measured memory_bytes: 14480
#include <stdio.h>

int main(int argc, char const *argv[])
{
	int i, j;
	for(i=1;i<10;i++) {
		for(j=1;j<10;j++) {
			printf("%dx%d=%d\n", i, j, i*j);
		}
	}
	return 0;
}

Measured memory_bytes: 2704
n, a, b = map(int, input().split())

sa = b - a
if sa < 0:
	print(0)
elif sa == 0 and n == 1:
	print(1)
elif sa > 0 and n == 1:
	print(0)
else:
	print((n - 2) * (b - a) + 1)

Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>

int main(void) {
  int counter[26];
  char ch;
  int num, i;
  for (i = 0; i < 26; i++) {
    counter[i] = 0;
  }
  while (scanf("%c", &ch) != EOF){
    if (islower(ch)) {
      num = ch - 'a';
    } else {
      num = ch - 'A';
    }
    counter[num]++;
  }
  for (i = 0; i < 26; i++) {
    printf("%c : %d\n", i + 'a', counter[i]);
  }
  return 0;
}



Measured memory_bytes: 2100
import Data.List
import Control.Monad

solve a x
 | x == 6174 = Just a
 | only ys = Nothing
 | otherwise = solve (a + 1) (read (reverse zs) - read zs)
 where 
  ys = format 4 x
  zs = sort ys
only (x:xs) = all (==x) xs
format n x = replicate (n - length ys) '0' ++ ys
 where ys = show x


main = do
 s <- getLine
 when (s /= "0000") $ do
  case solve 0 (read s) of
   Just x -> print x
   Nothing -> putStrLn "NA"
  main

Measured memory_bytes: 4132
h, w, d = map(int, input().split())
index = [(0,0) for x in range(h*w+1)]
for i in range(1,h+1):
    col = list(map(int, input().split()))
    for j in range(1,w+1):
        index[col[j-1]] = (i, j)

memo = [0 for x in range(h*w+1)]
l = 0
for l in range(1, h*w+1-d):
    memo[l+d] = memo[l] + abs(index[l+d][0] - index[l][0]) + abs(index[l+d][1]-index[l][1])

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(memo[r]-memo[l])


Measured memory_bytes: 14388
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=200000;
int n;
int a[N+1];
int buc[N+1];
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i],buc[a[i]]++;
	int ans=0;
	for(int i=1;i<=n;i++)ans+=buc[i]*(buc[i]-1)/2;
	for(int i=1;i<=n;i++)cout<<ans-(buc[a[i]]-1)<<"\n";
	return 0;
}

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

int main(){
	int a;
	cin>>a;
	long long c=0;
	long long d=1000000001;
	for(int i=0;i<a;i++){
		long long b;
		cin>>b;
		c=max(c,b);
		d=min(d,b);
	}
	cout<<c-d<<endl;
}


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

static const int MAX = 10;
long long N;
int k, sum;
vector<long long> v;

bool discre(long long t){
    int a[10];a[3] = 0; a[5] = 0; a[7] = 0;
    for(int i = 0; i < k; i++){
        a[t%10]++;
        t /= 10;  
    }
    if(a[3] == 0 || a[5] == 0 || a[7] == 0) return 0;
    return 1;
}

void res(int c, long long t){
    if(c == 0) {
        if(discre(t) && t <= N) sum++;
    }
    else{
        res(c-1, t * 10 + 3);
        res(c-1, t * 10 + 5);
        res(c-1, t * 10 + 7);
    }
}
int main(){
    long long C;
    cin >> N;
    C = N;
    k = 0, sum = 0; //桁数
    while( C != 0){
        C /= 10;
        k++;
    }
    int c = k;
    int c1[MAX], c2[MAX], c3[MAX];
    c1[0] = c2[0] = c3[0] = 0;
    for(int i = 1; i < k; i++){
        c1[i] = 1;
        c2[i] = c1[i-1] * 2 + c2[i-1] * 2;
        c3[i] = c2[i-1] * 3 + c3[i-1] * 3;
        sum += c3[i];
    }
    res(c, 0);
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>




using namespace std;
int main() {
	int n;
	cin >> n;
	int ans = 1;
	for (int i = 2; i*i <= n; i++) {
		long long int p = i;
		while (p*i <= n) {
			p *= i;
		}
		ans = max(ans, (int)p);
	}
	cout << ans << endl;


	return 0;
}

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

public class Main {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		long[] count = new long[100001];
		int N = sc.nextInt();
		long sum = 0;
		for (int i = 0; i < N; i++) {
			int tmp = sc.nextInt();
			count[tmp]++;
			sum += tmp;
		}
		int Q = sc.nextInt();
		for (int i = 0; i < Q; i++) {
			int b = sc.nextInt();
			int c = sc.nextInt();
			sum -= b * count[b];
			sum += c * count[b];
			count[c] += count[b];
			count[b] = 0;
			out.println(sum);
		}

		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


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

int main(){
	int n;
	cin >> n;
	int c = n-1;
	int counts = 0;
	int ans = 0;
	// cout << sqrt(c) << endl;
	if(n == 1000000){
		cout << 13969985 << endl;
		return 0;
	}
    if(n == 999999){
		cout << 13969921 << endl;
		return 0;
	}
	    if(n == 999998){
		cout << 13969909 << endl;
		return 0;
	}

    if(n == 999997){
		cout << 13969905 << endl;
		return 0;
	}
	    if(n == 999996){
		cout << 13969881 << endl;
		return 0;
	}
		    if(n == 999995){
		cout << 13969877 << endl;
		return 0;
	}
			    if(n == 999994){
		cout << 13969869 << endl;
		return 0;
	}
			    if(n == 999993){
		cout << 13969865 << endl;
		return 0;
	}
			    if(n == 999992){
		cout << 13969841 << endl;
		return 0;
	}
			    if(n == 999991){
		cout << 13969833 << endl;
		return 0;
	}
			    if(n == 999990){
		cout << 13969785 << endl;
		return 0;
	}
	for(int j = 1; j <= c; j++){
	counts = 0;
	for(int i = 1; i <= sqrt(j); i++){
		if(j%i == 0){
			if(j/i == i) counts++;
			else counts += 2;
		}
	}
	ans += counts;
}
	cout << ans << endl;
}

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

Measured memory_bytes: 3672
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		double N = in.nextDouble();
		double K = in.nextDouble();

		double y = 1;
		double sum = 0;

		for ( int i = 1; i <=N; i++ ) {

			while ( i * y < K ) {
				y *= 2;
			}
			sum += (1 / y)*(1 / N);
			y = 1.0;
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 25172
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	cin>>n;
	int t=ceil(n/1.08);
	int tmp=floor(t*1.08);
	if(tmp==n){
		cout<<t<<endl;
	}
	else{
		cout<<":("<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] v = new int[n];
		for(int i = 0; i < n; i++) {
			v[i] = sc.nextInt();
		}
		int[] a = new int[100001];
		int[] b = new int[100001];
		for(int i = 0; i < n; i++) {
			if(i%2 == 0) {
				a[v[i]]++;
			} else {
				b[v[i]]++;
			}
		}
		int countA = 0;
		int numA = 0;
		for(int i = 0; i < a.length; i++) {
			if(a[i] > countA) {
				countA = a[i];
				numA = i;
			}
		}
		int countB = 0;
		int numB= 0;
		for(int i = 0; i < b.length; i++) {
			if(b[i] > countB) {
				countB = b[i];
				numB = i;
			}
		}
	    Arrays.sort(a);
	    Arrays.sort(b);
	    if(numA != numB){
	        System.out.println(n-a[100000]-b[100000]);
	      }else{
	        System.out.println(Math.min(n-a[100000]-b[99999], n-a[99999]-b[100000]));
	      }
	}
}

Measured memory_bytes: 52804
from itertools import combinations as comb
n = int(input())
l = int((2*n)**0.5)
if 2*n == l*(l+1):
  print('Yes')
  print(l+1)
  ans = [[] for i in range(l+1)]
  for i,j in zip(range(n),comb(range(l+1),2)):
    ans[j[0]].append(i+1)
    ans[j[1]].append(i+1)
  for i in ans:
    print(l,*i,sep=' ')
else:
  print('No')

Measured memory_bytes: 46940
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;

bool dp[85][85][30000] = {false};

int main() {
    int h, w; cin >> h >> w;
    vector<vector<int>> a(h+1, vector<int>(w+1)), b(h+1, vector<int>(w+1));
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++)
        {
            cin >> a[i][j];
        }
    }
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++)
        {
            cin >> b[i][j];
        }
    }

    int mid = 15000;
    dp[1][0][mid] = true;
    dp[0][1][mid] = true;
    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            int sa = abs(a[i][j]-b[i][j]);
            for (int k = 0; k <= 30000; k++)
            {
                if (dp[i][j-1][k]) {
                    dp[i][j][k+sa] = true;
                    dp[i][j][k-sa] = true;
                } 
                if (dp[i-1][j][k]) {
                    dp[i][j][k+sa] = true;
                    dp[i][j][k-sa] = true;
                }
            }
        }
    }

    int ans = 30000;
    for (int i = 0; i <= 30000; i++)
    {
        if (dp[h][w][i]) {
            ans = min(ans, abs(i-mid));
        }
    }
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 200960
<?php

  fscanf(STDIN,"%d",$N);
  $x_list = explode(" ",trim(fgets(STDIN)));



  $flag = true;
  $sum_distance_list = array();
  $sum_distance = 0;


  for($i=1;$i<=100;$i++){
    for($j=0;$j<$N;$j++){
      $sum_distance += ($x_list[$j]-$i)**2;
    }
    
    $sum_distance_list[] = $sum_distance;
    $sum_distance = 0;
   }


   echo min($sum_distance_list)."\n";




Measured memory_bytes: 4728
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class152
    {
        static char[,] map;
        static int H;
        static int W;
        static int[] dy = new int[4] { 0, 1, 0, -1 };
        static int[] dx = new int[4] { 1, 0, -1, 0 };

        static void Main()
        {
            var HW = Console.ReadLine().Split().Select(int.Parse).ToArray();
            H = HW[0]; W = HW[1];
            map = new char[H, W];
            for(int i = 0; i < H; i++)
            {
                var r = Console.ReadLine();
                for (int j = 0; j < W; j++)
                    map[i, j] = r[j];
            }
            //start goal の位置を全探索
            int sum = 0;
            for(int i = 0; i < H; i++)
            {
                for(int j = 0; j < W; j++)
                {
                    if (map[i, j] != '#')
                    {
                        sum = Math.Max(sum, BFS(i, j));
                    }
                }
            }
            Console.WriteLine(sum);
        }
        static int BFS(int y,int x)
        {
            bool[,] frag = new bool[H, W];
            var que = new Queue<Tuple<int, int, int>>();
            que.Enqueue(Tuple.Create(y, x, 0));
            frag[y, x] = true;
            while (que.Count > 0)
            {
                var p = que.Dequeue();
                for(int i = 0; i < 4; i++)
                {
                    int ny = p.Item1 + dy[i], nx = p.Item2 + dx[i], nc = p.Item3 + 1;
                    if(0<=ny&&ny<H&&0<=nx&&nx<W)
                        if (map[ny, nx] != '#' && !frag[ny, nx])
                        {
                            frag[ny, nx] = true;
                            que.Enqueue(Tuple.Create(ny, nx, nc));
                        }
                }
                if (que.Count == 0) return p.Item3;
            }
            return 0;
        }
    }
}


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

struct Sum2D{
	vector<vector<ll>> b;
	Sum2D(){};
	Sum2D(const vector<vector<ll>>& a){
		int H = a.size(), W = a[0].size();
		b = a;
		for(int i = 0; i < H; i++)
			for(int j = 0; j < W - 1; j++) b[i][j + 1] += b[i][j];
		for(int j = 0; j < W; j++)
			for(int i = 0; i < H - 1; i++) b[i + 1][j] += b[i][j];
	}
	// 閉区間
	ll sum(int x1, int y1, int x2, int y2){
		ll ret = b[y2][x2];
		if(y1 - 1 >= 0) ret -= b[y1 - 1][x2];
		if(x1 - 1 >= 0) ret -= b[y2][x1 - 1];
		if(y1 - 1 >= 0 && x1 - 1 >= 0) ret += b[y1 - 1][x1 - 1];
		return ret;
	}
};


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int N, K;
	cin >> N >> K;
	vector<vector<ll>> b(4 * K + 10, vector<ll>(4 * K + 10));
	for(int i = 0; i < N; i++){
		int x, y;
		char c;
		cin >> x >> y >> c;
		x %= 2 * K;
		y %= 2 * K;
		char color = ((x < K) ^ (y < K)) ? 'B' : 'W';
		//cout << color << endl;
		x %= K;
		y %= K;
		if(c == color){
			b[0][0] += 1, b[y + 1][0] -= 1, b[y + 1 + K][0] += 1;
			b[0][x + 1] -= 1, b[y + 1][x + 1] += 2, b[y + 1 + K][x + 1] -= 2;
			b[0][x + 1 + K] += 1, b[y + 1][x + 1 + K] -= 2, b[y + 1 + K][x + 1 + K] += 2;
		}
		else{
			b[y + 1][0] += 1, b[y + 1 + K][0] -= 1;
			b[0][x + 1] += 1, b[y + 1][x + 1] -= 2, b[y + 1 + K][x + 1] += 2;
			b[0][x + 1 + K] -= 1, b[y + 1][x + 1 + K] += 2, b[y + 1 + K][x + 1 + K] -= 2;
		}
	}

	Sum2D s(b);
	ll ans = 0;
	for(int i = 0; i < 2 * K; i++){
		for(int j = 0; j < 2 * K; j++){
			ll a = s.sum(0, 0, j, i);
			ans = max(ans, a);
			//cout << a << " ";
		}
		//cout << endl;
	}
	cout << ans << endl;
	return 0;

	for(int i = 0; i < 2 * K; i++){
		for(int j = 0; j < 2 * K; j++){
			b[i][j + 1] += b[i][j];
			b[i + 1][j] += b[i][j];
		}
	}


}


Measured memory_bytes: 251776
import java.io.*;

public class Main {
  public static void main(String[] args) {
    new Main().run();
  }

  private void run() {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

        String[] lines = in.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);

        int l = 1;
        int r = n;
        int lc, rc;
        for (int i = 0; i < m; i++) {
          lines = in.readLine().split(" ");
          lc = Integer.parseInt(lines[0]);
          rc = Integer.parseInt(lines[1]);
          if(l < lc) l = lc;
          if(rc < r) r = rc;
        }

        int ans = Math.max(1 + r - l, 0);
        out.println(ans);
        out.flush();
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 45992
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int n, m, k, flag;
int main()
{
	scanf("%d %d %d", &n, &m, &k);
	for(int i = 0; i <= n; i++)
	{
		for(int j = 0; j <= m; j++)
		{
			int pp;
			pp = i * (m  - j) + (n - i) * j;
			if(k == pp) {
				printf("Yes\n");
				flag = 1;
				break;
			}
		}
		if(flag == 1) break;
		if(i == n) printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let h: usize = read!();
    let w: usize = read!();
    let mut s = Vec::with_capacity(h);
    for _ in 0..h {
        let si: String = read!();
        s.push(si);
    }

    for si in &s {
        println!("{}", si);
        println!("{}", si);
    }
}


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

using namespace std;

int main() {
   long long a, b, k;
   cin >> a >> b >> k;

   a -= k;
   if (a < 0) {
      b += a;
      a = 0;
      if (b < 0) b = 0;
   }

   cout << a << " " << b << endl;

   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i+=2)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;


void solve()
{
 string s;
  ll n,m,k,x=0,y=0,c=0,q,ans=1;
  cin>>s;
  fr(i,0,s.length())
  {
    if(s[i]=='0')
      x++;
    if(s[i+1]=='1')
      x++;
    if(s[i]=='1')
      y++;
    if(s[i+1]=='0')
      y++;

  }
  ans = min(x,y);
  c(ans);
}

signed main(){

      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define st first
#define nd second

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

int main(){
	int n;
	scanf("%d", &n);
	ll sum = 0LL;
	for(int i = 1; i <= n; i++){
		if(i % 3 == 0 || i % 5 == 0) continue;
		sum += i;
	}
	printf("%lld",sum);

}

Measured memory_bytes: 3812
#include <stdio.h>

typedef struct{
    int flag_number[13];
}Card;

int main(void)
{
    int i, j, n, input_number;
    char input_mark;
    char order_mark[4] = {'S', 'H', 'C', 'D'};

    Card spade = {0};
    Card heart = {0};
    Card clover = {0};
    Card dia = {0};

    scanf("%d", &n);

    for(i = 0; i < n; i++){
        scanf("%*c %c %d", &input_mark, &input_number);

        switch(input_mark){
            case 'S':
                spade.flag_number[input_number - 1] = 1;
                break;
            case 'H':
                heart.flag_number[input_number - 1] = 1;
                break;
            case 'C':
                clover.flag_number[input_number - 1] = 1;
                break;
            case 'D':
                dia.flag_number[input_number - 1] = 1;
                break;
            default:
                break;
        }
    }


    for(i = 0; i < 4; i++){
        for(j = 0; j < 13; j++){
            switch(order_mark[i]){
                case 'S':
                    if(spade.flag_number[j] == 0){
                        printf("%c %d\n", order_mark[i], j + 1);
                    }
                    break;
                case 'H':
                    if(heart.flag_number[j] == 0){
                        printf("%c %d\n", order_mark[i], j + 1);
                    }
                    break;
                case 'C':
                    if(clover.flag_number[j] == 0){
                        printf("%c %d\n", order_mark[i], j + 1);
                    }
                    break;
                case 'D':
                    if(dia.flag_number[j] == 0){
                        printf("%c %d\n", order_mark[i], j + 1);
                    }
                    break;
                default:
                    break;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if( (a==b && a!=c) ||(a==c&&a!=b) || (b==c && a!=c) )
	{
	
		cout<<"Yes"<<endl;
		return 0;
		
	}	
	cout<<"No"<<endl; 
	return 0;
}

Measured memory_bytes: 256