akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

class Main{
  static class Scnr{
    private final InputStream ins;
    private final byte[] buf=new byte[1024];
    private int ptr=0;
    private int buflen=0;
    Scnr(){
      this(System.in);
    }
    Scnr(InputStream ins){
      this.ins=ins;
    }
    private boolean hasNextByte(){
      if(ptr<buflen){
        return true;
      }
      ptr=0;
      try{
        buflen=ins.read(buf);
      }catch(IOException e){
        e.printStackTrace();
      }
      return buflen>0;
    }
    private int readByte(){
      if(hasNextByte()){
        return buf[ptr++];
      }else{
        return -1;
      }
    }
    private static boolean isChar(int c){
      return '!'<=c&&c<='~';//33~126
    }
    public boolean hasNext(){
      while(hasNextByte()&&!isChar(buf[ptr])){
        ptr++;
      }
      return hasNextByte();
    }
    public String next(){
      if(!hasNext()){
        throw new NoSuchElementException();
      }
      StringBuilder sb=new StringBuilder();
      int b=readByte();
      while(isChar(b)){
        sb.appendCodePoint(b);
        b=readByte();
      }
      return sb.toString();
    }
    public long nextLong(){
      if(!hasNext()){
        throw new NoSuchElementException();
      }
      long res=0;
      int b=readByte();
      boolean minus=false;
      if(b=='-'){
        minus=true;
        b=readByte();
      }
      if(b<'0'||'9'<b){
        throw new NumberFormatException();
      }
      while(true){
        if('0'<=b&&b<='9'){
          res*=10;
          res+=b-'0';
        }else if(b==-1||!isChar(b)){
          return minus?-res:res;
        }else{
          throw new NumberFormatException();
        }
        b=readByte();
      }
    }
    public int nextInt(){
      long nl=nextLong();
      if(nl<Integer.MIN_VALUE||Integer.MAX_VALUE<nl){
        throw new NumberFormatException();
      }
      return (int) nl;
    }
  }
  static int n;
  static int m;
  static int q;
  static int[] ary;
  static int[] a;
  static int[] b;
  static int[] c;
  static int[] d;
  public static void main(String[] args){
    Scnr sc=new Scnr();
    n=sc.nextInt();
    m=sc.nextInt();
    q=sc.nextInt();
    a=new int[q];
    b=new int[q];
    c=new int[q];
    d=new int[q];
    for(int i=0;i<q;i++){
      a[i]=sc.nextInt()-1;
      b[i]=sc.nextInt()-1;
      c[i]=sc.nextInt();
      d[i]=sc.nextInt();
    }
    ary=new int[n];
    System.out.println(calc(0));
  }
  static int calc(int p){
    if(p<n){
      int res=0;
      for(ary[p]=(p==0?1:ary[p-1]);ary[p]<=m;ary[p]++){
        res=Math.max(calc(p+1),res);
      }
      return res;
    }else{
      int res=0;
      for(int i=0;i<q;i++){
        if(ary[b[i]]-ary[a[i]]==c[i]){
          res=res+d[i];
        }
      }
      return res;
    }
  }
}


Measured memory_bytes: 33748
#include<iostream>
using namespace std;
int min(int a, int b)
{
	return (a < b ? a : b);
}
int main()
{
	int a, b, k;
	cin >> a >> b >> k;
	int min_num = min(a, b);
	int big = 1;
	int ans = 1;
	for (int i = min_num; i >= 1; i--)
	{
		if (a%i == 0 && b%i == 0)
		{
			if (big == k)
			{
				ans = i;
				break;
			}
			else
			{
				big++;
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define f first
#define s second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll INF = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 300500;
const int inf = (int)1e9;

int n;
string s, t;

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);

	cout << setprecision(10) << fixed;
	
	cin >> n >> s >> t;

	for(int i = n; i <= n + n; ++i){
		string x = s;
		x += t.substr(n + n - i, i - n);
		if(x.substr(x.size() - n, n) == t){
			cout << i;
			return 0;
		}
	}

	cout << n + n;
	
	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define CHMIN(a,b) (a)=min((a),(b))
typedef long long ll;
typedef vector<int> vi;

char s[125252];
int n;

struct PMA{
  PMA* next[27];
  bool goal;
  PMA(){
    REP(i,27)next[i] = NULL;
    goal = false;
  }
};

#define FAIL 26
PMA *build(vector<string> pat){
  PMA *root = new PMA();
  PMA *now;
  root->next[FAIL] = root;
  for(string s : pat){
    now = root;
    REP(i,s.size()){
      int id = s[i]-'a';
      if(now->next[id]==NULL){
        now->next[id] = new PMA();
      }
      now = now->next[id];
    }
    now->goal = true;
  }
  queue<PMA*> Q;
  REP(i,26){
    if(root->next[i]==NULL){
      root->next[i] = root;
    }else{
      root->next[i]->next[FAIL] = root;
      Q.push(root->next[i]);
    }
  }
  while(!Q.empty()){
    now = Q.front(); Q.pop();
    REP(i,26){
      if(now->next[i] != NULL){
        PMA *nxt = now->next[FAIL];
        // nxt->next[FAIL] = root;
        while(nxt->next[i] == NULL){
          nxt = nxt->next[FAIL];
        }
        now->next[i]->next[FAIL] = nxt->next[i];
        now->next[i]->goal |= nxt->next[i]->goal;
        Q.push(now->next[i]);
      }
    }
  }
  return root;
}

int main(){
  scanf("%s",s);
  scanf("%d",&n);
  vector<string> pat;
  REP(i,n){
    string s;
    cin>>s;
    pat.push_back(s);
  }
  PMA *root = build(pat);
  int ans = 0;
  PMA *now = root;
  int len = strlen(s);
  REP(i,len){
    int id = s[i]-'a';
    while(now->next[id]==NULL)now = now->next[FAIL];
    now = now->next[id];
    if(now->goal){
      ans++;
      now = root;
    }
  }
  printf("%d\n",ans);
  return 0;
}



Measured memory_bytes: 23004
import sys
from collections import Counter
input=sys.stdin.readline
n,k,q=map(int,input().split())
a=[int(input()) for _ in range(q)]
cnt=Counter(a)

for i in range(1,n+1):
    if k+cnt[i]>q:
        print("Yes")
    else:
        print("No")


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

signed main(void){
    int A,B,C;
    cin >> A >> B >> C;
    if(A+B+C<=21){
        cout << "win" << endl;
    }else{
        cout << "bust" << endl;
    }
    return 0;
}



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

int S(int n);

int main(){
  string out;
  int n;
  cin >> n;
  if(n%S(n)==0) out = "Yes";
  else out = "No";
  cout << out << endl;

  return 0;
}

int S(int n){
  string s = to_string(n);
  int sum = 0;
  for(auto c:s){
    sum+= c-'0';
  }
  return sum;
}

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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 2e18
#define ROOT 1
#define M 1000000007
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

int gcd(int a, int b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}

int calc(int n, int a, int b, int c, int d) {
  if (n == 0) return 0;
  int cnta = 0;
  while (n % 2 == 0) {
    cnta += a;
    n /= 2;
  }
  int cntb = 0;
  while (n % 3 == 0) {
    cntb += b;
    n /= 3;
  }
  int cntc = 0;
  while (n % 5 == 0) {
    cntc += c;
    n /= 5;
  }
  int ans = cnta + cntb + cntc + n * d;
  return ans;
}

map<int, int> dp;
vector<int> ku;

int solve(int n, int a, int b, int c, int d) {
  if (n == 0) return 0;
  if (dp.count(n)) return dp[n];
  int &ans = dp[n];
  ans = INF;

  if (n < INF / d) ans = min(ans, n * d);

  for (int x : ku) {
    int fl = (n / x);
    int ce = ((n + x - 1) / x);
    int cst;
    if (x == 2)
      cst = a;
    else if (x == 3)
      cst = b;
    else
      cst = c;
    ans = min(ans, solve(fl, a, b, c, d) + cst + abs(fl * x - n) * d);
    ans = min(ans, solve(ce, a, b, c, d) + cst + abs(ce * x - n) * d);
  }
  return ans;
}

void solution() {
  int t;
  cin >> t;
  while (t--) {
    int n, a, b, c, d;
    dp.clear();
    ku.pb(3);
    ku.pb(5);
    ku.pb(2);
    cin >> n >> a >> b >> c >> d;
    cout << solve(n, a, b, c, d) << endl;
  }
}

int32_t main() {
  DESYNC;
  solution();
}


Measured memory_bytes: 4400
import math

x = []
sum = 0
min = 0
for i in range(5):
    x = input()
    y = x % 10
    if y == 0:
        sum += x
    else:
        sum += x + 10 - y
        if min == 0:
            min = y
        elif y < min:
            min = y

if min == 0:
    print(sum)
else:
    print(sum - 10 + min)

Measured memory_bytes: 2568
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {

            var A = cin.ReadInt;
            var B = cin.ReadInt;
            var C = cin.ReadInt;
            var K = cin.ReadInt;

            var maxNum = Max(A, Max(B, C));
            var bigger = maxNum;
            for (int i = 0; i < K; i++){
                bigger = bigger * 2;
            }

            WriteLine(bigger + A + B + C - maxNum);

        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
int  N;
long long h,n,w;
int main()
{
     scanf("%d",&N);
     int i,j,k;
     for(h=1;h<=3500;h++)
     {  if(4*h<=N) continue;
        for(n=1;n<=3500;n++)
        {
            if((long long)N*(h+n)>=(long long)4*n*h) continue;
            if((long long)N*(n+h+h*n)<(long long)4*n*h) break;
            long long fenz=4*n*h-N*n-h*N;
             long long fenm=N*h*n;
             if(fenz>0&&fenm>0&&fenm%fenz==0)
             {
                printf("%lld %lld% lld\n",h,n,fenm/fenz);return 0;
             }
        }
     }
}


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

using namespace std;

int main()
{
   int n;
   double Ysum = 0;

   cin >> n;
   double *x = new double[n];
   string *u = new string[n];

   for(int i=0;i<n;i++){
      cin >> x[i];
      cin >> u[i];
   }

   for(int i=0;i<n;i++){
      if(u[i] == "JPY"){
         Ysum += x[i];
      }else if(u[i] == "BTC"){
         Ysum += x[i] * 380000.0;
      }
   }

   cout << Ysum << endl;

   return 0;
}


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

int gcd(int a, int b) {
	if (a % b == 0)
		return b;
	return gcd(b, a % b);
}
int main() {
	int n,ans;
	cin >> n>>ans;

	for (int i = 0,a; i < n-1; i++) {
		cin>>a;
		ans=gcd(ans,a);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
void COME_LET_THE_GAMES_BEGIN(){cout << setprecision(20);}
void vin(vector<ll>*a,int N){for (; N; N--){ll x;cin >> x;(*a).push_back(x);}}
void vin(vector<tuple<ll, ll, ll>>*a,int N){for(;N;N--){tuple<ll, ll, ll>x;cin>>get<0>(x)>>get<1>(x)>>get<2>(x);(*a).push_back(x);}}
void output(bool f){if(f){puts("Yes");}else{puts("No");}}
void output(ll a){printf("%lld\n", a);}
string S;
ll A, B, M;
vector<ll> a, b;
vector<tuple<ll, ll, ll>> c;
void input() {
    cin >> A >> B >> M;
    vin(&a, A);
    vin(&b, B);
    vin(&c, M);
}
ll solve() {
    ll ans = *min_element(a.begin(), a.end())+*min_element(a.begin(), a.end());
    for (auto g: c) {
        ll x = get<0>(g);
        ll y = get<1>(g);
        ll c = get<2>(g);
        x--, y--;
        ans = min(ans, a[x]+b[y]-c);
    }
    return ans;
}
int main () {
    COME_LET_THE_GAMES_BEGIN();
    input();
    output(solve());
}

Measured memory_bytes: 7152
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
#include <iomanip>
#include <queue>
#include <cmath>
#include <math.h>
#include <map>
#include <string>
using namespace std;
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; }
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;
#define min(a, b) ((a) < (b) ? (a) : (b))


//struct moji {
//    int 
//    string name;
//};

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


    long long N;
    cin >> N;
    vector<string> S(N);
    for (long long i = 0; i < N; i++) {
        cin >> S.at(i);
    }
    sort(S.begin(), S.end());
    typedef pair<string, long long> pair;
    vector<pair> res;
    string tmp = S.at(0);
    long long tmpCount = 0;
    for (long long i = 0; i < N; i++) {
        if (tmp != S.at(i)) {
            res.push_back(make_pair(tmp, tmpCount));
            tmp = S.at(i);
            tmpCount = 1;
        }
        else {
            ++tmpCount;
        }
    }
    res.push_back(make_pair(tmp, tmpCount));

    sort(res.begin(), res.end(),
        [](const pair& x, const pair& y) {return x.second > y.second; });
    long long maxCount = res[0].second;
    vector<string> test;
    for (auto x : res) {
        if (x.second < maxCount) {
            break;
        }
        test.push_back(x.first);
    }
    sort(test.begin(), test.end());
    for ( long long i =  0; i  < test.size(); ++i) {
        cout << test.at(i) << endl;
    }

 	return 0;
}


Measured memory_bytes: 26088
import collections

n = int(input())
data = list(map(int, input().split()))
c = collections.Counter(data)

# 合計値
sum = 0
for key in c.keys():
  sum += int( c[key] * (c[key]-1) / 2 )

# print("sum:", sum)

for i in range(n):
  out = sum
  out -= int( c[data[i]] * (c[data[i]]-1) / 2 )
  # print("-out:", out)
  out += int( (c[data[i]]-1) * (c[data[i]]-2) / 2)
  # print("+out:", out)
  print(out)


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

int n, A[50];

bool solve(int i, int m) {
  if(m == 0)return true;
  if(i >= n) return false;
  bool res = solve(i + 1, m) || solve(i + 1, m - A[i]);
  return res;
}

int main() {
  cin >> n;
  int q, M;
  rep(i, n) cin >> A[i];
  cin >> q;
  rep(i, q){
    cin >> M;
    if(solve(0, M)) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long N){
    std::string ns = std::to_string(N);
    int sum = 0;
    for (auto c: ns) {
        sum += c - '0';
    }
    if (N % sum == 0) cout << YES << endl; else cout << NO << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3724
def main():
    length, num = map(int, input().split())
    a = list(map(int, input().split()))
    max_dis = 0 
    first_h = a[0]
    prev_h = a[0]
    for h in a[1:]:
        dis = h - prev_h
        if dis > max_dis:
            max_dis = dis
        prev_h = h

    dis = (length - prev_h) + first_h
    max_dis = max(max_dis, dis)

    print(length - max_dis)


if __name__ == "__main__":
    main()

Measured memory_bytes: 26444
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
int main(){
  	  char a[5];
      scanf("%c%c%c\n",&a[0],&a[1],&a[2]);
      scanf("%c%c%c",&a[3],&a[4],&a[5]);
  	  if (a[0]==a[5]&&a[1]==a[4]&&a[2]==a[3])
  	  	  printf("YES\n");
  	  	  else
  	  	  	  printf("NO\n");


  	  	  	  return 0;

              }


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <queue>

int main() {
    std::vector<int> pazzle(9);
    for (int i = 0; i < 9; i++) {
        std::cin >> pazzle[i];
    }

    

    std::map<std::vector<int>, int> m;
    std::queue <std::pair<std::vector<int>, int> > q;

    m[pazzle] = 0;

    std::vector<int> ans(9);
    for (int i = 0; i < 9; i++) {
        ans[i] = (i + 1) % 9;
    }

    if (pazzle == ans) {
        std::cout << 0 << std::endl;
        return 0;
    }
    m[{1, 2, 3, 4, 5, 6, 7, 8, 0}] = 10000;

    q.push({pazzle, 0});
    while (!q.empty()) {
        pazzle = q.front().first;
        int num = q.front().second;
        q.pop();
        if (m[{1, 2, 3, 4, 5, 6, 7, 8, 0}] != 0 && m[{1, 2, 3, 4, 5, 6, 7, 8, 0}]  < num) break;
        //if (m[pazzle] != 0 && m[pazzle] <= num) continue;

        int space = std::find(pazzle.begin(), pazzle.end(), 0) - pazzle.begin();

        if (space > 2) {
            std::swap(pazzle[space], pazzle[space - 3]);
            if (m.find(pazzle) == m.end() || m[pazzle] > num + 1) {
                m[pazzle] = num + 1;
                q.push({pazzle, num + 1});
            }
            std::swap(pazzle[space], pazzle[space - 3]);
        }
        if (space < 6) {
            std::swap(pazzle[space], pazzle[space + 3]);
            if (m.find(pazzle) == m.end() || m[pazzle] > num + 1) {
                m[pazzle] = num + 1;
                q.push({ pazzle, num + 1 });
            }
            std::swap(pazzle[space], pazzle[space + 3]);
        }
        if (space % 3 != 0) {
            std::swap(pazzle[space], pazzle[space - 1]);
            if (m.find(pazzle) == m.end() || m[pazzle] > num + 1) {
                m[pazzle] = num + 1;
                q.push({ pazzle, num + 1 });
            }
            std::swap(pazzle[space], pazzle[space - 1]);
        }
        if (space % 3 != 2) {
            std::swap(pazzle[space], pazzle[space + 1]);
            if (m.find(pazzle) == m.end() || m[pazzle] > num + 1) {
                m[pazzle] = num + 1;
                q.push({ pazzle, num + 1 });
            }
            std::swap(pazzle[space], pazzle[space + 1]);
        }
    }

    std::cout << m[{1, 2, 3, 4, 5, 6, 7, 8, 0}] << std::endl;
    return 0;
}

Measured memory_bytes: 26260
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using namespace std;

int main() {
	uint64_t n, a, b, s, r, ans;
	cin >> n >> a >> b;
	s = n / (a + b);
	r = n % (a + b);

	ans = a * s;

	if (r >= a) ans += a;
	else ans += r;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
def c_not_so_diverse(N, K, A):
    from collections import Counter
    count = Counter(A)  # 各数字が何回出たかを格納

    if len(count) <= K:
        # 数字の種類がK以下の場合、数字を書き換える必要はない
        return 0
    else:
        count = sorted(count.items(), key=lambda x: x[1], reverse=True)
        count = count[K:]  # 出現頻度がK番目以降の数字だけ残す
        ans = 0
        for l in count:
            ans += l[1]
    return ans

N,K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(c_not_so_diverse(N, K, A))

Measured memory_bytes: 39324
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) begin(v), end(v)
#define allg(v) begin(v), end(v), greater<int>()



int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int a, b;
  cin >> a >> b;
  
  int ans = -1;
  
  rep(i, 1, 10000) {
    int c = i*0.08;
    int d = i*0.10;
    if(c==a and d==b) {
      ans = i;
      break;
    }
  }
    
  cout << ans << "\n";

}


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

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

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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

	int ans = inf;

	for (int i = 0; i <= (x + (a - 1)) / a; ++i) {
		for (int j = 0; j <= (x + (b - 1) / b); ++j) {
			int tmp = 1000 * i + 500 * j;
			if (tmp > x + 1000 || tmp < x) continue;

			ans = min(ans, a * i + b * j);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3124
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m,c = map(int, input().split())
    b = list(map(int, input().split()))
    a = [list(map(int, input().split())) for _ in range(n)]
    res = 0
    for i in range(n):
        total = 0
        for j in range(m):
            total += a[i][j]*b[j]
        if total + c > 0:
            res += 1
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import math

def readInt():
	return int(input())
 
def readInts():
	return list(map(int, input().split()))
 
def readChars():
	return input().split()

N,Y = readInts()
o = Y



for x in range(Y//10000,-1,-1):
	o=Y-x*10000
	#print(Y,x,o)
	for y in range(o//5000,-1,-1):
		#print(y)
		o=Y-x*10000-y*5000
		z=o//1000
		res = x*10000+y*5000+z*1000
		if x+y+z>N or res>Y:
			break
		if res==Y and x+y+z==N:
			print(str(x)+" "+str(y)+" "+str(z))
			exit()

print("-1 -1 -1")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

    ll N, W;
    cin >> N >> W;
    ll w[N], v[N];
    ll total_v = 0ll;
    rep(i, 0, N) {
        cin >> w[i] >> v[i];
        total_v += v[i];
    }
    ll dp[N + 1][total_v + 1];
    rep(i, 0, N + 1) rep(j, 0, total_v + 1) dp[i][j] = INF;
    dp[0][0] = 0ll;

    rep(i, 0, N) rep(j, 0, total_v + 1) {
        if(j - v[i] >= 0) {
            dp[i + 1][j] = min(dp[i + 1][j], min(dp[i][j], dp[i][j - v[i]] + w[i]));
        } else {
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
    }

    ll rsl = 0ll;
    rep(j, 0, total_v + 1) {
        if(dp[N][j] <= W) rsl = j;
    }
    cout << rsl << endl;

}


Measured memory_bytes: 79104
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
	static StringBuilder sb=new StringBuilder();
	public static void main(String[] args) {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String work[]=new String[2];
		int n=0;
		int x=0;

		//入力
		try {
			int count=0;	//結果をカウントする
			while(true){
				//nとmとrの入力
				work=br.readLine().split("\\s+");
				n=Integer.parseInt(work[0]);
				x=Integer.parseInt(work[1]);
				
				if(n==0 && x==0) {break;}	//終了条件
				
				//組み合わせを判定する
				
				for(int i=1; i<=n-2; i++) {
					for(int j=i+1; j<=n-1; j++) {
						for(int k=j+1; k<=n; k++) {
							if(x==(i+j+k)) {
								count++;
							}
						}
					}
				}
				sb.append(count);
				sb.append(String.format("%n", ""));
				count=0;
			}	
			
			//出力
			System.out.print(sb);
			
		}catch(Exception e) {
			e.printStackTrace();
		}
	}
	
}


Measured memory_bytes: 25528
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <stdio.h>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;

vector<vector<ll>> dp(4, vector<ll>(101));
int dpp[101];

int main(){
	string s;
	int k;
	cin >> s >> k;
	int n = s.size();
	dpp[n] = 0; 
	rip(i,n,0){ 
		rip(j,k+1,0){
			dp[j][n-i-1] = dp [j][n-i];
		}
		rip(j,k,0){
			dp[j+1][n-i-1] += dp[j][n-i]*9;
		}
		if(s[i] == '0'){
			dpp[n-i-1] = dpp[n-i];
		}
		else{
			dpp[n-i-1] = dpp[n-i]+1;
			if(dpp[n-i] < k) dp[dpp[n-i]+1][n-i-1] += s[i]-'1';
			if(dpp[n-i] <= k) dp[dpp[n-i]][n-i-1] += 1;
		}
	}
	if(dpp[0]==k) dp[k][0]++;
	//vdeb(dp);
	cout << dp[k][0] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Ll long long
using namespace std;
const int Maxn=1;
int main()
{
    int n,M,a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    M=max(max(a,b),c);
    if((M-a+M-b+M-c)%2==0) printf("%d\n",(3*M-a-b-c)/2);
    else
        printf("%d\n",(3*M-a-b-c)/2+2);
}


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


int main()
{
	string s;  cin>>s;
	
     if(s=="RSR"||s=="SRS"||s=="SSR"||s=="RSS"){
		 cout<<"1"<<endl;
	 }
	 
	 else if(s=="RRS"||s=="SRR"){
		 cout<<"2"<<endl;
	 }
	 
	 else if(s=="SSS"){
		 cout<<0<<endl;
	 }
	 
	 else if(s=="RRR"){
		 cout<<"3"<<endl;
	 }
	 
	
}



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

using namespace std;

#define ll long long 






int main(){
  

  int cnt =0 ;
  int n;
  cin>>n;
  
  vector < int > arr(n);
  
  for(int i =0 ; i < n;i++)
  cin>>arr[i];
  
  do{
	  cnt++;
	  
	  
  }while(next_permutation( arr.begin(),arr.end())) ;
  
  for(int i=0;i<n;i++)
  cin>>arr[i];
  
  
  do{
	
	cnt--;  
	  
  }while( next_permutation(arr.begin(), arr.end()));
  



  cout<<abs(cnt) ; 
  
  return 0 ;
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
  vector<int> x(3);
  rep(i,3){
    cin >> x[i];
  }
  sort(x.begin(),x.end());
  rep(i,3){
    cout << x[i];
    if(i!=2)cout << ' ';
  }
  cout << endl;
}



Measured memory_bytes: 3156
import java.util.*;
import java.util.Scanner;
import java.lang.Math;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] x = new long[N];
        long[] y = new long[N];
        for (int i=0;i<N;i++){
            x[i] = sc.nextLong();
            y[i] = sc.nextLong();
            //System.out.printf("%d %d\n",x[i],y[i]);
        }
        
        double ans = 0;
        for (int d = 0; d<3600;d++){
            long temp = 0;
            long tx = 0;
            long ty = 0;
            for (int i=0;i<N;i++){
                if (x[i]*Math.cos(d*Math.PI/180)+y[i]*Math.sin(d*Math.PI/180)>0){
                    tx += x[i];
                    ty += y[i];
                }
            }
            //System.out.printf("%d %d\n",tx,ty);
            if (ans < Math.sqrt(tx*tx+ty*ty)){
                ans = Math.sqrt(tx*tx+ty*ty);
            }
        }
        System.out.printf("%.12f\n",ans);
    }
}


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

int main(){
    int x;
    vector<int>a;
    while(1){
        cin>>x;
        if(x==0)break;
        a.push_back(x);
    }
    for(int i=0; i<a.size(); ++i){
        cout<<"Case "<<i+1<<": "<<a[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3248
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 200500
queue<int> tp;
int n,m,a,head[N],cnt=1,id[N],fa[N],cur[N],dis[N],is[N],ct1;
vector<int> st2[N];
struct edge{int t,next,v;}ed[N*4];
void adde(int f,int t,int v){ed[++cnt]=(edge){t,head[f],v};head[f]=cnt;ed[++cnt]=(edge){f,head[t],0};head[t]=cnt;}
bool bfs(int s,int t)
{
	memset(dis,-1,sizeof(dis));
	memcpy(cur,head,sizeof(cur));
	dis[s]=0;
	queue<int> st;st.push(s);
	while(!st.empty())
	{
		int a=st.front();st.pop();
		for(int i=head[a];i;i=ed[i].next)
		if(ed[i].v&&dis[ed[i].t]==-1)
		{
			dis[ed[i].t]=dis[a]+1,st.push(ed[i].t);
			if(ed[i].t==t)return 1;
		}
	}
	return 0;
}
int dfs(int u,int t,int f)
{
	if(u==t||!f)return f;
	int as=0,tp;
	for(int &i=cur[u];i;i=ed[i].next)
	if(ed[i].v&&dis[ed[i].t]==dis[u]+1&&(tp=dfs(ed[i].t,t,min(ed[i].v,f))))
	{
		as+=tp,f-=tp;ed[i].v-=tp;ed[i^1].v+=tp;
		if(!f)return as;
	}
	return as;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d",&m);
		for(int j=1;j<=m;j++)scanf("%d",&a),st2[a].push_back(i),adde(a,i+n,1);
	}
	for(int i=1;i<n;i++)adde(2*n,i+1,1),adde(i+n,2*n+1,1);
	int as=0;while(bfs(n*2,n*2+1))
	as+=dfs(n*2,n*2+1,n);
	if(as<n-1){printf("-1\n");return 0;}
	for(int i=1;i<n;i++)
	for(int j=head[i+n];j;j=ed[j].next)if(ed[j].v)id[i]=ed[j].t;
	queue<int> st;
	st.push(1);
	while(!st.empty())
	{
		int a=st.front();st.pop();
		ct1++;
		for(int j=0;j<st2[a].size();j++)if(!fa[id[st2[a][j]]])fa[id[st2[a][j]]]=a,st.push(id[st2[a][j]]);
	}
	if(ct1<n){printf("-1\n");return 0;}
	for(int i=1;i<n;i++)printf("%d %d\n",fa[id[i]],id[i]);
}

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

int main(){
    ll n;
    vector<ll> v(5);
    cin >> n;
    for(int i=0; i<5; i++) cin >> v[i];
    ll mi = *min_element(v.begin(), v.end());
    ll ans = n/mi + (n%mi != 0) + 4;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

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

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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vector<long long>>;
df data(n, vector<long long>(m));
const int MOD = 1e9 + 7;
const long long INF = 1e18;
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

int main() {
  int x;
  cin >> x;
  cout << (x < 1200 ? "ABC" : "ARC") << endl;
}


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

void	InputSortData(int* p_sort_data, int sort_data_num);
void	InsecsionSortData(int* p_sort_data, int sort_data_num);
void	OutputSortData(int* p_sort_data, int sort_data_num);

int main()
{
    int     sort_data_num   = 0;
    int*    p_sort_data     = NULL;

    // 取引回数を入力する
    //cout << "入力データ数を入力してください" << endl;
    cin >> sort_data_num;

    // 取引データを入力する配列を用意する
    p_sort_data = new int[sort_data_num];

    // 取引データを入力する
    InputSortData(p_sort_data, sort_data_num);

    // 挿入ソートする
    InsecsionSortData(p_sort_data, sort_data_num);

    // ソート後のデータを出力する
    OutputSortData(p_sort_data, sort_data_num);

}

void InputSortData(int* p_sort_data, int sort_data_num) {

    // 取引データを入力する
    //cout << "ソートするデータを入力してください" << endl;

    for (int i = 0; i < sort_data_num; i++) {

        cin >> p_sort_data[i];
    }
}

void InsecsionSortData(int* p_sort_data, int sort_data_num) {

    int false_sort = 0;
    int sort_search_pos = 0;

    // 未ソート部分をソートする
    for (int i = 1; i < sort_data_num; i++) {

        // ソートしたデータを出力する
        OutputSortData(p_sort_data, sort_data_num);

        // 未ソート部分の先頭部分を保持する
        false_sort = p_sort_data[i];

        // ソート部分の最後部分を保持する
        sort_search_pos = i - 1;

        while (sort_search_pos >= 0 && p_sort_data[sort_search_pos] > false_sort) {

            p_sort_data[sort_search_pos + 1] = p_sort_data[sort_search_pos];
            sort_search_pos--;
        }

        // 未ソート部分を挿入する
        p_sort_data[sort_search_pos + 1] = false_sort;

    }
}

void	OutputSortData(int* p_sort_data, int sort_data_num) {

    //cout << "ソートしたデータを出力する" << endl;

    for (int i = 0; i < sort_data_num; i++) {
        
        if(i < sort_data_num - 1) {
            cout << p_sort_data[i] << " ";
        }
        else {
            cout << p_sort_data[i] << endl;
        }
    }
}


Measured memory_bytes: 3104
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int N,M,K,A,B,C,ans=0,cnt=0;
string S,T;
vector<int> P,Q;
vector<pair<int,int>> PP;
bool CAN=false;


int main(){
  cin>>N>>K;
  REP(i,N){
    int a;
    cin>>a;
    if(a>=K) ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

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

  ll i = 0, sub = abs(a-b);
  while (i * 2 <= n - 1) {
    ll right = d * (n - 1 - i * 2);
    ll left = c * (n - 1 - i * 2);

    ll ma = abs(c-d) * i;
    if (left - ma <= sub and sub <= right + ma) {
      cout << "YES" << endl;
	  return 0;
    }
    i++;
  }
  cout << "NO" << endl;
}


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

using namespace std ;

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

int a, b , c , d ;
cin >> a >> b >> c >> d; 
int fo = -1 ; 
while ( true ) { 
	c-= b ; 
	if ( c <= 0 ) {
		fo = 1  ; 
		break ; 
	}
	a-= d ;
	if ( a <= 0 ){
		fo = 0 ; 
		break ;
	}
}
if ( fo == 1 ) 
	cout << "Yes" << endl ; 
else
	cout << "No" << endl ; 
}


Measured memory_bytes: 3648
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
  ll a, b, k;
  cin >> a >> b >> k;
  if (a >= k) {
    cout << a - k << " " << b << endl;
  }
  else {
    cout << 0 << " " << max(b - (k-a), 0LL) << endl;
  }
}

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

int main() {
    ll n;
    string c;
    cin >> n >> c;
    ll l = 0, r = n - 1;
    ll ans = 0;
    while (true) {
        while (c[r] == 'W') r--;
        while (c[l] == 'R') l++;
        if (l > r) break;
        c[l] = 'R';
        c[r] = 'W';
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

int n,m;
signed main(){
  cin>>n>>m;
  if(abs(n-m) > 1)cout << 0 << endl;
  else{
    int ans = 0, a = 1, b = 1;
    repd(i,1,n+1)a = (a*i)%MOD;
    repd(i,1,m+1)b = (b*i)%MOD;
    cout << (a*b*(n == m ? 2 : 1))%MOD << endl;
  }
}


Measured memory_bytes: 256
from collections import deque

def solve(N, M, graph):

	indegree = {n: 0 for n in range(1, N + 1)}
	for node in graph:
		for nei in graph[node]:
			indegree[nei] += 1

	queue = deque()
	for node in graph:
		if indegree[node] == 0:
			queue.append(node)

	lengths = [0] * (N + 1)

	while queue:
		node = queue.popleft()

		for nei in graph[node]:
			indegree[nei] -= 1

			if indegree[nei] == 0:
				queue.append(nei)

			lengths[nei] = max(lengths[nei], lengths[node] + 1)

	return max(lengths)


N, M = [int(s) for s in input().split()]
graph = {}
for n in range(1, N + 1):
	graph[n] = []
for _ in range(M):
	x, y = [int(s) for s in input().split()]
	graph[x].append(y)

print(solve(N, M, graph))

Measured memory_bytes: 41824
k,n=map(int,input().split())
a=list(map(int,input().split()))

m=0
for i in range(n-1):
    d=a[i+1]-a[i]
    m=max(d,m)
d_last=a[0]+k-a[n-1]
m=max(d_last,m)

ans=k-m
print(ans)


Measured memory_bytes: 26444
n = gets.chomp.split("").map(&:to_i)
op = []
#0 -> `+`, 1 -> `-`
[0, 1].repeated_permutation(3) do |bits|
    sum = n[0]
    op = []
    3.times do |i|
        if bits[i] == 0
            sum += n[i+1]
            op << "+"
        else
            sum -= n[i+1]
            op << "-"
        end
    end
    break if sum == 7
end

puts n[0].to_s + op[0] + n[1].to_s + op[1] + n[2].to_s + op[2] + n[3].to_s + "=7"

Measured memory_bytes: 3836
N=int(input())
W=list(map(int,input().split()))

ans=10000000000000000
for t in range(N):
    sum1=0
    sum2=0
    for j in range(0,t+1):
        sum1+=W[j]
    for k in range(t+1,N):
        sum2+=W[k]
    if abs(sum2-sum1)<ans:
        ans=abs(sum2-sum1)
print(ans)


Measured memory_bytes: 9168
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

int n,A[55],B[55];
char s[55];

int main()
{
	#ifdef DMC
		freopen("DMC.txt","r",stdin);
	#endif
	
	cin >> n;
	for (int i = 0; i < 26; i++) A[i] = 233;
	while (n--)
	{
		scanf("%s",s + 1); int len = strlen(s + 1);
		for (int i = 1; i <= len; i++) ++B[s[i] - 'a'];
		for (int i = 0; i < 26; i++) A[i] = min(A[i],B[i]);
		memset(B,0,sizeof(B));
	}
	for (int i = 0; i < 26; i++)
		for (int j = 0; j < A[i]; j++) putchar(i + 'a');
	puts("");
	return 0;
}

Measured memory_bytes: 256
require 'pp'

k = gets.to_i
x = "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".split(", ")
puts x[k-1]


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int inf = 1001001001;
 
int main(){

    ll r,d,x;
    cin >> r >> d >> x;
    rep(i,10){
        cout << r*x-d << endl;
        x=r*x-d;
    }
 
}

Measured memory_bytes: 256
'use strict'

function Main(input) {
    let temp = input.trim().split('\n');
    let n = parseInt(temp[0]);
    let v = temp[1].split(' ').map((v)=>(parseInt(v)));
    let c = temp[2].split(' ').map((v)=>(parseInt(v)));

    let ans = 0;

    for(let i=0;i<n;i++){
        if( v[i] - c[i] > 0){
            ans += v[i]-c[i];
        }
    }
    console.log(ans);

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
#problems2
#silver fox vs monster
import math
N,D,A=map(int,input().split())
d=[]
for _ in range(N):
    x,h=map(int,input().split())
    d.append((x,h))
d.sort(key=lambda x:x[0])

now_damage=0
from collections import deque
d=deque(d)
ans=0
d_field=deque()
while d:
    x=d.popleft()
    place,life=x
    if d_field:
        while (d_field and d_field[0][0]<place) :
            now_damage-=A*d_field[0][1]
            d_field.popleft()      
    if life<=now_damage:
        pass
    elif life>now_damage:
        K=math.ceil((life-now_damage)/A)
        ans+=K
        now_damage+=K*A
        d_field.append((2*D+place,K))        
print(ans)

Measured memory_bytes: 34296
# -*- coding: utf-8 -*-
import math
import sys


n,m = map(int, sys.stdin.readline().rstrip().split())
a_s = list(map(int, sys.stdin.readline().rstrip().split()))

imos_map = {}
a_now = 0

for i in range(0, len(a_s)):
  a_now = (a_now + a_s[i]) % m
  if a_now not in imos_map:
    imos_map[a_now] = 1
  else:
    imos_map[a_now] += 1

ans = 0
if 0 in imos_map:
  ans += imos_map[0]

for i in imos_map:
  if imos_map[i] >= 2:
    ans += imos_map[i] * (imos_map[i]-1) // 2

print(ans)

Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
 
int main() {
ll n,k;
cin>>n;
ll ca=10000000000;
ll counter=0;
ll a[n+1]={};
ll cb=10000000000;
for(ll i=0;i<n;i++){
cin>>ca;
if(ca<=n){
a[ca]++;}
else
counter++;}
for(ll i=1;i<n+1;i++){
if(a[i]<i){
counter+=a[i];}
else {
counter+=a[i]-i;}}
cout<<counter<<endl;}


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

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

int a[210],dist[210][210];

int main(void){
	int N,M,K;
	cin >> N >> M >> K;
	REP(i,K){
		cin >> a[i];
		a[i]--;
	}
	sort(a,a+K);
	REP(i,N) REP(j,N)
		if(i!=j)
			dist[i][j]=1e9;
	REP(i,M){
		int x,y,z;
		cin >> x >> y >> z;
		x--,y--;
		dist[x][y] = dist[y][x] = z;
	}
	REP(k,N) REP(i,N) REP(j,N)
			if(i!=j&&i!=k&&j!=k)
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
	int cnt,ans=1e9;
	do{
		int cnt = 0;
		REP(i,K-1)
			cnt += dist[a[i]][a[i+1]];
		ans = min(ans,cnt);
	}while(next_permutation(a,a+K));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
const int MODU = 1e9+7;
const int N = 1e5+10;


void solve() {
	
}

int main() {
	long long int n,m;
	long long int sum = 0;
	cin >> n >> m;
	long long int temp;
	for(int i=0; i<m; i++) {
		cin >> temp;
		sum += temp;
	}
	cout << max(n-sum, -1LL) << endl;
	return 0;
}

Measured memory_bytes: 3636