akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	string n; cin >> n;
	int nsize = n.l_ength();
	int m; cin >> m;
	ll dp[100010][2][100];
	memset( dp, 0ll, sizeof(dp) );
	dp[0][0][0] = 1;
	for( int i = 0; i < nsize; ++i ){
		for( int less = 0; less <= 1; ++less ){
			for( int k = 0; k < m; ++k ){
				int bound = less ? 9 : n[i] - '0';
				for( int d = 0; d <= bound; ++d ){
					dp[i+1][ less || ( d != bound ) ][ (k+d)%m ] += dp[i][less][k];
                 	dp[i+1][ less || ( d != bound ) ][ (k+d)%m ] %= MOD;
				}
			}
		}
	}
	cout << ( dp[nsize][0][0] + dp[nsize][1][0] + MOD - 1 ) % MOD << endl;
	return 0;
}

Measured memory_bytes: 156544
from functools import reduce


def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a % b)


def gcd(num):
    return reduce(euclid, num)


k = int(input())
ans = 0
i_list = []

for i1 in range(1, k+1):
    for i2 in range(1, k+1):
        for i3 in range(1, k+1):
            ans += gcd([i1, i2, i3])

print(ans)


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

int a[3];

int main() {
    cin >> a[0] >> a[1] >> a[2];

    sort(a, a+3);

    int ans = 3;
    if (a[0] == a[1]) ans--;
    if (a[1] == a[2]) ans--;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define int long long
#define double long double
#define all(a) a.begin(), a.end()
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; }
using namespace std;

signed main(void){
    
    int K; cin >> K;
    int cur = 0, add = 1;

    auto sum = [](int x){
        int res = 0;
        while(x > 0)res += x % 10, x /= 10;
        return res;
    };

    auto judge = [&](int x, int y){
        return x * sum(y) <= y * sum(x);
    };

    rep(i, K){
        if(!judge(cur + add, cur + add * 10))add *= 10;
        cur += add;
        cout << cur << endl;
    }

}

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

int main() {
	// your code goes here
	long long n,k,i,ans=1;
	cin >> n >> k;
	ans=k;
	for(i=2;i<=n;i++) ans*=(k-1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define hii cout << "hii" << endl
#define int long long
#define endl '\n'
#define all(s) s.begin(), s.end()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

const int N = 5e5 + 5;
const int MAX = 250000 + 5;
const int M = 1e6 + 5;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int INF = 1e18 + 8;
const int LG = 21;

int arr[N];
int DP[N];

int f(int idx)
{
	if(idx == 0)
	{
		return 1;
	}
	int & ret = DP[idx];
	if(~ret) return ret;
	ret = 0;
	for(int i = 3; i <= idx; i++)
	{
		ret += f(idx - i);
		ret %= mod;
	}
	return ret;
}

void solve()
{
	int n;
	cin >> n;
    int mx1 = -INF; 
    int mx2 = -INF;
    int mn1 = INF;
    int mn2 = INF;
    for(int i = 0; i  < n; i++)
    {
       int a, b;
       cin >> a >> b;
       mx1 = max(mx1, a + b);
       mx2 = max(mx2, a - b);
       mn1 = min(mn1, a + b);
       mn2 = min(mn2, a - b);
    }
    cout << max(mx1 - mn1, mx2 - mn2);
}


 
int32_t main() 
{	
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	    int t = 1;
	    // cin >> t;
	while(t--)solve();
	return 0;
}

Measured memory_bytes: 3644
n = int(input())
arr = map(int, input().split())
d = {}
for i in arr:
    i -= 1
    if i not in d:
        d[i] = 1
    else:
        d[i] += 1

for i in range(n):
    if i in d:
        print(d[i])
    else:
        print(0)




Measured memory_bytes: 107596
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func fSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	s, t := Scan(), Scan()
	ans := mod
	for i := 0; i < len(s)-len(t)+1; i++ {
		x := s[i : i+len(t)]
		c := 0
		for j := 0; j < len(t); j++ {
			if t[j] != x[j] {
				c++
			}
		}
		ans = smaller(c, ans)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1776
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int[]X = new int[N];
		int[]Y = new int[N];
		for(var i=0;i<N;i++){
			string[]str = Console.ReadLine().Split();
			X[i] = int.Parse(str[0]);
			Y[i] = int.Parse(str[1]);
		}
		int min1 = 2000000000;
		int max1 = -2000000000;
		int min2 = 2000000000;
		int max2 = -2000000000;
		for(var i=0;i<N;i++){
			min1 = Math.Min(min1,X[i] - Y[i]);
			max1 = Math.Max(max1,X[i] - Y[i]);
			min2 = Math.Min(min2,X[i] + Y[i]);
			max2 = Math.Max(max2,X[i] + Y[i]);
		}
		long ans = Math.Max(max2-min2,max1-min1);
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 22968
//C
#include <cassert>
//#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//ここまで標準include

using namespace std;

long aCb(long a, long b) {
	long out = 1;
	for (long i = 1; i <= b; i++) {
		out = out * (a + 1 - i) / i;
	}
	return out;
}

long long gcd(long long a, long long b) {
	long long r = -1;
	if (a < b) {
		swap(a, b);
	}
	while (r != 0) {
		r = a % b;
		if (r == 0) {
			return b;
		}
		else {
			a = b;
			b = r;
		}
	}
}

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

int main() {
	int X, A, B;
	cin >> X >> A >> B;
	if (B <= A) {
		cout << "delicious" << endl;
		return 0;
	}
	else if (B - A <= X) {
		cout << "safe" << endl;
		return 0;
	}
	else {
		cout << "dangerous" << endl;
		return 0;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,s,a[105][2];
long long f[105][100005];
int main(){
    cin >> n >> s;
    for(int i=1;i<=n;++i){
        cin >> a[i][0];
        cin >> a[i][1];
    }
    for(int j=1;j<=s;++j){
        for(int i=1;i<=n;++i){
            if(j>=a[i][0]){
                f[i][j]=max(f[i-1][j],f[i-1][j-a[i][0]]+a[i][1]);
            }
            else{
                f[i][j]=f[i-1][j];
            }
        }
    }
    cout << f[n][s];
    return 0;
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Pos(i) cout<<(i?"Possible":"Impossible")<<endl
#define co(i) cout<<i<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;

int main(){
	int n,m; cin>>n>>m;
	vector<PA> v,w;
	FOR(i,0,m){
		int a,b; cin>>a>>b;
		v.PB(PA(b,a));
	}
	sort(v.begin(), v.end());
	int na=0,nb=0;
	FOR(i,0,m){
		int a=v[i].SE, b=v[i].FI;
		if(na<a&&nb==b){
			w[w.size()-1]=PA(a,b);
			na=a;
			nb=b;
		}
		if(na<a&&nb<b){
			w.PB(PA(a,b));
			na=a;
			nb=b;
		}
	}
	int ans=0;
	int brk=0;
	FOR(i,0,w.size()){
		//co(w[i].FI<<" "<<w[i].SE);
		if(w[i].FI>=brk){
			brk=w[i].SE;
			ans++;
		}
	}
	co(ans);
}

Measured memory_bytes: 2548
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
    int P, Q, R;

    cin >> P >> Q >> R;

    int max = 0;

    if (P > max)
    {
        max = P;
    }
    if (Q > max)
    {
        max = Q;
    }
    if (R > max)
    {
        max = R;
    }

    int time = P + Q + R - max;

    cout << time << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

#include <map>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n;
    cin, n;
    map<ll, ll> m;
    ll t = n;
    for (ll i = 2; i * i <= n; i++) {
        while (t % i == 0) {
            m[i]++;
            t /= i;
        }
    }
    if (t != 1) {
        m[t]++;
    }
    ll ans = 0;
    for (auto p : m) {
        for (int i = 1; p.second > 0; i++) {
            if (p.second >= i) {
                ans++;
            }
            p.second -= i;
        }
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

class UnionFind {
public:
	vector<int> r, p;

	UnionFind() {}
	UnionFind(int size) {
		r.resize(size, 0);
		p.resize(size, 0);
		rep(i, 0, size)makeSet(i);
	}

	void makeSet(int x) {
		p[x] = x;
		r[x] = 0;
	}

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

	void unite(int x, int y) {
		link(findSet(x), findSet(y));
	}

	void link(int x, int y) {
		if (r[x] > r[y]) {
			p[y] = x;
		}
		else {
			p[x] = y;
			if (x == y) {
				r[y]++;
			}
		}
	}


	int findSet(int x) {
		if (x == p[x]) {
			return x;
		}
		else {
			return p[x] = findSet(p[x]);
		}
	}

};


vector<ll>a;
int N, M;


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

	cin >> N >> M;
	UnionFind un = UnionFind(N);
	a.resize(N);
	for (int i = 0; i < N; i++)cin >> a[i];

	for (int i = 0; i < M; i++) {
		int x, y;
		cin >> x >> y;
		un.unite(x, y);
	}

	min_priority_queue<ll>q[101010];
	min_priority_queue<ll>q2;
	set<int>st;
	for (int i = 0; i < N; i++) {
		int pa = un.findSet(i);
		q[pa].push(a[i]);
		st.insert(pa);
	}
	if(st.size() == 1){puts(0);return 0;}
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		if (q[i].size()) {
			ans += q[i].top();
			q[i].pop();
			while (q[i].size()) {
				q2.push(q[i].top());
				q[i].pop();
			}
		}
	}

	for (int i = 0; i < (int)st.size()-2; i++) {
		if (!q2.size()) { puts("Impossible"); return 0; }
		ans += q2.top();
		q2.pop();
	}
	puts(ans);

	return 0;
}

Measured memory_bytes: 12800
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int y = sc.nextInt();
        int x = sc.nextInt();
        boolean grid[][] = new boolean[y][x];
        for (int iy = 0; iy < y; iy++) {
            String tmpStr[] = sc.next().split("");
            for (int ix = 0; ix < x; ix++) {
                grid[iy][ix] = tmpStr[ix].equals("#");
            }
        }

        for (int iy = 0; iy < y; iy++) {
            for (int ix = 0; ix < x; ix++) {
                if (!grid[iy][ix]) {
                    continue;
                }

                if ((iy > 0 && grid[iy - 1][ix]) ||
                    (iy < y - 1 && grid[iy + 1][ix]) ||
                    (ix > 0 && grid[iy][ix - 1]) ||
                    (ix < x - 1 && grid[iy][ix + 1]))
                {
                    continue;
                }
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}

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

int main() {
  double D, T, S;
  cin >> D >> T >> S;
  double ds;
  ds = D/S;
  if(ds > T) {
    cout << "No" << endl;
  }else {
    cout << "Yes" << endl;
  }
  
}

Measured memory_bytes: 3712
#include<iostream>
#include<string>
#include<set>
using namespace std;

int main() {
	int n;
	cin >> n;

	set<string> Dic;
	string com, word;

	while( n-- ) {
		cin>>com>>word;
		if(com[0] == 'i' ) Dic.insert(word);
		else {
			if( Dic.find(word) != Dic.end() ) cout << "yes" << endl;
			else cout << "no" <<endl;
		}
	}
}


Measured memory_bytes: 32580
#include <iostream>
using namespace std;
      
int main()
{
	int n, m;
	cin >> n >> m;
	char a[n][n], b[m][m];
	for(int i = 0; i < n; i++)
    	for(int j = 0; j < n; j++)
			cin >> a[i][j];


	for(int i = 0; i < m; i++)
    	for(int j = 0; j < m; j++)
    		cin >> b[i][j];

	bool check = false;
	for(int i = 0; i <= n-m; i++)
		for(int j = 0; j <= n-m; j++)
		{
	    	for(int k = 0; k < m; k++)
	        	for(int l = 0; l < m; l++)
	        		if( b[k][l] != a[i+k][j+l] )
	        		{
	            		check = true;
	        			goto end;
	        		}
	      	end:{}
	      	if( check == false )
	    	{
	    		cout << "Yes";
				return 0;
			}
	    	check = false;
	    }
	cout << "No";
}

Measured memory_bytes: 3160
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: i32 = input();
    let k: i32 = input();

    if k == 1 {
        println!("0");
    } else {
        println!("{}", n - k);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll gcd(ll x, ll y){
  if(x%y==0)return y;
  return gcd(y,x%y);
}
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}
vector<vector<ll>>G(MAX);
vector<bool>seen(MAX,false);
vector<ll> ans(MAX);

void dfs(int p,int v){
  seen[v]=true;
  if(v!=0)ans[v]+=ans[p];
  for(auto nv:G[v]){
    if(!seen[nv]) dfs(v,nv);
  }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int a,b,q;
  cin >> a >> b >> q;
  vector<ll>s(a+2);
  vector<ll>t(b+2);
  rep(i,a) cin >> s[i];
  rep(i,b) cin >> t[i];
  s[a]=INF,s[a+1]=-INF;
  t[b]=INF,t[b+1]=-INF;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  rep(i,q){
    ll x;
    cin >> x;
    ll ans=INF;
    ll rs=abs(*lower_bound(s.begin(),s.end(),x));
    ll rt=abs(*lower_bound(t.begin(),t.end(),x));
    ll ls=abs(*(upper_bound(s.begin(),s.end(),x)-1));
    ll lt=abs(*(upper_bound(t.begin(),t.end(),x)-1));
    
    chmin(ans,abs(rs-x)+abs(rt-rs));
    chmin(ans,abs(rs-x)+abs(lt-rs));
    chmin(ans,abs(ls-x)+abs(rt-ls));
    chmin(ans,abs(ls-x)+abs(lt-ls));
    chmin(ans,abs(rt-x)+abs(rs-rt));
    chmin(ans,abs(rt-x)+abs(ls-rt));
    chmin(ans,abs(lt-x)+abs(rs-lt));
    chmin(ans,abs(lt-x)+abs(ls-lt));
    cout << ans << endl;
  }
    
  
}


Measured memory_bytes: 18944
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    
    if(b-a==c-b) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
    return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

void read() {
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if (u == s)
        a--;
    else
        b--;
    cout << a << " " << b << endl;
} 

void run() {

}

void write() {

}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    read();
    run();
    write();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cin_fit() cin.tie(nullptr);ios::sync_with_stdio(false)
#define rep(i, N) for(int i=0; i<(N); i++)
#define reps(i, N) for(int i=1; i<=(N); i++)
#define rrep(i, N) for(int i=(int)(N)-1; i>=0; i--)
#define rreps(i, N) for(int i=(int)(N); i>=1; i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using V = vector<ll>;
using P = pair<ll, ll>;
constexpr int inf = 1e9;
constexpr int mod = 1e9+7;
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;}

ll n, m;

int main() {
    cin >> n >> m;
    ll id_min = 1, id_max = n;
    rep(i, m) {
        ll l, r; cin >> l >> r;
        id_min = max({l, id_min});
        id_max = min({r, id_max});
    }
    ll ans = max({id_max - id_min + 1, 0LL});
    cout << ans << endl;
    return 0;
}


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

int main() {
    string s,t;
    cin >> s >> t;
    rep(i,s.size()) {
        s = s[s.size()-1]+s.substr(0,s.size()-1);
        if(s == t) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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



signed main(){
    string n;
    cin>>n;
    ll count=0;
    for(auto i:n){
        count+=i-'0';
        count%=9;
    }
    if(count==0)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3752
#include <stdio.h>

int G[100][100],d[100],v[100];
int saisyou(int);

int main(){
  int a,n,i,j;
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&G[i][j]);
    }
  }
  a=saisyou(n);
  printf("%d\n",a);

  return 0;
}

int saisyou(int n){
  int i,j,k=1,min,minp,sum=0;
  
  d[0]=0;
  v[0]=1;

  for(i=1;i<n;i++) v[i]=0;

  while(1){
    min = 2001;
    for(i=0;i<k;i++){
      for(j=0;j<n;j++){
	if(G[d[i]][j]<min && G[d[i]][j] != -1 && v[j] != 1){
	  min = G[d[i]][j];
	  minp = j;
	}
      }
    }
    
    if(k==n) break;
    d[k] = minp;
    v[minp] = 1;
    sum += min;
    k++;
  }

  return sum;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
 int A,B,C ;
 int login=0;
 int coin=0;
 cin >> A >> B >> C;
 while(coin<C){
     coin = coin + A;
     login++;
     if(login%7==0){
         coin = coin + B;
     }
 }
 cout << login << endl;
}


Measured memory_bytes: 3112
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#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__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

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

ll f1[NMAX*2];
ll f2[NMAX*2];
ll inv[NMAX*2];
    
    
void fact()
{
	inv[1] = 1;
	int M = MOD;
	for(int i = 2; i< NMAX*2; ++i)
	{
		inv[i] = M - M/i * inv[M%i] % M;
	} 

	f1[0] = f2[0] = 1;;
	for(int i = 1; i< NMAX * 2; ++i)
	{
		f1[i] = (f1[i-1] * i) % MOD;
		f2[i] = (f2[i-1] * inv[i]) %  MOD;
	}
}


ll C(ll n, ll k)
{
    return f1[n]*f2[n-k]%MOD * f2[k] %MOD;
}
    

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

	int n,k;
	cin >> n >> k;
	fact();
	


	ll ans = C(2*n -1, n- 1);

	for(++k; k <= n -1; ++k)
	{
		ans = (ans + MOD - C(n,k)* C(n-1,n-1-k)% MOD)%MOD;
	}

	cout << ans;


    return 0;
}

Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	string s1, s2;
	cin >> s1 >> s2;
	int a, b;
	cin >> a >> b;
	string u;
	cin >> u;
	if(u==s1) a--;
	else b--;
	cout << a << " " << b << endl;
	return 0;
}



Measured memory_bytes: 3596
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,x,t;
	scanf("%d %d %d",&n,&x,&t);
	if(n%x==0)	printf("%d\n",(n/x)*t);
	else	printf("%d\n",(n/x+1)*t);
	return 0;
}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vector<Int> a(n,0);
    for(int i=0; i<n; i++) cin>>a[i];
    int q; cin>>q;
    rep(i,q) {
        Int k; cin>>k;
        auto d= lower_bound(a.begin(),a.end(),k);
        cout<<distance(a.begin(),d)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N, M;
int s[600*600], t[600*600];
vector<int> e[600];

double dp[600][600];
bool vis[600][600] ={};
double solve(int n, int x){
    if(vis[n][x]) return dp[n][x];
    vis[n][x] = true;
    if(n == N-1) dp[n][x] = 0;
    else{
        dp[n][x] = 0;
        if(x != n || e[n].size() == 1){
            rep(i, e[n].size()){
                dp[n][x] += solve(e[n][i], x) + 1;
            }
            dp[n][x] /= e[n].size();
        }
        else{
            double M = 0;
            rep(i, e[n].size()){
                dp[n][x] += solve(e[n][i], x) + 1;
                M = max(M, solve(e[n][i], x) + 1);
            }
            dp[n][x] -= M;
            dp[n][x] /= e[n].size()-1;
        }
    }
    return dp[n][x];
}

signed main(){
    cin >> N >> M;
    rep(i, M){
        cin >> s[i] >> t[i];
        s[i]--; t[i]--;
        e[s[i]].pb(t[i]);
    }

    double ans = LLONG_MAX;
    rep(i, N){
        ans = min(ans, solve(0, i));
    }
    cout << fixed << setprecision(16) << ans << endl;
}

Measured memory_bytes: 6144
def main():
    N = int(input())
    from math import hypot
    XY = [[int(i) for i in input().split()] for j in range(N)]
    from itertools import permutations
    ans = 0
    for p in permutations(range(N)):
        cur = 0
        pre = p[0]
        for i in p[1:]:
            cur += hypot(XY[pre][0] - XY[i][0], XY[pre][1] - XY[i][1])
        ans += cur
    acc = 1
    for i in range(2, N+1):
        acc *= i
    print(ans/acc)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40556
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int ans,j,mx,n,i,a[200001];
bool cmp(int a,int b){
	return a>b;
}
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1,cmp);
	/*mx=2e9;
	for(i=1;i<=n;i++){
		if(a[i]>a[i-1])mx=min(mx,a[i]-i);
	}
	ans=mx+n-1;
	if(ans%2==0)puts("Second");
	 else puts("First");*/
	for(i=1;i<=n;i++)if(i>a[i])break;
	i--;
	if((a[i]-i)%2)return puts("First"),0;
	for(j=i+1;a[j]==i;j++);
	j--;
	if((j-i)%2)puts("First");
	 else puts("Second");
}
/*
观察到sg函数0 or 1跟与端点距离有关 
*/

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int n, m;
char mat[8][8];
int main() {
	cin >> n >> m;
	int c = 0;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++) {
			cin >> mat[i][j];
			if(mat[i][j] == '#') c++;
		}
	if(c != n+m-1) return cout << "Impossible", 0;
	for(int i = 0; i < 1<<(n+m-2); i++) {
		int x = 0, y = 0, cc = mat[1][1]=='#';
		for(int j = 0; j < n+m-2; j++) {
			if((i>>j)&1) x++;
			else y++;
			if(x >= n || y >= m) break;
			cc += mat[x][y] == '#';
		}
		if(cc != n+m-1) return cout << "Possible", 0;
	}
	cout << "Impossible";
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	private void doit() {
		Scanner sc = new Scanner(System.in);
		int MAX = 3000000;
		boolean [] isprime = new boolean[MAX + 1];
		for(int i = 6; i <= MAX;i+= 7){
			isprime[i] = true;
		}
		for(int i = 8; i<= MAX; i+= 7){
			isprime[i] = true;
		}
		for(int i = 6; i * i <= MAX ; i+=7){
			if(isprime[i]){
				for(int j = i * 2; j <= MAX; j += i){
					isprime[j] = false;
				}
			}
			if((i + 2) <= MAX && isprime[i+2]){
				for(int j = (i+2) * 2; j <= MAX; j+= (i+2)){
					isprime[j] = false;
				}
			}
		}
		while(true){
			int n = sc.nextInt();
			if(n == 1){
				break;
			}
			System.out.print(n+":" );
			for(int i = 6; i <= n; i+=7){
				if(isprime[i] && n % i == 0){
					System.out.print(" " +i);
				}
				if((i + 2) <= n && isprime[i+2] && n % (i+2) == 0){
					System.out.print(" " +(i+2));
				}
			}
			System.out.println();
		}
	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

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

int arr[1000100];
int flag[1000100];

int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		arr[x]++;
		flag[x] = (arr[x] == 1);
	}
	for(int i = 1; i < 1000001; i++) {
		if(arr[1]){
			if(i > 1)
				flag[i] = 0;
		}
		for(int j = 2; j < 1002; j++) {
			if(i * j > 1000000) break;
			if(arr[i]) {
				flag[i*j] = 0;
			} else if(arr[j]) {
				if(i == 1 && arr[1])
					flag[i*j] = 0;
				else if(i > 1) flag[i*j] = 0;
			}
		}
	}
	int cnt = 0;
	for(int i = 0; i < 1000001; i++) {
		if(flag[i]){
			cnt++;
		}
	}
	printf("%d\n", cnt);
}


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

int main(){
    ll n,t;
    cin >> n >> t;
    vector<ll> people(n);
    for(int i=0; i<n; i++){
        cin >> people.at(i);
    }
    ll ans = t;
    for(int i=1; i<n; i++){
        if(people.at(i-1)+t<=people.at(i)) ans+=t;
        else ans+=t-(people.at(i-1)+t-people.at(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 4752
import numpy as np
from scipy.sparse.csgraph import shortest_path

H, W = map(int, input().split())
path = shortest_path(np.array(tuple(tuple(map(int, input().split())) for _ in range(10))))
A = np.array(tuple(tuple(map(int, input().split())) for _ in range(H))).flatten()

print(int(sum(path[n][1] for n in A if n not in [-1, 1])))


Measured memory_bytes: 18124
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] s = br.readLine().split("");
		String[] t = br.readLine().split("");
		
		
		boolean flag = true;
		
		
		ArrayList<String> S = new ArrayList<>();
		ArrayList<String> T = new ArrayList<>();
		
		
		for (int i = 0; i < s.length && flag; i++) {
			if (!S.contains(s[i])) {
				S.add(s[i]);
			}
			s[i] = Integer.toString(S.indexOf(s[i]));
			if (!T.contains(t[i])) {
				T.add(t[i]);
			}
			t[i] = Integer.toString(T.indexOf(t[i]));
			if (!s[i].equals(t[i]))
				flag = false;
		}

		if (flag) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 68564
def readinput():
    n=int(input())
    return n

def main(n):
    if n%2==1:
        return 0
    
    n=n//2
    count=0
    base=5
    while(base<=n):
        count+=n//base
        base*=5
    return count

if __name__=='__main__':
    n=readinput()
    ans=main(n)
    print(ans)


Measured memory_bytes: 9176
#include <iostream>
#include <iomanip>

int main(void){
    int a,b;
    std::cin >> a >> b;
    std::cout << std::fixed;
    std::cout << a/b << " " << a%b << " " << std::setprecision(11) << (double)a/(double)b << std::endl;
    return 0;
}


Measured memory_bytes: 3252
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
vector<i64> s;
int main() {
  cin >> n;
  read_n(s, 1 << n);

  sort(begin(s), end(s), greater<i64>());

  bool ok = true;

  map<i64, i64> rest, added;
  for (i64 x : s) rest[x]++;
  i64 x = rbegin(rest)->first;
  added[x] = 1;
  rest[x]--;
  if (rest[x] == 0) {
    rest.erase(x);
  }

  while (!rest.empty()) {
    map<i64, i64> added_new = added;
    for (auto p : added) {
      for (i64 i = 0; i < p.second; ++i) {
        i64 x = p.first;
        auto it = rest.lower_bound(x);
        if (it == begin(rest)) {
          cout << "No\n"; return 0;
        }
        it--;
        i64 y = it->first;
        added_new[y]++;
        rest[y]--;
        if (rest[y] == 0) rest.erase(y);
      }
    }
    added = added_new;
  }

  cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 35072
#include <iostream>
 
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <random>
#include <chrono>

#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
 
#define itn int
#define fro for
#define lowbit(x) (x & (-x))
#define Fast freopen("in.txt", "r", stdin)

using namespace std;
typedef long long ll;


/*------------------------------------------------------------------------------------*/
template <typename _t>
inline void read(_t &x){
    x = 0; _t fu = 1; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-') fu = - 1; ch = getchar();}
    while(ch >= '0' && ch <= '9'){
        x = (x << 3) + (x << 1) + (ch & 15);
        ch = getchar();
    }
    x *= fu ;
}
/*------------------------------------------------------------------------------------*/
ll gcd(ll x, ll y){return !x? y: gcd(y % x, x);}
void exgcd(ll a, ll b, ll &x, ll &y){
    if(!b){x = 1; y = 0;return;}
    exgcd(b, a % b, y, x);
    y -= a / b * x;
}
/*------------------------------------------------------------------------------------*/
struct Mart{
    int a, b, c, d;
    Mart operator *(Mart &m){
        Mart temp;
        temp.a = a * m.a + b * m.c;
        temp.b = a * m.b + b * m.d;
        temp.c = c * m.a + d * m.c;
        temp.d = c * m.b + d * m.d;
        return temp;
    }
    Mart(){a = b = c = d = 0;}
    Mart(int x[4]){a = x[0]; b = x[1]; c = x[2]; d = x[3];}
    Mart(int u, int v, int w, int x){a = u; b = v; c = w; d = x;}
    int det(){return a * d - b * c;}
};
/*------------------------------------------------------------------------------------*/

//const int maxn = 1e4 + 10;
const double pi = acos(-1);

int main(){
//    Fast;
    int r; scanf("%d", &r);
    printf("%.10f\n", 2 * pi * r);
    
    return 0;
}


Measured memory_bytes: 3784
#include <stdio.h>

int n;
long long int A[100000];

// max_{R} xor_R  + (A xor xor_R)
// max_{R} xor_R and ~A
/*
110
101
011

110
011
011

001
101
110

*/

int main(){
  int i;
  long long int a=0, b, c, z=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%lld", A+i);
    a ^= A[i];
  }
  for(i=0;i<n;i++){
    A[i] &= ~a;
  }

  for(b=1LL<<59;b;b>>=1){
    if(b&a) continue;
    for(i=0;i<n;i++){
      if(A[i]&b) break;
    }
    if(i==n) continue;
    if(!(z&b)) z ^= A[i];
    c = A[i];
    A[i] = 0;
    for(;i<n;i++){
      if(A[i]&b) A[i] ^= c;
    }
  }

  printf("%lld\n", 2*z + a);

  
  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int h, w;
int a[10][10];
int c;
int main() {
	cin >> h >> w;
	rep(i, 10) {
		rep(j, 10) {
			cin >> a[i][j];
		}
	}
	rep(k, 10) {
		rep(i, 10) {
			rep(j, 10) {
				a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
			}
		}
	}
	int ans = 0;
	rep(i, h) {
		rep(j, w) {
			cin >> c;
			if (c != -1)ans += a[c][1];
		}
	}
	cout << ans << endl;
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
s = input()
t = input()
ss = s+s
NEXT = [[-1]*(len(s)+1) for _ in range(26)]
cur = [-1]*26
for i in range(len(ss)):
    char = ord(ss[i])-97
    if cur[char] < len(s):
        for j in range(cur[char],min(i,len(s))):
            NEXT[char][j+1] = i
            cur[char] = i
ans = 0
tmp = -1
for i in range(len(t)):
    char = ord(t[i])-97
    if NEXT[char][tmp+1] == -1:
        print(-1)
        exit()
    ans += NEXT[char][tmp+1]-tmp
    tmp = NEXT[char][tmp+1]
    if tmp >= len(s):
        tmp -= len(s)
print(ans)


Measured memory_bytes: 63852
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=510;
char mat[N][N];
bool b[N][N];
int main(){
	memset(b,0,sizeof(b));
	int n=ni,m=ni;
	for(int i=1;i<=n;i++){
		scanf("%s",mat[i]+1);
		for(int j=i&1?min(2,m):m;j<=m;j++){
			b[i][j]=true;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			putchar(mat[i][j]=='#'||b[i][j]?'#':'.');
		}
		putchar('\n');
	}
	putchar('\n');
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			putchar(mat[i][j]=='#'||!b[i][j]?'#':'.');
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
struct edge{
	int to,next,w;
}e[maxn<<1];
int head[maxn<<1],cnt=0,color[maxn],vis[maxn]={0};
void add(int u,int v){
	e[++cnt].to=v;
	e[cnt].next=head[u];
	head[u]=cnt;
}
bool f=0;
void dfs(int u,int fa){
	vis[u]=1;
	for(int i=head[u];i;i=e[i].next){
		int v=e[i].to;
		if(v==fa)continue;
		if(vis[v]==2)continue;
		if(vis[v]==1){
			f=1;
			continue;
		}
		if(vis[v]==0){
			dfs(v,u);
		}
	}
	vis[u]=2;
} 
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		add(a,b);
		add(b,a); 
	}
	int num=0;
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			num++;
			f=0;
			dfs(i,0);
		}
	}
	printf("%d\n",num);
}


Measured memory_bytes: 8064
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
using namespace std;

const double PI = acos(-1.0);
struct Point{
    double x,y;
};

void koch(int n, Point a, Point b) {
    // 递归结束
    if (n == 0)
        return;
    // 三等分点s,t ，(u 是 s,t 上方的点)
    Point s, t, u;
    // 角度从度转成弧度
    double th = PI * 60.0 / 180.0;
    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;


    koch(n - 1, a, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(n - 1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(n - 1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(n - 1, t, b);
}
int main(){
    Point a, b;
    int n;
    scanf("%d", &n);

    // 初始化
    a.x = a.y = 0;
    b.x = 100, b.y = 0;
    printf("%.8f %.8f\n", a.x, a.y);
    koch(n, a, b);
    printf("%.8f %.8f\n", b.x, b.y);
    return 0;
}



Measured memory_bytes: 3232
import collections
N = int(input())
inp = list(map(int,input().split()))
dic = dict(collections.Counter(inp))
wa = 0
for i, j in dic.items():
	wa += i * j
se = set(dic.keys())
for i in range(int(input())):
	a, b = map(int,input().split())
	if a in se:
		wa += dic[a] * (b-a)
		if b in se:
			pass
		else:
			dic[b] = 0
		se.add(b)
		dic[b] += dic[a]
		dic[a] = 0
	print(wa)

Measured memory_bytes: 111672
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 998244353;

/*
    0
  1   2


*/

long long mod_pow(long long x, long long n) {
	if (n==0) return 1;
	long long res = mod_pow(x * x % MOD, n/2);
	if (n&1) res = res * x % MOD;
	return res;
}

vector<int> v;
ll c[100005];

int main(void) {
    int n, mx = -1;
    cin >> n;
    rep(i, 0, n) {
        int x;
        scanf("%d", &x);
        v.pb(x);
        mx = max(mx, x);
    }
    if (v[0]!=0) {
        puts("0");
        return 0;
    }

    rep(i, 0, n) c[v[i]]++;

    if (c[0]!=1) {
        puts("0");
        return 0;
    }
    ll ans = 1;
    rep(i, 1, mx+1) {
        ans *= mod_pow(c[i-1], c[i]);
        ans %= MOD;
    }

    cout << ans % MOD << endl;

	return 0;
}


Measured memory_bytes: 1528
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int main(void) {
	string str; cin >> str;
	int ans = 100000;
	for (int i = 0; i < str.length()-2; i++) {
		int a = (str[i] - 0x30) * 100 +
			(str[i + 1] - 0x30) * 10 +
			(str[i + 2] - 0x30);
		ans = min(abs(753 - a),ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import math
def nCr(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N,K = [int(i) for i in input().split()]
mod = 1000000000+7
for i in range(1,K+1):
    if N-K+1< i:
        print(0)
    else:
        ans = (nCr((N-K+1),i) * nCr(K-1,i-1)) % mod
        print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define IL inline
IL int read() {
	char ch = getchar(); int u = 0, f = 1;
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { u = (u << 1) + (u << 3) + ch - 48; ch = getchar(); }
	return u * f;
}
typedef long long ll;
int main() {
	int n = read();
	ll nowa = 0, nowb = 0;
	for (int i = 1; i <= n; ++i) {
		int a = read(), b = read();
		ll t = max(max((nowa % a == 0) ? nowa / a : nowa / a + 1, (nowb % b == 0) ? nowb / b : nowb / b + 1), 1ll);
		ll p = a * t;
		ll q = b * t;
		nowa = p, nowb = q; 
	}
	cout << nowa + nowb << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  bool p = false;
  bool w = false;
  bool g = false;
  bool y = false;

  for (int i=0; i<N; i++){
    string s;
    
    cin >> s;
    
    if (s=="P")
      p = true;
    if (s=="W")
      w = true;
    if (s=="G")
      g = true;
    if (s=="Y")
      y = true;
  }
  if (p && w && g && !y)
    cout << "Three" << endl;
  if (p && w && g && y)
    cout << "Four" << endl;
}


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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using v = vector<T>;
template <class T>
using vv = v<v<T>>;
#define ALL(c) (c).begin(), (c).end()

int main()
{
    int sx, sy;
    int tx, ty;
    cin >> sx >> sy >> tx >> ty;

    v<string> root(4);

    for (int i = 0; i < ty - sy; i++)
    {
        root[0].push_back('U');
        root[1].push_back('D');
    }

    for (int i = 0; i < tx - sx; i++)
    {
        root[0].push_back('R');
        root[1].push_back('L');
    }

    root[2].push_back('L');
    root[3].push_back('R');
    for (int i = 0; i < ty - sy + 1; i++)
    {
        root[2].push_back('U');
        root[3].push_back('D');
    }

    for (int i = 0; i < tx - sx + 1; i++)
    {
        root[2].push_back('R');
        root[3].push_back('L');
    }
    root[2].push_back('D');
    root[3].push_back('U');

    for (int i = 0; i < root.size(); i++)
        cout << root[i];

    cout << endl;

    return 0;
}

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

using namespace std;

bool s[100001];
bool w[100001];

int main()
{
    #ifdef DEBUG
    freopen("input.txt", "r", stdin);
    #endif
    int n;
    cin >> n;
    string s1;
    cin >> s1;
    for (int i = 0; i < n; i++){
        s[i] = s1[i] == 'x';
    }
    for (int mask = 0; mask < 8; mask++){
            w[0] = mask & 1;
            w[1] = (mask >> 1) & 1;
            w[2] = (mask >> 2) & 1;
            for (int i = 3; i < n; i++){
                w[i] = w[i - 3] ^ s[i - 2] ^ s[i - 1];
            }
            bool b = true;
            for (int i = 0; i < n; i++){
                b &= (s[i] == w[(i + n - 1) % n] ^ w[i] ^ w[(i + 1) % n]);
            }
            if (b){
                for (int i = 0; i < n; i++){
                    if (w[i]) cout << "W";
                    else cout << "S";
                }
                return 0;
            }
    }
    cout << -1;
    return 0;
}



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

using namespace std;

typedef long long ll;

const ll N = 2e5 + 100;

ll h[N];

int main() {
    ll n, k, sum = 0;
    cin >> n >> k;
    for (ll i = 0; i < n; ++i)
        cin >> h[i];
    sort(h, h + n);
    if (k >= n)
        cout << "0\n";
    else {
        for (ll i = 0; i < n - k; ++i)
            sum += h[i];
        cout << sum << '\n';
    }
}

Measured memory_bytes: 1792