akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(){
    int a,b;
  	int result;
  	int ans[3] = {1,2,3};
  	
  	scanf("%d\n%d",&a,&b);
  	for (int i = 0; i < 3; i++) {
      if (ans[i] != a && ans[i] != b) {
        result = ans[i];
      }
    }
    printf("%d\n",result);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <math.h>
using namespace std;
using s64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{
    int n,m,c;
    cin >> n >> m >> c;
    int b[m];
    rep(i,m) cin >> b[i];
    int a[n][m];
    rep(i,n) rep(j,m) cin >> a[i][j];

    int cnt = 0;
    rep(i,n)
    {
        int sum = c;
        rep(j,m)
            sum += a[i][j] * b[j];
        if(sum > 0) ++cnt;
    }
    
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> p_ii;

struct union_find {
	vector<int> v;
	union_find(int n) : v(n, -1) {}
	int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x;
	}
	bool root(int x) { return v[x] < 0; }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};


int main() {
	int n, m;
	cin >> n >> m;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		--p[i];
	}

	union_find uf(n);

	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		uf.unite(x, y);
	}

	vector<vector<int>> a(n), b(n);

	for (int i = 0; i < n; i++) {
		int k = uf.find(i);
		a[k].push_back(i), b[k].push_back(p[i]);
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (!a[i].empty()) {
			set<int> s(b[i].begin(), b[i].end());
			for (int x : a[i])if (s.count(x))ans++;
		}
	}

	cout << ans << endl;


	return 0;
}

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

int main(){
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<vector<int>> LR;
    LR = vector<vector<int>>(N+1, vector<int>(N+1, 0));
    for(int i=0; i<M; i++){
        int L, R;  cin >> L >> R;
        LR[L][R]++;
    }
    for(int i=1; i<=N; i++){
        for(int j=1; j<=N; j++){
            LR[i][j] += LR[i][j-1];
        }
    }

    for(int i=0; i<Q; i++){
        int p, q;  cin >> p >> q;
        int ret = 0;
        for(int j=p; j<=q; j++){
            ret += LR[j][q] - LR[j][p-1];
        }
        cout << ret << endl;
    }
}


Measured memory_bytes: 1920
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	ll n, m;
	cin >> n >> m;
	Vec h(n);
	rep(i, n) cin >> h[i];
	VecB c(n, true);
	rep(i, m){
		ll a, b;
		cin >> a >> b;
		a--, b--;
		if(h[a] >= h[b]) c[b] = false;
		if(h[a] <= h[b]) c[a] = false;
	}

	ll ans = 0;
	rep(i, n) if(c[i]) ans++;
	co(ans);

	return 0;
}


Measured memory_bytes: 4052
/**
*   @author Mustafa Khaled.
**/
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;

#define REP(i, n) for(int i = 0 ; i < n ; ++i )

string to_string(string s){return '"' + s + '"';}string to_string(const char* s){return to_string((string) s);}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v){bool first = true;string res = "{";for (const auto &x : v){if (!first){res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void debug_out(){cerr << endl;}template <typename Head, typename... Tail>void debug_out(Head H, Tail... T){cerr << " " << to_string(H);debug_out(T...);}/*input*/inline void in(const char *t) {}template <typename Head, typename... Tail>inline void in(const char *t,Head &H, Tail&... T){scanf(t,&H);in(t,T...);}
#define D(...)    in(  "%d",__VA_ARGS__);
#define LLD(...)  in("%lld",__VA_ARGS__);
#define neig(u , v) for(auto v : adj[u])
#ifndef ONLINE_JUDGE
    #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define dbg(...) {}
#endif
/// start driven program
const int OO = 0x3f3f3f3f, N=57  , MOD= 1000000007;

int main(){
    int n , k ;D(n , k);
    int one=0 , x;
    for(int i =0 ; i <n ; ++i){
        D(x);
    }int ans=0;
    while(n>1){
        ans++;
        n-=(k-1);
    }
    cout<<ans;
}


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

int main() {
    long long n;
    scanf("%lld", &n);
    long long s = 0;
    for (int q = 1; 1LL * q * q <= n; ++q) {
        if (n % q == 0) {
            long long lo = n / (q + 1) + 1, hi = n / q;
            long long m = n / q - 1;
            if (lo <= m && m <= hi) {
                assert((n / m) == n % m);
                s += m;
            }
        }
    }
    printf("%lld\n", s);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

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

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

int main()
{
	cin >> n;
	vs v;
	REP(i, n)
	{
		cin >> s;
		if (s[0] == 'A') {
			cnt++;
		} else {
			if (cnt == 0) {
				cout << "NO" << endl;
				return 0;
			} else {
				cnt--;
			}
		}
	}
	if (cnt == 0) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}

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

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var ast = Input();
		var bst = Input();
		var cst = Input();
		var a = new long[n];
		var b = new long[n];
		var c = new long[n];
		for(int i = 0; i < n; i++)
		{
			a[i] = ast[i].ToLong();
			b[i] = bst[i].ToLong();
			c[i] = cst[i].ToLong();
		}
		Array.Sort(a);
		Array.Sort(b);
		Array.Sort(c);
		long wa = 0;
		for(int i = 0; i < n; i++)
		{
			long jv = LowerBound(a, 0, a.Length, b[i], Comparer<long>.Default);
			long kv = UpperBound(c, 0, c.Length, b[i], Comparer<long>.Default);
		
			wa += jv * (n - kv);

		}
		Console.WriteLine(wa);
	}

	public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
	{
	    int low = start;
	    int high = end;
	    int mid;
	    while (low < high)
	    {
	        mid = ((high - low) >> 1) + low;
	        if (comparer.Compare(arr[mid], value) <= 0)
	            low = mid + 1;
	        else
	            high = mid;
	    }
	    return low;
	}

	//引数省略のオーバーロード
	public static int UpperBound<T>(T[] arr, T value)
	{
	    return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default);
	}

	public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
	{
	    int low = start;
	    int high = end;
	    int mid;
	    while (low < high)
	    {
	        mid = ((high - low) >> 1) + low;
	        if (comparer.Compare(arr[mid], value) < 0)
	            low = mid + 1;
	        else
	            high = mid;
	    }
	    return low;
	}

	//引数省略のオーバーロード
	public static int LowerBound<T>(T[] arr, T value) where T : IComparable
	{
	    return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
	}

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 39356
#include<stdio.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
static inline void Radix32(int A[],const int sz)
{
  int temp[200001];const int bit=8,mask=255;
  rep(k,4)
  {
    int u[256]={},v[256]={};
    rep(i,sz)u[A[i]>>bit*k&mask]++;
    rep(i,mask)u[i+1]+=u[i];
    rep(i,sz){temp[--u[A[sz-1-i]>>bit*k&mask]]=A[sz-1-i];}k++;
    rep(i,sz)v[temp[i]>>bit*k&mask]++;
    rep(i,mask)v[i+1]+=v[i];
    rep(i,sz)A[--v[temp[sz-1-i]>>bit*k&mask]]=temp[sz-1-i];
  }
}
int main(void)
{
  int N=IN(),x,p=0,m=0,z=0,A[200000];
  long K,count=0,l=-2e18,r=-l,mid;x=scanf("%ld",&K);
  rep(i,N){x=IN();if(x>0)A[m+p++]=x;else if(x<0)A[p+m++]=x;else z++;}
  Radix32(A,m+p);
  if(K>1l*m*p&&K<1l*m*p+1l*z*(N-1)/2)return puts("0"),0;
  if(K<=1l*m*p)r=1l;else l=-1l;
  while(l<=r)
  {
    mid=(l+r)/2;count=0;
    if(mid>=0)
    {
      int plus=p-1,minus=m-1;count+=1l*z*(p+m)+1l*z*(z-1)/2+1l*p*m;
      rep(i,plus){while(1l*A[i]*A[plus]>mid){plus--;}if(i>=plus){break;}count+=1l*plus-i;}
      rep(i,minus){while(1l*A[m+p-1-i]*A[m+p-1-minus]>mid){minus--;}if(i>=minus){break;}count+=1l*minus-i;}
    }
    else{int low=0;rep(i,m){while(1l*A[low]*A[p+i]>mid&&low<p){low++;}count+=1l*p-low;}}
    if(count>=K)r=mid-1l;else l=mid+1l;
  }
  return OUT(l),0;
}

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

int main(){
    int N;
    cin>>N;
    string mark;
    int suuji;
    map<int,int> spade;
    map<int,int> heart;
    map<int,int> club;
    map<int,int> diamond;
    for(int i=0;i<N;++i){
        cin>>mark>>suuji;
        if(mark=="S")spade[suuji]=1;
        if(mark=="H")heart[suuji]=1;
        if(mark=="C")club[suuji]=1;
        if(mark=="D")diamond[suuji]=1;
    }
    for(int i=1;i<=13;++i){
        if(spade[i]==0)cout<<"S "<<i<<endl;
    }
    for(int i=1;i<=13;++i){
        if(heart[i]==0)cout<<"H "<<i<<endl;
    }
    for(int i=1;i<=13;++i){
        if(club[i]==0)cout<<"C "<<i<<endl;
    }
    for(int i=1;i<=13;++i){
        if(diamond[i]==0)cout<<"D "<<i<<endl;
    }
}


Measured memory_bytes: 3116
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pt;

#define fi first
#define se second
#define dump(x) cout << #x << " = " << x << endl
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

ll dp[100107];
ll n, w, x, y;
pt a[107];

int main () {
    fastIO;
    cin >> n >> w;
    for(li i = 0; i < n; i ++) {
        cin >> x >> y;
        for(li j = w-x; j >= 0; j --) {
            dp[j+x] = max(dp[j+x], dp[j]+y);
        }
    }
    cout << dp[w];
}


Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		for (;;) {
			int N = sc.nextInt();
			int M = sc.nextInt();
			if ((N | M) == 0)
				return;

			long[] p = new long[N + 1];
			long[] t = new long[(N + 2) * (N + 1) / 2];
			int index = 0;
			for (int i = 1; i <= N; i++) p[i] = sc.nextLong();
			for (int i = 0; i <= N; i++) {
				for (int j = i; j <= N; j++) {
					t[index++] = p[i] + p[j];
				}
			}
			Arrays.sort(t);

			long max = 0;
			for (int i = 0; i < t.length; i++) {
				long border = M - t[i];
				if (border < 0) continue;
				int later = binarySearch(t, border);
				max = Math.max(max, t[i] + t[later]);
			}
			System.out.println(max);
		}
	}

	int binarySearch(long[] t, long border) {
		int l = -1;
		int r = t.length;
		while (r - l > 1) {
			int mid = (l + r) / 2;
			if (t[mid] <= border) l = mid;
			else r = mid;
		}
		return l;
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

const int MAX_N = 10000;

class UnionFind {
public:
  int par[MAX_N];                 // 親
  int rank[MAX_N];                // 木の深さ

  // n要素で初期化
  UnionFind(int n){
    for(int i=0;i<n;++i){
      par[i]=i;
      rank[i]=0;
    }
  }

  // 木の根を求める
  int find(int x){
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
  }

  // xとyの属する集合を併合
  void unite(int x, int y){
    x = find(x); y = find(y);
    if(x == y) return;

    if(rank[x]<rank[y])
      par[x]=y;
    else {
      par[y]=x;
      if(rank[x]==rank[y]) rank[x]++;
    }
  }

  // xとyが同じ集合に属するか否か
  bool same(int x, int y){
    return find(x) == find(y);
  }
};

int n,q,com,x,y;


int main() {
  cin>>n>>q;
  UnionFind u(n);
  for(int i=0;i<q;++i){
    cin>>com>>x>>y;
    if(com==0) u.unite(x,y);
    else if(com==1) cout<<u.same(x,y)<<endl;
  }
  return 0;
}



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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  int M = 0;
  int N = 0;
  
  M += A - B;
  
  if (C > M){
    N += C - M;
  }
  
  cout << N << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n,i,c,total=0,cost;
    scanf("%d",&n);
    int a[n+5],a1[n+5],a2[n+5];
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0; i<n; i++)
    {
        if(i==0)
        {
            a1[i] = abs(a[i]);
            a2[i] = abs(a[i]-a[i+1]);
            c = a1[i];
        }

        else if(i==(n-1))
        {
            a1[i] = abs(a[i]-a[i-1]);
            a2[i] = abs(a[i]);
            c = a1[i]+a2[i];
        }

        else
        {
            a1[i] = abs(a[i]-a[i-1]);
            a2[i] = abs(a[i]-a[i+1]);
            c = a1[i];
        }
        total = total+c;
    }

    for(i=0; i<n; i++)
    {

        if(i==0)
        {
            cost = total-a1[i]-a2[i]+abs(a[i+1]);
        }

        else if(i==(n-1))
        {
            cost = total-a1[i]-a2[i]+abs(a[i-1]);
        }

        else
        {

            if((a[i]<a[i+1] && a[i]>a[i-1]) || (a[i]>a[i+1] && a[i]<a[i-1]))
            {
                cost = total;
            }
            else
            {
                cost = total-a1[i]-a2[i]+abs(a[i+1]-a[i-1]);
            }
        }

        printf("%d\n",cost);
    }
}

Measured memory_bytes: 2304
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        Pattern p = Pattern.compile("A[A-Z]*Z");
        Matcher m = p.matcher(s);
        if (m.find()) {
            System.out.println(m.group().length());
        }
    }
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

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

static const ll INF = 1e15;

int main(void)
{
	ll x;
	cin >> x;
	ll m = x / 500;
	x -= m * 500;
	ll a = x / 5;
	cout << m * 1000 + a * 5 << endl;
	return 0;
}


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

int main(void){
    int x,y;
    cin>>x>>y;
    bool ans=false;
    rep(i,x+1){
        int j=x-i;
        if(2*i+4*j==y)
            ans=true;
    }
    if(ans) puts("Yes");
    else puts("No");
    return 0;
}


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

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */
class modint {
    using u64 = std::uint_fast64_t;

public:
    u64 x;

    constexpr modint(const u64 x = 0) noexcept : x(x % mod) {}

    constexpr u64 &value() noexcept { return x; }

    constexpr const u64 &value() const noexcept { return x; }

    constexpr modint operator+(const modint rhs) const noexcept {
        return modint(*this) += rhs;
    }

    constexpr modint operator-(const modint rhs) const noexcept {
        return modint(*this) -= rhs;
    }

    constexpr modint operator*(const modint rhs) const noexcept {
        return modint(*this) *= rhs;
    }

    constexpr modint operator/(const modint rhs) const noexcept {
        return modint(*this) /= rhs;
    }

    constexpr modint &operator+=(const modint rhs) noexcept {
        x += rhs.x;
        if (x >= mod) {
            x -= mod;
        }
        return *this;
    }

    constexpr modint &operator-=(const modint rhs) noexcept {
        if (x < rhs.x) {
            x += mod;
        }
        x -= rhs.x;
        return *this;
    }

    constexpr modint &operator*=(const modint rhs) noexcept {
        x = x * rhs.x % mod;
        return *this;
    }

    constexpr modint &operator/=(modint rhs) noexcept {
        u64 exp = mod - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
};

typedef vector<modint> vmod;
typedef vector<vmod> vvmod;

void solve() {
    ll n, k;
    cin >> n >> k;
    vmod d(n + 2);
    d[0] = 0;
    rep(i, n + 2) d[i + 1] += d[i] + i;
    modint ans;
    for (ll i = k; i <= n + 1; ++i) {
        ans += d[n + 1] - d[n + 1 - i] - d[i] + 1;
    }
    cout << ans.x << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}


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

using namespace std;


int arr[100][100];

int main()
{
   int a,b;
   string s;
   cin>>a>>b;
   for(int i=1;i<=a;++i){
    cin>>s;
    for(int j=1;j<=s.size();++j){
        if(s[j-1]=='#')
            arr[i][j] =-1;
        else
            arr[i][j] =0;
    }
   }

   for(int i=1;i<=a;++i)
   for(int j=1;j<=b;++j){
        if(arr[i][j]!=-1){
            for(int ii = i-1;ii<=i+1;++ii){
                for(int jj = j-1;jj<=j+1;++jj)
                    if(arr[ii][jj]==-1)
                        ++arr[i][j];
            }
        }
   }

    for(int i=1;i<=a;++i){
        for(int j=1;j<=b;++j){
            if(arr[i][j]!=-1)
                cout<<arr[i][j];
            else
                cout<<"#";
        }
        cout<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

struct topological_sort{
    vector<vector<int>> G;
    vector<int> indegree;
    vector<int> par;
    int V;

    topological_sort(int V) : V(V) {G.resize(V); indegree.resize(V); par.assign(V,-1);}
    void add_edge(int a, int b) {
        G[a].push_back(b);
        indegree[b]++;
    }
    void sort() {
        queue<int> q;
        for (int i = 0; i < V; i++) if (indegree[i] == 0) q.push(i);
        while (!q.empty()) {
            int v = q.front(); q.pop();
            for (int i = 0; i < G[v].size(); i++) {
                int u = G[v][i];
                par[u] = v + 1;
                indegree[u]--;
                if (indegree[u] == 0) q.push(u);
            }
        }
    }
};

int main() {
    int n, m; cin >> n >> m;
    topological_sort ts(n);
    vvint dest(n);
    rep(i,n-1+m) {
        int a, b; cin >> a >> b;
        a--; b--;
        ts.add_edge(a,b);
        dest[b].push_back(a);
    }
    ts.sort();
    vint ans = ts.par;
    rep(i,ans.size()) {
        cout << (ans[i] == -1 ? 0 : ans[i]) << endl;
    }
}

Measured memory_bytes: 15320
#include <bits/stdc++.h>
using namespace std;
const int N=55;
int n,a[N],h=0;//head
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(abs(a[i])>abs(a[h]))h=i;
    }
    cout<<2*n-1<<'\n';
    for(int i=0;i<n;i++){
        cout<<h+1<<' '<<i+1<<'\n';
    }
    if(a[h]>0){
        for(int i=0;i<n-1;i++){
            cout<<i+1<<' '<<i+2<<'\n';
        }
    }else{
        for(int i=n;i>1;i--){
            cout<<i<<' '<<i-1<<'\n';
        }
    }
}


Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)

    val n = sc.nextInt()
    val points = Array.fill(n) {
      val x, y, h = sc.nextInt()
      (x, y, h)
    }

    var xx = Array[Int]()
    var yy = Array[Int]()
    var hh = Array[Int]()

    for {
      cx <- 0 to 100
      cy <- 0 to 100
    } {
      val p =
        points
          .map {
            case (x, y, h) =>
              h match {
                case 0 => None
                case _ => Option(h + math.abs(x - cx) + math.abs(y - cy))
              }
          }
          .filter(_.isDefined)
          .map(_.get)
      if (p.foldLeft((true, p.head)) { case ((b, i), n) => (b && i == n, n) }
            ._1) {
        xx = xx :+ cx
        yy = yy :+ cy
        hh = hh :+ p.head
      }

    }

    for (i <- xx.indices) {
      if (points.forall {
            case (x, y, h) =>
              h == math.max(
                0,
                hh(i) - math.abs(x - xx(i)) - math.abs(y - yy(i))
              )
          }) println(s"${xx(i)} ${yy(i)} ${hh(i)}")

    }

  }

  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
  }
}


Measured memory_bytes: 113428
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n=int(input())
k=int(input())
s = list(map(int, input().split()))
r=0
for i in range(0,n):
  if s[i] < k-s[i]:
    r=r+(s[i]*2)
  else:
    r=r+(k-s[i])*2
print(r)


Measured memory_bytes: 3060
res = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

count = int(input())

print(res[count - 1])

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <cmath>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = true;

int main(){

    string s;
    ll K;
    cin >> s;
    cin >> K;

    vector <ll> cont;
    ll tmp = 1;
    for(ll i = 1; i < s.size(); i++){
        if(s[i] == s[i-1]){
            tmp ++;
        }
        else{
            cont.push_back(tmp);
            tmp = 1;
        }
    }
    cont.push_back(tmp);

    if(cont.size() == 1){
        cout << cont[0] * K / 2 << endl;
        return 0;
    }

    if( s[0] == s[s.size() - 1] ){
        ll ans = 0;
        for(int i = 1; i < cont.size() - 1; i++){
            ans += cont[i] / 2;
        }
        ans *= K;

        ans += cont.front() / 2;
        ans += cont.back() / 2;
        ans += (cont.front() + cont.back()) / 2 * (K - 1) ;

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

    ll ans = 0;
    for(int i = 0; i < cont.size(); i++){
        ans += cont[i] / 2;
    }
    ans *= K;
    cout << ans << endl;

}

Measured memory_bytes: 256
from heapq  import heappush, heappop

N,M=map( int, raw_input().split() )
S="z"+raw_input()
num=[ [ 0 for i in range(2) ] for j in range(N+1) ] 

nl= [ [] for j in range(N+1) ] 

deleted=[ 0 for j in range(N+1) ] 

for i in range(M):
	a,b=map( int, raw_input().split() )
	if not b in nl[a]:
		nl[a].append(b)
		nl[b].append(a)
		if S[b]=="A":  num[a][0]+=1
		elif S[b]=="B":  num[a][1]+=1
		if S[a]=="A":  num[b][0]+=1
		elif S[a]=="B":  num[b][1]+=1

hq=[]

for i in range(1,N+1):
	if num[i][0]==0 or num[i][1]==0:
		heappush(hq,i)



while hq:
	x=heappop(hq)
	if deleted[x]==1: continue
	if num[x][0]==0 or num[x][1]==0:

		deleted[x]=1
		for u in nl[x]:
			if deleted[u]==0:
				if S[x]=="A": num[u][0]-=1						
				elif S[x]=="B": num[u][1]-=1
			
		#	print "x,u,num:::",x,u,num
			if ( num[u][0]==0 or num[u][1]==0 ) and deleted[u]==0:
				heappush(hq,u)
			#	print "x,u,hq:::",x,u,hq

				

	

#print "num:::",num
#print "deleted:::",deleted
#print "nl:::",nl

if sum(deleted[1:])==N:
	print "No"
else:
	print "Yes"



Measured memory_bytes: 80156
#include <bits/stdc++.h>
#define ll long long
#define oo 1000000010
using namespace std;

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

	int k;
	cin >> k;
	queue<ll> q;
	for(int i=1; i<=9; i++) q.push(i);
	ll ans;
	for(int i=0; i<k; i++){
		ans = q.front();
		q.pop();
		if (ans % 10 != 0) q.push(ans * 10 + ans % 10 - 1);
		q.push(ans * 10 + ans % 10);
		if (ans % 10 != 9) q.push(ans * 10 + ans % 10 + 1);
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef long long ll;
typedef pair<ll,ll> PP;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false

signed main(void){
    int S,W;
    cin >> S >> W;
    if(S<=W){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3636
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    int N;
    cin >> N;

    int sum = 0;
    FOR(i, 0, N){
        int l, r;
        cin >> l >> r;
        sum += (r-l) + 1;
    }

    p(sum);
    
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8

str = input()
q = int(input())

for _ in range(q):
    line = input().split()
    c = line[0]
    a = int(line[1])
    b = int(line[2]) + 1

    if c == 'replace':
        str = str[:a] + line[3] + str[b:]
    elif c == 'reverse':
        str = str[:a] + str[a:b][::-1] + str[b:]
    else:
        print(str[a:b])


Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]==','){
      cout<<' ';
    }
    else{
      cout<<s[i];
    }
  }
  cout<<endl;
  return(0);
}


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

int main(void){
	int num1;
	int num2;
	int num3;
	scanf("%d %d %d", &num1, &num2, &num3);
	
	if(1<=num1<=9 && 1<=num2<=9 && 1<=num3<=9){
		if((num1*100+num2*10+num3)%4 == 0){
			printf("YES");
		} else {
			printf("NO");
		}
	} else {
		exit(1);
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdint.h>
#include<inttypes.h>
#define PROCESS_MAX 100001
 
typedef struct{
    char          name[11];
    uint_fast32_t time    ;
} s_process;
 
int main(void)
{
    uint_fast32_t n, q, head = 0, tail = 0, process_time = 0;
    s_process process[PROCESS_MAX];
 
    scanf("%"SCNu32" %"SCNu32, &n, &q);
    for(uint_fast32_t i=0; i<n; ++i){
        scanf("%s %"SCNu32, process[i].name, &process[i].time);
    }
    tail = n;
 
    while(head != tail){
        if(process[head].time > q){
            process_time       += q            ;
            process[head].time -= q            ;
            process[tail]       = process[head];
            head = (head+1) % PROCESS_MAX;
            tail = (tail+1) % PROCESS_MAX;
        }else{
            process_time += process[head].time;
            printf("%s %"PRIu32"\n", process[head].name, process_time);
            head = (head+1) % PROCESS_MAX;
        }
    }
 
    return 0;
}

Measured memory_bytes: 4136
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

//#include "All.h"

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

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

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

int N;

int main() {
    cin >> N;
    int i = 1;
    while (true) {
        if ((1000 * i) < N) i++;
        else {
            cout << 1000 * i - N << endl;
            break;
        }
    }
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
#include <array>

using namespace std;
#define C 110

int main(){
  int W, H, N, x[C], y[C], a[C], i;
  cin >> W >> H >> N;
  int xmax=0, xmin=W, ymax=0, ymin=H;
  for (i = 0; i < N; i++){
    cin >> x[i] >> y[i] >> a[i];
    switch (a[i]) {
      case 1:
        if (x[i] > xmax)
          xmax = x[i];
        break;
      case 2:
        if (x[i] < xmin)
          xmin = x[i];
        break;
      case 3:
        if (y[i] > ymax)
          ymax = y[i];
        break;
      case 4:
        if (y[i] < ymin)
          ymin = y[i];
        break;
    }
  }
  if (xmin <= xmax || ymin <= ymax)
    cout << 0 << endl;
  else
    cout << (xmax - xmin) * (ymax - ymin) << endl;
  return 0;
}


Measured memory_bytes: 256
input_mins = []
input_nums = 5
total_mins = []
total_min = 0

for i in range(input_nums):
  input_mins.append(int(input()))


for i in range(input_nums):
  total_min = 0
  for j in range(input_nums-1):
    position = (i+j) % 5
    amari = input_mins[position] % 10
    if amari == 0:
      total_min += input_mins[position]
    else:
      total_min += input_mins[position]+(10-amari)
  total_min += input_mins[(i+4)%5]
  total_mins.append(total_min)

print(min(total_mins))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b+c>=22) cout << "bust" << endl;
    else cout << "win" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<float.h>
#include<math.h>

int height(int N){
  return 5 * N - 5;
}

int main(void){
  double vmin,tmin,ymin;
  while(scanf("%lf",&vmin)!=EOF){
    int k=1;
    tmin = vmin / 9.8;
    ymin = 4.9 * pow(tmin,2);
    while(1){
        if(fabs(height(k)-ymin) < DBL_EPSILON || height(k) > ymin) break;
    k++;
    }
    printf("%d\n",k);
  }
  return 0;
}

Measured memory_bytes: 628
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int n, s = 0;
    scanf("%d", &n);
    vector<int> a(n);
    for (int i = 0; i < n - 1; i++)
    {
        scanf("%d ", &a[i]);
    }
    scanf("%d", &a[n - 1]);
    bool b = true;
    while (b)
    {
        b = false;
        for (int i = n - 1; i > 0; i--)
        {
            if(a[i - 1] > a[i])
            {
                swap(a[i - 1], a[i]);
                b = true;
                s++;
            }
        }
    }
    for (int i = 0; i < n - 1; i++)
    {
        printf("%d ", a[i]);
    }
    printf("%d\n%d\n", a[n - 1], s);
}


Measured memory_bytes: 3204
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int sum = 0;
		for (int i = 0; i < 5; ++i) {
			sum += Math.max(40, sc.nextInt());
		}
		System.out.println(sum / 5);
	}

}

Measured memory_bytes: 17352
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define PI 3.1415926535897932
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
long long LCM(long long A,long long B){
  long long g=GCD(A,B);
  return A/g*B;
}
long long num_order(long long X){
  long long ans=0;
  while(true){
    if(X==0){
      break;
    }
    else{
      X/=10;
      ans++;
    }
  }
  return ans;
}

vector<pair<long long,long long>> prime_factorize(long long N){
  vector<pair<long long,long long>> res;
  
  for(long long i=2;i*i<=N;i++){
    if(N%i!=0){
    continue;
    }
    
    long long ex=0;
    while(N%i==0){
      ex++;
      N/=i;
    }
    
    res.push_back({i,ex});
  }
  
  if(N!=1){
  res.push_back({N,1});
  }
  
  return res;
}


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

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


int main(){
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    vector<ll> A(M,0);
    vector<ll> B(M,0);
    vector<vector<ll>> graph(N, vector<ll>(0));
    for(ll i=0;i<M;i++){cin>>A[i]>>B[i];A[i]--;B[i]--;
    graph[A[i]].emplace_back(B[i]);
    graph[B[i]].emplace_back(A[i]);}
    queue<P> qu;
    vector<ll> d(N,INF);d[0]=0;
    qu.push(P(0,0));
    while(!qu.empty()){
        P x=qu.front();qu.pop();
        ll y=x.first;
        ll z=x.second;
        if(y>d[z])continue;
        for(auto p: graph[z]){
            if(d[p]>d[z]+1){
                d[p]=d[z]+1;
                qu.push(P(d[p],p));
            }
        }
    }
    for(ll i=0;i<N;i++){
        if(d[i]==INF){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    vector<ll> ans(N,0);
    for(ll i=1;i<N;i++){
        for(auto p: graph[i]){
            if(d[p]==d[i]-1){
                ans[i]=p;
            }
        }
    }
    for(ll i=1;i<N;i++){
        cout<<ans[i]+1<<endl;
    }


    return 0;
}

Measured memory_bytes: 16704
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {

    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    long long int N,D,X,Y;
    int count = 0;
    cin >> N >> D;
    D = D*D;
    for(int i = 0; i<N;i++){
        cin >> X >> Y;
        X = X*X;
        Y = Y*Y;
        if(D >= X+Y) count++;
    }
    cout << count++;
    /////////////////////

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int inf = 1001001001;

//DMDMDMDMD; D = 5, M = 4
//5! * 4!
int main(){
  ll n,m;
  cin >> n >> m;
  if(abs(n-m)>1) {
    cout << 0 << endl;
    return 0;
  }

  const int mod = 1000000007;

  ll ans = 1;
  if (n == m) ans *= 2;
  while(n>0){
    n %= mod;
    ans *= n;
    ans %= mod;
    n--;
  }

  while(m>0){
    m %= mod;
    ans *= m;
    ans %= mod;
    m--;
  }

  ans %= mod;
  cout << ans << endl;
  
}


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

int main() {
    int n;
    cin >> n;
    map<string, ll> m;

    rep(i, n) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        m[s]++;
    }

    ll ans = 0;
    for (auto s : m) {
        if (s.second >= 2) ans += s.second * (s.second - 1) / 2;
    }

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


Measured memory_bytes: 11136
#include <iostream>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
int gcd(int a, int b, int c){
    int m = min(a, b);
    int ans;
    m = min(m, c);
    for (int i=m; i>0; i--){
        if (a%i==0 && b%i==0 && c%i==0) {
            ans = i;
            break;
        }
    }
    return ans;
}
int main(){
    int K;
    long long ans=0;
    cin >> K;
    for (int i=1; i<K+1; i++){
        for (int j=1; j<K+1; j++){
            
            for (int k=1; k<K+1; k++){
                ans = ans + gcd(i, j, k);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(void){
  vector<int> f;
  while(1){
    f.clear();
    int n, r, p, c;
    cin >> n >> r;
    if(n == 0 && r == 0) return 0;
    for(int i=n; i > 0; i--){
      f.push_back(i);
    }


    vector<int> t;
    for(int i=0; i < r; i++){
      cin >> p >> c;
      t.clear();
      for(int j=p-1; j < p+c-1; j++){
        t.push_back(f.at(j));
      }
      for(int j=p-1; j > 0; j--){
        f.at(j+c-1) = f.at(j-1);
      }
      for(int j=0; j < c; j++){
        f.at(j) = t.at(j);
      }


    }
    cout << f.front() << endl;
  }
}

Measured memory_bytes: 1220
// AOJ ALDS1_5_C Koch Curve
// 2018.4.30 bal4u

#include <stdio.h>
#include <math.h>

#define PI 3.1415926535897932384626433832795

double d; int a;
double vcos[6], vsin[6];
double x, y;

void koch_curve(int k)
{
	if (k == 0) {
		x += d*vcos[a % 6], y += d*vsin[a%6];
		printf("%.8lf %.8lf\n", x, y);
	} else {
		d /= 3;
		koch_curve(k-1), a++, koch_curve(k-1);
		a += 4;
		koch_curve(k-1), a++, koch_curve(k-1);
		d *= 3;
	}
}

int main()
{
	int n, i;
	
	for (i = 0; i < 6; i++) vcos[i] = cos(i*PI/3), vsin[i] = sin(i*PI/3);

	scanf("%d", &n);

	d = 100;		// (0,0) - (100,0);

	a = 0, x = 0, y = 0; puts("0.00000000 0.00000000");
	koch_curve(n);
	return 0;
}



Measured memory_bytes: 2100
//finding.cpp
#include<iostream>
#include<string>
using namespace std;

int main()
{
    int n,i,j,a,ans[5][14];
    string s;
    for ( i = 1; i <= 4; i++)
    {
        for ( j = 1; j <= 13; j++) ans[i][j]=0;
    }
    cin>>n;
    for ( i = 0; i < n; i++) 
    {
        cin>>s>>a;
        if (s=="S") ans[1][a]=1;
        else if (s=="H") ans[2][a]=1;
        else if (s=="C") ans[3][a]=1;
        else ans[4][a]=1;
    }
    for ( i = 1; i <= 4; i++)
    {
        for ( j = 1; j <= 13; j++)
        {
            if (ans[i][j]==0)
            {
                if (i==1) cout<<"S"<<" "<<j<<endl;
                else if (i==2) cout<<"H"<<" "<<j<<endl;
                else if (i==3) cout<<"C"<<" "<<j<<endl;
                else cout<<"D"<<" "<<j<<endl;
            }
        }
    }
}


Measured memory_bytes: 3168
#include <cstdio>
#include <algorithm>
#include <utility>

using namespace std;

typedef pair<int,int> AB_t;
int N;
char buf[1000007];

AB_t arr[1000007];
int mid=0,endp=0;

int main(){
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        scanf("%s",buf);
        int cur=0;

        int A=0,A_temp=0;
        while(buf[cur]){
            if (buf[cur]=='(') A_temp--;
            else A_temp++;
            A=max(A,A_temp);
            cur++;
        }

        cur--;
        int B=0,B_temp=0;
        while(cur>=0){
            if (buf[cur]==')') B_temp--;
            else B_temp++;
            B=max(B,B_temp);
            cur--;
        }

        if (A<=B){
            swap(arr[mid],arr[endp++]);
            arr[mid++]=AB_t(A,B);
        } 
        else arr[endp++]=AB_t(A,B);
    }

    sort(arr,arr+mid,[](auto const& a,auto const& b){ return a.first<b.first; });
    sort(arr+mid,arr+endp,[](auto const& a,auto const& b){ return a.second>b.second; });

    int diff=0;
    for(int i=0;i<N;i++){
        if (diff+arr[i].first>0){
            puts("No");
            return 0;
        }

        diff+=arr[i].first;
        diff-=arr[i].second;
    }

    if (diff==0) puts("Yes"); else puts("No");
    
    // for(int i=0;i<N;i++){
    //     printf("%d,%d\n",arr[i].first,arr[i].second);
    // }

    return 0;
}

Measured memory_bytes: 9432
#include <stdio.h>

int main(void){
    int N;
    scanf("%d",&N);
    int a[N];
    int b[N];
    for(int i=0;i<N;i++)scanf("%d",&a[i]);
    for(int i=0;i<N;i++){scanf("%d",&b[i]);if(a[i]!=b[i]&&b[i]*2>=a[i]){printf("-1");return 0;}}
    long long int d[51][51];
    for(int i=0;i<51;i++)for(int j=0;j<51;j++)d[i][j]=3223372036854775807;
    for(int i=0;i<51;i++)for(int j=50;j>=1;j--){d[i][i%j]=(long long int)1<<j;}
    for(int i=0;i<51;i++)d[i][i]=0;
    long long int maxcost=1;
    long long int ans=0;
    while(maxcost!=0){
    maxcost=0;
    for(int k=0;k<51;k++)for(int i=0;i<51;i++)for(int j=0;j<51;j++)if(d[i][j]>d[i][k]+d[k][j])d[i][j]=d[i][k]+d[k][j];
    for(int i=0;i<N;i++)if(a[i]!=b[i]&&maxcost<d[a[i]][b[i]])maxcost=d[a[i]][b[i]];
    for(int i=1;;i++){
        if((maxcost>>i)==0)break;
        else{
            int buri=(maxcost>>i)%2;
            if(buri==1)for(int j=0;j<51;j++)d[j][j%i]=0;
        }
    }
    ans|=maxcost;
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a >= 13) {
		cout << b;
	}
	else if (a <= 12 && a >= 6) {
		cout << b / 2;
	}
	else if (a <= 5) {
		cout << 0;
	}
	return 0;
}

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

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    int n;
    cin>>n;
    int a[n];
    REP(i, n){
        cin>>a[i];
    }
    sort(a, a+n);
    int ans = a[n-1]-a[0];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256