akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0; i<(int)(n); ++i)
#define REP(i,m,n) for(ll i=(ll)(m); i<(ll)(n); ++i)
#define F first
#define S second
const double PI=acos(-1);
//fixed<<setprecision(11)<<

int main(){
  string s;cin>>s;
  
  if(s[0]==s[1]){
    cout<<"Bad"<<endl;
    return 0;
  }
  if(s[1]==s[2]){
    cout<<"Bad"<<endl;
    return 0;
  }
  if(s[2]==s[3]){
    cout<<"Bad"<<endl;
    return 0;
  }

  cout<<"Good"<<endl;
return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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

struct UnionFind {
  vector<ll> d;
  UnionFind(ll n = 0) : d(n, -1) {
  }
  ll find(ll x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(ll x, ll y) {
    return find(x) == find(y);
  }
  ll size(ll x) {
    return -d[find(x)];
  }
};

signed main() {
  init();
  ll N, M;
  cin >> N >> M;
  vector<P> p(M);
  rep(i, M) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    p[i] = {a, b};
  }

  ll ans = 0;
  rep(i, M) {
    UnionFind union_find(N);
    rep(j, M) {
      if (i == j) {
        continue;
      }
      union_find.unite(p[j].first, p[j].second);
    }

    bool flag = false;
    rep(k, N) {
      if (k == 0) {
        continue;
      }
      if (!union_find.same(k, k - 1)) {
        flag = true;
        break;
      }
    }
    if (flag) {
      ans++;
    }
  }

  COUT(ans);

  return 0;
}

Measured memory_bytes: 256
# Date [ 2020-08-15 21:13:42 ]
# Problem [ c.py ]
# Author Koki_tkg

import sys;      from decimal import Decimal
import math;     from itertools import combinations, product
import bisect;   from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 6 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b)

def Main():
    x, k, d = read_ints()
    x = abs(x)
    cnt = x // d
    if cnt < k:
        x -= cnt * d
    else:
        cnt = k
        x -= cnt * d
    if abs(x - d) < x and (k-cnt)%2 == 1:
        x = abs(x - d)
        cnt += 1
    
    if (k - cnt) % 2 == 0:
        print(x)
    elif x == 0:
        print(d)
    else:
        print(min(abs(x - d), x + d)) 

if __name__ ==  '__main__':
    Main()

Measured memory_bytes: 9940
#include <bits/stdc++.h>
#define ll long long
using namespace std;
pair <ll,ll> p[200005];
ll c[200005];
ll n,d,a;
main()
{
    cin>>n>>d>>a;
    d*=2;
    ll x,y;
    for(int i=1;i<=n;i++)
    {
        cin>>x>>y;
        y=(y+a-1)/a;
        p[i]={x,y};
    }

    sort(p+1,p+n+1);
    ll k=0,ans=0;
    ll l=1;
    for(int i=1;i<=n;i++)
    {
        while(l<i&&p[i].first-p[l].first>d) k-=c[l++];
        c[i]=p[i].second-k;
        if(c[i]<0) c[i]=0;
        ans+=c[i];
        k+=c[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
#include <typeinfo>
#include <cctype>

int grandy(long long int current, long long int max) {
	long long int lower = max / 2 + 1;
	assert(lower * 2 > max);
	assert((lower - 1) * 2 <= max);
	std::vector<int> pair(2);
	if (max % 2 == 0) {
		pair[0] = 0;
		pair[1] = 1;
	}
	else {
		pair[0] = 1;
		pair[1] = 0;
	}
	while (current < lower) {
		if (lower % 2 == 1) {
			int other = -1;
			if (std::find(pair.begin(), pair.end(), 0) == pair.end()) {
				other = 0;
			}
			else if (std::find(pair.begin(), pair.end(), 1) == pair.end()) {
				other = 1;
			}
			else {
				other = 2;
			}
			pair[0] = other;
			pair[1] = pair[1];
		}
		else {
			pair[1] = pair[0] == 0 ? 1 : 0;
			if (pair[0] == 2) {
				pair[0] = 1;
			}else {
				pair[0] = 2;
			}
		}
		lower = (lower + 1) / 2;
	}
	return current % 2 == 0 ? pair[0] : pair[1];
}

int main() {
	int n; std::cin >> n;
	int result = 0;
	for (auto i = 0; i < n; ++i) {
		long long int current, max; std::cin >> current >> max;
		result ^= grandy(current, max);
	}
	std::cout << (result != 0 ? "mo3tthi" : "tubuann") << std::endl;
}



Measured memory_bytes: 3120
import Control.Applicative ((<$>))
import qualified Control.Monad as Monad (forM, replicateM)

type Vector = [Int]
type Row = [Int]
type Matrix = [Row]

main = do
    [n,m] <- getLine'
    a <- Monad.replicateM n getLine'
    b <- toVector <$> Monad.replicateM m getLine'
    mapM_ print $ vectorAndMatrixProduct a b

getLine' :: IO [Int]
getLine' = map (read :: String -> Int) . words <$> getLine

toVector :: [[Int]] -> Vector
toVector = concat

vectorAndMatrixProduct :: Matrix -> Vector -> Vector
vectorAndMatrixProduct xs ys = toVector $ do
    Monad.forM [0..(length xs - 1)] $ \i -> dotProduct (xs !! i) ys

dotProduct :: Row -> Vector -> Row
dotProduct xs ys = return $ sum $ zipWith (*) xs ys


Measured memory_bytes: 7568
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(i==(n-1)){
    cout<<a[i];
    }
    else{
      cout<<a[i]<<" ";
    }
  }
  cout<<endl;
  
  for(int i=1;i<=n-1;i++){
    int v=a[i];
    int j=i-1;
    while(j>=0&&a[j]>v){
      a[j+1]=a[j];
      j--;
      a[j+1]=v;
    }
    for(int k=0;k<n;k++){
      if(k==(n-1)){
	cout<<a[k];
	}
      else{
	cout<<a[k]<<" ";
      }
    }
    cout<<endl;
  }
  return 0;
}

  

Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;scanf("%d",&n);
    long long sum=0;
    long long a[n];
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
        sum+=a[i];
    }
    long long now=a[0],ans=abs(sum-now*2);
    for(int i=1;i<n-1;i++){
        now+=a[i];
        ans=min(ans,abs(sum-now*2));
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    int64_t L0=2;
    int64_t L1=1;
    int64_t Ln;
    int N;
    cin>>N;
    if(N>1){
        for(int i=1;i<N;i++){
            Ln=L0+L1;
            L0=L1;
            L1=Ln;
        }
        cout<<Ln<<endl;
    }else{
        cout<<L1<<endl;
    }
  

}



Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (long long i = x; i < 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
typedef long long ll;
const int START_N = 97;
const int END_N = 122;

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

    string text;
    cin >> text;

    char c = START_N;
    bool a[26];
    bool b[26];
    int max = 0;

    rep(i, n - 1) {
        fill_n(a, 26, false);
        fill_n(b, 26, false);
        
        int res = 0;
        rep(j, n) {
            int num = text.at(j);
            num = num - START_N;

            if (j <= i) {
                a[num] = true;
            } else {
                if (a[num] == true && b[num] == false) {
                    res++;
                    b[num] = true;
                }
            }
        }

        if (res > max) {
            max = res;
        }
    }

    cout << max << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>

using namespace std;

int main() {
    vector<bool> v(30, false);
    for(int i = 0; i < 28; ++i) {
        int n;
        cin >> n;
        v[n-1] = true;
    }
    for(int i = 0; i < 30; ++i) {
        if(!v[i]) {
            cout << i+1 << endl;
        }
    }
    return 0;
}

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

int main() {
    using Int = long long;
    
    const Int mod = 1000000007;
    
    int n;
    cin >> n;
    
    map<int, int> m;
    
    m[0] = 3;
    
    Int ans = 1;
    
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        
        ans = (ans * m[a]) % mod;
        
        m[a]--;
        m[a+1]++;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=b-1;i>=a;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
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);}
//constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}



int main(){
  ll N;
  cin >> N ;
  if(N%10==3){
    cout << "bon" << endl;
  }
  else if((N%10 == 0 || (N%10 == 1 || (N%10 == 6 || (N%10 == 8))))){
    cout << "pon" << endl;
  }
  else {
    cout << "hon" << endl;
  }
}

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

#define ll long long
#define INF 1e9

void In_Out() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
}

void display_arr(std::vector<int> v) {
	for (auto ele : v) {
		cout << ele << " ";
	}
	cout << endl;
}

int min_cost(std::vector<int> &stones, int k) {
	int n = stones.size();
	int dp[100005] = {0};
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		dp[i] = INF;
		for (int j = 1; j <= k and i - j >= 0; j++) {
			int res = abs(stones[i] - stones[i - j]) + dp[i - j];
			dp[i] = min(dp[i], res);
		}
	}
	return dp[n - 1];
}

int main() {
	// In_Out();
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, k;
	cin >> n >> k;
	vector<int>stones(n);
	for (int i = 0; i < n; i++) {
		cin >> stones[i];
	}
	cout << min_cost(stones, k) << endl;
}

Measured memory_bytes: 3992
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N;
int MA;
int MB;
int A;
int B;
int C;
int dp[401][401];
int main(){
  int Lj4PdHRW, i;
  int res = 1073709056;
  rd(N);
  rd(MA);
  rd(MB);
  for(i=(0);i<(401);i++){
    int j;
    for(j=(0);j<(401);j++){
      dp[i][j] = 1073709056;
    }
  }
  dp[0][0] = 0;
  for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
    rd(A);
    rd(B);
    rd(C);
    for(i=(401)-1;i>=(A);i--){
      int j;
      for(j=(401)-1;j>=(B);j--){
        chmin(dp[i][j], dp[i-A][j-B] + C);
      }
    }
  }
  A = MA;
  B = MB;
  while(A <= 400 && B <= 400){
    chmin(res, dp[A][B]);
    A += MA;
    B += MB;
  }
  if(res==1073709056){
    wt_L(-1);
    wt_L('\n');
  }
  else{
    wt_L(res);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190921-1

// --- original code ---
// int N, MA, MB, A, B, C;
// int dp[401][401];
// {
//   int res = int_inf;
//   rd(N,MA,MB);
//   rep(i,401) rep(j,401) dp[i][j] = int_inf;
//   dp[0][0] = 0;
//   rep(N){
//     rd(A,B,C);
//     rrep(i,A,401) rrep(j,B,401) dp[i][j] <?= dp[i-A][j-B] + C;
//   }
//   A = MA;
//   B = MB;
//   while(A <= 400 && B <= 400){
//     res <?= dp[A][B];
//     A += MA;
//     B += MB;
//   }
//   wt( if[res==int_inf, -1, res] );
// }


Measured memory_bytes: 896
import java.util.Scanner;

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

        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();

        long ans = f(B, C, D) - f(A - 1, C, D);
        System.out.println(ans);
    }

    //X以下でC,Dのどちらでも割り切れない整数の個数を求める
    static long f(long X, long C, long D) {
        long quanty = X;
        quanty -= X / C;
        quanty -= X / D;
        //上2行でCDどっちでも割れる数の個数を
        // 2回引いたので同じものを一回足す
        quanty += X / lcm(C, D); 
        return quanty;
    }

    static long lcm(long C, long D) {
        return C * D / gcd(C, D);
    }

    static long gcd(long C, long D) {
        return D > 0 ? gcd(D, C % D) : C;
    }

}


Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#define MAXN 52
typedef long long ll;
ll MOD = 1000000007;
using namespace std;
int main(void) {
  int n;
  cin >> n;
  string s1, s2;
  vector<bool> domino;
  cin >> s1 >> s2;
  for (int i = 0; i < s1.length(); i++) {
    if (s1[i] == s2[i]) {
      domino.push_back(0);
    } else {
      domino.push_back(1);
      i++;
    }
  }
  ll answer;
  if (!domino[0]) {
    answer = 1LL * 3;
  } else {
    answer = 1LL * 6;
  }
  for (int i = 1; i < domino.size(); i++) {
    if (!domino[i - 1]) {
      answer = answer * 2 % MOD;
    } else if (domino[i]) {
      answer = answer * 3 % MOD;
    }
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int v[100005], n;
char res[100005];
bool dfs(int id, int a, int b, int c) {
  if(id == n) return true;
  if(v[id] == 0) {
    if(b) {
      res[id] = 'A';
      if(dfs(id + 1, a + 1, b - 1, c)) return true;
    }
    if(a) {
      res[id] = 'B';
      if(dfs(id + 1, a - 1, b + 1, c)) return true;
    }
  } else if(v[id] == 1) {
    if(c) {
      res[id] = 'A';
      if(dfs(id + 1, a + 1, b, c - 1)) return true;
    }
    if(a) {
      res[id] = 'C';
      if(dfs(id + 1, a - 1, b, c + 1)) return true;
    }
  } else {
    if(b) {
      res[id] = 'C';
      if(dfs(id + 1, a, b - 1, c + 1)) return true;
    }
    if(c) {
      res[id] = 'B';
      if(dfs(id + 1, a, b + 1, c - 1)) return true;
    }
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int a, b, c; cin >> n >> a >> b >> c;
  for(int i = 0; i < n; i++) {
    string s; cin >> s;
    if(s == "AB") v[i] = 0;
    else if(s == "AC") v[i] = 1;
    else v[i] = 2;
  }
  if(dfs(0, a, b, c)) {
    cout << "Yes\n";
    for(int i = 0; i < n; i++) {
      cout << res[i] << '\n';
    }
  } else {
    cout << "No\n";
  }
}

Measured memory_bytes: 11872
import numpy as np

x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()

p = np.array(list(map(int, input().split())))
for i in range(100):
    if not x-i in p:
        print(x-i)
        exit()
    elif not x+i in p:
        print(x+i)
        exit()

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define INF 1e18
ll N, M, X[101010], Y[101010];


char d[5],D[101010];
ll i, j, k;
ll lx, rx, ly, ry;
//ll lxy[4], rxy[4];
ll xx, yy;
ll ans,ans2;
ll mxn[4];
ll calc(ll n){
    ll i = 0;
    mxn[0]=-INF,mxn[1]=INF,mxn[2] = -INF, mxn[3] = INF;
    fornum(i,0,N){
        ll x = X[i]*2;
        ll y = Y[i]*2;
        switch(D[i]){
            case 'U':
                y += n;
                break;
            case 'D':
                y -= n;
                break;
            case 'R':
                x += n;
                break;
            case 'L':
                x-=n;
                break;
        }
        if(mxn[0]<x){
            mxn[0] = x;
        }
        if(x<mxn[1]){
            mxn[1] = x;
        }
        if(mxn[2]<y){
            mxn[2] = y;
        }
        if(y<mxn[3]){
            mxn[3] = y;
        }
    }
    //printf("%lf,%lf,%lf,%lfd\n", xmx, xmn, ymx, ymn);
    return (mxn[0]-mxn[1])*(mxn[2] - mxn[3]);
}

void bs(ll xy){
    ll l = 0,r=1e9;
    while(l<r){
        ll mid = (l + r+1) / 2;
        calc(mid);
        ll a = mxn[xy];
        calc(mid - 1);
        ll b = mxn[xy];
        if(xy%2?b<a:a<b){
            l = mid;
        }else{
            r = mid - 1;
        }
    }
    ll a = calc(l);
    if(a<ans){
        ans = a;
    }
    ll p = mxn[xy];
    l = lx;
    r = 1e9;
    while(l<r){
        ll mid = (l + r+1) / 2;
        calc(mid);
        ll a=mxn[xy];
        if(p==a){
            l = mid;
        }else{
            r = mid - 1;
        }
    }
    a = calc(l);
    if(a<ans){
        ans = a;
    }
}

int main(){
    scanf("%lld", &N);
    fornum(i, 0, N){
        scanf("%lld%lld%s", &X[i], &Y[i], d);
        D[i] = d[0];
    }
    ans = INF;
    fornum(i,0,4){
        bs(i);
    }
    printf("%.12lf", ans/4.0);

    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	// no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} 
using io :: gi;
using io :: putc;
using io :: print;
const int N=605,mod=1e9+7;
int f[N][N][N],vis[N],p[N],fac[N];
// vis = -1 确定位置且已配对
// vis = 0 没确定位置且没配对
// vis = 1 确定位置但没配对 
// dp[i][j][k] [i,2n] j确定位置的数等待配对 k个没确定位置的数等待匹配 
inline void add(int &x,ri y){
	x=(x+=y)>=mod?x-mod:x; 
}
int main(){
	ri n,i,j,k,cnt,res,ans;
	gi(n);n<<=1;
	for(i=1;i<=n;++i) gi(p[i]);
	cnt=0;
	for(i=2;i<=n;i+=2)
		if(p[i-1]!=-1&&p[i]!=-1)
			vis[p[i-1]]=vis[p[i]]=-1;
		else if(p[i-1]!=-1)
			vis[p[i-1]]=1;
		else if(p[i]!=-1)
			vis[p[i]]=1;
		else
			++cnt;
//	for(i=1;i<=n;++i) printf("%d ",vis[i]); puts("");
	f[n+1][0][0]=1;
	for(i=n+1;i>1;--i)
		for(j=0;j<=n-i+1;++j)
			for(k=0;k<=n-i+1;++k)
				if(res=f[i][j][k]){
					if(vis[i-1]==-1)
						add(f[i-1][j][k],res);
					else if(vis[i-1]==0){
						if(j) add(f[i-1][j-1][k],(ll)res*j%mod);
						if(k) add(f[i-1][j][k-1],res);
						add(f[i-1][j][k+1],res);
					}
					else{
						if(k) add(f[i-1][j][k-1],res);
						add(f[i-1][j+1][k],res);
					}
				} 
	ans=f[1][0][0];
	fac[0]=1;
	for(i=1;i<=cnt;++i) fac[i]=(ll)fac[i-1]*i%mod;
	ans=(ll)ans*fac[cnt]%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 863104
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;



char a[22][22];
bool vis[22][22];
int dist[22][22];
int ans = 0 , cnt = 0;
int n,m;

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

bool is_valid(int x , int y){
    if((x >=0 && x < n) && (y>=0 && y<m) )return true;

    return false;
}
void bfs(int x,int y){
    vis[x][y] = true;
    queue<pair<int,int> > q;
    q.push(make_pair(x,y));
    dist[x][y] = 0;
    while (!q.empty()) {
        //pair<int,int> next = q.front();
        int x1 = q.front().first;
        int y1 = q.front().second;
        q.pop();
        for (size_t i = 0; i < 4; i++) {
            int tx = x1 + dx[i];
            int ty = y1 + dy[i];
            if(is_valid(tx , ty) && a[tx][ty] != '#' && !vis[tx][ty]){
                q.push(make_pair(tx , ty));
                dist[tx][ty] = dist[x1][y1] + 1;
                cnt = max(cnt , dist[tx][ty]);
                vis[tx][ty] = true;
            }
        }
    }

}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>m;
    for (size_t i = 0; i < n; i++) {
        for (size_t j = 0; j < m; j++) {
            cin>>a[i][j];
        }
    }

    for (size_t i = 0; i < n; i++) {
        for (size_t j = 0; j < m; j++) {
            if( a[i][j] != '#'){
                cnt = 0;
                memset(vis ,false, sizeof(vis));
                bfs(i , j );

                ans = max(ans , cnt);


            }
        }
    }
    cout<<ans;
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n, k, q, w;
    cin >> n >> k >> q;
    vector<int> points(n, k-q);
    for (int i=0; i<q; i++){;
        cin >> w;
        points.at(w-1)++;
    }
    for (int p : points) {
        if(p>0)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}

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

int l;

string whc(string a, string b)
{
	for(int i = 0; i < l; i++){
		if(a[i] < b[i]) return a;
		if(a[i] > b[i]) return b;
	}
	return a;
}

int main()
{
	int n;
	cin >> n >> l;
	vector<string> s;
	for(int i = 0; i < n; i++){
		string str;
		cin >> str;
		s.push_back(str);
	}
	for(int i = n-1; i >= 0; i--){
		for(int j = 0; j < i; j++){
			if(s[j] != s[j+1] && whc(s[j], s[j+1]) == s[j+1]){
				string str = s[j];
				s[j] = s[j+1];
				s[j+1] = str;
			}
		}
	}
	for(int i = 0; i < n; i++){
		cout << s[i] << flush;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
def solve():
    N = int(input())
    A = [int(a) for a in input().split()]
    A.sort()

    Adict = dict()
    for i, a in enumerate(A):
        if a in Adict: Adict[a] += 1
        else: Adict[a] = 1

    rect = 0
    ri = -1
    for i in reversed(range(N)):
        if Adict[A[i]] >= 4:
            rect = A[i] ** 2
            break
        if Adict[A[i]] >= 2:
            rect = A[i]
            ri = i
            break
    if ri > -1:
        for i in reversed(range(ri)):
            if Adict[A[i]] >= 2 and A[i] != rect:
                rect *= A[i]
                break
    print(rect)

if __name__ == "__main__":
    solve()


Measured memory_bytes: 17960
import numpy as np
from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    counter = Counter(A)
    for a, cnt in counter.most_common():
        tmp = counter[a-1] + cnt + counter[a+1]
        if ans < tmp:
            ans = tmp


    print(ans) 


main()

Measured memory_bytes: 24728
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

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

    vector<double> x(N);
    vector<string> v(N);
    for(int i=0;i<N;i++){
        cin >> x[i] >> v[i];
    }

    double ans = 0;
    for(int i=0;i<N;i++){
        if( v[i] == "BTC" ){
            ans += x[i] * 380000.0;
        } else{
            ans += x[i];
        }
    }

    cout << ans << endl;
}

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

typedef long long ll;
typedef pair<int,int> ii;

struct LCA {
	vector<int> height, euler, first, segtree;
	vector<ll> d_to_r;
	vector<bool> visited;
	int n;

	LCA(vector<vector<ii>> &adj, int root = 0) {
		n = adj.size();
		d_to_r.resize(n);
		height.resize(n);
		first.resize(n);
		euler.reserve(n * 2);
		visited.assign(n, false);
		d_to_r[root]=0;
		dfs(adj, root);
		int m = euler.size();
		segtree.resize(m * 4);
		build(1, 0, m - 1);
	}

	void dfs(vector<vector<ii>> &adj, int node, int h = 0) {
		visited[node] = true;
		height[node] = h;
		first[node] = euler.size();
		euler.push_back(node);
		for (auto to : adj[node]) {
			if (!visited[to.first]) {
				d_to_r[to.first]=d_to_r[node]+to.second;
				dfs(adj, to.first, h + 1);
				euler.push_back(node);
			}
		}
	}

	void build(int node, int b, int e) {
		if (b == e) {
			segtree[node] = euler[b];
		} else {
			int mid = (b + e) / 2;
			build(node << 1, b, mid);
			build(node << 1 | 1, mid + 1, e);
			int l = segtree[node << 1], r = segtree[node << 1 | 1];
			segtree[node] = (height[l] < height[r]) ? l : r;
		}
	}

	int query(int node, int b, int e, int L, int R) {
		if (b > R || e < L)
			return -1;
		if (b >= L && e <= R)
			return segtree[node];
		int mid = (b + e) >> 1;

		int left = query(node << 1, b, mid, L, R);
		int right = query(node << 1 | 1, mid + 1, e, L, R);
		if (left == -1) return right;
		if (right == -1) return left;
		return height[left] < height[right] ? left : right;
	}

	int lca(int u, int v) {
		int left = first[u], right = first[v];
		if (left > right)
			swap(left, right);
		return query(1, 0, euler.size() - 1, left, right);
	}

	ll dist(int u, int v) {
		return d_to_r[u]+d_to_r[v]-2*d_to_r[lca(u,v)];
	}
};

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N; cin>>N;
	vector<vector<ii>> adj(N);
	for (int i=0; i<N-1; i++) {
		int a,b,c; cin>>a>>b>>c; a--; b--;
		adj[a].push_back({b,c});
		adj[b].push_back({a,c});
	}
	LCA lca(adj);
	int Q,K; cin>>Q>>K; K--;
	for (int i=0; i<Q; i++) {
		int x,y; cin>>x>>y; x--; y--;
		cout<<lca.dist(x,K)+lca.dist(K,y)<<"\n";
	}
	return 0;
}

Measured memory_bytes: 16128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <limits>
#include <numeric>
#include <functional>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
using namespace std;

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

	int n;

	cin >> n;

	FOR(i, 1, 10)
	{
		int z = i * 100 + i * 10 + i;
		if (n <= z)
		{
			cout << z << endl;
			break;
		}
	}


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define mod 10e9+7

#define rep(i,n) for(int i=0;i<n;i++)
int main(){
   ll n,mini=INF,time,a=INF,b=INF;
   int cx,cy,pin,i,j;
  cin >> n;
  for(int i=0;i<1000;i++){
     
     if(n/100==(n%100)/10 && (n%100)/10 == n%10 )
     break;

     else
     {
        n++;
     }
     
  } 
 cout << n << endl;


}
   



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

tree = {}
for i in range(n-1):
    a, b = map(int, input().split())
    if a in tree:
        tree[a].append(b)
    else:
        tree[a] = [b]

op = {i: 0 for i in range(1, n+1)}
for i in range(q):
    p, x = map(int, input().split())
    op[p] = op[p] + x

res = []
for node in op.keys():
    cnt = op[node]
    res.append(cnt)
    if node in tree:
        for i in tree[node]:
            op[i] += cnt

print(*res)


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 998244353;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

const int N = 2e5+2;
pii a[N];
int R[N], dp[N], psum[N], n;

struct BIT{
  vector <int> bit;

  void prepare(int n){
    bit.assign(n + 1, -INF);
  }

  void Update(int p, int val){
    for (; p > 0; p -= p&-p) bit[p] = max(bit[p], val);
  }

  int Get(int p){
    int ans = -INF;
    for (; p <= n; p += p&-p) ans = max(ans, bit[p]);
    return ans;
  }
} cur;


int main()
{
  fastio;
  cin >> n; cur.prepare(n);
  for (int i = 1; i <= n; i++){
    cin >> a[i].first >> a[i].second;
  }
  sort(a + 1, a + 1 + n);
  R[n] = n;
  for (int i = n - 1; i > 0; i--){
    int pos = -1;
    int l = i + 1; int r = n;
    while (l <= r){
      int m = (l + r) / 2;
      if (a[i].first + a[i].second > a[m].first){
        pos = m;
        l = m + 1;
      }
      else r = m - 1;
    }
    if (pos == -1) R[i] = i;
    else R[i] = R[pos];
  }
  dp[0] = 1; psum[0] = 1;  
  for (int i = 1; i <= n; i++){
    int pos = cur.Get(i);
    if (pos == -INF) dp[i] += psum[i - 1];
    else {
      dp[i] += (psum[i - 1] - psum[pos - 1] + MOD) % MOD;
    }
    dp[i] %= MOD; psum[i] = (psum[i - 1] + dp[i]) % MOD;
    cur.Update(R[i], i);
  }
  int res = 0;
  for (int i = 0; i <= n; i++) (res += dp[i]) %= MOD;
  cout << res;
  return 0;
}

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

int main(){
    int n; cin >> n;
    vector<int> lis(100000, 0);
    lis[0] = 1;
    for(int i = 0; i < n; i++){
        int mid; cin >> mid;
        for(int l = 10000; l >= mid; l--){
            if(lis[l-mid] == 1){
                lis[l] = 1;
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < 10000; i++){
        if(lis[i] == 1 && i % 10 != 0){
            ans = i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define Msize 1300000
using namespace std;
 
bool prime[Msize] = {0};
 
void setp(){
    prime[0] = prime[1] = 1;
    for(int i = 2;i < Msize;++i)
        if(!prime[i])
            for(int j = 2;j * i < Msize;++j)
                prime[i * j] = 1;
}
 
int x;
 
int solve();
 
int main(){
    setp();
    while(1){
        cin >> x;
        if(x == 0)break;
        cout << solve() << endl;
    }
    return 0;
}
 
int solve(){
    if(!prime[x])return 0;
    int ans = 0,now = x;
    while(prime[now])++ans,++now;
    now = x;
    while(prime[now])++ans,--now;
    return ans;
}



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

int dist[410][410];
string s[25];
const int inf = 1e4;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int h,w;
	cin >> h >> w;
	for(int i=0;i<h;i++)cin >> s[i];
	for(int i=0;i<h*w;i++){
		for(int j=0;j<h*w;j++){
			if(i==j)continue;
			dist[i][j] = inf;
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(s[i][j]=='.'&&i+1<h&&s[i+1][j]=='.'){
				int t1 = i*w+j;
				int t2 = (i+1)*w+j;
				dist[t1][t2] = dist[t2][t1] = 1;
			}
			if(s[i][j]=='.'&&j+1<w&&s[i][j+1]=='.'){
				int t1 = i*w+j;
				int t2 = i*w+j+1;
				dist[t1][t2] = dist[t2][t1] = 1;
			}
		}
	}
	for(int k=0;k<h*w;k++){
		for(int i=0;i<h*w;i++){
			for(int j=0;j<h*w;j++){
				dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}
	int ans = 0;
	for(int i=0;i<h*w;i++){
		for(int j=0;j<h*w;j++){
			if(dist[i][j]<inf){
				ans = max(ans,dist[i][j]);
			}
		}
	}
	cout << ans << "\n";
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,a[107],s=0,ans=0;
int main()
{
	n=read();
	for (int i=1;i<=n;i++)
	{
		a[i]=read();
		s+=a[i];
	}
	if (s%10!=0) printf("%d\n",s);
	else
	{
		for (int i=1;i<=n;i++)
			if ((s-a[i])%10!=0) ans=max(ans,s-a[i]);
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define  rep(i,n) for(li i=0;i<(n);i++)
#define  red(i,n) for(li i=(n)-1;i>=0;i--)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
#define  fi first
#define  se second 
using namespace std;
using li = long long;
using ul = unsigned long long;
using vi = vector<li>;
using vs = vector<string>;
inline ul gcd(ul a,ul b) { return b?gcd(b,a%b):a; }
const int INF=1e9+9;


int main()
{
    char s[10];
    rep(i,6)cin>>s[i];
    if(s[0]==s[5]&&s[1]==s[4]&&s[2]==s[3])cout<<"YES\n";
    else cout<<"NO\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int H, W;
    cin >> H >> W;

    map<int, int> mp;
    multiset<int> ms;

    rep(i, W) mp[i] = i;
    rep(_, W) ms.insert(0);

    rep(i, H) {
        int l, r;
        cin >> l >> r;
        --l;
        auto it = mp.lower_bound(l);
        int R   = -1;

        while (it != mp.end() && it->first <= r) {
            R     = max(R, it->second);
            int x = it->first - it->second;
            ms.erase(ms.find(x));
            it = mp.erase(it);
        }

        if (R != -1 && r < W) {
            ms.insert(r - R);
            mp[r] = R;
        }

        int ans = -1;
        if (ms.size() > 0) ans = *ms.begin() + i + 1;

        cout << ans << '\n';
    }
}


Measured memory_bytes: 22320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll h,w; cin>>h>>w;
    vector<string> s(h);
    rep(i,h) cin>>s[i];
    vector<vector<bool>> painted(h, vector<bool>(w, false));
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='.') continue;
            if(s[i][j]=='#'){
                bool ifokay=false;
                if(i<h-1 && s[i+1][j]=='#'){
                    painted[i+1][j]=true;
                    ifokay=true;
                }
                if(j<w-1 && s[i][j+1]=='#'){
                    painted[i][j+1]=true;
                    ifokay=true;
                }
                if(!painted[i][j] && !ifokay){
                    cout<<"No"<<endl;
                    return 0;
                }
                painted[i][j]=true;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
n,a,b,c,d =map(int,input().split())
s=list(input())

i=0
j=0
gg=0
nnt=0
if c<d:
    i=a-1
    while i!=d:
        if s[i]=="#":
            j=j+1
        else:
            j=0
        if j==2:
            nnt=1
            break
        i=i+1

else:
    i=a-1
    nnt=1
    while i!=c-1:

        if s[i]==".":
            gg=gg+1
        else:
            gg=0
        if gg>=3:
            if i>=b:
                if i<=d:
                    nnt=0




        if s[i]=="#":
            j=j+1
        else:
            j=0
        if j==2:
            nnt=1
            break

        i=i+1
if nnt==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 4916
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;	

int main() {
    int n; cin >> n;
    if (n % 2 == 0) {
        cout << n / 2 << endl;
    }
    else {
        cout << (n + 1) / 2 << endl;
    }
}


Measured memory_bytes: 3568
#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 = 998244353;
typedef long long LL;

int main() {
  int A, B, C, D; cin >> A >> B >> C >> D;
  vector<vector<LL>> dp(C + 1, vector<LL>(D + 1, 0));
  dp[C][D] = 1;
  for (int c = D - 1; c >= B; --c) {
    dp[C][c] = C * dp[C][c + 1];
    dp[C][c] %= kMod;
  }
  for (LL r = C - 1; r >= A; --r) {
    LL S = 0;
    dp[r][D] = (D * dp[r + 1][D]) % kMod;
    for (LL c = D-1; c >= B; --c) {
      S = (r * (S + dp[r + 1][c + 1])) % kMod;
      dp[r][c] = (c * dp[r + 1][c] + S) % kMod;
    }
  }
  cout << dp[A][B] << endl;
}


Measured memory_bytes: 73728
#include <cstdio>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int main(){
	int n , p ,t ;
	string name;
	int timeflow=0;
	cin>>n>>p;
	queue<pair<string,int> > A;
	for(int i = 1 ; i<=n;i++){
		cin>>name>>t;
		A.push(make_pair(name, t));
	}
	while(!A.empty()){
		if(A.front().second<=p){
			timeflow+=A.front().second;
			cout<<A.front().first<<" "<<timeflow<<endl;
			A.pop();
		}
		else{
			timeflow+=p;
			A.front().second-=p;
			A.push(A.front());
			A.pop();
		}
	}
	return 0;
}


Measured memory_bytes: 6336
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    int k,s,c=0;
    cin>>k>>s;
    rep(x,k+1){
        rep(y,k+1){
            int z=s-x-y;
            if (x+y+z==s && z<=k && z>=0) c++;
        }
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {


	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int[][] a = new int[n][m];
		int[] 	b = new int[m];
		int[] 	c = new int[n];

		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				a[i][j]=scan.nextInt();
			}
		}

		for(int i=0;i<m;i++){
			b[i]=scan.nextInt();
		}



		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				c[i]=c[i]+a[i][j]*b[j];
			}
		}

		for(int data:c){
			System.out.println(data);
		}
	}
}

Measured memory_bytes: 40548
#include<bits/stdc++.h>//'三玖是天！ '.
using namespace std;
char s[52],j[52];
int main(){
    cin>>s;
    cin>>j;
    int la=strlen(s),lb=strlen(j);
    int l=min(la,lb),ll=max(la,lb);
    for(int i=0;i<=l-1;i++)
        cout<<s[i]<<j[i];
    if(la>lb)
        for(int i=l;i<=ll-1;i++)
            cout<<s[i];
    else for(int i=l;i<=ll-1;i++)
            cout<<j[i];
    return 0;
}

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

int main() {
   int n, m, x;
   cin >> n >> m >> x;
   vector<int> c(n);
   vector<vector<int>> a(n,vector<int>(m));


   rep(i, n){
      cin >> c[i];
      rep(j, m){
         cin >> a[i][j];
      }
   }


   int min = 1200001;
   for(int s=0; s < (1<<n); s++){
      vector<int> ans;
      for(int i=0; i<n; i++){
         if(s & (1<<i)) ans.push_back(i);
      }
      //cout << "{";
      int sum = 0;
      vector<int> sums(m, 0);
      for(int i=0; i<ans.size(); i++){
         //cout << ans[i];
         //if(i < ans.size()-1) cout << ",";
         sum += c[ans[i]];
         rep(j, m){
            sums[j] += a[ans[i]][j];
            //sum += c[ans[i]];
            //cout << c[ans[i]] << " ";
         }
      }
      //cout << sum << endl;
      bool flag = true;
      rep(i, m){
         if(sums[i] >= x){

         }else{
            flag = false;
         }
      }
      if(flag == true){
         if(sum < min){
            min = sum;
         }
      }
      //cout << "}" << endl;
   }
   if(min == 1200001){
      cout << -1;
   }else{
      cout << min;
   }
   return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<P> table;
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        table.emplace_back(a, i);
    }
    sort(table.begin(), table.end(), greater<P>());
    constexpr ll inf = 1e+15;
    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, -inf));
    dp[0][0] = 0;
    for(int i = 0; i < n; ++i){
        int val = table[i].first, p = table[i].second;
        for(int j = 0; j <= i; ++j){
            if(dp[i][j] == -inf)    continue;
            chmax(dp[i + 1][j + 1], dp[i][j] + (ll)val * abs(p - j));
            chmax(dp[i + 1][j], dp[i][j] + (ll)val * abs(n - i + j - 1 - p));
        }
    }
    ll ans = 0;
    for(int i = 0; i <= n; ++i) chmax(ans, dp[n][i]);
    cout << ans << endl;
}

Measured memory_bytes: 34596
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

string S;
int N;

int main() {
    cin >> S;
    N = S.size();
    ll count = 0, state = 0, mul = 0;
    for (int i = 0; i < N; ++i) {
        if (state == 0) {
            if (S[i] == 'A') {
                mul = 1;
                state = 1;
            }
        } else if (state == 1) {
            if (S[i] == 'A') {
                mul++;
            } else if (S[i] == 'B') {
                state = 2;
            } else {
                state = 0;
            }
        } else if (state == 2) {
            if (S[i] == 'A'){
                mul = 1;
                state = 1;
            } else if (S[i] == 'B') {
                mul = 0;
                state = 0;
            } else {
                count += mul;
                state = 1;
            }
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 640