akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main()
{

    int h,w;
    while (true){
    cin >> h>>w;
    if(h==0&&w==0)break;
    for (int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                if(i==1||i==h){
                    cout<<"#";
                }
                else if(j==1||j==w){
                    cout<<"#";
                }
                else{
                    cout<<".";
                }

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



Measured memory_bytes: 3080
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){
  int a, b, c;

  scanf("%d%d%d", &a, &b, &c);

  if(a == b){
    printf("%d\n", c);
  }else if(a == c){
    printf("%d\n", b);
  }else if(b == c){
    printf("%d\n", a);
  }

  return 0;
}


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


int main()
{
  string S;
  cin >> S;
  vector<int> n(4);
  for (int i = 0; i < 4; i++) {
    n.at(i) = stoi(S.substr(i,1));
  }

  string o = "   ";
  for (int bit = 0; bit < 8; bit++) {
    int answer = n.at(0);
    for (int i = 0; i < 3; i++) {
      if (bit & (1<<i)) {
        answer += n.at(i+1);
        o.at(i) = '+';
      }
      else {
        answer -= n.at(i+1);
        o.at(i) = '-';
      }
    }
    if (answer == 7) {
      break;
    }
  }

  cout << n.at(0);
  for (int i = 0; i < 3; i++) {
    cout << o.at(i) << n.at(i+1);
  }
  cout << "=7" << endl;
}


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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        long k = sc.NextLong();
        long mod = 1000000007;

        long answer = 0;
        for (long i = k; i <= n + 1; i++)
        {
            long min = i * (i - 1) / 2;
            long max = min + i * (n + 1 - i);
            answer += max - min + 1;
            answer = answer % mod;
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 27544
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vl v(n);
	rep(i,n)cin>>v[i];
	ll ans=1,mx=0;
	vl cnt(n,n);
	rep(i,n){
		ll rec=(i*2)+1;
		ll tab=((rec-v[i])+1);
		chmax(tab,0ll);
		tab/=2;
		chmax(mx,tab);
		cnt[mx]=i+1;
	}
	rrep(i,n-1)chmin(cnt[i],cnt[i+1]);
	//puta(cnt);
	rep(i,n)ans*=(min(n,cnt[i]+1)-i),ans%=MOD;
	//rep(i,n)puta(min(n,cnt[i]+1)-i);
	puta(ans);
}


Measured memory_bytes: 1792
#include<stdio.h>



int max(int a[],int N );


int main(){
	
	int i,j,k,l,N,a[110],sort[110],alice=0,bob=0;
	scanf("%d",&N);
	
	for(i=0;i<N;i++){
	scanf("%d",&a[i]);
	}
	
	for(j=0;j<N;j++){
	sort[j]=max(a,N);
	/*printf("%d\n",sort[j]);*/
	
	for(l=0;l<N;l++){
	if(a[l]==sort[j]){
		a[l]=0;
		break;
	}
	}
	}
	
	
	
	if(N%2==0){
	for(k=0;k<N/2;k++){
		alice+=sort[2*k];
		bob+=sort[2*k+1];
	}
	}else {
		for(k=0;k<(N-1)/2;k++){
		alice+=sort[2*k];
		bob+=sort[2*k+1];
	}
	alice+=sort[N-1];	
		
	}
	
	
	
	
	printf("\n%d\n\n",alice-bob);
	
	
	return 0;
}


int max(int a[],int N ){

	int i,max;
		max=a[0];
	for(i=0;i<N;i++){
		if(a[i]>max){
			max=a[i];
		}
	}
	
	return max;
}




Measured memory_bytes: 128
N=int(input())
ABC=[[]]*N
for i in range(N):
  ABC[i] = list(map(int, input().split()))

dp = [[0 for i in range(3)] for j in range(N+1)]
for i in range(1,N+1):
  for j in range(3):
    for k in range(3):
      if j!=k:
        dp[i][j] = max(dp[i][j], dp[i-1][k]+ABC[i-1][k])
print(max(dp[N][0],dp[N][1],dp[N][2]))

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

void solve()
{
	int n, x, t;
	cin >> n >> x >> t;
	
	cout << (n+x-1)/x*t << "\n";
	
}

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


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#define MN 2000
#define mod 1000000007
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int f[MN*2+5][MN*2+5],g[MN*2+5][MN*2+5],n,p[MN*4+5],inv[MN*4+5],ans=0;
inline int C(int n,int m){return 1LL*p[n]*inv[m]%mod*inv[n-m]%mod;}
int main()
{
    n=read();p[0]=p[1]=inv[0]=inv[1]=1;
    for(int i=2;i<=MN<<2;++i) p[i]=1LL*p[i-1]*i%mod,inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod;
    for(int i=2;i<=MN<<2;++i) inv[i]=1LL*inv[i-1]*inv[i]%mod;
    for(int i=1,a,b;i<=n;++i)
        a=read(),b=read(),ans=(ans+mod-C(a+b<<1,b<<1))%mod,
        ++f[MN-a][MN-b],++g[MN+a][MN+b];
    for(int i=0;i<=MN<<1;++i)
        for(int j=0;j<=MN<<1;++j)
        {
            if(i) f[i][j]=(f[i][j]+f[i-1][j])%mod;
            if(j) f[i][j]=(f[i][j]+f[i][j-1])%mod;
            ans=(ans+1LL*g[i][j]*f[i][j])%mod;
        }
    printf("%d\n",1LL*ans*(mod+1)/2%mod);
    return 0;
}


Measured memory_bytes: 94848
#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, t;
	cin >> s >> t;
	cout << t+s << endl;

	return 0;
}


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

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int read(void) {
	int d;
	cin >> d;
	return d;
}

string readString(void) {
	string s;
	cin >> s;
	return s;
}

void Print(const string& str, int a, int b) {
	cout << str.substr(a, b - a + 1) << endl;
	return;
}

string Reverse(string str, int a, int b) {
	string sub = str.substr(a, b - a + 1);
	std::reverse(sub.begin(), sub.end());
	return str.replace(a, b - a + 1, sub);
}

string Replace(string str, int a, int b, const string& p) {
	return str.replace(a, b - a + 1, p);
}

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

	string str = readString();
	int p = read();
	REP(i, p) {
		string op = readString();
		if (op == "print") {
			const int a = read();
			Print(str, a, read());
		}else if (op == "reverse") {
			const int a = read();
			str = Reverse(str, a, read());
		}else if (op == "replace") {
			const int a = read();
			const int b = read();
			str = Replace(str, a, b, readString());
		}
	}

	return 0;
}



Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define vec vector
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << a << endl
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const ll mod = 1e9+7;
struct mint {
  ll x;
  mint(ll x=0) : x((x%mod+mod)%mod) {}
  mint &operator+=(const mint &p) { if((x += p.x) >= mod) x -= mod; return *this; }
  mint &operator-=(const mint &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; }
  mint &operator*=(const mint &p) { x = x * p.x % mod; return *this; }
  mint &operator/=(const mint &p) { *this *= p.inverse(); return *this; }
  mint operator-() const { return mint(-x); }
  mint operator+(const mint &p) const { return mint(*this) += p; }
  friend mint operator+(const int &c,const mint &p) { return mint(c) += p; }
  mint operator-(const mint &p) const { return mint(*this) -= p; }
  friend mint operator-(const int &c,const mint &p) { return mint(c) -= p; }
  mint operator*(const mint &p) const { return mint(*this) *= p; }
  friend mint operator*(const int &c,const mint &p) { return mint(c) *= p; }
  mint operator/(const mint &p) const { return mint(*this) /= p; }
  friend mint operator/(const int &c,const mint &p) { return mint(c) /= p; }
  bool operator==(const mint &p) const { return x == p.x; }
  friend bool operator==(const int &c,const mint &p) { return mint(c) == p; }
  bool operator!=(const mint &p) const { return x != p.x; }
  friend bool operator!=(const int &c, const mint &p) { return mint(c) != p; }
  mint inverse() const {
    ll a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return mint(u);
  }
  mint pow(ll n) const {
    mint ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os,const mint &p) { return os << p.x; }
  friend istream &operator>>(istream &is,mint &a) {
    ll t;
    is >> t;
    a = mint(t);
    return (is);
  }
};


int main() {
  int N;
  cin >> N;
  vec<ll> A(N);
  vec<mint> sum(N+1,0);
  rep(i,N) cin >> A[i];
  repr(i,N,0) {
    sum[i] += sum[i+1] + A[i];
  }
  mint ans = 0;
  rep(i,N-1) {
    ans += sum[i+1]*A[i];
  }
  print(ans);
  return 0;
}

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

using namespace std;
typedef long long ll;

const int maxn = 1e5 + 5;
int d, n;
bool check(ll num){
    int ret = 0;
    while(true){
        if(num % 100 == 0){
            ret ++;
            num /= 100;
        }
        else{
            break;
        }
    }
    return (ret == d);
}
int main(){
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
    cin >> d >> n;
    ll tmp = 1;
    while(n){
        if(check(tmp)){
            n --;
        }

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


Measured memory_bytes: 256
#include<stdio.h>
int linearSearch(int );
int main(){
  int x,i,j;
  int cont=0;
  scanf("%d",&x);
  int n;
  n=x+1;
  int a[n];
  for(i=0;i<x;i++)scanf("%d",&a[i]);
  int y,l,r,mid;
  scanf("%d",&y);
  int b[y];
  for(i=0;i<y;i++)scanf("%d",&b[i]);
  for(j=0;j<y;j++){
    l=0;
    r=x;
    while(l<r){
      mid=(l+r)/2;
      if(a[mid]==b[j]){
	cont++;
	break;
      }
      else if(b[j]<a[mid])r=mid;
      else l=mid+1;
    }
  }
  printf("%d\n",cont);
  return 0;
}



Measured memory_bytes: 2324
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int cmp(int a,int b)
{
    return a>b;
}
int main()
{
    ll a,b,c;
    scanf("%lld%lld%lld",&a,&b,&c);
    if(a>b)
        swap(a,b);
    ll num[10010];
    ll flag=0;
    for(int i=1;i<=a;i++)
    {
        if(a%i==0&&b%i==0)
        {
            num[flag++]=i;
        }
    }
    sort(num,num+flag,cmp);
    printf("%lld ",num[c-1]);
    return 0;
}


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

int main() {
  int N,K;
  string S;
  cin >> N >> S >> K;
  char a=S.at(K-1);
  for(int i=0;i<N;i++){
    if(S.at(i)!=a){
    S.at(i)='*';
    }
  }
    cout << S <<endl;
 }

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

int main() {
    int n;

    int i;
    int cnt;
    string current;
    string s;

    cin >> n;
    cin >> s;

    current = s[0];
    cnt = 1;
    for(i = 1; i < n; i++) {
        if(current[0] != s[i]) {
            current[0] = s[i];
            cnt += 1;
        }
    }
    cout << cnt << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;

int n,m;
int dp[100010];
int flag[100010];
vvi to(100010,vi(0));

int ddpp(int x){
    if(flag[x]){
        return dp[x];
    }
    else{
        flag[x]=1;
        auto xto=to[x];
        int ans1=0;
        if (xto.size()==0){
            dp[x]=ans1;
            return ans1;
        }
        else{
            for (int y:xto){
                ans1=max(ans1,ddpp(y)+1);
            }
            dp[x]=ans1;
            return dp[x];
        }
        
    }
}

int main() {
    cin>>n>>m;
    rep(i,m){
        int x,y;
        cin>>x>>y;
        to[x].push_back(y);
    }
    int ans=0;
    for (int i=1;i<n+1;i++){
        ans=max(ddpp(i),ans);
        //cout<<dp[i]<<endl;
    }
    cout<<ans<<endl;
    

    return 0;
}

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

#define rep(i, N) for(int i = 0;i < N;i++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;



int main(void) {
	ll a, b, c; cin >> a >> b >> c;
	bool ans;
	if (c-a-b < 0) {
		ans = false;
	}
	else {
		ans = 4 * a * b < (a + b - c) * (a + b - c);
	}

	cout << (ans ? "Yes" : "No") << endl;

	return 0;
}

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

using namespace std;

#define fi first
#define sc second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define up(x, v) upper_bound(all(x), v)
#define low(x, v) lower_bound(all(x), v)
#define bin(x, v) binary_search(all(x), v)
#define FOR(k, a, b) for(int k = (a); k < (b); ++k)
#define ROF(k, a, b) for(int k = (a); k > (b); --k)
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

int main() {

	string s;

	cin >> s;

	for(char c : s) cout << 'x';

	cout << '\n';

    return 0;
}


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


int main() {
    char a,b;
    cin >> a >> b;
    if(a>=b){
        for(int i=0;i<a-'0';i++) cout << b;
    }
    else {
        for(int i=0;i<b-'0';i++) cout << a;

    }
    cout <<endl;
}

Measured memory_bytes: 256
N = int(input())
TXY = [tuple(map(int, input().split())) for _ in range(N)]

lt, lx, ly = 0, 0, 0
for t, x, y in TXY:
	difft = t - lt
	diffp = abs(x - lx) + abs(y - ly)
	if difft < diffp or (diffp - difft) % 2:
		print("No")
		break
	lt, lx, ly = t, x, y
else:
	print("Yes")


Measured memory_bytes: 17312
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	var line string
	var lines []string
	for sc.Scan() {
		line = sc.Text()
		lines = append(lines, line)
	}
	err := sc.Err()
	if err != nil {
		log.Fatal(err)
	}
	x, err := strconv.Atoi(lines[0])
	if err != nil {
		log.Fatal(err)
	}
	result := math.Pow(float64(x), 3)
	fmt.Println(int(result))
}



Measured memory_bytes: 1148
n = int(input())
a = input()
b = input()
if len(a) + len(b) < n:
  print(n)
else:
  result = len(a) + len(b)
  for i in range(1, min(len(a), len(b)) + 1):
    if len(a) + len(b) - i >= n and a[-i:] == b[:i]:
      result = min(result, len(a) + len(b) - i)
  print(result)


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

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

    ll a,b,c;
    cin >> a >> b >> c;
    if(b>=c)
        cout << b+c<< endl;
    else
        cout << min(a+1, c - b) + 2 * b << endl;

    return 0;
}


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

using namespace std;

typedef long long lin;
typedef long double ld;
typedef pair < int, int > pii;

const int N = int(1e6) + 5;
const int inf = (int)1e9 + 7;


int f[N], rf[N];

int cnk(int n, int m){
  return ((f[n] * 1ll * rf[n - m]) % inf) * 1ll * rf[m] % inf;
}

int binpow(int x, int y){
  if(y == 0){
    return 1;
  }
  if(y & 1){
    return binpow(x, y - 1) * 1ll * x % inf;
  }
  int z = binpow(x, y / 2);
  return z * 1ll * z % inf;
}

int n, m;

int main(){
  scanf("%d %d", &n, &m);
  f[0] = 1;
  for(int i = 1; i <= n + m; ++i){
    f[i] = f[i - 1] * 1ll * i % inf;
  }
  if(abs(n - m) > 1){
    printf("0");
    return 0;
  }
  int ans = f[n] * 1ll * f[m] % inf;
  if(n == m){
    ans = ans * 2ll % inf;
  }
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
const string tr="abcdefghijklmnopqrstuvwxyz";
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}
bool ip/*is_prime*/(long long N) {if (N == 1) return false;for (long long i = 2; i * i <= N; ++i) {if (N % i == 0) return false;}return true;}
int digit(ll N) {int ans = 0;while (N) {++ans;N /= 10;}return ans;}
vector<pair<ll,ll>> pf/*prime_factorize*/(ll n){vector<pair<ll,ll>> res;for(ll a=2;a*a<=n;a++){if(n%a!=0) continue;ll ex=0;while(n%a==0){ex++;n/=a;}res.pb({a,ex});}if(n!=1) res.pb({n,1});return res;}
vector<ll> div/*divisor*/(ll n){  vector<ll> res={1};for(ll a=2;a*a<=n;a++){if(n%a!=0) continue;ll b=n/a;res.pb(b);if(b!=a) res.pb(a);}sort(all(res));return res;}

int main() {
  ll n,m;
  cin>>n>>m;
  v(ll) mdiv=div(m);
  mdiv.pb(m);
  ll ans=1;
  ll cnt;
  for(auto x:mdiv){
    if(x==1) continue;
    if(m/x<n) continue;
    ll ja=m/x;
    if(ja%n==0){
      cnt=(ja/n)*x;
    }else{
      cnt=x;
    }
    maxs(ans,cnt);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3648
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        FastReader scan = new FastReader();
        //PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("marathon.out")));
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        Task solver = new Task();
        //int t = scan.nextInt();
        int t = 1;
        for(int i = 1; i <= t; i++) solver.solve(i, scan, out);
        out.close();
    }
    static class Task {
        public void solve(int testNumber, FastReader sc, PrintWriter pw) {
            long n = sc.nextLong();
            long ct = 1;
            long total = 0;
            while(n>0){
                total+=ct;
                n/=2;
                ct*=2;
            }
            pw.println(total);
        }
    }
    static class tup implements Comparable<tup>{
        int a, b;
        tup(int a, int b){
            this.a=a;
            this.b=b;
        }

        @Override
        public int compareTo(tup o) {
            return a!=o.a?Integer.compare(a,o.a):Integer.compare(b,o.b);
        }
    }
    static void shuffle(long[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            long temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }
    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(new File(s)));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 23508
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include <assert.h>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//cout<<setprecision(20)
//cin.tie(0);
//ios::sync_with_stdio(false);
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int LBI(vector<int>&ar,llint in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
int UBI(vector<int>&ar,llint in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int i,j,h,w;cin>>h>>w;
	vector<string>aa(h+2,string(w+2,'.'));
	for(i=1;i<=h;i++){
		string s;cin>>s;
		aa[i]=s;
		aa[i].insert(aa[i].begin(),'.');
		aa[i].pub('.');
	}
	for(i=1;i<=h;i++){
		for(j=1;j<=w;j++){
			if(aa[i][j]=='.'){continue;}
			if(aa[i+1][j]=='.'&&aa[i-1][j]=='.'&&aa[i][j+1]=='.'&&aa[i][j-1]=='.'){
				cout<<"No"<<endl;return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, sum = 0, ans = 0; cin >> n;
    int a[n]; for(int i = 0; i < n; ++i){
        cin >> a[i];
        sum += a[i];
    }
    int ave = sum / n;
    int ans2 = 0;

    for(int i = 0; i < n; ++i){
        ans += pow(a[i] - ave, 2);
        ans2 += pow(a[i] - ave - 1, 2);
    }cout << min(ans, ans2);
}
    


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

int main(){
  int x,ans=1;
  std::cin >> x;
  for (int i = 1; i <= x; i++) {
    /* code */
    for (int j = 2; j <=x; j++) {
      /* code */
      for (int k = 2; x>=int(pow(j,k)) ; k++) {
        /* code */
        if(ans<int(pow(j,k))&&int(pow(j,k))<=x)ans=int(pow(j,k));
      }
    }
  }
  std::cout << ans << std::endl;
}

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

using int64 = long long;

int main() {
  int64 n;
  cin >> n;
  int64 ret = n - 1;
  for (int64 i = 1; i * i <= n; ++i) {
    if (n % i)
      continue;
    int64 k = i + n / i - 2;
    ret = min(ret, k);
  }
  cout << ret << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int a,b,c,d,e,f;
cin >>a>>b>>c>>d>>e>>f;
cout<<(a+b+c+d+e+f)-min(min(a,b),min(c,d))-min(e,f)<<endl;
}



Measured memory_bytes: 3124
import java.util.*;
class Main{
  	public static void main(String[]args){
      	Scanner sc=new Scanner(System.in);
      int n=sc.nextInt();
      	int a[]=new int[n];
      int k=sc.nextInt();
      for(int i=0;i<n;i++)a[i]=sc.nextInt();
      Arrays.sort(a);
      int ans=0;
      for(int i=0;i<k;i++)ans+=a[i];
      System.out.println(ans);
    }
}

Measured memory_bytes: 38836
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	ll N;
	string S;
	std::cin >> N >> S;

	vector<queue<ll>> q(3);
	rep(i, 0, N) {
		if (S[i] == 'R') {
			q[0].push(i);
		}
		else if (S[i] == 'G') {
			q[1].push(i);
		}
		else {
			q[2].push(i);
		}
	}


	ll ans = q[0].size() * q[1].size() * q[2].size();

	repeq(i, 1, N / 2) {
		rep(j, 0, N - i - i) {
			if (S[j] != S[j + i] && S[j + i] != S[j + i + i] && S[j] != S[j + i + i]) {
				ans--;
			}
		}
	}

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


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;

const ll INF = 5e15;
const ll MOD = 1e9 + 7;

int main(){
    ll N;
    cin >> N;
    ll num[] = {3, 5, 7};
    ll ans = 0;
    for(ll d = 3; d <= 10; d++){
        ll upper = pow(3, d);
        for(ll i = 0; i < upper; i++){
            ll tmp = 0;
            bool f[3] = {};
            ll cpy = i;
            for(ll j = 0; j < d; j++){
                tmp = tmp * 10 + num[cpy % 3];
                f[cpy % 3] = 1;
                cpy /= 3;
            }
            if(tmp <= N && f[0] && f[1] && f[2]) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#define N 8
#define FREE -1//不受攻击
#define NOT_FREE 1//受到攻击

int row[N],col[N],dpos[2*N-1],dneg[2*N-1];//行、列、斜向左下、斜向右下
int X[N][N];

void printBoard()
{
    for(int i=0; i<N; i++)
    {
        for(int j=0; j<N; j++)
        {
            if (X[i][j]==1)
            {
                if(row[i]!=j)
                    return;
            }
        }
    }
    for(int i=0; i<N; i++)
    {
        for(int j=0; j<N; j++)
        {
            if(row[i]==j)
                printf("Q");
            else
                printf(".");
        }
        printf("\n");
    }
}

void recursive(int i)
{
    if(i==N)                   //成功放置皇后
    {
        printBoard();
        return;
    }
    for(int j=0; j<N; j++)               //如果(i,j)受到其他皇后攻击，则忽略该格子
    {
        if(NOT_FREE==col[j]||NOT_FREE==dpos[i+j]||NOT_FREE==dneg[N+i-j-1])  //斜向左下，横纵坐标关系是：横纵坐标和相等；
            continue;                                                       //斜向右下，横纵坐标关系是：横纵坐标N+i-j-1
        //在(i,j)放置后
        row[i]=j;
        col[j]=dpos[i+j]=dneg[N+i-j-1]=NOT_FREE;
        //尝试下一行
        recursive(i+1);
        //(i,j)拿掉摆放在(i,j)的皇后
        row[i]=col[j]=dpos[i+j]=dneg[N+i-j-1]=FREE;
    }
    //皇后放置失败
}

int main()
{
    memset(X,0,sizeof X);
    memset(row,0,sizeof row);
    memset(col,0,sizeof col);
    memset(dpos,0,sizeof dpos);
    memset(dneg,0,sizeof dneg);
    int k,r,c;
    scanf("%d",&k);;
    for(int i=0; i<k; i++)
    {
        scanf("%d%d",&r,&c);
        X[r][c]=1;
    }
    recursive(0);
    return 0;
}



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

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

struct UnionFind
{
	vector<int> par;
	UnionFind(int n) 
	{
		par.resize(n);
		REP(i, n) par[i] = i;
	}
	int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }
	void unite(int x, int y)
	{
		x = find(x); y = find(y);
		if (x == y) return;
		par[y] = x;
		//if (find(x) != find(y)) par[find(y)] = x;
	}
	int count()
	{
		int cnt = 0;
		REP(i, par.size()) if (par[i] < 0) cnt++;
		return cnt;
	}
	bool same(int x, int y)
	{
		return find(x) == find(y);
	}
};


int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	//int n, q;
	//cin >> n >> q;
	//UnionFind even(n);
	//vi odd(n, -1);
	//REP(i, q)
	//{
	//	int w, a, b, c;
	//	cin >> w >> a >> b >> c;
	//	a--; b--; c %= 2;
	//	if (w == 1)
	//	{
	//		if (c == 0)
	//		{
	//			even.unite(a, b);
	//		}
	//		else
	//		{

	//		}
	//	}
	//	else
	//	{
	//		if (even.same(a, b)) cout << "YES" << endl;
	//		else cout << "NO" << endl;
	//	}
	//}
	int n, q;
	cin >> n >> q;
	UnionFind uf(n);
	REP(i, q)
	{
		int a, b, c;
		cin >> a >> b >> c;
		if (a == 0) uf.unite(b, c);
		else
		{
			cout << uf.same(b, c) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3184
//#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
//#include <time.h>
//#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
#define WAIT system ("pause")
#define rt0 return 0
using namespace std;
int main()
{
	int N, A[100002];
	int ans=0;
	A[0]=0;
	A[100001]=0;
	
	cin>>N;
	for(int i=1;i<=N;i++) {
		cin>>A[i];
		ans+=abs(A[i]-A[i-1]);
	}
	ans+=abs(A[N]);
		
	for(int i=1;i<=N;i++)	{
		int temp= ans-abs(A[i]-A[i-1]);
		temp-=abs(A[i+1]-A[i]);
		temp+=abs(A[i+1]-A[i-1]);
		cout<<temp<<endl;

	} 
    rt0;
}


Measured memory_bytes: 1664
n=int(input())
a=[]
for i in range(n):
    ai=int(input())
    a.append(ai)
finish=False
for i in range(n):
    if a[0]==2:
        print(1)
        finish=True
        break
    if i==0:
        next=a[a[0]-1]
    else:
        next=a[next-1]
    if next==2:
        print(i+2)
        finish=True
        break
if not finish:
    print(-1)
    


Measured memory_bytes: 7084
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
    int A, B, C, K;
    A = sc.nextInt();
    B = sc.nextInt();
    C = sc.nextInt();
    K = sc.nextInt();
    //System.out.println(A+B+C+K);
    if (K <= A + B) {
      System.out.println(Math.min(A,K));
    } else {
      System.out.println(A-(K-A-B));
    }
  }
}

Measured memory_bytes: 27084
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(s,x) memset(s,x,sizeof(s))
#define ls rt<<1
#define rs rt<<1|1
#define pb push_back
#define mp make_pair
#define inf 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

const double PI = acos(-1.0);
const double eps = 1e-8;
const int MAXN = 5e5+5;
const ll MOD = 1e9+7;

int main()
{
    long double a, b, c;
    cin >> a >> b >> c;
    long double x = sqrtl(a*b);
    if (a + b + x*2 < c) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cassert>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;

int m,n,k;
vector<string> map;
void init(){
  map.clear();
}
bool input(){
  if(!(cin>>m>>n>>k))return false;
  for(int i=0;i<m;i++){
    string tmp;
    cin>>tmp;
    map.push_back(tmp);
  }
  return true;
}
string c="JOI";
int box[3][1010][1010];
void make_table(){
  for(int i=0;i<3;i++){
    for(int j=0;j<1010;j++){
      for(int k=0;k<1010;k++){
        box[i][j][k]=0;
      }
    }
  }
  for(int i=0;i<3;i++){
    box[i][0][0]=(map[0][0]==c[i]);
    for(int j=1;j<n;j++){
      box[i][0][j]=box[i][0][j-1]+(map[0][j]==c[i]);
    }
    for(int j=1;j<m;j++){
      box[i][j][0]=box[i][j-1][0]+(map[j][0]==c[i]);
    }
    for(int j=1;j<m;j++){
      for(int k=1;k<n;k++){
        box[i][j][k]=box[i][j-1][k]+box[i][j][k-1]-box[i][j-1][k-1]+(map[j][k]==c[i]);
      }
    }
  }
}
vector<int> solve(){
  vector<int> res;
  res.resize(3);
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  a--;b--;c--;d--;
  for(int i=0;i<3;i++){
    res[i]=box[i][c][d];
    if(a>0){
      res[i]-=box[i][a-1][d];
    }
    if(b>0){
      res[i]-=box[i][c][b-1];
    }
    if(a>0&&b>0){
      res[i]+=box[i][a-1][b-1];
    }
  }
  return res;
}


int main(){
  while(input()){
    make_table();
    for(int i=0;i<k;i++){
      vector<int> ans=solve();
      cout<<ans[0]<<" "<<ans[1]<<" "<<ans[2]<<endl;
    }
  }
}

Measured memory_bytes: 14200
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

constexpr int MOD = 1000000007;
struct ModInt {
    ll x;
    ModInt (ll a) : x((a % MOD + MOD) % MOD) {}
    ModInt operator- () const {
        return ModInt(-x);
    }
    ModInt &operator+= (const ModInt &a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    ModInt &operator-= (const ModInt &a) {
        if ((x -= a.x) < 0) x += MOD;
        return *this;
    }
    ModInt &operator*= (const ModInt &a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    ModInt operator+ (const ModInt &a) const {
        ModInt res(*this);
        return res += a;
    }
    ModInt operator- (const ModInt &a) const {
        ModInt res(*this);
        return res -= a;
    }
    ModInt operator* (const ModInt &a) const {
        ModInt res(*this);
        return res *= a;
    }
    ModInt pow(ll t) const {
        if (!t) return 1;
        ModInt a = pow(t / 2);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    ModInt inv() const {
        return pow(MOD - 2);
    }
    ModInt &operator/= (const ModInt &a) {
        return (*this) *= a.inv();
    }
    ModInt operator/ (const ModInt &a) const {
        ModInt res(*this);
        return res /= a;
    }
    friend istream &operator>> (istream &is, ModInt &a) {
        is >> a.x;
        return is;
    }
    friend ostream &operator<< (ostream &os, const ModInt &a){
        os << a.x;
        return os;
    }
};
vector<ModInt> fact, ifact;
void init(int n) {
    fact.resize(n + 1, ModInt{0});
    ifact.resize(n + 1, ModInt{0});
    fact[0] = ModInt{1};
    for (int i = 1; i <= n; ++i) {
        ModInt M(i);
        fact[i] = fact[i - 1] * M;
    }
    ifact[n] = fact[n].inv();
    for (int i = n; i > 0; --i) {
        ModInt M(i);
        ifact[i - 1] = ifact[i] * M;
    }
}
ModInt comb(int x, int y) {
    if (x < y) return ModInt{0};
    else return fact[x] * ifact[y] * ifact[x - y];
}

int main() {
    int N, M;
    cin >> N >> M;
    
    if (max(N, M) - min(N, M) > 1) {
        cout << 0 << "\n";
        return 0;
    }
    init(max(N, M));
    ModInt ans(N == M ? 2 : 1);
    ans *= fact[N];
    ans *= fact[M];
    cout << ans << "\n";
    return 0;
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void solve ( int test_case )
{
    int n , k ;
    cin >> n >> k ;

    vb vis ( n ) ;

    for ( int i=0 ; i < k ; i ++ )
    {
        int d ;
        cin >> d ;

        while ( d -- )
        {
            int a ;
            cin >> a ;

            a -- ;
            vis[a] = 1 ;
        }
    }

    int ans = 0 ;

    for ( int i=0 ; i < n ; i ++ )
    {
        if ( vis[i] == false )
            ans ++ ;
    }

    cout << ans ; line ;
}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i = 1 ; i <= t ; i ++ )
    {
        solve ( i ) ;
    }

    return 0;
}


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

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

int main(){
    int a,b;
    while(scanf("%d%d",&a,&b)!=EOF)
        printf("%d %d\n",gcd(a,b),lcm(a,b));

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<llong> a(n);
  rep(i, n) cin >> a[i];
  const int mod = 1e9 + 7;
  llong ans = 0;
  rep(i, 60) {
    llong tr = 0;
    rep(j, n) if (a[j] >> i & 1) tr++;
    llong now = tr * (n - tr) % mod;
    rep(j, i) now = now * 2 % mod;
    ans += now;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  int n;
  scanf("%d",&n);
  long long a[n];
  int kai[n];
  int ans=0;

  for(int i=0;i<n;i++){
    kai[i]=0;
  }
  
  for(int i=0;i<n;i++){
    scanf("%lld",&a[i]);
    if(a[i]>=n){
      ans++;
    }
    else{
      kai[a[i]]++;
    }
      
  }

  for(int i=0;i<n;i++){
    if(kai[i]>=i){
      ans=ans+kai[i]-i;
    }
    else{
      ans=ans+kai[i];
    }
  }

  for(int i=0;i<n;i++){
    if(a[i]!=n){
      printf("%d\n",ans);
      return 0;
    }
  }
  printf("0\n");
  
  return 0;
}
  
  

Measured memory_bytes: 1280
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
int main() {
  ios::sync_with_stdio(false);
  int x;
  cin>>x;
  if(x>=30)cout<<"Yes\n";
  else cout<<"No\n";
  return 0;
}

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

int main()
{
    int c[3][3];
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> c[i][j];
        }
    }
    string ans = "Yes";
    for (int i = 0; i < 3; i++)
    {
        if (c[i][0] - c[(i + 1) % 3][0] != c[i][1] - c[(i + 1) % 3][1] ||
            c[i][1] - c[(i + 1) % 3][1] != c[i][2] - c[(i + 1) % 3][2])
        {
            ans = "No";
        }
    }

    for (int i = 0; i < 3; i++)
    {
        if (c[0][i] - c[0][(i + 1) % 3] != c[1][i] - c[1][(i + 1) % 3] ||
            c[1][i] - c[1][(i + 1) % 3] != c[2][i] - c[2][(i + 1) % 3])
        {
            ans = "No";
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

#define N_MAX 100000 

using namespace std;

int main(void)
{
  int N;
  cin >> N;
  int A[N_MAX+1];
  A[0] = 0;
  vector<vector<int>> B;
  int n = 1;
  for(int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if(A[n-1] != a) {
      A[n] = a;
      vector<int> bi;
      bi.push_back(A[n]);
      bi.push_back(n);
      B.push_back(bi);
      n++;
    }
  }
  A[n] = 0;
  vector<int> prv = { 0, 0 };
  B.push_back(prv);

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

  int max_island = 0;
  for(int j = 1; j <= n; j++) {
    if(A[j-1] <= 0 && A[j] > 0) max_island++;
  }

  int island = max_island;
  for (int i = 0; i < n; i++) {
	  int idx = B[i][1];
	  if (B[i][0] == 0) continue;
	  else if (B[i][0] > A[idx - 1] && B[i][0] > A[idx + 1]) island--;
	  else if (B[i][0] < A[idx - 1] && B[i][0] < A[idx + 1]) island++;
	  if (island > max_island && B[i+1][0] != B[i][0]) max_island = island;
  }

  cout << max_island << endl;

  return 0;
}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  bool flag = true;
  v[0]--;
  for (int i = 1; i < n; i++) {
    if(v[i] > v[i-1]) {
      v[i]--;
    }
  }

  for (int i = 1; i < n; i++) {
    if(v[i] < v[i-1]) flag = false;
  }
  // print(v);

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


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll x;
    cin>>x;
    ll ans=(x/500)*1000;
    x%=500;
    cout<<ans+(x-x%5)<<"\n";
}


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

ll n,x;
ll sum[55],b[55];

ll dfs(int p){
    ll ret = 0;
    if(x==sum[p]){
        x=0;
        return b[p];
    }
    if(sum[p-1] +1 == x){
        ret += b[p-1];
        x = 0;
        return ret;
    }
    if(sum[p-1] == x){
        ret += b[p-1];
        if(p==1) ret--;
        x=0;
        return ret;
    }
    if(sum[p-1]+2 <= x){
        ret += b[p-1]+1;
        x -= sum[p-1]+2;
    }
    else{
        x--;
    }
    if(x==0)return ret;
    ret += dfs(p-1);
    return ret;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
 
    
    cin>>n>>x;
    sum[0]=1,b[0]=1;
    for(int i=0;i<n;i++){
        sum[i+1] = 2*sum[i] + 3;
        b[i+1] = 2*b[i] + 1;
    }
    cout << dfs(n) << endl;
}

Measured memory_bytes: 256