akhauriyash/Code-Regression huggingface dataset:
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 0
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	var ans, t int64
	t = 1000000000
	for i := 0; i < 10; i++ {
		ans *= 10
		l := -1
		r := 10
		for l+1 < r {
			m := (l + r) >> 1
			if ans+int64(m) == 0 {
				r = 1
				break
			}
			res := ask((ans+int64(m))*t+t-1, scanner, writer)
			if res == "Y" {
				r = m
				continue
			}
			l = m
		}
		t /= 10
		ans += int64(r)
	}
	if pow10(ans) {
		for ans > 0 {
			res := ask(ans/10+1, scanner, writer)
			if res == "N" {
				fmt.Fprintln(writer, fmt.Sprintf("! %d", ans))
				return
			}
			ans /= 10
		}
		fmt.Fprintln(writer, fmt.Sprintf("! %d", 1))
		return
	}
	for ans > 0 {
		res := ask(ans-1, scanner, writer)
		if res == "Y" {
			fmt.Fprintln(writer, fmt.Sprintf("! %d", ans))
			return
		}
		ans /= 10
	}
}

func pow10(x int64) bool {
	for x%10 == 0 {
		x /= 10
	}
	return x == 1
}
func ask(n int64, scanner *bufio.Scanner, writer *bufio.Writer) string {
	fmt.Fprintln(writer, fmt.Sprintf("? %d", n))
	writer.Flush()
	return getNextString(scanner)
}


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

int main() {
  int n;
  cin >> n;
  long answer = 0;
  
  for(int i = 0; i < n; i++) {
    int x = 0;
    x = i + 1;
    if(x % 3 == 0 || x % 5 == 0){
      //何もしない
    }
    else {
      answer += x;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 3640
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

cb = {}
for i in range(M):
    b, c = map(int, input().split())
    if cb.get(c) is None:
        cb[c] = b
    else:
        cb[c] += b

a_ind = 0
for c in sorted(cb.keys(), reverse=True):
    flg = 0
    for b in range(cb[c]):
        if c < A[a_ind]:
            flg = 1
            break
        else:
            A[a_ind] = c
            a_ind += 1
            if a_ind == N:
                flg = 1
                break
    if flg:
        break
print(sum(A))

Measured memory_bytes: 23336
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        double A = Math.log10(sc.nextDouble());
        double B = Math.log10(sc.nextDouble());

        if(A > B){
            System.out.println("GREATER");
        }else if(A < B){
            System.out.println("LESS");
        }else{
            System.out.println("EQUAL");
        }
    }
}
 

Measured memory_bytes: 23124
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	for(int i=1;;i++){
		if(i%2!=0){
			c -=b;
			if(c<=0){
				cout<<"Yes";
				break;
			}
		}
		else{
			a -= d;
			if(a<=0){
				cout<<"No";
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3536
fn main() {                                                                                                                                                                                                                                      let scan = std::io::stdin();                                                                                                                                                                                                             
    let mut line = String::new();

    let _ = scan.read_line(&mut line);
    let vec: Vec<&str> = line.split_whitespace().collect();

    let a: u32 = vec[0].parse().unwrap_or(0);
    let b: u32 = vec[1].parse().unwrap_or(0);
    let c: u32 = vec[2].parse().unwrap_or(0);

    let mut v = vec![a, b, c];
    v.sort();

    println!("{} {} {}", v[0], v[1], v[2]);
}


Measured memory_bytes: 5012
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
#define MOD 1000000007
#define PI 3.14159265358979323846
using namespace std;
typedef long long ll;

#define MAX 1000000000000



int main(void) {
	ll a, b, n; cin >> a >> b >> n;
	cout << (a*(min(b - 1,n))) / b << endl;
	return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
  int n;
  bool w[10];
  bool flg;
  while(cin>>n){
    for(int i=0;i<10;i++)w[i]=false;
    flg=false;
    for(int i=9;i>=0;i--){
      if(n>=(int)pow(2.0,(double)i)){w[i]=true; n-=(int)pow(2.0,(double)i);}
    }
    for(int i=0;i<10;i++){
      if(w[i]){
	if(!flg){flg=true;
cout<<(int)pow(2.0,(double)i);
	}
	else{
	  cout<<' '<<(int)pow(2.0,(double)i);
	}
      }
    }
    cout<<endl;
  }
}

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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace

#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s, t;
    cin >> s >> t;    
    cout << t + s << '\n';
}



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

using namespace std;

#define MAX 334
typedef pair<int, int> pii;

int main()
{
    int s, d, m;
    while (cin >> s >> d >> m) {
        vector<pii> v[s];
        for (int i = 0; i < s; i++) {
            int k, w, p;
            cin >> k;
            for (int j = 0; j < k; j++) {
                cin >> w >> p;
                v[i].push_back(pii(w, p));
            }
        }

        int dp[MAX], f;
        memset(dp, -1, sizeof(dp));
        dp[m] = 0;
        for (int i = 0; i < d; i++) {
            cin >> f;
            for (int j = 0; j < (int)v[f].size(); j++) {
                for (int k = 0; k <= m; k++) {
                    if (dp[k] == -1) continue;
                    int nm = k - v[f][j].second;
                    if (nm >= 0) {
                        dp[nm] = max(dp[nm], dp[k] + v[f][j].first);
                    }
                }
            }   
        }
        
        int idx = m;
        for (int i = m-1; i >= 0; i--) {
            if (dp[i] > dp[idx]) {
                idx = i;
            }
        }
        cout << dp[idx] << " " << m - idx << endl;
    }
    return 0;
}

Measured memory_bytes: 3004
// failed to generate code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

int main(){	
	int n;
  long long k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  const int MAX = 200010;
  vector<int> nxt(MAX, -1);
  vector<int> first_on_suffix(n + 1);
  first_on_suffix[n] = -1;
  for (int i = n - 1; i >= 0; i--) {
    if (nxt[a[i]] != -1) {
      first_on_suffix[i] = first_on_suffix[nxt[a[i]] + 1];
    } else {
      first_on_suffix[i] = a[i];
    }
    nxt[a[i]] = i;
  }
//   rep(i, n) {
// 	  cout << first_on_suffix[i] << " " << nxt[a[i]] << endl;
//   } 
  int wut = -1;
  long long steps = 0;
  while (k > 1) {
    ++steps;
    if (wut == -1) {
      wut = first_on_suffix[0];
    } else {
      wut = first_on_suffix[nxt[wut] + 1];
    }
	// cout << k << " " << wut << endl;
    --k;
    if (wut == -1) {
      k = (k - 1) % steps + 1;
    }
  }
  vector<int> occ(MAX);
  vector<int> b;
  int start = (wut == -1 ? 0 : nxt[wut] + 1);
  for (int i = start; i < n; i++) {
    int x = a[i];
    if (occ[x] == 0) {
      occ[x]++;
      b.push_back(x);
    } else {
      while (occ[x] != 0) {
        occ[b.back()]--;
        b.pop_back();
      }
    }
  }
  for (int i = 0; i < (int) b.size(); i++) {
    if (i > 0) {
      cout << " ";
    }
    cout << b[i];
  }
  cout << '\n';
  return 0;
}


Measured memory_bytes: 5492
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

signed main() {
    string s;
    cin>>s;
    int l=s.size();
    int h=l/2;
    int r=0;
    REP(i,h){
        if( s.at(i) != s.at(l-1-i)){
            r++;
        }
    }
    cout<<r<<endl;
    


    // cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
   public static void main(String[] args) {  
      Scanner sc = new Scanner(System.in);
      
      int a = sc.nextInt();
      int b = sc.nextInt();
      int k = sc.nextInt();
      
      ArrayList<Integer> list = new ArrayList<Integer>();
      for(int i = 1; i <= Math.min(a, b); i++) {
         if(a % i == 0 && b % i == 0) {
            list.add(i);
         }
      }
      System.out.println(list.get(list.size() - k));
   }
}

Measured memory_bytes: 25044
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define MOD 1000000007
typedef long long LL;
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

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


	if (S[0] != 'A') {
		cout << "WA" << endl;
		return 0;
	}
	

	for (auto it = begin(S)+2; it != end(S)-1;it++)
	{
		if (*it == 'C') {
			break;
		}

		if (it == end(S) - 2) {
			cout << "WA" << endl;
			return 0;
		}
	}


	int count = 0;
	for (auto it = begin(S); it != end(S); it++) {
		if (*it == 'C') {
			count++;
		}
	}
	if (count != 1) {
		cout << "WA" << endl;
		return 0;
	}
	

	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] == 'B' or (S[i] >= 'D' and S[i] <= 'Z')) {
			cout << "WA" << endl;
			return 0;
		}
	}

	cout << "AC" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<stdlib.h>
#include<ctime>
#include<string>
#include<cmath>
#include<algorithm>
#include<complex>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef pair<int,int> pa;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int vs,k;
LL now,v[500010];
int S(LL x){
	int t=0;
	while (x) t+=x%10,x/=10;
	return t;
}
int main(){
	now=1e15;
	--now;
	v[vs=1]=now;
	while (now>1){
		LL t;
		if (now==1199){
			int tt=1;
		}
		for (t=1;t<now;t*=10){
			LL tmp=now-t;
			if (S(tmp)*now>=S(now)*tmp){//S(tmp)/tmp>=S(now)/now
				now=tmp;
				v[++vs]=now;
				break;
			}
		}
	}
	reverse(v+1,v+vs+1);
	cin>>k;
	FOR(i,1,k) cout<<v[i]<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

var N, ans int

func main() {
	fmt.Scan(&N)
	reader := bufio.NewScanner(os.Stdin)
	reader.Split(bufio.ScanWords)

	a := make(SortBy, N)
	for i := 0; i < N; i++ {
		reader.Scan()
		a[i], _ = strconv.Atoi(reader.Text())
	}
	sort.Sort(a)

	var Alice, Bob int
	for 0 < len(a) {
		Alice += a[0]
		if len(a) == 1 {
			break
		}

		Bob += a[1]
		a = append(a[2:])
	}
	fmt.Println(Alice - Bob)
}

/*  ----------------------------------------  */
func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i] > a[j] }


Measured memory_bytes: 640
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
const int mod = 1000000007;
int N, M, lp, rp, sum[3009], r[3009], dp[3009][3009]; string s;
int main() {
	cin >> N >> M >> s;
	for (int i = 0; i < N; i++) sum[i + 1] = sum[i] + s[i] - 48;
	for (int i = 0; i < M; i++) {
		cin >> lp >> rp;
		r[lp] = max(r[lp], rp);
	}
	for (int i = 1; i <= N; i++) r[i] = max({ r[i], r[i - 1], i });
	dp[0][0] = 1;
	for (int i = 1; i <= N; i++) {
		int pl = max(sum[r[i]] - r[i] + i, 0), pr = min(sum[r[i]], i);
		for (int j = pl; j <= pr; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j != 0) {
				dp[i][j] += dp[i - 1][j - 1];
				if (dp[i][j] >= mod) dp[i][j] -= mod;
			}
		}
	}
	int ret = 0;
	for (int i = 0; i <= N; i++) {
		ret += dp[N][i];
		if (ret >= mod) ret -= mod;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 33920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}


vector<ll> enum_div(ll n){//yakusu
  vector<ll> ret;
  for(ll i=1 ; i*i<=n ; ++i){
      if(n%i == 0){
        ret.push_back(i);
        if(i*i!=n)ret.push_back(n/i);
      }
  }
  return ret;
}


int main(){

  ll N;
  cin >> N;
  vector<ll> A(N);
  FOR(i,0,N) cin >> A[i];

  SORT(A);
  if(A[0] == 1 && N>1 && A[1] == 1){
    cout << 0 << endl;
    return 0;
  }
  if(A[0]==1 && N==1){
    cout << 1 << endl;
    return 0;
  }
  if(A[0] == 1 && N>1 && A[1] > 1){
    cout << 1 << endl;
    return 0;
  }

  set<ll> se;

  ll ans = 0;
  FOR(i,0,N){
    bool ok = true;
    if(i!=(N-1) && A[i]==A[i+1])ok = false;
    for(auto x:enum_div(A[i])){
      if(se.count(x))ok = false;
    }
    ans += ok;
    se.insert(A[i]);
  } 
  cout << ans << endl;
}



Measured memory_bytes: 14080
#include <bits/stdc++.h>
char s1[110],s2[10]="keyence";
int n,i,j,k;
int main()
{
	scanf("%s",s1);
	n=strlen(s1);
	for (i=0;(i<7) && (s1[i]==s2[i]);i++);
	for (j=1;(n-j>=0) && (7-j>=0) && (s1[n-j]==s2[7-j]);j++);
	k=i+j-1;
	if (k>=7) printf("YES");
		else printf("NO");
	return 0;
}

Measured memory_bytes: 256
S = input()

comp = []
other = []
cnt = 0
for c in S:
    if c == 'x':
        cnt += 1
    else:
        other.append(c)
        comp.append(cnt)
        cnt = 0
comp.append(cnt)

#print(other)
L = len(other)

dame = False
for i in range(L // 2):
    if other[i] != other[L - i - 1]:
        dame = True

if dame:
    print(-1)
else:
    K = len(comp)
    ans = 0
    for i in range(K // 2):
        ans += abs(comp[i] - comp[K - i - 1])
    print(ans)


Measured memory_bytes: 4848
#include<iostream>
#include<vector>
#include<algorithm>
typedef unsigned long long ll;

using namespace std;

vector<ll> make1(){
  ll i, x;
  vector<ll> data;
  for(i=1, x=1; i<=100000; ++i){
    x *= i;
    x %= 1000000007;
    data.push_back(x);
  }
  //  for(int i=0; i<=30; ++i){
  //    cout << data[i] << endl;
  //  }
  return data;
}

vector<ll> make2(int n){
  vector<ll> data;
  for(int i=1; i<=n; ++i){
    data.push_back(i);
  }
  return data;
}

int main(){
  ll n, r, a, b;
  const vector<ll> data1 = make1();

  while(1){
    cin >> n;
    if(n == 0) break;
    vector<ll> data2 = make2(n);
    cin >> r;
    for(ll i=0; i<r; ++i){
      cin >> a >> b;
      swap(data2[a-1], data2[b-1]);
    }
    reverse(data2.begin(), data2.end());

    vector<ll> data3;
    vector<ll>::iterator it; 
    ll a, ans=0;
    for(ll i=data2.size()-1; i>0; --i){
      it = upper_bound(data3.begin(), data3.end(), data2[i]);
      a = it - data3.begin();
      ans += (data1[i-1]*(data2[i]-a-1));
      ans %= 1000000007;
      data3.insert(it, data2[i]);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 4492
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define N (int)1e5
#define mod (int)(1e9 + 7)
typedef long long LL;
int n, ch[50][40], ma;
string s[50], ans;
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> s[i];
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < s[i].size(); j++)
		{
			ch[i][s[i][j] - 96]++;
		}
	}
	for (int i = 1; i <= 26; i++)
	{
		ma = mod;
		for (int j = 0; j < n; j++)
		{
			ma = min(ma, ch[j][i]);
		}
		while (ma--)
			ans += 96 + i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,W;
  cin >> N >> W;
  vector<int> w(N);
  vector<ll> v(N);
  for(int i=0;i<N;i++)  cin >> w.at(i) >> v.at(i);

  vector<vector<ll>> dp(N+1,vector<ll>(W+1,0));
  for(int i=0;i<N;i++){
    for(int j=0;j<=W;j++){
      if(j-w.at(i)>=0)  dp.at(i+1).at(j)=max(dp.at(i).at(j),dp.at(i).at(j-w.at(i))+v.at(i));
      else  dp.at(i+1).at(j)=dp.at(i).at(j);
    }
  }
  cout << dp.at(N).at(W) << endl;

  return 0;
}

Measured memory_bytes: 80256
import sys
def main():
  _int = int
  n = int(input())
  data = [[_int(e) for e in input().split()] for _ in range(n)]
  t, x, y = 0, 0, 0
  for d in data:
    rt = d[0] - t - abs(x - d[1]) - abs(y - d[2])
    if rt < 0 or rt & 1 == 1:
      print('No')
      sys.exit()
    t, x, y = d
  print('Yes')
main()


Measured memory_bytes: 60376
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;
int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0' && c<='9'){
		x=(x<<3)+(x<<1)+c-48;
		c=getchar();
	}
	return x*f;
}
int main(){
	char c;
	c=getchar();
	if(c=='T')printf("A\n");
	if(c=='A')printf("T\n");
	if(c=='C')printf("G\n");
	if(c=='G')printf("C\n");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> ppiii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> query;

/*
state is
[number of towns seen so far][size of SCC]
*/
ll dp[301][301];
ll ndp[301][301];

ll facs[305];
ll ifacs[305];
const int MOD = 1000000007;
ll modpow(ll b, ll e, ll m) {
  ll r = 1;
  while(e) {
    if(e%2) {
      r*=b;
      r%=m;
    }
    b*=b;
    b%=m;
    e/=2;
  }
  return r;
}

ll choose(int n, int k) {
  ll ret = facs[n];
  ret *= ifacs[k];
  ret %= MOD;
  ret *= ifacs[n-k];
  ret %= MOD;
  return ret;
}

int n;
void solve() {
  facs[0] = 1;
  int m;
  cin >> n >> m;
  for(int i = 1; i <= n; i++) {
    facs[i] = facs[i-1] * i;
    facs[i] %= MOD;
  }
  ifacs[n] = modpow(facs[n], MOD-2, MOD);
  for(int i = n-1; i >= 0; i--) {
    ifacs[i] = (i+1) * ifacs[i+1];
  }
  dp[1][1] = 1;
  while(m--) {
    memset(ndp, 0, sizeof(ndp));
    for(int x = 1; x <= n; x++) {
      for(int y = 1; y <= x; y++) {
        // case 1: connect to SCC (y nodes)
        ndp[x][x] += dp[x][y] * y;
        ndp[x][x] %= MOD;
        // case 2: connect to a new node (n-x nodes)
        ndp[x+1][y] += dp[x][y] * (n - x);
        ndp[x+1][y] %= MOD;
        // case 3: connect to something else (x-y) nodes
        ndp[x][y] += dp[x][y] * (x-y);
        ndp[x][y] %= MOD;
      }
    }
    memcpy(dp, ndp, sizeof(dp));
  }
  cout << dp[n][n] << "\n";
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << " ";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


Measured memory_bytes: 1664
n = int(input())
a_l = list(map(int,input().split()))
b_l = list(map(int,input().split()))
c_l = list(map(int,input().split()))

ans = 0
before = None
for i in a_l:
    ans += b_l[i-1]
    if before == i-1:
        ans += c_l[before-1]
    before = i
print(ans)

Measured memory_bytes: 8972
#include<iostream>

using namespace std;

#define ll long long

void sort(int *a,int *b,int n)
{
	int i = 0,j = n - 1;
	int pivot = a[(i+j)/2];

	while(true)
	{
		while(a[i] < pivot)i++;
		while(a[j] > pivot)j--;

		if( i >= j )break;

		int hold = a[i];
		a[i] = a[j];
		a[j] = hold;

		hold = b[i];
		b[i] = b[j];
		b[j] = hold;

		i++;
		j--;
	}

	if(i > 1)sort(a,b,i);
	if(n-j-1 > 1)sort(a+j+1,b+j+1,n-j-1);
}

int main()
{

	int N,M;
	int *A,*B;

	long long ans = 0;

	cin >> N >> M;

	A = new int[N];
	B = new int[N];

	for(int i=0;i<N;i++)
	{
		cin >> A[i] >> B[i];
	}

	sort(A,B,N);



	for(int i=0;i<N;i++)
	{
		if( M > B[i])
		{
			ans += ((ll)A[i]*(ll)B[i]);
			M -= B[i];
		}
		else
		{
			ans += ((ll)A[i]*(ll)M);
			M = 0;
		}

		if(M == 0)break;
	}

	cout << ans << endl;

	delete(A);
	delete(B);

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;
#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 repf(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repr(i,a,b) for(ll i=(ll)a-1;i>=(ll)b;i--)
#define Fi first
#define Se second
typedef pair<ll, ll> pll;
const ll MAX = 1000;
const char END = '\n';

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

	ll Ans = 0, N;
	cin >> N;
	rep(i, N - 1)
		Ans += i + 1;
	cout << Ans;
	cout << END;
	return 0;
}

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

int main() {
    unsigned long N, K;
    string S;
    cin >> N >> S >> K;
    auto c = S[K - 1];
    for(auto& a : S)if(a != c)a = '*';
    cout << S << endl;
    return 0;
}

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


int main(){
  int K, X;
  cin>> K >> X;
  if(K==1){
    cout << X << endl;
    return 0;
  }
  for(int i = (X-(K-1)); i < (X + K); i++){
    if(i == (X + (K-1))){
      cout << i << endl;
    }
    else{
      cout << i << " ";
    }
  }
    
}


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

int main(){
    string s; cin >> s;
    long long k; cin >> k;
    bool all_one = true;
    int val;

    for (int i=0;i<k;i++){
        auto c = s[i];
        if (c != '1'){
            all_one = false;
            val = c - '0';
            break;
        }
    }
    if (all_one){
        cout << 1 << endl;
    } else {
        cout << val << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll long long
#define ld long double

#define all(x) x.begin(), x.end()
#define sz(x) x.size()

using namespace std;

const char nl = '\n';

void solve() {
	int x;
	cin >> x;
	if(x>=30)
		cout << "Yes" << nl;
	else
		cout << "No" << nl;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin >> t;
	while(t--) {
		solve();
	}
}


Measured memory_bytes: 3632
N = int(input())
S = [int(input()) for _ in range(N)]
sumS = sum(S)
if all(s % 10 == 0 for s in S):
    print(0)
elif sumS % 10 != 0:
    print(sumS)
else:
    S = sorted(S)
    for s in S:
        if s % 10 != 0:
            t = s
            break
    print(sumS - t)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    int diff = b - a;
    int b_actual = 0;
    for(int i = 1; i <= diff; i++){
        b_actual += i;
    }
    cout << b_actual - b << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String... args){
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      double sum = 0.0;
      for(int i = 0; i < N; i++) {
        int input = sc.nextInt();
        sum += (double) (1 / (double)input);
      }
      sum = 1 / sum;
      System.out.println(sum);
      
    }
}

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

int main() {
    vector<int> t(5);
    for (int i = 0; i < 5; i++) {
        cin >> t[i];
    }
    int last = 0; int x = 9;
    for (int i = 0; i < 5; i++) {
        if (t[i] % 10 > 0 && chmin(x, t[i] % 10)) last = i;
    }

    int ans = 0;
    for (int i = 0; i < 5; i++) {
        if (i == last) {
            continue;
        }
        double n = t[i] / 10.0;
        int time = ceil(n) * 10;
        ans += time;
    }
    ans += t[last];
    cout << ans << endl;
    return 0;
}

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

const int SIZE = 310;

int a[SIZE];
int DP[SIZE][SIZE*SIZE];
int DP2[SIZE][SIZE*SIZE];

const int MOD = 998244353;

int p3(int a){ 

  if( a == 0 ){ return 1LL;}
  else if ( a == 1 ){ return 3LL;}
  else{
    if( a % 2 == 0 ){ return ( p3(a/2)*p3(a/2) )%MOD;}
    else{ return ( ((p3( (a-1)/2 ) * p3( (a-1)/2 ))%MOD) * 3 )%MOD;}
  }
}

signed main(void){ 
  
  int N; cin >> N;
  int sum = 0;
  for(int i = 1; i <= N; i++){ cin >> a[i]; sum += a[i];}
  
  DP[0][0] = 1;
  
  for(int i = 1; i <= N; i++){ // a[i]を選ぶ
    for(int j = 0; j < SIZE*SIZE; j++){
      DP[i][j] += 2*DP[i-1][j]; //赤以外にたす
      DP[i][j] %= MOD;
      DP[i][j+a[i]] += DP[i-1][j];
      DP[i][j+a[i]] %= MOD;
    }
  }
  
  int X = 0; int judge = (sum+1)/2;
  
  for(int i = judge; i < SIZE*SIZE; i++){ X += DP[N][i]; X %= MOD;} 
  
  X*= 3;
  X %= MOD;
         
  //次に重複する場合を考える
  
  DP2[0][0] = 1;
  for(int i = 1; i <= N; i++){ 
    for(int j = 0; j < SIZE*SIZE; j++){ 
      DP2[i][j] += DP2[i-1][j];
      DP2[i][j] %= MOD;
      DP2[i][j+a[i]] += DP2[i-1][j];
      DP2[i][j+a[i]] %= MOD;
    }
  }
  
  int res = 0;
  if( sum % 2 == 0 ){ res += DP2[N][judge]; res %= MOD;}
  X -= 3*res;
  X = (X+3*MOD)%MOD;
  int ans = (p3(N)-X+10*MOD)%MOD; //どれか一つでもS/2を超えているものがある場合を全体から除く
  
  cout << ans << endl;
  
  return 0;
}
  


Measured memory_bytes: 454144
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;

LL n,m,ans = 0,col[3],cnt,rep,ect;
LL vis[200005] = {0},cco[200005] = {0};

LL ec = 0,nxt[400005],to[400005],hed[200005] = {0},w[400005];
void add_edge(LL f,LL t,LL cst){
	++ ec; to[ec] = t; nxt[ec] = hed[f]; hed[f] = ec; w[ec] = cst;
}

void dfs(LL u,LL co){
	cnt ++; col[co] ++;
	vis[u] = 1; cco[u] = co;
	for(LL i = hed[u];i;i = nxt[i]){
		LL v = to[i];
		if(w[i] == 1) ect ++;
		if(vis[v]){
			if((co + w[i] + 3) % 3 != cco[v]) rep = 1;
			continue;
		}
		dfs(v,(co + w[i] + 3) % 3);
	}
}

int main(){
	LL u,v;
	cin >> n >> m;
	for(LL i = 1;i <= m;i ++){
		cin >> u >> v;
		add_edge(u,v,1);
		add_edge(v,u,-1);
	}
	memset(vis,0,sizeof(vis));
	for(LL i = 1;i <= n;i ++){
		if(vis[i]) continue;
		col[0] = col[1] = col[2] = 0;
		cnt = 0; rep = 0; ect = 0; dfs(i,0);
        if(rep) ans += cnt * cnt;
		else if(col[0] && col[1] && col[2]) ans += (col[0] * col[1] + col[1] * col[2] + col[2] * col[0]);
		else ans += ect;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 16768
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N, sum = 0, sum2 = -1;
    cin >> N;
    for (int i = 0; i < N; i++){
        int a;
        cin >> a;
        if (a % 4 == 0) {
            sum += 2;
        }
        else if (a % 2 == 0) {
            sum2++;
        }
    }
    if (sum2 == -1) {
        if (sum >= N - 1) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    else {
        if (sum + sum2 >= N - 1){
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl; 
        }
    }
}


Measured memory_bytes: 256
N,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
ans=0
for i in range(N):
    if x-a[i]>=0 and i!=(N-1):
        x-=a[i]
        ans+=1
    elif x-a[i]<0:
        break
    elif x-a[i]==0 and i==(N-1):
        ans+=1
    elif x-a[i]>0 and i==(N-1):
        ans+=0
print(ans)

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define SIZE 500010
#define rep(i, a, b) for (long long i = a; i <= b; ++i)
#define ll long long
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
ll n, m, k, t;
namespace Graph { // 链式前向星
	int cnt, head[SIZE];
	struct Edge {
		int nxt, to;
		int w;
	}e[SIZE];
	void init(int n) {
		memset(head, -1, sizeof(head));
		cnt = 0;
	}
	void add(int u, int v, int w) {
		e[++cnt].w = w;
		e[cnt].to = v;
		e[cnt].nxt = head[u];
		head[u] = cnt;
	}
}
using namespace Graph;

struct Node {
	int u, d;
	Node(int u_, int d_) :u(u_), d(d_) {}
	bool operator < (const Node& b) const { return b.d < d; }
};

ll Dijkstra(int s, int t) { // minimum distance from s to t
	vector<ll> dis(k + 1, 1e18);
	priority_queue<Node> pq;
	dis[s] = 0;
	pq.push(Node(s, 0));
	while (!pq.empty()) {
		Node top = pq.top();
		pq.pop();
		int u = top.u, d = top.d;
		if (d != dis[u]) continue;
		for (int i = head[u]; ~i; i = e[i].nxt) {
			int v = e[i].to, w = e[i].w;
			if (dis[v] > dis[u] + w) {
				dis[v] = dis[u] + w;
				pq.push(Node(v, dis[v]));
			}
		}
	}
	return dis[t];
}
int main() {
	io(); cin >> k;
	init(k);
	rep(i, 1, (k - 1)) {
		add(i, (i + 1) % k, 1);
		add(i, i * 10 % k, 0);
	}
	cout << Dijkstra(1, 0) + 1;
}

Measured memory_bytes: 9468
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
bool ki[222222];
ll dp[222222];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;cin>>n>>m;
  for(int i=0;i<m;i++){
    ll a;cin>>a;
    ki[a]=true;
  }
  dp[0]=1;
  for(int i=0;i<n;i++){
    if(ki[i+1]==false){dp[i+1]+=dp[i];dp[i+1]%=MOD;}
    if(ki[i+2]==false){dp[i+2]+=dp[i];dp[i+2]%=MOD;}
  }
  cout<<dp[n]%MOD<<endl;
  return 0;
}


Measured memory_bytes: 1152
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')
import sys
import itertools
import copy


def main():
    N, D = MI()
    L = LLIN(N)
    cnt = 0
    for l in L:
        num = l[0] ** 2 + l[1] ** 2 
        if num <= D ** 2:
            cnt+=1
    print(cnt)
    # print(row)
    # total = sum(row)
    # target = total - K
    # if K == total:
    #     print(1)
    #     sys.exit()
    # col = []
    # for w in range(W):
    #     cnt = 0
    #     for h in range(H):    
    #         print(A[h][w])
    #         if A[h][w] == '#':
    #             cnt += 1
    #     col.append(cnt)
    # print(col)
    # ans = 0
    # for w in range(W):
    #     for h in range(H):
    #         if A[h][w] == '#':
    #             if col[w] + row[h] - 1 == target:
    #                 print(str(h) + str(w))
    #                 ans +=1
    #         else:
    #             if col[w] + row[h] == target:
    #                 print(str(h) + str(w))
    #                 ans +=1
    # print(ans)
    #     for  in x:


    # print('AC x ' + str(cnt['AC']))
    # print('WA x ' + str(cnt['WA']))
    # print('TLE x ' + str(cnt['TLE']))
    # print('RE x ' + str(cnt['RE']))
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 47252
#include <algorithm>
#include <cstdio>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define whole(x) begin(x), end(x)
using ll = long long;
using namespace std;

constexpr int mod = 1e9+7;
int main() {
    // input
    int n; scanf("%d", &n);
    vector<int> a(n); repeat (i, n) scanf("%d", &a[i]);
    vector<int> b(n); repeat (i, n) scanf("%d", &b[i]);
    // solve
    vector<pair<int, bool> > events;
    repeat (i, n) {
        events.emplace_back(a[i], false);
        events.emplace_back(b[i], true);
    }
    sort(whole(events));
    ll result = 1;
    int cnt = 0;
    for (auto event : events) {
        int delta = (event.second ? 1 : -1);
        if (cnt != 0 and (cnt > 0) != event.second) {
            result = (result * std::abs(cnt)) % mod;
        }
        cnt += delta;
    }
    // output
    printf("%lld\n", result);
    return 0;
}


Measured memory_bytes: 3188
#include <stdio.h>
int main(void)

{
    int n,m,c,i,j,s,o=0;
    scanf("%d%d%d",&n,&m,&c);
    int a[n][m],b[m];

    for(i=0;i<m;i++)
       scanf("%d",&b[i]);
    for(i=0;i<n;i++){
       for(j=0;j<m;j++)
          scanf("%d",&a[i][j]);
          }

    for(i=0;i<n;i++){
       s = 0;
       for(j=0;j<m;j++){
           s = a[i][j] * b[j] + s;
           }
       if(s+c>0) o++;
       }

    printf("%d\n",o);
    return 0;
}


Measured memory_bytes: 128
function main(input) {
    var min=Math.pow(10,10), max=-1;
    var list = input[1].split(" ").map(v=>v-0).forEach(v=>{
        min = Math.min(min, v);
        max = Math.max(max, v);
    });
    console.log(max-min);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 7372
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
    int N; cin >> N;

    unsigned long long B, prev, total;
    cin >> B; total = B; prev = B;
    for (int i = 1; i < N-1; i++) {
        cin >> B;
        total += min(prev, B);
        prev = B;
    }
    
    total += prev;
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;cin>>a>>b;
    cout << max(0LL, a-2*b) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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


const int N = 1e6 + 5;

int dp[N][2];

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	string s;
	cin >> s;
	dp[0][0] = 0;
	dp[0][1] = 1;
	rep(i,1,s.length()+1){
		int cur = s[i-1] - '0';	
		dp[i][0] = min(dp[i-1][0] + cur,dp[i-1][1] + 10 - cur);
		++cur;
		dp[i][1] = min(dp[i-1][0] + cur,dp[i-1][1] + 10 - cur);
	}
	cout << dp[s.length()][0] << '\n';
}


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

int dp[100001][4][4][4];
tuple<int, int, int> prv[100001][4][4][4];
char ch[100001][4][4][4];

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

	int n, a, b, c; cin >> n >> a >> b >> c;
	a = min(a, 3); b = min(b, 3); c = min(c, 3);

	dp[0][a][b][c] = 1;
	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		for (int x = 0; x <= 3; x++) {
			for (int y = 0; y <= 3; y++) {
				for (int z = 0; z <= 3; z++) {
					if (!dp[i][x][y][z]) continue;

					if (s == "AB") {
						// move x to y or y to x
						if (x > 0) {
							dp[i+1][x-1][min(y+1, 3)][z] = 1;
							prv[i+1][x-1][min(y+1, 3)][z] = make_tuple(x, y, z);
							ch[i+1][x-1][min(y+1, 3)][z] = 'B';
						}
						if (y > 0) {
							dp[i+1][min(x+1, 3)][y-1][z] = 1;
							prv[i+1][min(x+1, 3)][y-1][z] = make_tuple(x, y, z);
							ch[i+1][min(x+1, 3)][y-1][z] = 'A';
						}
					} 

					if (s == "BC") {
						if (y > 0) {
							// add to z
							dp[i+1][x][y-1][min(z+1, 3)] = 1;
							prv[i+1][x][y-1][min(z+1, 3)] = make_tuple(x, y, z);
							ch[i+1][x][y-1][min(z+1, 3)] = 'C';
						}
						if (z > 0) {
							// add to y
							dp[i+1][x][min(y+1, 3)][z-1] = 1;
							prv[i+1][x][min(y+1, 3)][z-1] = make_tuple(x, y, z);
							ch[i+1][x][min(y+1, 3)][z-1] = 'B';
						}
					}

					if (s == "AC") {
						if (x > 0) {
							// add to z
							dp[i+1][x-1][y][min(z+1, 3)] = 1;
							prv[i+1][x-1][y][min(z+1, 3)] = make_tuple(x, y, z);
							ch[i+1][x-1][y][min(z+1, 3)] = 'C';
						}
						if (z > 0) {
							// add to x
							dp[i+1][min(x+1, 3)][y][z-1] = 1;
							prv[i+1][min(x+1, 3)][y][z-1] = make_tuple(x, y, z);
							ch[i+1][min(x+1, 3)][y][z-1] = 'A';
						}
					}
				}
			}
		}
	}

	int x, y, z, f = 0;
	for (x = 0; x <= 3; x++) {
		for (y = 0; y <= 3; y++) {
			for (z = 0; z <= 3; z++) {
				if (dp[n][x][y][z]) {
					f = 1; break;
				}
			}
			if (f) break;
		}
		if (f) break;
	}
	if (!f) {cout << "No\n";}
	else {
		cout << "Yes\n";
		string ans;
		int i = n;
		while (i > 0) {
			ans.push_back(ch[i][x][y][z]);
			tie(x, y, z) = prv[i][x][y][z];
			i--;
		}

		reverse(ans.begin(), ans.end());
		for (char c: ans) cout << c << '\n';
	}

	return 0;
}


Measured memory_bytes: 109984
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>

using namespace std;

int main(void) {
  int N;
  cin >> N;
  int v[N];
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  sort(v, v+N);
  double s;
  s = v[0];
  for (int i = 0; i < N - 1; i++) {
    s = (s + v[i+1]) / 2;
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let (n, l): (usize, i64) = read();
    let a: Vec<i64> = readnc();

    let mut lol: usize = n+1;
    for i in 0..n-1 {
        if a[i] + a[i+1] >= l {
            lol = i;
            break;
        }
    }

    if lol >= n {
        println!("Impossible");
    } else {
        println!("Possible");
        for i in 0..lol {
            println!("{}", i+1);
        }
        for i in (lol+1..n-1).rev() {
            println!("{}", i+1);
        }
        println!("{}", lol+1);
    }
}

Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for(int i=0; i<(int)(n); ++i)
const int MAX_N = 1e5 + 5;

vector<int> g[MAX_N];
vector<int> color;
bool bipartite;
int b, w;
void dfs(int u = 0, int c = 0) {
  color[u] = c;
  if (c) ++w;
  else ++b;
  for (int to : g[u]) {
    if (color[to] != -1) {
      if (color[to] == c) {
        bipartite = false;
        return;
      } else {
        continue;
      }
    }
    dfs(to, 1-c);
  }
}

void solve() {
  int n, m;
  cin >> n >> m;
  rep(i, m) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  bipartite = true;
  color.assign(n, -1);
  dfs();
  ll ans = 1;
  if (bipartite) {
    ans = ans * b * w;
  } else {
    ans = ans * n * (n-1) / 2;
  }
  cout << ans-m << endl;
}
void solve(bool tests) {
  int t;
  cin >> t;
  while (t--) solve();
}

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

Measured memory_bytes: 6912