akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#pragma GCC optimise ("0fast")
 
using namespace std;
 
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void inline add(int&,int);
int mul(int,int);
int powz(int,int);
int sub(int,int);
template<typename A> ostream& operator<<(ostream&,vector<A>&);
 
const int N=100002;


void solve(){
	int ans=0;
	int n;
	cin>>n;
	vi a(n);
	cin>>a;
	int pf=a[0];
	for(int i=1;i<n;i++){
		if(a[i]>pf){
			a[i]--;
			pf=a[i];
		}
		else{
			if(pf>a[i])ans++;
			else{
				pf=a[i];
			}
		}
	}
	if(ans)cout<<"No";
	else cout<<"Yes";
	
}

 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void inline add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
	    output<<i<<' ';
	return output;
}


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

ll N;


int main(){

	cin >> N;

	ll max_div = 1;
	for (ll i=2; i*i<=N; i++) {
		if (N % i == 0) {
			max_div = i;
		}
	}

	ll ans;
	if (max_div == 1) {
		ans = N - 1;
	} else {
		ans = max_div + (N / max_div) - 2;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int N;
	cin >> N;
	int d[100];
	int sum = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> d[i];
	}

	for (int i = 0; i < N; i++)
	{
		for (int j = i+1; j < N; j++)
		{
			sum += d[i] * d[j];
		}
	}
	cout <<sum<<endl;
}



Measured memory_bytes: 256
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[107];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    int sum=0;
    for(int i=1;i<=n;++i){
        cin>>a[i];
        sum+=a[i];
    }
    int sum2=0;
    if(sum%n>n/2)
        ++sum2;
    sum2+=sum/n;
    int ans=0;
    for(int i=1;i<=n;++i)
        ans+=(a[i]-sum2)*(a[i]-sum2);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

int sum = 0;

int main(){
    while (1){
        char num[1001] = {};
        scanf("%s", num);
        if (num[0] == '0') break;
        for (int i = 0; i < strlen(num); i++){
            sum += num[i] - '0';
        }
        printf("%d\n", sum);
        sum = 0;
    }
    return 0;
}

Measured memory_bytes: 2664
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 100005;

int n;
int a[N][3];
int dp[N][4];

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < 3; j++)
			cin >> a[i][j];
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (k != j) {
					dp[i][j] = max(dp[i][j], dp[i + 1][k] + a[i][j]);
				}
			}
		}
	}
	int res = 0;
	for (int i = 0; i < 3; i++)
		res = max(res, dp[0][i]);
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 2944
package main

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

func main() {
	n := readS()

	for _, v := range n {
		if v == '7' {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

/*-----------Utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const maxBuf = 200100
	var buf []byte = make([]byte, maxBuf)
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error : There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readSs(a int) []string {
	b := make([]string, a)
	for i := 0; i < a; i++ {
		b[i] = readS()
	}
	return b
}

func readI() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func readIs(a int) []int {
	b := make([]int, a)
	for i := 0; i < a; i++ {
		b[i] = readI()
	}
	return b
}

func readF() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

func readFs(a int) []float64 {
	b := make([]float64, a)
	for i := 0; i < a; i++ {
		b[i] = readF()
	}
	return b
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            StringBuilder sb = new StringBuilder();

            string d = "RDLU";
            int[] dx = { 1, 0, -1, 0 };
            int[] dy = { 0, 1, 0, -1 };

            int[,] width = new int[6, 6];
            int[,] height = new int[6, 6];

            for (int i = 0; i < 9; i++)
            {
                string input = Console.ReadLine();

                if (i % 2 == 0)
                {
                    for (int j = 1; j <= 4; j++)
                    {
                        width[j, i / 2 + 1] = int.Parse(input[j - 1].ToString());
                    }
                }
                else
                {
                    for (int j = 1; j <= 5; j++)
                    {
                        height[j, (i + 1) / 2] = int.Parse(input[j - 1].ToString());
                    }
                }
            }

            int x = 1, y = 1;
            int dir = 0;

            do
            {
                switch (dir)
                {
                    case 0:
                        if (height[x, y - 1] == 1) dir--;
                        else if (width[x, y] == 0 && height[x, y] == 1) dir++;
                        else if (width[x, y] == 0 && height[x, y] == 0) dir += 2;
                        break;
                    case 1:
                        if (width[x, y] == 1) dir--;
                        else if (height[x, y] == 0 && width[x - 1, y] == 1) dir++;
                        else if (height[x, y] == 0 && width[x - 1, y] == 0) dir += 2;
                        break;
                    case 2:
                        if (height[x, y] == 1) dir--;
                        else if (width[x - 1, y] == 0 && height[x, y - 1] == 1) dir++;
                        else if (width[x - 1, y] == 0 && height[x, y - 1] == 0) dir += 2;
                        break;
                    case 3:
                        if (width[x - 1, y] == 1) dir--;
                        else if (height[x, y - 1] == 0 && width[x, y] == 1) dir++;
                        else if (height[x, y - 1] == 0 && width[x, y] == 0) dir += 2;
                        break;
                }
                dir = (4 + dir) % 4;

                x += dx[dir];
                y += dy[dir];

                sb.Append(d[dir]);

            } while (x != 1 || y != 1);

            Console.WriteLine(sb);
        }
    }
}

Measured memory_bytes: 8808
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll a,b,c,d,e=0,f=0,j,i;
string s,ss;
    cin>>s>>ss;
    s+=ss;
    
   stringstream ab;
  ab<<s;
  ab>>a;
  c=sqrt(a);
 if(c*c==a)cout<<"Yes\n";
else cout<<"No\n";
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }

lint N;
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	string S;
	cin >> N;
	cin >> S;
	if (SZ(S) > N) {
		cout << S.substr(0, N) << "...";
	}
	else {
		cout << S;
	}
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const int INF = INT_MAX / 2;

int main(){
    int a, b, c; cin >> a >> b >> c;
    if(a==b && b==c && a%2==0){
        cout << -1 << endl;
        return 0;
    }

    int cnt =0;
    while(a%2==0 && b%2==0 && c%2==0){
        cnt++;
        int tmpa = a;
        int tmpb = b;
        a = tmpb/2 + c/2;
        b = tmpa/2 + c/2;
        c = tmpa/2 + tmpb/2;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


N = ni()

ans = 0

for i in range(1, N+1):
    ans += i * (N-i+1)

for _ in range(N-1):
    u, v = na()
    tmp = 0
    if v < u:
        tmp = v
        v = u
        u = tmp
    ans -= u * (N - v + 1)

print(ans)


Measured memory_bytes: 73692
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define log(i,n) log(n)/log(i);
using namespace std;
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;
typedef long long ll;
ll MOD = 1000000007;

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

	ll n,k;
	cin >> n >> k;
	vector<ll>h(100010,0),dp(100010,INF);
	rep(i, n)cin >> h[i];
	dp[0] = 0;//初期条件（dpの初項）

	for (ll i = 0; i < n; ++i) {
		for (ll j = 1; j <= k; ++j) {
			chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
		}
	}

	// 答え
	cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<unordered_set>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    unordered_set<int>s;
    int element=a;
    int k=2;
    bool no=true;
    while(s.find(element)==s.end()){
        if(element==(c%b)){
            no=false;
        }
        s.insert(element);
        element=a*k;
        element%=b;
        k++;
    }
    if(no){
        cout<<"NO";
    }
    else{
        cout<<"YES";
    }
}

Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main(void){
  int data[100000];
  int n,k,q;
  cin>>n>>k>>q;
  int temp = 0;
  for(int i=0;i<n;i++){
    data[i]=0;
  }
  for(int i=0;i<q;i++){
    cin>>temp;
    data[temp-1]++;
  }
  for(int i=0;i<n;i++){
    if(k - q + data[i] > 0){
      cout<<"Yes"<<endl; 
    }else{
      cout<<"No"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (ll i=(a); i<(b); ++i)
inline ll in() { ll x; cin >> x; return x; }

int main() {
  int m = in(), d = in();
  int ans = 0;
  FOR(i,22,d+1) {
    int d1 = i % 10, d10 = i / 10;
    if (d1<2 || d10<2) continue;
    if (d1*d10<=m) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	
	static Map<String,Integer> dayMap = new HashMap<String, Integer>() {{
		put("SUN", 7);
		put("SAT", 1);
		put("FRI", 2);
		put("THU",3);
		put ("WED",4);
		put("TUE", 5);
		put("MON",6);
	}};
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String dayStr = sc.nextLine();
		sc.close();
		System.out.println(dayMap.get(dayStr));
	}

}

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

int n, m, cnt = 0;
bool A[10][10] = {};
bool used[10] = {};

void dfs(int u, int d){
  if(d == n){
    cnt++;
    return ;
  }
  
  for(int i = 1;i <= n;i++){
    if(!used[i] && A[u][i]){
      used[i] = true;
      dfs(i, d + 1);
      used[i] = false;
    }
  }
}

int main(){
  int a, b;
  
  cin >> n >> m;
  for(int i = 0;i < m;i++){
    cin >> a >> b;
    A[a][b] = A[b][a] = true;
  }
  
  used[1] = true;
  dfs(1, 1);
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = []
n.times do |_i|
  x, y = gets.split.map(&:to_i)
  a << [x, y]
end

total = 0
count = 0
a.permutation do |list|
  count += 1
  _x = _y = -1
  list.each do |x, y|
    if _x != -1
      add  = Math.sqrt(((_x - x)**2) + ((_y - y)**2))
      total += add
    end
    _x = x
    _y = y
  end
end

puts format('%.14f', 1.0 * total / count)


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

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

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

int main(void){
    long long a,b,c,d;
    cin >> a >> b >> c >> d;
    a = a-1;
    long long a_total = a/c+a/d;
    a = a-a_total+a/lcm(c,d);
    long long b_total = b/c+b/d;
    b = b-b_total+b/lcm(c,d);
    cout << b-a << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/operators.hpp>
#include <boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

void Main()
{
	int A, B;
	std::cin >> A >> B;
	for (auto i : boost::irange(1, 10001))
	{
		auto a = 8 * i / 100;
		auto b = 10 * i / 100;
		if (a == A && b == B)
		{
			std::cout << i << std::endl;
			return;
		}
	}
	std::cout << -1 << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

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

int main(){
  string S;
  cin >> S;
  ll K;
  cin >> K;
//  cout << "K = " << K << endl;

//  char x, y;
//  x = S.at(0);
  vector<ll> repeat(101, 0);
  ll tail_rep = 0;
// 1文字目
  ll rep = 1;
  repeat.at( 1 )++;
// 2文字目以降
  for( int i = 1; i < S.size(); i++ ){
    if( S.at(i) == S.at(i-1) ){
      repeat.at( rep )--;
      rep++;
      repeat.at( rep )++;
    }else{
      rep = 1;
      repeat.at( rep )++;
    }
  }
  tail_rep = rep;

// head_repを調べる
  ll head_rep = 1;
  for( int i = 1; i < S.size(); i++ ){
    if( S.at(i) == S.at(i-1) ){
      head_rep++;
    }else{
      break;
    }
  }
  
  ll y, ans_one;
  if( head_rep == S.size() ){
    y = S.size() * K;
    ans_one = y / 2;
    cout << ans_one;
    return 0;
  }

/*
  cout << "rep1 = " << repeat.at(1) << endl;
  cout << "rep2 = " << repeat.at(2) << endl;
  cout << "rep3 = " << repeat.at(3) << endl;
  cout << "rep9 = " << repeat.at(9) << endl;
  cout << "rep10 = " << repeat.at(10) << endl;
  cout << "head_rep = " << head_rep << endl;
  cout << "tail_rep = " << tail_rep << endl;
  
  cout << "repeat K times" << endl;
*/
  for( int i = 1; i < 101; i++ )   repeat.at(i) *= K;
/*
  cout << "rep1 = " << repeat.at(1) << endl;
  cout << "rep2 = " << repeat.at(2) << endl;
  cout << "rep3 = " << repeat.at(3) << endl;
  cout << "rep9 = " << repeat.at(9) << endl;
  cout << "rep10 = " << repeat.at(10) << endl;
*/
  
  if( S.at(0) == S.at( S.size()-1 ) ){
    repeat.at( head_rep ) -= (K-1);
    repeat.at( tail_rep ) -= (K-1);
    repeat.at( head_rep + tail_rep ) += (K-1);
  }

/*
  cout << "connect head and tail" << endl;
  cout << "rep1 = " << repeat.at(1) << endl;
  cout << "rep2 = " << repeat.at(2) << endl;
  cout << "rep3 = " << repeat.at(3) << endl;
  cout << "rep9 = " << repeat.at(9) << endl;
  cout << "rep10 = " << repeat.at(10) << endl;
*/
  
  ll ans = 0;
  int j = 0;
  for( int i = 1; i <= 100; i++ ){
    j = i / 2;
    ans += j*repeat.at(i);
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 110000
int n,tot;
int head[N],nex[N<<1],to[N<<1];
int sg[N];
void add(int x,int y)
{
	tot++;
	nex[tot]=head[x];head[x]=tot;
	to[tot]=y;
}
void dfs(int x,int y)
{
	for(int i=head[x];i;i=nex[i])
		if(to[i]!=y)
		{
			dfs(to[i],x);
			sg[x]^=sg[to[i]]+1;		
		}
}
int main()
{
	//freopen("tt.in","r",stdin);
	scanf("%d",&n);
	for(int i=1,x,y;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	dfs(1,0);
	puts(sg[1] ? "Alice" : "Bob");
	return 0;
}


Measured memory_bytes: 7296
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<iomanip>
#include<cstdlib>
#include<cmath>
#include<cstdio>
using namespace std;

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

Measured memory_bytes: 1280
open Batteries

let () =
  let n, m = Scanf.scanf " %d %d\n" (fun n m -> (n, m)) in
  let arr = Array.make n 0 in
  let () =
    1 -- m
    |> Enum.iter (fun _ ->
           Scanf.scanf " %d %d" (fun n m ->
               arr.(n - 1) <- arr.(n - 1) + 1 ;
               arr.(m - 1) <- arr.(m - 1) + 1 ) )
  in
  let () = Array.iter (fun x -> Printf.printf "%d\n" x) arr in
  ()


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define zcin(type, a) type a; cin >> a;
#define zcout(a, sep1, b, sep2) cout << a << sep1 << b << sep2;
#define zfor(i, b, n) for (int i = b; i < n; ++i)
#define pb push_back
const int INF = 1e9 + 5;

using namespace std;

int main()
{
	#ifdef ME
		freopen("input.txt", "r", stdin);
		//freopen("output.txt", "w", stdout);
	#endif
	zcin(int, n);
	vector<int> dp(n, INF);
	vector<int> arr(n);
	zfor(i, 0, n)
		cin >> arr[i];

	dp[0] = 0;
	for (int i = 0; i < n ; ++i)
	{
		for (auto j : {i + 1, i + 2})
		{
			if (j < n)
			{
				int cost = abs(arr[i] - arr[j]);
				dp[j] = min(dp[j], dp[i] + cost);
			}
		}
	}

	cout << dp[n - 1];

	
	return 0;
}




Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			String input_str[] = br.readLine().split("\\s+");
			int N = Integer.parseInt(input_str[0]);
			int LIMIT = Integer.parseInt(input_str[1]);

			Queue Q = new Queue(N);

			for(int loop = 0; loop < N; loop++){

				input_str = br.readLine().split("\\s+");
				Q.push(new Process(input_str[0],Integer.parseInt(input_str[1])));
			}

			int current = 0;

			StringBuilder ans = new StringBuilder();

			while(!Q.isEmpty()){

				Process tmp = Q.pop();

				if(tmp.getTIME() <= LIMIT){

					current += tmp.getTIME();
					ans.append(tmp.getName()).append(" ").append(Integer.toString(current)).append("\n");

				}else{

					current += LIMIT;
					tmp.setTIME(tmp.getTIME()-LIMIT);
					Q.push(tmp);
				}
			}

			System.out.print(ans.toString());

		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
	}
}


class Process{

	private String name;
	private int TIME;

	Process(String arg_name,int arg_TIME){
		name = arg_name;
		TIME = arg_TIME;
	}

	public String getName() {
		return name;
	}

	public int getTIME() {
		return TIME;
	}

	public void setTIME(int arg_TIME) {
		TIME = arg_TIME;
	}
}

class Queue{

	private Process[] table;
	private int head;
	private int tail;
	private int size;
	private int num_data;

	Queue(int arg_size){

		size = arg_size;
		table = new Process[arg_size];
		head = 0;
		tail = 0;
		num_data = 0;
	}

	boolean isEmpty(){

		return num_data == 0;
	}

	void push(Process process){

		table[tail] = process;
		tail = (tail+1)%size;
		num_data++;
	}

	public Process pop(){

		head = (head+1)%size;
		num_data--;
		return table[(head-1+size)%size];
	}
}


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


namespace Test1 {





    class ClassMain {



        public static string tikaiiro(int r, int g, int b) {
            int minD = 1000000007;
            int dk = 0;
            int minColorIndex = -1;
            dk = (r - 0) * (r - 0) + (g - 0) * (g - 0) + (b - 0) * (b - 0);
            if (dk < minD) { minD = dk;  minColorIndex = 0; }
            dk = (r - 0) * (r - 0) + (g - 0) * (g - 0) + (b - 255) * (b - 255);
            if (dk < minD) { minD = dk; minColorIndex = 1; }
            dk = (r - 0) * (r - 0) + (g - 255) * (g - 255) + (b - 0) * (b - 0);
            if (dk < minD) { minD = dk; minColorIndex = 2; }
            dk = (r - 0) * (r - 0) + (g - 255) * (g - 255) + (b - 255) * (b - 255);
            if (dk < minD) { minD = dk; minColorIndex = 3; }
            dk = (r - 255) * (r - 255) + (g - 0) * (g - 0) + (b - 0) * (b - 0);
            if (dk < minD) { minD = dk; minColorIndex = 4; }
            dk = (r - 255) * (r - 255) + (g - 0) * (g - 0) + (b - 255) * (b - 255);
            if (dk < minD) { minD = dk; minColorIndex = 5; }
            dk = (r - 255) * (r - 255) + (g - 255) * (g - 255) + (b - 0) * (b - 0);
            if (dk < minD) { minD = dk; minColorIndex = 6; }
            dk = (r - 255) * (r - 255) + (g - 255) * (g - 255) + (b - 255) * (b - 255);
            if (dk < minD) { minD = dk; minColorIndex = 7; }
            return intToColor(minColorIndex);

        }

        public static string intToColor(int index) {
            switch (index) {
                case 0:
                    return "black";
                case 1:
                    return "blue";
                case 2:
                    return "lime";
                case 3:
                    return "aqua";
                case 4:
                    return "red";
                case 5:
                    return "fuchsia";
                case 6:
                    return "yellow";
                case 7:
                    return "white";
            }
            return "";
        }

        public static int henkan(char ch) {
            if (ch <= '9'&& '0' <= ch) {
                return ch - '0';
            }
            else {
                return 10 + (ch - 'a');
            }
        }



        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                //int n = int.Parse(line);
                if (line == "0") { break; }
                char[] chrs = line.ToCharArray();
                int r = 16 * henkan(chrs[1]) + henkan(chrs[2]);
                int g = 16 * henkan(chrs[3]) + henkan(chrs[4]);
                int b = 16 * henkan(chrs[5]) + henkan(chrs[6]);
                Console.WriteLine(tikaiiro(r, g, b));

            }
        }
    
    }



    
}

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

using namespace std;

int main(void)
{
	long long int n;
	string res;

	cin >> n;

	if(n==0)
	{
		cout << 0 << '\n';
		return 0;
	}
	while(1)
	{
		if(n==0)
		{
			break;
		}
		else if(n<0)
		{
			int a = (n%(-2));
			if(a==-1)
			{
				n = (n/(-2)) + 1;
				res = (char)(1+'0') + res;
			}
			else
			{
				n = (n/(-2));
				res = (char)(0+'0') + res;
			}
		}
		else
		{
			int a = (n%(-2));
			if(a==1)
			{
				n = (n/(-2));
				res = (char)(1+'0') + res;
			}
			else
			{
				n = (n/(-2));
				res = (char)(0+'0') + res;				
			}
		}
	}

	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
//#define m 1000000007
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> //required
// #include <ext/pb_ds/tree_policy.hpp>     //required
// using namespace __gnu_pbds;              //required
// using namespace std;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// ordered_set<int> s;
// ordered_set<int>::iterator itr;
// /* or:
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// ordered_set s;
// This works in C++98 but the above version only works in C++11
// */
// //char str[10000000];
void swap(ll *xp, ll *yp)
{
    ll temp = *xp;
    *xp = *yp;
    *yp = temp;
}
int main()
{
    ll n, m;
    cin >> n >> m;
    ll p1 = n * 2;
    ll p2 = n * 4;
    if (m >= p1 && m <= p2 && m % 2 == 0)
        cout << "Yes"
             << "\n";
    else
    {
        cout << "No"
             << "\n";
    }

    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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;
}

bool cmp1(vi& a, vi &b){
  return a[0] < b[0];
}
bool cmp2(vi& a, vi &b){
  return a[1] < b[1];
}
int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  ll n;
  cin >> n;
  // 0: value
  // 1: index
  // 2: the median when i is excluded
  vector< vi > v(n, vi(3));
  fi(0, n) {
    cin >> v[i][0];
    v[i][1] = i;
  }

  sort(all(v), cmp1);

  // 0 1 2 3 4 5
  // .     #
  //   .   #
  //     . #
  //     # .
  //     #   .
  //     #     .
  fi(0, n) {
    if(i < n / 2)
      v[i][2] = v[n / 2][0];
    else
      v[i][2] = v[n / 2 - 1][0];
  }

  sort(all(v), cmp2);
  fi(0, n) {
    cout << v[i][2] << endl;
  }
  return 0;
}



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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 100005;
int N;
int A[MAX_N];

signed main()
{
  cin >> N;
  REP(n,N) {
    cin >> A[n];
  }

  int ans = 1;
  int C[3] = {0, 0, 0};

  FOR(n,0,N) {
    int cnt = 0;
    REP(i,3) {
      if(C[i] == A[n]) {
        cnt++;
      }
    }
    ans *= cnt;
    ans %= MOD;
    REP(i,3) {
      if(C[i] == A[n]) {
        C[i]++;
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
w=input()
nw=len(w)
lw=list(w)
n=int(input())
alpha="qwertyuiopasdfghjklzxcvbnm"
l=sorted(list(alpha))
d={}
for i in range(26):
  d[l[i]]=i
num=n
count=0
while num>0 and count<nw:
  if lw[count]=="a":
    count+=1
  else:
    letter=lw[count]
    if 27-d[letter]-1<=num:
      num-=27-d[letter]-1
      lw[count]="a"
      count+=1
    else:
      count+=1
if num>0:
  a=lw[-1]
  num1=d[a]
  lw[-1]=l[(num1+num)%26]
print("".join(lw))

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

#define INF 0x33433433

int n;
int rmin;
int rmax;
int rsum;
int wsum;
int r[114514];
int w[114514];
bool G[114514];

void SubsetSum(int N, int *as, int n) {
  int maxsum = 1000;
  int sum = 0;

  fill(G, G+N+1, false);
  G[0] = true;
  for (int i=1; i<=n; i++) {
    int lim = max(min(maxsum, N-as[i]), 1000);
    for (int j=lim; j>=lim-1000; j--) {
      G[j+as[i]] |= G[j];
    }
    sum += as[i];
    maxsum = max(maxsum, sum);
  }
}

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) return 0;

    rsum = 0;
    wsum = 0;
    rmax = -1;
    rmin = INF;
    for (int i=1; i<=n; i++) {
      scanf("%d%d", &r[i], &w[i]);
      rsum += r[i];
      wsum += w[i];
      rmax = max(rmax, r[i]);
      rmin = min(rmin, r[i]);
    }

    /*if (n > 3) {
      printf("%d\n", rsum+wsum);
      continue;
    }*/

    int leftover;
    if (rmax >= rsum/2 + rsum%2) {
      leftover = rmax*2-rsum;
    } else {
      if (rmin < rsum/3 + (rsum%3 != 0)) {
        printf("%d\n", rsum+wsum);
        continue;
      }

      assert(rsum%3 == 0); // r = 0 mod 3 if the program reaches here
      leftover = rsum/3;
    }

    bool should_move = false; // remove w[i] from w if r[i] == rmax
    for (int i=1; i<=n; i++) {
      if (r[i] == rmax) should_move = true;
      if (should_move) {
        r[i] = r[i+1];
        w[i] = w[i+1];
      }
    }

    //printf("wsum: %d\n", wsum);
    //printf("rsum: %d\n", rsum);
    //printf("rmax: %d\n", rmax);
    //printf("leftover: %d\n", leftover);
    SubsetSum(leftover, w, n-1); // put wi as many as possible
    int ans = -1;
    for (int i=leftover; i>=0; i--) {
      if (G[i]) {
        //printf("i: %d\n", i);
        ans = rsum+wsum+leftover-i;
        break;
      }
    }
    assert (ans != -1);
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 3156
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * Organize Your Train part II
 */
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = Integer.parseInt(line);
			for (int i = 0; i < n; i++) {
				HashSet<String> trains = new HashSet<String>();
				line = br.readLine();
				for (String train : organize(line)) {
					if (!trains.contains(train)) trains.add(train);
				}
				System.out.println(trains.size());
			}
		} // end while
	} // end main

	static List<String> organize(String line) {
		List<String> os = new ArrayList<String>();
		for (int j = 1; j < line.length(); j++) {
			String t1 = line.substring(0, j);
			String t2 = line.substring(j);
			//
			os.add(t1 + t2);
			os.add(t1 + new StringBuilder(t2).reverse().toString());
			os.add(new StringBuilder(t1).reverse().toString() + t2);
			os.add(new StringBuilder(t1).reverse().toString() + new StringBuilder(t2).reverse().toString());
			//
			os.add(t2 + t1);
			os.add(t2 + new StringBuilder(t1).reverse().toString());
			os.add(new StringBuilder(t2).reverse().toString() + t1);
			os.add(new StringBuilder(t2).reverse().toString() + new StringBuilder(t1).reverse().toString());
		}
		return os;
	}
}

Measured memory_bytes: 57316
n, m = map(int, input().split())

a = min(n, m)
b = max(n, m)

if a >= 3:
    print((a-2)*(b-2))
elif a == 2:
    print(0)
elif a == 1:
    if b >= 3:
        print(b-2)
    elif b == 2:
        print(0)
    elif b == 1:
        print(1)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){

int W,H,x,y,r;
cin>>W>>H>>x>>y>>r;
if (0<=x-r && x+r<=W && 0<=y-r && y+r<=H){cout<<"Yes"<<endl;}
else {cout<<"No"<<endl;}




	return 0;
}


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

int		main(void)
{
	int		a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b != c + d)
		cout << (a + b > c + d ? "Left" : "Right") << endl;
	else
		cout << "Balanced" << endl;
}

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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  int n;cin>>n;
  cout<<"ABC"<<n<<endl;

  return 0;
}


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

const static ll MOD = (1e+9)+7;

ll modpow(ll a,ll n){
    if(n==0)return 1;
    if(n%2==1)return a*modpow(a,n-1)%MOD;
    ll t = modpow(a,n/2) % MOD;
    return t*t % MOD;
}

int main(){
    ll ans = 0;
    ll X;cin>>X;
    ll now = 100;
    while(now < X){
        now*=1.01;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define lint long long
#define INF 1000000000000000
#define pii pair<long long,long long>

/* source code below */
int garden[102][102];
void dfs(int h,int k) {
	garden[k][h] = 0;

	if (garden[k+1][h] == 1)
	{
		dfs(h, k + 1);
	}

}
int main() {
	
	int N; cin >> N;
	vector<lint> h(N);
	for (int i = 0; i < N; i++)
	{
		cin >> h[i];
	}
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < h[i]; j++)
		{
			garden[i][j] = 1;
		}
	}

	int count = 0;
	
	for (int h = 0; h < 100; h++)
	{
		for (int i = 0; i < N; i++)
		{
			if (garden[i][h] == 1) {
				count++;
				dfs(h,i);
			}
		}
	}

	cout << count << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            if (a == 0 && b == 0) {
                break;
            }
            for (int i = 1; i <= a; i++) {
                for (int j = 1; j <= b; j++) {
                    if ((i + 2) % 2 == 1) {
                        if ((j + 2) % 2 == 1&&j!=b) {
                            System.out.print("#");
                        } else if((j + 2) % 2 == 0&&j!=b) {
                            System.out.print(".");
                        }
                        else if((j + 2) % 2 == 1){
                            System.out.println("#");
                            
                        }
                        else{
                            System.out.println(".");
                        }
                    } else if ((j + 2) % 2 == 0&&j!=b) {
                            System.out.print("#");
                        } else if((j + 2) % 2 == 1&&j!=b) {
                            System.out.print(".");
                        }
                        else if((j + 2) % 2 == 0){
                            System.out.println("#");
                            
                        }
                        else{
                            System.out.println(".");
                        }
                }
                
            }
            System.out.println("");
        }
    }
}

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

// Shrotening
#define fst first
#define snd second
#define pb push_back
#define mp std::make_pair

// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::pair<int,int> PII;

typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
typedef std::vector<PII> VPII;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

int n, m;
VI a(1000);
int main() {
    while(std::cin >> n >> m) {
        if(n == 0 && m == 0) break;
        REP(i, n) {
            std::cin >> a[i];
        }

        int ans = 0, cnt = 0;;
        REP(i, n) REP(j, n) {
            if(i == j) continue;
            if(a[i] + a[j] <= m) {
                ans = std::max(ans, a[i] + a[j]);
                ++cnt;
            }
        }
        if(cnt == 0) {
            std::cout << "NONE" << std::endl;
        } else {
            std::cout << ans << std::endl;
        }
    }
}


Measured memory_bytes: 3064
import bisect
n, m = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
setA = set(A)
setB = set(B)
A.sort()
B.sort()
if len(setA) < n or len(setB) < m:
    print(0)
    exit()
mod = 10 ** 9 + 7
cnt = 1
for i in range(n * m, 0, -1):
    cntA = n-bisect.bisect_left(A, i)
    cntB = m-bisect.bisect_left(B, i)
    if i in setA and i not in setB:
        cnt = (cnt*cntB) % mod
    if i not in setA and i in setB:
        cnt = (cnt*cntA) % mod
    if i not in setA and i not in setB:
        cnt = (cnt*(cntA*cntB-(n*m-i))) % mod
print(cnt)


Measured memory_bytes: 3188
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto N = readln.chomp.to!int;
    auto X = new long[](N);
    auto S = new long[](N);
    foreach (i; 0..N) {
        auto s = readln.split.map!(to!long);
        X[i] = s[0];
        S[i] = s[1];
    }

    long[] Y;
    foreach (i; 0..N) {
        Y ~= S[i];
        if (i < N - 1) Y ~= X[i] - X[i+1];
    }

    long ans = 0;
    long tmp = 0;

    for (int i = 0, j = 0; i < N * 2 - 1; ++i) {
        if (j < i) {
            j = i;
            tmp = 0;
        }
        while (j < N * 2 - 1 && tmp + Y[j] >= 0) {
            tmp += Y[j];
            ++j;
            ans = max(ans, tmp);
        }
    }

    ans.writeln;
}


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

int main(){
  long long A, B; cin >> A >> B;
  
  if((A+B)%2 != 0){
    cout <<"IMPOSSIBLE";
  }
  else{
    cout << (A+B)/2;
  }
  
  return 0;
}

Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n");
  var n = parseInt(input[0].split(" ")[0]);
  tmp=input[1].split(" ");
  a = new Array(n).fill(0);
  b = new Array();
  var max=-Math.pow(10,6)-1;
  var min=Math.pow(10,6)+1;
  for(i=0;i<n;i++){
    a[i]=parseInt(tmp[i]);
    max=Math.max(a[i],max);
    min=Math.min(a[i],min);
  }
  if(max>=Math.abs(min)){
    for(i=0;i<n;i++){
      if(a.indexOf(max)!=i){
        bsub=[a.indexOf(max)+1,i+1];
        b.push(bsub);
        a[i]=a[i]+max;
      }
    }
    for(i=0;i<n;i++){
      if(i>0&&a[i]<a[i-1]){
        bsub=[i,i+1];
        b.push(bsub);
        a[i]=a[i-1]+a[i];
      }
    }
  }else if(Math.abs(min)>max){
    for(i=0;i<n;i++){
      if(a.indexOf(min)!=i){
        bsub=[a.indexOf(min)+1,i+1];
        b.push(bsub);
        a[i]=a[i]+min;
      }
    }
    for(i=n-1;i>=0;i--){
      if(i<n-1&&a[i]>a[i+1]){
        bsub=[i+2,i+1];
        b.push(bsub);
        a[i]=a[i+1]+a[i];
      }
    }
  }
  var ans =b.length;
  for(i=0;i<b.length;i++){
    ans+="\n"+b[i][0]+" "+b[i][1];
  }
  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9420
fn main() {
    let ks = read_vec::<i32>();
    let k = ks[0];
    let s = ks[1];

    let mut cnt = 0;
    for x in 0..k+1 {
        for y in 0..k+1 {
            let z = s - x - y;
            if z >= 0 && z <= k {
                cnt += 1;
            }
        }
    }

    println!("{}", cnt);
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
l = input()

mod = 10 ** 9 + 7
ans = 1
one = 1
zero = 0
for i in l:
    if i == "1":
        zero = 1 * one + 3 * zero
        one *= 2
        ans = one + zero
    else:
        one = one
        zero = 3 * zero
        ans = one + zero

print(ans % mod)

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

int main(){
    int n;
    cin>>n;
    
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    
    for(int i=n-1;i>=0;i--) {
        if(i==0)cout<<a[i];
        else cout<<a[i]<<' ';
    }
    cout<<endl;
}



Measured memory_bytes: 3092
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value


void solve() {

	int X, A;
	cin >> X >> A;

	cout << ((X < A) ? 0 : 10) << endl;

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

Measured memory_bytes: 256
import heapq

n=int(input())
u=[0]*n
k=[0]*n
v=[0]*n
z=[[] for _ in range(n) ]
for i in range(n):
  u[i],k[i],*v[i] = map(int,input().split())
  for j in range(0,len(v[i]),2):
    z[i].append([v[i][j],v[i][j+1]])
d=[float("inf")]*n 
e=[-1] *n #いったことなければ -1


def dijkstra(x):
  e[x]=0 #ブクマ
  d[x]=0
  q= [ (d[x],x) ] 
  
  while len(q)>0:
    #print(d)
    b,a = heapq.heappop(q)
    e[a]=0
    
    if d[a] < b:
      pass
    else:
      to_go = z[a]
      for s,t in to_go:
        if e[s]==0:
          pass
        else:
          if d[s] > d[a]+t :
            d[s] = d[a]+t
            heapq.heappush( q, (d[s],s) )

  
dijkstra(0)
for i in range(n):
  print(i,d[i])


Measured memory_bytes: 6236