akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N,M;
vector<int> A,B;

vector<int> g[100010];
vector<int> ans,res;
int used[100010];

void dfs(int now){
    used[now]=1;
    ans.push_back(now);
    for(auto nex:g[now]){
        if(used[nex]==0){
            dfs(nex);
            return;
        }
    }
}

void rfs(int now){
    used[now]=1;
    res.push_back(now);
    for(auto nex:g[now]){
        if(used[nex]==0){
            rfs(nex);
            return;
        }
    }
}

int main(){
  cin>>N>>M;
  A.resize(M);
  B.resize(M);
  rep(i,M){
      cin>>A[i]>>B[i];
      A[i]--;
      B[i]--;
      g[A[i]].push_back(B[i]);
      g[B[i]].push_back(A[i]);
  }

  dfs(0);
  rfs(0);

  reverse(res.begin(),res.end());
  res.pop_back();
  for(int i=0;i<ans.size();i++) res.push_back(ans[i]);

  cout<<res.size()<<endl;
  for(auto n:res) cout<<n+1<<" ";
  cout<<endl;

  return 0;
}


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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}

vector<ll> prime_factor(ll a) {
  vector<ll> ret;
  for (ll i = 2; i*i <= a; i++) {
    if (a % i == 0) ret.push_back(i);
    while (a % i == 0) a /= i;
  }
  if (a != 1) ret.push_back(a);
  return ret;
}

int main() {
  ll A, B;
  cin >> A >> B;
  ll x = gcd(A, B);
  vector<ll> ans = prime_factor(x);
  ans.push_back(1);

  cout << ans.size() << endl;
  return 0;
}


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

using namespace std;

#define int long long

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)

template <typename T> T gcd(T m, T n) { return n == 0 ? m : gcd(n, m % n); }
template <typename T> T lcm(T m, T n) { return n * m / gcd(n, m); }
template <typename T> T fact(T n) { return (n == 0 ? 1 : n * fact(n - 1)); }
template <typename T> T modpow(T a, T e, T m) { return (e == (T)0 ? 1 : ((a % m) * modpow((a % m), e - 1, m)) % m); }

constexpr int MOD = 1e9 + 7;

signed main(void) {
  int num;
  int m, d;
  cin >> m >> d;
  num = 0;
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= d; ++j) {
      int d1 = j % 10;
      int d2 = j / 10;
      if (d1 >= 2 && d2 >= 2 && d1 * d2 == i) ++num;
    }
  }
  cout << num << endl;
}

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

int main(){

    int N;
    cin >> N;

    vector<int> A(N, 0);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }

    double ans = 0;
    for(int i = 0; i < N; i++){
        ans = ans + 1.0/A.at(i); 
    }

    cout << fixed << setprecision(10) << 1.0/ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define INF 10000000000

ll a, b, c, n, m, x, y, z, w, h, ans = 0, cnt = 0, mx = 0, mn = INF;
string s;

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

    cin >> n;
    ll list[n], dp[n + 1];
    rep(i, n){
        cin >> list[i];
        if(list[i] == list[i - 1]){
            list[i] = -1;
            ans++;
        }
    }
    cout << ans << endl;
}



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

int main() {
	int a, b;
	cin >> a >> b;
	
	if (a % 2 == 0 || b % 2 == 0) {
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  string ans = "";
  cin >> s;
  int N = s.size();
  for (int i=0; i < N; i++){
    if (i%2==0) ans = ans +s[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define M_PI 3.1415926535897932384626433832795
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

struct Point {
	int x, y;
};

double distance(Point p1, Point p2) {
	return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}

Point p[8];

int main()
{
	int N;
	double ans = 0;

	cin >> N;
	rep(i, N) cin >> p[i].x >> p[i].y;

	rep(i, N) {
		repc(j, i + 1, N - 1) {
			ans += distance(p[i], p[j]);
		}
	}

	ans = ans * 2 / N;

	printf("%.10lf\n", ans);

	return 0;
}


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

using namespace std;
#define gc getchar()
#define re register
#define int long long
inline int read()
{
	re int x(0);re char c(gc);
	while(c>'9'||c<'0')c=gc;
	while(c<='9'&&c>='0')x=x*10+c-48,c=gc;
	return x;
}

const int N=1e5+10;

namespace maxflow_cost
{
	const int INF=1e15+10;
	int n,h[N],cnt=1,s,t,dis[N],vis[N],pre[N],f[N];
	struct edge{int next,to,f,c;}e[N<<1];
	#define QXX(u) for(int i=h[u],v;v=e[i].to,i;i=e[i].next)
	void add(int u,int v,int f,int c)
	{
		e[++cnt]=(edge){h[u],v,f, c};h[u]=cnt;
		e[++cnt]=(edge){h[v],u,0,-c},h[v]=cnt;
	}
	queue <int> q;
	int SPFA()
	{
		queue<int> q;
		while(!q.empty()) q.pop();
		q.push(s);
		for(int i=1;i<=t;++i)
			dis[i]=INF,vis[i]=0;
		vis[s]=1,dis[s]=0,pre[t]=-1,f[s]=INF;
		while(!q.empty())
		{
			int u=q.front();
			q.pop(); vis[u]=0;
			QXX(u) if(e[i].f) {
				if(dis[v]>dis[u]+e[i].c) {
					dis[v]=dis[u]+e[i].c;
					f[v]=min(f[u],e[i].f);
					pre[v]=i;
					if(!vis[v])
						vis[v]=1,q.push(v);
				}
			}
		}
	    return pre[t]==-1?-1:f[t];
	}
	int dinic()
	{
		int in,maxf=0,maxc=0,x,y;
		while((in=SPFA())!=-1) {
			x=t;
			while(x!=s) {
				y=pre[x];
				e[y].f-=in;
				e[y^1].f+=in;
				x=e[y^1].to;
			}
			maxf+=in;
			maxc+=in*dis[t];
		}
		return -maxc;
	}
}

using namespace maxflow_cost;

signed main()
{
	n=read();
	s=n*2+5,t=s+1;
	for(int i=1;i<=n;++i)
	{
		int x=read(),y=read(),c=read();
		add(s,i,c,0);
		add(i,2*n+1,c,+x+y);
		add(i,2*n+2,c,+x-y);
		add(i,2*n+3,c,-x+y);
		add(i,2*n+4,c,-x-y);
	}
	for(int i=1;i<=n;++i)
	{
		int x=read(),y=read(),c=read(),id=i+n;
		add(id,t,c,0);
		add(2*n+1,id,c,-x-y);
		add(2*n+2,id,c,-x+y);
		add(2*n+3,id,c,+x-y);
		add(2*n+4,id,c,+x+y);
	}
	cout<<dinic()<<'\n';
	return 0;
}

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

#define MAX 100000
#define INF 1 << 31

struct Node 
{
  int parent;
  int cost;
};

int parent[MAX];
int depth[MAX];
int cost[MAX];

Node findParent(int child)
{
  Node tmp;
  if (child != parent[child])
  {
    tmp = findParent(parent[child]);
    parent[child] = tmp.parent;
    cost[child] += tmp.cost;
  }

  tmp.parent = parent[child];
  tmp.cost = cost[child];

  return tmp;
}

void relate(int x, int y, int z)
{
  Node nodeX = findParent(x);
  Node nodeY = findParent(y);

  if (nodeX.parent == nodeY.parent) return;

  if (depth[nodeY.parent] > depth[nodeX.parent])
  {
    parent[nodeX.parent] = nodeY.parent;
    cost[nodeX.parent] = nodeY.cost - nodeX.cost - z;
  }
  else
  {
    parent[nodeY.parent] = nodeX.parent;
    cost[nodeY.parent] = nodeX.cost - nodeY.cost + z;

    if (depth[nodeX.parent] == depth[nodeY.parent])
    {
      depth[nodeX.parent]++;
    }
  }
}

int diff(int x, int y)
{
  Node NodeX = findParent(x);
  Node NodeY = findParent(y);

  if (NodeX.parent != NodeY.parent) return INF;

  return NodeY.cost - NodeX.cost;
}

int main()
{
  int n, q, i, query, x, y, z, ans;

  cin >> n >> q;
  for (i = 0; i < n; i++) 
  {
    parent[i] = i;
    depth[i] = 0;
    cost[i] = 0;
  }

  for (i = 0; i < q; i++)
  {
    cin >> query;
    if (query == 0) 
    {
      cin >> x >> y >> z;
      relate(x, y, z);
    }
    else 
    {
      cin >> x >> y;
      ans = diff(x, y);
      if (ans == INF) cout << "?" << endl;
      else cout << ans << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 4276
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,A[100],ans=0;
  cin>>n;
  for(int i=0;i<n;i++)cin>>A[i];
  for(int i=0;i<n-1;i++){
    for(int j=n-1;j>i;j--){
      if(A[j]<A[j-1]){
    swap(A[j],A[j-1]);
    ans++;
      }
    }
  }
  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    cout<<A[i];
  }
  cout<<endl<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>
#include <iomanip>
using namespace std;

int main(void){
    int a, n;
    cin >> a >> n;
    int check[n];
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> check[i];
        sum += check[i];
    }
    if(a <= sum)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define K 971
using namespace std;
typedef unsigned long long ull;

string s, t;
map<ull,int> cnt;
ull d[300005], H[300005];

signed main(){
  
  cin>>s>>t;

  ull h=0, x=1;
  
  for(int i=0;i<t.size()-1;i++) x=x*K;
  
  for(int i=0;i<s.size();i++){
    h=h*K+s[i];
    if(i>=t.size()-1){
      cnt[h]++;
      h=h-s[i-(t.size()-1)]*x;
    }
  }

  d[0]=1;
  
  for(int i=1;i<=t.size();i++) d[i]=d[i-1]*K;
  
  h=0;
  
  for(int i=0;i<t.size();i++){
    h=h*K+t[i];
    H[i]=h;
  }
  
  int ans=0;

  for(int i=0;i<t.size();i++){
    for(int j='a';j<='z';j++){
      if((char)j==t[i]) continue;
      ull hash=j;
      if(i!=0) hash=H[i-1]*d[1]+hash;
      if(i!=t.size()-1)
	hash=hash*d[t.size()-i-1]+H[t.size()-1]-H[i]*d[t.size()-i-1];

      if(cnt.count(hash)) ans+=cnt[hash];
    }
    for(int j='A';j<='Z';j++){
      if((char)j==t[i]) continue;
      ull hash=j;
      if(i!=0) hash=H[i-1]*d[1]+hash;
      if(i!=t.size()-1)
	hash=hash*d[t.size()-i-1]+H[t.size()-1]-H[i]*d[t.size()-i-1];

      if(cnt.count(hash)) ans+=cnt[hash];
    }
  }
  
  cout<<ans<<endl;
  
  return 0;
}

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

main(){
	string s;
	cin >> s;
	int counter =0;
	if(s[0] == 'o') ++counter;
	if(s[1] == 'o') ++counter;
	if(s[2] == 'o') ++counter;

 	cout << 700 + (100 * counter ) << endl;
	}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Data
{
public:
    int t1, t2, r1, r2;
    bool operator< (const Data& d) const{
        return t1 < d.t1;
    }
};

int n;
vector<Data> d;
vector<int> nextTV;

vector<vector<int> > memo;

int solve(int a, int b)
{
    if(a == n+1 || b == n+1)
        return 0;
    if(a == n && b == n)
        return 0;
    if(memo[a][b] != -1)
        return memo[a][b];

    int ret = 0;
    ret = max(ret, solve(a, b+1));
    ret = max(ret, solve(a+1, b));
    if(a == b){
        ret = max(ret, d[a].r1 + solve(nextTV[a], b+1));
        ret = max(ret, d[b].r2 + solve(a+1, nextTV[b]));
    }else if(a > b){
        ret = max(ret, d[b].r2 + solve(a, nextTV[b]));
    }else{
        ret = max(ret, d[a].r1 + solve(nextTV[a], b));
    }

    return memo[a][b] = ret;
}

int main()
{
    for(;;){
        cin >> n;
        if(n == 0)
            return 0;

        d.resize(n+1);
        for(int i=0; i<n; ++i){
            string s;
            int h1, m1, h2, m2;
            char c;
            cin >> s >> h1 >> c >> m1 >> h2 >> c >> m2 >> d[i].r1 >> d[i].r2;
            d[i].t1 = h1 * 60 + m1;
            d[i].t2 = h2 * 60 + m2;
        }
        d[n].t1 = INT_MAX / 2;
        d[n].t2 = INT_MAX / 2 + 1;
        d[n].r1 = d[n].r2 = 0;
        sort(d.begin(), d.end());

        nextTV.resize(n+1);
        for(int i=0; i<=n; ++i){
            Data tmp;
            tmp.t1 = d[i].t2;
            nextTV[i] = lower_bound(d.begin(), d.end(), tmp) - d.begin();
        }

        memo.assign(n+1, vector<int>(n+1, -1));
        cout << solve(0, 0) << endl;
    }
}

Measured memory_bytes: 4952
let m = 1000000007
let ( +^ ) x y = (x + y) mod m
let ( *^ ) x y = (x * y) mod m

let rec power ( * ) e m n =
  if n <= 0 then e
  else if n mod 2 = 0 then
    power ( * ) e (m * m) (n / 2)
  else
    power ( * ) (e * m) m (n - 1)
let power = power ( *^ ) 1

let () =
  let s = read_line () in
  let count_a = Array.make (String.length s) 0 in
  let count_c = Array.make (String.length s) 0 in
  let count_q_lt = Array.make (String.length s) 0 in
  let count_q_gt = Array.make (String.length s) 0 in
  for i = 0 to String.length s - 2 do
    count_a.(i + 1) <- count_a.(i) + if s.[i] = 'A' then 1 else 0;
    count_q_lt.(i + 1) <- count_q_lt.(i) + if s.[i] = '?' then 1 else 0
  done;
  for i = String.length s - 1 downto 1 do
    count_c.(i - 1) <- count_c.(i) + if s.[i] = 'C' then 1 else 0;
    count_q_gt.(i - 1) <- count_q_gt.(i) + if s.[i] = '?' then 1 else 0
  done;
  Printf.printf "%d\n" @@ Array.fold_left ( +^ ) 0 @@ Array.init (String.length s) @@ fun i ->
    if s.[i] <> 'B' && s.[i] <> '?' then 0
    else
      (power 3 count_q_lt.(i) *^ count_a.(i)
        +^ count_q_lt.(i) *^ power 3 (count_q_lt.(i) - 1)) *^
      (power 3 count_q_gt.(i) *^ count_c.(i)
        +^ count_q_gt.(i) *^ power 3 (count_q_gt.(i) - 1))


Measured memory_bytes: 5120
#include<stdio.h>

int main(){

  int a,b,c,d,total,x,y;

    scanf("%d %d %d %d",&a,&b,&c,&d);
  total=a+b+c+d;
  x=total/60;
  y=total-x*60;

  printf("%d\n",x);
  printf("%d\n",y);
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <queue>
#include <cmath>
#include <iterator>
#include <math.h>

using namespace std;
using lli = long long int;

int main(void){
    string str;
    cin >> str;
    int counter = 0;
    bool flag = false;
    int save = 0;
    for(char a:str){
        if(counter == 0 && a == 'A')flag = true;
        if(flag)counter++;
        if(flag && a == 'Z'){
            save = counter;
        }
    }
    cout << save << endl;
    return 0;
}


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

int main() {
	
	int x, y;
	while(cin >> x >> y) {
		if(x == 0 && y == 0) {
			break;
		}
		
		cout << min(x, y) << " " << max(x, y) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>

using namespace std ; 

typedef long long ll ; 

int main()
{
    char c ; 
    int ans = 0 ; 
    int s = 0, t = 0 ; 
    int tot = 0 ; 
    while(c = getchar()) {
        if(c == 'S') {
            s++ ; 
            tot++ ; 
        }
        else if(c == 'T') {
            t++ ; 
            tot++ ; 
            if(s) {
                s-- ; 
                t-- ; 
                ans++ ; 
            }
        }
        else {
            return printf("%d\n", tot-2*ans)*0 ; 
        }
    }
    return 0 ; 
}



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

int main() {
    int N;
    ll K;
    cin >> N >> K;
    vector<int> A(N+1);
    rep(i, N) cin >> A[i+1];

    // solve
    int now = 1;
    if (K >= 500000) {
        // first
        vector<bool> vis(N+1);
        ll step = 0;
        vis[now] = true;
        while (true) {
            step++;
            now = A[now];
            if (vis[now]) {
                break;
            }
            vis[now] = true;
        }
        K -= step;
        // roop
        vector<bool> vis2(N+1);
        step = 0;
        vis2[now] = true;
        while (true) {
            step++;
            now = A[now];
            if (vis2[now]) {
                break;
            }
            vis2[now] = true;
        }
        // output
        K %= step;
    }
    rep(j, K) {
        now = A[now];
    }
    cout << now << endl;
}

Measured memory_bytes: 4056
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1e9 + 7;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
/*ll fact_[200000];
ll comb(ll x, ll y, ll mod = Mod) {
	if (!fact_[0]) {
		fact_[0] = 1;
		for (int i = 1; i < 200000; i++) {
			fact_[i] = fact_[i - 1] * i % mod;
		}
	}
	if (x < y) return 0;
	return mod_pow(fact_[x], mod, mod) *
		mod_pow(fact_[x - y], mod - 2, mod) % mod *
		mod_pow(fact_[y], mod - 2, mod) % mod;
}//xCy*/
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
H p[200000];
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i].x;;
		p[i].y = i;
	}
	sort(p, p + n);
	reverse(p, p + n);
	multiset<int>s;
	s.insert(-1); s.insert(-1);
	s.insert(n); s.insert(n);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int w, x, y, z;
		auto it = s.lower_bound(p[i].y);
		it++;
		z = (*it);
		y = (*(--it));
		x = (*(--it));
		w = (*(--it));
		ans += p[i].x * ((x - w) * (y - p[i].y) + (z - y) * (p[i].y - x));
		s.insert(p[i].y);
	}
	cout << ans << endl;
}

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

using namespace std;

int main()
{
	int A, B;

	cin >> A >> B;

	if (A <= 8 && B <= 8)
	{
		cout << "Yay!" << endl;
	}
	else
	{
		cout << ":(" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main
{
    private static Scanner scan = new Scanner(System.in);

    public static void out(int i)
    {
        System.out.println(i);

    }

    public static void main(String[] args)
    {
        int tow1 = scan.nextInt();
        int tow2 = scan.nextInt();
        int tou = tow2 - tow1;
        int hight = 0;
        int snow;

        for (int i = 1; i <= tou; i++)
        {
            hight += i;
        }
        snow = hight - tow2;
        out(snow);
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define mp            make_pair
#define PI            3.14159265
#define M             1000000007
#define MM            998244353
#define fr            first
#define sc            second
#define all(v)        (v).begin(),(v).end()
#define rall(v)       (v).rbegin(),v.rend()
#define vc            vector
#define vi            vector<int>
#define pii           pair<int,int>
#define psi           pair<string,int>
#define pis           pair<int,string>
#define mii           map<int,int>
#define msi           map<string,int>

bool compare(const tuple<string,int,int> &a,const tuple<string,int,int> &b){
    if(get<0>(a)==get<0>(b)) return (get<1>(a)>get<1>(b));
    else return (get<0>(a)<get<0>(b));
}
int solve(){
    int a,b; cin>>a>>b;
    if(a>=13) cout<<b;
    else if(a<=5) cout<<0;
    else cout<<b/2;
}

signed main() {
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

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

T = list(map(int,input().split()))

A = T

M = int(input())

PM = [list(map(int,input().split())) for i in range(M)]

for i in range(M):
	
	Ans = 0
	
	a = T[PM[i][0] - 1]
	
	T[PM[i][0] - 1] = PM[i][1]
		
	Ans += sum(T)
	
	print(Ans)
	
	T[PM[i][0] - 1] = a
	

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] height = new int[n];
        for(int i = 0; i < n; i++){
            height[i] = scanner.nextInt();
        }
        System.out.println(new Main().f(n, k, height));
    }

    public int f(int n, int k, int[] height) {
        int[] dp = new int[n];
        if(n <= 1)
            return 0;
        for(int i = 1; i < n; i++){
            dp[i] = Integer.MAX_VALUE;
            for(int j = 1; j <= k && i - j >= 0; j++){
                dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(height[i] - height[i-j]));
            }
        }
        return dp[n-1];
    }
}


Measured memory_bytes: 51108
#include <bits/stdc++.h>
using namespace std;
int main() 
{
  string s; cin >> s;
  int firstTwo = (((int)s[0] -48) * 10) + (int)(s[1] - 48);
  int lastTwo = (((int)s[2] - 48) * 10) + (int)(s[3] - 48);

  if(firstTwo <= 12 && firstTwo)
  {
    if(lastTwo <= 12 && lastTwo)
      cout << "AMBIGUOUS";
    else
      cout << "MMYY";
  }
  else
  {
    if(lastTwo <= 12 && lastTwo)
      cout << "YYMM";
    else
      cout << "NA";
  }
  cout << endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;

  if (a%3==0 || b%3==0 || (a+b)%3==0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
from heapq import heappush, heappop


def dijkstra(Graph, s):
    dis, vis, hq = {}, {}, []
    
    for node in Graph:
        dis[node], vis[node] = sys.maxint, False
        
    dis[s] = 0
    heappush(hq, (0, start))
    
    while hq:
        (d, node) = heappop(hq)
        vis[node] = True
        
        for n, weight in Graph[node].items():
            if d + weight < dis[n]:
                dis[n] = d + weight
                heappush(hq, (dis[n], n))
    return dis
    
    
if __name__ == '__main__':
    line = sys.stdin.readline()
    V, E, start = line.split()
    V, E, start = int(V), int(E), int(start)
    G = {}
    for i in range(V):
        G[i] = {}
    
    for i in range(E):
        line = sys.stdin.readline()
        s, e, w = line.split()
        s, e, w = int(s), int(e), int(w)
        G[s][e] = w
    
    dis = dijkstra(G, start)
    for i in range(V):
        if dis[i] == sys.maxint:
            sys.stdout.write('INF\n')
        else:
            sys.stdout.write(str(dis[i]) + '\n')

Measured memory_bytes: 124684
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(), v.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vll = vector<ll>;
using vvll = vector<vll>;

int main()
{
  ll N,alice=0,bob=0;
  cin >> N;
  vll a(N);
  rep(i,N)
  {
    cin >> a[i];
  }
  sort(all(a));
  reverse(all(a));

  rep(i,N)
  {
    if(i%2)
      bob += a[i];
      else
        alice += a[i];
  }
  cout << alice - bob << endl;
}


Measured memory_bytes: 3632
n=int(input())

a=input().split()

i=0
while i<=(n-1)/2:
    a[i], a[n-i-1]=a[n-1-i], a[i]
    i+=1

i=0
while i<=n-1:
    print(a[i], end="")
    if i<n-1:
        print(" ", end="")
    i+=1 
print()


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

using namespace std;

int main() {
	int r = 0, m = 0;
	for (int i = 0; i < 5; i++) {
		int a;
		cin >> a;
		int b = (a + 9) / 10 * 10;
		r += b;
		m = max(m, b - a);
	}
	cout << r - m << endl;
	return 0;
}


Measured memory_bytes: 256
H, W, K = map(int, input().split())
S = []

for _ in range(H):
    s = list(input())
    S.append(s)

ans = [[0 for wi in range(W)] for hi in range(H)]

from collections import defaultdict
found = defaultdict(list)
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            found[i].append(j)

cur = 1
for i in range(H):
    if i in found.keys():
        for j in range(W):
            ans[i][j] = cur
            if S[i][j] == '#':
                if found[i][-1] != j:
                    cur += 1
        cur += 1

foundp = list(found.keys())
foundp.sort()
kmax = foundp[-1]
kmin = foundp[0]
np = 0
for i in range(H):
    if i not in found.keys():
        if i < kmax:
            while not i < foundp[np]:
                np += 1
            ans[i] = ans[foundp[np]]
        else:
            ans[i] = ans[kmax]

for s in range(H):
    print(*ans[s])

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int W, H, N;
    cin >> W >> H >> N;
    
    vector<vector<bool>> mp(H, vector<bool>(W, true));
    for(int i=0; i<N; i++)
    {
        int x, y, a;
        cin >> x >> y >> a;
        if(a==1)
        {
            for(int j=0; j<x; j++)
            {
                for(int k=0; k<H; k++)
                {
                    mp[k][j] = false;
                }
            }
        }
        if(a==2)
        {
            for(int j=x; j<W; j++)
            {
                for(int k=0; k<H; k++)
                {
                    mp[k][j] = false;
                }
            }
        }
        if(a==3)
        {
            for(int j=0; j<y; j++)
            {
                for(int k=0; k<W; k++)
                {
                    mp[j][k] = false;
                }
            }
        }
        if(a==4)
        {
            for(int j=y; j<H; j++)
            {
                for(int k=0; k<W; k++)
                {
                    mp[j][k] = false;
                }
            }
        }
    }

    int ans = 0;
    for(auto vec : mp)
    {
        for(auto b : vec)
        {
            if(b) ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
//ll MOD = 1000000007;
ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
int N;
string str;
vi hoge;
int main(){
	cin>>str;
	int cnt=0;
	int k=str.size();
	rep(i,k){
		if(str[i]=='o')cnt++;
	}
	if(cnt+(15-k)>=8)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main() {
  string str;

  cin >> str;

  ll ans = 0;
  for (size_t i = 0; i < str.length(); i++) {
    if (str[i] == '1') ans++;
  }

  cout << ans << endl;

  return 0;
}


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

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

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

int main(){
    int N; cin >> N;
    map<string,int> ma;
    for(int i=0;i<N;i++){
        string t; cin >> t;
        ma[t]++;
    }
    cout << "AC x " << ma["AC"] << endl;
    cout << "WA x "  << ma["WA"] << endl;
    cout << "TLE x " << ma["TLE"] << endl;
    cout << "RE x " << ma["RE"] << endl;
}

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

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

    long a, b, c;
    long long k;
    cin >> a >> b >> c >> k;
    int s = pow(-1, (k % 2));


    cout << s * (a -b) << '\n';

    return 0;
}


Measured memory_bytes: 256
import copy

class Cards:
    def __init__(self, letter, value):
        self.letter = letter
        self.value = value

def Partition(NUM_LIST, left, right):
    v = NUM_LIST[right-1].value
    border = left
    for foot in range(left, right-1):
        if NUM_LIST[foot].value <= v:
            NUM_LIST[foot], NUM_LIST[border] = NUM_LIST[border], NUM_LIST[foot]
            border += 1
    NUM_LIST[right-1], NUM_LIST[border] = NUM_LIST[border], NUM_LIST[right-1]
    return border
    
def QuickSort(NUM_LIST, left, right):
    if left+1 < right:
        q = Partition(NUM_LIST, left, right)
        QuickSort(NUM_LIST, left, q)
        QuickSort(NUM_LIST, q+1, right)

def MergeSort(NUM_LIST, left, right):
    if left+1 < right:
        mid = (left+right)//2
        MergeSort(NUM_LIST, left, mid)
        MergeSort(NUM_LIST, mid, right)
        Merge(NUM_LIST, left, mid, right)

def Merge(NUM_LIST, left, mid, right):
    L = NUM_LIST[left:mid]
    inf = Cards("inf", 1000000001)
    L.append(inf)
    R = NUM_LIST[mid:right]
    R.append(inf)
    i=0
    j=0
    for k in range(left, right):
        if L[i].value > R[j].value:
            NUM_LIST[k] = R[j]
            j += 1
        else:
            NUM_LIST[k] = L[i]
            i += 1

n = int(input())
CARD_LIST = []

for i in range(n):
    c, v = input().split()
    v = int(v)
    tmp = Cards(c, v)
    CARD_LIST.append(tmp)

QUICK_LIST = copy.copy(CARD_LIST)
MERGE_LIST = copy.copy(CARD_LIST)

QuickSort(QUICK_LIST, 0, len(QUICK_LIST))
MergeSort(MERGE_LIST, 0, len(MERGE_LIST))


if QUICK_LIST == MERGE_LIST:
    print("Stable")
else:
    print("Not stable")
    
for i in range(len(MERGE_LIST)):
    print("%s %d"%(QUICK_LIST[i].letter, QUICK_LIST[i].value))
    
    


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

using namespace std;

int sx, sy, tx, ty;

int main(){
  cin>>sx>>sy>>tx>>ty;

  string ans="";

  for(int i=0; i<tx-sx; i++) ans+='R';
  for(int i=0; i<ty-sy; i++) ans+='U';
  
  for(int i=0; i<ans.size(); i++){
    if(ans[i]=='R') ans+='L';
    else if(ans[i]=='U') ans+='D';
  }
  
  string ans2="";
  ans2+='D';

  for(int i=0; i<tx+1-sx; i++) ans2+='R';
  for(int i=0; i<ty+1-sy; i++) ans2+='U';

  ans2+='L';
  ans2+='U';

  for(int i=0; i<tx+1-sx; i++) ans2+='L';
  for(int i=0; i<ty+1-sy; i++) ans2+='D';

  ans2+='R';

  cout<<ans+ans2<<endl;
}


Measured memory_bytes: 3628
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S; cin >> S;
    int cnt = 0;
    rep(i,4) {
        if (S[i]=='+') cnt++;
        else cnt--;
    }

    cout << cnt << ln;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <limits>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, a, n) for (int i = a; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eps 1e-15

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef tuple<int, int, int> ti3;

int main()
{
    int a, b, x;
    scanf("%d %d %d", &a, &b, &x);

    if (a <= x && x <= a + b) {
        printf("YES");
    } else {
        printf("NO");
    }
}


Measured memory_bytes: 256
import sys


def _i(): return int(sys.stdin.readline().strip())


def main():
    n = _i()
    r = ""
    while True:
        n -= 1
        m = n % 26
        r = chr(97 + m) + r
        n -= m
        n //= 26
        if n == 0:
            break

    return r


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 61720
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
const ll MOD = 1000000007;

ll solve(ll N) {
	if (N == 1)return 1;
	return solve(N / 2) * 2 + 1;
}

int main() {
	ll H;
	cin >> H;
	cout << solve(H) << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)

string S;
signed main(){
	cin >> S;
	if(S[2] == S[3] && S[4] == S[5]) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
LL stack[20];
inline void write(LL x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    LL top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
inline void pr1(LL x){write(x);putchar(' ');}
inline void pr2(LL x){write(x);putchar('\n');}
const LL MAXN=55;
struct edge{LL x,y,next;}a[2*MAXN];LL len,last[MAXN];
void ins(LL x,LL y){len++;a[len].x=x;a[len].y=y;a[len].next=last[x];last[x]=len;}

LL siz[MAXN],val[MAXN];
void dfs(LL x,LL fa)
{
	siz[x]=1;
	for(LL k=last[x];k;k=a[k].next)
	{
		LL y=a[k].y;
		if(y!=fa)dfs(y,x),siz[x]+=siz[y],val[x]+=val[y];
	}
}
LL f[MAXN*MAXN*MAXN];
LL n,X,D;
struct node{LL v,c,sz;}w[MAXN*MAXN],A[MAXN];LL ln;
bool cmp(node n1,node n2){return 1LL*n1.v*n2.c>1LL*n2.v*n1.c;}
int main()
{
	n=read();X=read();D=read();
	val[1]=read();
	for(LL i=2;i<=n;i++)
	{
		val[i]=read();
		ins(read(),i);
	}
	dfs(1,0);
	for(LL i=1;i<=n;i++)
	{
		LL lst=min(n,D);
		LL lim=(i==1?X/val[1]:D-min(n,D));
		A[i].c=val[i];A[i].v=siz[i];A[i].sz=lim;
		for(LL p=1;p<=lst;p<<=1)
		{
			ln++;
			w[ln].c=1LL*val[i]*p;w[ln].v=1LL*p*siz[i];
			lst-=p;
		}
		if(lst)w[++ln].c=1LL*val[i]*lst,w[ln].v=1LL*siz[i]*lst;
	}
	memset(f,63,sizeof(f));LL inf=f[0];
	f[0]=0;
	for(LL i=1;i<=ln;i++)
		for(LL j=MAXN*MAXN*MAXN-1;j>=w[i].v;j--)if(f[j-w[i].v]!=inf)
			f[j]=min(f[j],f[j-w[i].v]+w[i].c);
	LL ans=0;
	sort(A+1,A+1+n,cmp);
	for(LL i=0;i<MAXN*MAXN*MAXN;i++)if(f[i]!=inf)
	{
		if(f[i]>X)continue;
		LL ok=X-f[i];
		LL num=i;
		for(LL j=1;j<=n;j++)
		{
			num+=1LL*A[j].v*min(A[j].sz,ok/A[j].c);
			ok-=A[j].c*min(A[j].sz,ok/A[j].c);
			if(!ok)break;
		}
		ans=max(ans,num);
	}
	pr2(ans);
	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define mod 1000000007

int main (){
	int n, k ;
	string s ;
	cin >> n >> k ;
	cin >> s ;
	int sc = 0 ;
	rep(i, n - 1) {
		if(s[i] == s[i + 1]){
			sc++ ;
		}
	}
	int ans = min(sc + 2*k, n - 1) ;
	cout << ans << endl ;
}

Measured memory_bytes: 3736
#include<bits/stdc++.h>
#define D 1000000007
using namespace std;
using ull = long long;
ull func(ull x){
    if(x==1 || x==0) return 1;
    else{
        return x * func(x-1);
    }
}

int main(){
    ull n, m; cin >> n >> m;
    ull ans =0;
    ull n_func=1, m_func=1;
    if(n-m > 1 || m-n > 1){
        cout << 0 << endl;
        return 0;
    }
    for(int i=n; i>=1; i--){
        n_func = n_func*i;
        n_func = n_func%D;
    }
    for(int i=m; i>=1; i--){
        m_func = m_func*i;
        m_func = m_func%D;
    }
    ans = n_func * m_func;
    if(n==m) ans = ans*2;
    ans = ans%D;

    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 3608
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    a, b, c, d = map(int, input().split())
    print(max(a * c, a * d, b * c, b * d))
resolve()

Measured memory_bytes: 61832
#include<stdio.h>
#include <stdlib.h>
int main() {
	int N;
	scanf("%d", &N);
	long long *A = (long long *)malloc(sizeof(long long)*N);
	long long cltsum = 0, total = 0;
	long long tmp = 0, min = 100000000000;
	for (int i = 0; i < N; i++)
	{
		scanf("%lld", &A[i]);
		total += A[i];
	}
	for (int i = 0; i < N - 1; i++)
	{
		cltsum += A[i];
		tmp = llabs(cltsum - (total - cltsum));
		if (tmp < min)
		{
			min = tmp;
		}
	}
	printf("%lld\n", min);

	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define int long long
#define rg register
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
const int mod=1e9+7;
const int N=2e5+10;
int read(){
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
	while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
	return f*x;
}
int f[5101][5101];
int inv[N+10],jc[N+10];
int a[N],b[N];
int ksm(int a,int b){
	int ans=1;
	while(b){
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
int C(int n,int m){
	return jc[n]*inv[m]%mod*inv[n-m]%mod;
}
main(){
	int n=read(),ans=0;
	for(int i=1;i<=n;i++) a[i]=read(),b[i]=read(),f[2100-a[i]][2100-b[i]]++;
	jc[0]=1;
	for(int i=1;i<=N;i++) jc[i]=jc[i-1]*i%mod;
	inv[N]=ksm(jc[N],mod-2);
	for(int i=N-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
	for(int i=1;i<=5000;i++)
		for(int j=1;j<=5000;j++)
			f[i][j]=(f[i][j]+f[i-1][j]+f[i][j-1])%mod;
	for(int i=1;i<=n;i++)
		ans=(ans+f[a[i]+2100][b[i]+2100])%mod;
	for(int i=1;i<=n;i++)
		ans=(ans-C(2*(a[i]+b[i]),a[i]*2)+mod)%mod;
	cout<<ans*inv[2]%mod;
	return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

string S[55];
ll x[4] = {1, 0, -1, 0};
ll y[4] = {0, 1, 0, -1};
ll C[55][55];
struct Data {
    pll g;
    ll cost;
};

int main() {
    ll H, W;
    cin >> H >> W;
    REP(i, H) {
        cin >> S[i];
    }

    ll b = 0;
    REP(i, H) {
        REP(j, W) {
            C[i][j] = INF;
            if (S[i][j] == '#')
                b++;
        }
    }

    queue<Data> q;
    q.push(Data{pll(0, 0), 0});
    while (!q.empty()) {
        auto d = q.front();
        q.pop();
        REP(i, 4) {
            ll nx = x[i] + d.g.first;
            ll ny = y[i] + d.g.second;
            if (nx < 0 || ny < 0 || nx >= H || ny >= W)
                continue;
            ll cost = d.cost + 1;
            if (S[nx][ny] == '#')
                continue;
            if (C[nx][ny] <= cost)
                continue;
            C[nx][ny] = cost;
            q.push(Data{pll(nx, ny), cost});
        }
    }

    if (C[H - 1][W - 1] == INF)
        cout << -1 << endl;
    else
        cout << H * W - (C[H - 1][W - 1] + 1) - b << endl;
    return 0;
}

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

int main(){
    int x;
    cin >> x;
    if(x == 0){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
}

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


#define MAX 100002

int n;


vector<int> v;
vector<int> vv;
map<int, int> mp;
int main(){
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		v.push_back(a);
		vv.push_back(a);
		mp[a] = i % 2;
	}
	sort(vv.begin(), vv.end());
	int ar[] = { 0, 0 };
	for (int i = 0; i < vv.size(); i++){
		if (mp[vv[i]] != i % 2){
			ar[i % 2]++;
		}
	}
	int k = max(ar[0], ar[1]);
	cout << k << endl;
	return 0;
}

Measured memory_bytes: 5872
import java.util.*;

public class Main {

	public static int i_max;
	public static int j_max;
	public static int field[][];
	public static boolean nurui[];
	public static boolean nuruj[];

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		i_max = Integer.parseInt(sc.next());
		j_max = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());

		field = new int[i_max][j_max];
		for (int i = 0; i < i_max; i++) {
			String s = sc.next();
			for (int j = 0; j < j_max; j++) {
				field[i][j] = (s.charAt(j) == '.') ? 0 : 1;
			}
		}

		nurui = new boolean[i_max];
		nuruj = new boolean[j_max];
		int answer = 0;

		for (int i = 0; i < (int) Math.pow(2, i_max); i++) {
			for (int j = 0; j < (int) Math.pow(2, j_max); j++) {

				// 塗りパターンを作る
				String bin_i = String.format("%0" + i_max + "d",
						Integer.valueOf(Integer.toBinaryString(i)));
				String bin_j = String.format("%0" + j_max + "d",
						Integer.valueOf(Integer.toBinaryString(j)));
				for (int p = 0; p < i_max; p++) {
					nurui[p] = (bin_i.charAt(p) == '0') ? false : true;
				}
				for (int p = 0; p < j_max; p++) {
					nuruj[p] = (bin_j.charAt(p) == '0') ? false : true;
				}

				// このパターンで塗ったときの黒マス数は、目標 k と一致するか？
				if (countBlack() == k) {
					answer++;
//					System.out.println(Arrays.toString(nurui));
//					System.out.println(Arrays.toString(nuruj));
//					System.out.println("");
				}

			}
		}

		// 出力
		System.out.println(answer);
		
	}

	// 現在のnurui, nurujで塗ったときの黒マス数
	private static int countBlack() {

		int result = 0;

		for (int i = 0; i < i_max; i++) {
			for (int j = 0; j < j_max; j++) {
				if (!nurui[i] && !nuruj[j] && field[i][j] == 1) {
					result++;
				}
			}
		}
		return result;

	}
}

Measured memory_bytes: 55672
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n;
    in>>n;
    vector<int> a(n);
    fr(i,n) in>>a[i];
    int ans=0;
    fr(i,n) if(a[i]==ans+1) ++ans;
    cout<<(ans?n-ans:-1)<<endl;
}

Measured memory_bytes: 1024
local List = {}
function List.new ()
    return {first = 0, last = -1}
end

function List.pushleft (list, value)
    local first = list.first - 1
    list.first = first
    list[first] = value
end

function List.pushright (list, value)
    local last = list.last + 1
    list.last = last
    list[last] = value
end

function List.popleft (list)
    local first = list.first
    local value = list[first]
    list[first] = nil
    list.first = first + 1
    return value
end

function List.popright (list)
    local last = list.last
    local value = list[last]
    list[last] = nil
    list.last = last - 1
    return value
end

function List.empty (list)
    return list.first > list.last
end

----------

local n=io.read("n")

local graph={}
for i=1,n do
    graph[i]={}
end

for i=1,n-1 do
    local a,b,c=io.read("n","n","n")
    graph[a][b]=c
    graph[b][a]=c
end

local q,k=io.read("n","n")

local stack=List.new()
List.pushright(stack,{k,0})
local dist={[k]=0}

while not List.empty(stack) do
    local pop=List.popright(stack)
    local a=pop[1]
    local c=pop[2]
    for b,_ in pairs(graph[a]) do
        local nc=c+graph[a][b]
        if not dist[b] then
            dist[b]=nc
            List.pushright(stack,{b,nc})
        end
    end
end

for i=1,q do
    local x,y=io.read("n","n")
    print(dist[x]+dist[y])
end

Measured memory_bytes: 34140
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String S[] = s.split("");
    System.out.print(S[0]);
    System.out.print(S.length-2);
    System.out.print(S[S.length-1]);
    System.out.println();
  }
}


Measured memory_bytes: 23252