akhauriyash/Code-Regression huggingface dataset:
/*
 * Copyright (c) 2019 ... All rights reserved.
 * ...
 */
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {

    // source code
    int N, K;
    char S[50];

    // 入力
    cin >> N >> K;
    for (int i = 0; i < N; i++) cin >> S[i];
    char target = S[K - 1];

    if (target == 'A') S[K - 1] = 'a';
    else if(target == 'B') S[K - 1] = 'b';
    else S[K - 1] = 'c';

    for( int i = 0; i < N; i++) cout << S[i];


    return 0;
}

Measured memory_bytes: 256
fn solve() {
    let n: usize = read();
    let mut h: Vec<usize> = vec![];
    for i in 0..n {
        h.push(read());
    }
    let mut ok = false;
    let mut res = 0;
    while !ok {
        ok = true;
        let mut cont = false;
        for i in 0..n {
            if h[i] != 0 {
                if !cont {
                    res += 1;
                    cont = true;
                    ok = false;
                }
                h[i] -= 1;
            } else if h[i] == 0 && cont {
                cont = false;
            }
        }
    }
    println!("{}", res);
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min, Reverse};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


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

using namespace std;
long mem[100005][3];
int n;
int arr[100005][4];
long dp(int id,int ch){
    if(id==n+1)return 0;
    if(mem[id][ch]!=-1)return mem[id][ch];
    if(ch==0){
        mem[id][ch]=max(dp(id+1,1)+arr[id+1][1],max(dp(id+1,2)+arr[id+1][2],dp(id+1,3)+arr[id+1][3]));
    }
    if(ch==1){
        mem[id][ch]=max(dp(id+1,2)+arr[id+1][2],dp(id+1,3)+arr[id+1][3]);
    }
    if(ch==2){
        mem[id][ch]=max(dp(id+1,1)+arr[id+1][1],dp(id+1,3)+arr[id+1][3]);
    }
    if(ch==3){
        mem[id][ch]=max(dp(id+1,1)+arr[id+1][1],dp(id+1,2)+arr[id+1][2]);
    }
    return mem[id][ch];

}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    memset(mem,-1,sizeof(mem));
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>arr[i][1];
        cin>>arr[i][2];
        cin>>arr[i][3];
    }
    cout<<dp(0,0)<<endl;

    return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

ll GCD(ll a, ll b) {
    return (b > 0) ? GCD(b, a % b) : a;
}

ll LCM(ll a, ll b) {
    return a / GCD(a, b) * b;
}

int main() {
    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    if(n % m == 0){
        bool v = true;
        rep(i, m)if(s[i*(n/m)] != t[i])v = false;
        if(v)cout << n << endl;
        else cout << -1 << endl;
    }else if(m % n == 0){
        bool v = true;
        rep(i, n)if(s[i] != t[i*(m/n)])v = false;
        if(v)cout << m << endl;
        else cout << -1 << endl;
    }else{
        bool v = true;
        int g = GCD(n, m);
        rep(i, g)if(s[i*(n/g)] != t[i*(m/g)])v = false;
        if(v)cout << LCM(n, m) << endl;
        else cout << -1 << endl;
    }
    
}

Measured memory_bytes: 3740
A = int(input())
B = int(input())
C = int(input())
X = int(input())

A_list = [500*i for i in range(A+1)]
B_list = [100*i for i in range(B+1)]
C_list = [50*i for i in range(C+1)]
sum_list = []

for i in A_list:
    for j in B_list:
        i_j = i + j
        for k in C_list:
            sum_list.append(i_j + k)

result = 0
for i in sum_list:
    if i == X:
        result += 1

print(result)

Measured memory_bytes: 8344
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int count = 0;
  rep(i, a+1) {
    rep(j, b+1) {
      rep(k, c+1) {
        int sum = i*500+j*100+k*50;
        if (sum == x) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}
          


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

int main()
{
    set <string> data;
    int n;
    cin>>n;
    string* a = new string[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    data.insert(a[0]);
    for(int i=1;i<n;i++)
    {
        if( data.find(a[i])!= data.end() )
        {
            cout<<"No";
            return 0;
        }
        else data.insert(a[i]);
        if( a[i-1][a[i-1].length()-1 ]  != a[i][0] )
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}

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

int main(){
	int n;
	cin >> n;
	int a[n];
	int max=0;
	int max_sub=0;

	for(int i=0;i<n;i++){
		cin >> a[i];
		if(max<=a[i]){
			max_sub=max;
			max=a[i];
		}else if(max_sub<a[i]){
			max_sub=a[i];
		}
	}

	if(max_sub==max){
		for(int i=0;i<n;i++){
			cout << max <<endl;
		}
	}else{
		for(int i=0;i<n;i++){
			if(a[i]==max){
				cout << max_sub <<endl;
			}else{
				cout << max << endl;
			}
		}
	}
}

Measured memory_bytes: 2432
# -*- coding: utf-8 -*-
import sys

def main():
	a, b, c = input().split(" ")
	aa = list(a)
	bb = list(b)
	cc = list(c)
	
	if aa[len(aa)-1] == bb[0] and bb[len(bb)-1] == cc[0]:
		print("YES")
	else:
		print("NO")
	
if __name__ == "__main__":
	main()
	

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

using namespace std;

bool check(int a, int b){
	if(a != 1 && b != 1){
		return a > b;
	}else{
		return a == 1;
	}
}

int main(){
	int a, b;
	cin >> a >> b;
	if(a == b){
		cout << "Draw" << endl;
	}else{
		if(check(a, b)){
			cout << "Alice" << endl;
		}else{
			cout << "Bob" << endl;
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    ll a,b,n;
    cin>>a>>b>>n;
    ll x;
    if(n>=b-1) x=b-1;
    else x=n;

    ll ans=(a*x)/b-a*(x/b);
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;
typedef long long ll;
const int MAX = 100010;
ll inv[MAX],fact[MAX],fi[MAX],mod = 998244353;
void inverse(){
	int i;
	inv[1] = 1;
	for(i=2;i<MAX;i++){
		inv[i] = mod - (mod/i)*inv[mod%i]%mod;
	}
	fact[0] = fi[0] = 1;
	for(i=1;i<MAX;i++){
		fact[i] = fact[i-1]*i%mod;
		fi[i] = (fi[i-1]*inv[i])%mod;
	}
}

ll comb(int n,int k){
	if(n<0 || k<0 || n<k){
		return 0;
	}else{
		return fact[n]%mod*fi[k]%mod*fi[n-k]%mod;
	}
}

ll solve(int x,int s,int t){
	int k = s + 2*t;
	if(k<x) return comb(s + t,t);
	if((k - (x - 1))&1) return 0;
	if(s==0) return (x&1);
	if(k>=2*(x - 1)) return 0;
	int l = k - (x - 1);
	return comb(s + t - l,s);
}

int main(){
	int i,j,n,x;
	cin >> n >> x;
	inverse();
	ll ans = 0;
	for(i=0;i<=n;i++){
		for(j=0;j<=n;j++){
			(ans += solve(x,i,j)*comb(n,(i + j))%mod) %= mod;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 2560
import math

N, M = map(int, input().split())
S = input()
T = input()

g = math.gcd(N, M)
lcm = N * M // g
flg = True
N //= g
M //= g
for i in range(g):
    if S[i*N] != T[i*M]:
        flg = False
        break
if flg:
    print(lcm)
else:
    print(-1)


Measured memory_bytes: 64300
#include <iostream>
#include <vector>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#define endl "\n"
#define ll long long int
#define mod 1000000007
using namespace std;

unordered_map <ll, ll> mp;
vector <bool> primes(1100000, true);
vector <ll> primeList;

ll fastExp(ll base, ll exp)
{
	ll result = 1;
	while(exp > 0)
	{
		if(exp % 2 == 1)
			result = ((result % mod) * (base % mod)) % mod;
		base = ((base % mod) * (base % mod)) % mod;
		exp = exp / 2;
	}
	return result;
}

ll fermat(ll base, ll exp)
{
	ll result = 1;
	while(exp > 0)
	{
		if(exp % 2 == 1)
			result = ((result % mod) * (base % mod)) % mod;
		base = ((base % mod) * (base % mod)) % mod;
		exp = exp / 2;
	}
	return result;
}

void primeFactorization(ll n) 
{
    for (ll d : primeList) {
    	ll count = 0;
        if (d*d > n)
            break;
        while (n % d == 0) {
            count ++;
            n /= d;
        }
        if(count > mp[d])
        	mp[d] = count;
    }
    if (n > 1)
    {
    	if(mp[n] == 0)
    		mp[n] = 1;
    }
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n, data, i, j;
    cin >> n;

    for(i = 2; i <= sqrt(1000010); i ++)
    {
    	if(primes[i] == true)
    	{
	    	for(j = 2; i*j <= 1000010; j ++)
	    	{
	    		primes[i * j] = false;
	    	}
    	}
    }
    for(i = 2; i < 1000010; i ++)
    {
    	if(primes[i] == true)
    		primeList.push_back(i);
    }

    ll lcmVal = 1;
    vector <ll> v(n);
    for(i = 0; i < n; i ++)
    {
    	cin >> data;
    	v[i] = data;
    	primeFactorization(v[i]);
    }

    for(auto it = mp.begin(); it != mp.end(); it ++)
    {
    	// cout << it -> first << " " << it -> second << endl;
    	lcmVal = ((lcmVal % mod) * (fastExp(it -> first, it -> second) % mod)) % mod;
    }
    // cout << lcmVal << endl;
    ll ans = 0;
    for(i = 0; i < n; i ++)
    {
    	ll valInv = fermat(v[i], mod - 2) % mod;
    	ll inm = ((lcmVal % mod)*(valInv % mod)) % mod;
    	ans = ((ans % mod) + (inm % mod)) % mod;
    }
    cout << ans << endl;
}

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

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

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

Measured memory_bytes: 256
import sys
from operator import itemgetter
from heapq import heappush

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    N = ii()
    A = lmi()

    A.sort(reverse=True)
    ans = 0
    for i in range(N-1):
        ans += A[(1+i)//2]

    print(ans)

    return

main()


Measured memory_bytes: 31496
#include<stdio.h>
#define MAX 100005
#define NIL -1

struct Node{int p,l,r,ls,rs;}; 
struct Node T[MAX];
int n, root;

void findRoot()
{
  int i;
  for(i=0; i<n; i++)
    {
      if(T[i].p == NIL) 
	{
	  root = i;
	  break;
	}
    }   
}

void preorderPrint(int value)
{
 printf(" %d",value);
  if(T[value].l != -1)
    {   
      preorderPrint(T[value].l);
    }
  if(T[value].r != -1)
    {
      preorderPrint(T[value].r);
    } 
}

void inorderPrint(int value){
  if(T[value].l != -1)
    {   
      inorderPrint(T[value].l);
    }
  
  printf(" %d",value);
  
  if(T[value].r != -1)
    {
      inorderPrint(T[value].r);
    } 
}

void postorderPrint(int value){
  if(T[value].l != -1)
    {   
      postorderPrint(T[value].l);
    }

  if(T[value].r != -1)
    {   
      postorderPrint(T[value].r);
    } 

  printf(" %d",value);
 
}

main(){
  int i,j,d,v,c,l;
  
  scanf("%d",&n);
  
  for (i=0; i<n; i++){
    T[i].p = T[i].l = T[i].r = T[i].ls = T[i].rs = NIL;
  }
  
  for (i=0; i<n; i++){
    scanf("%d",&v);
    for (j=0; j<2; j++){
      scanf("%d",&c);
      
      if(j == 0){
	T[v].l = c;
	T[c].p = v;
	T[v].rs = c; 
      }
      else if(j == 1){
	T[v].r = c;
	T[c].p = v;
	T[v].ls = c;
      }
    }
  }
  
  
  findRoot();
  printf("Preorder\n");
  preorderPrint(root);
  printf("\n");
  printf("Inorder\n");
  inorderPrint(root);
  printf("\n");
  printf("Postorder\n");
  postorderPrint(root);
  printf("\n");
    return 0;
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
using namespace std;
#define int long long
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
    const int MAX =100002;
const int MOD =1000000007;
vector<int> hen[200000];
int modpow(int a, int n, int mod) {
    int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
vector<pair<int,int>> solve(int a){
    vector<pair<int,int>> x;
    int t=0;
    for(int i:hen[a]){
        vector<pair<int,int>> y=solve(i);
        if(x.size()<y.size())swap(x,y);
        int k=y.size();
        t=max(t,k);
        for(int j=0;j<y.size();j++){
            x[x.size()-1-j]={(y[y.size()-1-j].second*x[x.size()-1-j].first%MOD+x[x.size()-1-j].second*y[y.size()-1-j].first%MOD)%MOD,y[y.size()-1-j].second*x[x.size()-1-j].second%MOD};
        }
    }
    for(int i=0;i<t;i++){
        x[x.size()-1-i].second=(MOD+1-x[x.size()-1-i].first)%MOD;
    }
    t=modpow(2,MOD-2,MOD);
    x.push_back({t,t});
    

    return x;
}
     signed main(){
      int n;
      cin>>n;
      int p;
      for(int i=1;i<=n;i++){
          cin>>p;
          hen[p].push_back(i);
      }
      int ans=0;
      vector<pair<int,int>>q=solve(0);
      for(int i=q.size()-1;i>=0;i--){
          ans=(ans+q[i].first)%MOD;
      }
      cout<<ans*modpow(2,n+1,MOD)%MOD<<endl;
   }
     


 


 






    





      

        


Measured memory_bytes: 37060
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int k=sc.nextInt();
		ArrayDeque<Long> q=new ArrayDeque<>();
		for(long i=1; i<=9; i++){
			q.add(i);
		}
		long tmp=0;
		for(int i=0; i<k; i++){
			tmp=q.poll();
			if(tmp%10!=0){
				q.add(tmp*10+tmp%10-1);
			} 
			q.add(tmp*10+tmp%10);
			if(tmp%10!=9){
				q.add(tmp*10+tmp%10+1);
			}
		}
		System.out.println(tmp);
	}
}


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

long long n,k,now=1,cnt,a[223456],pre[223456];

int main(){
  cin>>n>>k;
  for(int i=1;i<=n;i++)cin>>a[i];
  while(k--){
    now=a[now];
    if(pre[now])k%=cnt-pre[now];
    pre[now]=cnt++;
  }
  cout<<now<<endl;
}


Measured memory_bytes: 6776
N,K,S = map(int,input().split())
ans = []
if S == 10**9:
    for i in range(K):
        ans.append(S)
    for i in range(N-K):
        ans.append(1)
else:
    for i in range(K):
        ans.append(S)
    for i in range(N-K):
        ans.append(S+1)
print(" ".join(map(str,ans)))

Measured memory_bytes: 15000
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  long long cnt[2019];
  fill(cnt, cnt + 2019, 0);
  int sum = 0, pw10 = 1;
  for (int i = S.length() - 1; i >= 0; i--) {
    sum = ((S[i] - '0') * pw10 + sum) % 2019;
    debug(sum);
    pw10 = pw10 * 10 % 2019;
    cnt[sum]++;
  }
  //   debugArray(cnt, 2019);
  long long ans = cnt[0];
  for (int i = 0; i < 2019; i++) {
    ans += cnt[i] * (cnt[i] - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3736
#include <stdio.h>
#include <string.h>

#define Q_MAX (400000)

typedef struct {
	char block[10][11];
    int num[3];
	int time;
} COLOR;

int head, tail;
COLOR queue[Q_MAX];

void enq(COLOR t)
{
	queue[tail++ % Q_MAX] = t;
}

void deq(COLOR *t)
{
	*t = queue[head++ % Q_MAX];
}

int conv(char c)
{
    return ((c > 'B') + (c > 'G'));
}

int x, y;

void dfs(COLOR *exm, char c, char change, int p, int q)
{
	int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
	int mx, my;
	int i;
	
    exm->num[conv(exm->block[q][p])]--;
    exm->num[conv(c)]++;
	exm->block[q][p] = c;
	
	for (i = 0; i < 4; i++){
		mx = p + dx[i];
		my = q + dy[i];
		if (0 <= mx && mx < x && 0 <= my && my < y && exm->block[my][mx] == change){
			dfs(exm, c, change, mx, my);
		}
	}
}

void check(COLOR p, char col)
{
	if (p.block[0][0] != col){
		p.time++;
		dfs(&p, col, p.block[0][0], 0, 0);
		enq(p);
	}
}

int main(void)
{
	COLOR puzzle, temp;
	int i, j;
	char c;
    
	while (1){
		scanf("%d%d", &x, &y);
		
		if (x + y == 0){
			break;
		}
        memset(puzzle.num, 0, sizeof(puzzle.num));
		
		for (i = 0; i < y; i++){
			for (j = 0; j < x; j++){
				do {
					c = puzzle.block[i][j] = getchar();
				} while (c != 'R' && c != 'G' && c != 'B');
                puzzle.num[conv(c)]++;
			}
		}
		memset(queue, 0, sizeof(queue));
		head = tail = 0;
		puzzle.time = 0;
		enq(puzzle);
        
		while (1){
			deq(&temp);
			
			if (temp.num[0] == x * y || temp.num[1] == x * y || temp.num[2] == x * y){
				break;
			}
			
			check(temp, 'R');
			check(temp, 'G');
			check(temp, 'B');
		}
		
		printf("%d\n", temp.time);
	}
	
	return (0);
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N;
    cin >> N;
    vector<ll> A;
    for (int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        A.pb(a);
    }
    bool flg = true;
    for (int i = 0; i < N; i++) {
        if(A[i] % 2 == 0 && (A[i] % 3 != 0 && A[i] % 5 != 0)){
            flg = false;
        }
    }
    SANKOU(flg,APPROVED,DENIED);
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
const int N=2005;
char s[N];
int n,m,a[N][N],up[N][N],right[N][N],left[N][N],ans;
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++){
		scanf("%s",s+1);
		for (int j=1;j<=m;j++)
			if (s[j]=='#') a[i][j]=1;
			else a[i][j]=0;
	}
	n--,m--;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			a[i][j]=a[i][j]^a[i+1][j]^a[i][j+1]^a[i+1][j+1];
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			if (!a[i][j]) right[i][j]=right[i][j-1]+1;
	for (int i=1;i<=n;i++)
		for (int j=m;j>=1;j--)
			if (!a[i][j]) left[i][j]=left[i][j+1]+1;
	int ans=std::max(n,m)+1;
	for (int i=1;i<=n;i++)
		for (int j=m;j>=1;j--){
			if (a[i][j]) continue;
			up[i][j]=up[i-1][j]+1;
			if (up[i-1][j]) 
				right[i][j]=std::min(right[i][j],right[i-1][j]),left[i][j]=std::min(left[i][j],left[i-1][j]);
			ans=std::max(ans,(left[i][j]+right[i][j])*(up[i][j]+1));	
		}
	printf("%d\n",ans);
}

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

using namespace std;

const int N = 55;
const int NN = N * N * 5;
vector<tuple<int, int, int>> g[N];
int c[N], d[N];
long long dp[N][NN];

priority_queue<tuple<long long, int, int>> q;

int add(int a, int b) {
  return min(a + b, NN - 1);
}

long long add2(long long a, long long b) {
  if (LLONG_MAX - a < b) {
    return LLONG_MAX;
  } else {
    return a + b;
  }
}

void push(long long d, int i, int j) {
  if (dp[i][j] > d) {
    dp[i][j] = d;
    q.emplace(-d, i, j);
  }
}

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

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < NN; ++j) {
      dp[i][j] = LLONG_MAX;
    }
  }

  int n, m, s;
  cin >> n >> m >> s;
  s = add(0, s);
  while (m--) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    --u, --v;
    g[u].emplace_back(v, a, b);
    g[v].emplace_back(u, a, b);
  }
  for (int i = 0; i < n; ++i) {
    cin >> c[i] >> d[i];
  }
  push(0, 0, s);
  while (!q.empty()) {
    long long dd;
    int i, j;
    tie(dd, i, j) = q.top();
    q.pop();
    dd = -dd;
    if (dp[i][j] < dd) {
      continue;
    }
    push(add2(dd, d[i]), i, add(j, c[i]));
    for (auto [v, a, b] : g[i]) {
      if (j < a) {
        continue;
      }
      push(add2(dd, b), v, j - a);
    }
  }
  for (int i = 1; i < n; ++i) {
    cout << *min_element(dp[i], dp[i] + NN) << '\n';
  }

  return 0;
}


Measured memory_bytes: 17920
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long int;
const ll MAXS = 1000010;

int main() {
  ll X, Y, Z, A, B, C, N;
  cin >> X >> Y >> Z >> A >> B >> C >> N;

  vector<ll> ans(N);

  // z-axis
  vector<ll> ans_z(N);
  for(int i=0; i<Z; i++) {
    ll idx = (i < C ? C - i : i - C) % N;
    // fprintf(stderr, "idx = %lld\n", idx);
    ans_z[idx]++;
  }

  /*
  for(int i=0; i<N; i++) {
    cerr << ans_z[i] << " \n"[i+1 == N];
  }
  */

  // y-axis
  vector<ll> ans_y(N);
  ll sa = B + 1, sb = Y - B;
  
  // solve (a)
  ll div = sa / N, mod = sa % N;
  for(int i=0; i<N; i++) {
    ll mul = div + (i < mod);
    for(int j=0; j<N; j++) {
      ans_y[(j+i+N)%N] += mul * ans_z[j];
    }
  }

  // solve (b)
  div = sb / N, mod = sb % N;
  for(int i=0; i<N; i++) {
    ll mul = div + (i < mod);

    // do not overlap
    if(i == 0) mul--;
    
    for(int j=0; j<N; j++) {
      // fprintf(stderr, "index = %d, mul = %lld, j = %d\n", (j+i+N)%N, mul, j);
      ans_y[(j+i+N)%N] += mul * ans_z[j];
    }
  }

  /*
  for(int i=0; i<N; i++) {
    cerr << ans_y[i] << " \n"[i+1 == N];
  }
  */

  // x-axis
  sa = A + 1, sb = X - A;
  // solve(a)
  div = sa / N, mod = sa % N;
  for(int i=0; i<N; i++) {
    ll mul = div + (i < mod);
    for(int j=0; j<N; j++) {
      ans[(j+i+N)%N] += mul * ans_y[j];
    }
  }

  div = sb / N, mod = sb % N;
  for(int i=0; i<N; i++) {
    ll mul = div + (i < mod);

    if(i == 0) mul--;

    for(int j=0; j<N; j++) {
      ans[(j+i+N)%N] += mul * ans_y[j];
    }
  }

  for(int i=0; i<N; i++) {
    cout << ans[i] << " \n"[i+1 == N];
  }
  return 0;
}



Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
int p[1000005];
vector<int> num;
int main(){
    int x;
    cin>>x;
    for(int i=2;i<=1000000;i++){
        if(p[i]==1) continue;
        if(p[i]==0) num.push_back(i);
        for(int j=i;j<=1000000;j+=i){
            p[j]=1;
        }
    }
    cout<<*lower_bound(num.begin(),num.end(),x)<<endl;
}

Measured memory_bytes: 4860
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;

using namespace std;
int kaijo(int n){
	int ans = 1;
	if (n != 0){
		for (int i = 0; i < n; i++){
			ans *= (n - i);
		}
	}
	else{
		ans = 1;
	}
	return ans;
}

int main(){
	double a, b, c, d, e, f;
	double x,y;
	while (cin >> a >> b >> c >> d >> e >> f){
		x = (c*e - b*f) / (a*e - b*d);
		y = (c*d - a*f) / (b*d - a*e);
		if (fabs(x) * 1000 < 1){
			x = 0;
		}
		if (fabs(y) * 1000 < 1){
			y = 0;
		}
		cout << fixed << setprecision(3) << x << " " << fixed << setprecision(3) << y << endl;
	}
	return 0;
}

Measured memory_bytes: 3232
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node{
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

Node * treeMinimum(Node *x) {
  while( x->left != NIL ) x = x->left;
  return x;
}

Node * find(Node *u, int k) {
  while( u != NIL && k != u->key ) {
    if ( k < u->key ) u = u->left;
    else u = u->right;
  }
  return u;
}

Node * treeSuccessor(Node *x) {
  if ( x->right != NIL ) return treeMinimum(x->right);
  Node *y = x->parent;
  while( y != NIL && x == y->right ) {
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node *z) {
  Node *y;   // 削除する対象
  Node *x;   // yの子
  
//削除する節点を求める
  if ( z->left == NIL || z->right == NIL ) y = z;
  else y = treeSuccessor(z);
  
  
// yの子xを決める
  if ( y->left != NIL ) {
    x = y->left;
  } else {
    x =y->right;
  }
  
  if( x != NIL ) {
    x->parent = y->parent;
  }
  
  if( y->parent == NIL ) {
    root = x;
  } else {
    if ( y == y->parent->left) {
      y->parent->left = x;
    } else {
      y->parent->right = x;
    }
  }
  
  if ( y != z ) {
    z->key = y->key;
  }
  
  free(y);
}

void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;
  
  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while( x != NIL ){
    y = x;
    if( z->key < x->key ){
      x = x->left;
    } else {
      x = x->right;
    }
  }
  
  z->parent = y;
  if( y == NIL ){
    root = z;
  } else {
    if( z->key < y->key ){
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node *u) {
  if ( u == NIL ) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node *u) {
  if ( u == NIL ) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main() {
  int n, i, x;
  string com;
  
  scanf("%d", &n);
  
  for( i = 0; i < n; i++ ) {
    cin >> com;
    if ( com[0] == 'f' ) {
      scanf("%d", &x);
      Node *t = find(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com == "insert" ) {
      scanf("%d", &x);
      insert(x);
    } else if ( com == "print" ) {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com == "delete" ) {
      scanf("%d", &x);
      treeDelete(find(root, x));
    }
  }
  
  return 0;
}


Measured memory_bytes: 22052
inputs = Array.new
while line = $stdin.gets
  inputs << line.chomp
end

r, D, x2000 = inputs[0].split(" ").map(&:to_i)

x = Hash.new
(1..10).each do |index|
  if index == 1
    x[index] = r * x2000 - D
    next
  end
  x[index] = r * x[index - 1] - D
end

(1..10).each do |index|
  puts x[index]
end


Measured memory_bytes: 1788
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
char str[6][40];
int dp[1<<20][11];
int ng[5];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<5;i++)scanf("%s",str[i]);
		for(int i=0;i<(1<<a);i++)for(int j=0;j<11;j++){
			dp[i][j]=999999999;
		}
		for(int i=0;i<5;i++)ng[i]=0;
		for(int i=0;i<5;i++){
			for(int j=0;j<a;j++)for(int k=j+1;k<a;k++){
				if(str[i][j]=='X'&&str[i][k]=='X')ng[i]|=(1<<(a+j-k));
			}
	//		printf("%d\n",ng[i]);
		}
		dp[0][0]=0;
		for(int j=0;j<10;j++){
			for(int i=(1<<a)-1;i>=0;i--){
				if(dp[i][j]>999999)continue;
		//		printf("%d %d: %d\n",j,i,dp[i][j]);
				dp[i/2][j]=min(dp[i/2][j],dp[i][j]+1);
				bool ok=true;
				for(int k=0;k<5;k++)if(i&ng[k])ok=false;
				if(ok){
					dp[i/2+(1<<(a-1))][j+1]=min(dp[i/2+(1<<(a-1))][j+1],dp[i][j]+1);
				}
			}
		}
		int ret=999999999;
		for(int i=0;i<(1<<a);i++){
			ret=min(ret,dp[i][10]+a-1);
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1076
a=[list(map(int,input().split())) for i in range(3)]
n=int(input())
b=[int(input()) for i in range(n)]
flag =False
for i in range(3):
  if all(a[i][j] in b for j in range(3)):
    flag=True
  if all(a[j][i] in b for j in range(3)):
    flag=True
if all(a[j][j] in b for j in range(3)) or all(a[i][2-i] in b for i in range(3)) :
  flag=True
if(flag):
  print("Yes")
else:
  print("No")
       


Measured memory_bytes: 38256
N,P = map(int,input().split())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

import collections
import math
c = collections.Counter(prime_factorize(P)) 
#print(c)

ans = 1
for n,k in c.items():
  ans *= n**(math.floor(k/N))
print(ans)

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

bool isPrime(int);

int main(){
	int n;
	while(cin >> n&&n != 0){
		int ans=0;
		for(int i=n+1;i<=2*n;i++){
			if(isPrime(i)){
				ans++;
			}
		}
		cout << ans << endl;
	}
}

bool isPrime(int num){
	for(int i=2;i*i<=num;i++){
		if(num%i==0){return false;}
	}
	return true;
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define MOD 100000

using namespace std;

int N,M,S;
int dp[50][3001];

int main()
{
  while(scanf("%d %d %d",&N,&M,&S),N|M|S)
    {

      rep(i,N*N+1)rep(j,S+1)dp[i][j] = 0;
      dp[0][0] = 1;

      for(int v=1;v<=M;v++)
	{
	  for(int cnt=N*N-1;cnt>=0;cnt--)
	    {
	      for(int def=0;def<=S;def++)
		{
		  if(dp[cnt][def] == 0)continue;
		  if(def+v <= S)
		    {
		      dp[cnt+1][def+v] = (dp[cnt+1][def+v] + dp[cnt][def]) % MOD;
		    }
		}
	    }
	}
      printf("%d\n",dp[N*N][S]);
    }
  return 0;
}

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

int main() {
  int count=0;
  int q=0,w=0;
  int N; cin>>N;
  vector<int>A(N);
  rep(i,N){
    cin>>A[i];
  }
  count=*max_element(A.begin(),A.end());
rep(i,N){
  if(A[i]==count){
    q=i;
  break;
}
}
    rep(i,N){
      if(i==q){
        A[i]=0;
        w=*max_element(A.begin(),A.end());
      }
      else w=count;
      cout<<w<<endl;
  }
}

Measured memory_bytes: 2432
n = int(input())
A = list(map(int, input().split()))
A = [0]+A+[0]

front = [0]*(n+2)
back = [0]*(n+2)
delta = [0]*(n+1)
delta2 = [0]*n
# print(A)

for i in range(n+1):
    delta[i] = abs(A[i]-A[i+1])
# print(delta)

for i in range(n):
    delta2[i] = abs(A[i]-A[i+2])
# print(delta2)

for i in range(1,n+2):
    front[i] = front[i-1]+delta[i-1]
    back[i] = back[i-1]+delta[(n+1)-i]
back.reverse()
# print(front)
# print(back)

for i in range(n):
    print(front[i]+delta2[i]+back[i+2])


Measured memory_bytes: 23764
N,W = gets.split().map(&:to_i)
r = [0] * (W+1)

N.times do
	v,w = gets.split().map(&:to_i)
	W.downto(w) do |ri|
		if r[ri] < r[ri-w]+v
			r[ri] = r[ri-w]+v
		end
	end
end

p r.max

Measured memory_bytes: 8712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	if(b>d){
		cout << 1;
	}
	else{
		cout <<0;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 100005
#define ll signed long long int
using namespace std;

ll ans = 0, a, b, c ,n , t, k;
signed main()
{
    FAST;
    cin >> a >> b >> c >> k;
    if(k > 0){
    	t = min(a, k);
    	k -= t;
    	ans += t;
	}
	if(k > 0){
		t = min(b, k);
		k -= t;
		
	}
	if(k > 0){
		t = min(c, k);
		k -= t;
		ans -= t;
		
	}
	cout << ans ; return 0;
}

Measured memory_bytes: 3608
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.math.BigInteger;
 
public class Main{
 
static PrintWriter out;
static InputReader ir;
 
static void solve(){
 int n=ir.nextInt();
 int temp=n;
 int ct=0;
 while(true){
  if(n==0) break;
  n/=3;
  ct++;
 }
 if(Math.pow(3,ct-1)==temp) ct--;
 out.println(ct);
}
 
public static void main(String[] args) throws Exception{
 ir=new InputReader(System.in);
 out=new PrintWriter(System.out);
 solve();
 out.flush();
}
 
static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;
 
 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
  
 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }
 
 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}
  
 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
  
 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}
  
 public boolean hasNext(){skip(); return hasNextByte();}
  
 public String next(){
  if(!hasNext()) throw new NoSuchElementException();
  StringBuilder sb=new StringBuilder();
  int b=readByte();
  while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  }
  return sb.toString();
 }
  
 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
  
 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public double nextDouble(){return Double.parseDouble(next());}
 
 public int[] nextIntArray(int n){
  int[] a=new int[n];
  for(int i=0;i<n;i++) a[i]=nextInt();
  return a;
 }
 
 public long[] nextLongArray(int n){
  long[] a=new long[n];
  for(int i=0;i<n;i++) a[i]=nextLong();
  return a;
 }
 
 public char[][] nextCharMap(int n,int m){
  char[][] map=new char[n][m];
  for(int i=0;i<n;i++) map[i]=next().toCharArray();
  return map;
 }
}
}

Measured memory_bytes: 24476
N=int(input())
T=[int(input()) for i in range(N)]

def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)

ans=T[0]
for i in range(1,N):
    ans=lcm(ans,T[i])
print(ans)

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

struct C {
  char suit;
  int value;
};

void BubbleSort(C a[], int n) {
  for (int i=0; i<n; i++) {
    for (int j=n-1; j>i; j--) {
      if (a[j].value < a[j-1].value) {
        C temp = a[j];
        a[j] = a[j-1];
        a[j-1] = temp;
      }
    }
  }
}

void SelectionSort(C a[], int n) {
  for (int i=0; i<n; i++) {
    int min_j = i;
    for (int j=i; j<n; j++) {
      if (a[j].value < a[min_j].value) min_j = j;
    }
    if (i != min_j) {
      C temp = a[i];
      a[i] = a[min_j];
      a[min_j] = temp;
    }
  }
}

int main() {
  int n;
  cin >> n;
  C a[n], b[n];
  for (int i=0; i<n; i++) cin >> a[i].suit >> a[i].value;
  for (int i=0; i<n; i++) b[i] = a[i];

  BubbleSort(a, n);
  SelectionSort(b, n);

  for (int i=0; i<n-1; i++) cout << a[i].suit << a[i].value << " ";
  cout << a[n-1].suit << a[n-1].value << endl;
  cout << "Stable" << endl;

  string res = "Stable";
  for (int i=0; i<n; i++) {
    if (a[i].suit != b[i].suit) {
      res = "Not stable";
      break;
    }
  }

  for (int i=0; i<n-1; i++) cout << b[i].suit << b[i].value << " ";
  cout << b[n-1].suit << b[n-1].value << endl;
  cout << res << endl;

  return 0;
}



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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    string s, t;
    cin >> s >> t;

    ll ret = 0;
    REP(i, 3) ret += s[i]==t[i];
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
import sys

MOD = (10**9)+7
N,M = map(int,input().split())
if not(N == M or N+1 == M or N == M+1):
    print(0)
    sys.exit()

if N == M:
    ans = 2
else:
    ans = 1
for i in range(1,N+1):
    ans *= i
    ans %= MOD
for i in range(1,M+1):
    ans *= i
    ans %= MOD
print(ans)


Measured memory_bytes: 3060
# count p<=x<=q and p<=y <=q
# 長方形に含まれる格子点の数
import numpy as np
N,M,Q = map(int,input().split())

cnt = [[0]*(N+1) for _ in range(N+1)]
for _ in range(M):
  x,y = map(int,input().split())
  cnt[x][y] += 1

# cumsumだけnumpyを使って、添字アクセスするときはlistの方が速い
cnt = np.cumsum(cnt,axis=0).cumsum(axis=1).tolist()

for _ in range(Q):
  p,q = map(int,input().split())
  p -= 1
  x = cnt[q][q]
  x -= cnt[q][p]
  x -= cnt[p][q]
  x += cnt[p][p]
  print(x)

Measured memory_bytes: 26252
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int main()
{
    ll n;
    cin >> n;
    vector<ll> vec(n);
    rep(i,n){
        cin >> vec[i];
    }
    sort(all(vec));
    ll ans = 0;
    while(1){
        if(vec[n-1] <= n-1){
            break;
        }
        bool flag = false;
        rep(i,n-1){
            ll diff = vec[i+1] - vec[i];
            ll hoge = diff / (n+1);
            if(hoge >= 1){
                flag = true;
                for(int j=0;j<=i;j++){
                    vec[j] += hoge*(n-i-1);
                }
                for(int j=i+1;j<n;j++){
                    vec[j] -= hoge*(i+2);
                }
                ans += hoge*(n-i-1);
            }
        }
        if(!flag){
            if(vec[n-1]-(100*n) > 0){
                ans += n*(vec[n-1]-(100*n));
                rep(j,n){
                    vec[j] -= vec[n-1]-(100*n);
                }
            }
            while(vec[n-1] > n-1){
                rep(j,n-1){
                    vec[j]++;
                }
                vec[n-1] -= n;
                ans++;
                sort(all(vec));
            }
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {

	public static void main(String[] args)throws IOException  {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		 List<Integer> list = new ArrayList<Integer>();
		 for (String s : Arrays.asList(br.readLine().trim().split("\\s+"))) list.add(Integer.parseInt(s));
		 
		 int a = list.get(0), b = list.get(1);
		 
		 System.out.println(""+(a*b)+" "+(2*a+2*b));
		 
	}

}

Measured memory_bytes: 24336
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

struct Node {
  unsigned int key;
  Node *prev, *next;
};

Node *nil;

Node* listSearch(int key) {
  Node *cur = nil->next;
  while (cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

void init() {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

void deleteNode(Node *t) {
  if (t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst() {
  deleteNode(nil->next);
}

void deleteLast() {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  Node *node = listSearch(key);
  deleteNode(node);
}

void printList() {
  Node *cur = nil->next;
  int isf = 1;
  while (1) {
    if (cur == nil) break;
    if (isf == 0) printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

int main() {
  int n;
  scanf("%d", &n);

  char command[20];
  int key;
  init();
  for (int i = 0; i < n; i++) {
    scanf("%s", command);
    if (strcmp(command, "insert") == 0) {
      scanf("%d", &key);
      insert(key);
    } else if (strcmp(command, "delete") == 0) {
      scanf("%d", &key);
      deleteKey(key);
    } else if (strcmp(command, "deleteFirst") == 0) deleteFirst();
    else if (strcmp(command, "deleteLast") == 0) deleteLast();
  }

  printList();

  return 0;
}



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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//-----------------------------------------------------------------------------

string s,t="abcdefghijklmnopqrstuvwxyz";
int k;

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

	cin>>s>>k;
	int sz=(int)s.size();
	REP(i,sz){
		if(s[i]=='a') continue;
		if(k==0) continue;
		int need=26-(s[i]-'a');
		if(k<need) continue;
		k-=need;
		s[i]='a';
	}
	k=k%26;
	s[sz-1]=t[(s[sz-1]-'a'+k)%26];
	cout<<s<<endl;

	return 0;
}


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

typedef struct dice {
  int a[6];
  void change(char ch) {
    if(ch == 'E') {
      int temp = a[0];
      a[0] = a[3];
      a[3] = a[5];
      a[5] = a[2];
      a[2] = temp;
    }
    if(ch == 'N') {
      int temp = a[0];
      a[0] = a[1];
      a[1] = a[5];
      a[5] = a[4];
      a[4] = temp;
    }
    if(ch == 'S') {
      int temp = a[0];
      a[0] = a[4];
      a[4] = a[5];
      a[5] = a[1];
      a[1] = temp;
    }
    if(ch == 'W') {
      int temp = a[0];
      a[0] = a[2];
      a[2] = a[5];
      a[5] = a[3];
      a[3] = temp;
    }
  }
  int query(int x) { return a[x]; }
} dice;

bool check(dice a, dice b) {
  string d = "EEEENEEEENEEEENEEEEWSEEEENNEEEE";
  for(int i = 0; i < d.length(); i++) {
    a.change(d[i]);
    bool flag = true;
    if(a.query(0) != b.query(0))
      flag = false;
    if(a.query(1) != b.query(1))
      flag = false;
    if(a.query(2) != b.query(2))
      flag = false;
    if(a.query(3) != b.query(3))
      flag = false;
    if(a.query(4) != b.query(4))
      flag = false;
    if(a.query(5) != b.query(5))
      flag = false;
    if(flag)
      return true;
  }
  return false;
}

int main(void) {
  int n;
  cin >> n;
  dice di[n];
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < 6; j++) {
      cin >> di[i].a[j];
    }
  }
  for(int i = 0; i < n - 1; i++) {
    for(int j = i + 1; j < n; j++) {
      if(check(di[i], di[j])) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}



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

int main(){
  string A, B;
  cin >> A;
  for (int i=0; i<A.length(); i++){
    if (A.at(i)=='0'){
      B+="0";
    }
    else if(A.at(i)=='1'){
      B+="1";
    }
    else if(A.at(i)=='B'){
      if (B.length()==0){
        continue;
      }
      else {
        B=B.substr(0,B.length()-1);
      }
    }
  }
  cout << B << endl;

}


Measured memory_bytes: 256
N=int(input())
list =input()
S=list.split()[0]
T=list.split()[1]
ans=""
for n in range(N*2):
    if n % 2 == 0:
        ans+=str(S[int(n/2)])
    else:
        ans+=str(T[int(n/2)])
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include <vector>
using namespace std;
int main() {
	long long a, b, n, c, d;
	for (int h = 0; h < 5; h++) {
		cin >> a >> b;
		if (a == 0 && b == 0) { cin >> n; return 0; }
		cin >> n;
		int test[123] = { 0 }, uiop[123] = { 0 };
		std::vector<std::vector<long long>> dp(1001, std::vector<long long>(1001, 0));
		for (int i = 0; i < n; i++) {
			cin >> c >> d; test[i] = c; uiop[i] = d;
		}
		dp[1][1] = 1;
		int e = 0;
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= b; j++) {
				e = 0;
				if (i == 1 && j == 1) { continue; }
				for (int k = 0; k < n; k++) {
					if (test[k] == i && uiop[k] == j) {
						dp[i][j] = 0; e++;
					}
				}
				if (e != 0) { continue; }
				if (i != 1) {// 上移動
					dp[i][j] += dp[i - 1][j];
				}
				if (j != 1) {//右移動
					dp[i][j] += dp[i][j - 1];
				}
			}
		}
		cout << dp[a][b] << endl;
	}
}


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

using namespace std;

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

	string t;
	cin >> t;

	int change = 0;

	for (int i = 0; i < s.size(); i++) {
		if (t[i] != s[i]) {
			change++;
		}
	}
	cout << change << endl;
	return 0;
}

Measured memory_bytes: 3844
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>


using namespace std;

int main()
{
    long K, S;

    cin >> K >> S;
    int count = 0;
    for (int i = 0; i <= K; ++i) {
        for (int j = 0; j <= K; ++j) {
            if (0 <= S - i - j && S - i - j <= K) {
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256