akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
using ll = long long;


int main()
{
	int n, q;
	cin >> n >> q;
	string s, t;
	cin >> s;
	t = s;
	vector<int> l(q), r(q), sum(n + 1);

	for(int i = 1; i < n; i++) {
		if(s[i] == 'C' && s[i - 1] == 'A')t[i] = 'Z', t[i- 1] = 'X';
	} 
	//cout <<t << endl;
	s = t;

	for(int i = 0; i < n; i++) sum[i + 1] += sum[i] + (s[i] == 'Z' || s[i] == 'X');
	for(int i = 0; i < q; i++) {cin >> l[i] >> r[i], l[i]--;}
	//for(int i = 0; i <= n; i++)cout << sum[i + 1] << " "; cout << endl;

	for(int i = 0; i < q; i++) {
		cout << (sum[r[i]] - sum[l[i]]) / 2 - (s[r[i] - 1] == 'X' && s[l[i]] == 'Z') << endl;
	}

}

Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pairs;

#define MOD 998244353


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

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}




int main(){
    ll n;
    cin>>n;
    
    if(n%10 == 2 || n%10 == 4 || n%10 == 7 || n%10 == 5 || n%10 == 9){
        puts("hon");
    }
    if(n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8){
        puts("pon");
    }
    if(n%10 == 3)puts("bon");
    
    
    return 0;
}


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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << i << endl
using namespace std;
char convert(int n){
  char ans;
    if(n == 2){
        ans = '+';
      }else if(n == 1){
          ans = '0';
        }else{
            ans = '-';
          }
          return ans;
  }

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

  vector<char> ans;
  int r = 1;
  int count = 1;
  while(count < w){
      count *= 3;
      r++;
    }

  int offset = (pow(3, r) - 1) / 2;

  w += offset;

  while(w > 0){
     int a = w % 3;
     w = w / 3;
     ans.pb(convert(a));
    }

   int s = ans.size() - 1;
   if(ans[s] != '0') cout << ans[s];
   REPB(i, (s - 1)) cout << ans[i];
   cout << endl;
   return 0;
}



Measured memory_bytes: 3280
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
--import Data.Array
import Data.Array.IArray
--import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe
 
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
dictCompare :: [a -> a -> Ordering] -> a -> a -> Ordering
dictCompare [] _ _ = EQ
dictCompare (f:fs) x y = let c = f x y in if c==EQ then dictCompare fs x y else c
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
-- end of templete



main = do
    [h, w] <- getInts
    replicateM h $ getLine >>= putStrLn . sjoin . map (fromMaybe (-1)) . tail . scanl (\m c -> if c=='c' then Just 0 else (+1) <$> m) Nothing


Measured memory_bytes: 4108
#include <iostream>
#include <string>
#include <cctype>
#include <cmath>

using namespace std;

int main() {
  long N, x = 1;
  cin >> N;
  for (int n = 1; n <= N; n++) {
    x = (x * n) % ((long)pow(10, 9) + 7);
  }
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b){
  vector<pair<ll, ll>> v;
  ll ans = 0;
  for(ll i=0; i<M; i++) {
    v.push_back(make_pair(b[i], a[i]));
  }
  sort(v.begin(), v.end());
  ll right = -1;
  for(ll i=0; i<M; i++) {
    if(right < v[i].second) {
      ans++;
      right = v[i].first-1;
    }
  }
  std::cout << ans << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long M;
  scanf("%lld",&M);
  std::vector<long long> a(M);
  std::vector<long long> b(M);
  for(int i = 0 ; i < M ; i++){
    scanf("%lld",&a[i]);
    scanf("%lld",&b[i]);
  }
  solve(N, M, std::move(a), std::move(b));
  return 0;
}



Measured memory_bytes: 4084
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int n,i,j;
  while(scanf("%d",&n)!=EOF){
    vector<int> v(1000000,0);
    for(i=2;i<n+1;i++){
      if(v[i])continue;
      for(j=2;i*j<n+1;j++)
	v[i*j]=1;
    }
    int sum=0;
    for(i=2;i<n+1;i++)
      if(v[i]==0)sum++;
    cout<<sum<<endl;
  }
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> v(K);
  
  for (int i = 0; i < K; i++) {
    cin >> v.at(i);
  }
  
  bool b = false;
  for (int i = N; i <= 99999; ) {
    int sub = i;
    for (int j = 0; j < K; ) {
      //cout << j << endl;
      if (!(sub)) {
        b = true;
        break;
      }
      if ((sub % 10) == v.at(j)) {
        i++;
        break;
      }
      if (j == (K - 1)) {
        sub /= 10;
        j = 0;
      } else {
        j++;
      }
    }
    if (b) {
      N = i;
      break;
    }
  }
  //cout << b << endl;
  cout << N << endl;
}

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

using namespace std;
typedef long long ll;
#define mp make_pair
const int INF = 1e9;


int solve(string s, char c) {
	int n = s.size();
	bool ind = true;
	for (int i = 0; i < n; i++) {
		if (s[i] == c)
			ind = false;
	}
	if (ind)
		return INF;
	int res = 0;
	while (true) {
		bool ind = true;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] != c)
				ind = false;
		}
		if (ind)
			return res;
		res++;
		string s1 = "";
		for (int i = 0; i < s.size() - 1; i++) {
			if (s[i]  == c || s[i + 1] == c) 
				s1 += c;
			else
				s1 += s[i];
		}
		s = s1;
	}
	return res;
}

int main() {
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);	
	string s;
	cin >> s;
	int ans = INF;
	for (int i = 0; i < 26; i++)
		ans = min(ans, solve(s, (char)('a' + i)));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b;
    scanf("%d %d", &a, &b);
    //printf("%d %d\n", a, b);
    
    if(a<1 || a>9 || b<1 || b>9) {
        printf("%d", -1);
        return 0;
    }
    
    int ans;
    ans = a * b;
    printf("%d", ans);
    
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
#include <math.h>
#include<iostream>
using namespace std;
typedef long long           ll;
typedef unsigned long long  ull;
typedef long double         ld;

#define sf                  scanf
#define pf                  printf
#define srev                reverse(s.begin(),s.end())
#define sortstr             sort(s.begin(), s.end());
#define gtl(x)              getline(cin, (x))
#define gcd(a, b)           __gcd(a, b)
#define lcm(a, b)           ((a)*((b)/gcd(a,b)))
#define PI                  acos(-1)
#define Precision(a) cout << fixed << setprecision(a)
#define FasterIO     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


template <typename T> T Sqr(T x) { T n = x * x ; return n ;}
template <typename T> T Pow(T B,T P){ if(P==0) return 1; if(P&1) return B*Pow(B,P-1);  else return Sqr(Pow(B,P/2));}
template <typename T> T Abs(T a) {if(a<0)return -a;else return a;}
template <typename T> T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template <typename T> T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
//scanf("%[^\n]%*c", str);
//sort(s,s+n,greater<int>());

int main()
{
    FasterIO
    string s;
    cin >> s;
    int flag=0;
    for(int i=0; i<s.size(); i++)
    {
        if(s[2]==s[3] && s[4]==s[5])
        {
            flag=1;
        }
    }
    if(flag==1)  cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!


N = int(input())
V = input().split()
C = input().split()

t_v = 0
t_c = 0

for i in range(N):
    v = int(V[i])
    c = int(C[i])

    if v - c > 0:
        t_v += v
        t_c += c
    elif c - v < 0:
        t_v += v

print(t_v - t_c)


Measured memory_bytes: 3060
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
template<typename V> typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();

// clang-format on

bool dfs(vi v, int l, int r) {
  if (v.size() == 0) {
    return true;
  }
  bool hoge = false;
  if (v.back() > l) {
    vi _v  = v;
    int _l = v.back();
    _v.pop_back();
    hoge |= dfs(_v, _l, r);
  }
  if (v.back() > r) {
    vi _v  = v;
    int _r = v.back();
    _v.pop_back();
    hoge |= dfs(_v, l, _r);
  }
  return hoge;
}

main {
  int n;
  cin >> n;
  rep(_, n) {
    vi v(10);
    rep(i, 10) cin >> v[9 - i];
    cout << (dfs(v, 0, 0) ? "YES" : "NO") << endl;
  }
  return 0;
}

Measured memory_bytes: 3088
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }
const int mx = 1e5;

int n, m, s, t;
vector<pair<int, ll>> G[100100];

ll d[2][100100];
ll dp[2][100100];

void dijkstra() {
  rep(i, 2) rep(j, n) d[i][j] = INF;
  d[0][s] = 0, d[1][t] = 0;
  dp[0][s] = 1, dp[1][t] = 1;
  priority_queue<pair<ll, int>> pq;
  pq.push({0, s});
  pq.push({0, t + mx});
  while (pq.size()) {
    pair<ll, int> p = pq.top();
    pq.pop();
    int v = p.second % mx, id = p.second / mx;
    if (d[id][v] != -p.first) continue;
    for (auto e: G[v]) {
      int u = e.first;
      ll c = e.second;
      if (chmin(d[id][u], d[id][v] + c)) {
        dp[id][u] = 0;
        pq.push({-d[id][u], id * mx + u});
      }
      if (d[id][u] == d[id][v] + c) dp[id][u] = (dp[id][u] + dp[id][v]) % mod;
    }
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  cin >> n >> m >> s >> t;
  s--, t--;
  rep(i, m) {
    int u, v;
    ll x;
    cin >> u >> v >> x;
    u--, v--;
    G[u].push_back({v, x});
    G[v].push_back({u, x});
  }

  dijkstra();
  ll ans = dp[0][t] * dp[0][t] % mod;
  rep(i, n) if (d[0][i] + d[1][i] == d[0][t]) {
    if (d[0][i] == d[1][i]) {
      ans += mod - dp[0][i] * dp[0][i] % mod * dp[1][i] % mod * dp[1][i] % mod;
      ans %= mod;
    }
    else if (d[0][i] < d[1][i]) {
      for (auto e: G[i]) {
        int j = e.first;
        ll c = e.second;
        if (d[0][j] + d[1][j] == d[0][t] && d[0][j] > d[1][j] && d[0][j] == d[0][i] + c) {
          ans += mod - dp[0][i] * dp[0][i] % mod * dp[1][j] % mod * dp[1][j] % mod;
          ans %= mod;
        }
      }
    }
  }
  cout << ans << '\n';


  




  
  return 0;
}

Measured memory_bytes: 22260
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1e9 + 10;

int xs[5001], ys[5001];
int sum[5100][5100];

int main() {

  int N, M; cin >> N >> M;
  vector<int> X, Y;
  rep(i, N) {
    scanf("%d%d", &xs[i], &ys[i]);
    X.push_back(xs[i]); Y.push_back(ys[i]);
  }

  sort(X.begin(), X.end()); X.erase(unique(all(X)), X.end());
  sort(Y.begin(), Y.end()); Y.erase(unique(all(Y)), Y.end());

  rep(i, N) {
    sum[upper_bound(all(Y), ys[i]) - Y.begin()][upper_bound(all(X), xs[i]) - X.begin()] ++;
  }

  rep(i, Y.size() + 10) rep(j, X.size() + 10) {
    if(i && j) sum[i][j] -= sum[i-1][j-1];
    if(i) sum[i][j] += sum[i-1][j];
    if(j) sum[i][j] += sum[i][j-1];
  }

  rep(i, M) {
    int rx1, ry1, rx2, ry2; scanf("%d%d%d%d", &rx1, &ry1, &rx2, &ry2);
    int x1 = lower_bound(all(X), rx1) - X.begin();
    int y1 = lower_bound(all(Y), ry1) - Y.begin();
    int x2 = upper_bound(all(X), rx2) - X.begin();
    int y2 = upper_bound(all(Y), ry2) - Y.begin();
    printf("%d\n", sum[y2][x2] - sum[y2][x1] - sum[y1][x2] + sum[y1][x1]);
  }

  return 0;
}

Measured memory_bytes: 103212
// PrimeNumber
// 素数判定
// ヒント：入力xが素数か否か判定する方法。
//  ・2からx-1まで順に検査してmod値が0になるか否かで判定（シンプルだけど計算量大）
//  ・2以外の偶数は素数ではないので検査対象から外す（高速化・・計算量半減）

//　・「合成数xはp<=sqrt(x)を満たす素因数pを持つ」という定理による。
//  ・合成数とは素数でない数のこと。たとえば31が素数か否かを確認するには、sqrt(x)=>5.XXなの2,3,5,6を検査すれば良い。

//  ・細かいことはおいといて2からsqrt(x)まで調べれば良い。
//
// 入力　n,n個の検査対象の自然数
// 出力　検査対象の素数の数
// 
// 1,
// 2,
// 3,

#include <cmath>
#include<iostream>

int main(){
	
	int n,i,j,x,c=0,isPrime;

	// Input
	std::cin >>n;

	// Search

	for (i=0;i<n;i++) {
		std::cin >> x;

		if (x == 2)c++;
		else if ((x < 2) || (x % 2 == 0)) {
			// do nothing
		}
		else {
			j = 3;
			isPrime = 1;
			while(j<=sqrt(x)) {
				if (x % j == 0) {
					isPrime = 0;
					break;
				}
				j += 2;
			}
			if (isPrime == 1)c++;
		}
	}

	std::cout << c	<< std::endl;

	return 0;
}


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

int N, K, h[100000];

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; ++i){
      	cin >> h[i];
    }
    sort(h, h + N);

    int ans = 1e9 + 10;
    for (int i = 0; i < N - K + 1; ++i){
    	ans = min(ans, h[i+K-1] - h[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
// https://atcoder.jp/contests/abc121/tasks/abc121_b

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, m, c;
    cin >> n >> m >> c;

    vector<int> b(m);
    for (int i = 0; i < m; i++)
    {
        cin >> b[i];
    }

    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        long s = c;
        for (int j = 0; j < m; j++)
        {
            int a_j;
            cin >> a_j;
            s += a_j * b[j];
        }
        ans += int(s > 0);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int count(vector<vector<int>>& vec, vector<bool> flag, int k){
    flag[k]=false;
    bool f=true;
    for(bool b : flag){
        if(b){
            f=false;
            break;
        }
    }
    if(f)
        return 1;
    int c=0;
    for(int v : vec[k]){
        if(flag[v]){
            c+=count(vec, flag, v);
        }
    }
    return c;
}

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> vec(n);
    for(int i=0;i<n;++i){
        vec[i]=vector<int>(n-1);
    }
    int a, b;
    for(int i=0;i<m;++i){
        cin >> a >> b;
        --a; --b;
        vec[a].push_back(b);
        vec[b].push_back(a);
    }
    //vector<bool> flag(n, true);
    cout << count(vec, vector<bool>(n, true), 0);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int flag = 0;
	for(int i = 1; i <= b; i ++){
		if(i * a % b == c){
			flag = 1;
			break;
		}
	}
	if(!flag){
		cout<<"NO"<<endl;
	}else{
		cout<<"YES"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=1e9;
const long long LINF=1e18;
#define int long long
//template
template <typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
int N,A,B,C;
int pw(int n,int k){
  if(k<0)return pw(n,k+MOD-1);
  int res=1;
  while(k){
    if(k&1)res*=n;res%=MOD;
    n*=n;n%=MOD;
    k>>=1;
  }
  return res;
}
std::vector<int> Factorial(5e6),Finverse(5e6);
void Cinit(){// limit is 5e6 /// write Cinit&pw /// this takes 792ms at AtCoder
  Factorial[0]=1;
  for(int i=1;i<5e6;i++)Factorial[i]=Factorial[i-1]*i%MOD;
  for(int i=0;i<5e6;i++)Finverse[i]=pw(Factorial[i],MOD-2);
}
int nCk(int n,int k){
  if(n<k)return 1;if(k<0)return 0;
  int res=Factorial[n];
  res*=Finverse[k];res%=MOD;
  res*=Finverse[n-k];res%=MOD;
  return res;
}
int f(int x,int y,int z,int w){
  int res=nCk(x+y+z+w,x)*nCk(y+z+w,z+w)%MOD*nCk(z+w,z);res%=MOD;
  int t=C-z-3*w;
  res*=nCk(t+y-1,y-1);res%=MOD;
  return res;
}
//main
signed main(){
  Cinit();
  cin>>N>>A>>B>>C;
  //pattern 1:x
  //pattern 23...32:y=B/2
  //pattern 1in3:z=A-x
  //pattern 333:w
  if(B&1)fin(0);int y=B/2;
  if(y==0){
    int res=0;
    for(int w=0;3*w<=C;w++){
      int z=C-3*w;
      int x=A-z;if(x<0)continue;
      res+=nCk(x+w+z,x+w)*nCk(x+w,x);res%=MOD;
    }
    fin(res);
  }
  int ans=0;
  for(int x=0;x<=A;x++){
    int z=A-x;
    for(int w=0;3*w+z<=C;w++){
      ans+=f(x,y,z,w);
      ans%=MOD;
    }
  }
  fin(ans);
}
/*
解説AC
パターンが少ないの、言われて見ればそうだねという感じ
いやなんかその後のO(1)が求められないのが下手くそ
組み合わせのお勉強が弱いね
先に場所求めてからそこに順番も気にしつつ割り振れば全部のパターンが過不足なく網羅できるってやつ
これがしっかり出来れば取れる問題増えそう
*/


Measured memory_bytes: 78336
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

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

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }


int main(){
    ll A, B;
    cin >> A >> B;

    cout << LCM(A, B) << endl;
}

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

int main()
{
    ll n ,k;
    cin>>n>>k;
    cout.precision(15);

    double p[n];
    for(int i=0;i<n;i++)
    {
        cin>>p[i];
        p[i] = (p[i] + 1)/2;
    }
    double curr =0, ans =0 ;

    for(int i=0;i<k;i++)
    {
        curr += p[i];
    }
    ans =max( ans, curr);
    for(int i = k ;i< n ;i++)
    {
        curr = curr - p[i - k] + p[i];
        ans = max( ans , curr);
    }
    printf("%.12f" , ans);

}

Measured memory_bytes: 5316
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
static const int INF=2e9;
int cnt=0;

void merge(int A[],int left,int mid,int right){
    int n1=mid-left,n2=right-mid;
    int B[n1+1],C[n2+1];
    B[n1]=C[n2]=INF;
    rep(i,n1)B[i]=A[left+i];
    rep(i,n2)C[i]=A[mid+i];
    int j=0,k=0;
    for(int i=left;i<right;i++){
        cnt++;
        if(B[j]>C[k])A[i]=C[k++];
        else A[i]=B[j++];
    }
    return;
}

void mergesort(int A[],int left,int right){
    if(left+1>=right)return;
    int mid=(left+right)/2;
    mergesort(A,left,mid);
    mergesort(A,mid,right);
    merge(A,left,mid,right);
    return;
}

int main(){
    int n;cin>>n;
    int A[n];
    rep(i,n)scanf("%d",&A[i]);
    mergesort(A,0,n);
    rep(i,n){
        if(i!=0)cout<<" ";
        cout<<A[i];
    }
    cout<<"\n"<<cnt<<"\n";
    return 0;
}


Measured memory_bytes: 7160
// +build ignore
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func solve(sc *scanner, wr *bufio.Writer) int {
	X1 := sc.i()
	X2 := sc.i()
	X3 := sc.i()
	X4 := sc.i()
	X5 := sc.i()

	sum := 0
	if X1 == 0 {
		sum += 1
	}

	if X2 == 0 {
		sum += 2
	}

	if X3 == 0 {
		sum += 3
	}

	if X4 == 0 {
		sum += 4
	}

	if X5 == 0 {
		sum += 5
	}

	fmt.Println(sum)

	return 0
}

func main() {
	sc := newScanner(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	ret := solve(sc, wr)
	wr.Flush()
	os.Exit(ret)
}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}


Measured memory_bytes: 1752
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <algorithm>
#define brijesh ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pb push_back
#define popb pop_back
#define l1 long long
#define vi vector<int>
#define vl vector<l1>
#define vs vector<string>
using namespace std;
int main() {
    brijesh;
    l1 count = 0;
    int t;
    cin>>t;
    l1 v1[t];
    for(l1 i=0;i<t;i++)
        cin>>v1[i];
    sort(v1,v1+t);
    for(l1 i=0;i<t;i++) {
        for (l1 j = i + 1; j < t; j++) {
           if(v1[i]!=v1[j])
           {
               for(l1 k=j+1;k<t;k++)
               {
                   if(v1[i]!=v1[k]&&v1[j]!=v1[k]&&v1[i]+v1[j]>v1[k])
                       count++;
               }
           }
        }
    }
    cout<<count;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
const ld pi = acos(-1);
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int a, p; cin >> a >> p;
    cout << (3 * a + p) / 2 << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



struct Edge{
	Edge(int arg_from,int arg_to){
		from = arg_from;
		to = arg_to;
	}
	int from,to;
};


int main(){

	int N,K;

	scanf("%d %d",&N,&K);

	if(K > ((N-1)*(N-2))/2){

		printf("-1\n");
		return 0;
	}

	ll num_2 = (N-1)*(N-2)/2;
	vector<Edge> V;

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

		V.push_back(Edge(1,i));
	}

	int base = 2;

	while(num_2 > K){

		if(num_2-(N-base) > K){
			for(int i = base+1; i <= N; i++){
				V.push_back(Edge(base,i));
			}
			num_2 -= (N-base);
			base++;
			continue;
		}else{

			for(int i = base+1; i <= N && num_2 > K; i++){
				V.push_back(Edge(base,i));
				num_2--;
			}
			break;
		}
	}

	printf("%lld\n",V.size());

	for(int i = 0; i < V.size(); i++){

		printf("%d %d\n",V[i].from,V[i].to);
	}

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type&x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type&x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}

inline void fast_io(){ios::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple

int main()
{
  for (int i = 0; i < 1000; i++){
    string s;
    cin >> s;
    vector<int> v;
    for (const auto& c : s) v.push_back(c - 'A');
    bool na = false;
    int x = v[0] % 3, y = v[0] / 3;
    for (int i = 1; i < v.size(); i++){
      int nx = v[i] % 3, ny = v[i] / 3;
      if (abs(nx - x) + abs(ny - y) != 1){
        na = true;
        break;
      }
      x = nx, y = ny;
    }
    if (!na) cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    char a[200005];
    int s=0,b,c;
    scanf("%s",a);
    int n=strlen(a);
    for(int i=0;i<n;i++)
    {
        if(a[i]=='A')
        {
            b=i;
            break;
        }
    }
    for(int i=n;i>=0;i--)
    {
        if(a[i]=='Z')
        {
            c=i;
            break;
        }
    }
    s=c-b+1;
    cout<<s;
    return 0;
}



Measured memory_bytes: 384
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    t = I()
    aa = [LI() for _ in range(t)]

    rr = []
    for n,a,b,c,dd in aa:
        e = {2: a, 3: b, 5: c}
        def search(s, t):
            d = collections.defaultdict(lambda: inf)
            d[s] = 0
            q = []
            heapq.heappush(q, (0, s))
            v = collections.defaultdict(bool)
            while len(q):
                k, u = heapq.heappop(q)
                if u == t:
                    break
                if v[u]:
                    continue
                v[u] = True

                if d[t] > k + dd * (u-t):
                    d[t] = k + dd * (u-t)
                for ek, ev in e.items():
                    m = u % ek
                    if m == 0:
                        if d[u//ek] > k + ev:
                            d[u//ek] = k + ev
                            heapq.heappush(q, (k+ev, u//ek))
                    else:
                        if d[u//ek + 1] > k + ev + (ek - m) * dd:
                            d[u//ek + 1] = k + ev + (ek - m) * dd
                            heapq.heappush(q, (k + ev + (ek - m) * dd, u//ek + 1))
                        if d[u//ek] > k + ev + m * dd:
                            d[u//ek] = k + ev + m * dd
                            heapq.heappush(q, (k + ev + m * dd, u//ek))

            return d[t]

        rr.append(search(n, 1) + dd)

    return JA(rr, "\n")

print(main())





Measured memory_bytes: 13736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sf(n) scanf("%lld",&n)
#define sff(n,m) scanf("%lld %lld",&n,&m)
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PLL pair<ll,ll>
#define mod 1000000007
#define mx 1002
#define FILE freopen("input.txt","r",stdin)

ll r,c;
char a[mx][mx];
ll dp[mx][mx];

bool valid(ll x,ll y)
{
  if(x<1||x>r||y<1||y>c||a[x][y]=='#') return false;
  else return true;
}

ll F(ll x,ll y)
{
  if(x==r&&y==c) return 1;

  if(dp[x][y]!=-1) return dp[x][y];

  ll ret = 0;

  if(valid(x+1,y)) ret = (ret + F(x+1,y))%mod;
  if(valid(x,y+1)) ret = (ret + F(x,y+1))%mod;

  return dp[x][y] = ret;
}

int main()
{
cin>>r>>c;

for(ll i = 1;i<=r;i++)
{
  for(ll j = 1;j<=c;j++)
  {
    cin>>a[i][j];
  }
}

memset(dp,-1,sizeof dp);
cout<<F(1,1)<<endl;

return 0;
}


Measured memory_bytes: 9088
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;

int main(){
    int a,b;
    cin>>a>>b;
    if(a%2==1&&b%2==1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <stdlib.h>
#include <algorithm>

#define rep(i,s,t) for(int i=s;i<t;i++)
#define mp(a,b) make_pair(a,b)
#define mii map<int,int>

using namespace std;

// 木構造で各選挙区の親子関係を保持する
class tree{
	public:
		//その選挙区で必要となる過半数の票数
		int value;
		//その選挙区がどの階層なのか
		int lv;
		//その選挙区よりひとつうえの選挙区
		tree* parent;
		//その選曲よりひとつしたの選挙区
		vector<tree*> child;
		tree(){value=0;lv=0;}
};

int main(void){

	//入力 n
	int n;
	//データセットは1行で取得
	string str;
	cin >> n;
	//n回のデータセットに対して
	rep(rnd,0,n){
		//各lv(第lv段目の選挙区)ごとの
		//選挙区の木のノードのポインタを保持するmap
		map<int,vector<tree*> > lvs;
		//注目点pをNULLで初期化
		tree *p=NULL;
		//入力を1行で読み込む
		cin >> str;

		//一行で読み込んだ区割り表を1文字ずつ走査するため，
		//選挙区の有権者数も当然1桁ずつしか読み込めない，
		//そこで第1段階の選挙区の有権者数を保持するための
		//文字列を用意
		string numstr;
		//木構造の高さを保持する変数
		int lv=0;
		//木の最大の高さを保持する変数
		int maxlv=0;
		//1行の文字列に対して1文字ずつ
		rep(i,0,str.length()){
			//文字を取得し,文字が'['か']'か数字を調べる
			char c=str.at(i);
			switch(c){
				case '[':{//'['の場合
					//木の高さを一つ上げ，最大の木の高さを更新する
					lv++;
					if(maxlv<lv) maxlv=lv;
					//木の高さが上がったため，新しい高さのノードを生成
					tree *newnode = new tree();
					//その点の親とレベルを与える．
					(*newnode).parent=p;
					(*newnode).lv=lv;

					//lv番目の木の高さのノードを覚えておくための
					//mapにポインタを追加
					lvs[lv].push_back(newnode);
					
					//そのノードの親に自らを子として追加
					if(p!=NULL)
						(*p).child.push_back(newnode);
					//注目点を新しいレベルのノードに変更する
					p=newnode;
					//数値を保持する文字列を空白で初期化する
					numstr="";
					break;
				}
				case ']':{//']'の場合 木の階層がひとつ下る
					//数値保持の文字列が空でない場合
					if(numstr.compare("")!=0){
						//文字列をint型に変換し，
						int val = atoi(numstr.c_str());
						//その値の過半数を注目点pの値に代入する
						(*p).value=(val+1)/2;
					}
					//木の階層がひとつ下るため，
					//注目点pをpの親のポインタに更新
					p=(*p).parent;
					//階層をひとつ下げ
					lv--;
					//数値保持の変数を空白で初期化する
					numstr="";
					break;
				}
				default:{//数字が入力された場合
					//数値保持の変数の末尾に新しい数字を足す
					numstr+=c;
				}
			}
		}
		//木の生成が完了し，葉のノードにのみ
		//値が代入された状態となっているため，各節点の値を更新する
		//各節点にはその選挙区で必要となる過半数の値が代入される
		//葉のノードは見る必要がないので葉の一つ前の選挙区について
		rep(i,0,maxlv-1){
			//iを逆転させて葉に近い方からレベルを下げて見ていく
			int j=maxlv-1-i;
			//そのレベルの選挙区の集合を取得する
			vector<tree*> ll=lvs[j];

			//選挙区すべてについて
			rep(k,0,ll.size()){
				//その選挙区が必要とする過半数の票数を保持する変数
				int valval=0;
				//その選挙区のポインタを取得
				tree *q=ll[k];

				//その下の選挙区の票数を保持するvector
				vector<int> values;
				//その選挙区の下の選挙区のリストを取得
				vector<tree*> ch=(*q).child;
				//その選挙区の下の選挙区の過半数票数をリストに追加する
				rep(l,0,ch.size())
					values.push_back((*ch[l]).value);
				//票数をソートし
				sort(values.begin(),values.end());
				//少ない票数から順に過半数分だけ数え上げ，足していく
				rep(l,0,(values.size()+1)/2)
					valval+=values[l];
				//足された票数がその選曲で必要となる過半数票数になる
				(*q).value=valval;
			}
		}
		//葉から順位上がっていき得られた最終的に必要なlv=1(最終選挙区)
		//での票数を出力
		cout << (*(*(lvs[1].begin()))).value << endl;

		//動的確保したノードを削除していく
		rep(i,1,maxlv+1){
			vector<tree*> ll=lvs[i];
			rep(k,0,ll.size()){
				tree *q=ll[k];
				delete q;
			}
		}
	}
	

	return 0;
}

Measured memory_bytes: 1524
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <functional>

using namespace std;
using ll = long long;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> h(n, 0);
	for (int i = 0; i < n; i++) cin >> h.at(i);

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

	int res = h.at(k - 1) - h.at(0);
	for (int i = k; i < n; i++)
	{
		res = min(res, h.at(i) - h.at(i - k + 1));
	}

	cout << res << endl;
}

Measured memory_bytes: 640
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))

graph = [[-1] * W for _ in range(H)]
h, w = 0, 0 #現在地

if H == W == 1:
    print (1)
    exit()

#動ける範囲
right = W - 1
left = 0
up = 0
down = H - 1

tmp = 0
count = 1
flag = True
while count <= H * W:
    while w < right and flag:
        # print (h, w)
        graph[h][w] = tmp + 1
        a[tmp] -= 1
        if a[tmp] == 0:
            tmp += 1
        count += 1
        if count > H * W:
            flag = False
            break
        w += 1
    right -= 1
    while h < down and flag:
        # print (h, w)
        graph[h][w] = tmp + 1
        a[tmp] -= 1
        if a[tmp] == 0:
            tmp += 1
        count += 1
        if count > H * W:
            flag = False
            break
        h += 1
    down -= 1
    while left < w and flag:
        # print (h, w)
        graph[h][w] = tmp + 1
        a[tmp] -= 1
        if a[tmp] == 0:
            tmp += 1
        count += 1
        if count > H * W:
            flag = False
            break
        w -= 1
    left += 1
    while up < h and flag:
        # print (h, w)
        graph[h][w] = tmp + 1
        a[tmp] -= 1
        if a[tmp] == 0:
            tmp += 1
        count += 1
        if count > H * W:
            flag = False
            break
        h -= 1
    up += 1
    h += 1
    w += 1
    # print (h, w)
    # print ('right = ', right)
    # print ('left = ', left)
    # print ('up = ', up)
    # print ('down = ', down)
    if right == left == 1:
        right += 1
    if up == down == 1:
        down += 1
    if right == left and up == down:
        right += 1

for i in graph:
    print (*i)


Measured memory_bytes: 3956
#include "bits/stdc++.h"
using namespace std;

int main() {
	string S;
	int number = 0;
	string p = "+";

	cin >> S;

	for (int i = 0; i < S.size(); i++) {
		if (S.substr(i, 1)== p) {
			number++;
		}
		else {
			number--;
		}
	}


	cout << number << endl;

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = LLONG_MAX / 3;
const double eps = (1e-9);


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

  ll n; cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  ll ans = 0;
  for (int i = n-1; i >= 0; i--) {
    if ((a[i] + ans) % b[i] == 0) continue;
    ans += b[i] - ((a[i] + ans) % b[i]);
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin (),(x).end()
#define sqrt(x) sqrt(abs(x))
#define re return
#define sz(x) ((int)(x).size ())
#define prev PREV
#define next NEXT

using ll = long long;
using ii = pair<int, int>;
using ld = long double;
using D = double;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vs = vector<string>;

template<typename T> T abs (T x) { re x < 0 ? -x : x; }
template<typename T> T sgn (T x) { re x < 0 ? -1 : (x > 0 ? 1 : 0); }
template<typename T> T sqr (T x) { re x * x; }
template<typename T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }

const int N = 500;

int n;
int m;
ll ans = 0;
int g[N][N];
ii q[N * N];
int used[N][N];
int was[N][N];
int cur;
int l, r;

int go (int i, int j) {
	if (i >= n || j >= n || g[i][j] == 0 || was[i][j]) re 0;
	was[i][j] = 1;
	int cr = r;
	q[r++] = mp (i, j);
	used[i][j] = 1;
	while (l < r) {
		int x = q[l].fi;
		int y = q[l].se;
//		printf ("add %d %d\n", x, y);
		cur += g[x][y];
		l++;
		for (int t = 0; t < 2; t++) {
			int nx = x - int (t == 0);
			int ny = y - int (t == 1);
			if (nx >= 0 && ny >= 0 && !used[nx][ny] && g[nx][ny] > 0) {
				q[r++] = mp (nx, ny);
				used[nx][ny] = 1;
			}
		}
	}
//	printf ("%d %d = %d\n", i, j, cur);
	ans += (ll)(cur - g[i][j]) * g[i][j];
	go (i, j + 1);
	go (i + 1, j);
	while (r > cr) {
		r--;
		int x = q[r].fi;
		int y = q[r].se;
//		printf ("del %d %d\n", x, y);
		cur -= g[x][y]; 
		used[x][y] = 0;
	}
	l = r;
//	printf ("%d %d = %d\n", i, j, cur);
	re 0;
}

int main () {
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < n; j++)
			if (s[j] == '#')
				g[i][j] = 0;
			else
				g[i][j] = s[j] - '0';	
	}	
	l = r = 0;
	cur = 0;
	ans = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (!was[i][j] && g[i][j] > 0)
				go (i, j);
	cout << ans << endl;
	cerr << clock () << endl;
	return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i = n;i >= 0;--i)
#define FOR(i,m,n) for(int i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

int main(void)
{
    int n;
    cin >> n;
    cout << n*n*n << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define emp emplace
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MAXN = 200100;
const ll INF = 1e9;
const ll MOD = 1e9+7;

ll N,Q,a,b,c,d,e,M,X;
ll A,B,C;
map<ll,ll> p;
ll ans;
string S;
vector<char> out;
vector<string> V;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>Q>>A>>B>>C;
	if(A+B+C!=2){
		while(Q--){
			cin>>S;
			if(S=="AB"){
				if(A==0&&B==0){cout<<"No";return 0;}
				if(A>B){out.pb('B');--A;++B;}
				else {out.pb('A');--B;++A;}
			}else if (S=="AC"){
				if(A==0&&C==0){cout<<"No";return 0;}
				if(A>C){out.pb('C');--A;++C;}
				else {out.pb('A');--C;++A;}
			}else{
				if(C==0&&B==0){cout<<"No";return 0;}
				if(C>B){out.pb('B');--C;++B;}
				else {out.pb('C');--B;++C;}
			}
		}
		cout<<"Yes\n";
		for(auto i:out)cout<<i<<'\n';
		return 0;
	}
	for(int i=0;i<Q;++i){
		cin>>S;
		V.pb(S);
	}
	for(int cur=0;cur<Q;++cur){
		S = V[cur];
		// fail con
		if(S=="AB"&&A+B==0){cout<<"No";return 0;}
		if(S=="AC"&&A+C==0){cout<<"No";return 0;}
		if(S=="BC"&&B+C==0){cout<<"No";return 0;}

		if(S=="AB"&&A==0){out.pb('A');--B;++A;continue;}
		if(S=="AB"&&B==0){out.pb('B');--A;++B;continue;}
		if(S=="AC"&&A==0){out.pb('A');--C;++A;continue;}
		if(S=="AC"&&C==0){out.pb('C');--A;++C;continue;}
		if(S=="BC"&&B==0){out.pb('B');--C;++B;continue;}
		if(S=="BC"&&C==0){out.pb('C');--B;++C;continue;}
		if(cur==Q-1){
			out.pb(S[0]);continue;
		}
		string nxt = V[cur+1];
		if(S==nxt){
			out.pb(S[0]);
			if(S=="AB"){A=2;B=0;}
			else if(S=="AC"){A=2;C=0;}
			else {B=2;C=0;}
		}
		if(S=="AB"&&nxt=="AC"){out.pb('A');A=2;B=0;continue;}
		if(S=="AB"&&nxt=="BC"){out.pb('B');B=2;A=0;continue;}
		if(S=="AC"&&nxt=="AB"){out.pb('A');A=2;C=0;continue;}
		if(S=="AC"&&nxt=="BC"){out.pb('C');C=2;A=0;continue;}
		if(S=="BC"&&nxt=="AB"){out.pb('B');B=2;C=0;continue;}
		if(S=="BC"&&nxt=="AC"){out.pb('C');C=2;B=0;continue;}
	}
	cout<<"Yes\n";
	for(auto i:out)cout<<i<<'\n';
	return 0;
}

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

int main(){
  int n,d,flag=0;
  string x,s;
  cin>>n;
  cin>>x;
  cin>>d;
  s=x;
  for(int i=0;i<d;i++){
    int f=0;
    for(int j=0;j<x.size();j++)
      if(x[j]=='0') f=1;
    if(f==0) flag=1;
    if(flag==0){
      for(int j=0;j<x.size();j++){
	if(x[j]=='0'){
	  x[j]='1';
	  break;
	}
      }
    }
    else{
      for(int j=x.size()-1;j>=0;j--){
	if(x[j]=='1'&&s[j]=='1'){
	  x[j]='0';
	  break;
	}
      }
    }
  }
  cout<<x<<endl;
  return 0;
}

Measured memory_bytes: 1208
#include<stdio.h>
int d[2][100010],r[2],u[100010];
int ta[100010],to[200010],nt[200010];
int f(int s,int j){
  int i;
  u[s]=1;
  d[j][r[j]++]=s;
  for(i=ta[s];i+1;i=nt[i]){
    if(u[to[i]])continue;
    if(f(to[i],j))return 1;
  }
  return 1;
}
int main(){
  int n,m,i,a,b;
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++)ta[i+1]=-1;
  for(i=0;i<m;i++){
    scanf("%d %d",&a,&b);
    nt[i  ]=ta[to[i+m]=a];
    nt[i+m]=ta[to[i  ]=b];
    ta[a]=i;
    ta[b]=i+m;
  }
  /*for(i=0;i<n;i++){printf("%d:",i+1);
    for(a=ta[i+1];a+1;a=nt[a])printf("%d ",to[a]);printf("\n");
    }//return 0;*/
  f(1,0);
  u[1]=0;
  f(1,1);
  //for(i=0;i<r[0];i++)printf("%d ",d[0][i]);printf("\n");
  //for(i=0;i<r[1];i++)printf("%d ",d[1][i]);printf("\n");return 0;
  printf("%d\n",r[0]+r[1]-1);
  for(i=r[0];--i;)printf("%d ",d[0][i]);
  printf("1");
  for(i=1;i<r[1];i++)printf(" %d",d[1][i]);
  printf("\n");
  return 0;
}


Measured memory_bytes: 6016