akhauriyash/Code-Regression huggingface dataset:
package main

import "fmt"

/*
展開図の展開の仕方を固定して、回転動作によってどのように展開図の数字が移るかを記録する。
展開図は次の通り。手前の目2番を中心に据える展開の仕方。
         ___
    ____|_1_|_______
    |_4_|_2_|_3_|_5_|
        |_6_|

サイコロの状態は上面と前面を指定することで一意に決定される。それぞれを指定された目に揃えて、
展開図の3番を記録。
入力された二つのサイコロについて上面前面を揃えた上で右側面の値を比較することで判定。
で、できるかと思ったが、サイコロの各面の数字がすべて異なるという制約は今回の問題にはないので、
この判定方法は不完全。

よって、力ずくで全通り調べる。
*/

type Dice struct {
	Nums []int
}

func (d *Dice) rotate(direction string, times int) {
	times %= 4
	switch direction {
	case "W":
		for i := 0; i < times; i++ {
			d.Nums[0], d.Nums[2], d.Nums[5], d.Nums[3] = d.Nums[2], d.Nums[5], d.Nums[3], d.Nums[0]
		}
	case "E":
		for i := 0; i < times; i++ {
			d.Nums[0], d.Nums[2], d.Nums[5], d.Nums[3] = d.Nums[3], d.Nums[0], d.Nums[2], d.Nums[5]
		}
	case "N":
		for i := 0; i < times; i++ {
			d.Nums[0], d.Nums[4], d.Nums[5], d.Nums[1] = d.Nums[1], d.Nums[0], d.Nums[4], d.Nums[5]
		}
	case "S":
		for i := 0; i < times; i++ {
			d.Nums[5], d.Nums[1], d.Nums[0], d.Nums[4] = d.Nums[1], d.Nums[0], d.Nums[4], d.Nums[5]
		}
	}
}

func (d *Dice) roll(direction string, times int) {
	times %= 4
	switch direction {
	case "R":
		for i := 0; i < times; i++ {
			d.Nums[3], d.Nums[1], d.Nums[2], d.Nums[4] = d.Nums[1], d.Nums[2], d.Nums[4], d.Nums[3]
		}
	case "L":
		for i := 0; i < times; i++ {
			d.Nums[3], d.Nums[1], d.Nums[2], d.Nums[4] = d.Nums[4], d.Nums[3], d.Nums[1], d.Nums[2]
		}
	}
}

func (d *Dice) printStatus() {
	status :=
`	　　　 _ _ _ _
     _ _ _|_%3d_|_ _ _ _ _ _
    |_%3d_|_%3d_|_%3d_|_%3d_|
 　       |_%3d_|
`
	fmt.Printf(status, d.Nums[0], d.Nums[3], d.Nums[1], d.Nums[2], d.Nums[4], d.Nums[5])
	fmt.Println()
}

func getIndex(nums []int, target int) (index int) {
	for i, v := range nums {
		if target == v {
			index = i
			break
		} else {
			index = -1
		}
	}
	return index
}

func (d *Dice) isEqual(other Dice) bool {
	for i, v := range d.Nums {
		if v != other.Nums[i] {
			return false
		}
	}
	return true
}

func main() {
	dice1 := Dice{
		make([]int, 6),
	}
	dice2 := Dice{
		make([]int, 6),
	}
	for i := 0; i < 6; i++ {
		var n int
		fmt.Scan(&n)
		dice1.Nums[i] = n
	}
	for i := 0; i < 6; i++ {
		var n int
		fmt.Scan(&n)
		dice2.Nums[i] = n
	}

	directionOrder := []string{"N", "S", "W", "E"}
	rollOrder := []string{"R", "L"}
	flag := false

	CHECK:
		for i := 0; i <= 2; i++ {
			for j := 0; j <= 2; j++ {
				for _, direction := range directionOrder {
					for _, roll := range rollOrder {
						tmp := new(Dice)
						tmp.Nums = append([]int{}, dice2.Nums...)
						tmp.rotate(direction, i)
						tmp.roll(roll, j)
						if tmp.isEqual(dice1) {
							flag = true
							break CHECK
						}
					}
				}
			}
		}
	if flag {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}



Measured memory_bytes: 1156
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());

		int[] stu = new int[n];

		for (int i = 0; i < n; i++) {
			stu[sc.nextInt() - 1] = i;
		}

		for (int i = 0; i < n; i++) {
			System.out.print(i == 0 ? "" : " ");
			System.out.print(stu[i]+1);
		}
		System.out.println();

	}
}

Measured memory_bytes: 60056
n = int(input())
li = list()
for i in range(n):
    a, b = [int(x) for x in input().split()]
    li.append([a,b])

count = 0
for i in li:
    if count < 3:
        if i[0] == i[1]:
            count += 1
        else:
            count = 0
    else:
        break

if count >= 3: print('Yes')
else: print('No')

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

using _i64 = int64_t;
using _u64 = uint64_t;
using _f64 = double;

#define endl "\n"

#define _for(i, start, end) for(_i64 i = (_i64)start; i < (_i64)end; ++i)
#define _rep(i, number) _for(i, 0, number)
#define _foreach(e, data) for(auto& e : data)
#define _all(data) data.begin(), data.end()

template<typename type>
_i64 _size(const type& data) { return static_cast<_i64>(data.size()); }
template<typename type, size_t size>
_i64 _size(const type (&)[size]) { return static_cast<_i64>(size); }

enum _flag : bool { able = true, disable = false };

struct _time {
    _time(_flag flag) { check = flag; if(!check) { return; } gettime(start); }
    ~_time() {
        if(!check) { return; }; gettime(end);
        _i64 elapse = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cout << endl << "Time: " << elapse << " ms" << endl;
    }
    private:
    using _timer = chrono::time_point<chrono::system_clock>;
    _timer start, end; bool check;
    void gettime(_timer& time) { time = chrono::system_clock::now(); }
};

struct _ini { _ini() { ios::sync_with_stdio(false); cin.tie(nullptr); } } _ini;

int main() {
    {
        _time time(disable);
        _i64 q, query, element1, element2; deque<_i64> A; cin >> q;
        _rep(i, q) {
            cin >> query;
            switch(query) {
                case 0:
                    cin >> element1 >> element2;
                    switch(element1) {
                        case 0: A.push_front(element2); break;
                        case 1: A.push_back(element2); break;
                    }
                    break;
                case 1:
                    cin >> element1;
                    cout << A[element1] << endl;
                    break;
                case 2:
                    cin >> element1;
                    switch(element1) {
                        case 0: A.pop_front(); break;
                        case 1: A.pop_back(); break;
                    }
                    break;
            }
        }
    }
    return 0;
}


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

#define 	pi 				3.1415926536
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(ll i = a ; i < b ; i++)
#define     repn(i, a, b)   for(ll i = a ; i > b ; i--)
#define 	mod1 			1000003
#define     mod2            998244353
#define     inf             2e18
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define     sz              size()
#define     len             length()
#define 	F 				first
#define 	S 				second
#define 	PB 				push_back
#define 	MP				make_pair
#define 	B 				begin()
#define     RB              rbegin()
#define 	E 				end()
#define     UB              upper_bound
#define     LB              lower_bound
#define     present(k, m)   (m.find(k)!=m.end())?1:0
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define     pll             pair<ll, ll>
#define     vll             vector<ll>
#define     vpll            vector<pll>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	print3(a) 		for(auto i : a)cout<<i<<nl;
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


/*############################# DSU ##############################*/
vll parent(1e5), Size(1e5), Rank(1e5);

void make_set(ll v){
    parent[v]=v;
    Size[v] = 1;
    // Rank[v] = 0;
}

int find_set(ll v){
    return (parent[v]==v) ?  v : parent[v] = find_set(parent[v]);
}

void union_sets(ll a, ll b){
    a = find_set(a);
    b = find_set(b);
    if(a != b){
        if(Size[a] < Size[b])
            swap(a, b);
        // if(Rank[a] < Rank[b])
        //     swap(a, b);
        parent[b] = a;
        Size[a] += Size[b];
        // if(Rank[a] == Rank[b])
        //     Rank[a]++;
    }
}
/*############################# DSU ##############################*/


bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }

bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }

double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }

vll pwx(32);
void cal(ll x){ pwx[0] = 1; rep(i, 1, 32)pwx[i] = x*pwx[i-1]; }

/* ################################################################ */

void solve()
{
    string s, t; cin>>s>>t;
    if(s == t.substr(0, s.len)){
        cout<<"Yes\n";
    }
    else cout<<"No\n";
}


int main()
{
    // boost;
    cal(2);
    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}

Measured memory_bytes: 5404
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = list(map(int, input().split()))
a = [None]*n
d = [None]*n
from collections import Counter
for i in range(n):
    a[i] = list(map(lambda x: int(x)-1, input().split()))
    d[i] = a[i][0]

ans = float("inf")
used = [True] * m
num = m
while True:
    c = Counter(d)
#     print(c, used)
    mv, mk = max((v,k) for k,v in c.items())
#     print(mv, mk)
    ans = min(ans, mv)
    used[mk] = False
    num -= 1
    if num==0:
        break
    for i in range(n):
        if not used[d[i]]:
            for j in range(m):
                if used[a[i][j]]:
                    d[i] = a[i][j]
                    break
print(ans)

Measured memory_bytes: 75616
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
#include <set>
#include <numeric>
using namespace std;
using ll = long long;
using ld = long double;

const ll MOD = 998244353;
const ld PI = acos((long double)(-1));

#define no "no"
#define No "No"
#define NO "NO"
#define yes "yes"
#define Yes "Yes"
#define YES "YES"
#define next '\n'
#define sp " "
#define print(x) cout << (x) << endl;
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(elem, _list) for(auto& (elem) : (_list))
#define view(_list) foreach(e, _list){ cout << e << sp; } cout << next
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define ALL(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e)
#define INF 1e+9
#define EPS 0.00000001

int main() {
    FAST;

    int x, n;
    cin >> x >> n;
    vector<int> p(110);
    vector<bool> b(110);
    rep(i, n){
        cin >> p[i];
        b[p[i]] = true;
    }
    
    for(int i = 0; i <= 101; ++i){
        int l = x - i;
        int r = x + i;

        if(!b[l]){
            print(l);
            break;
        }

        if(!b[r]){
            print(r);
            break;
        }
    }
}


Measured memory_bytes: 3652
import java.util.Scanner;
 
class Main {
	int a;
	int b;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
		sc.close();
	}
	Main(Scanner sc){
		a = sc.nextInt();
		b = sc.nextInt();
	}
	void solve(){
		int cnt = 0;
		for(int i=a;i<=b;i++){
			if(i/10000==i%10){
				if((i/1000)%10==(i%100)/10){
					cnt++;
				}
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
//size_t f = string::npos
//make pair, tuple

int main(){
      string s;cin >> s;
      map<char, int> m;
      int n = s.length();
      int ans = 0;
      for(int i = 0;i < n;i++){
            m[s[i]]++;
            if(m[s[i]] & 1)ans++;
            else ans--;
      }
      if(ans == 0)cout << "Yes";
      else cout << "No";
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import itertools
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#A
r = I()
g = I()
print(2*g-r)

Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <utility>
#include <iterator>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
using namespace std; 
  
typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<pii> vii; 
typedef vector<ll> vl; 
typedef vector<vl> vvl; 

#define IOS ios_base::sync_with_stdio(false);\
        cin.tie(0);\
        cout.tie(0);
#define endl "\n"  
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) 
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a)) 
#define FOREACH(a, b) for (auto&(a) : (b)) 
#define rep(i, n) FOR(i, 0, n) 
#define repn(i, n) FORN(i, 1, n) 
#define RESET(a, b) memset(a, b, sizeof(a)) 
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back 
#define ALLA(arr, sz) arr, arr + sz 
#define all(c) c.begin(),c.end()
#define SORT(v) sort(all(v)) 
#define REVERSE(v) reverse(all(v)) 
#define SORTA(arr, sz) sort(ALLA(arr, sz)) 
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) 
#define PERMUTE next_permutation 
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container),element) != container.end())
#define w(x)   int x; cin>>x; while(x--)
#define sz(a) int((a).size())
#define ps(x,y)         fixed<<setprecision(y)<<x
int main()
{
	IOS;
	ll items,W;
	cin>>items>>W;
	vl dp(W+1);
	//dp[i]-> max value with weight i
	for(int i=0;i<items;i++)
	{
		ll weight,value;
		cin>>weight>>value;
		for(int j=W-weight;j>=0;j--)
		{
			dp[j+weight]=max(dp[j+weight],dp[j]+value);
		}
	}
	ll answer=0;
	for(auto xh:dp)
	{
		answer=max(answer,xh);
	}
	cout<<answer;
		
		
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdio>
using namespace std;

typedef pair<int,int> pii;

int func(vector<pii> v){
	sort(v.begin(), v.end());
	int s = 0;
	for(size_t i = 0; i < v.size(); ++i){
		if(s < v[i].first){ return -1; }
		s += v[i].second;
	}
	return s;
}

bool solve(){
	int n;
	cin >> n;
	vector<string> s(n);
	for(int i = 0; i < n; ++i){
		cin >> s[i];
	}
	
	vector<pii> pos, neg;
	for(int i = 0; i < n; ++i){
		int c = 0, m = 0;
		for(size_t j = 0; j < s[i].size(); ++j){
			if(s[i][j] == '('){
				++c;
			}
			else{
				--c;
				m = min(m, c);
			}
		}
		
		if(c >= 0){
			pos.push_back(pii(-m, c));
		}
		else{
			neg.push_back(pii(c - m, -c));
		}
	}

	int a = func(pos), b = func(neg);
	return a >= 0 && a == b;
}

int main(){
	puts(solve() ? "Yes" : "No");
}


Measured memory_bytes: 46196
#include <iostream>

int main(void)
{
    int N;
    std::cin >> N;

    switch(N % 28)
    {
        case 0:
        case 4:
        case 7:
        case 8:
        case 11:
        case 12:
        case 14:
        case 15:
        case 16:
        case 18:
        case 19:
        case 20:
        case 21:
        case 22:
        case 23:
        case 24:
        case 25:
        case 26:
        case 27:
            std::cout << "Yes" << std::endl;
            break;
        default:
            std::cout << "No" << std::endl;
            break;
    }

    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var ok = false
    for (i in 0..n/4){
        for(k in 0..n/7){
            if(4*i + 7*k == n) ok = true
        }
    }
    if(ok) println("Yes") else println("No")
}

Measured memory_bytes: 31580
#include <iostream>
#include <string>
#define ll long long int

using namespace std;

int main(){
    string s;
    cin >> s;

    int len = s.length();

    if(len == 2){
        if(s[0] == s[1])
            cout << "1 2"<< endl;
        else
            cout << "-1 -1" << endl;
    }
    else{
        bool flag=false;
        int a=0;
        int b=0;
        for(int i=0; i<=len-2; i++){
            if(s[i] == s[i+1] || s[i] == s[i+2]){
                flag = true;
                a = i+1;
                b = i+3;
                break;
            }
        }
        if(s[len-2] == s[len-1]){
            flag = true;
            a = len-2;
            b = len;
        }

        if(flag) cout << a << " " << b <<endl;
        else cout << "-1 -1" <<endl;
    }
    


    return 0;
}

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

int compare(std::string a, std::string b)
{
    for(int i = 0; i < a.size() && i < b.size(); ++i){
        if(a[i] > b[i]) return 1;
        if(a[i] < b[i]) return -1;
    }
    if(a.size() == b.size()) return 0;
    if(a.size() >  b.size()) return 1;
    return -1;
}

int main()
{
    int taro = 0;
    int hana = 0;
    int n;
    std::cin >> n;
    for(int i = 0; i < n; i++){
        std::string t;
        std::string h;
        std::cin >> t >> h;
        // if(compare(t,h) < 0){
        if(t.compare(h) < 0){
            hana += 3;
        }else
        // if(compare(t,h) > 0){
        if(t.compare(h) > 0){
            taro += 3;
        }else{
            hana += 1;
            taro += 1;
        }
    }
    std::cout << taro << " " << hana << std::endl;
    return 0;
}

Measured memory_bytes: 3164
///****In the name of Allah, most Gracious, most Compassionate****//

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

#define NL cout<<"\n";
#define ALL(a) a.begin(), a.end()
#define DBG(a) cout<< #a <<" --> "<<(a)<<endl;
#define FastIO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define IN freopen("input.txt","r+",stdin)
#define OUT freopen("output.txt","w+",stdout)

template < class T1,class T2>
ostream &operator <<(ostream &os,const pair < T1,T2 > &p)
{
    os<<"{"<<p.first<<","<<p.second<<"}";
    return os;
}

const int N=3e5+5;
const int oo=1e9+7;




typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<PII> VPII;

//#define STRICTLY_INCREASNG

int LongestIncreasingSubsequence(VI v) {
  VPII best;
  VI dad(v.size(), -1);

  for (int i = 0; i < v.size(); i++) {
#ifdef STRICTLY_INCREASNG
    PII item = make_pair(v[i], 0);
    VPII::iterator it = lower_bound(best.begin(), best.end(), item);
    item.second = i;
#else
    PII item = make_pair(v[i], i);
    VPII::iterator it = upper_bound(best.begin(), best.end(), item);
#endif
    if (it == best.end()) {
      dad[i] = (best.size() == 0 ? -1 : best.back().second);
      best.push_back(item);
    } else {
      dad[i] = it == best.begin() ? -1 : prev(it)->second;
      *it = item;
    }
  }

  VI ret;
  for (int i = best.back().second; i >= 0; i = dad[i])
    ret.push_back(v[i]);
  reverse(ret.begin(), ret.end());
  return ret.size();
}


int32_t main()
{
    FastIO;
    int n;
    cin>>n;
    VI v;
    while(n--)
    {
        int x;
        cin>>x;
        v.push_back(-x);
    }
    cout<<LongestIncreasingSubsequence(v)<<"\n";
}


Measured memory_bytes: 3188
def main():
    N, X = map(int, raw_input().split())
    co = map(int, raw_input().split())
    D = 0
    for coo in co:
        dist = abs(coo - X)
        if D!=0:
            D = gcd(dist,D)
        else:
            D = dist
    print(D)

def gcd(a, b):
    """Calculate the Greatest Common Divisor of a and b.

    Unless b==0, the result will have the same sign as b (so that when
    b is divided by it, the result comes out positive).
    """
    while b:
        a, b = b, a%b
    return a

if __name__ == '__main__':
    main()


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

using namespace std;

int main(){
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a;
    for (int i = 0; i < n; i++)
        a.push_back(k);

    for (int i = 0; i < q; i++){
        int x;
        cin >> x;
        a[x - 1]--;
    }

    for (int i = 0; i < n; i++){
        if (2*k - a[i] - q > 0){
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    //for (int i = 0; i < n; i++){
    //    if (a[i] )
    //}
    return 0;
}

/*

    if (a[i] - k + 1 >= 0)
            cout << "Yes" << endl;
        else cout << "No" << endl;

*/


Measured memory_bytes: 1144
#include <stdio.h>          // printf(), scanf()
#include <stdlib.h>         // qsort()
#include <math.h>           // fabs()
#include <stdbool.h>

#define MAX_N 1000

typedef struct rbmi_tbl
{
	int p;
	double rbmi;
} rbmi_t;

int
cmp_func(const void *l_, const void *r_)
{
	const rbmi_t *l = (const rbmi_t*) l_;
	const rbmi_t *r = (const rbmi_t*) r_;

	if (l->rbmi < r->rbmi)
		return -1;

	if (l->rbmi > r->rbmi)
		return 1;

	if (l->p < r->p)
		return -1;

	if (l->p > r->p)
		return 1;

	return 0;
}

int
main(int argc, char **argv)
{
	int n;
	rbmi_t rbmi[MAX_N];
	int h, w;
	double m;

	while (true)
	{
		scanf("%d", &n);
		if (n == 0)
			break;

		for (int i = 0; i < n; ++i)
		{
			scanf("%d%d%d", &rbmi[i].p, &h, &w);
			m = h / 100.0;
			rbmi[i].rbmi = fabs(w / (m * m) - 22.0);
		}

		qsort(rbmi, n, sizeof(rbmi_t), cmp_func);
		printf("%d\n", rbmi[0].p);
	}

	return 0;
}


Measured memory_bytes: 1724
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
al.sort(reverse=True)
al.append(0)
bl.sort(reverse=True)
bl.append(0)

res = 1
MOD = 10**9+7
ba = 0
bb = 0
for x in range(n*m,0,-1):
    if al[ba]>x or bl[bb]>x:
        res = 0
        break

    s = 1
    if al[ba]==x and bl[bb]==x:
        ba += 1
        bb += 1
    elif al[ba]==x:
        s = bb
        ba += 1
    elif bl[bb]==x:
        s = ba
        bb += 1
    else:
        s = ba*bb - (n*m-x)
    # print(x,ba,bb,s)
    if s<=0:
        res = 0
        break

    res = (res*s)%MOD

print(res)


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

using ll=long long;
using namespace std;

#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

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

const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

char BigAlphaToSmall(char a){
    if (a >= 65 && a <= 90){
        return a + 32;
    }
    return a;
}

char SmallAlphaToBig(char a){
    if (a >= 97 && a <= 122){
        return a - 32;
    }
    return a;
}

class Dice{
    public:
        int top;
        int button;
        int south;
        int north;
        int east;
        int west;
        void to_south();
        void to_north();
        void to_east();
        void to_west();
};

void Dice::to_south(){
    int tmp;
    tmp = this->button;
    this->button = this->south;
    this->south = this->top;
    this->top = this->north;
    this->north = tmp;
}

void Dice::to_north(){
    int tmp;
    tmp = this->button;
    this->button = this->north;
    this->north = this->top;
    this->top = this->south;
    this->south = tmp;
}

void Dice::to_east(){
    int tmp;
    tmp = this->button;
    this->button = this->east;
    this->east = this->top;
    this->top = this->west;
    this->west = tmp;
}

void Dice::to_west(){
    int tmp;
    tmp = this->button;
    this->button = this->west;
    this->west = this->top;
    this->top = this->east;
    this->east = tmp;
}

Dice NewDice(vector<int> v){
    Dice d;
    d.top = v[0];
    d.south = v[1];
    d.east = v[2];
    d.west = v[3];
    d.north = v[4];
    d.button = v[5];
    return d;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    vector<int> hoge(6);
    for (int i = 0; i < 6; i++){
        cin >> hoge[i];
    }
    Dice d;
    d = NewDice(hoge);
    string cmds;
    cin >> cmds;

    for (int i = 0; i < cmds.length(); i++){
        if(cmds[i] == 'S'){
            d.to_south();
            continue;
        }
        if(cmds[i] == 'N'){
            d.to_north();
            continue;
        }
        if(cmds[i] == 'E'){
            d.to_east();
            continue;
        }
        if(cmds[i] == 'W'){
            d.to_west();
            continue;
        }
    }

    cout << d.top << endl;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
int solve() {
	var(int, n);
	vec(int, v, n);
	int n2 = n / 2;
	if (len(set<int>(all(v))) == 1)
		return n2;
	map<int, int> m[2];
	rep(i, 0, n) {
		++m[i & 1][v[i]];
	}
	vector<pii> vp[2];
	each(a, m[0]) {
		vp[0].eb(mp(a.se, a.fi));
	}
	each(a, m[1]) {
		vp[1].eb(mp(a.se, a.fi));
	}
	sort(rall(vp[0]));
	sort(rall(vp[1]));
	vp[0].eb(mp(0, 0));
	vp[1].eb(mp(0, 0));
	if (vp[0][0].se != vp[1][0].se)
		return n2 - vp[0][0].fi + n2 - vp[1][0].fi;
	int max_v = (vp[0][0].fi + vp[1][1].fi < vp[0][1].fi + vp[1][0].fi? 1 : 0);
	int min_v = 1 - max_v;
	return n2 - vp[max_v][0].fi + n2 - vp[min_v][1].fi;
}
int main() {
	print(solve());
	return 0;
}


Measured memory_bytes: 6524
from math import gcd
N,X=map(int,input().split())
x=list(map(int,input().split()))

if N==1:
  print(abs(X-x[0]))

else:
  l=[]
  for i in range(N):
    l_=abs(X-x[i])
    l.append(l_)
  #print(l)
  ans=l[0]
  for i in range(1,len(l)):
    ans=gcd(ans,l[i])

  print(ans)

Measured memory_bytes: 20452
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<string.h>
#include<string>
using namespace std;
typedef long long int llint;
int main() {
	int n;
	cin >> n;
	vector<int>t(n);
	int sum = 0;
	for (int i = 0;i < n;i++) {
		cin >> t[i];
		sum += t[i];
	}
	int m;
	cin >> m;
	vector<int>ans(m);
	int p, x;
	for (int i = 0;i < m;i++) {
		cin >> p >> x;
		ans[i] = sum - t[p - 1] + x;
	}
	for (int i = 0;i < m;i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
def check(s):
    for i  in range(len(s)//2):
        if s[i] != s[len(s)-i-1]:
            return False
    return True

if __name__ == '__main__':
    s = input()
    if check(s):
        if check(s[0:len(s)//2]):
            if check(s[(len(s)//2)+1:len(s)]):
                print("Yes")
            else:
                print("No")
        else:
            print("No")
    else:
        print("No")



Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
	int n,m,a[101],b[101],i,j,x[101],y;
	scanf("%d %d",&n,&m);
	for(i=1;i<=m;i++){
		scanf("%d",&a[i]);
	}
	for(i=1;i<=n;i++)	x[i]=0;
	
	for(i=1;i<=m;i++){
		for(j=1;j<=n;j++){
			scanf("%d",&b[j]);
			if(b[j]==a[i])	x[j]++;
			else	{
				y=a[i];
				x[y]++;
			}
		}
	}
	for(i=1;i<=n;i++){
		printf("%d\n",x[i]);
	}
	return 0;
}
		
		



		


Measured memory_bytes: 2076
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  char c;
  cin>>c;
  cout<<(char)(c+1)<<endl;
}

Measured memory_bytes: 256
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;
using System.Timers;

static class MainClass
{
    public static void Main(string[] args)
    {
        var nm = Console.ReadLine().SplittedStringToInt32List();
        var n = nm[0];
        var m = nm[1];
        Console.WriteLine((n - 1)* (m -1));
    }


    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    #endregion
}


Measured memory_bytes: 13268
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M=map(int,input().split())
tree=UnionFind(N)
for i in range(M):
  A,B=map(int,input().split())
  tree.union(A-1,B-1)
print(tree.group_count()-1)
  

Measured memory_bytes: 75200
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template <class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iterator i=(c).begin();i!=(c).end();++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS=1e-10;
const double PI=acos(-1.0);


bool pred(const string &left, const string &right){
	if(left.size()!=right.size())return left.size()<right.size();
	return left<right;
}
int dx[]={-1,0},dy[]={0,-1};
typedef vector<vs> vvs;
int main(){
	int W,H;
	while(cin>>W>>H,W&&H){
		vs matrix(W,string(H,' '));
		REP(i,H)REP(j,W){
			cin>>matrix[j][i];
		}
		vvs dp(W,vs(H,"0"));

		REP(i,W)REP(j,H){
			if(!isdigit(matrix[i][j])){
				dp[i][j]="0";
			}else{
				dp[i][j]=matrix[i][j];
				REP(k,2){
					int x=i+dx[k],y=j+dy[k];
					if(x>=0&&y>=0){
						string prev=(dp[x][y]=="0"?"":dp[x][y]);
						dp[i][j]=max(dp[i][j],prev+matrix[i][j],pred);
					}
				}
			}
		}
		string maxs;
		REP(i,W)REP(j,H){
			maxs=max(maxs,dp[i][j],pred);
		}
		cout<<maxs<<endl;
	}

}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;


int main(int argc, const char * argv[]) {

    vector<vector<char>> c(2, vector<char> (3));
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < 3; j++){
            cin >> c.at(i).at(j);
        }
    }
    bool result = true;
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < 3; j++){
            if(c.at(i).at(j) != c.at(1-i).at(2-j)){
                result = false;
            }
        }
    }
    if(result){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define PI 3.141592653589
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EPS 1e-9
using namespace std;
int n, k;
bool dp[100005];
int main(){
    IO;
    cin >> n >> k;
    int arr[n+1];
    for(int i =0; i < n; ++i)
        cin >> arr[i];
    dp[0] = 0;
    for(int i = 1; i<= k; ++i){
        for(int j = 0; j < n; j++){
            if(arr[j] <= i && !dp[i-arr[j]])
                dp[i] = true;
        }
    }
    cout << (dp[k] ? "First" : "Second");

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;
#define ar array 
const int mod = 1e9+7;
struct mint {
  ll x; // typedef long long ll;
  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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


void test_case() {
	int n;
	cin >> n;
	if(n == 1){
		cout<<0;
		return;
	}
	mint ans = 1;
	mint res = 1;
	mint num = 1;
	for(int i = 1 ; i <= n ; i++){
		ans*=10;
		res*=8;
		num*=9;
	}
	num*=2;
	cout<<ans-num+res;
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T = 1;
	//cin >> T;
	while(T--){
		test_case();
	}
}


Measured memory_bytes: 3636
/*
  AOJ 2135
  Title:Reverse a Road
  @kankichi573
*/
#include <stdio.h>
#include <string.h>

int N,S,T,M;
int from[10001],to[10001];
char road[1001][1001];
int distance[2][1001];   // distance from start,end

int dist_all;

void calc_distance(int start,int d,int dist[])
{
  int i;

  //printf("c_d__ %d %d\n",start,d);

  if(dist[start]==-1 || dist[start]>d)
    {
      dist[start]=d;
      if(start==T)
	dist_all=d;
    }
  else
    return;

  for(i=1;i<=1000;i++)
    if(road[start][i])
      calc_distance(i,d+1,dist);
}

void calc_distance_r(int start,int d,int dist[])
{
  int i;

  //printf("c_d_r %d %d\n",start,d);

  if(dist[start]==-1 || dist[start]>d)
    {
      dist[start]=d;
      //if(start==T)
      //dist_all=d;
    }
  else
    return;

  for(i=1;i<=1000;i++)
    if(road[i][start])
      calc_distance_r(i,d+1,dist);
}

solve()
{
  int i,shortcut,min_,min_r,min_road,d1,d2;
  
  for(i=1,min_=dist_all,min_r=0;i<=M;i++)
    {
      d1=distance[1][from[i]];
      d2=distance[0][to[i]];
      //printf("%d:%d %d [%d %d %d]\n",i,from[i],to[i],d1,d2,d1+d2+1);

      if(d1 + d2 +1  <dist_all && d1>=0 && d2>=0)
	{
	  shortcut=(d1+d2+1);
	  if(shortcut<min_)
	    {
	      //printf("*+\n");
	      min_=shortcut;
	      min_r=i;
	    }
	}
    }
  if(min_ < dist_all)
    printf("%d %d\n",min_, min_r);
  else
    printf("%d 0\n",dist_all);

}

main()
{
  int i,ret,a,b;
  

  while(scanf("%d",&N)  && (N))
    {
      memset(distance,-1,sizeof(distance));
      memset(road,0,sizeof(road));
      scanf("%d %d",&S,&T);
      scanf("%d",&M);
      for(i=1;i<=M;i++)
	{
	  scanf("%d %d",&a,&b);
	  from[i]=a;
	  to[i]=b;
	  road[a][b]=1;
	}
      calc_distance(S,0,&distance[0][0]);
      calc_distance_r(T,0,&distance[1][0]);
      //printf("dall=%d\n",dist_all);
      solve();
    }
  return(0);
}

Measured memory_bytes: 1716
#include <iostream>

int main(void){
	using namespace std;
	int n, i;
	cin >> n;
	for (i = 3; i <= n; i++){
		if(i%3 == 0)
			cout << " " << i;
		else{
			int x = i;
			while(x){
				if(x%10 == 3)
					{cout << " " << i;
					break;
					}
				else
					x /= 10;
			}
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3128
/**************************************
 * Au: Hany01
 * Email: hany01@foxmail.com
**************************************/

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
#define rep(i, j) for (register int i = 0, i##_end_ = j; i < i##_end_; ++ i)
#define For(i, j ,k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define SZ(a) ((int)(a.size()))
#define ALL(a) a.begin(), a.end()
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define Mod (1000000007)
#define y1 wozenmezhemecaia 
#ifdef hany01
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }

inline int read() {
    register char c_; register int _, __;
    for (_ = 0, __ = 1, c_ = getchar(); !isdigit(c_); c_ = getchar()) if (c_ == '-')  __ = -1;
    for ( ; isdigit(c_); c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}

const int maxn = 500005;

struct SAM
{
    int ch[26], fa, len;
}t[maxn << 1];

int sz[maxn << 1], tot = 1, las = 1, sum[maxn << 1], per[maxn << 1], c[maxn];

int n;
char s[maxn];

inline void extend(int c)
{
    register int np = ++ tot, p = las;
    las = tot, t[np].len = t[p].len + 1, sz[np] = 1;
    while (p && !t[p].ch[c]) t[p].ch[c] = np, p = t[p].fa;
    if (!p) t[np].fa = 1;
    else {
        register int q = t[p].ch[c];
        if (t[q].len == t[p].len + 1) t[np].fa = q;
        else {
            register int nq = ++ tot;
            t[nq] = t[q], t[nq].len = t[p].len + 1;
            t[np].fa = t[q].fa = nq;
            while (p && t[p].ch[c] == q) t[p].ch[c] = nq, p = t[p].fa;
        }
    }
}

void dfs(int u, int k)
{
    if (k <= sz[u]) return ;
    k -= sz[u];
    rep(i, 26) if (t[u].ch[i])
    {
        if (sum[t[u].ch[i]] >= k)
        {
            putchar(i + 97);
            dfs(t[u].ch[i], k);
            return ;
        } else k -= sum[t[u].ch[i]];
    }
}
int main()
{
#ifdef hany01
    File("c");
#endif

    int ty, k;

    //Init
    scanf("%s", s), n = strlen(s);
    ty = 0, k = read();
    rep(i, n) extend(s[i] - 97);

    //Sort
    For(i, 1, tot) ++ c[t[i].len];
    For(i, 1, n) c[i] += c[i - 1];
    For(i, 1, tot) per[c[t[i].len] --] = i;

    //Deal with the requirement
    if (ty) {
        Fordown(i, tot, 1) sz[t[per[i]].fa] += sz[per[i]];
        sz[1] = 0;
    } else For(i, 2, tot) sz[i] = 1;

    //Get the sum
    Fordown(i, tot, 1) {
        sum[per[i]] = sz[per[i]];
        rep(c, 26) sum[per[i]] += sum[t[per[i]].ch[c]];
    }

    //Print
    if (k > sum[1]) puts("-1");
    else dfs(1, k);

    return 0;
}


Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const  long long INF = 1e18;
const  long long MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i,n,init) for(long long i=init;i*i<=(n);i++)
#define repd(i,n,init) for(long long i=(n);i>=init;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)

int main()
{
    ll N;
    cin >> N;
    ll ans = INF;
    repi(i,N,1){
        if(N%i != 0){
            continue;
        }
        ll j = N/i;
        ans = min(ans,i+j-2);
    }
    cout << ans << endl;
    return 0;
}

/*memo*/
// 数学的考察をしましょう
// 表を使うときは対称性に気をつける。
// 2次元にとらわれすぎない
// 整数の性質を使う
//sqrt(N)よりかはi*i < Nのほうがよき

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        int ans = x;
        ans -= a;

        System.out.println(ans % b);
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


Measured memory_bytes: 21844
import java.io.*;
import java.util.*;
class Main
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	
    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt(),x=sc.nextInt();int[] a=new int[n];long res=0;
		for(int i=0;i<n;i++)
		{
			a[i]=sc.nextInt();
		}
		if(a[0]>x)
		{
			res+=a[0]-x;a[0]=x;
		}
		for(int i=1;i<n;i++)
		{
			if(a[i]+a[i-1]>x)
			{
				int curr=x-a[i-1];
				res+=(a[i]-curr);a[i]=curr;
			}
		}
		out.println(res);out.close();
    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }
	
    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
	
	public String next() throws Exception {
		return nextToken().toString();
	}
	
    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}

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

int main(void) {
  int N;
  scanf("%d", &N);
  
  char S[100][11];
  int P[100];
  int id[100];

  int i, j;
  for(i=0; i<N; i++) {
    scanf("%s %d", S[i], &P[i]);
	id[i] = i+1;
  }

  char tempS[11];
  int tempP;
  int tempid;
  for(i=0; i<N; i++) {
    for(j=0; j<N; j++) {
      if(i != j){
		  int flag = strcmp(S[i], S[j]);
		  if(flag < 0){
			  strcpy(tempS, S[i]);
			  strcpy(S[i],S[j]);
			  strcpy(S[j],tempS);
			  tempP = P[i];
			  P[i] = P[j];
			  P[j] = tempP;
			  tempid = id[i];
			  id[i] = id[j];
			  id[j] = tempid;
		  }

		  else if(flag == 0) {
		  	  if(P[i] > P[j]){
				  strcpy(tempS, S[i]);
				  strcpy(S[i],S[j]);
				  strcpy(S[j],tempS);
				  tempP = P[i];
				  P[i] = P[j];
				  P[j] = tempP;
				  tempid = id[i];
				  id[i] = id[j];
				  id[j] = tempid;
			  }
		  }
	  }
	}
  }
  for(i=0; i<N; i++) {
	  printf("%d\n", id[i]);
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
  int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b!=c)cout<<"Yes"<<endl;
    else if(a==c&&c!=b)cout<<"Yes"<<endl;
    else if(b==c&&b!=a)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
        string s;
        cin >> s;
        if(s == "a" || s == "i"|| s == "u"|| s == "e"|| s == "o"){
            cout << "vowel" << endl;
        }else{
            cout << "consonant" << endl;
        }
        
    }

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()

using ll = long long;
using ld = long double;
using namespace std;

const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 5;

int s, t, d;

void code() {
    cin >> d >> t >> s;

    cout << (t * s >= d ? "Yes\n" : "No\n");
}

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

    int t = 1;
    // cin>>t;

    while (t-- > 0) {
        code();
    }
}

Measured memory_bytes: 3648