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

using namespace std;

int main() {
    string S, c1, c2, c3;;
    cin >> S;
    c1 = S.substr(0,1);
    c2 = S.substr(1,1);
    c3 = S.substr(2,1);
    if (c1 == c2 && c1 == c3) cout << "No";
    else if (c1 != c2 && c1 == c3) cout << "Yes";
    else if (c1 == c2 && c1 != c3) cout << "Yes";
    else if (c2 == c1 && c2 != c3) cout << "Yes";
    else if (c2 != c1 && c2 == c3) cout << "Yes";
}

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

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  string s;

  map<string, int> m;
  REP(i, N){
    cin >> s; m[s]++;
  }
  int M;
  cin >> M;
  REP(i, M){
    cin >> s; m[s]--;
  }

  int ans = 0;
  for(auto p : m) chmax(ans, p.second);

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int MN=200000+5;
using namespace std;
typedef long long ll;
template<typename T>inline T&IN(T&in){
	in=0;char c=getchar();int f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))in=in*10+c-'0',c=getchar();
	return in*=f;
}
int n;ll ans=1;
int nxt[MN],to[MN],h[MN],cnt,w[MN];
int dis[MN];
queue<int>q;
void add(int u,int v,int _w){to[cnt]=v,nxt[cnt]=h[u],w[cnt]=_w,h[u]=cnt++;}
void input(){
	IN(n);memset(h,-1,sizeof h);memset(dis,63,sizeof dis);
	for(int i=1;i<=n;++i)
		add(i,(i+1)%n,1),add(i,i*10%n,0);
	q.push(1);dis[1]=0;
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int e=h[u],v=to[e];~e;e=nxt[e],v=to[e])if(dis[v]>dis[u]+w[e]){
			dis[v]=dis[u]+w[e];
			q.push(v);
		}
	}
	printf("%d\n",dis[0]+1);
}
int main(){
	input();
	return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;
//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

void solve() {
    int n;
    cin >> n;
    if (n == 1) {
        cout << 1 << endl;
    } else if (n == 2) {
        cout << 8 << endl;
    } else {
        cout << n * n * n << endl;
    }
}

int main(int argc, char *argv[]){
    // /* Regular */
    // int case_num = 1;
    // if (argc > 1 && stoi(argv[1])) cin >> case_num;
    // REP(case_no, case_num) {
    //   cerr << endl << "case " << case_no + 1 << endl;
    //   solve();
    // }
    /* AOJ */
    solve();
    return 0;
}

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "YES"
#define FALSE__ "NO"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}

string s;
int l;

void init()
{
	cin >> s;
	l = s.length();
}

void solve()
{
	if (l == 3) reverse(all(s));
	cout << s << endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int s,n;
  cin>>s;
  vector<int> a(1000000);
  a[s-1]++;
  n=s;
  for(int i=0;;i++){
    if(n%2==0) n/=2;
    else n=3*n+1;
    a[n-1]++;
    if(a[n-1]==2){
      cout<<i+2<<endl;
      break;
    }
  }
}


Measured memory_bytes: 4096
#include<stdio.h>
int main(void){
  int a,b,c,d=1,e=1,i;
  scanf("%d",&a);
  for(i=1;i<=a;i++){
    b=i;
    c=0;
    while(1){
      if(b%2==1) break;
      b=b/2;
      c++;
    }
    if(d<=c){
      d=c;
      e=i;
    }
  }
  printf("%d\n",e);
  return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <new>
#include <sstream>
#include <complex>
#define BIT(nr) (1ULL << (nr))
#define int long long
#define ll long long
#define double complex<long double>
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	
#define LL_HALFMAX 9223372036854775807 / 2	
#define MIN -(9223372036854775807 / 2)
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }

using namespace std;

int G[15][15];

signed main() {
	int n;
	cin >> n;
	vector<int> S(n);
	rep(i, n) {
		cin >> S[i];
	}

	int q;
	cin >> q;
	vector<int> T(q);
	rep(i, q) {
		cin >> T[i];
	}

	sort(ALLOF(S));
	sort(ALLOF(T));

	int ans = 0;

	auto lookit = S.begin();
	while (lookit != S.end()) {
		auto lit = lower_bound(ALLOF(T), *lookit);
		auto rit = upper_bound(ALLOF(T), *lookit);

		int add = rit - lit;
		ans += add;

		lookit = upper_bound(ALLOF(S), *lookit);
	}

	cout << ans << "\n";

	return 0;
}


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

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

int main() {
    int a, b;
    cin >> a >> b;
    cout << gcd(a, b) << endl;
    return 0;
}


Measured memory_bytes: 3088
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	rev := float64(0)
	for i := 0; i < n; i++ {
		rev += 1.0 / nextFloat64()
	}
	fmt.Println(1.0 / rev)
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        ArrayList<Integer> L = new ArrayList<>();
        ArrayList<Integer> R = new ArrayList<>();
        for (int i=0;i<m;i++){
            L.add(scanner.nextInt());
            R.add(scanner.nextInt());
        }
        int l = Collections.max(L);
        int r = Collections.min(R);

        if (l>r){
            System.out.println(0);
        }else {
            System.out.println(r-l+1);
        }

    }

}

Measured memory_bytes: 66752
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int k1[n],k2[n];
    for(int i=0;i<n;i++){
        cin>>k1[i]>>k2[i];
        int ans=k1[i]%k2[i];
        if(ans==0){
            cout<<k2[i]<<endl;
        }
        else{
            cout<<ans<<endl;
        }
    }
        return 0;
}

Measured memory_bytes: 3100
# 参考
# https://atcoder.jp/contests/yahoo-procon2019-qual/submissions/4223019

L = int(input())
a_list = [int(input()) for _ in range(L)]

dp = [[0] * 5 for _ in range(L+1)]

for i in range(L):
    a = a_list[i]

    if a > 0:
        even = a % 2
    else:
        even = 2
    odd = (a + 1) % 2

    #0
    dp[i+1][0] = dp[i][0] + a
    #偶数（0であれば0の項目に含まれるはずなので、0より大きい偶数）
    dp[i+1][1] = min(dp[i][:2]) + even
    #奇数（スタートとゴールの間の区間）
    dp[i+1][2] = min(dp[i][:3]) + odd
    #偶数（0であれば0の項目に含まれるはずなので、0より大きい偶数）
    dp[i+1][3] = min(dp[i][:4]) + even
    #0
    dp[i+1][4] = min(dp[i][:5]) + a
print(min(dp[L]))


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

const int moder = (int) 1e9 + 7;
const int N = 1000010;

int fac[N], inv[N], invf[N];

int powermod(int a, int exp){
    int ret = 1;
    for ( ; exp > 0; exp >>= 1){
        if (exp & 1){
            ret = 1ll * ret * a % moder;
        }
        a = 1ll * a * a % moder;
    }
    return ret;
}

int comb(int a, int b){
    return 1ll * fac[a] * invf[b] % moder * invf[a - b] % moder;
}

int main(){
    fac[0] = invf[0] = 1;
    for (int i = 1; i < N; ++ i){
        fac[i] = 1ll * fac[i - 1] * i % moder;
        inv[i] = i == 1 ? 1 : moder - 1ll * (moder / i) * inv[moder % i] % moder;
        invf[i] = 1ll * invf[i - 1] * inv[i] % moder;
    }
    int n, a, b, c;
    scanf("%d%d%d%d", &n, &a, &b, &c);
    int sum = 0;
    int aa = 1ll * a * inv[a + b] % moder;
    int bb = 1ll * b * inv[a + b] % moder;
    for (int i = n; i <= 2 * n - 1; ++ i){
        int coe = (1ll * powermod(aa, n) * powermod(bb, i - n) + 1ll * powermod(aa, i - n) * powermod(bb, n)) % moder;
        sum = (sum + 1ll * coe * comb(i - 1, n - 1) % moder * i) % moder;
    }
    sum = 1ll * sum * 100 % moder * inv[100 - c] % moder;
    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 11904
use std::io::stdin;

macro_rules! read {
    ($t: ty) => {{
        let mut line = String::new();
        stdin().read_line(&mut line);
        line.trim().parse::<$t>().unwrap()
    }};
    ($($t: ty), *) => {{
        let mut line = String::new();
        stdin().read_line(&mut line);
        let mut iter = line.split_whitespace();
        (
            $(iter.next().unwrap().parse::<$t>().unwrap(), )*
        )
    }}
}
macro_rules! reads {
    ($e:expr, $t:ty) => {{
        let mut v = vec![];
        for _ in 0..$e {
            let mut line = String::new();
            stdin().read_line(&mut line);
            v.push(line.trim().parse::<$t>().unwrap());
        }
        v
    }};
}

fn main() {
    let (a, b, k) = read!(u32, u32, u32);

    let mut n = 101;
    for _ in 0..k {
        for i in (1..n).rev() {
            if a % i == 0 && b % i == 0 {
                n = i;
                break;
            }
        }
    }
    println!("{}", n);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    unordered_map<long long, int> mp;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        mp[x]++;
    }
    vector<long long> ans(2);
    for (auto p : mp) {
        for (int i = 0; i < 2; i++) {
            if(p.second < 2) break;
            if (p.first > ans[i]) {
                ans[i] =  p.first;
                p.second -= 2;
            }
        }
        sort(ans.begin(), ans.end());
        debug(ans);
    }
    cout << ans[0] * ans[1];
    return 0;
}


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

int main(){
  int N;
  cin>>N;
  vector<vector<int>> G(N);
  vector<pair<int,int>> vp;
  for(int i=1;i<N;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
    vp.emplace_back(a,b);
  }

  int K=0;
  map<pair<int,int>,int> I;
  vector<int> cs(N,0); // color of edge between its parent

  vector<int> used(N,0);
  queue<int> que;
  used[0]=1;
  que.emplace(0);
  while(!que.empty()){
    int v=que.front();que.pop();
    if(K<(int)G[v].size()) K=G[v].size();
    int cur=1;
    for(int u:G[v]){
      if(used[u]) continue;
      if(cur==cs[v]) cur++;
      cs[u]=I[make_pair(u,v)]=I[make_pair(v,u)]=cur++;
      used[u]=1;
      que.emplace(u);
    }
  }

  cout<<K<<endl;
  for(auto p:vp) cout<<I[p]<<endl;
  return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

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

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


int main(){
	int h,w;
	cin>>h>>w;
	char m[h][w];
	int sum[h][w];
	bool used[h][w];

	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			cin>>m[i][j];
		}
	}

	int mx=0;
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			memset(sum, -1, sizeof(sum));
			if(m[i][j]=='.'){
				sum[i][j]=0;
				int mx2=0;
				queue<pii> que;
				que.push(pii(i,j));

				while(que.size()){
					pii p=que.front();
					que.pop();
					for (int k = 0; k < 4; k++){
						int nh=p.first+dy[k];
						int nw=p.second+dx[k];
						if(m[nh][nw]=='.'&&sum[nh][nw]==-1&&nh>=0&&nw>=0&&nh<h&&nw<w){
							sum[nh][nw]=sum[p.first][p.second]+1;
							chmax(mx2, sum[nh][nw]);
							que.push(pii(nh,nw));
						}
					}
				}
				chmax(mx,mx2);
			}
		}
	}

	cout<<mx<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	string s; cin >> s;
	int a = -1, b = -1;
	REP(i, s.size() - 1)
	{
		if (s[i] == s[i + 1]) a = i + 1, b = i + 2;
	}
	REP(i, s.size() - 2)
	{
		if (s[i] == s[i + 2]) a = i + 1, b = i + 3;
	}
	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#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()
const ll M = pow(10, 9) + 7;

vector<ll> fac(1000001);  //n!(mod M)
vector<ll> ifac(1000001); //k!^{M-2} (mod M)
int n, m;
ll mpow(ll x, ll n)
{ //x^n(mod M)
    ll ans = 1;
    while (n != 0)
    {
        if (n & 1)
            ans = ans * x % M;
        x = x * x % M;
        n = n >> 1;
    }
    return ans;
}
//conbination
ll comb(ll a, ll b)
{ //aCb(mod M)
    if (a == 0 && b == 0)
        return 1;
    if (a < b || a < 0)
        return 0;
    ll tmp = ifac[a - b] * ifac[b] % M;
    return tmp * fac[a] % M;
}
//permitation
ll perm(ll a, ll b)
{
    if (a < b)
        return 0;
    ll tmp = ifac[a - b] % M;
    return tmp * fac[a] % M;
}
//重複組合せ
ll dupc(ll a, ll b)
{
    if (a == 0 && b == 0)
        return 1;
    if (a < 0 || b == 0)
        return 0;
    ll tmp = ifac[a - 1] * ifac[b] % M;
    return tmp * fac[a + b - 1] % M;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    fac[0] = 1;
    ifac[0] = 1;
    for (ll i = 0; i < 1000000; i++)
    {
        fac[i + 1] = fac[i] * (i + 1) % M;              // n!(mod M)
        ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M)
    }
    ll ans;
    if (m == n)
    {
        ans = perm(m, m) * perm(n, n);
        ans %= M;
        ans *= 2;
    }
    else if (m + 1 == n || n + 1 == m)
    {
        ans = perm(m, m) * perm(n, n);
    }
    else
    {
        ans = 0;
    }
    ans %= M;
    cout << ans << "\n";
}

Measured memory_bytes: 15872
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int count = 0;
		count += n*(n-1)/2;
		count += m*(m-1)/2;
		System.out.println(count);
	}

}


Measured memory_bytes: 21844
def main():
    A,B,M = [int(n) for n in input().split()]
    arrA = [int(n) for n in input().split()]
    arrB = [int(n) for n in input().split()]
    arrC = []
    for i in range(M): 
        x,y,c = [int(n) for n in input().split()]
        x-=1
        y-=1
        arrC.append((x,y,c))
    res = min(arrA) + min(arrB)
    for i in range(M):
        wari = arrC[i]
        price = arrA[wari[0]] + arrB[wari[1]] - wari[2]
        res = min(res, price)
    print(res)
main()


Measured memory_bytes: 28980
s = gets.chomp!

ans = 0
pre = ""
x = false
s.length.times do |i|
    #p [x,i,pre]
    if x 
        x = false
        next
    end

    if s[i] == pre
        x = true
        pre = ""
    else
        pre = s[i]
    end
    ans += 1
end

puts x ? ans - 1 : ans

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

string str;

void C(int len){
    char tmp = str[0];
    for(int i = 1 ; i < len; i++){
        str[i-1] = str[i];
    }
    str[len-1] = tmp;
}

void J(int len){
    char tmp = str[len-1];
    for(int i = len-2; i >=0 ; i--){
        str[i+1] = str[i];
    }
    str[0] = tmp;
}

void E(int len){
    int div = len/2;
    
    if(len%2==0){
        string f = str.substr(0,div) , g = str.substr(div,len-1);
        str = "";
        str += g+f;
    }
    else{
        string f = str.substr(0,div), g = str.substr(div+1,len);
        string mid = str.substr(div,1);
        str = "";
        str += g+mid+f;
    }
}

void A(){
    reverse(str.begin(),str.end());
}

void M(int len){
    for(int i = 0 ; i < len ; i++){
        if('0' <= str[i] && str[i] <= '8'){
            str[i] += 1;
        }
        else if(str[i] == '9') str[i] = '0';
    }
}

void P(int len){
    for(int i = 0 ; i < len ; i++){
        if('1' <= str[i] && str[i] <= '9'){
            str[i] -= 1;
        }
        else if(str[i] == '0') str[i] = '9';
    }
}

int main(){
    int n;
    cin >> n;
    while(n--){
        string order;
        cin >> order >> str;
        
        int len = str.size();
        reverse(order.begin(),order.end());
        
        for(int i = 0 ; i < order.size() ; i++){
            switch(order[i]){
                    case 'J':
                    J(len);
                    break;
                    
                    case 'C':
                    C(len);
                    break;
                    
                    case 'E':
                    E(len);
                    break;
                    
                    case 'A':
                    A();
                    break;
                    
                    case 'M':
                    M(len);
                    break;
                    
                    case 'P':
                    P(len);
                    break;
            }
        }
        cout << str << endl;
    }
    return 0;
}

Measured memory_bytes: 1212
n=int(input())
l=[input().split() for i in range(n)]
for i in range(n):
  l[i].append(i+1)
  l[i][1]=int(l[i][1])
l.sort(reverse=True, key=lambda x:x[1])
l.sort(key=lambda x:x[0])
for i in range(n):
  print(l[i][2])

Measured memory_bytes: 3060
N,A,B,C=map(int,input().strip().split())
l=[int(input()) for n in range(N)]

AMP=0
BMP=0
CMP=0
MP=10**5

def dfs(S,N,l,A,B,C):
    A_l=0
    B_l=0
    C_l=0
    A_cnt=0
    B_cnt=0
    C_cnt=0
    if len(S)==N:
        #calcurlate length and merge MP
        for n in range(N):
            if S[n]==0:
                pass
            elif S[n]==1:
                A_l+=l[n]
                A_cnt+=1
            elif S[n]==2:
                B_l+=l[n]
                B_cnt+=1
            else:
                C_l+=l[n]
                C_cnt+=1
        #calculate lengthen and shorten MP
        global MP
        if A_cnt>=1 and B_cnt>=1 and C_cnt>=1:
            MP=min(MP,(A_cnt-1+B_cnt-1+C_cnt-1)*10+abs(A-A_l)+abs(B-B_l)+abs(C-C_l))
        return
    else:
        for n in range(4):
            S.append(n)
            dfs(S,N,l,A,B,C)
            S.pop()

dfs([],N,l,A,B,C)
print(MP)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i, n) cin>>v[i];
    int now = 0;
    sort(v.begin(), v.end());
    map<int, int> mp;
    vector<int> v_use;
    int bef = v[0];
    mp[bef]++;
    v_use.push_back(bef);
    rep(i, n-1){
        mp[v[i+1]]++;
        if(v[i+1] != bef){
            v_use.push_back(v[i+1]);
            bef = v[i+1];
        }
    }
    vector<int> dp(1000005);
    rep(i, v_use.size()){
        int a = v_use[i];
        int b = a;
        while(b<=1000001){
            dp[b]++;
            b+=a;
        }
    }
    int ans = 0;
    rep(i, v_use.size()){
        if(dp[v_use[i]]==1 && mp[v_use[i]] == 1) {
            ans++; 
        }
    }
    cout<<ans<<endl;

    return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main() {
    int n; cin >> n;
    vi a(n); rep(i, n) cin >> a[i];
    sort(rall(a));

    ll tot1 = 0, tot2 = 0;
    
    /*
        n = 4, n/2 = 2
        tot1 = p0 - p1 + p2 - p1 + p2 - p3 = p0 - 2p1 + 2p2 - p3
        tot2 = p1 - p0 + p1 - p2 + p3 - p2 = -p0 + 2p1 - 2p2 + p3
        n = 5, n/2 = 2
        tot1 = p0 - p1 + p2 - p1 + p2 - p3 + p4 - p3 = p0 - 2p1 + 2p2 - 2p3 + p4
        tot2 = p1 - p0 + p1 - p2 + p3 - p2 + p3 - p4 = -p0 + 2p1 - 2p2 + 2p3 - p4
    */
    
    if(n&1){
        rep(i, n){
            if(i < n/2 - 1) tot1 += 2 * a[i];
            else if(i == n/2 - 1 || i == n/2) tot1 += a[i];
            else tot1 -= 2 * a[i];
        }
        
        rep(i, n){
            if(i < n/2) tot2 += 2 * a[i];
            else if(i == n/2 || i == n/2 + 1) tot2 -= a[i];
            else tot2 -= 2 * a[i];
        }
    }
    else{
        rep(i, n){
            if(i < n/2 - 1) tot1 += 2 * a[i];
            else if(i == n/2 - 1) tot1 += a[i];
            else if(i == n/2) tot1 -= a[i];
            else tot1 -= 2 * a[i];
        }
    }

    cout << max(tot1, tot2) << endl;
    return;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int a,b,c,d;
signed main(){
    cin>>a>>b>>c>>d;
    int T=(c%b==0?c/b:c/b+1);
    int A=(a%d==0?a/d:a/d+1);
    if(T<=A)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3600
#include<iostream>
using namespace std;
int main()
{
	int n,a,b,c,d;
	cin>>n;
	d=n%10;
	c=(n/10)%10;
	b=(n/100)%10;
	a=n/1000;
	if(a+b+c+d==7) printf("%d+%d+%d+%d=7\n",a,b,c,d);
	else if(a+b+c-d==7)printf("%d+%d+%d-%d=7\n",a,b,c,d);
	else if(a+b-c+d==7)printf("%d+%d-%d+%d=7\n",a,b,c,d);
	else if(a+b-c-d==7)printf("%d+%d-%d-%d=7\n",a,b,c,d);
	else if(a-b+c+d==7)printf("%d-%d+%d+%d=7\n",a,b,c,d);
	else if(a-b+c-d==7)printf("%d-%d+%d-%d=7\n",a,b,c,d);
	else if(a-b-c+d==7)printf("%d-%d-%d+%d=7\n",a,b,c,d);
	else if(a-b-c-d==7)printf("%d-%d-%d-%d=7\n",a,b,c,d);
	return 0;
}

Measured memory_bytes: 764
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		double p = P / 100.0;
		switch(X % 2){
			case 0:
				Console.WriteLine( (X / 2) * (1.0 / p) );
				break;
			case 1:
				Console.WriteLine( (X / 2 + 1) * (1.0 / p) );
				break;
		}
		
		
		
	}
	int X,P;
	public Sol(){
		X = ri();
		P = ri();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13140
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pNO cout << "NO" << endl
#define pYES cout << "YES" << endl
using namespace std;
using ll = long long;


int main() {
	int N, K; cin >> N >> K;
	string s; cin >> s;
	char prev = s[0];
	vi vec;
	vec.push_back(0);
	for (int i = 0; i < N; i++) {
		if (s[i] == prev) vec.back()++;
		else {
			vec.push_back(1);
			prev = s[i];
		}
	}
	vi acc(vec.size() + 1);
	for (int i = 1; i < acc.size(); i++) {
		acc[i] = acc[i - 1] + vec[i-1];
	}

	int ans = 0;
	if (s[0] == '0') {
		for (int s = 0; s < acc.size(); s += 2) {
			int g = min(s + 2 * K, int(acc.size()) - 1);
			if (s == 0) {
				ans = max(ans, acc[g]);
			}
			else {
				ans = max(ans, acc[g] - acc[s - 1]);
			}
		}

	}
	else {
		for (int s = 1; s < acc.size(); s += 2) {
			int g = min(s + 2 * K, int(acc.size()) - 1);
			ans = max(ans, acc[g] - acc[s - 1]);
		}
	}

	cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  
  int i;
  vector<string> w(n);
  set<string> s;
  for(i = 0; i < n; i++){
    cin >> w.at(i);
    s.insert(w.at(i));
  }
  
  bool ans = true;
  if(s.size() == n){
    for(i = 1; i < n; i++){
      string a, b;
      a = w.at(i - 1);
      b = w.at(i);
      if(a.at(a.size() - 1) != b.at(0)) ans = false;
    }
  }
  else ans = false;
  
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#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 drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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 const INF = 1001001001;


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

int A,B,K;
cin >> A >> B >> K;
int U = A+K-1;
int V = B-K+1;
if(U >= V) {
    for(int i = A; i <= B; ++i) cout << i << endl;
}
else {
    for(int i = A; i <= U; ++i) cout << i << endl;
    for(int i = V; i <= B; ++i) cout << i << endl;
}

return 0;
}

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

struct process{
    string name;
    int time;
};

int main(){
    int n, q; cin >> n >> q;
    queue<process> round;

    rep(i, n){
        process x;
        cin >> x.name >> x.time;
        round.push(x);
    }

    int elapsed_time = 0;
    while(true){
        process x = round.front();
        round.pop();

        if(x.time  - q <= 0){
            elapsed_time += x.time;
            cout << x.name << " " << elapsed_time << endl;
        }else{
            elapsed_time += q;
            x.time = x.time - q;
            // cout << x.name << " " << elapsed_time << " " << "after process " << x.time + q << "----->" << x.time << endl;
            round.push(x);
        }

        if(round.size() == 0){
            break;
        }
    }

}



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

#include <iostream>
#include <fstream>

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

using namespace std;

typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x,y)                out<<x<<" "<<y
#define p1d(a,n)                for(int ix=0;ix<n;ix++) out<<a[ix]<<" "; out<<endl
#define p2d(a,n,m)              for(int ix=0;ix<n;ix++){ for(int jx=0;jx<m;jx++) out<<a[ix][jx]<<" "; out<<endl;}
#define range(v)                v.begin(),v.end()
#define w(x)                    while(x--)
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2

int count(int n, int k){
    int ans= 1;
    if(n < 0) return 0;
    if(k>n)
        return 0;
    f(i,0,k){
        ans*=(n-i);
    }
    f(i,0,k){
        ans/=(i+1);
    }
    return ans*pow(9,k);
}

int count_last(string n, int k){
    int used = 0;
    int ans = 0;
    int tt = 0;
    f(i,0,n.size()){
        if(used == k) break;
        if(i == 0){
        if(n[i] != '0'){ used++;
        ans+= (n[i]-'1')*count(n.size()-i-1, k-used);
        }}
        if(i>=1){
            if(n[i] != '0'){
                ans+= count(n.size()-i-1, k-used);
                used++;
                ans+= (n[i]-'1')*count(n.size()-i-1, k-used);

            }else{
                tt++;
            }
        }

    }
    if(used == k) ans++;
    return ans;
}

int ssolve(string n, int k){
    int ans = count(n.size()-1, k);
    ans+= count_last(n, k);
    return ans;
}

int nonz(int i){
    int r = 0;
    while(i!=0){
        if(i%10 != 0)r++;
        i/=10;
    }
    return r;
}

int count_natora(int n, int k){
    int c = 0;
    f(i,1,n+1){
        if(nonz(i) == k) c++;
    }
    return c;
}
class EAlmostEverywhereZero {
public:
	void solve(std::istream& in, std::ostream& out) {
        string n;
        s(n);
        int k;
        s(k);

        out<<ssolve(n,k)<<endl;

	}
};


integer main() {
	EAlmostEverywhereZero solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
}


Measured memory_bytes: 384
def compress(digits):
  compressed_list = list()
  for digit in digits:
    if compressed_list == [] or compressed_list[-1][1] != digit:
      compressed_list.append([1, digit])
    else:
      compressed_list[-1][0] += 1

  return compressed_list


def decompress(compressed_list):
  new_digits = ""
  for pair in compressed_list:
    new_digits += "{}{}".format(*pair)

  return new_digits


while 1:
  proc_num = int(input())
  if proc_num == 0:
    break
  digits = input().strip()

  for i in range(proc_num):
    compressed_list = compress(digits)
    digits = decompress(compressed_list)
  print(digits)

Measured memory_bytes: 10932
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(vec) vec.begin(), vec.end()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define repc(bit, k, n) for (ll bit = (1 << k) - 1; bit < (1 << n); bit = next_combination(bit))
#define repi(itr, vec) for (auto itr = vec.begin(); itr != vec.end(); ++itr)
using namespace std;

void uniq(vector<ll> &vec)
{
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return;
}
ll GCD(ll a, ll b)
{
  if (b == 0)
    return a;
  return GCD(b, a % b);
}
ll solve(ll k, const vector<ll> &a)
{
  ll cur = k;
  while (true)
  {
    auto itr = lower_bound(ALL(a), cur);
    if (itr == a.end())
      return -1;
    if ((*itr) >= 2 * cur)
      return cur;
    cur = (*itr) - cur;
  }
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n)
  {
    cin >> a[i];
  }
  sort(ALL(a));
  ll flag = solve(k, a);
  if (flag == -1)
  {
    cout << "IMPOSSIBLE\n";
    return 0;
  }
  ll gcd = a[0];
  rep(i, n - 1)
  {
    gcd = GCD(max(gcd, a[i + 1]), min(gcd, a[i + 1]));
  }
  if (flag % gcd == 0)
    cout << "POSSIBLE\n";
  else
    cout << "IMPOSSIBLE\n";

  return 0;
}

Measured memory_bytes: 3976
//@source: 
//@create: 19:10:35 Sunday 02/08/2020
//@author: nghethuat102
#include <bits/stdc++.h>
using namespace std;

#define len(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define discrete(x) sort(all(x), x.erase(unique(all(x)), x.end())

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int d = 0;
    int c = n - 1;
    int cnt = 0;
    while (d < c) {
        while (d < n && s[d] == 'R') {
            ++d;
        }
        while (c >= 0 && s[c] == 'W') {
            --c;
        }
        if (d < c) {
            swap(s[d], s[c]);
            cnt++;
            d++;
            c--;
        }
    }
    cout << cnt << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    for (int it = 1; it <= t; ++it) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int di[] = {-1, 0, 0, 1};
int dj[] = {0, -1, 1, 0};

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

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

    queue<P> q;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (m[i][j] == '#') {
                q.emplace(i, j);
            }
        }
    }
    q.emplace(-1, -1);

    int ans = 0;
    while (true) {
        int i = q.front().first;
        int j = q.front().second;
        q.pop();
        if (i == -1 && j == -1) {
            if (q.empty()) {
                break;
            }
            ans++;
            q.emplace(-1, -1);
            continue;
        }
        for (int k = 0; k < 4; k++) {
            int ni = i + di[k];
            int nj = j + dj[k];
            if (ni >= 0 && ni < h && nj >= 0 && nj < w) {
                if (m[ni][nj] == '.') {
                    m[ni][nj] = '#';
                    q.emplace(ni, nj);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9488
#include <iostream>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int N, A;
  cin >> N;
  int c = 1;
  int ret = 0;
  for (int i=0; i<N; i++) {
    cin >> A;
    if (A == c) {
      c++;
    } else {
      ret++;
    }
  }
  if (ret == N) cout << -1 << endl;
  else cout << ret << endl;
}

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

#define pb push_back
#define all(x) begin(x), end(x)
#define log(x) cout << (x) << endl
#define loop(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(i, n) for(int i=0;i<(int)(n);++i)

struct cell {
	int up,down,left,right;
	bool free;
};

int main() {
	int h,w;
	char x;
	cin>>h>>w;
	vector<vector<cell>> grid(h);
	rep (i, h) {
		rep (j, w) {
			cin>>x;
			grid[i].pb({0,0,0,0,x=='.'});
		}
	}

	int mx = 0;

	cell* c;
	rep (i, h) {
		rep (j, w) {
			c = &grid[i][j];

			if (c->free) {

				// right
				if (!c->right) {
					if (j==0 || !grid[i][j-1].free) {
						cell* d;
						int cnt = 0;
						loop (k, j+1, w) {
							d = &grid[i][k];
							if (d->free) d->left = ++cnt;
							else break;
						}
						c->right = cnt;						
					} else {
						c->right = grid[i][j-1].right-1;
					}
				}

				// down
				if (!c->down){
					if (i==0 || !grid[i-1][j].free) {
						cell* d;
						int cnt = 0;
						loop (k, i+1, h) {
							d = &grid[k][j];
							if (d->free) d->up = ++cnt;
							else break;
						}
						c->down = cnt;
					} else {
						c->down = grid[i-1][j].down-1;
					}
				}

				mx = max(mx, 1+c->up+c->down+c->left+c->right);
			}
		}
	}

	log(mx);
}


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int n,m; cin>>n>>m;
  vector<int> cnt(n, 0);
  for (int i=0; i<m; i++) {
    int a,b; cin>>a>>b;
    a--; b--;
    cnt[a]++;
    cnt[b]++;
  }
  for (int i=0; i<n; i++) {
    cout << cnt[i] << endl;
  }
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var xs = Console.ReadLine().Split(' ')
                .Select(num => int.Parse(num))
                .OrderBy(x => x)
                .ToArray();
            var result = int.MaxValue;
            for (var i = 1; i <= 100; i++)
            {
                var tmp = 0;
                for (var j = 0; j < xs.Length; j++)
                {
                    var sa = i - xs[j];
                    tmp += sa * sa;
                }

                if (result > tmp) result = tmp;
            }

            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 28424
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;



int main(){

    int count=0,i=0,j=1,k,l,n=0;
    string s;
    char a;
    cin >> s;
    sort(s.begin(),s.end());
    if(s[0]==s[1] && s[2]==s[3] && s[0]!=s[2])cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
lst = [k+1 for k in range(n)]
lmax = 0
rmin = 10**5
for i in range(m):
    lx,rx = map(int,input().split())
    if lx >= lmax:
        lmax = lx
    if rx <= rmin:
        rmin = rx
res = rmin - lmax + 1
if res > 0:
    print(res)
else:
    print(0)

Measured memory_bytes: 7088
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, q;
	cin >> a >> b >> q;
	vl s(a), t(b);
	REP(i, a)cin >> s[i];
	REP(i, b)cin >> t[i];
	sort(ALL(s));
	sort(ALL(t));
	REP(i, q) {
		ll x; cin >> x;
		ll ans = INF * INF;
		int ls = upper_bound(ALL(s), x) - s.begin() - 1, rs = lower_bound(ALL(s), x) - s.begin(),
			lt = upper_bound(ALL(t), x) - t.begin() - 1, rt = lower_bound(ALL(t), x) - t.begin();
		if (ls >= 0 && lt >= 0) {
			chmin(ans, x - min(s[ls], t[lt]));
		}
		if (rs < a&&rt < b) {
			chmin(ans, max(s[rs], t[rt]) - x);
		}
		if (ls >= 0 && rt < b) {
			chmin(ans, 2 * min(x - s[ls], t[rt] - x) + max(x - s[ls], t[rt] - x));
		}
		if (rs < a&&lt >= 0) {
			chmin(ans, 2 * min(s[rs] - x, x - t[lt]) + max(s[rs] - x, x - t[lt]));
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
typedef long long ll;
using namespace std;

int main(){
    ll N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;
    ll ans = 4;
    ans += max((N + min({A, B, C, D, E}) - 1) / min({A, B, C, D, E}), ll(1));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256