akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

#define INF LLONG_MAX / 5
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define enld endl

signed main() {
	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;
	vector<int>a(N);
	vector<int>b(N);
	vector<int>c(N);
	rep(i, N) {
		cin >> a[i] >> b[i] >> c[i];
	}
	int Sa = 0;
	int Sb = 0;
	rep(i, N) {
		Sa += a[i];
		Sb += b[i];
	}
	Sa++;
	Sb++;
	vector<vector<vector<int>>>dp(N + 1, vector<vector<int>>(Sa, vector<int>(Sb,INF)));
	rep(i, N + 1) {
		rep(j, Sa) {
			rep(k, Sb) {
				if (i == 0) {
					if (j == 0 && k == 0) {
						dp[i][j][k] = 0;
					}
				}
				else {
					if (j - a[i - 1] < 0 || k - b[i - 1] < 0) {
						dp[i][j][k] = dp[i - 1][j][k];
					}
					else {
						if (dp[i - 1][j][k] == INF && dp[i - 1][j - a[i - 1]][k - b[i - 1]] == INF) {
							dp[i][j][k] = INF;
						}
						else {
							dp[i][j][k] = min(dp[i - 1][j][k], dp[i - 1][j - a[i - 1]][k - b[i - 1]] + c[i - 1]);
						}
					}
				}
			}
		}
	}
	int ans = INF;
	rep(i, N + 1) {
		rep(j, Sa) {
			rep(k, Sb) {
				if (i == N && j * Mb == k * Ma &&j!=0&&k!=0) {
					ans = min(ans, dp[i][j][k]);
				}
			}
		}
	}
	if (ans == INF) {
		cout << -1 << enld;
	}
	else {
		cout << ans << endl;
	}
}

Measured memory_bytes: 22172
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#define LL long long
using namespace std;
const int N=1e5+7;
char s[N];
int R[N];
int L[N];
int ans[N];

int main()
{
	scanf("%s",s);
	int n=strlen(s);
	int pos;
	for(int i=0;i<n;i++){
		if(s[i]=='R') pos=i;
		R[i]=pos;
	}
	for(int i=n-1;i>=0;i--){
		if(s[i]=='L') pos=i;
		L[i]=pos;
	}
	int k;
	for(int i=0;i<n;i++){
		if(s[i]=='R'){
			k=L[i]-i;
			ans[L[i]-k%2]++;
		}
		else {
			k=i-R[i];
			ans[R[i]+k%2]++;
		}
	}
	cout<<ans[0];
	for(int i=1;i<n;i++) {
		cout<<' '<<ans[i];
	}
	cout<<endl;
	return 0;
 } 


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <stdlib.h>
#include <numeric>
#include <math.h>
using namespace std;
int main(){
  	int N, i, max=0, j=0;
    cin>>N;
    int H[N];
    for ( i = 0; i < N; i++)
    {
      cin>>H[i];
    }
    for ( i = 0; i < N-1; i++)
    {
      for(j=0; H[i+j]>=H[i+j+1]&&i+j+1<N; ){
        j++;
      }

      if(max<j){
        max=j;
        i=i+max;
      }
    }
    cout<<max<<endl;
    
    
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}




int main(){
  ll n,m;
  cin >> n >> m;
  ll c[n+1],b[n+1];
  vector<pair <ll,ll>> a;
  rep (i,n){
    cin >> c[i] >> b[i];
    a.push_back({c[i],b[i]});
  }
  sort(a.begin(),a.end());
  ll ans=0,cnt=0;
  for (auto v : a){
    while (v.second>0){
      if (cnt==m) break;
      ans += v.first;
      cnt++;
      //cout << ans << endl;
      v.second--;
    }
  }
  //cout << cnt << endl;
  cout << ans << endl;

  
}

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

if (n < 357):
   print(0)
   exit()

m = len(str(n))

from itertools import product
nums = ['3', '7', '5']

ans = 0
for i in range(3, m+1):
   a = list(product(nums, repeat=i))
   b = [int(''.join(list(j))) for j in a if ('3' in j and '5' in j and '7' in j)]
   if (i == m):
      ans += len([k for k in b if k <= n])
   else:
      ans += len(b)

print(ans)


Measured memory_bytes: 7284
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#ifndef ONLINE_JUDGE
//#include <custom/prettyprint.hpp>
//#endif
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef string str;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b) - 1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define rb(i,x) for (auto& i : x)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define UNIQUE(x) (x).resize(unique(all(x)) - begin(x))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define pow10(n) stoll("1"+string(n,'0'))
#define dbg(x) cout << ">>> " << #x << ": " << x << '\n'

const int MOD = 1e9+7; //998244353
const int inf = 1e9+3;
const ll INF = ll(3e18)+3;
const ld PI = acos((ld)-1);
const int dx[8] = {1,0,-1,0,1,1,-1,-1}, dy[8] = {0,1,0,-1,-1,1,1,-1};
mt19937_64 rng((uint64_t)chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll n) { return uniform_int_distribution<ll>(0, n)(rng); }
template<class T> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; }
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void setIO(const string& s) {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen((s+".in").c_str(),"r",stdin);
//	freopen((s+".out").c_str(),"w",stdout);
#endif
}

int main() {

    setIO("input");
    int a,b,c; cin >> a >> b >> c;
    int k; cin >> k;
    while(k && b <= a) {
        b *= 2;
        k--;
    }
    while(k && c <= b) {
        c *= 2;
        k--;
    }
    cout << (a < b && b < c ? "Yes\n" : "No\n");

}

/*  ! CHECK THIS IF YOU GET IT WRONG !
	* int overflow, array bounds, NO VLAs
	* uninitialized local variables, rounding errors
	* intermediate result type, scientific
	* special cases (n = 0 or 1?)
	* reset your variables in scope
	* INF not large enough for ans, adding value to _MAX
	* using wrong variables, sorting extra 0s in global array
	* comment out input from file
	* operator precedence
*/

Measured memory_bytes: 3616
N, M, X, Y = map(int, input().split())
X_list = list(map(int, input().split()))
Y_list = list(map(int, input().split()))
X_list.append(X)
Y_list.append(Y)
if max(X_list) < min(Y_list):
    print('No War')
else:
    print('War')



Measured memory_bytes: 38384
// A.cpp
#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
ll A, B, C;
int main()
{
    scanf("%lld%lld%lld", &A, &B, &C);
    if (B >= C || B + A >= C - 1)
        printf("%lld", B + C);
    else
        printf("%lld", min(C, A + B + 1) + B);
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        long L = sc.nextLong();
        long R = sc.nextLong();
        long ans = Long.MAX_VALUE;
        loop:for(long i=L; i<=R; i++){
            for(long j=i+1; j<=R; j++){
                ans = Math.min(ans, (i * j) % 2019);
                if(ans==0){
                    break loop;
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func DFS(T *[][]int, D *[]int, p, v int) int {
  if len((*T)[v]) == 1 {
    (*D)[v] = 1
    return 1
  }
  for _, adj := range (*T)[v] {
    if adj == p { continue }
    (*D)[v] += DFS(T, D, v, adj)
  }
  return (*D)[v]
}

func Solve() {
  N := NextInt()
  T := make([][]int, N)
  for i := range T {
    T[i] = make([]int, 0)
  }
  for i := 1; i < N; i++ {
    xy := NextIntVec()
    x, y := xy[0], xy[1]
    T[x] = append(T[x], y)
    T[y] = append(T[y], x)
  }
  max := 0
  for i, t := range T {
    if len(T[max]) < len(t) { max = i }
  }
  D := make([]int, N)
  DFS(&T, &D, max, max)
  Q := make([]int, 0)
  Q = append(Q, max)
  for 0 < len(Q) {
    q := Q[0]
    Q = Q[1:]
    rm := false
    for _, adj := range T[q] {
      if 0 < D[adj] { Q = append(Q, adj) }
      if D[q] == 1 || D[adj] != 1 || rm { continue }
      D[adj] = 0
      rm = true
    }
    if 1 < len(T[q]) { D[q] = 0 }
  }
  cnt := 0
  for _, d := range D {
    if 0 < d { cnt++ }
  }
  Write(cnt)
  return
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 41344
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>
#include <cassert>

using namespace std;


void solve(long long N, std::vector<std::vector<long long>> A){
  long long ans = 0;
  vector<long long> idxs(N, 0);  // 次が何番目の対戦相手か
  vector<long long> day(N, 0);  // 最後に試合をした日
  queue<long long> q;
  long long oponent;
  for (long long i = 0; i < N; i++) {
    oponent = A[i][idxs[i]]-1;
    if(A[oponent][idxs[oponent]]-1 == i) {
      idxs[oponent]++;
      idxs[i]++;
      day[i] = max(day[i], day[oponent]) + 1;
      day[oponent] = day[i];
      q.push(i);
      q.push(oponent);
    }
  }

  long long i;
  while (!q.empty()) {
    i = q.front();
    q.pop();
    if (idxs[i] == N-1) {
      continue;
    }
    oponent = A[i][idxs[i]]-1;
    if(A[oponent][idxs[oponent]]-1 == i) {
      idxs[oponent]++;
      idxs[i]++;
      day[i] = max(day[i], day[oponent]) + 1;
      day[oponent] = day[i];
      q.push(i);
      q.push(oponent);
    }
  }

  for (int i = 0; i < N; i++) {
    if (idxs[i] != N-1) {
      std::cout << -1 << std::endl;
      return;
    }
    ans = max(day[i], ans);
  }
  std::cout << ans << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<std::vector<long long>> A(N, std::vector<long long>(N-1));
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < N-1 ; j++){
      scanf("%lld",&A[i][j]);
    }
  }
  solve(N, std::move(A));
  return 0;
}


Measured memory_bytes: 8064
#include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long ull;
typedef long long ll;

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

using namespace std;

typedef pair<int ,int > P;

int ans;
int w,h;
char maze[27][27];

void dfs(int x,int y)
{
	//printf("[debug]:%d,%d\n",x,y);
	maze[x][y]='#';
	rep(i,4)
	{
		int nx=dx[i]+x;
		int ny=dy[i]+y;
		if(maze[nx][ny]=='.')
		{
			ans++;
			dfs(nx,ny);
		}
	}

}

void solve()
{
	/*
	rep(i,25)
	{
		rep(j,25)
		{
			cout<<maze[i][j];
		}
		cout<<endl;
	}
	*/
	rep(i,h) rep(j,w)
	{
		if(maze[i][j]=='@')
		{
			dfs(i,j);
			cout<<ans+1<<endl;
			return;
		}
	}


}

int main()
{
	rep(i,25) rep(j,25) maze[i][j]='#';
	
	while(cin>>w>>h)
	{
		if(w==0&&h==0) return 0;
		rep(i,h) rep(j,w) 
		{
			cin>>maze[i][j];
		}
		solve();
		ans=0;
		rep(i,25) rep(j,25) maze[i][j]='#';
	}


	return 0;
}

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

int target;
string s;
int maxi;
vector<int> ans, parts;

void rec(int sum, int p) {
  if(sum > target) {
    return;
  }
  if(p == s.size()) {
    if(sum == maxi) {
      ans.clear();
    } else if(sum > maxi) {
      ans = parts;
      maxi = sum;
    }
    return;
  }
  for(int len = 1; p+len <= s.size(); ++len) {
    int part = atoi(s.substr(p, len).c_str());
    parts.push_back(part);
    rec(sum + part, p+len);
    parts.pop_back();
  }
}

int main() {
  while(cin >> target >> s && !(target == 0 && s == "0")) {
    maxi = -1;
    rec(0, 0);
    if(maxi == -1) cout << "error" << endl;
    else if(ans.empty()) cout << "rejected" << endl;
    else {
      cout << maxi;
      for(int i = 0; i < ans.size(); ++i) {
        cout << " " << ans[i];
      }
      cout << endl;
    }
  }
  return 0;
}

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

using namespace std;

int main() {
	int n;
	string w;
	char c;
	set<string> used;

    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> w;
        if(i == 0) c = w[0];
        if(used.count(w) != 0 || w[0] != c) { cout << "No" << endl; return 0; }
        used.insert(w);
        c = w[w.size()-1];
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
static const int  MAX =200000;

int main(){
	int R[MAX], n;
	
	cin >> n;
	for( int i = 0; i< n; i++)cin >> R[i];
	
	int maxv =-2000000000;
	int minv = R[0];
	
	for(int i = 1; i < n; i++){
		maxv = max(maxv,R[i]- minv);
		minv = min(minv,R[i]);
	}
	
	cout << maxv << endl;

    return 0;
}

Measured memory_bytes: 3880
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define maxn 200010
using namespace std;
int a[200010];
int n;
int pos[200010],fa[maxn],book[maxn],du[maxn],ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)  cin>>a[i];
	for(int i=n;i>=1;i--) 
	{
		pos[a[i]]=i;
		if(pos[a[i]+1])
		{
			fa[pos[a[i]]]=pos[a[i]+1];
			du[pos[a[i]+1]]++;
		}	
	}
	for(int i=1;i<=n;i++)
	{
		if(du[i]==0)
		{
			int tmp=i;
			int sum=0;
			while(tmp)
			{
				sum++;
				tmp=fa[tmp];
			}
			ans=max(ans,sum);
		}
	}
	cout<<n-ans<<endl;
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>



using namespace std;
int N;


int gcd(int a, int b);


int main()
{

	cin >> N;


	int ans = 0;


	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			for (int k = 1; k <= N; k++) {
				int a = gcd(i, j);
				int b = gcd(a,k);

				ans += b;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

int gcd(int a, int b) {

	if (a < b) swap(a, b);



	while (1) {
		if (a < b) swap(a, b);

		if (!b) break;
		a %= b;
	}


	return a;
}

Measured memory_bytes: 3160
#include <iostream>

using namespace std;

int main(void){

  for( int i = 1 ; i <= 9 ; i++ ){
    for( int j = 1 ; j <= 9 ; j++ ){
      cout << i << "x" << j << "=" << i * j  << endl;
    }
  }
  return 0;
}

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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  set<int> s;
  int x;
  int n = 3;
  while(n--) cin>>x, s.emplace(x);
  cout << s.size() << endl;
}


Measured memory_bytes: 256
//q2 abc064
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <tuple>
#define pb push_back
#define mkt make_tuple
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
const int INF =  2147483647;
const ll INFLL = 9223372036854775807;



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

  int n, a, mmin = 1000, mmax = 0;
  cin >> n;
  for (size_t i = 0; i < n; i++) {
    cin >> a;
    if (mmin > a) {
      mmin = a;
    }
    if (mmax < a) {
      mmax = a;
    }
  }

  cout << mmax - mmin << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <math.h>
#include <bitset>

#define X first
#define Y second
#define vsort(v) sort(v.begin(), v.end())
#define vrev(v) reverse(v.begin(), v.end())
#define vmax_p(v) max_element(v.begin(), v.end())
#define vmin_p(v) min_element(v.begin(), v.end())
#define vmax_idx(v) distance(v.begin(), vmax_p(v))
#define vmin_idx(v) distance(v.begin(), vmin_p(v))
#define vcopy(src, dst) copy(src.begin(), src.end(), back_inserter(dst))
#define P pair

// stoi(s): string to int
// stod(s): string to double

// INT_MAX
// INT_MIN
// LLONG_MAX
// LLONG_MIN
// DBL_MIN
// DBL_MAX
// LDBL_MIN
// LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

// floor(x): truncate

// 2進数変換
// string s = bitset<20>(x).to_string();

using namespace std;
using ll = long long;

int main(int argc, const char *argv[])
{
    int n, k;
    cin >> n >> k;
  
    double ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int x = i;
        double y = 1;
        for (; x < k;)
        {
            x *= 2;
            y /= 2;
        }

        ans += 1.0 / n * y;
    }
    cout << setprecision(9) << ans << endl;
}


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

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

  lint X;
  cin >> X;
  lint cur = 100;
  lint ans = 0;
  while (cur < X) {
    ans++;
    cur += cur / 100;
  }

  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'

int main()
{
    ll n;
    cin>>n;
    vector<ll> v(n+1,0);
    for(ll i=1;i<n;i++)
    {
        ll x;
        cin>>x;
        v[x]++;
    }
    for(ll i=1;i<=n;i++) cout<<v[i]<<endl;
}

Measured memory_bytes: 4752
def main(N, M):
    member = [[0] * 721 for i in range(M)]
    r = int(input())
    for _ in range(r):
        t, _, m, s = map(int, input().split())
        t -= 540
        if s == 0:
            member[m - 1][t] -= 1
        else:
            member[m - 1][t] += 1
    for i in range(M):
        for t in range(1,721):
            member[i][t] += member[i][t - 1]
    
    q = int(input())
    for i in range(q):
        ts, te, m = map(int, input().split())
        ts -= 540
        te -= 540
        ans = 0
        #print(member[m-1][ts:te])
        for t in range(ts, te):
            ans += (member[m-1][t] > 0)
        print(ans)

while 1:
    n, m = map(int, input().split())
    if n == m == 0:
        break
    main(n,m)


Measured memory_bytes: 60772
import scala.io.Source

object Main {

  def main(args: Array[String]) {
    val lines = Source.stdin.getLines.toSeq
    val arr = lines.head.split(" ").map(_.toLong)
    val a = arr(1)
    val b = arr(2)
    val hs = lines.tail.map(_.toLong)

    def isSat(t: Long): Boolean = {
      def go(xs: Seq[Long], count: Long): Boolean =
        if (count < 0) false
        else xs match {
          case Nil => true
          case x +: rest => go(rest, count - ((x - 1) / (a - b) + 1))
        }
      go(hs.map(_ - b * t).filter(_ > 0), t)
    }

    def minimize(lower: Long, upper: Long): Long =
      if (lower >= upper) upper
      else {
        val mid = (lower + upper) / 2
        if (isSat(mid)) minimize(lower, mid)
        else minimize(mid + 1, upper)
      }

    val lowerBound = hs.max / a
    val upperBound = hs.max / b + 1
    println(minimize(lowerBound, upperBound))
  }

}


Measured memory_bytes: 131708
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N,D,X;
  cin >> N >> D >> X;
  int a[N];
  for(int i=0;i<N;i++) cin >> a[i];

  int ans = X;
  for(int i=0;i<N;i++){
    ans += (D-1)/a[i] + 1;
  }

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

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

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
//----------------------------------------------------------------

int main(void) {
  string s, t;
  cin >> s >> t;


  bool ok=false;
  s.pb('a');
  rep(i,26){
    if(i!=0) s[s.size()-1]++;
    if(s==t) ok=true;
  }
  prtok(ok);
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
/// Macros ---------------------
#define ll long long
#define sz(a) (int)a.size()
#define int long long
#define pb push_back
#define vi vector<int>
#define f first
#define s second
#define ii pair<int,int>
#define lb lower_bound
#define up upper_bound
#define rep(i,x,y) for(int i=(x);i<=(y);i++)
#define ld long double
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
/// Constracts -----------------------------------------------
const int maxn=1e5;
const int INF=(1ll)<<(30ll);
const int inf=1000000000000000000;
const int eps=1e-9;
const int mod=1e9+7;
/// Quick Pow ------------------------------------------------
int qpow(int b,int e)
{
    if( !e ) return 1;
    if( e & 1 ) return qpow(b, e - 1) * b;
    int pwur = qpow(b, e >> 1);
    return pwur * pwur;
}

int lcm(int a,int b){
    return a*b/__gcd(a,b);
}

/// My Code ---------------------------------------------------

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    vi v(n);
    for(auto &i:v)cin>>i;
    int ans=inf;
    for(int i=-100;i<=100;i++){
        int r=0;
        for(auto j:v){
            r+=qpow(j-i,2);
        }
        ans=min(ans,r);
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX = 1e9+7;

signed
main(){
		int d,w;
		while(cin >> d >> w && !(d==0 && w==0))
		{
				vector<vector<int> > e(d, vector<int>(w));
				for(int i=0;i<d;i++)
				{
						for(int j=0;j<w;j++)
						{
								cin >> e[i][j];
						}
				}
				int ans = 0;

				//縦A個, 横B個探索する
				for(int A=3;A<=d;A++)
				{
						for(int B=3;B<=w;B++)
						{
								//(y,x)が探索の初期値点
								for(int y=0;y<=d-A;y++)
								{
										for(int x=0;x<=w-B;x++)
										{
												//枠内の最大を求める
												int in_max = 0, in_sum = 0, in_num = 0;
												for(int a=y+1;a<=y+A-2;a++)
												{
														for(int b=x+1;b<=x+B-2;b++)
														{
																in_num++;
																in_sum += e[a][b];
																if(in_max < e[a][b])
																		in_max = e[a][b];
														}
												}
												//cout << in_sum << " " << in_max << endl;
													
												//枠外の最小を求める
												int out_min = MAX;
												for(int a=y;a<y+A;a++)
												{
														if(out_min > e[a][x]) out_min = e[a][x];
														if(out_min > e[a][x+B-1]) out_min = e[a][x+B-1];

												}
																									
												for(int b=x;b<x+B;b++)
												{
														if(out_min > e[y][b]) out_min = e[y][b];
														if(out_min > e[y+A-1][b]) out_min = e[y+A-1][b];

												}

												//cout << out_min << " " << in_max << endl;
												
												int sum = in_num * out_min - in_sum;
												if(out_min > in_max)
												{
														//cout << in_num << endl; 
														if(ans < sum) ans = sum;
												}
												
										}
								}

						}
				}
				cout << ans << endl;
		}
}



Measured memory_bytes: 3040
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

 
int main() {
    ll n, ans = 0;
    ll a, b;

    cin >> a >> b;

    cout << 6 - a - b << endl;

    
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll N, A, B, C, D; cin >> N >> A >> B >> C >> D;
  string result = "NO";
  ll diff = B-A;
  rep(i,N) {
    bool ok1 = diff<=D*i-C*((N-1)-i);
    bool ok2 = diff>=C*i-D*((N-1)-i);
    if (ok1&&ok2) result = "YES";
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		while(n--!=0)
		{
			int all=0;
			all=333*200+666*195+1;
			int y=in.nextInt();
			int m=in.nextInt();
			int d=in.nextInt();
			int yc =0;
			int mc =0;
			int dc =d;
			for(int i=1;i<y;i++)
			{	
				if(i%3==0)
					yc+=200;
				else
					yc+=195;
			}
			for(int j=1;j<m;j++)
			{
				if(y%3==0||j%2!=0)
					mc+=20;
				else
					mc+=19;
			}
			System.out.println(all-yc-mc-dc);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  if(N<=K){
    cout << N*X << endl;
  }
  else{
    cout << K*X+(N-K)*Y <<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) (a)=max(a, b)
#define chmin(a, b) (a)=min(a, b)
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/


int main() {
  ll i, j, k;
  
  ll H, W, K;
  cin >> H >> W >> K;
  string s[11];
  ll sum[11][1111]={};
  
  for(i=1; i<=H; i++) {
    cin >> s[i];
    s[i]="0"+s[i];
  }
  
  for(i=1; i<=H; i++) for(j=1; j<=W; j++) sum[i][j]=sum[i][j-1]+s[i][j]-'0';
  for(j=1; j<=W; j++) for(i=1; i<=H; i++) sum[i][j]+=sum[i-1][j];
  
  ll ans=INF;
  for(ll S=0; S<1<<(H-1); S++) {
    
    vector<ll> v;
    v.push_back(0);
    for(i=0; i<H-1; i++) if(S>>i&1) v.push_back(i+1);
    v.push_back(H);
    
    ll n=v.size()-1;
    vector<ll> cnt[n];
    for(k=0, i=1; i<v.size(); k++, i++) {
      cnt[k].push_back(0);
      for(j=1; j<=W; j++) cnt[k].push_back(sum[v[i]][j]-sum[v[i-1]][j]);
      cnt[k].push_back(INF);
    }
    
    ll c=-1;
    ll k=0;
    while(k<W) {
      ll t=W;
      for(i=0; i<n; i++) {
        ll p=k+1;
        while(cnt[i][k]+K>=cnt[i][p]) p++;
        p--;
        chmin(t, p);
      }
      
      if(k==t) {c=INF; break;}
      
      k=t;
      c++;
    }
    
    chmin(ans, (ll)v.size()-2LL+c);
    
  }
  
  
  pt(ans);
  
  
}




Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long a[2][200005];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m,k;
	cin>>n>>m>>k;
	int ai = 0;
	for(int i=1;i<=n;++i)
	{
		cin>>a[0][i],a[0][i] += a[0][i-1];
		if(a[0][i-1]<=k)
			ai = i;
	}
	for(int i=1;i<=m;++i)
		cin>>a[1][i],a[1][i] += a[1][i-1];
	int bi = 0, ans = 0;
	while(ai>=0&&bi<=m)
	{
		if(k>=a[0][ai]+a[1][bi])
			ans = max(ans,ai+bi),bi++;
		else
			ai--;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6728
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 105
#define int long long
using namespace std;
int n,w,W[li],V[li],dp[105][100005];
int dfs(int node,int ag){
	int cev=-inf;
	if(ag>w) return -inf;
	if(node==n+1) return 0;
	if(~dp[node][ag]) return dp[node][ag];
	cev=max(cev,dfs(node+1,ag));
	cev=max(cev,dfs(node+1,ag+W[node])+V[node]);
	return dp[node][ag]=cev;
}
main(){
	memset(dp,-1,sizeof(dp));
	scanf("%lld %lld",&n,&w);
	for(int i=1;i<=n;i++) scanf("%lld %lld",&W[i],&V[i]);
	int ty=dfs(1,0);
	printf("%lld\n",ty);
	return 0;
}




Measured memory_bytes: 82304
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n, m ,c;
	cin >> n >> m >> c ;
	vector<int>s(m);
	for (int q = 0; q < m; q++){
		cin >> s[q];
	}
	vector<vector<int>>a(n, vector<int>(m));
	for (int i = 0; i < n ; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	int kotae = 0;
	for (int w = 0; w < n; w++) {
		int sum = c;
		for (int x = 0; x < m; x++) {
			sum += a[w][x]*s[x];
		}
		if (sum > 0) {
			kotae++;
		}
	}
	cout << kotae;
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll n,k,ans=1;
    cin >> n >> k;
    rep(i,n)ans = min(ans+k,ans*2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mxn 1000010
#define db double
#define LL long long
#define ldb long double
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair<int,int> 
#define mp make_pair
#define fr first
#define sc second
#define x1 faqx1
#define y1 faqy1
#define x2 faqx2
#define y2 faqy2
using namespace std;
const int N=15000,mod=1e9+7;
int n,m,sl,fh,a[100][100],b[100][100];
bool f[100][100][30000];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int main()
{
	n=rd();m=rd();
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			a[i][j]=rd();
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			b[i][j]=rd();
	f[1][1][a[1][1]-b[1][1]+N]=1;
	f[1][1][b[1][1]-a[1][1]+N]=1;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			for(int v=-80*(i+j-1);v<=80*(i+j-1);++v)
				if(f[i][j][v+N])
				{
					f[i][j+1][v+N+a[i][j+1]-b[i][j+1]]=1;
					f[i][j+1][v+N+b[i][j+1]-a[i][j+1]]=1;
					f[i+1][j][v+N+a[i+1][j]-b[i+1][j]]=1;
					f[i+1][j][v+N+b[i+1][j]-a[i+1][j]]=1;
				}
	for(int i=0;i<=15000;++i)
		if(f[n][m][i+N]||f[n][m][-i+N])
			return printf("%d\n",i),0;
	return 0;
}

Measured memory_bytes: 240000
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

int main()
{
	ll N;
	cin >> N;
	vector<ll> A;
	//cout << N << endl;
	ll max = LLONG_MIN;
	ll sum = 0;
	for (int i = 0; i < N; ++i)
	{
		ll a;
		cin >> a;
		A.push_back(a);
		if (a < max)
		{
			sum += max - a;
		}
		max = std::max(a, max);

	}

	cout << sum << endl;

	return 0;

}

Measured memory_bytes: 5264
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u){
    int v;
    color[u] = GRAY;
    d[u] = ++tt;
    for(v=0;v<n;v++){
        if(M[u][v]==0) continue;
        if(color[v] == WHITE){
            dfs_visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt;
}

void dfs(){
    int u;
    for (int u = 0; u < n; ++u) {
        if(color[u]==WHITE) dfs_visit(u);

    }
    for(u=0;u<n;u++){
        printf("%d %d %d\n", u+1, d[u], f[u]);
    }
}

int main(){
    int u, v, k, i, j;

    scanf("%d",&n);

    for(i=0;i<n;i++){
        for(j=0;j<n;j++) M[i][j] = 0;
    }

    for(i=0;i<n;i++){
        scanf("%d %d", &u, &k);
        u--;
        for (int j = 0; j < k; j++) {
            scanf("%d",&v);
            v--;
            M[u][v]= 1;
        }
    }

    dfs();

    return 0;
}



Measured memory_bytes: 2064
import collections
n=[]
for i in range(int(input())):
    n.append(input())
    N = collections.Counter(n)
m=[]
for j in range(int(input())):
    m.append(input())
    M= collections.Counter(m)
intersection=list(N.keys()&M.keys())
for k in range(len(intersection)):
    N[intersection[k]]=N[intersection[k]]-M[intersection[k]]
print(max(max(list(N.values())),0))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  while (true) {
    int n, q; cin >> n >> q;
    if (!n) break;
    V<> a(100);
    while (n--) {
      int m; cin >> m;
      while (m--) {
        int d; cin >> d;
        ++a[d];
      }
    }
    auto itr = max_element(begin(a), end(a));
    cout << (*itr < q ? 0 : itr - begin(a)) << '\n';
  }
}


Measured memory_bytes: 3132
/***********************************************
#
#      Filename: a.cpp
#
#        Author: Comsyl - ylsong15@fudan.edu.cn
#   Description: ---
#        Create: 2017-04-29 20:03:04
***********************************************/
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, T;
    cin >> n >> T;
    int ans = 0;
    int begin = 0, end = 0;
    int t;
    for (int i = 0; i < n; ++ i) {
        cin >> t;
        if (t >= end) {
            ans += end - begin;
            begin = t;
            end = t + T;
        } else {
            end = t + T;
        }
    }
    ans += end - begin;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;


const int MAX_N = 2000000;
ll inv[MAX_N + 10];
ll fac[MAX_N + 10], facInv[MAX_N + 10];
class MATH{
public:
	MATH(){
		inverse();
		factroial();
	}
	ll nCk(ll n, ll k){// n! / k!*(n-k)!
		if(k < 0 || k > n) return 0;
		ll ret = fac[n];
		(ret *= facInv[k]) %= MOD;
		(ret *= facInv[n - k]) %= MOD;
		return ret;
	}
	ll nHk(ll n, ll k){// nHk = n+k-1 C k = (n+k-1)! / k! * (n-1)!
		if(n == 0 && k == 0) return 1;
		ll ret = fac[n + k - 1];
		(ret *= facInv[k]) %= MOD;
		(ret *= facInv[n - 1]) %= MOD;
		return ret;
	}
	ll nPk(ll n, ll k){//nPk = n! / (n-k)!
		if(k < 0 || k > n) return 0;
		ll ret = fac[n];
		(ret *= facInv[n - k]) %= MOD;
		return ret;
	}
private:
	void inverse(void){
		inv[1] = 1;
		for (int i = 2; i <= MAX_N; ++i){
			// inv[i] = MOD - (MOD / i) * inv[MOD % i] % MOD;
			inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
		}
	}
	void factroial(void){
		fac[0] = facInv[0] = 1;
		for (int i = 1; i <= MAX_N; ++i){
			fac[i] = (fac[i - 1] * i) % MOD;
			facInv[i] = (facInv[i - 1] * inv[i]) % MOD;
		}
	}
};

ll n, m;
int main(void) {
	cin >> n >> m;
	if(abs(n - m) > 1){
		printf("0\n");
		return 0;
	}
	MATH ma;
	if(n == m) {
		ll ans = fac[n] * fac[n] % MOD * 2 % MOD;
		printf("%lld\n", ans);
	}else {
		ll ans = fac[n] * fac[m] % MOD;
		printf("%lld\n", ans);
	}

	return 0;
}

Measured memory_bytes: 47104
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.util.*
import kotlin.math.*

fun main() {
    var fs = CodeForces.FastReader()
    var n = fs.nextInt()
    var x = fs.nextInt()
    var t = fs.nextInt()
    if(n%x == 0) println(n/x *t)
    else println((n/x +1)*t)
}
class CodeForces {
    internal class FastReader {
        private var br: BufferedReader = BufferedReader(InputStreamReader(System.`in`))
        private var st: StringTokenizer? = null

        operator fun next(): String {
            while (st == null || !st!!.hasMoreElements()) {
                try {
                    st = StringTokenizer(br.readLine())
                } catch (e: IOException) {
                    e.printStackTrace()
                }

            }
            return st!!.nextToken()
        }

        fun nextInt(): Int {
            return Integer.parseInt(next())
        }

        fun nextLong(): Long {
            return java.lang.Long.parseLong(next())
        }

        fun nextDouble(): Double {
            return java.lang.Double.parseDouble(next())
        }

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

        fun readIntArray(n: Int): IntArray {
            val a = IntArray(n)
            for (i in 0 until n) a[i] = nextInt()
            return a
        }

        fun readLongArray(n: Int): LongArray {
            val a = LongArray(n)
            for (i in 0 until n) a[i] = nextLong()
            return a
        }

        fun readDoubleArray(n: Int): DoubleArray {
            val a = DoubleArray(n)
            for (i in 0 until n) a[i] = nextDouble()
            return a
        }
    }
}


Measured memory_bytes: 34316
import numpy as np

x1,y1,x2,y2 = map(int, raw_input().split())
R90 = np.array([[0, -1], [1, 0]])
p1 = np.array([x1,y1])
p2 = np.array([x2,y2])
d12 = p2 - p1
d23 = np.dot(R90, d12)
p3 = p2 + d23
p4 = p3 - d12
print p3[0], p3[1], p4[0], p4[1]


Measured memory_bytes: 16224
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;

int main() {
	int n; cin >> n;
	if (n == 3) {
		cout << "2 5 63" << endl;
		return 0;
	}
	if (n == 4) {
		cout << "2 5 20 63" << endl;
		return 0;	
	}
	if (n == 5) {
		cout << "2 5 20 30 63" << endl;
		return 0;
	}
	vector<int> ans;
	int sum = 0;
	for (int i = 2; i <= 30000; i++) {
		if (i%2 == 0 || i %3 == 0) {
			sum += i;
			ans.push_back(i);
		}
		if (ans.size() >= n) break;
	}
	if (sum%6 == 2) {
		ans[4] = 30000;
	}
	else if (sum%6 == 3) {
		ans[5] = 30000;
	}
	else if (sum%6 == 5) {
		ans[5] = 29998;
	}
	for (auto a : ans) cout << a << (a == ans.back() ? "\n" : " ");
	return 0;
}

Measured memory_bytes: 512
N=input()

nl=[]
nl.append(1)
for i in range(1,7): nl.append(6**i)
for i in range(1,6): nl.append(9**i)

dp=[ float("inf") for i in range(N+1)]
dp[0]=0

for i in range(N+1):
	for dx in nl:
		if i+dx<=N:
			dp[i+dx]=min(dp[i+dx], dp[i]+1)


print dp[N]

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

int main() {
  int n, m;
  cin>>n>>m;
  int x[n];
  for (int i=0; i<n; i++) {
    cin>>x[i];
  }
  int same[(int)1e5+1];
  for (int i=0; i<1e5+1; i++) same[i] = 0;
  for (int i=0; i<n; i++) {
    ++same[x[i]];
  }
  int num_pairs[m];
  for (int i=0; i<m; i++) num_pairs[i] = 0;
  for (int i=0; i<1e5+1; i++) {
    num_pairs[i%m] += same[i] / 2;
  }
  int mods[m];
  for (int i=0; i<m; i++) mods[i] = 0;
  for (int i=0; i<n; i++) {
    ++mods[x[i]%m];
  }
  int cnt = 0;
  for (int i=0; i<=m/2; i++) {
    if (i == 0) {
      cnt += mods[0] / 2;
    } else if (m % 2 == 0 && i == m/2) {
      cnt += mods[m/2] / 2;
    } else {
      int l, s;
      if (mods[i] > mods[m-i]) {
        l = i;
        s = m - i;
      } else {
        l = m - i;
        s = i;
      }
      cnt += mods[s];
      cnt += min((mods[l] - mods[s]) / 2, num_pairs[l]);
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 1792
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)
//typedef pair < int, int> P;
ll gcd(ll a, ll b) {//最大公約数を求める///最大公倍数a*b/gcd(a,b)
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcd(ll a, ll b) {//最小公倍数を求める　b=0のときaを返す
	if (b == 0) return a;
	return (a / gcd(a, b)) * b;
}
vector<int> divnum(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
int digiter(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p.size();
}
vector<int> convertstring(string s) {
	vector<int> d;
	ll n = s.size();
	rep(i, n) {
		d.push_back(s[i] - '0');
	}
	return d;
}
map< int64_t, int > prime_factor(int64_t n) {
	map< int64_t, int > ret;
	for (int64_t i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
vector<ll> divisor(ll n) {
	vector<ll>res;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i != 0)continue;
		res.push_back(i);
		if (i * i != n)res.push_back(n / i);
	}
	return res;
}

ll N;
	set<ll> s;
ll cnt;
int main()
{
	cin >> N;
	vector<ll> d = divisor(N);
	
	for (ll e : d) {
		if (e == 1)continue;
		ll n = N/e;
		while (n % e == 0) {
			n /= e;
			if (n < e)break;
		}
		n %= e;
		if (n == 1) {
			
			cnt++;
		}
	}
	//cout << cnt << endl;
	vector<ll>f = divisor(N - 1);
	
	cnt += f.size()-1;
	
	cout << cnt << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

int main()
{
    int A, B, C;
    cin >> A >> B >> C;

    int count = abs(B/A);
    if (C < count) {
        count = C;
    }
    cout << count;

    return 0;
}   


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

int main(){
  int N , x , y;
  cin >> N;
  int k = 0;
  
  for (int i=0 ; i < N ; i++){
    cin >> x >> y;
    int z = y - x + 1;
    k += z;
   }
  
  cout << k << endl;
}
  

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

using namespace std;

#define pb push_back
#define ll long long
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define bug cout << "ok" << endl

const ll INF = 1e9 + 5, N = 1e6 + 5, mod = 998244353, M = 1e6 + 5;

ll d[N];

int main(){
	for(ll i = 2; i <= N - 5; i++){
		if(d[i] > 0) continue;
		d[i] = i;
		ll ch = i * 1ll * i;
		if(ch > N - 5) continue;
		for(ll j = i * i; j <= N - 5; j += i){
			if(d[j] > 0) continue;
			d[j] = i;
		}
	}
	ll n;
	cin >> n;
	ll ans = 1;
	for(int i = 2; i < n; i++){
		ll cnt = 1;
		ll x = i;
		while(x > 1){
			int dv = d[x];
			int um = 1;
			while(x % dv == 0){
				um++;
				x /= dv;
			}
			cnt *= um;
		}
		ans += (cnt);
	}	
	cout << ans << endl;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio( false );
  cin.tie( 0 );
  int w;
  cin >> w;
  string ans = "";
  while(w != 1)
  {
    switch( w % 3 )
    {
      case 0:
        ans = "0" + ans;
        break;
      case 1:       
        ans = "+" + ans;
        --w;
        break;
      case 2:
        ans = "-" + ans;
        ++w;
        break;
    }
    w /= 3;
  }
  ans = "+" + ans;
  cout << ans << "\n";
}

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000005
#define VMAX 10010

int main(){
  int *A, *B;
  int C[VMAX+1]={};
  int n, i, j;
  int max=0;

  scanf("%d", &n);

  A = malloc(sizeof(int)*n+1);
  B = malloc(sizeof(int)*n+1);

  /* your code */

  for(i=0;i<n;i++) {
    scanf("%d",&A[i]);
    C[A[i]] += 1;
    if(max<=A[i]) max = A[i];
  }

  for(i=1;i<max+1;i++) {
    C[i] += C[i-1];
  }

  for(i=n-1;i>=0;i--) {
    B[(C[A[i]]) - 1] = A[i];
    C[A[i]] -= 1;
  }

  /*
  for(i=0;i<max+1;i++) {
    printf("%d ",C[i]);
  }
  printf("\n");
  */
  
  for(i=0;i<n-1;i++) {
    printf("%d ",B[i]);
  }
  printf("%d\n",B[n-1]);

  return 0;
}



Measured memory_bytes: 17524