akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

int main() {
	int a, b, m;
	cin >> a >> b >> m;
	vector<int>as(a);
	vector<int>bs(b);
	FOR(i, 0, a-1) {
		cin >> as[i];
	}
	FOR(i, 0, b - 1) {
		cin >> bs[i];
	}
	int res = INF;
	FOR(i, 1, m) {
		int x, y, c;
		cin >> x >> y >> c;
		res = min(res, as[x - 1] + bs[y - 1] - c);
	}
	sort(ALL(as));
	sort(ALL(bs));
	res = min(res, as[0] + bs[0]);
	pv(res)
	return 0;
}

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

T = [[0 for _ in range(N)] for _ in range(N)]

for i in range(N):
  for j in range(i + 1, N):
    if S[i] == S[j]:
      T[i][j] += T[i - 1][j - 1] + 1

answer = 0
for i in range(N):
  for j in range(N):
    if T[i][j] and j - i >= T[i][j]:
      answer = max(answer, T[i][j])
print(answer)

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

int main(){
    int n;
    cin >> n;
    int ans=0;
    for(int i=1;i<=n;i+=2){
        int cnt=0;
        for(int j=1;j<=i;j++){
            if(i%j==0){
                cnt++;
            }
        }
        if(cnt==8)
            ans++;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;

int main() {
    string s;
    cin >> s;
    string t;
    cin >> t;

    int cnt = 0;
    rep(i, s.size()){
        if(s.at(i) != t.at(i)){
            cnt++;
        }
    }


    cout << cnt << endl;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

const int nmax = 40, abmax = 10, inf = 1e6;

int n, ma, mb;
int a[nmax], b[nmax], c[nmax];
int dp[nmax+1][nmax*abmax+1][nmax*abmax+1];

void solve() {
   for (int i = 0; i < n; i++) {
      for (int ca = 0; ca <= nmax*abmax; ca++) {
         for (int cb = 0; cb <= nmax*abmax; cb++) {
            if (dp[i][ca][cb] == inf) continue;
            dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb]);
            chmin(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i]);
         }
      }
   }

   int ans = inf;
   for (int ca = 1; ca <= nmax*abmax; ca++) {
      for (int cb = 1; cb <= nmax*abmax; cb++) {
         if (ca*mb==cb*ma) chmin(ans, dp[n][ca][cb]);
      }
   }
   if (ans == inf) ans = -1;
   cout << ans << endl;
}

int main() {
   cin >> n >> ma >> mb;
   rep (i, n) cin >> a[i] >> b[i] >> c[i];

   for (int i = 0; i <= n; i++) {
      for (int ca = 0; ca <= nmax*abmax; ca++) {
         for (int cb = 0; cb <= nmax*abmax; cb++) {
            dp[i][ca][cb] = inf;
         }
      }
   }
   dp[0][0][0] = 0;

   solve();

   return 0;
}

Measured memory_bytes: 25984
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  vector<int>vec={a,b,c,d};
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  vector<int>vec2={e,f};
  sort(vec2.begin(),vec2.end());
  reverse(vec2.begin(),vec2.end());
  
  cout<<vec[0]+vec[1]+vec[2]+vec2[0]<<endl;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
 
#define INF INT_MAX
#define ll long long
 
using namespace std;
 
int main(){
	int A,B,C;
	cin >> A >> B >> C;
	int ans;
	if(B/A > C){
		ans = C;
	}else{
		ans = B/A;
	}
	cout << ans << endl;
 
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cctype>
#include <climits>
#include <fstream>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int> > vpii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;
int sum[5000];
int main(){
	int N;
	int ans = 0;
	while(cin>>N&&N){
		int index=0;
		ans = INT_MIN;
		FOR(i,1,N+1){
			cin>>sum[i];
			sum[i] += sum[i-1];
		}
		FOR(i,1,N+1){
			FOR(j,i,N+1){
				ans = max(ans,sum[j]-sum[i-1]);
			}
		}
		cout<< ans <<endl;
	}
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define PI 3.141592653589793
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const ll INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

struct UnionFind {
    vector<ll> par,rank,con;
    UnionFind(ll n) : par(n,-1),rank(n,0),con(n,1) { }
    ll root(ll x){
        if (par[x]<0)return x;
        return par[x]=root(par[x]);
    }
    bool unite(ll x,ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        con[x] += con[y];
        return true;
    }
    bool same(ll x,ll y){
        ll rx=root(x);
        ll ry=root(y);
        return rx==ry;
    }
    ll size(int x) {
        return -par[root(x)];
    }
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main(){
    ll n,m,k;
    cin >> n >> m >> k;
    vector<set<ll> > frs(n);
    UnionFind uf(n);
    for (ll i=0;i<m;i++){
        ll a,b;
        cin >> a >> b;
        if (a>b)swap(a,b);
        a--;
        b--;
        uf.unite(a,b);
        frs[a].insert(b);
        frs[b].insert(a);
    }
    for (ll i=0;i<k;i++){
        ll a,b;
        cin >> a >> b;
        if (a>b)swap(a,b);
        a--;
        b--;
        if (uf.same(a,b)){
            frs[a].insert(b);
            frs[b].insert(a);
        }
    }
    for (ll i=0;i<n;i++){
        ll count=uf.con[uf.root(i)]-1;
        count-=frs[i].size();
        cout << count << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 29044
#include<stdio.h>
#define N 101

int main(){

  int i,j,key = 0,count = 0,array[N],n;

  scanf("%d",&n);

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

  for(i = 0; i < n; i++){
    for(j = n-1; j > i; j--){
      
      if(array[j] < array[j-1]){
	key = array[j];
	array[j] = array[j-1];
	array[j-1] = key;
	count++;
      }

    }
  }

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

  return 0;

}

Measured memory_bytes: 0
n, a, b = map(int, input().split())
V = list(map(int, input().split()))
V.sort(reverse=True)

import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

ans = 0
x = 0
y = 0
for i in range(n):
    if i <= a-1:
        ans += V[i]
        if V[i] == V[a-1]:
            x += 1
            y += 1
    else:
        if V[i] == V[a-1]:
            x += 1

if V[0] != V[a-1]:
    cnt = combinations_count(x, y)
    print(ans/a)
    print(cnt)
else:
    cnt = 0
    for i in range(a, b+1):
        if i <= x:
            cnt += combinations_count(x, i)
    print(ans/a)
    print(cnt)

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

int main(void){

    int N,K;
    cin >> N >>K;
    
    int d;
    int A;
    map<int,int> mp;
    for(int i = 0; i < K;i++){
        cin >> d;
        for(int i = 0; i < d;i++){
            cin >> A;
            mp[A]++;
        }
    }
    
    int ans = 0;
    for(int i = 1; i <= N;i++){
        if(mp[i]==0)ans++;
    }

    cout << ans <<endl;
}


Measured memory_bytes: 3620
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007

int P,Q,R;
signed main(){
    scanf("%lld %lld %lld",&P,&Q,&R);
    int ans=P+Q+R-max(max(P,R),Q);
    printf("%lld",ans);
    return 0;
}


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

#define db double
const db eps = 1e-6;
int sgn(db a, db b = 0) {
	a -= b;
	return (a > eps) - (a < -eps);
}

struct poi {
	db x, y;
	void r() { cin >> x; cin >> y; }
	void w() { cout << x << ' ' << y << '\n'; }
	poi operator -(poi p) {
		return {x - p.x, y - p.y};
	}
	poi operator +(poi p) {
		return {x + p.x, y + p.y};
	}
	poi operator *(db d) {
		return {x * d, y * d};
	}
	poi operator /(db d) {
		return {x / d, y / d};
	}
	bool operator ==(poi p) {
		return !sgn(x, p.x) && !sgn(y, p.y);
	}
	db dot(poi p) {
		return x * p.x + y * p.y;
	}
	db cross(poi p) {
		return x * p.y - y * p.x;
	}
	db len() { return sqrt(x * x + y * y); }
	db len2() { return x * x + y * y; }
	poi proj(poi p, poi q) {
		db s = (*this - p).dot(q - p) / (q - p).len2();
		return p + (q - p) * s;
	}
	db dis(poi p, poi q) {
		if((*this - p).dot(q - p) < 0) return (*this - p).len();
		if((*this - q).dot(p - q) < 0) return (*this - q).len();
		return abs((*this - p).cross(q - p) / (q - p).len());
	}
};
db xmul(poi a, poi b, poi c) {
	return (b - a).cross(c - a);
}

int ccw(poi a, poi b, poi c) {
	poi u = b - a, v = c - a;
	if(u.cross(v) > eps) return 1;
	if(u.cross(v) < -eps) return -1;
	if(u.dot(v) < -eps) return -2;
	if(u.len2() + eps < v.len2()) return 2;
	return 0;
}
bool si(poi a, poi b, poi c, poi d) {
	return ccw(a, b, c) * ccw(a, b, d) <= 0 &&
		ccw(c, d, a) * ccw(c, d, b) <= 0;
}
poi li(poi a, poi b, poi c, poi d) {
	db u = xmul(c, d, a), v = xmul(c, d, b);
	return (a * v - b * u) / (v - u);
}

int main() {
	ios :: sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int T; cin >> T;
	while(T --) {
		poi p0, p1, p2, p3; p0.r(); p1.r(); p2.r(); p3.r();
		if(si(p0, p1, p2, p3))
			cout << "0\n";
		else
			cout << min({p0.dis(p2, p3), p1.dis(p2, p3),
				p2.dis(p0, p1), p3.dis(p0, p1)}) << '\n';
	}

	return 0;
}

Measured memory_bytes: 3304
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
 
using namespace std;

int main (){
    int N,k;
	cin >> N;

	cout << (N-2)*180 << endl;
}

Measured memory_bytes: 764
/*
これを入れて実行
g++ code.cpp
./a.out
*/

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <stack>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = { -1, 0, +1, 0 };
int dx4[4] = { 0, +1, 0, -1 };
int dy8[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
int dx8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
	if (r == 0 || r == n){
		return 1;
	}
	else if (r == 1){
		return n;
	}
	return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
	r = n - r;
	ll ret = 1;
	for (ll i = n; i >= r + 1; i--) ret *= i;
	return ret;
}

//-----------------------ここから-----------

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

	int pairs[10][10];
	for (int i = 0; i < 10; i++){
		for (int j = 0; j < 10; j++){
			pairs[i][j] = 0;
		}
	}

	for (int i = 1; i <= n; i++){
		string s = to_string(i);
		int f = s[0] - '0';
		int e = s[s.size() - 1] - '0';
		pairs[f][e]++;
	}

	int ans = 0;
	for (int i = 1; i < 10; i++){
		for (int j = 1; j < 10; j++){
			//cout << i << "-" << j << pairs[i][j] << endl;
			ans += pairs[i][j] * pairs[j][i];
		}
	}
	cout << ans << endl;
}



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

int search_only_this_layer(int g, vector<int> &p, vector<int> &c, int unit_score) {
  int p_last = p.at(unit_score-1);
  int c_last = c.at(unit_score-1);
  
  //この unit_score のみで解けるか？
  
  int r = g % unit_score;
  int j = (g-r)/unit_score;
  if ( r > 0 ) {
    j++;
  }
  if ( j < p_last ) {
    //すべて解かなくても達成できる場合
    return j;
  }
  int complete_score = unit_score * p_last + c_last;
  if ( complete_score >= g ) {
    //すべて解いて達成できる場合
    return p_last;
  }
  
  //達成できない場合
  return -1;
}

int search(int g, vector<int> &p, vector<int> &c, int unit_score) {
  if ( g <= 0 ) {
    return 0;
  }
  if ( unit_score == 0 ) {
    return -1;
  }

  //(i)この unit_score のみで解く場合
  int result = search_only_this_layer(g, p, c, unit_score);
  if ( unit_score == 1 ) {
    return result;
  }
  //(ii)この unit_score を0問解く場合
  int cand = search(g, p, c, unit_score-1);
  if ( cand >= 0 && (result < 0 || result > cand) ) {
    result = cand;
  }
  
  //(iii)この unit_score をすべて解く場合
  int p_last = p.at(unit_score-1);
  int c_last = c.at(unit_score-1);
  int complete_score = unit_score * p_last + c_last;
  int rest = search(g-complete_score, p, c, unit_score-1);
  if ( rest >= 0 ) {
  	cand = p_last + rest;
  	if ( result < 0 || result > cand ) {
    	result = cand;
  	}
  }
  
  return result;
}

int main() {
  int D, G;
  cin >> D >> G;
  int g = G/100;
  vector<int> p(D), c(D);
  rep(i,D) {
    int C;
    cin >> p.at(i) >> C;
    c.at(i) = C/100;
  }
  int answer = search(g, p, c, D);
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  int N, K; cin >> N >> K;
  vector<int> x(N); cin >> x;
  int vmin = 1e9;
  for (int i = 0; i + K - 1 < N; ++i) {
    int a = x[i], b = x[i + K - 1];
    if (a < 0 && b < 0) vmin = min(vmin, abs(a));
    if (a > 0 && b > 0) vmin = min(vmin, abs(b));
    else                vmin = min(vmin, abs(a) + abs(b) + min(abs(a), abs(b)));
  }
  cout << vmin << endl;
}


Measured memory_bytes: 3768
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;
const double PI = 3.1415926535;
const int MOD = 1000000007; // 計算してからmodで割る ans = (ans * a) % mod
#define int long long
template <typename T = long long > T in () { T x; cin >> x; return(x);}
// int a = in() のように使うlong long以外の型の時はstirng s = in<string>()のように型を指定する

signed main(void){
    int h, w; cin >> h >> w;
    vector<vector<char>> A(h, vector<char>(w));
    REP(i, h){
        REP(j, w) cin >> A[i][j];
    }

    int dp[h][w];
    REP(i, h) REP(j, w) dp[i][j] = 0;
    dp[0][0] = 1;

    REP(i, h){
        REP(j, w){
            if(A[i][j] == '.'){
                if(i + 1 < h) dp[i + 1][j] += dp[i][j] % MOD;
                if(j + 1 < w) dp[i][j + 1] += dp[i][j] % MOD;
            }
        }
    }

    cout << dp[h - 1][w - 1] % MOD << endl;
}

Measured memory_bytes: 9088
using System;
using System.Linq;

namespace _0517
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (x.Max() == 0) break;
                bool[] card = new bool[x[0] + 1]; int white = 0;
                for (int i = 0; i < x[1]; i++)
                {
                    int n = int.Parse(Console.ReadLine());
                    if (n == 0) white++;
                    else card[n] = true;
                }
                int ret = 0;
                for (int i = 1; i < x[0]; i++)
                {
                    int nokori = white + 1;
                    int j;
                    for (j = i; j < x[0]; j++)
                    {
                        if (!card[j]) nokori--;
                        if (nokori == 0) break;
                    }
                    if (j == x[0] && nokori > 0) j++;
                    ret = Math.Max(ret, j - i);
                }
                Console.WriteLine(ret);
            }
        }
    }
}

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

auto chmin = [](auto&& l, auto r) { return r < l ? l = r, 1 : 0; };

template <class T> struct dijkstra {
  struct edge {
    int to;
    T w;
  };
  vector<vector<edge>> g;
  const T inf;
  dijkstra(int n, T _inf = numeric_limits<T>::max()) : g(n), inf(_inf) {}
  void add_edge(int from, int to, T w) { g[from].push_back({to, w}); }
  void add_undirected_edge(int u, int v, T w) {
    add_edge(u, v, w), add_edge(v, u, w);
  }
  vector<T> run(int s) const {
    vector<T> dist(g.size(), inf);
    priority_queue<pair<T, int>, vector<pair<T, int>>, greater<>> pq;
    pq.emplace(dist[s] = 0, s);
    while (not pq.empty()) {
      T d;
      int v;
      tie(d, v) = pq.top(), pq.pop();
      if (d > dist[v]) continue;
      for (auto e : g[v])
        if (chmin(dist[e.to], dist[v] + e.w)) pq.emplace(dist[e.to], e.to);
    }
    return dist;
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  --s, --t;
  dijkstra<int> g(n);
  while (m--) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g.add_undirected_edge(u, v, 1);
  }
  auto ds = g.run(s), dt = g.run(t);
  vector<int> cs(n), ct(n);
  for (int v = 0; v < n; ++v) {
    if (ds[v] < n) {
      ++cs[ds[v]];
    }
    if (dt[v] < n) {
      ++ct[dt[v]];
    }
  }
  long long res = 0;
  for (int i = 0; i <= ds[t] - 2; ++i) {
    res += (long long)cs[i] * ct[ds[t] - 2 - i];
  }
  cout << res << '\n';
}



Measured memory_bytes: 11636
N = int(input())

d = []
for i in range(N):
    d.append(int(input()))

l = sorted(d, reverse = True)

m = []
for i in range(len(l)):
    if i == 0:
        m.append(l[i])
    elif m[-1] > l[i]:
        m.append(l[i])

print(len(m))


Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
char s[100005],s1[100005];
int main()
{
	cin>>s;
	int len=strlen(s),m=-1;
	for(int i=len-1;i>=0;i--)
	{
		s1[++m]=s[i];
		if(s1[m]=='b')s1[m]='d';
		else if(s1[m]=='d')s1[m]='b';
		else if(s1[m]=='p')s1[m]='q';
		else if(s1[m]=='q')s1[m]='p';
	}
	int p=1;
	for(int i=0;i<len;i++)
	{
		if(s[i]!=s1[i])p=0;
	}
	if(p)printf("Yes");
	else printf("No");
	//printf("%c%c%c%c",s1[0],s1[1],s1[2],s1[3]);
	
	
	
	return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}


//Graph in adjcency list (weighted)
class Graph{
public:
    int N;
    vector<vector<pair<int,ll>>> adjlist;
    vector<ll> depth;
    vector<bool> check;

    Graph(int n) : N(n), adjlist(n), depth(n, 0), check(n, false){}

    void setEdge(int a, int b, ll c){
        adjlist[a].push_back(make_pair(b, c));
    }

    void dfs(int p, int v, ll dist){
        //static vector<bool> check(N, false);
        if(check[v]){
            return;
        }
        check[v] = true;
        depth[v] = dist;
        for(auto i : adjlist[v]){
            if(i.first == p){
                continue;
            }
            dfs(v, i.first, dist + i.second);
        }
    }

    ll diam(int v){
        dfs(-1, v, 0);
        int u = max_element(all(depth)) - depth.begin();
        REP(i, N){
            check[i] = false;
            depth[i] = 0;
        }
        dfs(-1, u, 0);
        return MAX(depth);
    }
};

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

    Graph G(n);
    REP(i, n-1){
        int a, b;
        cin >> a >> b;
        G.setEdge(a-1, b-1, 1);
        G.setEdge(b-1, a-1, 1);
    }
    
    cout << (G.diam(0)%3 == 1 ? "Second" : "First") << endl;

}


Measured memory_bytes: 22144
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <climits>
#include <cmath>
#include <algorithm>
#include <cassert>

#define TEST_ASSERT(msg, cond) do { if (cond) { cout << msg << " => pass" << endl;} else { cout << msg << " => failed" << endl;} } while(0)

using namespace std;

int main() {

  int n;
  cin >> n;

  vector<int> a;
  for (int i = 0; i < n; i++) {
    int ai;
    cin >> ai;
    a.push_back(ai);
  }

  unordered_map<int, int> table;
  for (int i = 0; i < n; i++) {
    if (table.count(a[i]) > 0) {
      ++table[a[i]];
    }
    else {
      table[a[i]] = 1;
    }
  }

  long long sum = 0;
  for (unordered_map<int, int>::const_iterator itr = table.begin(); itr != table.end(); ++itr) {
    int x = itr->first;
    int numX = itr->second;
    if (numX < x) {
      sum += numX;
    }
    else if (numX > x) {
      sum += (numX - x);
    }
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 4624
#include <bits/stdc++.h>
using namespace std;
int n, c, p = 1000000007;
int a[420], b[420];
long long f[420][420];
int main() {
	f[0][0] = 1;
	scanf("%d%d", &n, &c);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < n; i++) {
		scanf("%d", &b[i]);
	}
	for (int i = 0; i < n; i++) {
		for (int j = a[i]; j <= b[i]; j++) {
			long long u = 0;
			for (int k = 0; k <= c; k++) {
				u = (u * j + f[i][k]) % p;
				f[i + 1][k] = (f[i + 1][k] + u) % p;
			}
		}
	}
	printf("%lld\n", f[n][c]);
	return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>

int main(void)
{
	int i,flag,save,N;
	int count=0;
	scanf("%d",&N);
	int data[100];

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

	flag=1;

	while(flag)
	{
		flag=0;
		for(i=N-1;i>0;i--)
		{
			if(data[i]<data[i-1])
			{
				save=data[i];
				data[i]=data[i-1];
				data[i-1]=save;
				count++;
				flag=1;
			}
		}
	}
	
	printf("%d",data[0]);
	for(i=1;i<N;i++)
	{
		printf(" %d",data[i]);
	}
	printf("\n");
	printf("%d\n",count);


}


Measured memory_bytes: 1932
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read(){
	char c=getchar();ll x=0,f=1;
	while(c<'0'||c>'9'){ if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return x*f;
}
ll n,x,ans;
int main(){
	n=read(),x=read();ans=n;
	ll a=n-x,b=x;
	while(1){
		if(a<b) swap(a,b);
	//	cout<<a<<' '<<b<<endl;
		ans+=a/b*2*b;
		if(a%b==0){
			ans-=b;
			break;
		}
		a=a%b;
		
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

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

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    string t;
    cin >> t;
    string s;
    rep(i, SZ(t)){
        if(t[i] == 'B'){
            if(i + 1 < SZ(t) && t[i+1] == 'C'){
                s.push_back('X');
                i++;
                continue;
            }
        }
        s.push_back(t[i]);
    }
    int n = SZ(s);

    int ans = 0;
    int cnt = 0;
    rep(i, n){
        if(s[i] == 'A'){
            cnt++;
            continue;
        }
        if(s[i] == 'X'){
            ans += cnt;
            continue;
        }
        cnt = 0;
    }
    cout << ans << endl;

    return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long int

void solve(ll caseNo)
{
    int n;
    cin >> n;
    cout << (n+1)%2 << endl;
    return;
}

int main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ll cases;
    cases = 1;
    for(ll i=1;i<=cases;i++)
    {
        solve(i);
    }
    return 0;
}

Measured memory_bytes: 3648
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));

        StringTokenizer st=new StringTokenizer(f.readLine());
        int n = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());

        int []weight=new int[n];
        int []value=new int[n];
        for(int i=0;i<n;i++){
            st=new StringTokenizer(f.readLine());
            weight[i]=Integer.parseInt(st.nextToken());
            value[i]=Integer.parseInt(st.nextToken());
        }

        long[][]dp=new long[n+1][k+1];
//        for(int i=0;i<n;i++){
//            dp[0][i]=
//        }
        for(int i=1;i<n+1;i++){
            for(int j=1;j<k+1;j++){
                dp[i][j]=dp[i-1][j];
                if(j-weight[i-1]>=0)
                dp[i][j]=Math.max(dp[i-1][j-weight[i-1]]+(long)value[i-1],dp[i][j]);
            }
        }
//        for(int i=0;i<n+1;i++){
//            System.out.println();
//            for(int j=0;j<k+1;j++){
//                System.out.print(dp[i][j]+" ");
//            }
//        }
        System.out.println(dp[n][k]);
        f.close();

        //print to System. out.println

    }

}


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

using namespace std;

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

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


//グローバルの置くと全部0で初期化される。
int dp[101][4][4][4];
      
int main(){

        int n;
        cin >> n;

        //長さ０の文字列は1である。
        //今回は0,1,2に関する規約しかないから、sは333sと考えて問題ない。
        dp[0][3][3][3] = 1;

        //iが文字列の文字数
        for(int i = 0; i < n; i++){
                for(int j = 0; j < 4; j++){
                        for(int k = 0; k < 4; k++){
                                for(int l = 0; l < 4; l++){
                                        //これ入れると早くなるからこれをつける癖をつけると良い。dp[0][3][3][3] まで飛ばされる。
                                        if(dp[i][j][k][l] == 0) continue;

                                        //新しく追加する文字列をaとする。
                                        for(int a = 0; a < 4; a++){
                                                //012
                                                if(a == 2 && l == 1 && k == 0) continue;
                                                //102
                                                if(a == 2 && l == 0 && k == 1) continue;
                                                //021
                                                if(a == 1 && l == 2 && k == 0) continue;
                                                //0?12
                                                if(a == 2 && l == 1 && j == 0) continue;
                                                //01?2
                                                if(a == 2 && k == 1 && j == 0) continue;
                                                dp[i+1][k][l][a] += dp[i][j][k][l];
                                                dp[i+1][k][l][a] %= mod;
                                        }
                                }
                        }
                }
        }

        int ans = 0;

        for(int j = 0; j < 4; j++){
                for(int k = 0; k < 4; k++){
                        for(int l = 0; l < 4; l++){
                                ans += dp[n][j][k][l];
                                ans %= mod;
                        }
                }
        }

        cout << ans << endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
   string s;
   cin>>s;s='#'+s;
   vector<ll> r(n+1,0),g(n+1,0),b(n+1,0);
   for(int i=1;i<=n;i++)
   {
       r[i]=r[i-1];
       g[i]=g[i-1];b[i]=b[i-1];
       if(s[i]=='R')
        r[i]++;
       else if(s[i]=='G')
        g[i]++;
       else
        b[i]++;
   }
   ll ans=0;
   for(int i=1;i<=n;i++)
   {
       for(int j=i+2;j<=n;j++)
       {
           if(s[i]!=s[j])
           {
               if((s[i]=='R' && s[j]=='G') || (s[i]=='G' && s[j]=='R'))
               {
                   ans+=(b[j]-b[i-1]);
                   if((i+j)%2==0 && s[(i+j)/2]=='B')
                    ans--;
               }
               else if((s[i]=='R' && s[j]=='B') || (s[i]=='B' && s[j]=='R'))
               {
                   ans+=(g[j]-g[i-1]);
                   if((i+j)%2==0 && s[(i+j)/2]=='G')
                    ans--;
               }
               else if((s[i]=='B' && s[j]=='G') || (s[i]=='G' && s[j]=='B'))
               {
                   ans+=(r[j]-r[i-1]);
                   if((i+j)%2==0 && s[(i+j)/2]=='R')
                    ans--;
               }
           }
       }
   }
   cout<<ans;
}



Measured memory_bytes: 3728
#include<stdio.h>
int main(void){
	
	int n,q;
    scanf("%d",&n);
    
    int S[n];
    int t;
	int count=0;
	int i,j;


	for(i=0;i<n;i++){
		scanf("%d",&S[i]);
	}
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&t);
		for(j=0;j<n;j++){
			if(t==S[j]){
				count++;
				break;
			}
		}
	}
    printf("%d\n",count);
}


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

int main()
{
    int cntA = 0, cntB = 0;
    string s;
    cin >> s;
    
    for(int i = 0; i < 3; i++)
    {
        if(s[i] == 'A')
            cntA = 1;
        if(s[i] == 'B')
            cntB = 1;
    }
    
    if(cntA && cntB)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define MAXLENGTH_STRING 100
#define MAXDEPTH_STACK 100
int stack[MAXDEPTH_STACK];
int top=0;
void push(int num){stack[top++] = num;}
int pop(){return stack[--top];}
int main()
{
    char str[MAXLENGTH_STRING];
    int a=0;
    while(scanf("%s", str)!=EOF)
    {
        if(isdigit(str[0])){push(atoi(str));}
        if(str[0]=='+'){push(pop()+pop());}
        if(str[0]=='-'){a=pop();push(pop()-a);}
        if(str[0]=='*'){push(pop()*pop());}
    }
    printf("%d\n", stack[0]);
    return 0;
}



Measured memory_bytes: 2108
n = int(input())
a = list(map(int, input().split()))

ans = 1
status = 0
prev = a[0]

for i in a:
    diff = i - prev

    if diff == 0:
        pass
    elif diff > 0:
        if status >= 0:
            status = diff
        else:
            ans += 1
            status = 0
    else:
        if status <= 0:
            status = diff
        else:
            ans += 1
            status = 0

    prev = i

print(ans)

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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

const double eps = 1e-10;
const int MOD = 1000000007;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, s.size()) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n; cin >> n;
  REP(i, n) {
    string s1, s2; cin >> s1 >> s2;
    int i1 = 0, i2 = 0;
    REP(i, SZ(s1)) {
      if(s1[i] == 'm') {
        if(i > 0 && '0' <= s1[i-1] && s1[i-1] <= '9') {
          i1 += 1000 * (s1[i-1] - '0');
        } else {
          i1 += 1000;
        }
      } else if(s1[i] == 'c') {
        if(i > 0 && '0' <= s1[i-1] && s1[i-1] <= '9') {
          i1 += 100 * (s1[i-1] - '0');
        } else {
          i1 += 100;
        }
      } else if(s1[i] == 'x') {
        if(i > 0 && '0' <= s1[i-1] && s1[i-1] <= '9') {
          i1 += 10 * (s1[i-1] - '0');
        } else {
          i1 += 10;
        }
      } else if(s1[i] == 'i') {
        if(i > 0 && '0' <= s1[i-1] && s1[i-1] <= '9') {
          i1 += 1 * (s1[i-1] - '0');
        } else {
          i1 += 1;
        }
      }
    }

    REP(i, SZ(s2)) {
      if(s2[i] == 'm') {
        if(i > 0 && '0' <= s2[i-1] && s2[i-1] <= '9') {
          i2 += 1000 * (s2[i-1] - '0');
        } else {
          i2 += 1000;
        }
      } else if(s2[i] == 'c') {
        if(i > 0 && '0' <= s2[i-1] && s2[i-1] <= '9') {
          i2 += 100 * (s2[i-1] - '0');
        } else {
          i2 += 100;
        }
      } else if(s2[i] == 'x') {
        if(i > 0 && '0' <= s2[i-1] && s2[i-1] <= '9') {
          i2 += 10 * (s2[i-1] - '0');
        } else {
          i2 += 10;
        }
      } else if(s2[i] == 'i') {
        if(i > 0 && '0' <= s2[i-1] && s2[i-1] <= '9') {
          i2 += 1 * (s2[i-1] - '0');
        } else {
          i2 += 1;
        }
      }
    }

    int ans = i1 + i2;
    vi res(4);
    RREP(i, 3) {
      res[i] = ans % 10;
      ans /= 10;
    }

    REP(i, 4) {
      if(res[i] == 0) continue;
      if(res[i] != 1) cout << res[i];
      switch(i) {
      case 0:
        cout << "m";
        break;
      case 1:
        cout << "c";
        break;
      case 2:
        cout << "x";
        break;
      default:
        cout << "i";
        break;
      }
    }
    cout << endl;

  }
}



Measured memory_bytes: 3036
H, W, A, B = list(map(int, input().split()))
p = 1000000007

fac = [1] * (H + W + 1)
x = 1
for i in range(1, H + W + 1):
    x *= i
    x %= p
    fac[i] = x

ifac = [1] * (H + W + 1)
x = fac[H + W]
q = p - 2

while q > 0:
    if q & 1:
        ifac[H + W] *= x % p
    x *= x % p
    q >>= 1

for i in range(H + W - 1, 0, -1):
    ifac[i] = ifac[i + 1] * (i + 1) % p

def com(a, b):
    return (fac[a] * ifac[b] * ifac[a-b]) % p

ans = 0

for i in range(H-A):
    ans += com(B+i-1, i) * com(W-B+H-i-2, H-i-1)
    ans %= p

print(ans)


Measured memory_bytes: 18804
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

const int N = 3003;
typedef long long LL;
const LL mo = 1000000007;

int n,m,Ans;
LL f[N][N][2];// i-th times (for m) last j block of R is Sepcial or not  

int main()
{

    cin >> n >> m; f[0][0][1] = 1;
    if (n == 1)
    {
        Ans = 2;
        for (int i = 1; i <= m; i++)
            Ans = Ans * 2 % mo;
        cout << Ans << endl; return 0;
	}else if(n>=m){
		Ans=2;
		for(int i=1;i<2*m;i++) Ans = Ans*2%mo;
		cout << Ans << endl; return 0;
	}
    for (int i = 1; i <= n; i++) f[0][i][0] = 1;
    for (int i = 1; i <= m; i++)// i-th times (for m) last j block of R is Sepcial or not  
    {
        f[i][0][1] = (f[i - 1][0][1]  + f[i - 1][1][1] + f[i - 1][1][0]) % mo;// R-
        
        f[i][1][0] = (f[i - 1][1][0] + f[i - 1][2][0]) % mo;// 
        f[i][1][1] = (f[i - 1][0][1] + 2LL * f[i - 1][1][1] + f[i - 1][2][1]+ f[i - 1][1][0]) % mo;//
        
		for (int j = 2; j < n; j++)
        {
            f[i][j][0] = (f[i - 1][j - 1][0] + 2LL * f[i - 1][j][0] + f[i - 1][j + 1][0]) % mo;
            f[i][j][1] = (f[i - 1][j - 1][1] + 2LL * f[i - 1][j][1] + f[i - 1][j + 1][1]) % mo;
        }
        f[i][n][0] = (f[i - 1][n - 1][0] + f[i - 1][n][0]) % mo;//
        f[i][n][1] = (f[i - 1][n - 1][1] + f[i - 1][n][1]) % mo;//
    }
    for (int i = 0; i <= n; i++)
        Ans += f[m][i][1],Ans %= mo;
    cout << Ans << endl;
    return 0;
}

Measured memory_bytes: 140032
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    string a,b,c; cin>>a>>b>>c;
    if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0])cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  string s;
  cin >> s;
  int a = 0, b = 0, c = 0;
  int n = s.length();
  for(int i = 0; i < n; i++) {
    if(s[i] == 'a') {
      a++;
    } else if(s[i] == 'b') {
      b++;
    } else {
      c++;
    }
  }
  // cout << a << " " << b << " " << c << endl;
  if(abs(max({a, b, c}) - min({a, b, c})) < 2) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
  return 0;
}

Measured memory_bytes: 512
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans=0;
    ll temp=0;
    temp+=(b/c);
    temp+=(b/d);
    temp-=b/(lcm(c,d));
    ans+=b-temp;
    temp=0;
    temp+=((a-1)/c);
    temp+=((a-1)/d);
    temp-=(a-1)/(lcm(c,d));
    ans-=(a-1-temp);
    cout<<ans;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main(){
    FAST
    ll n;
    cin>>n;
    ll x;
    map<ll,ll>m;
    for(int i=1;i<=n;i++){
        cin>>x;
        m[x]++;
    }
    int y,count1=0,count2=0;
    for(auto pair:m){
        if(m[pair.first]>2){
            y=m[pair.first];
            while(!(y<3)){
                y=y/3 + y%3;
            }
            m[pair.first]=y;
        }
        if(m[pair.first]==2)count1++;
        else count2++;
    }
    if(count1%2==0)cout<<count1+count2;
    else cout<<count1+count2-1;
    
}

Measured memory_bytes: 6528
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 

int main()
{ 
    int n,m;
    cin>>n>>m;
    if(m==0){cout<<0<<' '<<0<<endl;return 0;}
    int p[m];
    int s[m];
    for(int i=0;i<m;i++){
        cin>>p[i];
        string x;
        cin>>x;
        if(x=="WA"){s[i]=0;}
        else{s[i]=1;}
    }
    int ans=0;
    int wor[n+1];
    int flg[n+1];
    for(int i=0;i<=n;i++){flg[i]=0;wor[i]=0;}
    for(int i=0;i<m;i++){
        if(flg[p[i]]==0){
            if(s[i]==1){flg[p[i]]=1;ans++;}
            else{wor[p[i]]++;}
        }
    }
    int sum=0;
    for(int i=1;i<=n;i++){
        if(flg[i]==0){wor[i]=0;}
        sum=sum+wor[i];
    }
    cout<<ans<<' '<<sum<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
using namespace std;

#define DEBUG(x) cerr << #x << " = " << x << endl

typedef pair<int, int> P;

int main() {
    for(int N, M; cin >> N >> M, N + M != 0; ) {
        int R; cin >> R;
        vector<int> used(N, -1);
        map<int, vector<P> > histo;

        for(int i = 0; i < R; i++) {
            int t, n, m, s; cin >> t >> n >> m >> s;
            n--, m--;
            if(s == 1) {
                assert(used[n] == -1);
                used[n] = t;
            }
            else {
                assert(used[n] != -1);
                histo[m].push_back(make_pair(used[n], t));
                used[n] = -1;
            }
        }

        for(map<int, vector<P> >::iterator it = histo.begin(); it != histo.end(); ++it) {
            sort(it->second.begin(), it->second.end());
        }

#if 0
        for(map<int, vector<P> >::iterator it = histo.begin(); it != histo.end(); ++it) {
            DEBUG(it->first);
            for(vector<P>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
                DEBUG(it2->first);
                DEBUG(it2->second);
            }
        }
#endif


        int Q; cin >> Q;
        while(Q--) {
            int ts, te, m; cin >> ts >> te >> m;
            m--;
            int end = ts;
            vector<P> v = histo[m];
            int res = te - ts;
            for(int i = 0; i < (int)v.size(); i++) {
                if(v[i].first >= te) break;
                if(v[i].first <= end) {
                    if(v[i].second > end) {
                        res -= (v[i].second - end);
                        end = v[i].second;
                    }
                }
                else {
                    res -= v[i].second - v[i].first;
                    end = v[i].second;
                }
            }
            if(end > te) {
                res += (end - te);
            }
            cout << te - ts - res << endl;
        }
    }
}

Measured memory_bytes: 1220