akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std; 
const int N = 200005;
int n;
int a[N], tot=0, h[N];
int dfn[N], low[N], sta[N], dfs_num=0, top=0;
vector<int> e[N]; 
int f[N];
bool vis[N], vis2[N];
void tarjan(int u){
	dfn[u] = low[u] = ++dfs_num;
	sta[++top] = u;
	for (int i = 0; i < e[u].size(); i++){
		int v = e[u][i];
		if (!dfn[v]){
			tarjan(v);
			low[u] = min(low[v], low[u]);
		}else if (!vis2[v]) low[u] = min(dfn[v], low[u]);
	}
	if (dfn[u] == low[u]){
		vis2[u] = 1;
		if (sta[top] == u){
			top--;
			return;
		}
		do{
			vis2[sta[top]] = 1;
			a[++tot] = sta[top];
			h[sta[top]] = 1;
		}while (sta[top--] != u);
	}
}
void dfs(int u){
	for (int i = 0; i < e[u].size(); i++){
		int v = e[u][i];
		if (!h[v]) dfs(v);
	}
    for (int i = 0; i < e[u].size(); i++){
		int v = e[u][i];
        if (!h[v]) vis[f[v]] = 1;
    }
	while (vis[f[u]]) f[u]++;
	for (int i = 0; i < e[u].size(); i++){
		int v = e[u][i];
		if (!h[v]) vis[f[v]] = 0;
	}
}
int main(){
	std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//	freopen("test_file/in.txt", "r", stdin);
//	freopen("test_file/out.out", "w", stdout);
	cin >> n;
	for (int i = 1; i <= n; i++){
		int fa;
		cin >> fa;
		e[fa].push_back(i);
	}
	for (int i = 1; i <= n; i++) if (!dfn[i]) tarjan(i);
	int mn = 0x3f3f3f3f, mx = -1;
	for (int i = 1; i <= tot; i++){
		dfs(a[i]);
		mn = min(f[a[i]], mn);
		mx = max(f[a[i]], mx);
	}
	puts((mn == mx && (tot&1) ? "IMPOSSIBLE" : "POSSIBLE"));
	return 0;
}

Measured memory_bytes: 22784
program bt;

var s:string;
    t:byte;
    
begin
   readln(s);
   t:=0;
   if (pos('R',S)<>0) then t:=1;
   if (pos('RR',S)<>0) then t:=2;
   if (pos('RRR',S)<>0) then t:=3;
   write(t);
end.

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

ll ans = 0;

//hは体力、numは敵の数
void hit(ll h,ll num){
  if(h==1){ans+=num; return;}
  else{
    ans += num;
    hit(h/2, num*2);
  }
}

int main()
{
  ll H; cin >> H;
  hit(H,1);

  cout << ans << endl;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n; cin>>n;
	vll x(n), y(n);
	rep(i, n) cin>>x[i]>>y[i];
	map<pll, ll> diff;
	rep(i, n){
		for(int j=i+1; j<n; j++){
			diff[mp(x[i]-x[j], y[i]-y[j])]++;
			diff[mp(x[j]-x[i], y[j]-y[i])]++;
		}
	}
	ll maxi = 0;
	for(auto itr=diff.begin(); itr!=diff.end(); itr++){
		maxi = max(maxi, itr->se);
	}

	cout << n-maxi << "\n";
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    int ttlT=0, ttlH=0;
    for(int i=0; i<n; i++){
        string t, h;
        cin >> t >> h;
        if(t==h) {
            ttlT++;
            ttlH++;
        }
        if(t<h) ttlH+=3;
        if(t>h) ttlT+=3;
    }
    cout << ttlT << " " << ttlH << endl;
    return 0;
}




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

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H,W,K;cin>>H>>W>>K;
    vector<string> S(H);
    vector<vector<int>> sum(H+1,vector<int>(W+1));
    for(int i=0;i<H;i++) cin>>S[i];
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(S[i][j]=='1') sum[i+1][j+1]++;
        }
    }
    
    for(int i=1;i<=H;i++){
        for(int j=0;j<=W;j++){
            sum[i][j]+=sum[i-1][j];
        }
    }
    
    for(int j=1;j<=W;j++){
        for(int i=0;i<=H;i++){
            sum[i][j]+=sum[i][j-1];
        }
    }
    
    int ans=INF;
    
    for(int bit=0;bit<(1<<(H-1));bit++){
        int last=0;
        
        int cut=__builtin_popcount(bit);
        
        int j=1;
        
        while(j<=W){
            bool ok=true;
            
            for(int i=0;i<H;i++){
                int cnt=sum[i+1][j]+sum[i][last]-sum[i+1][last]-sum[i][j];
                
                while((bit&(1<<i))==0&&i<H-1){
                    i++;
                    cnt+=sum[i+1][j]+sum[i][last]-sum[i+1][last]-sum[i][j];
                }
                
                if(cnt>K) ok=false;
                
                //cout<<bit<<" "<<j<<" "<<cnt<<endl;
            }
            
            if(ok) j++;
            else{
                if(j-last==1){
                    cut=INF;
                    break;
                }
                else{
                    j--;
                    cut++;
                    last=j;
                    j++;
                }
            }
        }
        //cout<<bit<<" "<<cut<<endl;
        ans=min(ans,cut);
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define fs first
#define sc second

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main(){
	int a; cin >> a;
	cout << a + a * a + a * a * a << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
main()
{
    ll n,m,a=0,b=0,temp=0,prev,ans,i;
    scanf("%lld %lld",&n,&m);
    ll len[n],wid[m];
    for(i=0;i<n;i++)
    {
        scanf("%lld",&len[i]);
    }
    sort(len,len+n);
    for(i=0;i<m;i++)
    {
        scanf("%lld",&wid[i]);
    }
    sort(wid,wid+m);

    for(i=1;i<n;i++)
    {
       a=a+(len[i]-len[0]);
       //printf("%lld\n",a);
    }
    temp=a;
    for(i=1;i<n;i++)
    {
      prev=temp;
      temp=prev-(n-i)*(len[i]-len[i-1]);
      a=a%mod+temp%mod;
      //printf("%lld\n",a);
    }

    for(i=1;i<m;i++)
    {
       b=b+(wid[i]-wid[0]);
       //printf("%lld\n",b);
    }
    temp=b;
    for(i=1;i<m;i++)
    {
      prev=temp;
      temp=prev-(m-i)*(wid[i]-wid[i-1]);
      b=b%mod+temp%mod;
      //printf("%lld\n",b);
    }
    ans=((a%mod)*(b%mod))%mod;
    printf("%lld\n",ans);
}


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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define dump(a) cout << a << endl; 

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0; true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void ansYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void ansYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Int euclidean_gcd(Int a, Int b) {
	while (true) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

typedef pair<int, int> pai;


//ここまでライブラリ
//ここから本文
int main() {
	string s;
	cin >> s;
	s.at(5) = ' ';
	s.at(13) = ' ';
	dump(s);
}

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

int main(){
  int N,K;
  cin >> N >> K;
  int rec = 1;
  for(int i = 0; i < N; ++i){
    if(rec + K > 2 * rec) rec = 2 * rec;
    else rec += K;
  }
  cout << rec << endl;

}


Measured memory_bytes: 256
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  int Q,H,S,D,N;
  cin >> Q >> H >> S >> D >> N;
  int L1_cost=min(min(4*Q,2*H),S);
  int L2_cost=min(2*L1_cost,D);

  cout << (ll)L2_cost*(N/2)+(ll)L1_cost*(N%2) << endl;

  return 0;
}


Measured memory_bytes: 3644
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	a+=b;c+=d;
	if(a>c)cout<<"Left";
	else if(c>a) cout<<"Right";
	else cout<<"Balanced";
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3596
s = str(input())
length = len(s)

bins = []
for i in range(2**(length-1)):
    bins.append(list(str(format(i,'b')).zfill(length-1)))

for i in range(2**(length-1)):
    tmp_str=s[0]
    tmp_ans=int(s[0])
    for j in range(length-1):
        if(bins[i][j]=='0'):
            tmp_str += '+'+s[j+1]
            tmp_ans += int(s[j+1])
        else:
            tmp_str += '-'+s[j+1]
            tmp_ans -= int(s[j+1])
    if(tmp_ans == 7):
        ans = tmp_str

print(ans+'=7')

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

int f(ll a, ll b){
	int counta=0, countb=0;
	while(a>0){
		a/=10;
		counta++;
	}
	while(b>0){
		b/=10;
		countb++;
	}
	return max(counta, countb);
}

int main(){
	ll n, a, b;
	int ans=10;
	cin>>n;
	for(a=1; a*a<=n; a++){
		if(n%a==0){
			b=n/a;
			ans=min(ans, f(a, b));
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define pf printf
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "

using namespace std;
///check n=1;
///check corner case;
pair<ll,ll>check[200000];
int main()
{
    ll n,k;
    cin>>n>>k;
    if(n>=10)cout<<k<<endl;
    else cout<<k+(100*(10-n))<<endl;
return 0;
}





Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>

using namespace std;


int main() {
	int num;
	int data[100];
	scanf("%d", &num);

	for (int i = 0; i < num; i++) {
		scanf("%d", &data[i]);
	}

	for (int i = num - 1; i > -1; i--) {
		if (i == num -1) {
			cout << data[i];
		}
		else {
			cout << " " << data[i];
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 3160
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int n; cin >> n;
    map<int, int> mp[2];
    rep(i, n) {
        int x;
        cin >> x;
        mp[i & 1][x] ++;
    }
    vector<P> v[2];
    rep(u, 2) {
        for(auto &p : mp[u]) {
            v[u].pb(P((int)p.sc, (int)p.fr));
        }
        if(v[u].size() == 1) {
            v[u].pb(P(0, -1));
        }
        sort(v[u].rbegin(), v[u].rend());
    }
    int ans = 0;
    rep(i, 2) {
        rep(j, 2) {
            if(v[0][i].sc != v[1][j].sc) {
                ans = max(ans, v[0][i].fr + v[1][j].fr);
            }
        }
    }
    cout << n - ans << endl;
	return 0;
}

Measured memory_bytes: 6140
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n);
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end());
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define reverse(a)      reverse((a).begin(), (a).end());
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d);
#define outl(d)         std::cout<<(d)<<"\n";
#define Yes()           printf("Yes\n");
#define No()            printf("No\n");
#define YES()           printf("YES\n");
#define NO()            printf("NO\n");
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int a, b; cin >> a >> b;
  if (a + b >= 10) {
    outl("error")
  } else {
    outl(a + b)
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12)

  solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define sz(v) (long long)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

string A;
int main(){
    cin >> A;
    map<char,ll> box;
    ll total = (sz(A)-1)*sz(A)/2;
    rep(i,sz(A)) box[A[i]]++;
    repi(i,'a','z') total -= box[i]*(box[i]-1)/2;
    cout << total+1 << '\n';
}

Measured memory_bytes: 720
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cassert>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

vector<P> graph[500005];
unordered_map<ll, int> mp;
vector<int> len;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m, k; cin >> n >> m;
  int num = n+1;
  rep(i, m) {
    ll p, q, c; cin >> p >> q >> c;
    ll pc = p*mod+c;
    ll qc = q*mod+c;
    int pp, qq;
    pp = mp[pc];
    if (pp == 0) {
      mp[pc] = pp = num;
      num++;
    }
    qq = mp[qc];
    if (qq == 0) {
      mp[qc] = qq = num;
      num++;
    }
    
    //debug(p); debug(q); debug(c); debug(pp); debugln(qq);
    graph[pp].emplace_back(qq, 0);
    graph[qq].emplace_back(pp, 0);
    graph[p].emplace_back(pp, 1);
    graph[pp].emplace_back(p, 0);
    graph[q].emplace_back(qq, 1);
    graph[qq].emplace_back(q, 0);
  }

  len.resize(num+1, INT_MAX/2);

  priority_queue<P, vector<P>, greater<>> que;
  que.emplace(0, 1);
  len[1] = 0;
  while(!que.empty()) {
    P p = que.top(); que.pop();
    int u = p.second;
    int l = p.first;
    if (len[u] < l) continue;
    for(auto e: graph[u]) {
      int v = e.first;
      int newlen = l + e.second;
      if (newlen < len[v]) {
        len[v] = newlen;
        que.emplace(newlen, v);
      }
    }
  }

  if (len[n] == INT_MAX/2) {
    cout << -1 << endl;
  } else {
    cout << len[n] << endl;
  }
}

Measured memory_bytes: 65764
#include <stdio.h>
int min(int x, int y) { return x < y ? x : y; }
int main() {
	int n, a, b, p, cnt1 = 0, cnt2 = 0, cnt3 = 0;
	scanf("%d%d%d", &n, &a, &b);
	for (int i = 0; i < n; i++) {
		scanf("%d", &p);
		if (p <= a) {
			cnt1++;
		} else if (p <= b) {
			cnt2++;
		} else {
			cnt3++;
		}
	}
	printf("%d\n", min(cnt1, min(cnt2, cnt3)));
	return 0;
}

Measured memory_bytes: 128
while True:
        H, W = map(int, input().split())
        if H == 0 and W == 0:
                break
        countH, countW = 0, 0
        while True:
                if countH == H:
                        break
                if countH == 0 or countH == H - 1:

                        while True:
                                if countW == W:
                                        print('')
                                        break
                                print('#',end='')
                                countW += 1
                else:
                        print('#',end='')
                        while True:
                                if countW == W - 2:
                                        break
                                print('.',end='')
                                countW += 1
                        print('#')
                countW = 0
                countH += 1
        print('')

Measured memory_bytes: 9092
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
  int H,W;
  cin >> H >> W;

  vector<string> V;
  int i,s,t,u;

  for(i=0;i<H;i++){
    string A;
    cin >> A;
    V.push_back(A);
  }
  for(s=0;s<W+1;s++){
    cout << "#";
    }
  cout << "#" << endl;
  for(t=0;t<H;t++){
    cout << "#"+V[t]+"#" << endl;
  }
  for(u=0;u<W+1;u++){
    cout << "#";
  }
  cout << "#" << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        if(a == 1){
            a = 14;
        }

        if(b == 1){
            b = 14;
        }

        if(a > b){
            System.out.println("Alice");
        } else if(b > a){
            System.out.println("Bob");
        } else {
            System.out.println("Draw");
        }
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int x, y;
    cin >> x >> y;
    // 4a + 2b = y
    // a + b = x
    // 2a + 2b = 2x
    // 2a = y - 2x
    // a = (y - 2x) / 2
    int a = (y - 2 * x) / 2;
    int b = x - a;
    yorn (a >= 0 && b >= 0 && 4 * a + 2 * b == y)
    return 0;
}

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

int main(void){
    int n, sum = 0;
    
    cin >> n;
    
    vector<int> a(n), b(n), c(n);
    
    rep(i, n){
        cin >> a.at(i);
    }
    rep(i, n){
        cin >> b.at(i);
    }
    rep(i, n){
        cin >> c.at(i);
    }
    
    rep(i, n){
        sum += b.at(a.at(i)-1);
        if(i != 0 && a.at(i) == a.at(i-1)+1){
            sum += c.at(a.at(i-1)-1);
        }
    }
    
    cout << sum << endl;
    
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)

#define ALL(v) v.begin(), v.end()

int main() {
  std::cout << std::fixed << std::setprecision(20);

  int x, n;
  cin >> x >> n;
  if(n == 0){
    cout << x << endl;
    return 0;
  }
  vector<int> p(n);
  REP(i,n) cin >> p[i];

  sort(ALL(p));
  
  for(int i = 0; ; i++){
    int t;
    t = x - i;
    if(!binary_search(ALL(p),t)){
      cout << t << endl;
      return 0;
    }
    t = x + i;
    if(!binary_search(ALL(p),t)){
      cout << t << endl;
      return 0;
    }
  }

}

Measured memory_bytes: 3600
#include<iostream>

int main(){
    int i,n,x;

    std::cin>>n;

    for(i=1;i<=n;i++){
        x=i;
        if(x%3==0){
            std::cout<<" "<<i<<std::flush;
        }else{
            while(x*10/10!=0){
                if(x%10==3){
                    std::cout<<" "<<i<<std::flush;
                    break;
                }
                x=x/10;
            }
        }
    }
    std::cout<<std::endl;
}


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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0001

int main() {
	int arr[10];
	for (int i = 0; i < 10; i++) cin >> arr[i];
	for (int i = 0; i < 9; i++)
		for (int j = 1; j <= 9; j++) {
			if (arr[j - 1] < arr[j]) {
				int t = arr[j];
				arr[j] = arr[j - 1];
				arr[j - 1] = t;
			}
		}
	
	for (int i = 0; i < 3; i++) cout << arr[i] << endl;
	return 0;
}

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

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

    cout << ((a+b+c>=22)? "bust" : "win") << endl;
}


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

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class ACalc {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int a;
        in>>a;
        out<<a+a*a+a*a*a<<'\n';
    }
};


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


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
vector<int> yoyo;
int main(){
    yoyo.clear();
    int a,b,c;
    cin>>a>>b>>c;
    int count=0;
    for(int i=1;i<=min(a,b);i++){
        if(a%i==0&&b%i==0){
            yoyo.push_back(i); 
            count++;
        }
    }
    cout<<yoyo[count-c]<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
#include <chrono>
#include <random>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repr(i, a, b) for (int i = (int)a; i > (int)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 4e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;

bool debug = true;

random_device rnd;
mt19937_64 mt(rnd());

ll c[26], s[370][26], D, last[26];

void input(){
    cin >> D;
    rep(i, 26) cin >> c[i];
    rep(i, D) rep(j, 26) cin >> s[i][j];
}

void make_input(){
    rep(i, 365) c[i] = mt() % 101;
    rep(i, 365) rep(j, 26) s[i][j] = mt() % 20001;
}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    D = 365;
    input();
    rep(i, 26) last[i] = -1;
    vll t(D, 0);
    rep(i, D) cin >> t[i];
    vll v(D, 0);
    rep(i,D){
        t[i]--;
        if (i>0)
            v[i] = v[i - 1];
        v[i] += s[i][t[i]];
        last[t[i]] = i;
        rep(j, 26) v[i] -= c[j] * (i - last[j]);
    }
    rep(i, D) cout << v[i] << ENDL;
}

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

int main() {
  string s;
  cin >> s;
  int a, b;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A') {
      a = i;
      break;
    }
  }
  for (int i = s.size() - 1; i > 0; i--) {
    if (s[i] == 'Z') {
      b = i;
      break;
    }
  }
  cout << b - a + 1 << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
long long n;
int cnt,ac[1000],res;
int main(){
	#ifndef DavidLaptop
		#ifdef FILIN
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=0;i<=20;i++){
		for(int j=i*(i+1)/2;j<(i+1)*(i+2)/2;j++)
			ac[j]=i;
	}
	res=0;
	for(long long x=2;x*x<=n;x++){
		cnt=0;
		while(n%x==0){
			n/=x;
			cnt++;
		}
		res+=ac[cnt];
	}
	if(n!=1) res+=ac[1];
	cout<<res<<endl;
	return 0;
}



Measured memory_bytes: 3656
#include<stdio.h>

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

    scanf("%d%d%d",&a,&b,&c);

    int poor = 0;
    if(a == b && a != c) poor =1;
    if(b == c && b != a) poor =1;
    if(c == a && c != b) poor =1;

    if (poor){
        puts("Yes");
    }else{
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
    struct card
    {
        char suit;
        int value;
    }in[36], out1[36], out2[36], temp;
    int n, i, j, min;
    char ch;

    scanf("%d", &n);
    ch=getchar();
    for(i=0; i<n; i++)
    {
        scanf("%c%d", &in[i].suit, &in[i].value);
		ch=getchar();
        out1[i]=out2[i]=in[i];
    }

    //BubbleSort
    for(i=0; i<n; i++)
    {
        for(j=n-1; j>=i+1; j--)
            if(out1[j].value<out1[j-1].value)
            {
                temp=out1[j];
                out1[j]=out1[j-1];
                out1[j-1]=temp;
            }
    }
    for(i=0; i<n-1; i++)
        printf("%c%d ", out1[i].suit, out1[i].value);
    printf("%c%d\nStable\n", out1[i].suit, out1[i].value);

    //SelectionSort
    for(i=0; i<n-1; i++)
    {
        min=i;
        for(j=i+1; j<n; j++)
            if(out2[j].value<out2[min].value) min=j;
        if(min!=i)
        {
            temp=out2[i];
            out2[i]=out2[min];
            out2[min]=temp;
        }
    }
    for(i=0; i<n-1; i++)
        printf("%c%d ", out2[i].suit, out2[i].value);
    printf("%c%d\n", out2[i].suit, out2[i].value);
    for(i=0; i<n; i++)
        if(out1[i].suit != out2[i].suit)
        {
            printf("Not stable\n");
            break;
        }
    if(i==n) printf("Stable\n");

    return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
map<pair<int,int>,int> m;
vector<vector<int>> v;
vector<int> ans;
bool vi[100001]={false};
void dfs(int r,int c,int co)
{
 if(vi[r])
 return;
 vi[r]=true;
 ans[r]=co;
 for(int i=0;i<v[r].size();i++)
 {
  if(!vi[v[r][i]]){
  if(m[{r,v[r][i]}]%2)
  dfs(v[r][i],m[{r,v[r][i]}]%2,(co+1)%2);
  else
  dfs(v[r][i],m[{r,v[r][i]}]%2,co);
 }}
}
int main(void){
    // Your code here!
 int i,n,t,x,y,w;
 cin >> n;
 t=n-1;
 v.resize(n);
 ans.resize(n);
 while(t--)
 {
  cin >> x >> y >> w;
  x--;
  y--;
  v[x].push_back(y);
  v[y].push_back(x);
  m[{x,y}]=m[{y,x}]=w;
 }
 dfs(0,0,0);
 for(i=0;i<n;i++)
 cout << ans[i] << '\n';
 return 0;
}

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

int main() {
  int n;
  cin >> n;
  set<int> prices;
  for (int i = 0; i < 26; ++i) {
    for (int j = 0; j < 15; ++j) {
      prices.insert(4 * i + 7 * j);
    }
  }
  cout << (prices.find(n) != prices.end() ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
long long a,b,n;
cin>>a>>b>>n;
long long temp=b;
long long ans;
if(n>=b){
  temp=b-1;
}
else{
  temp=n;
}
ans=(a*temp/b)-a*(temp/b);
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 3596
package main

import (
	"fmt"
	"sort"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	nums := []int{a, b, c}
	sort.Sort(sort.IntSlice(nums))
	fmt.Println(nums[0], nums[1], nums[2])
}



Measured memory_bytes: 1132
def init(N, parent, rank):
    for i in range(N):
        parent.append(i)
        rank.append(0)
    return parent, rank

def find(parent, v):
    if parent[v] == v:
        return v
    else:
        parent[v] = find(parent, parent[v])
        return parent[v]

def unite(parent, rank, a, b):
    a = find(parent, a)
    b = find(parent, b)
    if a == b:
        return 
    elif rank[a] < rank[b]:
        parent[a] = b
        return parent
    elif rank[a] > b:
        parent[b] = a
        return parent
    else:
        parent[b] = a
        rank[a] += 1
        return parent, rank

def union_find():
    N, Q = [int(i) for i in input().split()]
    parent = []
    rank = []
    init(N, parent, rank)
    for i in range(Q):
        P, A, B = [int(i) for i in input().split()]
        if P == 0:
            unite(parent, rank, A, B)
        else:
            a = find(parent, A)
            b = find(parent, B)
            if a == b:
                print("1")
            else:
                print("0")

if __name__ == "__main__":
    union_find()



Measured memory_bytes: 6184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fastio() ios::sync_with_stdio(0);cin.tie(0);
#define nl "\n"
#define wi(x) cerr << #x << " is " << x << nl
const double eps = 1e-6;
const int mod = 1e9 + 7;

void solve(){
	int h,w; cin >> h >> w;
	char mat[h][w];
	rep(i,0,h-1){
		rep(j,0,w-1) cin >> mat[i][j];
	}
	int dp[h][w];
	bool flag = false;
	rep(c,0,w-1){
		if(mat[0][c] == '#') flag = true;
		dp[0][c] = ((flag) ? 0 : 1);
	}
	flag = false;
	rep(r,0,h-1){
		if(mat[r][0] == '#') flag = true;
		dp[r][0] = ((flag) ? 0 : 1);
	}
	
	rep(r,1,h-1){
		rep(c,1,w-1){
			if(mat[r][c] == '#') dp[r][c] = 0;
			else dp[r][c] = (dp[r][c-1] + dp[r-1][c])%mod;
		}
	}
	
	cout << dp[h-1][w-1];
}

int main(){
	fastio()
	
	int T=1;
	//int T; cin>>T;
	while(T--) solve();

	return 0;
}


Measured memory_bytes: 8464
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    }
    else {
        gcd(b, a % b)
    }
}

fn lcm(a: u64, b: u64) -> u64 {
    a * b / gcd(a, b)
}

fn main(){
    let list: Vec<u64> = read_vec();
    let A = list[0];
    let B = list[1];
    let C = list[2];
    let D = list[3];
    
    let E = lcm(C, D);

    let a = (B / C | 0) - ((A - 1) / C | 0);
    let b = (B / D | 0) - ((A - 1) / D | 0);
    let c = (B / E | 0) - ((A - 1) / E | 0);
    
    println!("{}", (B - A + 1) - (a + b - c));
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll N,W;
	cin>>N>>W;
	
	ll w[N],v[N];
	ll sm=0;
	for(ll i=0;i<N;i++)
	{
		cin>>w[i]>>v[i];
		sm+=v[i];
	}
	ll dp[N][sm+5];
	for(ll i=0;i<N;i++)
	{
		for(ll j=0;j<sm+5;j++)
			dp[i][j]=1e16;
		if (w[i]<=W)
		dp[i][v[i]]=w[i];
	}

	for(ll i=1;i<N;i++)
	{
		for(ll j=0;j<=sm;j++)
		{
			dp[i][j]=min(dp[i][j],dp[i-1][j]);
			if (j-v[i]>=0 and dp[i-1][j-v[i]]+w[i]<=W)
				dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
		}
	}
	ll ans=0;
	for(ll j=sm;j>=0;j--)
	{
		for(ll i=0;i<N;i++)
		{
			if (dp[i][j]<=W)
				ans=max(ans,j);
		}
	}
	cout<<ans;
}

Measured memory_bytes: 78336
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = lines[0].split(" ")[0];
    var K = lines[0].split(" ")[1];

    console.log(N - K + 1)
});

Measured memory_bytes: 22332
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
    int n,x[100],i,xbar=0,ans,left,right,lvalue=0,rvalue=0;

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

    for ( i = 0; i < n; i++)
    {
        xbar+=x[i];
    }
    left=xbar/n;
    right=(xbar+n-1)/n;

    for ( i = 0; i < n; i++)
    {
        lvalue+=(x[i]-left)*(x[i]-left);
        rvalue+=(x[i]-right)*(x[i]-right);
    }

    printf("%d",(lvalue<rvalue)? lvalue:rvalue);

    return 0;
}

Measured memory_bytes: 128
def merge(A, left, mid , right):
  L = A[left:mid]
  R = A[mid:right]
  L.append(('J', 1000000001))
  R.append(('J', 1000000001))
  i = 0
  j = 0
  for k in range(left, right):
    if L[i][1] <= R[j][1]:
      A[k] = L[i]
      i += 1
    else:
      A[k] = R[j]
      j += 1

def merge_sort(A, p ,r):
  if p + 1 < r:
    m = (p + r) // 2
    merge_sort(A, p, m)
    merge_sort(A, m, r)
    merge(A, p, m, r)

def partition(A, p, r): 
  x = A[r][1]
  i = p - 1
  for j in range(p, r):
    if A[j][1] <= x:
      i += 1
      A[i], A[j] = A[j], A[i]
  A[i + 1], A[r] = A[r], A[i + 1]
  return i + 1

def quick_sort(A, p, r):
  if p < r:
    q = partition(A, p, r)
    quick_sort(A, p, q - 1)
    quick_sort(A, q + 1, r)

n = int(input())

cards = []

for i in range(n):
  card, rank = input().split(" ")
  cards.append((card, int(rank)))
copy_cards = cards[:]

quick_sort(cards, 0, len(cards) - 1)
merge_sort(copy_cards, 0, len(cards))

stable = True
for x, y in zip(cards, copy_cards):
  if x != y:
    stable = False
    print('Not stable')
    break

if stable:
  print('Stable')

for card in cards:
  print("{} {}".format(card[0], card[1]))


Measured memory_bytes: 17576
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int getSum(const vec<int, 2>& sum, int y, int x, int K) {
  int ys[3] = {y, y + K, 2 * K};
  int xs[3] = {x, x + K, 2 * K};
  int res = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if ((i + j) % 2 == 0) {
        int cnt = sum[ys[i]][xs[j]];
        if (i > 0) cnt -= sum[ys[i - 1]][xs[j]];
        if (j > 0) cnt -= sum[ys[i]][xs[j - 1]];
        if (i > 0 && j > 0) cnt += sum[ys[i - 1]][xs[j - 1]];
        res += cnt;
      }
    }
  }
  return res;
}

void sum2d(vec<int, 2>& sum) {
  int H = sum.size(), W = sum[0].size();
  for (int i = 1; i < H; i++)
    for (int j = 1; j < W; j++)
      sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
}

int main() {
  int N, K;
  while (cin >> N >> K) {
    vec<int, 2> sumB = make_v(2 * K + 1, 2 * K + 1, 0);
    vec<int, 2> sumW = make_v(2 * K + 1, 2 * K + 1, 0);
    int blackCount = 0, whiteCount = 0;
    for (int i = 0; i < N; i++) {
      int x, y;
      char c;
      cin >> x >> y >> c;
      x %= 2 * K;
      y %= 2 * K;
      if (c == 'B') {
        ++blackCount;
        ++sumB[x + 1][y + 1];
      } else {
        ++whiteCount;
        ++sumW[x + 1][y + 1];
      }
    }
    sum2d(sumB);
    sum2d(sumW);
    int res = 0;
    for (int y = 0; y <= K; y++) {
      for (int x = 0; x <= K; x++) {
        int score1 =
            getSum(sumB, y, x, K) + (whiteCount - getSum(sumW, y, x, K));
        res = max(res, score1);
        int score2 =
            getSum(sumW, y, x, K) + (blackCount - getSum(sumB, y, x, K));
        res = max(res, score2);
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 31616
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
ll a[300001];
ll sum1[300001],sum2[300001];
priority_queue<ll,vector<ll>,greater<ll> > pq;
int main(){
	ios::sync_with_stdio(0);
	int n;
	cin>>n;
	rep(i,3*n)
	cin>>a[i];
	ll sum=0ll;
	rep(i,n){
		sum+=a[i];
		pq.push(a[i]);
	}
	sum1[n-1]=sum;
	forn(i,n,3*n){
		pq.push(a[i]);
		sum+=a[i];
		sum-=pq.top();
		pq.pop();
		sum1[i]=sum;
	}
	sum=0ll;
	while(!pq.empty())pq.pop();
	for(int i=3*n-1;i>=2*n;i--){
		sum+=a[i];
		pq.push(-a[i]);
	}
	sum2[2*n]=sum;
	for(int i=2*n-1;i>=0;i--){
		pq.push(-a[i]);
		sum+=a[i];
		sum-=-pq.top();
		pq.pop();
		sum2[i]=sum;
	}
	ll ans=-1e18;
	for(int i=n-1;i<2*n;i++){
		ans=max(ans,sum1[i]-sum2[i+1]);
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 7668
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl;
#define INF 1ll<<60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

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

int main(){
    int n;cin >> n;
    int p[n];

    int ans = 0, ma=0;
    rep(i, n){
        int p; cin >> p;
        ma = max(ma, p);
        ans += p;
    }

    out(ans-ma/2);
}

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

const int MAX_N = 10005, MAX_V = 200005;

class Edge {
public:
  int nxt, to;
} e[5000006];

class Data {
public:
  int pos, id, rid;
  inline friend bool operator < (const Data &a, const Data &b) {
    return a.pos < b.pos;
  }
} da[MAX_N << 1];

int head[MAX_V], cnt;
void addedge(int u, int v) {
  e[++cnt] = (Edge){head[u], v}, head[u] = cnt;
}

int N, X[MAX_N], Y[MAX_N], tot, in[MAX_V], out[MAX_V];
int dfn[MAX_V], dfs_clock, scc[MAX_V], scc_cnt, low[MAX_V];

void dfs(int u, int v) {
  static int st[MAX_V], top;
  dfn[u] = low[u] = ++dfs_clock;
  st[++top] = u;
  for (int i = head[u]; i; i = e[i].nxt)
    if (e[i].to != v) {
      if (!dfn[e[i].to]) {
	dfs(e[i].to, u);
	low[u] = min(low[u], low[e[i].to]);
      } else if (!scc[e[i].to]) {
	low[u] = min(low[u], dfn[e[i].to]);
      }
    }
  if (low[u] == dfn[u]) {
    ++scc_cnt;
    while (true) {
      scc[st[top--]] = scc_cnt;
      if (st[top + 1] == u) break;
    }
  }
}

void tarjan() {
  memset(scc, 0, sizeof scc);
  memset(dfn, 0, sizeof dfn);
  scc_cnt = dfs_clock = 0;
  for (int i = 1; i <= tot; ++i)
    if (!dfn[i]) dfs(i, 0);
}

void build(int l, int r, int x) {
  in[x] = ++tot, out[x] = ++tot;
  if (l == r) {
    in[x] = da[l].rid, out[x] = da[l].id;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, x << 1), build(mid + 1, r, x << 1 | 1);
  addedge(in[x], in[x << 1]), addedge(in[x], in[x << 1 | 1]);
  addedge(out[x << 1], out[x]), addedge(out[x << 1 | 1], out[x]);
}

void work(int l, int r, int L, int R, int x, int id, int rid) {
  if (L <= l && r <= R) {
    addedge(id, in[x]), addedge(out[x], rid);
    return;
  }
  int mid = (l + r) >> 1;
  if (mid >= L) work(l, mid, L, R, x << 1, id, rid);
  if (mid < R) work(mid + 1, r, L, R, x << 1 | 1, id, rid);
}

bool check(int mid) {
static int cp[MAX_V], temp;
  memcpy(cp, head, sizeof head), temp = cnt;
  
  for (int i = 1; i <= N << 1; ++i) {
    int l = upper_bound(da + 1, da + i + 1, (Data){da[i].pos - mid, 0, 0}) - da;
    int r = lower_bound(da + 1, da + N + N + 1, (Data){da[i].pos + mid, 0, 0}) - da - 1;
    if (l <= 0) l = 1;
    if (r > N + N) r = N + N;
    if (l < i) work(1, N + N, l, i - 1, 1, da[i].id, da[i].rid);
    if (r > i) work(1, N + N, i + 1, r, 1, da[i].id, da[i].rid);
  }
  
  bool flag = 1;
  tarjan();
  for (int i = 1; i <= N; ++i)
    if (scc[i] == scc[i + N]) flag = 0;
  memcpy(head, cp, sizeof head), cnt = temp;
  return flag;
}

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d%d", &X[i], &Y[i]);
    da[i] = (Data){X[i], i, i + N};
    da[i + N] = (Data){Y[i], i + N, i};
  }
  
  sort(da + 1, da + N + N + 1);
  tot = N << 1;
  build(1, N + N, 1);
  
  int l = 0, r = 1000000000, res = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid)) res = mid, l = mid + 1;
    else r = mid - 1;
  }

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


Measured memory_bytes: 22272
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <queue>
using namespace std;

priority_queue<long> q;
int main(){
	while (true){
		char str[10]; scanf("%s",&str);
		if (strcmp(str, "insert")==0){
			long tmp; scanf("%ld",&tmp);
			q.push(tmp);
		}
		else if (strcmp(str, "extract")==0){
			cout << q.top() << '\n';
			q.pop();
		}
		else if (strcmp(str, "end")==0) break;
	}
}

Measured memory_bytes: 10940
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e2 + 5;

char s[8];

int main(){
    int n;
    scanf("%d", &n);
    printf("%d\n", (n / 500) * 1000 + 5 * ((n % 500) / 5));
}

Measured memory_bytes: 256