akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
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); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

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

set<string> st;

ll d[26];

bool make() {
    REP(i, 26) {
        if (d[i] != 0) {
            c = i + 'a';
            d[i] = 0;
            break;
        }
    }
    REP(i, s.size()) {
        sum = 0;
        if (s[i] == c) {
            FOR(j, i, s.size() + 1) {
                st.insert(s.substr(i, j - i + 1));
                sum++;
                if (sum >= k) {
                    break;
                }
            }
        }
    }
    if (st.size() >= k) {
        cnt = 0;
        for (auto x : st) {
            cnt++;
            if (cnt == k) {
                cout << x << endl;
                return true;
            }
        }
    }
    return false;
}

int main() {
    cin >> s >> k;
    REP(i, s.size()) {
        d[s[i] - 'a']++;
    }

    if (make()) {
        return 0;
    }
    if (make()) {
        return 0;
    }
    if (make()) {
        return 0;
    }
    if (make()) {
        return 0;
    }
    if (make()) {
        return 0;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
#define ll long long


int main(){
    std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
    int n, k,ans=0;
    cin >> n >> k;
    int cnt[101];
    memset(cnt, 0, sizeof(cnt));
    while(k--){
        int input;
        cin >> input;
        while(input--){
            int a;
            cin >> a;
            cnt[a]++;
        }
    }
    for (int i= 1; i <= n;i++){
        if(cnt[i]==0)
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fastio ios_base::sync_with_stdio(false); cout.tie(NULL);
using namespace std;

int main()
{
	fastio;
	lli a,b;
	cin>>a>>b;
	cout<<(a*b);
	return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>
#include<type_traits>

using namespace std;
using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;
constexpr ll LONGINF = 1050000000000000000;


int main() {
	int n; cin >> n;
	vector<tuple<string, int, int>> a;
	for (int i = 1; i <= n; i++) {
		string s;
		int p;
		cin >> s >> p;
		a.push_back(make_tuple(s, -1*p, i));
	}

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

	for (auto x : a) {
		cout << get<2>(x) << endl;
	}

	return 0;
}

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

int main(void) {
	int N, K;
	scanf("%d %d", &N, &K);
	string S;
	cin >> S;
	S[K - 1] -= 'A' - 'a';
	cout << S << "\n";
	return 0;
}


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

int main() {
	int N;
	cin >> N;
	int cmax = 0;
	int cnt = 0;
	vector<int> pr;
	for (int i=0;i<N;i++) {
		int tmp;
		cin >> tmp;
		if (cmax<tmp) {
			cmax=tmp;
			cnt = i;
		}
		pr.push_back(tmp);
	}
	int cost = 0;
	for (int i=0;i<N;i++) {
		if (i==cnt) {
			cost += pr[i]/2;
		} else {
			cost += pr[i];
		}
	}

	cout << cost << endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
using namespace std;
const int N = 200;
int f[N][N];
int n, m;
char a[N][N];
int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= m; j ++) {
            char c;
            scanf(" %c", &c);
            a[i][j] = c;
            if (i ==1 && j == 1)
                f[i][j] = (c == '#');
            else {
                f[i][j] = 1e9;
                if (i > 1)
                    f[i][j] = min(f[i][j], f[i - 1][j] + (a[i - 1][j] != c && c == '#'));
                if (j > 1)
                    f[i][j] = min(f[i][j], f[i][j - 1] + (a[i][j - 1] != c && c == '#'));
            }
        }
    printf("%d\n", f[n][m]);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n;
    cin >> n;
    for(int i = 0;i < n;i++)
    {
        int a,b,c;
        cin >> a >> b >> c;
        b+=c;
        if(a < b||(a-b)%2 == 1){cout << "No" << endl;return 0;}
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a[101];int n,i;
int main(){
	scanf("%d%*d",&n);
	for(i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(i=0;i<n;i++)
		cout<<a[i];
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <chrono>
#include <numeric>
#include <set>

using namespace std;

class cDict
{
	string com, op;
	set<string> sd;
	set<string>::iterator it;

	void insert(string &);
	void find(string &);

public:
	cDict()
	{
	}

	~cDict()
	{
	}

	void command(string &);
};

void cDict::insert(string &s)
{
	sd.insert(s);
}

void cDict::find(string &s)
{
	it = sd.find(s);
	if (it != sd.end())
	{
		cout << "yes" << endl;
	}
	else
	{
		cout << "no" << endl;
	}
}

void cDict::command(string &s)
{
		istringstream iss(s);
		iss >> com >> op;
		if (com == "insert")
		{
			insert(op);
		}
		else if (com == "find")
		{
			find(op);
		}
}

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

	int n;
	string str;
	cin >> n;
	cin.ignore();

	cDict cd;

	for (int i = 0; i < n; ++i)
	{
		getline(cin, str);
		cd.command(str);
	}

	return 0;
}

Measured memory_bytes: 29704
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
int n,m,a[15],q,ans;
int u[55][5];
void dfs(int x,int pre){
    if(x == n + 1){
        int cur = 0;
        rep(i,1,q) {
            if(a[u[i][1]] - a[u[i][0]] == u[i][2]) cur += u[i][3];
        }
        ans = max(cur, ans);
        return;
    }
    rep(j,pre,m) {a[x] = j;dfs(x+1,j);}
}
int main()
{
    scanf("%d%d%d",&n,&m,&q);
    rep(i,1,q){
        rep(j,0,3) scanf("%d",&u[i][j]);
    }
    dfs(1,1);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3828
#include <iostream>
#define MAXN 3000
using namespace std;

int N, ans, a, b, k, m;
string s;

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> s;
    for (int j = 1; j < s.length(); j++) {
      if (s[j] == 'B' && s[j-1] == 'A') ans++;
    }
    if (s[0] == 'B') a--, k++;
    if (s[s.length()-1] == 'A') a++;
    if (s[0] == 'B' && s[s.length()-1] == 'A') m++;
  }
  if (a < 0) k += a;
  if (k == N || (m == k && !a)) k--;
  ans += max(0, k);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int i, m, s, e, sp;

	cin >> i >> m >> s >> e;
	sp = i + m + s + e;
	cin >> i >> m >> s >> e;
	if (sp > i + m + s + e) cout << sp << endl;
	else cout << i + m + s + e << endl;

	return (0);
}

Measured memory_bytes: 3028
#include <algorithm>
#include <cstdio>
const int MAXN = 305;
const int S = 3;
double dp[MAXN][MAXN][MAXN]{ };
int cnt[S]{ };
int A, N;

void init() {
  int a = cnt[0];
  int b = cnt[1];
  int c = cnt[2];
  for (int i = a+b+c; i >= 0; --i) {
    for (int j = b+c; j >= 0; --j) {
      for (int k = c; k >= 0; --k) {
        dp[i][j][k] = -1.0;
      }
    }
  }
  dp[0][0][0] = 0.0;
}

// 1. Geometric expectation
//    Re-roll on empty sushi plates (failure).
// 2. Traverse an edge of the DFA
//    Weighted summation of expectations of simpler states.

double dfs(int i, int j, int k) {
  if (dp[i][j][k] >= 0.0) {
    return dp[i][j][k];
  }
  int sum = i + j + k;
  double p = 0.0;
  p += 1.0 * N / sum;
  if (k) p += 1.0 * k / sum * dfs(i, j+1, k-1);
  if (j) p += 1.0 * j / sum * dfs(i+1, j-1, k);
  if (i) p += 1.0 * i / sum * dfs(i-1, j, k);
  return dp[i][j][k] = p;
}

int main() {
  scanf("%d", &N);
  for (int i = 0; i < S; ++i) {
    cnt[i] = 0;
  }
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &A);
    ++cnt[A-1];
  }
  init();
  printf("%.12f\n", dfs(cnt[0], cnt[1], cnt[2]));
  return 0;
}

Measured memory_bytes: 219392
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <string>
#include <set>
#include <tuple>
#include <algorithm>
#include <unordered_map>
#include <vector>

using namespace std;

int main()
{
	int N;
	int A[100002];
	int out[100002];
	int sum = 0;
	int prev = 0;

	cin >> N;
	N += 2;

	A[0] = 0;
	for (int i = 1; i < N - 1; i++)
	{
		cin >> A[i];
		sum += std::abs(A[i] - prev);
		prev = A[i];
	}
	A[N - 1] = 0;
	sum += std::abs(A[N - 2]);

	for (int i = 1; i < N-1; i++)
	{
		int small = std::min(A[i - 1], A[i + 1]);
		int large = std::max(A[i - 1], A[i + 1]);
		if (A[i] > small && A[i] < large)
			out[i] = sum;
		else {
			int smallestDiff = std::min(std::abs(A[i] - large), std::abs(A[i] - small));
			out[i] = sum - smallestDiff * 2;
		}
	}

	for (int i = 1; i < N-1; i++)
	{
		cout << out[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair
 
typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;
 
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<string, string> ss;
typedef pair<int, ss> iss;
 
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<int, pii>> vpiii;
 
typedef map<string, string> mss;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, ll> mill;
typedef map<int, vpii> mivpii;

const int MAXN = 100;
const int MAXK = 1e5;

int a[MAXN + 1];
int dp[MAXK + 1];

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main() {
	fast_io();
//	freopen("input/dp_j.txt", "r", stdin);
	
	int n, k;
	cin >> n >> k;
	
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	for(int i = 1; i <= k; i++) {
		for(int j = 0; j < n; j++) {
			if(i - a[j] >= 0 and !dp[i - a[j]]) dp[i] = true;
		}
	}
	cout << (dp[k] ? "First" : "Second") << '\n';
	
	return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

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

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

int main() {
	ll K; cin >> K;
	int N = 50;
	V<ll> a(N);
	rep(i, N) a[i] = i + (K / N);
	K %= N;

	rep(i, K) {
		a[i] += N;
		rep(j, N) if (j != i) {
			--a[j];
		}
	}

	cout << N << endl;
	rep(i, N) cout << a[i] << (i == N-1 ? '\n' : ' ');

	return 0;
}

Measured memory_bytes: 256
module DirectedGraph
  (* 道の表現 *)
  (Path : sig
    type t
    (* 辺の名前 *)
    type edge
    (* 長さ0の道 *)
    val nil : t
    (* 道の後ろに辺を付け足した道 *)
    val snoc : t -> edge -> t
  end) :
sig
  (* BFSにより，重みのないグラフの最短経路を求める *)
  val bfs :
    (* 頂点数（Hashtblを用いるので目安程度） *)
    int ->
    (* 辺の名前が付いた隣接リスト *)
    ('v -> ('v * Path.edge) list) ->
    (* 始点 *)
    'v ->
    (* 最短経路を返す関数 辿り着けなければNoneを返す） *)
    ('v -> Path.t option)
end = struct
  let rec bfs_aux es d frontier t =
    try Some (Hashtbl.find d t) with
    | Not_found ->
        match !frontier with
        | [] -> None
        | _ :: _ ->
            frontier := List.fold_right (fun u ->
              List.fold_right (fun (v, e) frontier ->
                if Hashtbl.mem d v
                then frontier
                else (Hashtbl.add d v (Path.snoc (Hashtbl.find d u) e); v :: frontier))
              (es u)) !frontier [];
            bfs_aux es d frontier t

  (*
   * 終点に辿り着いた時点で探索を切り上げるが，
   * 戻り値の関数を覚えておくと，途中まで探索した結果が再利用される
   * （#trace bfs_aux すると分かりやすい）
   *)
  let bfs n es s =
    let d = Hashtbl.create n in
    Hashtbl.add d s Path.nil;
    let frontier = ref [s] in
    bfs_aux es d frontier
end
    
module G = DirectedGraph (struct
  type t = int
  type edge = unit
  let nil = 0
  let snoc t _ = t + 1
end)

let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let es = Array.make n [] in
  for i = 0 to m - 1 do
    Scanf.scanf "%d %d\n" @@ fun u v ->
      es.(u - 1) <- v - 1 :: es.(u - 1)
  done;
  Scanf.scanf "%d %d\n" @@ fun s t ->
  let dp = G.bfs (3 * n) (fun (v, m) ->
    List.map (fun u -> ((u, (m + 1) mod 3), ())) es.(v)) (s - 1, 0) in
  match dp (t - 1, 0) with
  | None -> print_endline "-1"
  | Some d -> Printf.printf "%d\n" @@ d / 3


Measured memory_bytes: 29952
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define RFOR(i, b, a) for (ll i = b; i >= a; --i)
#define ALL(x) x.begin(), x.end()
#define DEBUG(args...) { string _s = #args; replace(ALL(_s), ' ', '\0');\
replace(ALL(_s), ',', ' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);}
#define endl "\n"
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void _debug(istream_iterator<string>) {}
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T first, Args... args) {
    cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& out, const pair<T1, T2>& p) {
    return out << "(" << p.F << ", " << p.S << ")";
}
template<typename T>
inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty()) return out << "[]";
    else { out << '['; for (auto& e : v) { out << e << ", "; } return out << "\b\b]"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const set<T>& s) {
    if (s.empty()) return out << "{}";
    else { out << '{'; for (auto& e : s) { out << e << ", "; } return out << "\b\b}"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const unordered_set<T>& s) {
    return out << set<T>(ALL(s));
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const map<T1, T2>& m) {
    if (m.empty()) return out << "{}";
    out << '{'; for (auto& p : m) { out << p << ", "; } return out << "\b\b}";
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const unordered_map<T1, T2>& m) {
    return out << map<T1, T2>(ALL(m));
}
template<typename T>
inline ostream& operator << (ostream& out, const ordered_set<T>& s) {
    return out << set<T>(ALL(s));
}

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef unordered_map<ll, ll> STll;
/************************************** MAIN PROGRAM ********************************************/
const int MAX = 2001;
string grid[MAX];
int main()
{
    //freopen("input.txt", "r", stdin);
    SPEED

    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &e : a) {
        cin >> e;
    }
    sort(ALL(a));
    ld run = a[0];
    for (int i = 1; i < n; ++i) {
        run = (a[i] + run) / 2.0;
    }
    cout << fixed << setprecision(15);
    cout << run;
}
/************************************** END OF PROGRAM ******************************************/
/** Stuff you should look for:
 * int overflow, array bounds, over-counting
 * special cases (n=1?), set/unordered_set TLE, multi-set/set error
 * do something instead of nothing and stay organized
 */


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

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ldb long double 
#define db double
#define int long long

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int md = 1e9+7;
const int MX = 2e5+5;
const int INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

int power_md(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res=(res%md*a%md)%md;
  a=(a%md*a%md)%md;
  n/=2;
}
res%=md;
return res;
}

int power(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a=a*a;
  n/=2;
}
return res;
}

int abst(int a)
{
 return ((a<0)?(-1*a):(a));
}

class cmp_set{
public:
	bool operator() (int a, int b){
		return a > b;
	}
};

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int fun(int i)
{
    if(i%2)
     return (3*i+1);
     else
      return (i/2);
}

int32_t main()
{
   int n;
   cin>>n;
   int arr[n];
   int cnt=0;
   for(int i=0;i<n;i++)
   {
       cin>>arr[i];
       if(i==0)
        cnt+=arr[i];
       else
       {
           if(arr[i]>=arr[i-1])
           {
               cnt+=(arr[i]-arr[i-1]);
           }
       }
   }
   cout<<cnt<<"\n";
    return 0; 
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int main(void)
{
    int n, m;

    cin >> n >> m;
    cout << (n == 1 || m == 1 ? 1 : ((long long)n * m + 1) / 2) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include <string> 

int main(){
  std::string sent;
  int gyou,num=0;
  std::cin >> gyou;
  getline(std::cin, sent);
  for(int i=0;i<gyou;++i){
    num=0;
    getline(std::cin, sent);
    std::string bef="Hoshino",aft="Hoshina";
    while(num!=-1){
      num=(int)(sent.find(bef));
      if(num!=-1){
      sent.replace(num,bef.size(),aft);
      }
    }
    std::cout << sent << std::endl;
    /*if(i<gyou-1)
    std::cout << std::endl;*/
  }
  return 0; 
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
const double PI  =3.141592653589793238463;
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<ll,ll> P;
const int mod = 1e9+7;

struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a){
        (x+=a.x)%=mod;
        return *this;
    }
    mint& operator-=(const mint a){
        (x-=mod-a.x)%=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x)%= mod;
        return *this;
    }
    mint operator+(const mint a)const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a)const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a)const{
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
      if(!t)return 1;
      mint a = pow(t>>1);
      a*=a;
      if(t%1)a*=*this;
      return a;
    }

    // for prime mod
    mint inv() const {
      return pow(mod-2);
    }
    mint& operator/=(const mint a){
      return (*this) *= a.inv();
    }
    mint operator/(const mint a)const{
      mint res(*this);
      return res/=a;
    }
};

struct combination{
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i<n;++i)fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i>=1;--i) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k){
    if(k<0 || k>n)return 0;
    return fact[n] * ifact[k] + ifact[n-k]; 
  }
};

// int f(unsigned long a){
//     int t =0;
//     while(a/10>0){
//         a/=10;
//         ++t;
//     }
//     return t;
// }

int main(){
    int n; 
    cin >> n;
    vector<ll> A(n);
    rep(i,n)cin >> A[i];
    long long ans = 0;
    // bool flag = 0 ;
    // bool zero = 0;
    // unsigned long a;
    // cin >> ans;
    ans = A[0];
    rep(i,n){
        if(A[i]==0){
            cout<<0 <<endl;
            return 0;
        }
    }

    rrep(i,n-1){
        if(A[i]>(unsigned long)pow(10,18)/ans){
            // flag=1;
            cout << -1 << endl;
            return 0;
        }
        ans*=A[i];
        // if(a==0)zero=1;
        // keta_ans = f(ans);
        // cout << keta_ans <<": "<< keta<<endl;
    }
    // if(zero)cout<<0<<endl;
    // if(flag)cout << -1<<endl;
    cout << ans << endl;
    // if(ans<=(unsigned long)pow(10,18))cout<<ans<<endl;
    // else cout << -1 <<endl;
    // unsigned long tmp =1000000000000000001; 
    // if(tmp>pow(10,18))cout << "yes"<<endl;
    // else cout << "no"<<endl;
    return 0;
}

Measured memory_bytes: 4032
s=input()
n=len(s)
ans=[0]*(n+1)
  
for i in range(0,n):
  if s[i]=='<':
    ans[i+1]=ans[i]+1
for i in range(n-1,-1,-1):
  if s[i]=='>':
    ans[i]=max(ans[i+1]+1,ans[i])
print(sum(ans))

Measured memory_bytes: 29168
#include<stdio.h>
#include<math.h>

int main(void)
{
	int n;
	int i,j,c,k=0,t=0;
	
	scanf("%d",&n);
	
	int a[n];
	
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		
	}
	
	for(i=0;i<n;i++)
	{
		c=0;
		c=sqrt(a[i]);
		for(j=3;j<=c+1;j++)
		{
			if(a[i]<2||a[i]%2==0)
			{
				k++;
				break;
			}
			else if(a[i]%j==0)
			{
				k++;
			}
		}
		
		if(k==0)
		{
			t++;
		}
		else k=0;
	}
	
	printf("%d\n",t);
	
	return 0;
}


Measured memory_bytes: 2092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n) for (int i = 1; i <= (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
using Grid = vector<vector<int>>;
using vi = vector<int>;
const int mod = 1000000007;
struct mint {
    ll x;
    mint(ll x = 0)
        : x((x % mod + mod) % mod) {}
    mint operator-() const {
        return mint(-x);
    }
    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        return mint(*this) += a;
    }
    mint operator-(const mint a) const {
        return mint(*this) -= a;
    }
    mint operator*(const mint a) const {
        return mint(*this) *= a;
    }
    mint pow(ll t) const {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint &operator/=(const mint a) {
        return *this *= a.inv();
    }
    mint operator/(const mint a) const {
        return mint(*this) /= a;
    }
};
istream &operator>>(istream &is, const mint &a) {
    return is >> a.x;
}
ostream &operator<<(ostream &os, const mint &a) {
    return os << a.x;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<bool> a(N);
    vector<mint> v(N + 10);
    rep(i, M) {
        int x;
        cin >> x;
        a[x] = true;
    }
    v[0] = 1;
    rep(i, N + 1) {
        if (!a[i + 1])
            v[i + 1] += v[i];
        if (!a[i + 2])
            v[i + 2] += v[i];
    }
    cout << v[N] << endl;
}

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

int main(){
	int n;
	cin>>n;
	int a[9];
	int cnt=111;
	rep(i,9){
		a[i]=cnt;
		cnt+=111;
	}
	rep(i,9){
      if(n<=a[i]){
        cout << a[i] << endl;
		return 0; 
      }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  for (auto it = vc.begin(); it != vc.end(); ++it)
  {
    if (std::next(it) == vc.end())
      os << *it;
    else
      os << *it << ' ';
  }
  return os;
}

template<class T1, class T2>
inline
std::ostream & operator<<(std::ostream & os, const std::pair<T1, T2> & p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  using std::cout;
  ll A{}, B{}; std::cin >> A >> B;
  
  auto ans = B % A ? B - A : A + B;
  cout << ans << '\n';
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	rep(i, n){
		cin >> h.at(i);
	}
	sort(h.begin(), h.end());
	int hmx, hmn, ans = 1001001001, temp;
	rep(i, n-k+1){
		hmn = h.at(i);
		hmx = h.at(i+k-1);
		ans = min(ans, hmx - hmn);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <sstream>

using namespace std;

struct Stack {
    vector<int> vc;

    void push(int s) {
        vc.push_back(s);
    }

    int pop() {
        int ss = vc.back();
        vc.pop_back();
        return ss;
    }

    bool isEmpty() {
        return vc.empty();
    }
};

int main() {
    Stack st;

    string s, t;
    getline(cin, t);
    stringstream ss(t);

    while (getline(ss, s, ' ')) {
        if (s == "\n") {
            break;
        }
        if (s == "+") {
            int v1 = st.pop();
            int v2 = st.pop();
            st.push(v2 + v1);
        } else if (s == "-") {
            int v1 = st.pop();
            int v2 = st.pop();
            st.push(v2 - v1);
        } else if (s == "*") {
            int v1 = st.pop();
            int v2 = st.pop();
            st.push(v2 * v1);
        } else {
            st.push(stoi(s));
        }
    }

    cout << st.pop() << endl;

    return 0;
}


Measured memory_bytes: 3216
def solve():
    R,G,B,N = map(int, input().split())
    ans = 0
    for r in range( N // R + 1):
        nokori = N - r*R
        for g in range(  nokori // G + 1):
            nokoko = nokori - g * G
            if (nokoko % B == 0):
                ans += 1
    print(ans)
            

if __name__ == "__main__":
    solve()

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

int main(){
    //FILE *inp = freopen("in.txt", "r", stdin);
    int n;
    cin>>n;
    int arr[n];
    for(int i = 0; i < n; ++i)
        cin>>arr[i];
    int swap_count = 0;
    // algorithm
    for(int i = 0; i < n; ++i){
        int mini = i;
        for(int j = i; j < n; ++j){
            if(arr[j]<arr[mini]){
               mini = j;
            }
        }
        if(mini != i){
            swap(arr[i], arr[mini]);
            swap_count++;
        }
    }

    for(int i = 0; i < n; ++i){
        if(i) cout << " ";
        cout << arr[i];
    }
    cout << endl;
    cout << swap_count << endl;
    //fclose(inp);
    return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        int n; cin >> n;
        int ans = 0;
        for (int i = 1; i <= n; i++) ans += to_string(i).size() % 2 == 1;
        cout << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	string S;
	cin >> S;

	if(S[2]==S[3]&&S[4]==S[5]) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1 LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int N,K;cin >> N >> K;
    vector<int> l(N);rep(i,N)cin >> l[i];
    sort(rall(l));
    LL ans = 0;
    rep(i,K)ans += l[i];
    cout << ans << endl;   
}

Measured memory_bytes: 256
from math import gcd
 
n=int(input())
mod = 10**9+7
 
d = dict()
zeros=0
for _ in range(n):
  a,b=map(int,input().split())
  if not any((a,b)):
    zeros+=1
    continue
  if all((a,b)):
    g = gcd(a,b)*(a//abs(a))
  elif a:
    g = a
  else:
    g = b
  
  p = a//g,b//g
  d[p] = d.get(p,0)+1
 
ans = 1
done = set()
for (a,b),v in d.items():
  if (-b,a) in done or (b,-a) in done:
    continue
  done.add((a,b))
  w=d.get((-b,a),0)+d.get((b,-a),0)
  ans *= (pow(2,v,mod)+pow(2,w,mod)-1)
  ans %= mod
print((ans+zeros-1+mod)%mod)

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

template < int MOD >
class modint{

public:
  long long val;
  constexpr modint(const long long v = 0) noexcept : val(v % MOD) {
     if (val < 0) val += MOD;
  }
  constexpr modint operator -() const noexcept { return modint(-val); };
  constexpr modint operator +(const modint r) const noexcept { return modint(*this) += r; }
  constexpr modint operator -(const modint r) const noexcept { return modint(*this) -= r; }
  constexpr modint operator *(const modint r) const noexcept { return modint(*this) *= r; }
  constexpr modint operator /(const modint r) const noexcept { return modint(*this) /= r; }

  constexpr modint& operator +=(const modint& r) noexcept {
    val += r.val;
    if (val >= MOD) val -= MOD;
    return *this;
  }
  constexpr modint& operator -=(const modint& r) noexcept {
    val -= r.val;
    if (val < 0) val += MOD;
    return *this;
  }
  constexpr modint& operator *=(const modint& r) noexcept {
    (val *= r.val) %= MOD;
    return *this;
  }

  constexpr modint& operator /= (const modint& r) noexcept {
      return (*this) *= r.inv();
  }

  friend constexpr ostream& operator <<(ostream &os, const modint<MOD>& x) noexcept {
    return os << x.val;
  }
  friend constexpr modint<MOD> modpow(const modint<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        modint<MOD> t = modpow(a, n >> 1);
        t *= t;
        if (n & 1) t *= a;
        return t;
  }

private:
  modint mpow (const long long n) const noexcept {
      if (!n) return 1;
      modint a = mpow(n >> 1);
      a *= a;
      if (n & 1) a *= *this;
      return a;
  }
  // for prime mod
  modint inv() const noexcept {
    return mpow(MOD-2);
  }
};
const int MOD = 1000000007;
using mint = modint<MOD>;
// ------------------------

mint COM(long long n, long long k){
    mint res = 1;
    for (long long i = 0; i < k; ++i){
        res *= (n-i);
        res /= (i+1);
    }
    return res;
}


void solve() {
    long long n, a, b; cin >> n >> a >> b;
    mint res = modpow(mint(2), n);
    res -= COM(n, a) + COM(n, b) + 1;
    cout << res << "\n";
}

signed main() {
    cin.tie(nullptr); 
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  vl h(N);
  rep(i, N) cin >> h[i];

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

  ll C = A - B;
  
  ll left = 0;
  ll right = h[N - 1] / B + (h[N - 1] % B > 0 ? 1 : 0);

  while(true){
    ll mid = (left + right) / 2;
    ll mid_1 = mid - 1;

    ll add = 0;
    ll add_1 = 0;        
    
    rep(i, N){
      if(h[i] > mid * B){
		add += (h[i] - mid * B) / C + ((h[i] - mid * B) % C > 0 ? 1 : 0);
      }
      if(h[i] > mid_1 * B){
		add_1 += (h[i] - mid_1 * B) / C + ((h[i] - mid_1 * B) % C > 0 ? 1 : 0);
      }
    }

    if((add <= mid) && (add_1 > mid_1)){
      cout << mid << endl;
      return 0;
    } else if(mid < add){
      left = mid + 1;
    } else{
      right = mid - 1;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int a,b;

int get_h(int x)
{
	return (1+x)*x/2;
}

int main()
{
	scanf("%d%d",&a,&b);
	printf("%d\n",get_h(b-a)-b);
}


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

typedef struct {
	long center;
	long arm;
  long end;
} S_ROBOT;

int cmpAscVal(const void * n1, const void * n2)
{
	if (((S_ROBOT *)n1)->end > ((S_ROBOT *)n2)->end)
	{
		return 1;
	}
	else if (((S_ROBOT *)n1)->end < ((S_ROBOT *)n2)->end)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void) {

  long n;
  scanf("%ld", &n);
  S_ROBOT robots[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld %ld", &robots[i].center, &robots[i].arm);
    robots[i].end = robots[i].center+robots[i].arm;
  }
  qsort(robots, n, sizeof(S_ROBOT), cmpAscVal);
  long count = 1;
  long current_end = robots[0].end;
  for (long i = 1; i < n; i++) {
    if (robots[i].center-robots[i].arm >= current_end) {
      count++;
      current_end = robots[i].end;
    }
  }
  printf("%ld\n", count);

  return 0;
}

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

using namespace std;

int ans, a, b, c, k;

int main(){
	cin >> a >> b >> c >> k;
	ans += min(k, a);
	k -= min(k, a);
	if(k > 0){
		k -= min(k, b);
	}
	if(k > 0){
		ans -= min(k, c);
		k -= min(k, c);
	}
	cout << ans << endl;
}

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

int main(){
  int D;
  cin>>D;
  int C[26];
  map<int,int>mp;
  for(int i=0;i<26;i++){
    cin>>C[i];
    if(C[i]>10){
      mp[i]++;
    }   
  }
  int S[365][26];
  for(int i=0;i<365;i++){
    for(int j=0;j<26;j++){
      cin>>S[i][j];
    }
  }
  
  int flag=1;
  int temp=0;
  int now=0;
  int maxans=0;
  while(temp<365){
    maxans=0;
    now=0;
    for(int i=0;i<26;i++){
      if(S[temp][i]>maxans){
        now=i;
        maxans=S[temp][i];
      }
    }    
    
    if((temp/26)%3 == 1 && maxans<19000){
      cout<<temp%26+1<<endl;
      temp++;
      continue;
    }

    cout<<now+1<<endl;
    temp++;
  }
  return 0;
}



Measured memory_bytes: 3676
#include <iostream>
using namespace std;
int main(){
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    if(A*B>C*D){
        cout<<A*B<<endl;}
        else if(A*B<C*D){
            cout<<C*D<<endl;
        }
    else{cout<<A*B<<endl;}
    return 0;
    }

Measured memory_bytes: 256
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

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

    LL n, m;
    cin >> n >> m;
    LL res = 0;
    int nn = n, mm = m;
    int flg[SIZE * 2];
    if( n < m ) {
        flg[0] = false;
        res += m;
        --m;

    } else {
        flg[0] = true;
        res += n;
        --n;

    }

    int pos = 1;
    while( n || m ) {
        if( flg[pos - 1] ) {
            if( m == 0 ) {
                cout << 0 << endl;
                return 0;

            }
            res = ( res * m ) % MOD;
            --m;
            flg[pos] = false;

        } else {
            if( n == 0 ) {
                cout << 0 << endl;
                return 0;

            }
            res = ( res * n ) % MOD;
            --n;
            flg[pos] = true;

        }
        ++pos;
    }
    if( nn == mm ) res = ( res * 2 ) % MOD;
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 1024
function Main(input) {
  lines = input.split('\n');
  n = lines[0]
  s = lines[1]
  k = lines[2]
  c = s[k-1]
  re = new RegExp('[^' + c + ']', 'g')
  console.log(s.replace(re,'*'))
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21956
S = input().strip()
T = input().strip()


dp = [[0] * (len(T)+1) for _ in range(len(S)+1)]

for i, s in enumerate(S):
  for j, t in enumerate(T):
    if s == t:
      dp[i][j] = dp[i-1][j-1] + 1
    else:
      dp[i][j] = max(dp[i][j-1], dp[i-1][j])
ans = []
s = (len(S)-1, len(T)-1)
while True:
  x, y = s
  if x < 0 or y < 0:
    break
  if S[x] == T[y]:
    ans.append(S[x])
    s = (x-1, y-1)
  else:
    if dp[x-1][y] > dp[x][y-1]:
      s = (x-1, y)
    else:
      s = (x, y-1)

    
print(''.join(reversed(ans)))

Measured memory_bytes: 113244
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define ll long long
#define M (int)1e9+7
#define I (int)10e5

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

    int n, x, t;
    cin>>n>>x>>t;
    int count = 0;
    if(n%x==0)
    {
        count = ((n/x)*t);
    }
    else
    {
        count = ((n/x)*t)+t;
    }
    cout<<count;
    return 0;
}

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

struct Segment_tree {
	int T[800010], lazy[800010];
	void Build(int now, int l, int r, int n) {
		lazy[now] = 0x3f3f3f3f;
		if (l == r) {
			T[now] = n - 1;
			return ;
		}
		int mid = l + r >> 1;
		Build(now << 1, l, mid, n), Build(now << 1 | 1, mid + 1, r, n);
		T[now] = min(T[now << 1], T[now << 1 | 1]);
	}
	void pushdown(int now) {
		T[now << 1] = min(T[now << 1], lazy[now]), lazy[now << 1] = min(lazy[now << 1], lazy[now]);
		T[now << 1 | 1] = min(T[now << 1 | 1], lazy[now]), lazy[now << 1 | 1] = min(lazy[now << 1 | 1], lazy[now]);
		lazy[now] = 0x3f3f3f3f;
	}
	void Update(int now, int l, int r, int L, int R, int x) {
		if (l == L && r == R) {
			T[now] = min(T[now], x);
			lazy[now] = min(lazy[now], x);
			return ;
		}
		pushdown(now);
		int mid = l + r >> 1;
		if (R <= mid) Update(now << 1, l, mid, L, R, x);
		else if (L > mid) Update(now << 1 | 1, mid + 1, r, L, R, x);
		else Update(now << 1, l, mid, L, mid, x), Update(now << 1 | 1, mid + 1, r, mid + 1, R, x);
		T[now] = min(T[now << 1], T[now << 1 | 1]);
	}
	int Query(int now, int l, int r, int pos) {
		if (l == r) return T[now];
		pushdown(now);
		int mid = l + r >> 1;
		if (pos <= mid) return Query(now << 1, l, mid, pos);
		return Query(now << 1 | 1, mid + 1, r, pos);
	}
};

Segment_tree seg1, seg2;

int main () {
	int n, q; scanf("%d%d", &n, &q);
	long long ans = 1ll * (n - 2) * (n - 2);
	seg1.Build(1, 1, n, n), seg2.Build(1, 1, n, n);
	while (q--) {
		int op, x; scanf("%d%d", &op, &x);
		if (op == 1) {
			int len = seg1.Query(1, 1, n, x);
			ans -= len - 1;
			seg2.Update(1, 1, n, 1, len, x - 1);
		} else {
			int len = seg2.Query(1, 1, n, x);
			ans -= len - 1;
			seg1.Update(1, 1, n, 1, len, x - 1);
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 11996
#include<iostream>
#include <limits.h>

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
			　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
				  　　　　 （ ´_ゝ`）　/　 ⌒i
					   　　　　／　　　＼　 　  |　|
						   　　　 /　　 /￣￣￣￣/　　|
							   　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
								 　 　　　＼/＿＿＿＿/　（u　⊃
									  ---------------------------------------------------------------------------------------------------*/






int N, M; ll X[1010], Y[1010], Z[1010];
ll dp[1010][1010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;
	rep(i, 0, N) cin >> X[i] >> Y[i] >> Z[i];

	ll ans = -infl;
	rep(a, -1, 2) rep(b, -1, 2) rep(c, -1, 2) if (a) if (b) if (c) {
		rep(i, 0, N + 1) rep(j, 0, M + 1) dp[i][j] = -infl;
		dp[0][0] = 0;
		rep(i, 0, N) rep(j, 0, M + 1) {
			ll d = a * X[i] + b * Y[i] + c * Z[i];
			chmax(dp[i + 1][j], dp[i][j]);
			chmax(dp[i + 1][j + 1], dp[i][j] + d);
		}
		chmax(ans, dp[N][M]);
	}
	cout << ans << endl;

	getchar(); getchar();
}

Measured memory_bytes: 8192
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>

using namespace std;

const int MOD = 1000000007;
typedef long long ll;

std::vector<bool> IsPrime;

void sieve(size_t max){
  if(max+1 > IsPrime.size()){
    IsPrime.resize(max+1,true);
  } 
  IsPrime[0] = false;
  IsPrime[1] = false;

  for(size_t i=2; i*i<=max; ++i)
    if(IsPrime[i])
        for(size_t j=2; i*j<=max; ++j)
          IsPrime[i*j] = false;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int Q;
  cin>>Q;
  sieve(100000);
  vector<int> sum(100000,0);
  for(int i=3;i<100000;i+=2){
    if(IsPrime[i] && IsPrime[(i+1)/2]){
      sum[i]=sum[i-2]+1;
    }else{
      sum[i]=sum[i-2];
    }
  }
  for(int i=0;i<Q;i++){
    int r,l;
    cin>>l>>r;
    if(l==1){
      cout<<sum[r]<<endl;
    }else{
      cout<<sum[r]-sum[l-2]<<endl;
    }

  }
}


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

int main() {
    int x, y;
    cin >> x >> y;

    bool can = false;
    for (int i = 0; i <= x; i++) {
        if (2 * i + 4 * (x - i) == y) {
            can = true;
            break;
        }
    }

    if (can) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3628