akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define vcin(a); rp(i,a.size()){cin>>a[i];}
#define vcout(a); rp(i,a.size()){cout<<a[i]<<endl;}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef pair<int,int> P;

bool isOK(int index, int key,vi a) {
    if (a[index] >= key) return true;
    else return false;
}

int binary_search(int key,vi a) {
    int left = -1;
    int right = (int)a.size();
    while (right - left > 1) {
        int mid = left + (right - left) / 2;
        
        if (isOK(mid, key,a)) right = mid;
        else left = mid;
    }
    return right;
}

int modpow(int a,int b,int p){
    if(b==0){
        return 1;
    }elif(b%2==0){
        return modpow((a*a)%p,b/2,p);
    }else{
        return (a*modpow(a,b-1,p))%p;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi x(n),y(n),h(n);
    rp(i,n){
        cin >> x[i] >> y[i] >> h[i];
    }
    vi ans,ansx,ansy;
    rep(i,0,100){
        rep(j,0,100){
            bool judge=true;
            int H1;
            rp(k,n){
                if(h[k]!=0){
                    H1=h[k]+abs(i-x[k])+abs(j-y[k]);
                    break;
                }
            }
            rp(k,n){
                if(h[k]==0){
                    if(H1>abs(i-x[k])+abs(j-y[k])){
                        judge=false;
                        break;
                    }
                }else{
                    int H2=h[k]+abs(i-x[k])+abs(j-y[k]);
                    if(H1!=H2){
                        judge=false;
                        break;
                    }
                }
            }
            
            if(judge){
                cout << i << ' ' << j << ' ' << H1 << endl;
                return 0;
            }
        }
    }
    return 0;
}


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

// Template START
#define endl "\n"
#define async ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long int
#define all(y) y.begin(), y.end()
#define present( x, y ) (x.find( y ) != x.end())
const int mod = (int)1e9 + 7 ;
template<class T>
auto matrix( int r, int c, T v ){
    return vector<vector<T>>( r, vector<T>( c, v ) ) ;
}
template<class T>
auto matrix( int o1, int o2, int o3, T v ){ 
    return vector<vector<vector<T>>>( o1, vector<vector<T>>( o2, vector<T>( o3, v ) ) ) ;
}
#define v vector
// Template END

int power( int x, int n ){
    if( n == 0 ) return 1 ;
    else if( n & 1 ) return ( x * power( (x*x) % mod, n / 2 ) ) % mod ;
    return power( (x*x) % mod, n / 2 ) % mod ;
}


signed main(){
    int n ;
    cin >> n ;
    vector<int> a(n), b(n) ;
    for( int i = 0 ; i < n ; i++ ) cin >> a[i] ;
    for( int i = 0 ; i < n ; i++ ) cin >> b[i] ;
    shuffle( all(b), default_random_engine() ) ; // no need just to have fun
    int j = 0, prev = -1 ;
    for( int i = 0 ; i < n ; i++ ){
        if( a[i] != prev ) j = 0 ;
        if( a[i] == b[i] ){
            for( ; j < n ; j++ ){
                if( a[i] != b[j] && a[j] != b[i] ){
                    swap( b[i], b[j] ) ;
                    break ;
                }
            }
            if( a[i] == b[i] ){
                cout << "No" << endl ;
                return 0 ;
            }
        }
        prev = a[i] ;
    }
    cout << "Yes" << endl ;
    for( int i = 0 ; i < n ; i++ ){
        cout << b[i] << " " ;
    }
    cout << endl ;
    return 0 ;   
}          

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

template<typename T>
istream& operator >> (istream& istr, vector<T>& v){
    for(T& x: v) istr >> x;
    return istr;
}

template<typename T, typename U>
istream& operator >> (istream& istr, pair<T,U>& p){
    istr >> p.first >> p.second;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& v){
    if(!v.empty()){
        ostr << v.front();
        for(auto itr = ++v.begin(); itr != v.end(); itr++)
            // ostr << *itr;
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    // ostr << p.first << p.second;
    ostr << p.first << ", " << p.second;
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& vv){
    if(!vv.empty()){
        ostr << vv.front();
        for(auto itr = ++vv.begin(); itr != vv.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& vp){
    if(!vp.empty()){
        ostr << vp.front();
        for(auto itr = ++vp.begin(); itr != vp.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<double> vd;
// vll x(n); x[i]=a;
typedef vector<vll> vvll;
typedef vector<vc> vvc;
typedef vector<vd> vvd;
// vvll x(m,vi(n)); x[i][j]=a;
typedef pair<ll,ll> pll;
typedef pair<double,double> pd;
typedef vector<pll> vpll;
typedef vector<pd> vpd;
// vpll x(n); x[i]={a,b}; x[i].first/second;

#define PI 3.1415926535897932
#define EPS 1e-12
#define INF (ll)1e+12
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define fix(x) cout << fixed << setprecision(x)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()

template<typename T> T sum(vector<T>& v){return accumulate(all(v), (T)0);}
template<typename T> inline void sort(vector<T>& v){sort(all(v));}
template<typename T> inline void rsort(vector<T>& v){sort(all(v), greater<T>());}
template<typename T> inline void chmin(T& a, T b){if(a>b) a=b;}
template<typename T> inline void chmax(T& a, T b){if(a<b) a=b;}

int main(){
    ll n, m;
    cin >> n >> m;
    vll a(n);
    cin >> a;
    rsort(a);
    double s = sum(a)/(4.0*m);
    if(a[m-1]<s) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

int n, m, q;
int d[4010];

struct edge{
   int to, cost;
//    edge(int to, int cost):to(to), cost(cost){}
};
vector<edge> G[4010]; 

struct UF{
   vector<int> par;
   vector<int> sz;
   UF(){}
   UF(int n){
       par.resize(n);
       sz.resize(n, 1);
       rep(i, 0, n) par[i] = i;
   }
   int find(int x){
       if(x == par[x]) return x;
       return par[x] = find(par[x]);
   }
   void unite(int x, int y){
       x = find(x); y = find(y);
       if(x == y) return;
       if(sz[x] < sz[y]) swap(x, y);
       sz[x] += sz[y];
       par[y] = x;
   }
   bool same(int x, int y){
       return find(x) == find(y);
   }
};

vector<pair<int, P> > es; 
// vector<int> path;
int pMAX[4010][4010];
// int cost[4010][4010];

void dfs(int now, int pre, int MAX, int root){
    // cout << " " << now << " " << pre << endl;
    // path[now] = pre;
    pMAX[root][now] = MAX;
    // if(now == dest) return;
    rep(i, 0, G[now].size()){
        int next = G[now][i].to;
        if(next == pre) continue;
        // path[next] = now;       
        dfs(next, now, max(MAX, G[now][i].cost), root);
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    rep(i, 0, m){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        // G[a].push_back(edge{b, c});
        // G[b].push_back(edge{a, c});
        es.push_back(pair<int, P>(c, P(a, b)));
        // cost[a][b] = c;
        // cost[b][a] = c;
    }
    sort(all(es));
    UF uf(n);
    int sum = 0, cnt = 0;
    rep(i, 0, es.size()){
        int from = es[i].second.first;
        int to = es[i].second.second;
        if(uf.same(from, to) == false){
            uf.unite(from, to);
            sum += es[i].first;
            G[from]. push_back(edge{to, es[i].first});
            G[to]. push_back(edge{from, es[i].first});
        }
    }
    // cout << sum << endl;
    rep(i, 0, n){
        // path.clear(); path.resize(n, -1);
        dfs(i, -1, 0, i);
    }
    cin >> q;
    rep(i, 0, q){
        int s, t;
        cin >> s >> t;
        s--; t--;
        // path.clear(); path.resize(n, -1);
        // dfs(s, -1, t);
        cout << sum - pMAX[s][t] << endl;
        // int MAX = 0;
        // int now = t;
        // while(now != s){
        //     int next = path[now];
        //     chmax(MAX, cost[now][next]);
        //     now = next;
        // }
        // cout << sum - MAX << endl;
        // rep(j, 0, path.size()){
        //     cout << path[j] << " ";
        // }
        // cout << endl;
        // dijkstra(s);
        // cout << d[t] << endl;
    }
}

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

typedef long long ll;
class DSU {
	int n;
	vector< int > parent;
	vector< int > size;
	public:
	int nCC;
	DSU (int len) {
		n = len;
		init();
		nCC = n;
	}
	void init () {
		size.assign(n, 1);
		parent.resize(n);
		for (int i=0; i<n; i++) {
			parent[i] = i;
		}
	}
	int find_set (int v) {
		if (v == parent[v]) return v;
		return parent[v] = find_set(parent[v]);
	}
	void union_sets (int a, int b) {
		a = find_set(a);
		b = find_set(b);
		if (a != b) {
			if (size[a] < size[b]) swap(a,b);
			parent[b] = a;
			size[a] += size[b];
			--nCC;
		}
	}
};

int main() {
	int n, m;
	cin >> n >> m;
	DSU d1(n);
	
	for (int i=0; i<m; i++) {
		int u,v;
		cin >> u >> v;
		--u, --v;
		d1.union_sets(u,v);
	}
	
	
	int ans = d1.nCC;
	--ans;
	cout << ans << '\n';
	
	return 0;
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
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 main () {
  int h, n;
  cin >> h >> n;
  // dp[j] = (モンスターに合計jのダメージを与えるのに必要な魔力の最小値)
  vi dp(h+1,INF);
  dp[0] = 0;
  rep(i,n) {
    int a, b;
    cin >> a >> b;
    rep(j,h) {
      int nj = min(j+a, h); // j>=hについてはj=hに全部まとめる
      dp[nj] = min(dp[nj], dp[j]+b);
    }
  }
  cout << dp[h] << endl;
  return 0;
}

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

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

    int a, b, c;
    cin >> a >> b >> c;

    int cnt = 0;
    for (int i = a; i <= b; i++){
        if (c % i == 0) cnt++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3128
// https://atcoder.jp/contests/abc091/tasks/abc091_b
#include <stdio.h>
#include <string.h>

int n, m;
char s[101][11], t[101][11];

int point(char *str) {
  int i, p = 0;
  for (i = 0; i < n; i++) {
    if (strcmp(str, s[i]) == 0) {
      p++;
    }
  }
  for (i = 0; i < m; i++) {
    if (strcmp(str, t[i]) == 0) {
      p--;
    }
  }
  return p;
}

int solv() {
  int i, max = 0, p;

  for (i = 0; i < n; i++) {
    p = point(s[i]);
    if (p > max) {
      max = p;
    }
  }
  for (i = 0; i < m; i++) {
    p = point(t[i]);
    if (p > max) {
      max = p;
    }
  }

  return max;
}

int main(int argc, char **argv) {
  int i;

  while (scanf("%d", &n) != EOF) {
    for (i = 0; i < n; i++) {
      scanf("%s", s[i]);
    }
    scanf("%d", &m);
    for (i = 0; i < m; i++) {
      scanf("%s", t[i]);
    }

    printf("%d\n", solv());
  }

  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		char c = s.charAt(0);
		
		if( c >= 'A' && c <='Z') {
			System.out.println("A");
		}else {
			System.out.println("a");
		}
	}
}


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

constexpr int inf = 1e9;

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        vector<vector<int>> dp(256, vector<int>(n+1, 1<<30));
        dp[128][0] = 0;
        vector<int> c(m);
        for(int i = 0; i < m; i++)  cin >> c[i];
        for(int i = 0; i < n; i++){
            int x;  cin >> x;
            for(int j = 0; j < 256; j++){
                for(int k = 0; k < m; k++){
                    int next = j + c[k];
                    if(next < 0)    next = 0;
                    if(next > 255)  next = 255;
                    dp[next][i+1] = min(dp[next][i+1], dp[j][i]+(next-x)*(next-x));
                }
            }
        }
        int ans = 1<<30;
        for(int j = 0; j < 256; j++)    ans = min(ans, dp[j][n]);
        cout << ans << endl;
    }
    return 0;
}



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

#ifdef DONLINE_JUDGE
//freopen("a.in", "r", stdin);
//freopen("a.out","w",stdout); // console output is better (in most cases)
#else
// add i/o method of specific testing system
#endif

using namespace std;

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

    double r;
    cin >> r;
    double pi = acos(-1);
    cout << fixed << setprecision(6);
    cout << r * r * pi << " " << r * 2 * pi << endl;

    return 0;
}


Measured memory_bytes: 3256
package main

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

var scanner = bufio.NewScanner(os.Stdin)
var title = [4]int{0, 90, 180, 270}

func main() {
	p := make([][]string, 8)
	for i := range p {
		scanner.Scan()
		p[i] = strings.Split(scanner.Text(), "")
	}
	// log.Println(p)
	for i := 1; i < 4; i++ {
		fmt.Println(title[i])
		p = spin(p)
		print_p(p)
	}
}

func spin(p [][]string) [][]string {
	ret := make([][]string, 8)
	for i := range ret {
		ret[i] = make([]string, 8)
	}
	for i := 0; i < 8; i++ {
		for j := 0; j < 8; j++ {
			ret[i][j] = p[7-j][i]
		}
	}
	return ret
}

func print_p(p [][]string) {
	for _, v := range p {
		fmt.Println(strings.Join(v, ""))
	}
}


Measured memory_bytes: 1076
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#define lint long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++) // for簡略表記
#define DUMP(ar) for(int loop=0; loop<(int)ar.size(); loop++) cout << "[" << loop << "]:" << ar[loop] << endl // 配列一覧表示
#define DUMPL(ar) for(int loop=0; loop<(int)ar.size(); loop++) { cout << ar[loop]; if(loop<(int)ar.size()-1) cout << ' '; } cout << endl; // 配列一行一覧表示
#define COUT(x) cout << x << endl // 単要素出力
#define ALL(ar) ar.begin(), ar.end() // コンテナの全要素
#define LOOPD(i) cout << "ループ[" << i << "]回目---------------" << endl // ループ回数デバグ
using namespace std;
// cout << fixed << setprecision(4) で小数点以下4桁の桁そろえ
// cout << setw(5) << ... で表示形式を5桁に設定 5桁未満なら頭に空白がつく 5桁越なら先頭から5桁まで
// cout << setw(5) << setfill('0') << ... で空白部分の埋め文字に5を使う
// getline(cin, [変数]); で空白などを含む入力の受け取り(行ごとの受け取り)
// cin >> ws; でそこまでにストリームに残されたホワイトスペースを取り除く(=以降のgetlineの有効化)

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

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    FOR(i, n) cin >> a[i];
    FOR(i, n) cin >> b[i];

    lint a_cnt = 0, b_cnt = 0;
    for(int i=0; i<n; i++){
        lint tmp = a[i] - b[i];
        if(tmp > 0){
            b_cnt += tmp;
        }else if(tmp < 0){
            a_cnt += (-tmp) / 2;
        }
    }
    // COUT(a_cnt);
    // COUT(b_cnt);
    if(a_cnt == b_cnt || a_cnt > b_cnt){
        COUT("Yes");
        return 0;
    }else{
        COUT("No");
        return 0;
    }
    
    return 0;
}

Measured memory_bytes: 384
[H,W] = [int(s) for s in input().rstrip().split(" ")]
L = []
for num in range(10):
  L.append([int(s) for s in input().rstrip().split(" ")])
for k in range(10):
  for i in range(10):
    for j in range(10):
      L[i][j] = min(L[i][j],L[i][k] + L[k][j])
k = 0
for h in range(H):
  L_h = [int(s) for s in input().rstrip().split(" ")]
  for x in L_h:
    if x != -1:
      k += L[x][1]
print(k)

Measured memory_bytes: 3064
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
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
#if DEBUG
            ReadLine();
#endif
        }

        void Solve(ConsoleInput cin)
        {
            int n = cin.ReadInt;
            int[] h_n = cin.ReadIntArray(n);

            long ans = 0;

            while (true)
            {
                bool start = false;
                for (int i = 0; i < n; i++)
                {
                    if (!start)
                    {
                        if (h_n[i] > 0)
                        {
                            start = true;
                            h_n[i]--;
                        }
                    }
                    else
                    {
                        if (h_n[i] > 0)
                        {
                            h_n[i]--;
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                if (!start)
                {
                    break;
                }
                else
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);
        }

        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
import collections
N,M = map(int,input().split())
X = list(map(int,input().split()))

c = collections.Counter(X)
c = c.most_common()[::-1]

count = 0
if (len(c) > M):
	for i in range(len(c)-M):
		count += c[i][1]

print(count)

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

int main(){
  string s, t;
  cin >> s >> t;
  int ans = 0;
	
  for(int i = 0; i < 3; i++ ){
  	if(s[i] == t[i]) ans++; 
  }
  cout << ans <<endl;
	
	  
  return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<cstdio>
#include<cstring>
#include<math.h>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int a[200];
int main(void)
{
     int n,m,k;
     scanf("%d%d",&n,&m);
     k=n-m;
     if(k>=0)
          printf("%d\n",k);
     else
          printf("0\n");
     return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define Max(a,b) ((a) < (b) ? (b) : (a))
#define Min(a,b) ((a) > (b) ? (b) : (a))
#define AAA (1000000007)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}


int main() {
	int i, j, k;
	//ll N, M, K;
	int N, M, K;

	int A[1001]{ 0 };

	cin >> N;
	
	rep(i, 2, N + 1) {
		M = sqrt(i);
		j = 2;
		int I = i;
		while(j< M + 2 && I > 1) {
			if (I % j == 0) {
				I /= j;
				A[j]++;
//				cout << j << " " << A[j]  << " in " << i<< endl;
				continue;
			}
			else {
				j++;
			}

		}
		if (I != 1) {
			A[I] ++;
//			cout << i << " " << A[i] << " in " << i << endl;
		}
	}

	ll ans = 1;
	rep(i, 0, 1000) {
//		ans *= (A[i] != 0 ? A[i] + 1 : 1);
		if (A[i] != 0) {
			ans *= (A[i] + 1 % AAA);
			ans %= AAA;
		}
	}
	cout << ans;
	return 0;

}




Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void Solve()
    {
        var t = cin.Next;
        int ans = int.MaxValue;
        int N = t.Length;
        for (int i = 0; i < N; i++)
        {
            var s = t.ToCharArray();
            int K = N;
            while (K > 0)
            {
                bool flag = true;
                for (int j = 1; j < K; j++)
                {
                    if (s[j] != s[j - 1])
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    ans = Math.Min(ans, N - K);
                    break;
                }
                for (int j = 0; j < K - 1; j++)
                {
                    if (s[j] == s[i] || s[j + 1] == s[i])
                    {
                        s[j] = s[i];
                    }
                }
                //WriteLine(s);
                K--;
            }
        }
        WriteLine(ans);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

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

int main(){
  int N ; cin >> N ; 
  vector<int64_t> A(N) ; 
  int64_t ans = 0 ;
  
  for(int i = 0 ; i < N ; i++){
    cin >> A.at(i) ; 
  }
  

  int64_t x = A.at(0)%(1000000007)  ; 
  
  
  for(int i = 1 ; i < N ; i++){
    ans += (A.at(i)*x );
    ans %= (1000000007);
    x += A.at(i) ;
    x %=(1'000'000'007);

  }
  
  cout << ans << endl ;
  
}

Measured memory_bytes: 4816
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  set<string> st;
  rep(i, n) {
    string s;
    cin >> s;
    st.insert(s);
  }
  cout << st.size() << endl;
}

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



int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		string s;
		cin >> s;
		if(s == ".") return 0;
		string t;
		cin >> t;
		vector<int> p, q;
		for(int i=0; i<s.size(); ++i)
			if(s[i] == '"') p.push_back(i);
		p.push_back(s.size());
		for(int i=0; i<t.size(); ++i)
			if(t[i] == '"') q.push_back(i);
		q.push_back(t.size());
//		for(int i=0; i<p.size(); ++i) cout << p[i] << (i==p.size()-1?"\n":" ");
//		for(int i=0; i<q.size(); ++i) cout << q[i] << (i==q.size()-1?"\n":" ");
		if(p.size() != q.size()){
			cout << "DIFFERENT\n";
			continue;
		}
		bool f = false;
		int cnt = 0;
		for(int i=0; i<p.size(); ++i){
			if(i % 2 == 0){
				if(i == 0 && s.substr(0, p[i]) != t.substr(0, q[i])){
					cout << "DIFFERENT\n";
					f = true;
					break;
				}else if(i != 0 && s.substr(p[i-1]+1, p[i]-p[i-1]-1) != t.substr(q[i-1]+1, q[i]-q[i-1]-1)){
					cout << "DIFFERENT\n";
					f = true;
					break;
				}
			}else{
				if(s.substr(p[i-1]+1, p[i]-p[i-1]-1) != t.substr(q[i-1]+1, q[i]-q[i-1]-1)){
					++cnt;
				}
			}
		}
		if(f) continue;
		if(cnt == 0) cout << "IDENTICAL\n";
		else if(cnt == 1) cout << "CLOSE\n";
		else cout << "DIFFERENT\n";
	}
}


Measured memory_bytes: 3044
#include<iostream>
#include<vector>
#define INFTY 1000000000;
using namespace std;
int count=0;
void merge(int a[],int left,int mid,int right){
	int i;
	int n1=mid-left;
	int L[n1];
	int n2=right-mid;
	int R[n2];
	for(i=0; i<n1; i++){
		L[i]=a[left+i];
	}
	for(int i=0; i<n2; i++){
		R[i]=a[mid+i];
	}
	L[n1]=INFTY;
	R[n2]=INFTY;
	int cnt1=0,cnt2=0;
	for(int k=left; k<right; k++){
		if(L[cnt1]<=R[cnt2]){
			a[k]=L[cnt1];
			cnt1++;
			count++;
		}else{
			a[k]=R[cnt2];
			cnt2++;
			count++;
		}
	}
}

void mergeSort(int a[],int left,int right){
	int mid;
	if(left+1<right){
		mid=(left+right)/2;
		mergeSort(a,left,mid);
		mergeSort(a,mid,right);
		merge(a,left,mid,right);
	}
}
	
int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	mergeSort(a,0,n);
	for(int i=0; i<n; i++){
		cout<<a[i];
		if(i<n-1) cout<<" ";
	}
	cout<<endl<<count<<endl;
	return 0;
}


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

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


	int N;
	cin >> N;

	int A[1001][1000];
	rep1(i, N) {
		rep(j, N - 1) cin >> A[i][j];
		A[i][N - 1] = 0;
	}

	int k[1001] = {}, k2[1001] = {};
	vector<int> V;
	rep1(i, N) V.pb(i);

	int kotae = 0;
	while (V.size()) {
		kotae++;
		vector<int> kari;
		for (auto v : V) {
			if (k2[v] < kotae) {
				int a = A[v][k[v]];
				if (A[a][k[a]] == v) {
					kari.pb(v);
					k2[v] = kotae;
					kari.pb(a);
					k2[a] = kotae;
				}
			}
		}
		V = kari;
		for (auto v : V) k[v]++;
	}

	int OK = 1;
	rep1(i, N) if (k[i] != N - 1) OK = 0;
	if (OK) co(kotae - 1);
	else co(-1);

	Would you please return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
const int N=200000+10;
char s[N];int n,tr[N][26];
int vis[N],dp[N],use[N];
int dfs(int x){
	if(vis[x]) return dp[x];
	if(x>n) return 0;
	int &r=dp[x],tmp=0; r=N+1;
	for(int i=0;i<26;i++){
		int j=tr[x][i]; tmp=1+dfs(j);
		if(r>tmp){ r=tmp; use[x]=i; }
	}
	vis[x]=1;return r;
}
int main(){
	std::cin>>(s+1); n=strlen(s+1);
	for(int i=0;i<=n;i++) std::fill(tr[i],tr[i]+26,n+1);
	for(int i=n-1;i>=0;i--){
		for(int j=0;j<26;j++) tr[i][j]=tr[i+1][j];
		tr[i][s[i+1]-'a']=i+1;
	}
	dfs(0);
	fprintf(stderr,"len=%d\n",dp[0]);
	int q=0; while(q<=n){
		putchar(char(use[q]+'a'));
		q=tr[q][use[q]];
	}
	return 0;
}


Measured memory_bytes: 23296
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define N 100005
#define inf 1000000009
#define ll long long
#define pii pair<int,int>
#define sz(a) int(a.size())
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int a,b;

int main(){
	cin >> a >> b;
	cout << a*b;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

template<class T>
struct RollingHash{
	int Base=283;
	const int MASK30=(1ll<<30)-1;
	const int MASK31=(1ll<<31)-1;
	const int MOD=(1ll<<61)-1;
	vector<int>hash,power;
	int calcmod(int v){
		v=(v&MOD)+(v>>61);
		if(v>MOD)v-=MOD;
		return v;
	}
	int mul(int x,int y){
		int xu=x>>31,xd=x&MASK31;
		int yu=y>>31,yd=y&MASK31;
		int mid=xd*yu+xu*yd,midu=mid>>30,midd=mid&MASK30;
		return calcmod(xu*yu*2+midu+(midd<<31)+xd*yd);
	}
	RollingHash(T s){
		int sz=s.size();
		hash.resize(sz+1,0);power.resize(sz+1,1);
		rep(i,sz){
			hash[i+1]=calcmod(mul(hash[i],Base)+s[i]);
			power[i+1]=calcmod(mul(power[i],Base));
		}
	}
	int get(int l,int r){
		return calcmod(hash[r]-mul(hash[l],power[r-l])+MOD);
	}
	int lcp(int x,int y){
		int len=min(hash.size()-1-y,hash.size()-1-x);
		int ok=0,ng=len+1;
		while(ng-ok>1){
			int mid=(ok+ng)/2;
			if(get(x,x+mid)==get(y,y+mid))ok=mid;
			else ng=mid;
		}
		return ok;
	}
};
int N;
int A[200005],B[200005];
vector<int>xora,xorb;
signed main(){
	cin>>N;
	rep(i,N)cin>>A[i];
	rep(i,N)cin>>B[i];
	REP(i,2*N){
		xora.pb(A[i%N]^A[(i-1+N)%N]);
	}
	REP(i,N){
		xorb.pb(B[i]^B[i-1]);
	}
	RollingHash<vector<int>>RH1(xora),RH2(xorb);
	int b=RH2.get(0,N-1);
	rep(i,N){
		int j=RH1.get(i,i+N-1);
		if(b==j){
			cout<<i<<" "<<(A[i]^B[0])<<endl;
		}
	}
	cout<<endl;
}


Measured memory_bytes: 23348
#include <stdio.h>

int main(void){
	while(1){
		int n, i, j, field=0;
		int a[10] = {0};
		char c;
		
		scanf("%d", &n);
		if(n==0) break;
		
		for(i=0; i<100; i++) {
			scanf(" %c", &c);
			
			if(c=='M'){
				a[i%n]++;
			}
			else if(c=='S'){
				field += a[i%n]+1;
				a[i%n] = 0;
			}
			else if(c=='L'){
				a[i%n] += field+1;;
				field=0;
			}
			
		}
		
		for(i=0; i<n; i++){
			for(j=i; j<n; j++){
				if(a[i] > a[j]){
					int tmp = a[i];
					a[i] = a[j];
					a[j] = tmp;
				}
			}
		}
		
		for(i=0; i<n; i++)
			printf("%d ",a[i]);
		printf("%d\n", field);
				
	}

	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define PI 3.141592653589793
using namespace std;

int main(){
  int A,B,H,M;
  double ans;
  double argH,argM;
  double rad;


  cin >> A >> B >> H >> M;
  argH = H * 360 / 12 + 1.0 *M * 360 / 720;
  argM = 1.0 * M * 360 / 60;

  if(abs(argH - argM) < 180){
    rad = abs(argH - argM);
  }else{
    rad = 360 - abs(argH - argM);
  }

  ans = sqrt(A*A + B*B - 2*A*B*cos(rad * PI / 180));
  printf("%0.9lf",ans);
  cout << endl;
  return 0;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = k;
  for (int i = 0; i < n - 1; i++)
    ans *= k - 1;
  cout << ans << endl;
}


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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

// dp[i][j] := 元の数列から連続する区間a_i, a_i+1,...,a_j-1を抜き出した状態の局面から出発して，双方最善を尽くしたときのX-Yの値
// [i, j)

// 左側を取る [i+1, j)
// 右側を取る [i, j-1)
// 区間幅 len = j - iが0の場合が終わり
// 区間幅 len = j - 1の場合が次に決まる...
ll dp[3030][3030];

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    for (int len = 1; len <= n; ++len) {
        for (int i = 0; i + len <= n; ++i) {
            int j = i + len;
            if ((n - len) % 2 == 0) {
                dp[i][j] = max(dp[i+1][j] + a[i], dp[i][j-1] + a[j-1]);
            }
            else {
                dp[i][j] = min(dp[i+1][j] - a[i], dp[i][j-1] - a[j-1]);
            }
        }
    }

    cout << dp[0][n] << endl;
}


Measured memory_bytes: 72064
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = input.nextInt();
		}
		int UP = Integer.MIN_VALUE;
		int DOWN = Integer.MIN_VALUE;
		Arrays.sort(arr);
		/*for (int TOP = 0; TOP < N; TOP++) {
			for (int BOT = TOP+1; BOT<N; BOT++) {
				int Num = Math.max(arr[TOP], arr[BOT]);
				int Den = Math.min(arr[TOP], arr[BOT]);
				if (Num>=UP&&Den>=DOWN&&Num-Den>=UP-DOWN) {
					UP=Num;
					DOWN=Den;
				}
			}
		}*/
		int LDiff = 0;
		int RDiff = Integer.MAX_VALUE;
		for (int i = 0; i < N-1; i++) {
			int L = arr[i];
			int R = arr[N-1]-arr[i];
			if (Math.abs(L-R)<Math.abs(RDiff-LDiff)) {
				RDiff = arr[N-1]-arr[i];
				LDiff = arr[i];
				DOWN=arr[i];
			}
		} 
		System.out.println(arr[N-1]+" "+DOWN);
		//for int i = 0
	}
}

Measured memory_bytes: 50120
// 4_abc135_d
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.length();

    vector<vector<int>> residue(n, vector<int>(10));
    rep(j, 10){
        residue[n - 1][j] = j;
    }
    for(int i = n - 2; i >= 0; i--){
        rep(j, 10){
            residue[i][j] = residue[i + 1][j] * 10 % 13;
        }
    }

    vector<vector<ll>> dp(n, vector<ll>(13));
    rep(i, n){
        rep(j, 13){
            dp[i][j] = 0;
        }
    }

    if(s[0] == '?'){
        rep(k, 10){
            dp[0][residue[0][k]]++;
        }
    }else{
        int k = s[0] - '0';
        dp[0][residue[0][k]]++;
    }

    for(int i = 1; i < n; i++){
        if(s[i] == '?'){
            for(int h = 0; h < 10; h++){
                int k = h;
                int l = residue[i][k];
                for(int j = 0; j < 13 - l; j++){
                    dp[i][l + j] += dp[i - 1][j];
                    dp[i][l + j] %= MOD;
                }
                for(int j = 1; j <= l; j++){
                    dp[i][l - j] += dp[i - 1][13 - j];
                    dp[i][l - j] %= MOD;
                }
            }
        }else{
            int k = s[i] - '0';
            int l = residue[i][k];
            for(int j = 0; j < 13 - l; j++){
                dp[i][l + j] = dp[i - 1][j];
            }
            for(int j = 1; j <= l; j++){
                dp[i][l - j] = dp[i - 1][13 - j];
            }
        }
    }

    cout << dp[n - 1][5] << endl;

    return 0;
}


Measured memory_bytes: 20688
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <functional>
#include <string>
#include <cassert>
#include <cstring>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using ll = long long;

#define MOD (ll)(1e9 + 7)
#define MAX_N 100001 // 適宜変更すること

// memo
ll fact[MAX_N], fact_inv[MAX_N];

// n!
void factorial_prepare(ll n) {
  fact[0] = fact[1] = 1;
  for (int i = 2; i <= n; ++i) {
    fact[i] = (i * fact[i - 1]) % MOD;
  }
}

// pow(x, n) := x^n
ll power(ll x, ll n) {
  if (n == 0) return 1LL;

  ll ret = power((x * x) % MOD, n / 2) % MOD;
  if (n % 2) ret = (ret * x) % MOD;

  return ret;
}

// x^(-1) ≡ x^(MOD - 2) (mod MOD)
// (x!)^(-1) ≡ (x!)^(MOD - 2) (mod MOD)
void inverse_prepare(ll x) {
  // (x!)^(-1)を求めて, その値にx, x-1, ... を順に掛ける
  fact_inv[x] = power(fact[x], MOD - 2);

  for (int i = x - 1; i >= 1; --i) {
    fact_inv[i] = ((fact_inv[i + 1] * (i + 1)) % MOD);
  }
}

// nCr, nPr の想定される最大の n で初期化
void init(ll n) {
  factorial_prepare(n);
  inverse_prepare(n);
}

// nCr
ll C(ll n, ll r) {
  if (n < r || r < 0) return 0LL;
  if (n == r || r == 0) return 1LL;
  // n! / ((n - r)! * r!)
  return (((fact[n] * fact_inv[r]) % MOD) * fact_inv[n - r]) % MOD;
}

// nPr
ll P(ll n, ll r) {
  if (n < r || r < 0) return 0LL;
  if (n == r) return (fact[n]) % MOD;
  // n! / (n - r)!
  return (fact[n] * fact_inv[n - r]) % MOD;
}

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

  ll N, M;

  ll ans;

  cin >> N >> M;

  if (abs(N - M) > 1) {
    cout << 0 << endl;
    return 0;
  }

  init(MAX_N);

  ans = ((P(N, N) % MOD) * P(M, M)) % MOD;
  ans = (N == M) ? (ans * 2) % MOD : ans;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    int sum = 0;
    int id;
    for(int i = 1; i <= n; i++ ){
        sum += i;
        if(sum >= n) {
            id = i;
            break;
        }
    }
    int sa = sum - n;
    //cout << "sa" << sa << endl;
    for(int i = 1; i <= id; i++){
        if(i == sa) continue;
        cout << i << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
import numpy as np
N,W = map(int,input().split())
ndp = np.zeros(W+1,dtype= np.int64)
for _ in range(N):
    w,v = map(int,input().split())
    np.maximum(ndp[:-w] + v, ndp[w:], out = ndp[w:])
print(ndp[-1])

Measured memory_bytes: 18208
#include<iostream>
#include<string>
#include<stack>
using namespace std;
using ll = long long;

int main() {
	string s;
	cin >> s;
	int n = s.size();
	stack<char>ss;
	for (int i = 0;i < n;i++) {
		if (s[i] == 'T' && (ss.empty() || ss.top() == 'T')) {
			ss.push('T');
		}
		else if (s[i] == 'T'&&ss.top() == 'S') {
			ss.pop();
		}
		else ss.push('S');
	}
	cout << ss.size() << endl;
  	return 0;
}

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

int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if (abs(c - a) <= d || (abs(c - b) <= d && abs(b - a) <= d))
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define double long double
#define int long long
#define inf 1000000007 
#define sort(vec) sort(vec.begin(),vec.end());
#define rever(vec) reverse(vec.begin(),vec.end());
#define unsort(vec) sort(vec); rever(vec);
#define rep(i,n) for(int i=0;i<n;i++)
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
int h,w,cnt=0,ans=0;
int a[514][514],b[514][514];
signed main() {
  cin>>h>>w;
  rep(i,h) {
    rep(j,w) {
      scanf("%Ld",&a[i][j]);
      if(a[i][j]%2) cnt++;
      b[i][j]=a[i][j];
    }
  }
  if(cnt<2) cout<<0<<endl;
  else {
    cnt=0;
    rep(i,h) {
      rep(j,w) {
        int k=w-j-1;
        if(i%2) {
          if(a[i][k]%2) {
            if(k==0) {
              if(i==h-1) goto n;
              a[i+1][k]++;
              cnt++;
            }
            else {
              a[i][k-1]++;
              cnt++;
            }
          }
        }
        else {
          if(a[i][j]%2) {
            if(j==w-1) {
              if(i==h-1) goto n;
              a[i+1][j]++;
              cnt++;
            }
            else {
              a[i][j+1]++;
              cnt++;
            }
          }
        }
      }
    }
    n:;
    cout<<cnt<<endl;
    rep(i,h) {
      rep(j,w) {
        int k=w-j-1;
        if(i%2) {
          if(b[i][k]%2) {
            if(k==0) {
              if(i==h-1) return 0;
              cout<<i+1<<" "<<k+1<<" ";
              cout<<i+2<<" "<<k+1<<endl;
              b[i+1][k]++;
            }
            else {
              cout<<i+1<<" "<<k+1<<" ";
              cout<<i+1<<" "<<k<<endl;
              b[i][k-1]++;
            }
          }
        }
        else {
          if(b[i][j]%2) {
            if(j==w-1) {
              if(i==h-1) return 0;
              cout<<i+1<<" "<<j+1<<" ";
              cout<<i+2<<" "<<j+1<<endl;
              b[i+1][j]++;
            }
            else {
              cout<<i+1<<" "<<j+1<<" ";
              cout<<i+1<<" "<<j+2<<endl;
              b[i][j+1]++;
            }
          }
        }
      }
    }
  }
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 58;
const int MOD = 1000000007;
const int MAX_N = 200100;

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int N;
    cin >> N;
    if (N % 2 == 0)
        cout << N / 2 << endl;
    else
        cout << N / 2 + 1 << endl;

    return 0;
}

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

#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//ll MOD=1000000007LL;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;
//const ll MAX_V=114514LL;
//const ll MAX = 500010LL;
const ll mod=MOD;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={0,0,1,-1};
vl dy={1,-1,0,0};

//素因数分解O(√n)
map<ll,ll>prime_factor(ll n){
  map<ll,ll>res;
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
      res[i]++;
      n/=i;
    }
  }
  if(n!=1)res[n]=1;
  return res;
}

const ll MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
//finvが階乗の逆元

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll a, ll n, ll mod) {
  
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll N=2000010;
vl arr(N);
void Eratosthenes(){
	for(ll i = 0; i < N; i++){
		arr[i] = 1;
	}
        arr[1]=0;
	for(ll i = 2; i < sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) < N; j++){
				arr[i *(j + 2)] = 0;
			}
		}
	}
}
//素数判定O(√n)
bool is_prime(ll n){
  for(ll i=2;i*i<=n;i++){
    if(n%i==0)return false;
  }
  return n!=1;
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  /*--------------------------------*/
  
  ll k;cin>>k;
  queue<string>q;
  for(char i='1';i<='9';i++){
      string s="";
      s+=i;
      q.push(s);
  }
  ll cnt=0;
  while(true){
    string tmp=q.front();
    q.pop();
    cnt++;
    if(cnt==k){
        cout<<tmp<<endl;
        return 0;
    }
    if(tmp.back()!='0')q.push(tmp+char(tmp.back()-1));
    q.push(tmp+tmp.back());
    if(tmp.back()!='9')q.push(tmp+char(tmp.back()+1));
    //cout<<tmp<<endl;

  }
}
  

Measured memory_bytes: 25024