akhauriyash/Code-Regression huggingface dataset:
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n: usize = sc.read();

    // https://oeis.org/A024912/list
    let lst = vec![
        1, 3, 4, 6, 7, 10, 13, 15, 18, 19, 21, 24, 25, 27, 28, 31, 33, 40, 42, 43, 46, 49, 52, 54,
        57, 60, 63, 64, 66, 69, 70, 75, 76, 81, 82, 88, 91, 94, 97, 99, 102, 103, 105, 106, 109,
        115, 117, 118, 120, 123, 129, 130, 132, 136, 138,
    ];

    let mut ret = String::new();
    use std::fmt::Write;

    for i in 0..n {
        write!(&mut ret, "{} ", lst[i] * 10 + 1).unwrap();
    }

    ret
}
fn main() {
    let mut buf = String::new();
    use std::io::{Read, Write};
    std::io::stdin().read_to_string(&mut buf).unwrap();
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}


Measured memory_bytes: 4352
N = int(input())
A = list(map(int, input().split()))
B = []
C = []

B_append = B.append
C_append = C.append
#0をひとまとめにする
count = 0
for a in A:
    if a != 0:
        if count != 0:
            B_append(0)
            C_append(count)
        B_append(a)
        C_append(1)
        count = 0
    else:
        count += 1
if count != 0:
    B_append(0)
    C_append(count)

# print (A)
# print (B)
# print (C)
N = len(B)

count = 0
for l in range(N):
    tmp = C[l] #スタート地点の数
    tmp_count = 0
    total = B[l]
    xor = B[l]
    for r in range(l + 1, N): #せいぜい20 * 2 (0と1ビット立つのが繰り返された時)
        total += B[r]
        xor ^= B[r]
        if total == xor:
            tmp_count += C[r]
        else:
            break #条件を満たさなくなった時ループから抜ける
    count += tmp_count * tmp
    count += (tmp * (tmp + 1)) // 2

print (count)

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

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        long X = Long.parseLong(st.nextToken());
        long b=1,a=1,c=-2*X;
        int n = (int) (( -b + Math.sqrt(b^2 - 4*a*c) ) / 2*a);
        int ans=0;
        if(n*(n+1)/2==X){
            ans=n;
        }
        else
            ans=n+1;

        System.out.println(ans);

    }


}


Measured memory_bytes: 21204
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = input()
    L = len(S)
    ans = INF
    for i in range(L-2):
        tmp = int(S[i:i+3])
        ans = min(ans, abs(753-tmp))
    print(ans)




if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.IOException;
import java.util.LinkedList;

public class Main{

    static int n, q;

    static class Process {
        String pid;
        int task;
        int end;

        public Process(String pid, int task) {
            this.pid = pid;
            this.task = task;
        }

        public void setEnd(int end) {
            this.end = end;
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] st = br.readLine().split(" ");
        n = Integer.parseInt(st[0]);
        q = Integer.parseInt(st[1]);
        LinkedList<Process> Queue = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            st = br.readLine().split(" ");
            String pid = st[0];
            int task = Integer.parseInt(st[1]);
            Process p = new Process(pid, task);
            Queue.add(p);
        }

        int ePosition = 0;
        Process[] endProcess = new Process[n];
        int time = 0;
        while (!Queue.isEmpty()) {
            Process p = Queue.pollFirst();
            if (p.task < q) {
                time += p.task;
                p.end = time;
                endProcess[ePosition++] = p;
            } else if (p.task > q) {
                p.task -= q;
                time += q;
                Queue.add(p);
            } else {
                time += q;
                p.end = time;
                endProcess[ePosition++] = p;
            }
        }

        for (Process p : endProcess) {
            bw.append(p.pid + " " + p.end + "\n");
        }
        bw.flush();
    }
}


Measured memory_bytes: 60348
#include<stdio.h>

int main(void){
	
	int n,i,max,min,tmp,j;
	int count=0;
	scanf("%d",&n);
	int a[100];
	
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	
	for(i=0;i<n;i++)
	{
		min=i;
		for(j=i+1;j<n;j++){
			  if(a[j]<a[min]){
				min=j;	
			   }  
		
		}
		if(a[i]>a[min]){
		tmp=a[i];
		a[i]=a[min];
		a[min]=tmp;
			count++;
		}
	}
	
	for(i=0;i<n;i++)
	{
		printf("%d",a[i]);
		if(i!=n-1){printf(" ");}
	}
	printf("\n");
	printf("%d\n",count);
	return 0;
}


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

using namespace std;
using ll = long long;
using vi = vector<int>;

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

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

	int n, m;
	cin >> n >> m;
	vi a(m);
	rep(i, m) cin >> a[i];

	int sum = accumulate(begin(a), end(a), 0);

	n = n - sum;

	if (n >= 0)cout << n << endl;
	else if (n < 0)cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 3664
sx, sy, tx, ty = map(int, input().split(" "))
tx -= sx
ty -= sy
sx = 0
sy = 0
line = []
for i in range(tx):
    line.append("R")
for i in range(ty):
    line.append("U")
for i in range(tx):
    line.append("L")
for i in range(ty):
    line.append("D")
line.append("D")
for i in range(tx+1):
    line.append("R")
for i in range(ty+1):
    line.append("U")
line.append("L")
line.append("U")
for i in range(tx+1):
    line.append("L")
for i in range(ty+1):
    line.append("D")
line.append("R")
for i in range(len(line)):
    if i<len(line):
        print(line[i], end = "")
    else:
        print(line[i])

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	set<int> s = {1, 2, 3};
	for(int i =0; i< 2; i++) {
		int x;
		cin >> x;
		s.erase(x);
	}
	cout << *s.begin() << endl;
}


Measured memory_bytes: 256
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

struct Edge {
    ll a;
    ll b;
    ll opposite(ll x) {
        if (x == a) {
            return b;
        } else if (x == b) {
            return a;
        } else {
            assert(false);
            return 0;
        }
    }
};

void dfs(vector<vector<ll>>& graph, vector<Edge>& edges, vector<bool>& used, vector<ll>& number, vector<ll>& ans, ll now) {
    for (ll edge : graph[now]) {
        if (used[edge]) {
            continue;
        }
        used[edge] = true;
        ll to = edges[edge].opposite(now);
        dfs(graph, edges, used, number, ans, to);
        if (number[to] % 2 == 1) {
            ans[edge] = now;
            number[to]++;
        } else {
            ans[edge] = to;
            number[now]++;
        }
    }
}

int main() {
    ll N, M;
    cin >> N >> M;
    vector<vector<ll>> graph(N);
    vector<Edge> edges(M);
    rep(i,0,M) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        if (a > b) {
            swap(a, b);
        }
        edges[i].a = a;
        edges[i].b = b;
        graph[a].push_back(i);
        graph[b].push_back(i);
    }
    if (M % 2 == 1) {
        cout << -1 << endl;
        return 0;
    }
    vector<ll> number(N);
    vector<bool> used(M);
    vector<ll> ans(M);
    dfs(graph, edges, used, number, ans, 0);
    rep(i,0,M) {
        cout << edges[i].opposite(ans[i]) + 1 << " " << ans[i] + 1 << endl;
    }
}

/*
 
 5 6
 1 2
 1 3
 2 3
 2 4
 2 5
 4 5

 5 4
 1 2
 1 3
 2 4
 2 5
 
 4 4
 1 2
 2 3
 3 4
 4 2

 5 4
 1 2
 2 3
 3 4
 4 5

 
 5 4
 1 2
 2 3
 3 4
 4 5
 
 5 4
 1 2
 2 3
 2 4
 2 5
 
 5 4
 1 2
 2 3
 2 4
 4 5
 
 5 6
 1 2
 2 4
 2 5
 3 4
 4 5
 
 6 6
 1 2
 2 3
 3 4
 4 5
 5 6
 6 1
 
 6 6
 1 2
 2 3
 3 4
 2 4
 4 5
 4 6
 
 6 6
 1 2
 2 3
 3 4
 1 5
 5 6
 6 3

 */


Measured memory_bytes: 20480
#include<bits/stdc++.h>
using namespace std;
int main(){
  map<int,int> a;int b;
  for(int i=0;i<3;i++){
    cin>>b;
    a[b]++;}
  if(a.size()==2)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define int long long int
#define vi vector<int>
#define vvi vector < vi >
#define pii pair<int,int>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define tr(k,st,en) for(int k = st; k <= en ; k++)
#define trb(k,en,st) for(int k = en; k >= st ; k--)
using namespace std;

struct block{
    int str,wt,val;
    bool operator < (const block& b) const {
        return (str + wt < b.str + b.wt);
    }
};

void max_self(int & a,int b){
    a = max(a,b);
}
int32_t main()
{
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<block> in(n);
    tr(i,0,n-1){
        cin>>in[i].wt>>in[i].str>>in[i].val;
    }
    sort(in.begin(),in.end());
    int maxcp = 20005;
    vector<int> dp(maxcp+1);
    tr(i,0,n-1){
        trb(weight,maxcp-in[i].wt,0){
            if(weight > in[i].str){
                continue;
            }
            max_self(dp[weight + in[i].wt], in[i].val + dp[weight]);
        }
    }
    cout<<*max_element(dp.begin(), dp.end())<<endl;
    return 0;
}




Measured memory_bytes: 3680
import sys

file_input = sys.stdin

H, W, N = map(int, file_input.readline().split())

town_map = 'X' * (W + 2)
for line in file_input:
    town_map += 'X' + line.rstrip() + 'X'
town_map += 'X' * (W + 2)

move = (1, -1, W + 2, -W - 2)

from collections import deque

def search(start_pos, goal_lot):
    mouse = [start_pos, 0] # position, elapsed time
    q = deque()
    unvisited = [True] * len(town_map)
    unvisited[start_pos] = False
    goal_lot
    while True:
        cur_pos = mouse[0]
        for d in move:
            next_pos = cur_pos + d
            lot = town_map[next_pos]
            if lot != 'X' and unvisited[next_pos]:
                if lot == goal_lot:
                    return (next_pos, mouse[1] + 1)
                else:
                    m = [next_pos, mouse[1] + 1]
                    unvisited[next_pos] = False
                    q.append(m)
        mouse = q.popleft()

def solve():
    start_pos = town_map.find('S')
    time = 0
    for i in range(1, N + 1):
        start_pos, t = search(start_pos, str(i))
        time += t
    print(time)

solve()


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


class Cards
{
public:
	int num;
	char suit;

	void setValue(char s, int v) {
		suit = s;
		num = v;
	}
};


void printCards(Cards c[], int n) {
	for (int i = 0;i < n;i++) {
		cout << c[i].suit << c[i].num;
		if (i == n - 1) cout << endl;
		else cout << " ";
	}
}


void isstable(Cards c1[], Cards c2[], int n) {
	bool flg = true;
	for (int i = 0;i < n;i++) {
		if (c1[i].suit != c2[i].suit || c1[i].num != c2[i].num) {
			cout << "Not stable" << endl;
			return;
		}
	}

	if (flg) cout << "Stable" << endl;
	return;
}


void bubbleSort(Cards c[], int n) {
	for (int i = 0;i < n;i++) {
		for (int j = n - 1;i < j;j--) {
			if (c[j].num < c[j - 1].num) {
				swap(c[j], c[j - 1]);
			}
		}
	}
}


void selectionSort(Cards c[], int n) {
	for (int i = 0;i < n;i++) {
		int minj = i;
		for (int j = i;j < n;j++) {
			if (c[j].num < c[minj].num) {
				minj = j;
			}
		}

		swap(c[i], c[minj]);
	}
}


int main()
{
	int n;
	Cards c1[36], c2[36], c3[36];
	cin >> n;

	for (int i = 0;i < n;i++) {
		int val;
		char suit;
		cin >> suit >> val;

		c1[i].setValue(suit, val);
		c2[i].setValue(suit, val);
		c3[i].setValue(suit, val);
	}

	bubbleSort(c2, n);
	selectionSort(c3, n);

	printCards(c2, n);
	cout << "Stable" << endl;

	printCards(c3, n);
	isstable(c2, c3, n);
    return 0;
}



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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	map<int,int> M;
	REP(i,N){
		M[in()]++;
	}
	
	bool exist=false;
	for(auto& x:M){
		if(x.second>1){
			exist=true;
			break;
		}
	}
	
	out(exist?"NO":"YES");
	return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint(), C = getint();
	int D[31][31];
	rep1(i, C) rep1(j, C) {
		D[i][j] = getint();
	}

	int T[3][31] = {};
	rep1(i, N) rep1(j, N) {
		T[(i + j) % 3][getint()]++;
	}
	int T2[3][31] = {};
	rep1(i, C) {
		rep1(p, C) T2[0][i] += T[0][p] * D[p][i];
		rep1(p, C) T2[1][i] += T[1][p] * D[p][i];
		rep1(p, C) T2[2][i] += T[2][p] * D[p][i];
	}
	
	int kotae = 1e9;
	rep1(i, C) rep1(j, C) rep1(k, C) {
		if (i != j && j != k && k != i) {
			int kari = T2[0][i] + T2[1][j] + T2[2][k];
			kotae = min(kotae, kari);
		}
	}
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const LL mod = 1e9 + 7;
const LL N = 1e6 + 5;
const LL M = 1e3 + 5;
#define FOR(i, n, m) for (int i = n; i <= m; i++)
#define mid ((l + r) >> 1)
#define lson (l, mid)
#define rson (mid + 1, r)
#define r(a) read(a)
#define rr(a, b) r(a), r(b)
#define rrr(a, b, c) rr(a, b), r(c)
#define rrrr(a, b, c, d) rrr(a, b, c), r(d)
int n, m, k, T;
template <class T>
T read(T &x) {
    T f = 1;
    x = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 1) + (x << 3) + (ch - '0');
        ch = getchar();
    }
    x *= f;
}
LL qpow(LL a, LL b, LL p) {
    LL res = 1;
    while (b) {
        if (b & 1) res = (res * a) % p;
        a = (a * a) % p;
        b >>= 1;
    }
    return res;
}
LL ex_gcd(LL a, LL b, LL &x, LL &y) {
    if (!b) {
        x = 1, y = 0;
        return a;
    }
    LL res = ex_gcd(b, a % b, x, y);
    LL t = x;
    x = y;
    y = t - a / b * y;
    return res;
}
LL prime[N + 10], phi[N + 10], mou[N + 10], cnt_prime;
bool judgeprime[N + 10];
void ouler() {
    phi[1] = mou[1] = 1;
    FOR(i, 2, N) {
        if (!judgeprime[i]) prime[cnt_prime++] = i, phi[i] = i - 1, mou[i] = -1;
        for (int j = 0; j < cnt_prime && i * prime[j] <= N; j++) {
            judgeprime[i * prime[j]] = 1;
            if (i % prime[j] == 0) {
                phi[i * prime[j]] = phi[i] * prime[j];
                mou[i * prime[j]] = 0;
                break;
            } else {
                mou[i * prime[j]] = -mou[i];
                phi[i * prime[j]] = phi[i] * (prime[j] - 1);
            }
        }
    }
}
int main() {
    map<LL, int> mm;
    r(n);
    FOR(i, 1, n)
    r(m), mm[m]++;
    bool flag = 0;
    for(auto x:mm){
        if(x.second>1){
            flag = 1;
            break;
        }
    }
    if (flag) puts("NO");
    else
        puts("YES");
    return 0;
}

Measured memory_bytes: 12800
import math
n = int(input())

A = []
def koch(d, p1, p2):
    rot = math.radians(60)
    if d == 0:
        return 0
    else:
        s = ((2.0 * p1[0] + p2[0]) / 3.0, (2.0 * p1[1] + p2[1]) / 3.0)
        t = ((2.0 * p2[0] + p1[0]) / 3.0, (2.0 * p2[1] + p1[1]) / 3.0)
        ux = (t[0] - s[0]) * math.cos(rot) - (t[1] - s[1]) * math.sin(rot) + s[0]
        uy = (t[0] - s[0]) * math.sin(rot) + (t[1] - s[1]) * math.cos(rot) + s[1]
        u = (ux, uy)
        koch(d-1, p1, s) 
        print(s[0], s[1])
        koch(d-1, s, u)
        print(u[0], u[1])
        koch(d-1, u, t)
        print(t[0], t[1])
        koch(d-1, t, p2)

p1 = (0.0, 0.0)
p2 = (100.0, 0.0)
print(p1[0], p1[1])
koch(n, p1, p2)
print(p2[0], p2[1])


Measured memory_bytes: 5788
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

struct node {
    int cake;
    int count;
};

bool v_cmp(const struct node &p, const struct node &q) {
    return p.count > q.count;
}
// sort(v.begin(), v.end(), v_cmp); //large to samll

int main() {
    int K, T;
    cin >> K >> T;
    vector<node> a(T);
    for (int i = 0; i < T; i++) {
        struct node tmp;
        cin >> tmp.count;
        tmp.cake = i + 1;
        a.push_back(tmp);
    }

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

    cout << max(a[0].count - (K - a[0].count) - 1, 0) << endl;

    return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
int main(void)
{
    int q,i,j,can[4],ans=0;
    scanf("%d",&q);
    for(i=0;i<q;i++){
        ans=0;
        for(j=0;j<3;j++){
            scanf("%d",&can[j]);
        }
        while(1){
            if(can[0]==0||can[1]==0||can[2]==0)break;
            can[0]-=1;
            can[1]-=1;
            can[2]-=1;
            ans++;
        }
        while(1){
            if(can[0]-2<0||can[1]==0)break;
            can[0]-=2;
            can[1]-=1;
            ans++;
        }
        while(1){
            if(can[0]-3<0)break;
            can[0]-=3;
            ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}

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

int n;
int a[200000];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];

	int ans = -1000000000;	
	int buy = a[0];				//min a[0, i)

	for (int i = 1; i < n; i++) {
		ans = max(ans, a[i] - buy);
		buy = min(a[i], buy);
	}

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

Measured memory_bytes: 3860
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

void solve() {
    ll a, b, c, n, k, x;
    string s, t;
    ll ans;
    double dans;
    string sans;


    cin  >> k >> x;

    for(ll i = 1; i < 2*k; i++){
        cout << x-k+i <<" ";
    }

    // std::cout << ans << endl; 
    // std::cout << sans << endl; 
    
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

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

int n;
int id,k,c;

vector<int> L[100001];
int depth[100001] = {0};
int parent[100001];

bool no_root[100001] = {false};

int find_root(){
	for(int i = 0; i < n; i++){
		if(!no_root[i]){
			return i;
		}
	}
	return -1;
}

void update_depth_pa(int pa){
	for(int i = 0; i < L[pa].size(); i++){
		depth[L[pa][i]] = depth[pa] + 1;
		parent[L[pa][i]] = pa;
		update_depth_pa(L[pa][i]);
	}
}

void print_array(int node){
	printf("[");
	if(L[node].size() > 0){
		printf("%d",L[node][0]);
	}
	for(int i = 1; i < L[node].size(); i++){
		printf(", %d",L[node][i]);
	}
	printf("]\n");
}

void print_data(){
	char cond[32];
	for(int i = 0; i < n; i++){
		if(parent[i] == -1){
			strcpy(cond,"root");
		}
		else if(L[i].size() == 0){
			strcpy(cond,"leaf");
		}
		else{
			strcpy(cond,"internal node");
		}
		printf("node %d: parent = %d, depth = %d, %s, ",i,parent[i],depth[i],cond);
		print_array(i);
	}
}

int main(){
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		L[i] = vector<int>();
	}
	for(int i = 0; i < n; i++){
		scanf("%d%d",&id,&k);
		for(int j = 0; j < k; j++){
			scanf("%d",&c);
			no_root[c] = true;
			L[id].push_back(c);
		}
	}
	int root = find_root();
	parent[root] = -1;
	update_depth_pa(root);

	print_data();

	return 0;
}



Measured memory_bytes: 7224
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
	public static void main(String[] args) throws IOException{
		String str[], ans;
        int a, b;
        int d, r;
        String f;

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        str = br.readLine().split(" ");
        a = Integer.parseInt(str[0]);
        b = Integer.parseInt(str[1]);

        d = a / b;
        r = a % b;
        f = String.format("%.5f", ((double)a / (double)b));
        System.out.println(d + " " + r + " " + f);
	}
}

Measured memory_bytes: 24868
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int cntFirstB = 0;
		int cntLastA = 0;
		int cntAB = 0;
		int cntFirstBLastA = 0;
		int answer = 0;

		for (int i = 0; i < N; i++) {
			String s = sc.next();
			if (s.charAt(0) == 'B')
				cntFirstB++;
			if (s.charAt(s.length() - 1) == 'A')
				cntLastA++;
			if (s.charAt(0) == 'B' && s.charAt(s.length() - 1) == 'A')
				cntFirstBLastA++;
			int startId = s.indexOf("AB");
			while (startId != -1) {
				cntAB++;
				startId = s.indexOf("AB", startId + 2);
			}
		}
		if (cntFirstBLastA > 0 && cntFirstBLastA == cntFirstB && cntFirstBLastA == cntLastA)
			answer = cntAB + cntFirstBLastA - 1;
		else
			answer = cntAB + Math.min(cntFirstB, cntLastA);
		sc.close();
		System.out.println(answer);
	}
}


Measured memory_bytes: 31240
#!/usr/bin/env python3
import sys
from pprint import pprint

def solve(H: int, W: int, A: "List[str]"):
    used = [[False] * W for _ in range(H)]
    dx = [1, 0, -1, 0]
    dy = [0, -1, 0, 1]
    s = set()
    for i in range(H):
        for j in range(W):
            if A[i][j] == '#':
                s.add((i, j))
                used[i][j] = True

    ret = 0
    while True:
        nex = set()
        for x, y in s:
            for j in range(4):
                tx = x + dx[j]
                ty = y + dy[j]
                if 0 <= tx < H and 0 <= ty < W and not used[tx][ty]:
                    nex.add((tx, ty))
                    used[tx][ty] = True
        if len(nex) < 1:
            break
        s = nex
        ret += 1

    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    A = [next(tokens) for _ in range(H) ]  # type: "List[str]"
    solve(H, W, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 126944
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int X, Y;
bool ans = false;
void rec(int s, int n, int d) {
  if (n == 1) {
    int a = s - d;
    if (a == 0) {
      ans = true;
    }
    return;
  }
  rec(s - d, n-1, 2);
  rec(s - d, n-1, 4);
}
int main()
{
  cin >> X >> Y;
  if (Y > 4*X || Y % 2 != 0) {
    cout << "No" << endl;
    return 0;
  }
  if (X*2 > Y) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;    
  }
  
  return 0;
}

Measured memory_bytes: 3632
w,h,n = (int(i) for i in input().split())
xya = [[int(i) for i in input().split()] for i in range(n)]

sx = 0
sy = 0
ex = w
ey = h
for x,y,a in xya:
    if a == 1:
        sx = max(sx,x)
    if a == 2:
        ex = min(ex,x)
    if a == 3:
        sy = max(sy,y)
    if a == 4:
        ey = min(ey,y)

if ex-sx > 0 and ey-sy > 0:
    print((ex-sx)*(ey-sy))
else:
    print(0)


Measured memory_bytes: 3064
import sys
from collections import Counter
import numpy as np
 
n, *aaa = map(int, sys.stdin.buffer.read().split())
cnt = Counter(aaa)
duplicated = {x for x, c in cnt.items() if c > 1}
aaa.sort()
 
can = np.ones(aaa[-1] + 1, np.int8)
 
ans = 0
for a in aaa:
    if can[a] == 0:
        continue
    if a not in duplicated:
        ans += 1
    can[a * 2::a] = 0
print(ans)

Measured memory_bytes: 54068
# -*- coding: utf-8 -*-

import sys
import math
from decimal import Decimal, ROUND_DOWN
from collections import deque
from itertools import combinations
import copy

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        for line in sys.stdin:
            lines.append(line.strip())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (n, ) = [int(e) for e in lines[0].split(' ')]
    a = [int(e) for e in lines[1].split(' ')]


    return (n, a)


def solve(n, a):

             
    current = a[0]   
    total = 0
    for i in range(n):

        tmp = a[i] - current
        if tmp < 0:
            total = total + (-tmp)
        
        if a[i] > current:
            current = a[i]


    return total
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	


Measured memory_bytes: 36332
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int M = 2e5 + 5;
int tc, n, t[M], a[M], seg[4*M], l, r, at, qval;
vector <int> val;
int ans;

int get (int n, int s, int e) {
  if (l > e || r < s) return 0;
  if (l <= s && e <= r) return seg[n];
  int mid = (s+e) >> 1ll;
  return max(get(n*2, s, mid),get(2*n+1, mid+1, e));
}

void update (int n, int s, int e) {
  if (at > e || at < s) return;
  if (s == e) {seg[n] = qval; return;}
  int mid = (s+e) >> 1ll;
  update (n*2ll, s, mid);
  update (n*2ll+1, mid+1, e);
  seg[n] = max(seg[n*2],seg[n*2+1]);
}

int32_t main () {
    scanf ("%lld", &n);
    r = n;
    for (int i = 0; i < n; i++) {scanf ("%lld", &t[i]); val.push_back (t[i]);}
    for (int i = 0; i < n; i++) scanf ("%lld", &a[i]);
    sort (val.begin(), val.end());
    val.resize(unique (val.begin(), val.end())-val.begin());
    for (int i = 0; i < n; i++) {
      t[i] = lower_bound (val.begin(), val.end(), t[i]) - val.begin() + 1;
    }
    for (int i = n-1; i >= 0; i--) {
      l = t[i]+1;
      qval=a[i];
      if(l<=r)
        qval += get (1, 1, n);
      ans = max (ans, qval);
      at = t[i];
      update (1, 1, n);
    }
    printf ("%lld\n", ans);
}


Measured memory_bytes: 11248
import java.util.*;

// Tenakaichi 2017-D
// http://tenka1-2017.contest.atcoder.jp/tasks/tenka1_2017_d	

public class Main {

	public static void main (String[] args) throws InterruptedException {
		Scanner in = new Scanner(System.in);

		int N = in.nextInt();
		int K = in.nextInt();

		int[] nums = new int[N];
		int[] values = new int[N];
		
		for (int i = 0; i < N; i++) {
			nums[i] = in.nextInt();
			values[i] = in.nextInt();
		}
		
		long answer = 0;
		long tempAnswer = 0;
		
		for (int i = 0; i < N; i++) {
			boolean shouldAdd = true;
			int num = nums[i];
			
			for (int j = 0; j < 32; j++) {
				if ((K & (1 << j)) == 0 && (num & (1 << j)) > 0) {
					shouldAdd = false;
					break;
				}
			}
			
			if (shouldAdd) {
				tempAnswer += values[i];
			}
		}
		answer = Math.max(answer, tempAnswer);
		
		for (int i = 0; i < 32; i++) {
			if (((1 << i) & K) > 0) {
				tempAnswer = 0;
				for (int j = 0; j < N; j++) {
					if ((nums[j] & (1 << i)) == 0) {
						boolean shouldAdd = true;
						for (int k = i + 1; k < 32; k++) {
							if ((K & (1 << k)) == 0 && (nums[j] & (1 << k)) > 0) {
								shouldAdd = false;
								break;
							}
						}
						
						if (shouldAdd) {
							tempAnswer += values[j];
						}
					}
				}
				answer = Math.max(answer, tempAnswer);
			}
		}
		System.out.println(answer);
	}
	
}


Measured memory_bytes: 87312
#include<iostream>
using namespace std;
int main(){
	int a[4][2],b[4][2];
	while(cin >>a[0][0]>>a[1][0]>>a[2][0]>>a[3][0]){
		cin >>b[0][0]>>b[1][0]>>b[2][0]>>b[3][0];
		a[0][1] = a[1][1] = a[2][1] = a[3][1] = b[0][1] = b[1][1] = b[2][1] = b[3][1] = 1;
		int hit = 0,blow = 0;
		for(int i=0; i<4; i++){
			if(a[i][0] == b[i][0]){
				a[i][1] = 0;
				b[i][1] = 0;
				hit++;
			}
		}
		for(int i=0; i<4; i++){
			for(int l=0; l<4; l++){
				if(a[i][1] == 1 && b[l][1] == 1 && a[i][0] == b[l][0]){
					a[i][1] = 0;
					b[l][1] = 0;
					blow++;
				}
			}
		}
		cout<<hit<<" "<<blow<<endl;
	}
}

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;

struct edge {
    ll to;
    char cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int N;

int main(void){
    
    ll  N;
    map<ll, ll> _max;
    cin >> N;
    vector<ll> A(N);
    REP(i, N)cin >> A[i];
    REP(i, N){
        _max[A[i]]++;
    }
    map<ll, ll>::iterator it = _max.end();
    auto ans = --it;
    auto ans2 = --it;

    if(ans->second >= 2){
        REP(i, N){
            cout << ans->first << endl;
        }
    }else{
        REP(i, N){
            if(A[i] == ans->first){
                cout << ans2->first << endl;
            }else{
                cout << ans->first << endl;
            }
        }       
    }

    

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


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

int main(){
  string s, t, u;
  int a, b;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if (s == u) a--;
  if (t == u) b--;
  cout << a << ' ' << b << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
int main(){
    while(1){
        int start,end,target,n;
        scanf("%d",&target);
        if(!target) break;
        scanf("%d",&n);
        while(n--){
            scanf("%d %d",&start,&end);
            target -= end-start;
        }
        if(target>0) printf("%d\n",target);
        else printf("OK\n");
    }
}

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

#define ll long long

ll f(ll x){
	if(x<=0) return 0;
	if(x==1) return 1;
	ll res=0;
	ll y=2,r;
	r=(x+1)/2;
	if(r&1) res+=1;
	while(y<=x){
		y*=2;
		r=x%y;
		r-=y/2-1;
		if(r<0) r=0;
		if(r&1) res+=y/2;
	}
	return res;
}

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

	ll a,b;
	cin>>a>>b;
	cout<<(f(b)^f(a-1))<<"\n";
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func price(wantNum int, setNum int, setPrice int) int {
	return int(math.Ceil(float64(wantNum)/float64(setNum))) * setPrice
}

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var n, a, b, c, d int
	fmt.Scanf("%d %d %d %d %d", &n, &a, &b, &c, &d)

	var priceA = price(n, a, b)
	var priceB = price(n, c, d)
	var p = min(priceA, priceB)

	fmt.Printf("%d\n", p)
}



Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
const int cnt=1e6+7; 

int main()
{
//	freopen("input.txt","r",stdin);//设置 cin scanf 这些输入流都从 test.in中读取
    
    int k;
    cin>>k;
    bool flag=0;//是否满足条件，满足条件为1
    ll sum=0;
    int ans;
	for(int i=0;i<cnt;i++)
	{
		sum=(sum*10+7)%k;
		if(sum%k==0) 
		{
			flag=1;
			ans=i+1;
//			cout<<sum;
			break;
		}
	} 
	if(flag) cout<<ans;
    else cout<<"-1";
    
	return 0;
}


Measured memory_bytes: 3104
#include<stdio.h>
int main(void){
  int cou,A,B,C;
  scanf("%d %d %d",&A,&B,&C);
  if(A==5){
    cou++;
  }else if(A==7){
    cou--;
  }else{
    cou+=55;
  }
  if(B==5){
    cou++;
  }else if(B==7){
    cou--;
  }else{
    cou+=55;
  }
  if(C==5){
    cou++;
  }else if(C==7){
    cou--;
  }else{
    cou+=55;
  }
  
  if(cou==1){
    printf("YES");
  }else{
    printf("NO");
  }
  
  return 0;
}
    

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int func(int n){
	
	if(n %2 == 0){
		return n / 2;
	}else{
		return 3*n + 1;
	}
}
int main(void){
	
	int s; cin >> s;
	vector<int> A(1000000); A.at(0) = s;
	vector<int> check(1000000,0); check.at(A.at(0))++;
	
	int i;
	for(i = 1;i <= 1000000;i++){
		
		A.at(i) = func(A.at(i - 1));
		if(check.at(A.at(i)) == 1){
			check.at(A.at(i))++;
			break;
		}else{
			check.at(A.at(i))++;
		}
		
	}

	cout << i+1 << endl;
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main(){
    int n;cin >> n;
    vector<vector<ll>> a(n,vector<ll>(n));
    rep(i,n){
        rep(j,n){
            cin >> a[i][j];
        }
    }
    vector<vector<ll>> d=a;
    rep(k,n){
        rep(i,n){
            rep(j,n){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    rep(i,n){
        rep(j,n){
            if(d[i][j]!=a[i][j]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    set<l_l> ss;
    ll ans=0;
    for(ll k=0;k<n;k++){
        for(ll i=0;i<n;i++){
            for(ll j=0;j<n;j++){
                if(i!=j&&i!=k&&k!=j){
                    if(d[i][j]==d[i][k]+d[k][j]){
                        if(!ss.count({i,j})){
                            ss.insert({i,j});
                            ss.insert({j,i});
                        }
                    }
                }
            }
        }
    }
    set<l_l> s;
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            if(i!=j){
                if(!ss.count({i,j})&&!s.count({i,j})){
                    ans+=d[i][j];
                    s.insert({i,j});
                    s.insert({j,i});
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7296
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void Insertion(int*, int, int);
void Shell(int*, int);
int cnt=0, m, *G;

int main(){
  int i, n, *A;
  scanf("%d",&n);
  A = (int *)malloc(sizeof(int) * n);
  for(i=0; i<n; i++)
    scanf("%d",&A[i]);
  Shell(A, n);
  printf("%d\n",m);
  for(i=0; i<m; i++){
    printf("%d",G[i]);
    printf(i != m-1 ? " " : "\n");
  }
  printf("%d\n",cnt);
  for(i=0; i<n; i++){
    printf("%d",A[i]);
    printf("\n");
  }
  free(A);
  free(G);
  return 0;
}

void Insertion(int* A, int n, int g){
  int i, j, v;
  for(i=g; i<n; i++){
    v = A[i];
    j = i - g;
    while(j >= 0 && A[j] > v){
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
  }
}

void Shell(int* A, int n){
  int i;
  cnt = 0;
  for(i=0; i<n; i++)
    if(n < (pow(3,i+1)-1) / 2) break;
  m = i;
  G = (int *)malloc(sizeof(int) * m);
  for(i=0; i<m; i++)
    G[i] = (pow(3,m-i)-1) / 2;
  for(i=0; i<m; i++)
    Insertion(A, n, G[i]);
}

Measured memory_bytes: 4516
import java.util.ArrayList;
import java.util.Scanner;

class Main{

	static int N;
	static int M;
	static 		ArrayList<ArrayList<Integer>> map;
	static boolean[] used;
	static int f = 0;
	static int s = 0;

	static long mod = 1000000007;
	static ArrayList<Integer> saitan;




	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int m = sc.nextInt();

		if(n == m){
			long y = cal(n);
			System.out.println((y*y)*2%mod);
			return;
		}else if(Math.abs(n-m)==1){
			long a = cal(n);
			long b = cal(m);
			System.out.println(a*b%mod);

			
			
		}else{
			System.out.println(0);
		}




	}

	static long cal(int n){
		long x = (long)n;
		for(int i = n-1;i > 0;i--){
		//	System.out.println(i);
			x *= i;
			x %= mod;
		}
		return x;
	}

}




Measured memory_bytes: 21844
from collections import defaultdict

M = 10**9 + 7
N = int(input())
C = [0]*N
for i in range(N):
    C[i] = int(input())

P = [0]*N
Q = [0]*N
QS = defaultdict(int)
Q[0] = QS[C[0]] = 1
for i in range(1,N):
    if C[i] == C[i-1]:
        Q[i] = 0
    else:
        Q[i] = (P[i-1] + Q[i-1]) % M

    P[i] = QS[C[i]]
    QS[C[i]] = (QS[C[i]] + Q[i]) % M

print((P[N-1]+Q[N-1]) % M)

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

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

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

using namespace std;

int main()
{
  string s;
  cin >> s;
  int cnb = 0;
  int cnw = 0;
  for(int i = 0; i < s.length(); i++)
  {
    if(i%2 == 0)
    {
      if(s[i] == '1')
        cnb++;
      else
        cnw++;
    }
    else
    {
      if(s[i] == '0')
        cnb++;
      else
        cnw++;
    }
  }
  cout << min(cnb, cnw) << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i, n) for (int i = 0, i##_cond = (n); i < i##_cond; ++i)
#define FOR(i, a, b) for (int i = (a), i##_cond = (b); i < i##_cond; ++i)
#define ROF(i, a, b)                                                           \
  for (int i = (a)-1, i##_cond = (b); i >= i##_cond; --i) // ROF(i,n,0)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend() // sortで降順
#define SUM(a) accumulate(all(a), int(0))
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
constexpr ll inf = 1ll << 61;
constexpr ll mod = 1e9 + 7;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> T add(const T &a, const T &b) { return (a + b) % mod; }

signed main() {
  int n;
  cin >> n;
  vi a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  sort(all(a));
  sort(all(b));

  int amid, bmid;
  if (n % 2 == 0) {
    amid = (a[n / 2] + a[(n - 1) / 2]);
    bmid = (b[n / 2] + b[(n - 1) / 2]);
    dump(amid, bmid);
    cout << bmid - amid + 1 << endl;
  } else {
    amid = a[n / 2];
    bmid = b[n / 2];
    cout << (bmid - amid) + 1 << endl;
  }
}

Measured memory_bytes: 6360
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> A(3);
  cin >> A.at(0) >> A.at(1) >> A.at(2);
  sort(A.begin(), A.end());
  if (A[0] == 5 && A[1] == 5 && A[2] == 7) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <cassert>
using namespace std;

#define sz(a) int((a).size())
#define rep(i, s, n)  for(int i = s; i <= (n); ++i)
#define rev(i, n, s)  for(int i = (n); i >= s; --i)
#define fore(x, a) for(auto &&x : a)
typedef long long ll;
const int mod = 1000000007;
const int N = 100005;

vector<int> a[N];
bool v[N];
deque<int> ans;
int first = 1;

void go(int x, int p) {
  ans.push_back(x);
  v[x] = 1;
  if (first == 1) first = x;
  fore(y, a[x]) {
    if (!v[y]) {
      go(y, x);
      break;
    }
  }
}

void dfs_front(int x, int p) {
  if(x!=1) ans.push_front(x);
  v[x] = 1;
  fore(y, a[x]) {
    if (!v[y]) {
      dfs_front(y, x);
      break;
    }
  }
}

int main() {
#ifdef loc
  if(!freopen((string(FOLDER) + "inp.txt").c_str(), "r", stdin)) {
    assert(0);
  }
  freopen((string(FOLDER) + "out.txt").c_str(), "w", stdout);
#endif
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  int m;
  cin >> m;
  rep(i, 1, m) {
    int u, v;
    cin >> u >> v;
    a[u].emplace_back(v);
    a[v].emplace_back(u);
  }
  go(1, -1);
  dfs_front(1, first);
  cout << ans.size() << endl;
  fore(y, ans) {
    cout << y << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 6784
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;

using Graph = vector<vector<int>>;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n + 1);
    for (int i = 0; i <= n; i++)
    {
        cin >> a[i];
    }

    // n == 0 での例外処理
    if (n == 0)
    {
        if (a[0] == 1)
        {
            cout << 1 << endl;
        }
        else
        {
            cout << -1 << endl;
        }
        return 0;
    }
    // 根についての例外処理。
    if (a[0] != 0)
    {
        cout << -1 << endl;
        return 0;
    }

    vector<ll> MAX(n + 1); // 各深さで最大何個のノードを持ちうるのかを保持。

    // はじめは、深い方からMAXを更新。あとで浅い方からも更新する。
    MAX[n] = a[n];
    for (int i = n - 1; i >= 0; i--)
    {
        MAX[i] = MAX[i + 1] + a[i];
    }

    MAX[0] = 1;
    ll ans = 1;
    // 浅い方からMAXを更新。
    for (int i = 1; i <= n; i++)
    {
        MAX[i] = min((MAX[i - 1] - a[i - 1]) * 2, MAX[i]);
        ans += MAX[i];
        if (MAX[i] <= 0 || MAX[i] < a[i])
        {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << ans << endl;
    // debug_vec(MAX);

    return 0;
}


Measured memory_bytes: 4824
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Integer num = Integer.valueOf(new Scanner(System.in).nextLine());
		int min = Integer.MAX_VALUE;
		for (Integer a = num - 1, b = 1; a > 0 && b < num; a--, b = num - a) {
			int sum = 0;
			for (Integer ta = a, tb = b; ta > 0 || tb > 0; ta /= 10, tb /= 10) {
				sum += ta % 10;
				sum += tb % 10;
			}
			min = Integer.min(min, sum);
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 32708
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;
#define ll long long
int main(){
  string str;
  cin >> str;
  int i;
  int ans=0;
  for(i=0;i<4;i++){
    if(str[i]=='+'){
      ans++;
    }else{
      ans--;
    }
  }
  cout << ans;
  return 0;
}

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

int main() {
    int n;
    cin>>n;
    if(n%10 == 3)
    {
        cout<<"bon";
    }
    else if(n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8)
    {
        cout<<"pon";
    }
    else 
    {
        cout<<"hon";
    }
	// your code goes here
	return 0;
}


Measured memory_bytes: 3636