akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

typedef pair<int,string> P;

int comp(const P& a, const P& b) {
	return (a.first > b.first);
}

int main() {
	vector<P> seq;
	string s;
	string maxstr = "";
	int pos;
	
	getline(cin, s);
	
	while (1) {
		pos = s.find(' ');
		string word = s.substr(0, pos);

		bool inserted = false;
		for (int i = 0; i < seq.size(); i++) {
			if (seq[i].second == word) {
				seq[i].first++;
				inserted = true;
			}
		}
		if (!inserted) {
			seq.push_back(P(1, word));
		}

		if (word.size() > maxstr.size()) {
			maxstr = word;
		}

		if (pos == string::npos)
			break;
		s = s.substr(pos+1);
	}

	sort(seq.begin(), seq.end(), comp);

	cout << seq[0].second << " " << maxstr << endl;

	return 0;
}

Measured memory_bytes: 0
N, M = map(int, input().split())
XYZ = []
for _ in range(N):
    XYZ.append(list(map(int, input().split())))

ans = 0
# sort * 8
from itertools import product
for signs in product((-1, 1), repeat=3):
    arr = [sum(s * v for s, v in zip(signs, xyz)) for xyz in XYZ]
    arr.sort(reverse=True)
    ans = max(ans, sum(arr[:M]))

print(ans)

Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <vector>
#include <set>

using namespace std;

long long GCD(long long a, long long b)
{
    if (b > a)
        swap(a, b);
    if (a % b == 0)
        return b;
    return GCD(b, a % b);
}

int main(void)
{
    long long K, count = 0;
    cin >> K;
    for (long long i = 1; i <= K; ++i)
    {
        for (long long j = 1; j <= K; ++j)
        {
            for (long long k = 1; k <= K; ++k)
            {
                count += GCD(i, GCD(j, k));
            }
        }
    }
    cout << count << "\n";
}

Measured memory_bytes: 3656
#include <stdio.h>
#define N 36
typedef struct
{
	int value;
	char mark;	
}card;

void BubbleSort(card *c,int n)
{
	int i=n-1,j,flag=1;
	card cc;
	while(i>0&&flag==1)	
	{
		flag=0;
		for(j=0;j<i;j++)
		if(c[j].value>c[j+1].value)
		{
			cc=c[j];
			c[j]=c[j+1];
			c[j+1]=cc;
			flag=1;
		}
	}
	for(i=0;i<n;i++)
	{
	printf("%c%d",c[i].mark,c[i].value);	
	if(i+1!=n)
	printf(" ");
	}
	printf("\nStable\n");	
}

void SelectionSort(card *c,int n)
{
	int i,j,min;
	card cc;
	for(i=0;i<n-1;i++)
	{
		min=i;
		for(j=i+1;j<n;j++)
		if(c[j].value<c[min].value)
		min=j;
		if(min!=i)
		{
			cc=c[min];
			c[min]=c[i];
			c[i]=cc;
		}
	}
	for(i=0;i<n;i++)
	{
	printf("%c%d",c[i].mark,c[i].value);	
	if(i+1!=n)
	printf(" ");
	}
}

int main(int argc, char *argv[])
{
	card c1[N],c2[N];
	int n,i,flag=1;
	char ch;
	scanf("%d%c",&n,&ch);
	for(i=0;i<n;i++)
	scanf("%c%d%c",&c1[i].mark,&c1[i].value,&ch);
	for(i=0;i<n;i++)
	c2[i]=c1[i];
	BubbleSort(c1,n);
	SelectionSort(c2,n);
	/***********************/
	for(i=0;i<n;i++)
	if(c1[i].mark!=c2[i].mark)
	{
		flag=0;
		break;
	}
	if(flag==0)
	printf("\nNot stable\n");
	else
	printf("\nStable\n");
	return 0;
}

Measured memory_bytes: 1804
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        System.out.println(str);
    }

    public static void main(String[] args) {

        int N;
        int M;
        int[] Pn;
        int[] Xn;
        int[] Yn;

        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            M = sc.nextInt();
            Pn = new int[N];
            Xn = new int[M];
            Yn = new int[M];
            for(int i =0;i < N;i++){
                Pn[i] = sc.nextInt();
            }
            for(int i =0;i < M;i++){
                Xn[i] = sc.nextInt() -1;
                Yn[i] = sc.nextInt() -1;
            }
        }

        UnionF union = new UnionF(N);
        for(int i =0;i < M;i++){
            union.mergeSet(Xn[i], Yn[i]);
        }
        int result = 0;

        for(int i = N-1;i >= 0;i--){
            int k = union.root(Pn[i]-1);
            int j = union.root(i);
            if(k == j){
                result++;
            }
        }
        System.out.println(result);

    }
    public static class UnionF {
        int[] elements;
        int[] rank;

        public UnionF(int size) {
            this.elements = new int[size];
            this.rank = new int[size];
            for (int i = 0; i < elements.length; i++) {
                elements[i] = i;
                rank[i] = 0;
            }
        }

        public void mergeSet(int x, int y) {
            int i = root(x);

            int j = root(y);

            if (i == j) {
                return;
            }

            if (rank[i] > rank[j]) {
                elements[j] = i;

            } else {
                elements[i] = j;
                if (rank[i] == rank[j]) {
                    rank[i]++;
                }
            }
        }

        public int root(int x) {
            int i = x;
            while (elements[i] != i) {
                i = elements[i];
            }
            int root = i;
            //経路圧縮
            i = x;
            while (elements[i] != i) {
                i = elements[i];
                elements[i] = root;
            }
            return root;
        }

        public boolean isSameSet(int x, int y) {
            int i = root(x);

            int j = root(y);

            return i == j;
        }

        @Override
        public String toString() {
            return this.elements.toString();
        }

    }
}


Measured memory_bytes: 89360
N = int(input())

A = [int(input()) for _ in range(N)]

a_max = max(A)

a_max_count = 0

a_second = 0

for n in A:
    if n != a_max:
        a_second = max(n, a_second)
    else:
        a_max_count += 1

if a_max_count >= 2:
    for _ in A:
        print(a_max)
else:
    for n in A:
        if n == a_max:
            print(a_second)
        else:
            print(a_max)

Measured memory_bytes: 12512
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>

/* 値を入れ替える関数 */
void swap (int *x, int *y) {
    int temp;    // 値を一時保存する変数
    
    temp = *x;
    *x = *y;
    *y = temp;
}

/***
 * pivotを決め、
 * 全データをpivotを境目に振り分け、
 * pivotの添え字を返す
 ***/
int partition (int array[], int left, int right) {
    int i, j, pivot;
    i = left;
    j = right + 1;
    pivot = left;   // 先頭要素をpivotとする
    
    do {
        do { i++; } while (array[i] < array[pivot]);
        do { j--; } while (array[pivot] < array[j]);
        // pivotより小さいものを左へ、大きいものを右へ
        if (i < j) { swap(&array[i], &array[j]); }
    } while (i < j);
    
    swap(&array[pivot], &array[j]);   //pivotを更新
    
    return j;
}

/* クイックソート */
void quick_sort (int array[], int left, int right) {
    int pivot;
    
    if (left < right) {
        pivot = partition(array, left, right);
        quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
        quick_sort(array, pivot+1, right);
    }
}

int main(void){
    int i,j,k;
    int N,v[100];
    double answer = 0;
    
    scanf("%d",&N);
    for(i = 0;i < N - 1;i++){
        scanf("%d\n",&v[i]);
    }
    scanf("%d",&v[i]);
    
    quick_sort(v,0,N-1);
    
    answer = v[0];
    for(i = 1;i < N;i++){
        answer = (answer + v[i]) / 2;
    }
    
    printf("%lf\n",answer);
   
    return 0;
}













Measured memory_bytes: 128
N=int(input())
c=list(input())
i=0
j=len(c)-1
ans=0
while i<j:
    while i<len(c) and c[i]=='R':
        i+=1
    while j>=0 and c[j]=='W':
        j-=1
    if i<j:
        ans+=1
        i+=1
        j-=1
print(ans)

Measured memory_bytes: 77504
int main() {

	int R[200000], n, i, max, min;

	scanf("%d",&n);

	for (i = 0; i < n; i++)   scanf("%d",&R[i]);

	max = -100000000000;
	min = R[0];

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

			if (max < R[i] - min) max = R[i] - min;

			if (min > R[i]) min = R[i];
		}

	printf("%d\n", max);

	return 0;

}

Measured memory_bytes: 2536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define INF (1e9)

ll bfs(ll v, vvi G, ll N) {
  vi depth = vi(N, -100);
  ll ans = 0;
  depth[v] = 0;
  queue<ll> que;
  que.push(v);
  while (!que.empty()) {
    v = que.front();
    que.pop();
    for (auto next : G[v]) {
      if (depth[next] == depth[v] + 1) continue;
      if (depth[next] == depth[v] - 1) continue;
      if (depth[next] != -100) return -1;
      depth[next] = depth[v] + 1;
      ans = max(ans, depth[next]);
      que.push(next);
    }
  }
  return ans + 1;
}

int main() {
  ll N;
  cin >> N;
  vvi G(N);
  for (ll i = 0; i < N; i++) {
    string s;
    cin >> s;
    for (ll j = 0; j < N; j++) {
      if (s[j] == '0') continue;
      G[i].push_back(j);
      G[j].push_back(i);
    }
  }

  ll ans = -1;
  for (ll i = 0; i < N; i++) {
    ans = max(ans, bfs(i, G, N));
  }
  cout << ans << endl;
}


Measured memory_bytes: 4788
#include<iostream>
#include<cmath>

using namespace std;
typedef unsigned long long ullong;

ullong power(ullong m, ullong n, ullong M) {
    ullong res = 1;
    if(n > 0){
        res = power(m, n / 2, M);
        if ( n % 2 == 0) res = (res * res) % M;
        else res = (((res * res) % M) * m) % M;
    }
    return res;
}

int main(){
    ullong m, n;
    cin >> m >> n;
    
    cout << power(m, n, 1000000007) << endl;
    
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdlib>
#include <vector>
#include <iomanip>
#include <utility>
using namespace std;
#define ll long long

int main(void){
    ll n, m;
    cin >> n >> m;
    ll ans;
    ll MAX = m/n;
    if(m%n != 0){
    for(ll i = 1; i <= MAX; i++){
        if(m%i == 0 && m/i >= n)
            ans = i;
    }}
    else
        ans = m/n;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

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

    int n;
    cin >> n;

    vector<ll> x(n), y(n);
    vector<ll> sum(n), diff(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        sum[i] = x[i] + y[i];
        diff[i] = x[i] - y[i];
    }
    sort(sum.begin(), sum.end());
    sort(diff.begin(), diff.end());

    cout << max(sum.back() - sum.front(), diff.back() - diff.front()) << newl;

    return 0;
}

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

int main(){
  long long n,ans=0;
  cin >> n;
  for(int i=0;i<=n;i++){
    if(i%3 != 0 && i%5 != 0) ans += i;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;

typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int n, q; cin >> n >> q;
    
    priority_queue<int>pq[n];
    
    REP(i, q){
        int a, b, c; cin >> a;
        if(a==0){
            cin >> b >> c;
            pq[b].push(c);
        }
        if(a==1){
            cin >> b;
            if(pq[b].size()==0) continue;
            
            cout << pq[b].top() << endl;
        }
        if(a==2){
            cin >> b;
            if(pq[b].size()==0) continue;
            
            pq[b].pop();
        }
    }
	return 0;
}


Measured memory_bytes: 4120
package main
 
import (
	"sort"
	"bufio"
	"fmt"
	"os"
	"strconv"
)
 
var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)
 
func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }
 
func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}
 
func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }
 
//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
 
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)
 
	n := scanInt()
	r := make(robots, n)
 
	for i := 0; i < n; i++ {
		x := scanInt()
		l := scanInt()
		r[i] = robot{x-l,x+l}
	}
 
	sort.Sort(r)
 
	cnt := 0
	anc := int(-1e9)
	for i := 0; i < n; i++ {
		if anc <= r[i].a {
			anc = r[i].b
		} else {
			cnt++
		}
	}
 
	fmt.Fprintln(wr, n-cnt)

	// fmt.Fprintln(wr, r)
 
}
 
type robot struct {
	a,b int
}
 
type robots []robot
 
func (a robots) Len() int           { return len(a) }
func (a robots) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a robots) Less(i, j int) bool { 
	if a[i].b==a[j].b {
		return a[i].a<a[j].a
	}
	return a[i].b < a[j].b
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
const int N=1e5+5;
using namespace std;
char s1[N],s2[N];
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	if(n>m)scanf("%s%s",s2,s1),swap(n,m);else
		scanf("%s%s",s1,s2);
	long long w=(long long)m/__gcd(n,m)*n;
	int k1=w/n,k2=w/m,a1=1,a2=1,p1=1,p2=1;
	while(a1<=n&&a2<=m)
	{
		if(p1==p2&&s1[a1-1]!=s2[a2-1])
		{
			puts("-1");
			return 0;
		}
		if(p1<=p2)a1++,p1+=k1;else
			a2++,p2+=k2;
	}
	printf("%lld\n",w);
	return 0;
}

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


int main(){
int n;
cin>>n;
int i=1;

while(1){
 int x=i;
  if(x % 3 == 0){
  cout<<" "<<i;
  }
  else{
   while(1){
   if(x % 10 == 3){
   cout<<" "<<i;
   break;
  }
  x /= 10;
  if(x == 0) break;
  }
 }
 if(++i > n) break;
 
 }
 cout<<endl;

 return 0;
}


Measured memory_bytes: 3100
using System;

namespace MyProgram{
    class AtCoder{
        static void Main(string[] args){
            int N = int.Parse(Console.ReadLine());
            long[] H = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
            int sum_1=0;
            int sum_2=0;
            for(var i=0;i<N-1;i++){
                if(H[i]>=H[i+1]){
                    sum_1 ++;
                }else{
                    if(sum_1>sum_2)sum_2 = sum_1;
                    sum_1=0;
                }
            }
            if(sum_1>sum_2)sum_2 = sum_1;
            Console.WriteLine(sum_2);
        }
    }
}

Measured memory_bytes: 25308
parseInt(x) = parse(Int,x)

function main()
  N = parseInt(readline())
  B = map(parseInt,split(readline()))
  A = zeros(Int,N)
  A[1] = B[1]
  A[N] = B[N-1]
  for i = 2:(N-1)
    A[i] = minimum([B[i],B[i-1]])
  end
  s = sum(A)
  println(s)
end

main()

Measured memory_bytes: 164968
def gai(a,b,c,d):
    S = a*d - b*c
    return(S)
while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp  = map(float,input().split())
        if gai(x1 - x2,y1 - y2,x1 - xp,y1 - yp) < 0 and gai(x2 - x3,y2 - y3,x2 - xp,y2 - yp) < 0 and gai(x3 - x1,y3 - y1,x3 - xp,y3 - yp) < 0:
            print("YES")
        elif gai(x1 - x2,y1 - y2,x1 - xp,y1 - yp) > 0 and gai(x2 - x3,y2 - y3,x2 - xp,y2 - yp) > 0 and gai(x3 - x1,y3 - y1,x3 - xp,y3 - yp) > 0:
            print("YES")
        else:
            print("NO")
    except EOFError:
        break

Measured memory_bytes: 7488
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

N, *A = map(int, read().split())

cnt = 0

for i in range(1, N+1):
    if i % 2 == 1 and A[i-1] % 2 == 1:
        cnt += 1

print(cnt)


Measured memory_bytes: 9100
// UNNECESSARY
// #include <chrono>//std::chrono::/system_clock/steady_clock/high_resolution_clock/duration
// #include <cstdio>//printf/scanf/fopen/fclose/fprintf/fscanf/snprintf/putc/puts/getc/gets
// #include <fstream>//ifstream/ofstream

// DATA STRUCTURES
#include <array>
#include <bitset>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <valarray>
#include <vector>

// MISCELLANEOUS
#include <algorithm>//min/max/sort(rand-access it)/merge
#include <cassert>
#include <climits>//INT_MAX/INT_MIN/ULLONG_MAX
#include <cmath>//fmin/fmax/fabs/sin(h)/cos(h)/tan(h)/exp/log/pow/sqrt/cbrt/ceil/floor/round/trunc
#include <cstdlib>//abs/atof/atoi/atol/atoll/strtod/strtof/..., srand/rand, calloc/malloc, exit, qsort
#include <iomanip>//setfill/setw/setprecision/fixed/scientific
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific
#include <iterator>
#include <limits>//numeric_limits<type>::max/min/lowest/epsilon/infinity/quiet_NaN/signaling_NaN
#include <new>
#include <string>//stoi/stol/stoul/stoll/stoull/stof/stod/stold/to_string/getline
#include <utility>//pair

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

#ifndef REPST
#define REPST(i,n) for (size_t i = 0; i < n; ++i)
#endif

#ifndef READ
#define READ(x) std::cin >> x
#endif

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> plli;
typedef std::pair<ull, int> puli;
typedef std::pair<double, int> pdi;
typedef std::pair<ll, ll> pllll;
typedef std::pair<ull, ull> pulul;
typedef std::pair<double, double> pdd;
typedef std::tuple<int, int, int> ti3;
typedef std::tuple<int, int, int, int> ti4;

const bool debug = true;

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

using namespace std;

int main(void)
{
    size_t n;
    cin >> n;
    int a, prev;
    int stat = 0;
    ui count = 0;
    cin >> a;
    REP(i,n-1) {
        prev = a;
        READ(a);
        switch (stat) {
            case 0: {
                if (a > prev) {
                    stat = 1;
                } else if (a < prev) {
                    stat = -1;
                }
                break;
            }
            case 1: {
                if (a < prev) {
                    ++count;
                    stat = 0;
                }
                break;
            }
            case -1: {
                if (a > prev) {
                    ++count;
                    stat = 0;
                }
                break;
            }
            default: { break; }
        }
    }
    cout << (++count) << '\n';

    return 0;
}


Measured memory_bytes: 256
main=readLn>>=print.([1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]!!).subtract 1

Measured memory_bytes: 3860
#include <stdio.h>

int main()
{
	int i, N, t[101], v[101];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(t[i]));
	for (i = 1; i <= N; i++) scanf("%d", &(v[i]));

	int j, k;
	double dp[101][102] = {}, tmp;
	for (i = 0; i <= 100; i++) {
		for (j = 0; j <= 101; j++) dp[i][j] = -1.0;
	}
	for (i = 1, dp[0][0] = 0.0; i <= N; i++) {
		for (j = 0; j <= v[i] && dp[i-1][j] >= 0.0; j++) {
			for (k = 0; j - k > t[i]; k++);
			for (; k <= v[i] && k - j <= t[i]; k++) {
				if (t[i] >= v[i] * 2 - j - k) tmp = (double)(v[i] + j) * (v[i] - j) / 2.0 + (double)(v[i] + k) * (v[i] - k) / 2.0 + (double)v[i] * (t[i] - v[i] * 2 + j + k);
				else tmp = ((double)(t[i] - j + k) / 2.0 + j * 2.0) * (double)(t[i] - j + k) / 4.0 + ((double)(t[i] - k + j) / 2.0 + k * 2) * (double)(t[i] - k + j) / 4.0;
				if (dp[i-1][j] + tmp > dp[i][k]) dp[i][k] = dp[i-1][j] + tmp;
			}
		}
	}

	printf("%f\n", dp[N][0]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1788
#include <iostream>
using namespace std;
string s;
int cnt,MAX;
int main(void){
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C'){
            cnt++;
        }
        else cnt=0;
        MAX=max(MAX,cnt);
    }
    cout<<MAX<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
typedef pair<ll,ll> Pair;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }

const ll INF=99999999999999;
const ll MOD=1000000007;
 
int main() {
  ll n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  s += "2";
  vl a;
  ll num = 1;
  ll cnt = 0;
  if(s[0] == '0') a.push_back(0);
  rep(i,n){
    if(s[i] == s[i+1]) num++;
    if(s[i] != s[i+1]){
      a.push_back(num);
      num = 1;
  }
  }
  if(s[n-1] == '0') a.push_back(0);
  vl sum(a.size()+1,0);
  for(ll i=0; i<a.size(); i++) sum[i+1] = sum[i] + a[i];
  
  ll ans = 0;
  for(ll i=0; i<sum.size(); i += 2){
    ll j = i+2*k + 1;
    if(j>=sum.size()) j=sum.size()-1;
    ans = max(ans,sum[j]-sum[i]);
  }
  
  cout << ans;
    

 return 0;
}

Measured memory_bytes: 2164
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] nm = reader.readLine().split(" ");
        int n = Integer.parseInt(nm[0]);
        int m = Integer.parseInt(nm[1]);
        int[] k = new int[m];
        int[][] s = new int[m][];
        for (int i = 0; i < m; i++) {
            String[] arr = reader.readLine().split(" ");
            k[i] = Integer.parseInt(arr[0]);
            s[i] = new int[k[i]];
            for (int j = 0; j < k[i]; j++) {
                s[i][j] = Integer.parseInt(arr[j + 1]);
            }
        }
        String[] parr = reader.readLine().split(" ");
        int[] p = new int[m];
        for (int i = 0; i < m; i++) {
            p[i] = Integer.parseInt(parr[i]);
        }
        int maxState = 1 << n;
        Set<Integer> set = new HashSet<>(maxState);
        for (int i = 0; i < maxState; i++) {
            set.add(i);
        }
        for (int i = 0; i < m; i++) {
            for (Iterator<Integer> iter = set.iterator(); iter.hasNext(); ) {
                int cur = iter.next();
                int count = 0;
                for (int j = 0; j < k[i]; j++) {
                    int tmp = (cur >> (s[i][j] - 1)) & 1;
                    if (tmp == 1) {
                        count++;
                    }
                }
                if (count % 2 != p[i]) {
                    iter.remove();
                }
            }
        }
        System.out.println(set.size());
    }
}


Measured memory_bytes: 23124
import java.io.BufferedReader;
                    import java.io.FileReader;
                    import java.io.IOException;
                    import java.io.InputStream;
                    import java.io.InputStreamReader;
                    import java.io.PrintWriter;
                    import java.math.BigInteger;
                    import java.util.*;
                        public class Main {

                    
                    	    static PrintWriter pw = new PrintWriter(System.out);
                    	    static int[][] dp;
                    	    public static int f(String a,String b,int i,int j) {
                    	    	if(i==a.length())return 0;
                    	    	if(j==b.length())return 0;
                    	    	if(dp[i][j]!=-1)return dp[i][j];
                    	    	if(a.charAt(i)==b.charAt(j))
                    	    		return dp[i][j]=1+f(a,b,i+1,j+1);
                    	    	return dp[i][j] = Math.max(f(a,b,i+1,j),f(a,b,i,j+1));
                    	    }
                    	    public static void f2(String a,String b,int i,int j) {
                    	    	if(i==a.length())return ;
                    	    	if(j==b.length())return ;
                    	    	if(a.charAt(i)==b.charAt(j)) {
                    	    		pw.print(a.charAt(i));
                    	    		f2(a,b,i+1,j+1);
                    	    		return;
                    	    	}
                    	    	if(dp[i][j+1]>=dp[i+1][j]) {
                    	    		f2(a,b,i,j+1);
                    	    		return;
                    	    	}else {
                    	    		f2(a,b,i+1,j);
                    	    		return;
                    	    	}
                    	    }
                    	   // static long[][] C = binomialCoeff(1000, 5);
                    	    
                    	public static void main(String[] args) throws IOException{
                    		Scanner sc = new Scanner(System.in);
                    		String a = sc.next();
                    		String b = sc.next();
                    		dp = new int[3004][3004];
                    		for(int i=0;i<dp.length;i++)
                    			for(int j=0;j<dp[i].length;j++)
                    				dp[i][j] = -1;
                    		f(a,b,0,0);
                    		f2(a,b,0,0);
                    		pw.flush();
                    		pw.close();
                    	}
                    }

Measured memory_bytes: 82276
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N;
  N = S.size();
  bool D;
  D = true;
  for ( int i = 0 ; i <(N-1)/2 ; i++ ) {
    if (S[i] != S[N-i-1] || S[i] != S[(N-3)/2-i]) {
      D = false;
    };
  }
  int j = 1;
  for ( int i = (N+1)/2 ; i<N ; i++ ) {
    if (S[i] != S[N-j]) {
      D = false;
    }
    j++;
  }
  if (D) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

using namespace std;

void Main() {
    int N;
    cin >> N;
    vector<int> X(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> X[i];
    }
    vector<int> Y = X;
    sort(Y.begin(), Y.end());
    map<int, int> medians;
    for (int i = 0; i < N; ++i) {
        if (medians.count(Y[i]) > 0) {
            continue;
        }
        int n = 0;
        if (i < N / 2) {
            n = Y[N / 2];
        }
        else {
            n = Y[N / 2 - 1];
        }
        medians.insert(make_pair(Y[i], n));
    }

    for (int i = 0; i < N; ++i) {
        cout << medians[X[i]] << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 13908
#include<bits/stdc++.h>
using namespace std;
vector<string>v;
int main(){
 int n , l ;
 cin >> n >> l;
 for(int i=1;i<=n;i++){
    string a;
    cin >> a;
    v.push_back(a);
 }
 sort(v.begin(),v.end());
 for(int i=0;i<v.size();i++){
  cout << v[i];
 } 	  
 cout << endl;
 return 0;	
}


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

using namespace std;

int main(void)
{
  int N;
  long A[200000];

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  std::sort(A, A + N);

  for (int i = 0; i < N - 1; i++) {
    if (A[i] == A[i + 1]) {
      cout << "NO";
      return 0;
    }
  }

  cout << "YES";

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int n;
char s[2000];
int dp[2000][8];
int main(){
    cin >> n >> s;

    REP(i,n){
        if(s[i] == 'J')
            s[i] = 1;
        else if(s[i] == 'O')
            s[i] = 2;
        else
            s[i] = 4;
    }

    REP(i,8)
        dp[0][i] = 0;
    dp[0][1] = 1;

    FOR(i,1,n + 1){
        REP(j,8){
            dp[i][j] = 0;
            REP(k,8){
                if((j & s[i - 1]) != 0 && (j & k) != 0){
                    dp[i][j] += dp[i - 1][k];
                    dp[i][j] %= 10007;
                }
            }
        }
    }
    int ans = 0;
    REP(i,8){
        ans += dp[n][i];
        ans %= 10007;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int h1,h2,m1,m2,k;
    int start,end;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    start = h1*60 + m1;
    end = h2 * 60 + m2 - k;
    cout << end - start << endl;
}


Measured memory_bytes: 3636
def solve():
  def gcd(x, y):
   while(y): 
       x, y = y, x % y 
   return x

  N = int(input().strip())
  o = 0
  for i in map(int, input().split()):
    o = gcd(i,o)
  print(o)

if __name__=="__main__":
  solve()


Measured memory_bytes: 62832
CARD_NUM = 13
spades = [0] * CARD_NUM
hearts = [0] * CARD_NUM
clubs = [0] * CARD_NUM
diamonds = [0] * CARD_NUM

n = int(input())
for i in range(n):
	pair = list(map(str, input().split()))
	suit = pair[0]
	rank = int(pair[1])
	if suit == 'S': spades[rank - 1] = 1
	if suit == 'H': hearts[rank - 1] = 1
	if suit == 'C': clubs[rank - 1] = 1
	if suit == 'D': diamonds[rank - 1] = 1

for i in range(CARD_NUM):
	if spades[i] == 0: print('S ' + str(i + 1))
for i in range(CARD_NUM):
	if hearts[i] == 0: print('H ' + str(i + 1))
for i in range(CARD_NUM):
	if clubs[i] == 0: print('C ' + str(i + 1))
for i in range(CARD_NUM):
	if diamonds[i] == 0: print('D ' + str(i + 1))



Measured memory_bytes: 5612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)


int main(){
   int n;
   cin >> n;
   vector<ll> v(n);
   ll ans = 0LL;
   rep(i,n){
      cin >> v[i];
      if (i == 0) ans+=abs(v[i]);
      else if (i == n-1) ans += abs(v[i]) + abs(v[i] - v[i-1]);
      else ans += abs(v[i] - v[i-1]);
   }
   //cout << ans << endl;
   for (int i = 0;i < n;i++){
      int tmp = ans;
      if (i == 0) {
         tmp -= abs(v[i]) + abs(v[i+1]-v[i]);
         tmp += abs(v[i+1]);
      }
      else if (i == n-1) {
         tmp -= abs(v[i]) + abs(v[i] - v[i-1]);
         tmp += abs(v[i-1]);
      }
      else {
         tmp -= abs(v[i] - v[i-1]) + abs(v[i+1]- v[i]);
         tmp += abs(v[i+1]-v[i-1]);
      }
      cout << tmp << endl;
   }

   return 0;
}



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

int main() {
  
  int a, b, c; cin >> a >> b >> c; int ans = 0;
  
  for (int i = a; i <= b; i++) {
    if (c % i == 0) ans++;
  }
  
  cout << ans << endl;
  
}


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

using namespace std;

int main(){
    int n, a;
    cin >>n;
    bool ok = true;
    for(int i=0;i<n;i++){
        cin >>a;
        if(a%2==0){
            if(a%3 && a%5){
                ok = false;
            }
        }
    }
    cout <<(ok?"APPROVED":"DENIED")<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define min(a,b) (a<b?a:b)
#define ll long long
//#define file
using namespace std;

int p[17],pre[18],nxt[18],n,i,j,k,l,L,st;
ll a[18],ans,sum,sum2,s;

void dg(int t,int b,int B,ll sum,ll sum2)
{
	int St,i;
	if (sum+sum2>=ans) return;
	
	if (t>n)
	{
		if (st>n) {ans=sum;return;}
		if (B)
		dg(st,B,0,sum,sum2);
		return;
	}
	
	dg(nxt[t],b,B,sum,sum2);
	if (b&p[t])
	{
		B|=p[pre[t]]|p[nxt[t]];
		if (t==st && nxt[t]>n) sum2-=a[t]*2;
		else
		if (t!=st && nxt[t]<=n) sum2+=a[t]*2;
		if (t==st) sum+=a[t],St=st,st=nxt[st]; else St=st;
		if (nxt[t]>n) sum+=a[t];
		
		a[pre[t]]+=a[t];a[nxt[t]]+=a[t];
		nxt[pre[t]]=nxt[t];pre[nxt[t]]=pre[t];
		dg(nxt[nxt[t]],b,B,sum,sum2);
		nxt[pre[t]]=t;pre[nxt[t]]=t;
		a[pre[t]]-=a[t];a[nxt[t]]-=a[t];
		
		st=St;
	}
}

int main()
{
	#ifdef file
	freopen("agc035d.in","r",stdin);
	#endif
	
	scanf("%d",&n);scanf("%lld",&sum);n-=2;st=1;
	fo(i,1,n) scanf("%lld",&a[i]),sum2+=a[i],p[i]=1<<(i-1),nxt[i]=i+1,pre[i]=i-1;
	L=p[n]*2-1;nxt[n+1]=n+1,pre[n+1]=n;sum2*=2;
	scanf("%d",&j),sum+=j;
	
	if (n<=0) {printf("%lld\n",sum);return 0;}
	
	ans=9223372036854775807ll;
	dg(1,L,0,sum,sum2);
	
	printf("%lld\n",ans);
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}

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

public class Main {
  private static void execute(ContestReader reader, PrintWriter out) {
    out.println(reader.next().indexOf("9") >= 0 ? "Yes" : "No");
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 21204
#include <string>
#include <iostream>

using namespace std;
string s;
int cnt[26];
int main() {
  cin >> s;
  for(char c : s){
    cnt[c - 'a']++;
  }
  bool ok = true;
  for(int o : cnt) {
	if(o >= 2) ok = false;
  }
  cout << (ok ? "yes" : "no") << endl;
}


Measured memory_bytes: 256
object Main extends App {
  import scala.io.StdIn._
  val Array(n, a, b, c, d) = readLine.trim.split(' ').map(_.toInt)
  val buyX = (n.toDouble / a).ceil.toInt * b
  val buyY = (n.toDouble / c).ceil.toInt * d
  println(List(buyX, buyY).min)
}


Measured memory_bytes: 44144
#include <iostream>

using namespace std;

int main() {
    long long int N, A, B;
    cin >> N >> A >> B;
    
    long long int ans=A+B*(N-1)-(A*(N-1)+B)+1;
    if(ans<0) {
        cout << 0 << endl;
    } else {
        cout << ans << endl;
    }



    return 0;
    
}

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

#define range(i, l, r) for (int i = (int)l; i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = ((int)(r) - 1); i >= (int)l; --(i))

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define rwhole(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using int32 = int;
using int64 = long long;

const int mod     = 1e9 + 7;
const int32 inf   = 1001001001;
const int64 infll = 1001001001001001001ll;

const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const string YES = "YES", NO = "NO", Yes = "Yes", No = "No", yes = "yes", no = "no";

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(16); cerr << fixed << setprecision(16); } } iosetup;

template <typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solver() {
  int A = input(), B = input();

  cout << max({A + B, A - B, A * B}) << endl;
}

signed main(int argc, char *argv[]) {
  solver();
}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

vector<vector<ll>> comb(ll n) {
  vector<vector<ll>> v(n+1, vector<ll>(n+1, 0));
  for (ll i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (ll j = 1; j < v.size(); j++) {
    for (ll k = 1; k < j; k++) {
      v[j][k] = (v[j-1][k-1] + v[j-1][k]);
    }
  }
  return v; // v[n][r];
}

int main() {
  ll n, p;
  cin >> n >> p;

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


  vector<vector<ll>> cb = comb(n);

  ll ki = 0;
  ll gu = 0;
  for (ll i = 0; i < n; ++i) {
    if (a[i]%2 == 0) gu++;
    else ki++;
  }

  ll ans = 0;
  if (p == 0) {
    for (ll i = 0; i <= ki; i+=2) {
      ll m = cb[ki][i];
      ll n = 0;
      for (ll j = 0; j <= gu; ++j) {
        n = cb[gu][j];
        ans += m*n;
      }
    }
  } else {
    for (ll i = 1; i <= ki; i+=2) {
      ll m = cb[ki][i];
      ll n = 0;
      for (ll j = 0; j <= gu; ++j) {
        n = cb[gu][j];
        ans += m*n;
      }
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
n, c, k = list(map(int, input().split(' ')))

ts = []
for i in range(n):
    ts.append(int(input()))

tss = sorted(ts, reverse=True)

base = tss[0]
count = 0
limit = 0
for i in range(n):
    limit += 1
    if base - tss[i] > k or limit > c:
        count += 1
        base = tss[i]
        limit = 1
count += 1
print(count)


Measured memory_bytes: 8280
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int dp[2*112345];
int main() {
  string A;
  cin >> A;
  vector<vint> pos(26);
  repeat(i,A.length()){
    pos[A[i]-'a'].push_back(i);
  }
  repeat(c,26){
    pos[c].push_back(A.length());
  }
  dp[A.length()-1]=1;
  int flag=0;
  for(int i=A.length()-1;i>=0;i--){
    //debug(bitset<26>(flag));
    dp[i] += dp[i+1];
    flag |= 1<<(A[i]-'a');
    if(flag == (1<<26)-1){
      flag = 0;
      dp[i]++;
    }
  }
  debugArray(dp,A.length()+1);
  string ans="";
  int idx=0;
  while(idx < A.length()){
    //debug(idx);
    //debug(ans);
    repeat(c,26){
      int nidx = *lower_bound(pos[c].begin(),pos[c].end(),idx)+1;
      if(dp[idx] == dp[nidx]+1){
        ans += c+'a';
        idx = nidx;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2180
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>

constexpr int mod=1e9+7;

long long fact(int n) {
  long long res=1;
  for (int i=2; i<=n; ++i)
    res = res * i % mod;

  return res;
}

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

  if (std::abs(N-M) > 1)
    return puts("0"), 0;

  if (N == M) {
    printf("%lld\n", 2LL*fact(N)%mod*fact(M)%mod);
  } else {
    printf("%lld\n", fact(N)*fact(M)%mod);
  }

  return 0;
}


Measured memory_bytes: 128
n = int(input())
n_list = list(map(int, input().split()))
dp = [-1]*n
dp[0] = 0
dp[1] = abs(n_list[1]-n_list[0])

for i in range(2,n):
  dp[i] = min(abs(n_list[i]-n_list[i-1])+dp[i-1], abs(n_list[i]-n_list[i-2])+dp[i-2])
print(dp[n-1])

Measured memory_bytes: 20608
#pragma GCC optimize("Ofast")
#include <cstring>
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main() {
    ll A, B, C, D, a, c;
    int flag = 0;

    cin >> A >> B >> C >> D;

    while(flag == 0) {
        C -= B;
        if(C <= 0) {
            cout << "Yes";
            flag = 1;
        } else {
            A -= D;
            if(A <= 0) {
                cout << "No";
                flag = 1;
            }
        }
        
    }
    
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

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

const int inf=100000000;


int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int r=0;
    int g=0;
    int b=0;
    int n=0;
    cin>>r>>g>>b>>n;
    int cnt=0;
    for(int i=0; i<=n/r; i++)
    {
        for(int j=0; j<=n/g; j++)
        {
            if(n-r*i-g*j>=0)
            {
              if((n-r*i-g*j)%b==0||(n-r*i-g*j)==0)
              {
                  ++cnt;
              }
            }
        }
    }


    cout<<cnt<<endl;
}

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

namespace contest_Csharp
{
    class Program
    {
        

        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            
            var vals = Console.ReadLine().Split(' ').
                Select(x => long.Parse(x)).ToList();
            var N = vals[0];

            var s = new List<string>();
            for (int i = 0; i < N; i++)
            {
                s.Add(Console.ReadLine());
            }


            Console.WriteLine("AC x "+ s.Count(x=> x=="AC"));
            Console.WriteLine("WA x " + s.Count(x => x == "WA"));
            Console.WriteLine("TLE x " + s.Count(x => x == "TLE"));
            Console.WriteLine("RE x " + s.Count(x => x == "RE"));

            //Console.WriteLine((1000-N%1000)%1000);
            Console.Out.Flush();
        }
        




    }
}




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

#define pb(a) push_back(a)
#define INF 1145141919810364364
#define mod 1000000007

typedef long long ll;

const int dsize = 1e5+5;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
vector<ll> prime;

ll inv[dsize],fac[dsize];

template <class T = ll> T in(){T x;cin >> x;return (x);}
inline ll GCD(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;}
inline ll LCM(ll a,ll b){return a*b/GCD(a,b);}
inline ll POW(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%mod;}a=a*a%mod;b>>=1;}return c;}
inline void _nCr(){fac[0]=1;for(int i=1;i<dsize;i++){fac[i]=fac[i-1]*i%mod;}for(int i=0;i<dsize;i++){inv[i]=POW(fac[i],mod-2);}}
inline ll nCr(ll n,ll r){return (fac[n]*inv[r]%mod)*inv[n-r]%mod;}
inline void PRI(ll n){bool a[n+1];for(int i=0;i<n+1;i++){a[i]=1;}for(int i=2;i<n+1;i++){if(a[i]){prime.pb(i);ll b=i;while(b<=n){a[b]=0;b+=i;}}}}

int main() {
	int n=in(),m=in();
	int cnt[n];
	bool red[n];
	for (int i=0;i<n;i++) {
		cnt[i]=1;
		red[i]=false;
	}
	red[0]=true;
	for (int i=0;i<m;i++) {
		int x=in(),y=in();
		cnt[x-1]--;
		cnt[y-1]++;
		if (red[x-1]) {
			if (!cnt[x-1]) red[x-1]=0;
			red[y-1]=true;
		}
	}
	int ans=0;
	for (int i=0;i<n;i++) {
		if (red[i]) ans++;
	}
	cout << ans <<endl;
}
    

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

//#define int long long
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int a, b, c, s, r;

signed main() {
	cin >> a >> b >> c >> s;
	rept(i,a) rept(j,b) rept(k,c) r += (500*i+100*j+50*k == s);
	cout << r << ln;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int g[5][5];
bool hit[5][5];

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

  for (int i=0; i<3; i++) {
    for (int j=0; j<3; j++) {
      cin>>g[i][j];
    }
  }
  int q; cin>>q;
  while (q--) {
    int x; cin>>x;
    for (int i=0; i<3; i++) {
      for (int j=0; j<3; j++) {
	if (g[i][j] == x) {
	  hit[i][j] = true;
	}
      }
    }
  }

  for (int i=0; i<3; i++) {
    bool ok = true;
    for (int j=0; j<3; j++) {
      ok = ok && hit[i][j];
    }
    if (ok) out("Yes");
  }


  for (int j=0; j<3; j++) {
    bool ok = true;
    for (int i=0; i<3; i++) {    
      ok = ok && hit[i][j];
    }
    if (ok) out("Yes");
  }

  if (hit[0][0] && hit[1][1] && hit[2][2]) out("Yes");

  if (hit[2][0] && hit[1][1] && hit[0][2]) out("Yes");

  out("No");  

  return 0;
}
// don't forget to read in the input :^)


Measured memory_bytes: 256