akhauriyash/Code-Regression huggingface dataset:
//https://atcoder.jp/contests/abc169/submissions/13772481
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 ll mod = 998244353;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	mint& operator+=(const mint a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

mint dp[3005][3005];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, s;
    cin >> n >> s;
    vector<int> a(n);
    dp[0][0] = 1;
    rep(i,n){
        cin >> a[i];
        rep(j,s+1){
            if(j+a[i] <= s) dp[i+1][j+a[i]] += dp[i][j];
            dp[i+1][j] += (mint)2 * dp[i][j];
        }
    }
    cout << dp[n][s].x << endl;
    return 0;
}


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

string shuffle(string str,int h){
    string head=str.substr(0,h);
    string tail=str.substr(h,str.size()-h);
    return tail+head;
}

int main(){
    string cards;
    int m,h;
    
    while(1){
        cin>>cards;
        if(cards=="-")break;
        
        cin>>m;
        for(int i=0;i<m;i++){
            cin>>h;
            cards=shuffle(cards,h);
        }
        cout<<cards<<endl;
    }
    return 0;
}


Measured memory_bytes: 3048
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int tmp = 0;
        if(a < b)
        {
            if(a > c)
            {
                tmp = c;
                c = b;
                b = a;
                a = tmp;
            }
            else
            {
                if(b > c)
                {
                    tmp = c; 
                    c = b;
                    b = tmp;
                }
            }
        }
        else
        {
            if(a < c)
            {
                tmp = a;
                a = b;
                b = tmp;
            }
            else
            {
                if(b > c)
                {
                    tmp = a;
                    a = c;
                    c = tmp;
                }
                else
                {
                    tmp = a;
                    a = b;
                    b = c;
                    c = tmp;
                }
            }
        }
        System.out.println(a + " " + b + " " + c);
    }
}


Measured memory_bytes: 26116
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		while (true) {
			int m = scan.nextInt();
			int f = scan.nextInt();
			int r = scan.nextInt();
			scan.nextLine();
			
			if(m==-1 && f==-1 && r==-1) {
				break;
			}
			
			if(m==-1 || f==-1) {
				System.out.println("F");
			} else if(m+f >= 80) {
				System.out.println("A");
			} else if(m+f >= 65) {
				System.out.println("B");
			} else if(m+f >= 50) {
				System.out.println("C");
			} else if(m+f >= 30) {
				if(r>=50) {
					System.out.println("C");
				} else {
					System.out.println("D");
				}
				
			} else {
				System.out.println("F");
			}
		}
		
	}
}


Measured memory_bytes: 26364
#include<stdio.h>
int main() {
	int a, b, c, d;
	char e, f, g, h;
	scanf("%c%c%c%c", &e, &f, &g, &h);
	a = (int)(e-'0');
	b = (int)(f-'0');
	c = (int)(g-'0');
	d = (int)(h-'0');
	if(a+b+c+d==7) {
		printf("%d+%d+%d+%d=7",a,b,c,d);
	} else if(a+b+c-d==7) {
			printf("%d+%d+%d-%d=7",a,b,c,d);
	} else if(a+b-c+d==7) {
			printf("%d+%d-%d+%d=7",a,b,c,d);
	} else if(a+b-c-d==7) {
			printf("%d+%d-%d-%d=7",a,b,c,d);
	} else if(a-b+c+d==7) {
			printf("%d-%d+%d+%d=7",a,b,c,d);
	} else if(a-b+c-d==7) {
			printf("%d-%d+%d-%d=7",a,b,c,d);
	} else if(a-b-c+d==7) {
			printf("%d-%d-%d+%d=7",a,b,c,d);
	} else  {
			printf("%d-%d-%d-%d=7",a,b,c,d);
	} 
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef struct tree{
  int ki;
  struct tree *right,*left,*parent;
}tree;

tree *root,*nil;

tree* minimum(tree *);
tree * find(tree*,int);
tree* success(tree *);
void delete(tree *);
void insert(int);
void inwalk(tree *);
void prwalk(tree *);

tree* minimum(tree *a)
{
  while(a->left != nil)
    a = a->left;
  return a;
}

tree * find(tree *z,int k)
{
  while(z != nil && k != z->ki) {
    if(k < z->ki) {
      z = z->left;
    }else{
      z = z->right;
    }
  }
    return z;
}

tree* success(tree *b)
{
  if(b->right != nil)
    return minimum(b->right);
  tree *B = b->parent;
  while(B != nil && b == B->right) {
    b = B;
    B = B->parent;
  }
  return B;
}

void delete(tree *f)
{
  tree *d;
  tree *c;

  if(f->left == nil || f->right == nil)
    d = f;
  else
    d = success(f);

  if(d->left != nil) {
    c = d->left;
  }else{
    c = d->right;
  }

  if(c != nil) {
    c->parent = d->parent;
  }

  if(d->parent == nil) {
    root = c;
  }else{
    if(d == d->parent->left) {
      d->parent->left = c;
    }else{
      d->parent->right = c;
    }
  }

  if(d != f) {
    f->ki = d->ki;
  }

  free(d);
}


void insert(int k)
{
  struct tree *a=root,*b=nil,*c;

  c = (struct tree *)malloc(sizeof(struct tree));
  c->ki = k;
  c->left = nil;
  c->right = nil;

  while(a!=nil) {
    b = a;
    if(c->ki < a->ki) {
      a = a->left;
    }else{
      a = a->right;
    }
  }

  c->parent = b;
  if(b == nil) {
    root = c;
  }else{
    if(c->ki < b->ki) {
      b->left = c;
    }else{
      b->right = c;
    }
  }
}

void inwalk(tree *x)
{
  if(x == nil)
    return;
  inwalk(x->left);
  printf(" %d",x->ki);
  inwalk(x->right);
}

void prwalk(tree *y)
{
  if(y == nil)
    return;
  printf(" %d",y->ki);
  prwalk(y->left);
  prwalk(y->right);
}

int main()
{
  int m,k,i;
  char ins[10];

  scanf("%d",&m);

  for(i=0;i<m;i++) {
    scanf("%s",ins);
    if(ins[0] == 'f') { /*f = find*/
      scanf("%d",&k);
      tree *t = find(root,k);
      if(t != nil) {
	printf("yes\n");
      }else{
	printf("no\n");
      }
    }else if(ins[0] == 'i') { /*i = insert*/
      scanf("%d",&k);
      insert(k);
    }else if(ins[0] == 'p') { /*p = print*/
      inwalk(root);
      printf("\n");
      prwalk(root);
      printf("\n");
    }else if(ins[0] == 'd') {
      scanf("%d",&k);
      delete(find(root,k));
    }
  }

  return 0;
}



Measured memory_bytes: 20452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(obj) (obj).begin(), (obj).end()

int main(){
    int A, B, K, ans = 0;
    cin >> A >> B >> K;
    for(int j = min(A, B); j > 0; j--){
        if((A % j == 0)&&(B % j == 0)){
            if(--K == 0){
                printf("%d\n\r", j);
                break;
            }
        }
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);

		int A = stdIn.nextInt();
		int B = stdIn.nextInt();

		if(A <= 8 && B <= 8)
		{
			System.out.println("Yay!");
		}
		else
		{
			System.out.println(":(");
		}

	}

}


Measured memory_bytes: 35552
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// 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>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)&&islower(c));}

struct S{
    char c;
    int y,x;
};

bool qemp(vector<queue<S>> q){
    rep(i,0,q.size())if(!q[i].empty())return true;
    return false;
}

signed main (){
    int v[4][4]={0};
    rep(i,0,3){
        int a,b;cin>>a>>b;a--;b--;
        v[a][b]=1;
        v[b][a]=1;
    }

    int a[]={0,1,2,3};
    do{
        // rep(i,0,4)cout<<a[i]<<" ";
        // cout<<endl;
        if(v[a[0]][a[1]]==v[a[1]][a[2]]&&v[a[1]][a[2]]==v[a[2]][a[3]]&&v[a[1]][a[2]]==1){
            cout<<"YES"<<endl;
            return 0;
        }
    }while(next_permutation(a,a+4));
    cout<<"NO"<<endl;
}
/*
*/


Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
#endif

#ifdef _DEBUG
void init_global_A() {}
#else

#endif

int main_A() {
    cin.tie(0);
    ios::sync_with_stdio(false);
     
    int A, B, C; cin >> A >> B >> C;

    int ans = A;
    if (A == B) ans = C;
    else if (A == C) ans = B;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_7_B&lang=jp
def cal_depth(binary_tree, target_index, depth, parent, sibling):
    if target_index == -1:
        return 0
    binary_tree[target_index]["depth"] = depth
    binary_tree[target_index]["parent"] = parent
    binary_tree[target_index]["sibling"] = sibling
    height_left = cal_depth(binary_tree, binary_tree[target_index]["left"], depth + 1, target_index, binary_tree[target_index]["right"])
    height_right = cal_depth(binary_tree, binary_tree[target_index]["right"], depth + 1, target_index, binary_tree[target_index]["left"])
    height = max(height_left, height_right)
    binary_tree[target_index]["height"] = height
    return height + 1

def solve(node_data, node_num):
    binary_tree = [{"left":-1, "right":-1, "depth":0, "parent":-1, "sibling":-1, "height":0, "degree":0} for a in range(node_num)]
    root_index = sum([i for i in range(node_num)])
    for node in node_data:
        binary_tree[node[0]]["left"] =  node[1]
        binary_tree[node[0]]["right"] =  node[2]

        if not node[1] == -1:
            root_index -= node[1]
            binary_tree[node[0]]["degree"] += 1
        if not node[2] == -1:
            root_index -= node[2]
            binary_tree[node[0]]["degree"] += 1
            
    cal_depth(binary_tree, root_index, 0, -1,-1)
    return binary_tree

def main():
    node_num = int(input())
    node_data = [[int(a) for a in input().split()] for i in range(node_num)]
    binary_tree = solve(node_data, node_num)

    for i, node in enumerate(binary_tree):
        node_type = "root"
        if node["left"] == -1 and node["right"] == -1 and not node["parent"] == -1:
            node_type = "leaf"
        elif not node["parent"] == -1:
            node_type = "internal node"
        print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(i, node["parent"], node["sibling"], node["degree"], node["depth"], node["height"], node_type))
if __name__ == "__main__":
    main()
    

Measured memory_bytes: 7872
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

const int N = 11;
int a[N], b[N];
int n;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, 1, n) {
        cin >> a[i];
    }
    rep(i, 1, n) {
        cin >> b[i];
    }
    rep(i, 1, n) {
        if(a[i] > b[i]) {
            rep(j, 1, n) {
                swap(a[j], b[j]);
            }
            break;
        } else if(a[i] < b[i]) {
            break;
        }
    }
    int ans = 0;
    do {
        bool same = true;
        rep(i, 1, n) {
            if(a[i] != b[i]) {
                same = false;
                break;
            }
        }
        if(same) {
            cout << ans << endl;
            return 0;
        }
        ans++;
    } while(next_permutation(a + 1, a + n + 1));
    return 0;
}


Measured memory_bytes: 256
N=int(input())
S=list(input())
A=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
newS=[]
for i in range(len(S)):
  for r in range(len(A)):
    if S[i]==A[r]:
      a=r+N
      if (r+N)%25==0 and (r+N)/25!=1 and (r+N)/25!=0:
        a=24
      
      elif r+N>25:
        d=(r+N)//25
        a=(r+N)%25-(1*d)
      newS.append(A[a])
for h in range(len(newS)):
  print(*newS[h],end='')

Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
  return 0;
}


Measured memory_bytes: 3608
<?php

fscanf(STDIN, '%d', $N);
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, '%d', $n);
    if ($i === 0) {
        $min = $n;
        continue;
    } elseif ($i === 1) {
        $profit = $n - $min;
        $prev = $n;
        continue;
    }

    if ($prev < $min) {
        $min = $prev;
    }

    $result = $n - $min;
    $prev = $n;

    if ($result > $profit) {
        $profit = $result;
    }
}

echo $profit, PHP_EOL;

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

struct edge {
    int from, to;
    int cost;
};

struct vert {
    vector<edge> edges;
};

bool warshallfloyd(
        vector<vector<long long>>& dist
        ) {
    for (int k = 0; k < dist.size(); ++k) {
        for (int i = 0; i < dist.size(); ++i) {
            for (int j = 0; j < dist.size(); ++j) {
                if (dist[i][k] == LONG_LONG_MAX || dist[k][j] == LONG_LONG_MAX) continue;
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    for (int i = 0; i < dist.size(); ++i) {
        if (dist[i][i] < 0) return false;
    }
    return true;
}

template<class T>
void printVector(const vector<T> &a, string delimiter) {
    if (a.size() == 0) return;
    if (a[0] == LONG_LONG_MAX) cout << "INF";
    else cout << a[0];
    for (int i = 1; i < a.size(); ++i) {
        cout << delimiter;
        if (a[i] == LONG_LONG_MAX) cout << "INF";
        else cout << a[i];
    }
    cout << endl;
}

int main() {
    int V, E;
    cin >> V >> E;
    vector<vector<long long>> dist(V, vector<long long>(V, LONG_LONG_MAX));
    for (int i = 0; i < E; ++i) {
        int a, b, cost;
        cin >> a >> b >> cost;
        dist[a][b] = cost;
    }
    for (int i = 0; i < V; ++i) {
        dist[i][i] = 0;
    }
    bool negative_cycle = !warshallfloyd(dist);
    if (negative_cycle) {
        cout << "NEGATIVE CYCLE" << endl;
        return 0;
    }
    for (const auto & v : dist) {
        printVector(v, " ");
    }
    return 0;
}



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

const int MAX_H = 1e4 + 1;
const int MAX_N = 1e3 + 1;
const int INF = 2e9;
vector<vector<int> > memo(MAX_N, vector<int>(MAX_H+1, INF));
vector<pair<int, int > > magic(MAX_N);

int dp (int i, int j) { // i個目まで使うときのjの最小魔力
    if (memo[i][j] == INF) {
        if (j == 0) {
            memo[i][j] = 0;
        } else if (i == 0) {
            memo[i][j] = dp(i, max(0, j-magic[i].first)) + magic[i].second;
        } else {
            memo[i][j] = min(dp(i-1, j), dp(i, max(0, j-magic[i].first)) + magic[i].second);
        }
    }
    return memo[i][j];
}

int main() {
    int H, N; cin >> H >> N;
    for (int i = 0; i < N; i++) {
        cin >> magic[i].first;
        cin >> magic[i].second;
    }
    cout << dp(N-1, H) << endl;
}


Measured memory_bytes: 40064
<?php
$S = trim(fgets(STDIN));  
$Q = trim(fgets(STDIN));
$front = "";
$back = "";
$turn = 0;
for($i=0; $i<$Q; $i++){
    $query = trim(fgets(STDIN));
    list($mode,$F,$word) = sscanf($query,"%d %d %s");
    if($mode == 1){
        if ($turn == 0){
            $turn = 1;
        }else{
            $turn = 0;
        }
    }else{
        if($turn == 0){
            if($F == 1){
                $front = $word.$front;
            }else{
                $back = $back.$word;
            }
        }else{
            if($F == 2){
                $front = $word.$front;
            }else{
                $back = $back.$word;
            }
        }

    }
}

$str = $front.$S.$back;
if($turn == 1){
    $str=strrev($str);
}
printf($str);

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

using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;

#define out(a) cout << a << endl
#define out1(a) cout << a
#define in(a) cin >> a
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define rep(i, N) for (ll i = 0; i < (ll)N; i++)
#define rep1(i, N) for (ll i = 1; i <= (ll)N; i++)
#define repi(i, j, N) for (ll j = (ll)i + 1; j < (ll)N; j++)
#define all(v) v.begin(), v.end()
#define pb(a) push_back(a)

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 inf = 1e9;
constexpr ll linf = 1e18;
constexpr ll mod = 1e9 + 7;
constexpr int MAX = 200020;

int par[MAX];
int ran[MAX];
int siz[MAX];

void init(int n)
{
    rep(i, n)
    {
        par[i] = i;
        ran[i] = 0;
        siz[i] = 1;
    }
}

int find(int x)
{
    if (par[x] == x)
    {
        return x;
    }
    else
    {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if (ran[x] < ran[y])
    {
        par[x] = y;
        siz[x] += siz[y];
        siz[y] = siz[x];
    }
    else
    {
        par[y] = x;
        siz[x] += siz[y];
        siz[y] = siz[x];
        if (ran[x] == ran[y])
        {
            ran[x]++;
        }
    }
}

bool same(int x, int y)
{
    return find(x) == find(y);
}

void solve()
{
    int n, m;
    in2(n, m);
    int a[m], b[m];
    rep(i, m)
    {
        in2(a[i], b[i]);
        a[i]--;
        b[i]--;
    }
    int ans = 0;
    rep(i, m)
    {
        init(n);
        rep(j, m)
        {
            if (i == j)
            {
                continue;
            }
            unite(a[j], b[j]);
        }
        if (!same(a[i], b[i]))
        {
            ans++;
        }
    }
    out(ans);
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  int n;
  cin >> n;
  ll ans = 0;
  for(ll i = 1; i <= n; i++) {
    if(i % 3 != 0 && i % 5 != 0) {
      ans += i;
    }
  }
  cout << ans;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
Int V, E, r, s, t, d;

vector<P> edge[1100000];

vector<Int> dijkstra(Int start)
{
    priority_queue<P,vector<P>, greater<P>> pq;
    vector<Int> dist(V,LINF);
    dist[start]=0;
    pq.push(P(dist[start],start));
    while(!pq.empty()){
        auto p= pq.top(); pq.pop();
        Int d=p.first;
        Int from =p.second;
        if(dist[from]<d) continue;
        for(auto nxt: edge[from]){
            Int to=nxt.first;
            Int c=nxt.second;
            if(dist[from]+c<dist[to]){
                dist[to]=dist[from]+c;
                pq.push(P(dist[to],to));
            }
        }
    }
    return dist;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> V >> E >> r;
    for (int i = 0; i < E; i++)
    {
        cin >> s >> t >> d;
        edge[s].push_back(P(t, d));
    }
    auto dist = dijkstra(r);
    for (int i = 0; i < V; i++)
    {
        if (dist[i] == LINF)
            cout << "INF" << endl;
        else
            cout << dist[i] << endl;
    }
    return 0;
}


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

#define ll long long
#define ull unsigned long long

using namespace std;

const ull MOD = 1000000007;

int main() {
	string S;
	cin >> S;
	int Q;
	cin >> Q;

	int rev = 0;
	for (int ii = 0; ii < Q; ++ii){
		int T;
		cin >> T;
		if (T == 1){
			rev = (rev + 1) % 2;
		}
		if (T == 2){
			int F;
			string C;
			cin >> F >> C;

			if (F == 1){
				if (rev == 0){
					S.insert(0, C);
				} else {
					S.append(C);
				}
			}
			if (F == 2){
				if (rev == 0){
					S.append(C);
				} else {
					S.insert(0, C);
				}
			}
		}
	}

	if (rev == 1){
		reverse(S.begin(), S.end());	
	}

	cout << S << endl;

	return 0;
}


Measured memory_bytes: 900
#include <iostream>
//#include <iomanip>
#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
//using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	string s ; cin >> s ;
	int cnt = 0 ;
	for(int i=1;i<s.size();i++) if(s.at(i)!=s.at(i-1)) cnt++ ;
	cout << cnt << endl ;
}


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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

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

#ifdef DEBUG
#define DBG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll H, W, M;

    cin >> H >> W >> M;
    vector<ll> horizon(H,0);
    vector<ll> virtical(W,0);
    set<pair<ll,ll>> bombs;

    REP(i, M){
        ll h, w;
        cin >> h >> w;
        horizon[h-1]++;
        virtical[w-1]++;
        bombs.insert(make_pair(h-1,w-1));
    }

    ll h_max = 0;
    vector<size_t> h_indexes;
    REP(i, H){
        if( h_max == horizon[i] ){
            h_indexes.push_back(i);
        }
        if( h_max < horizon[i] ){
            h_indexes.clear();
            h_max = horizon[i];
            h_indexes.push_back(i);
        }
    }

    ll w_max = 0;
    vector<size_t> w_indexes;
    REP(i, W){
        if( w_max == virtical[i] ){
            w_indexes.push_back(i);
        }
        if( w_max < virtical[i] ){
            w_indexes.clear();
            w_max = virtical[i];
            w_indexes.push_back(i);
        }
    }

    if( w_indexes.size() * h_indexes.size() > M ){
        cout << h_max+w_max << endl;
        return 0;
    }else{
        REP(i, h_indexes.size()){
        REP(j, w_indexes.size()){
            if( bombs.find(make_pair(h_indexes[i],w_indexes[j])) == bombs.end() ){
                cout << h_max+w_max << endl;
                return 0;
            }
        }
        }
    }

    cout << h_max+w_max - 1<< endl;
}


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

int main() {

  long long int n, m;
  cin >> n >> m;

  if ( n * 2 >= m ) {
    cout << m / 2 << endl;
  }else {
    cout << n + ( m - n * 2 ) / 4 << endl;
  }

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

/* modとる */
inline ll modu(ll a){
    return(a % mod + mod) % mod;
}

/* modつき二分累乗法 */
ll modpow(ll a, ll b) {
    ll res = 1;
    for (a = modu(a); b; a = modu(a * a) , b >>= 1){
        if (b & 1) res = modu(res * a);
    }
    return res;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int H=in(),W=in(),K=in();
    vector<vector<int>> S(H+1,vector<int>(W+1));
    REP(i,H+1){
        REP(l,W+1){
            if(i == 0){
                S[i][l] = 0;
            }else if(l == 0){
                S[i][l] = 0;
            }else{
                S[i][l] = S[i-1][l]+S[i][l-1]-S[i-1][l-1] + (in<char>() == '1' ? 1 : 0);
            }
        }
    }
    int answer =INT32_MAX-50;
    vector<int> where;
    REP(i,modpow(2,H-1)){
        int tmpe = i;
        where.assign(1,false);
        int counn = 0;
        while(tmpe != 0){
            if(tmpe % 2 == 1)where.push_back(counn+1);
            counn++;
            tmpe = tmpe >> 1;
        }
        where.push_back(H);
        int point = 0;
        int beforecut = 0;
        REP(i,W){
            bool out = 0;
            REP(l,where.size()-1){
                if(S[where[l+1]][i+1] - S[where[l]][i+1] - S[where[l+1]][beforecut] + S[where[l]][beforecut] > K){
                    if(beforecut == i){
                        out = 1;
                        break;
                    }
                    beforecut = i;
                    point++;
                    break;
                }
            }
            if(out){
                point = INT32_MAX-50000;
                break;
                }
        }
        int wheresize = where.size();
        answer = min(answer,point + wheresize-2);
    }
    cout << answer << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i,j,k;
  
  int r,D,x;
  
  scanf("%d %d %d",&r,&D,&x);
  
  for(i=0;i<10;i++){
    x = r*x - D;
    printf("%d\n",x);
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <bitset>
#include <limits.h>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF (LL)1e15
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

//#define int long long

/*************** using variables ***************/
int x;
/**********************************************/

signed main(){
    cin >> x;

    string ans = "ai1333";
    cout << ans;
    REP(i, x/100){
        cout << "3";
    }

    cout << endl;
    
}



Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out, n) for(int i=0; i<n; i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

int main(){
    
    int K;
    cin >> K;
 
    if (K == 1) {
        cout << "1"<<endl;;
        return 0;
    }
    if (K % 2 == 0 || K % 5 == 0) {
        cout << "-1"<<endl;;
        return 0;
    }
    K *= 9;
    int a = 10;
    for (int i = 0; i <= 10 * K; i++) {
        if ((7 * (a - 1 + K)) % K == 0) {
            cout << i + 1 << endl;;
            return 0;
        }
        a = (a * 10) % K;
    }
   
}

Measured memory_bytes: 3600
#include<iostream>
#include<string.h>
using namespace std;
int main(){
  string str;
  cin>>str;
 
  str.erase(4,1);
    str.erase(6,1);

 if(stoi(str)<=20190430){
 cout<<"Heisei"<<endl;
 }else{
  cout<<"TBD"<<endl;
 }
return 0;
}

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

int main() {
    int n , maxw;
    cin>>n>>maxw;
    
    int weight[n];
    int value[n];
    for(int i = 0;i<n;i++){
        cin>>weight[i];
        cin>>value[i];
    }
    
    ll dp[n+1][maxw + 1];
    
    for(int i = 0 ;i<=n;i++){
        for(int j = 0;j<=maxw;j++){
            if(i==0 || j==0) dp[i][j] = 0;
            else if (weight[i-1]<=j){
                dp[i][j] = max(value[i-1] + dp[i-1][j-weight[i-1]] , dp[i-1][j]);
            }
            else dp[i][j] = dp[i-1][j];
        }
    }
    
    cout<<dp[n][maxw]<<endl;
	return 0;
}

Measured memory_bytes: 79104
import java.util.*;

class Main{

	public static void main(String[]$){
		var s=new Scanner(System.in);
		long r=0;
		for(int i=s.nextInt();i>0;--i) {
			if(i%3!=0&&i%5!=0)
				r+=i;
		}
		System.out.println(r);
	}
}

Measured memory_bytes: 35752
#include <iostream>
#include<string.h>
using namespace std;

int main()
{
	char S[1100];
	cin >> S;
	
	for(int i=0; i<strlen(S); i++){
		if(S[i] == '1'){
			cout << 9;
		}else{
			cout << 1;
		}
	}
	cout << endl;
	
	return 0;
}


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

/**
 * @author:26019
 */
public class Main {

    public static void main(String[] args) throws Exception {
        solve();
    }

    private static long gcd(long x, long y) {
        if (y == 0) return x;
        return gcd(y, x % y);
    }

    private static int cal(int x) {
        int res = 1;
        while (x != 1) {
            if ((x & 1) == 1) {
                x = x * 3 + 1;
            } else {
                x >>= 1;
            }
            res++;
        }
        return res;
    }

    private static void solve() throws Exception {
        FastScanner cin = new FastScanner();
        int a = cin.nextInt(), b = cin.nextInt();
        int res = b * 2 > a ? 0 : a - 2 * b;
        System.out.println(res);
    }


    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        FastScanner() throws IOException {
        }

        public String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        private void close() {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}


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

int gcd (int x, int y){
    if (y == 0) return x;
    return gcd (y, x % y);
}
int main(){
    int n, y;
    cin >> n >> y;
    for (int i = 0; i <= n; i++){
        for (int j = 0; i + j <= n; j++){
            if (10000 * i + 5000 * j + 1000 * (n - i - j) == y){
                cout << i << " " << j << " " << n - i - j << endl;
                exit(0);
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}

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

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n;
  map<ll, int> mp;
  cin >> n;
  bool ok = true;
  rep(i,n) {
    ll a;
    cin >> a;
    if (mp.count(a) == 0) mp[a] = 0;
    else {
      mp[a]++;
      ok = false;
    }
  }
  if (ok) cout << "YES\n";
  else cout << "NO\n";
  return 0;
}

Measured memory_bytes: 12800
// Problem: C - Connect Cities
// Contest: AtCoder - ACL Beginner Contest
// URL: https://atcoder.jp/contests/abl/tasks/abl_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define ll long long int
#define ii int
#define du double
#define jmp "\n"
#define vl vector<ll>
#define vvl vector<vl>
#define pb push_back
#define printv(v)     \
  for (auto x : v)    \
    cout << x << " "; \
  cout << jmp;
#define vi vector<int>
#define vb vector<bool>
#define ump unordered_map
#define SORT(v) sort(v.begin(), v.end())
#define REV(x) reverse(x.begin(), x.end())
#define all(x) x.begin(), x.end()
#define SET(x, a) memset(x, a, sizeof(x))
#define si(x) x.size()
#define ff first
#define ss second
#define iin insert
#define deb(x) cout << "test " << #x << "=" << x << jmp
#define deb2(x, y) cout << "test " << #x << "=" << x << "," << #y << "=" << y << jmp
using namespace std;
const ll nax = 1e5 + 5;
vl g[nax];
vb vis(nax);
void dfs(ll u)
{
  vis[u] = 1;
  for (auto x : g[u])
  {
    if (!vis[x])
      dfs(x);
  }
}
void solve()
{
  ll n, m, ctr = 0;
  cin >> n >> m;
  for (ll i = 0; i < m; i++)
  {
    ll u, v;
    cin >> u >> v;
    u--, v--;
    g[u].pb(v);
    g[v].pb(u);
  }
  fill(all(vis), 0);
  for (ll i = 0; i < n; i++)
    if (!vis[i])
    {
      dfs(i);
      ctr++;
    }
  cout << ctr - 1 << jmp;
}
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}

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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);


template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll HIGHINF = (ll)1e18;
const ll LOWINF = (ll)1e15;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	ll N,L; cin >> N >> L;
	V<ll> a(N); REP(i,N) cin >> a[i];
	priority_queue<P<ll,ll>,V<P<ll,ll>>, greater<P<ll,ll>> > pq;
	if(a[0]>a[1]) pq.push({0,0});
	for(int i = 1; i < N-1; ++i) if(a[i-1]<a[i]&&a[i]>a[i+1]) pq.push({0,i});
	if(a[N-2]<a[N-1]) pq.push({0,N-1});

	ll ans = 0;
	while(pq.size()){
		ll t = pq.top().first;
		ll idx = pq.top().second;
		pq.pop();
		ll diff = L - a[idx];
		chmax(ans,t + diff);
		a[idx] = 0;

		if(0<=idx-1){
			int flg = 1;
			if(0<=idx-2&&a[idx-2]>a[idx-1]) flg = 0;
			if(flg&&a[idx-1]) pq.push({t + diff,idx-1});
		}
		if(idx+1<N){
			int flg = 1;
			if(idx+2<N&&a[idx+1]<a[idx+2]) flg = 0;
			if(flg&&a[idx+1]) pq.push({t + diff,idx+1});
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 4656
#!python3

# input
N = int(input())
A = [0] + list(map(int, input().split())) + [0]


def main():
    s = sum([abs(A[i - 1] - A[i]) for i in range(N + 2)])
    for i in range(N):
        a = abs(A[i + 2] - A[i])
        d = abs(A[i + 1] - A[i]) + abs(A[i + 2] - A[i + 1])
        ans = s - d + a
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14044
S = input()
K = int(input())
L = len(S)

arr = [S[:j] for j in range(1, min(K, L)+1)]
for i in range(1, L):
  arr2 = [S[i:i+j] for j in range(1, min(K, L-i)+1)]
  arr = sorted(set(arr + arr2))
  arr = arr[:min(K, len(arr))]

print(arr[K-1])

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  ll N,M;
  cin>>N>>M;
  vector<ll> A(N),B(M);
  for(ll i = 0; i < N; i++) cin>>A[i];
  for(ll i = 0; i < M; i++) cin>>B[i];
  bool can = true;
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  for(ll i = 0; i < N-1; i++) {
    if(A[i]==A[i+1]) can = false;
  }
  for(ll i = 0; i < M-1; i++) {
    if(B[i]==B[i+1]) can = false;
  }
  ll ans = 1;
  for(ll i = N*M; i > 0; i--){
    auto itea = lower_bound(A.begin(),A.end(),i);
    auto iteb = lower_bound(B.begin(),B.end(),i);
    ll wa,wb;
    if(*itea!=i&&*iteb!=i) {
      wa =(ll) (A.end()-itea);
      wb = (ll)(B.end()-iteb);
      ans=(ans*(wa*wb-(N*M-i)))%mod;
    }
    else {
      if(*itea==i){
        wa=1LL;
      }
      else {
        wa =(ll)(A.end()-itea);
      }
      if(*iteb==i){
        wb=1LL;
      }
      else{
        wb=(ll)(B.end()-iteb);
      }
      ans=(ans*wa*wb)%mod;
    }
  }
  if(can)cout<<ans<<endl;
  else cout<<0<<endl;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

bool red[100*1000+1];
int num[100*1000+1];
int main() {
	red[1]=true;
	int N,M;
	cin >> N >> M;
	for(int i=1;i<=N;i++){
		num[i]++;
	}
	for(int i=0;i<M;i++){
		int x,y;
		cin >> x >> y;
		red[y]|=red[x];
		num[y]++;
		num[x]--;
		if(num[x]==0){
			red[x]=false;
		}
	}
	int ret=0;
	for(int i=1;i<=N;i++){
		if(red[i]){
			ret++;
		}
	}
	cout << ret << endl;
}


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

int arr[300][300] = {};
int tmp[310] = {};

int main(void){
    
    int n,m;
    cin >> n >> m;
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> arr[i][j];
        }
    }
    
    int res = n;
    
    for(int i = 0; i < m; i++){
        
        /*
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                cout <<  arr[i][j] << " ";
            }
            cout << endl;
        }
        cout << endl;
        */
        for(int j = 0; j < 301; j++){
            tmp[j] = 0;
        }
        for(int j = 0; j < n; j++){
            tmp[arr[j][0]]++;
        }
        int t = 0;
        for(int j = 0; j < 301; j++){
            if(tmp[j] > tmp[t]){
                t = j;
            }
        }
        
        res = min(tmp[t],res);
        
        for(int j = 0; j < n; j++){
            bool f = false;
            for(int k = 0; k < m; k++){
                if(arr[j][k] == t){
                    arr[j][k] = 0;
                    f = true;
                }
                if(f){
                    arr[j][k] = arr[j][k+1];
                }
            }
        }
    }
    
    cout << res << endl;
    
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,t,f,ans;
double a[200001];
map<pair<int,int>,int> m;
signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lf",&a[i]);
		int b=llround(a[i]*1000000000);
		t=f=-9;
		while(b%2==0)
		{
			b/=2;
			t++;
		}
		while(b%5==0)
		{
			b/=5;
			f++;
		}
		m[make_pair(t,f)]++;
	}
	for(auto i:m)
		for(auto l:m)
			if(i.first.first+l.first.first>=0&&i.first.second+l.first.second>=0)
			{
				if(i==l)
					ans+=i.second*(i.second-1)/2;
				if(i<l)
					ans+=i.second*l.second;
			}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5328
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

sum = 0
for i in range(n-1):
    sum+=b_list[a_list[i] - 1]
    if a_list[i+1] - a_list[i] == 1:
        sum+=c_list[a_list[i] - 1]
sum+=b_list[a_list[-1] - 1]

print(sum)


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>
#include<math.h>

typedef int32_t i32;

void run (void) {
  i32 n, k;
  scanf ("%" SCNi32 "%" SCNi32, &n, &k);
  double ans = 0;
  for (i32 i = 1; i <= n; ++i) {
    i32 t = i;
    double p = 1;
    while (t < k) {
      t *= 2;
      p *= 0.5;
    }
    ans += p;
  }
  printf ("%.10f\n", ans / n);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  int high[1001];
  rep(i,1000){
    high[i] = high[i-1] + i;
  }
  int a,b;
  cin >> a >> b;
  cout << high[b-a] - b;
}

Measured memory_bytes: 3596
n=int(input())
dp=[[0]*19 for _ in range(19)]
ans=0
for _ in range(n):
  a=round(float(input())*10**9)
  f,t=0,0
  while a%2==0:
    t+=1
    a//=2
  while a%5==0:
    f+=1
    a//=5
  t,f=min(t,18),min(f,18)
  ans+=dp[18-t][18-f]
  for i in range(t+1):
    for j in range(f+1):
      dp[i][j]+=1
print(ans)

Measured memory_bytes: 75524