akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

vector<long long> shr, tem;

int main() {
	int a, b, q;
	scanf("%d %d %d", &a, &b, &q);
	shr.assign(a, 0);
	tem.assign(b, 0);

	for (int i = 0;i < a;++i)
		scanf("%lld", &shr[i]);

	for (int i = 0;i < b;++i)
		scanf("%lld", &tem[i]);

	while (q--) {
		long long x;
		scanf("%lld", &x);

		long long mn = 1e18;

		auto rshr = lower_bound(shr.begin(), shr.end(), x);
		auto rtem = lower_bound(tem.begin(), tem.end(), x);
		auto lshr = rshr;
		auto ltem = rtem;
		if (rshr != shr.begin())
			lshr--;
		if (rtem != tem.begin())
			ltem--;
		if (rshr != shr.end() && *rshr == x)
			lshr = rshr;
		if (rtem != tem.end() && *rtem == x)
			ltem = ltem;

		if (rshr == shr.end())
			rshr--;
		if (rtem == tem.end())
			rtem--;

		mn = min(mn, abs(x - *lshr) + abs(*lshr - *ltem));
		mn = min(mn, abs(x - *lshr) + abs(*lshr - *rtem));
		mn = min(mn, abs(x - *rshr) + abs(*rshr - *ltem));
		mn = min(mn, abs(x - *rshr) + abs(*rshr - *rtem));
		mn = min(mn, abs(x - *ltem) + abs(*lshr - *ltem));
		mn = min(mn, abs(x - *rtem) + abs(*lshr - *rtem));
		mn = min(mn, abs(x - *ltem) + abs(*rshr - *ltem));
		mn = min(mn, abs(x - *rtem) + abs(*rshr - *rtem));

		printf("%lld\n", mn);
	}

	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MAX_N = 10101;

int prime[MAX_N];
bool is_prime[MAX_N + 1];

int sieve(int n) {
    int p = 0;
    for (int i = 0; i <= n; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            prime[p++] = i;
            for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;
        }
    }
    return p;
}

int main() {
    sieve(MAX_N);
    sort(prime, prime + MAX_N);
    int n;
    while (cin >> n && n) {
        int p = 0, q = 0;
        int idx = upper_bound(prime, prime + MAX_N, n) - prime;
        idx--;
        for (int i = idx; i > 0; i--) {
            if (prime[i] - 2 == prime[i - 1]) {
                p = prime[i - 1];
                q = prime[i];
                break;
            }
        }
        cout << p << ' ' << q << endl;
    }
}


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

typedef pair<int, int> edge;

int vernum[101];
edge path[101][101];
int n;

edge found[101];

int t=0;
void dfs(int v){
    t++;
    found[v].first = t;
    int i=0;
    while(1){
        if(!path[v][i].first)
            break;
        if(!found[path[v][i].second].first){
            dfs(path[v][i].second);
        }
        i++;
    }
    t++;
    found[v].second = t;
}

int main() {
    int i, j;
    ios_base::sync_with_stdio(0);
    
    int e, v;
    cin >> n;
    
    for(i=1; i<=n; i++){
        cin >> vernum[i];
        cin >> e;
        for(j=0; j<e; j++){
            cin >> v;
            path[i][j] = make_pair(i, v);
        }
    }
    
    for(i=1; i<=n; i++){
        if(!found[i].first)
            dfs(i);
    }
    
    for(i=1; i<=n; i++){
        cout << vernum[i] << " " << found[i].first << " " << found[i].second << endl;
    }
    
    
    return 0;
}

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

const int MAX_N = 100000;
const int MAX_H = 10000;

int N;
int H[MAX_N];
int DP[MAX_N];

inline int max(int a, int b)
{
	return a > b ? a : b;
}

inline int min(int a, int b)
{
	return a < b ? a : b;
}

inline int abs(int a)
{
	return a < 0 ? -a : a;
}

int calc(int i)
{
	if (DP[i] == -1) {
		int a = abs(H[i] - H[i + 1]) + calc(i + 1);
		int b = abs(H[i] - H[i + 2]) + calc(i + 2);
		DP[i] = min(a,  b);
	}
	return DP[i];
}

int main()
{
	std::cin >> N;
	for (int i = 0; i < N; ++i) {
		std::cin >> H[i];
		DP[i] = -1;
	}

	DP[N - 1] = 0;
	DP[N - 2] = abs(H[N - 1] - H[N - 2]);

	std::cout << calc(0);
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef pair<ll, ll> PLL;

#define REP(i, j) for(int i=0;i<j;i++)
#define DREP(i, j) for(int i=j;i>=0;i--)
#define FOR(i, b, e) for(int i=b; i<=e; i++)
#define FORD(i, b, e) for(int i=b; i>=e; i--)
#define SIZE(x) ((int)x.size())
#define LAST(x) (x[SIZE(x)-1])
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sp ' '
#define ent '\n'

ll dp[3005][3005];
string s, t;

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

    cin >> s >> t;

    REP(i, SIZE(s)){
        REP(j, SIZE(t)){
            if(s[i]==t[j])dp[i+1][j+1]=dp[i][j]+1;
            else dp[i+1][j+1]=max(dp[i+1][j], dp[i][j+1]);
        }
    }
    int y = SIZE(s);
    int x = SIZE(t);
    string pom = "";

    while(y && x){
        if(dp[y-1][x]==dp[y][x])y--;
        else if(dp[y][x-1]==dp[y][x])x--;
        else if(dp[y-1][x-1]<dp[y][x]){
            pom = s[y-1] + pom;
            x--;
            y--;
        }
        //cout << y << sp << x << ent;
    }

    cout << pom;

    return 0;
}


Measured memory_bytes: 70656
using System;

namespace ABC168_a
{
    class Program
    {
        static void Main(string[] args)
        {
            //標準入力文字列を数値に変換
            long N = long.Parse(Console.ReadLine());
            //1の位を抽出
            long N_1st = N % 10;

            if(N_1st == 3){
                Console.WriteLine("bon");
            }else if(N_1st == 0 || N_1st == 1 || N_1st == 6 || N_1st == 8){
                Console.WriteLine("pon");
            }else if(N_1st == 2 || N_1st == 4 || N_1st == 5 || N_1st == 7 || N_1st == 9){
                Console.WriteLine("hon");
            }
        }
    }
}

Measured memory_bytes: 27316
#include <bits/stdc++.h>
using namespace std;
int OK(string S){
    if(S.size()%2!=0) return -1;
    string s1="",s2="";
    for(int i=0;i<S.size()/2;i++){
        s1 += S.at(i);
    }
    for(int i=S.size()/2;i<S.size();i++){
        s2 += S.at(i);
    }
    //cout << "s1 = " << s1 << " s2 = " << s2 << endl;
    if(s1==s2) return S.size();
    return -1;
}
int main(){
    string S;
    cin >> S;
    int N = S.size();
    for(int i=0;i<N;i++){
        S.pop_back();
        //cout << S << endl;
        if(OK(S)!=-1){
            cout << OK(S) << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3636
N=int(input())
A=list(map(int,input().split()))
#437235829 mod(10^9+7)
sumAcol=0
sumA=0
sumtr=0
for i in range(N):
  sumtr+=A[i]**2
  sumAcol+=A[i]
  sumtr=sumtr % (10**9+7)
  sumAcol=sumAcol % (10**9+7)

for i in range(N):
  sumA+=(sumAcol*A[i])%(10**9+7)
  
sumA=(sumA-sumtr)+10**9+7

print(sumA*(5*10**8+4) % (10**9+7))



Measured memory_bytes: 31536
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t / 2;
    } else {
        return modpow(m, n - 1) * m;
    }
}

int main() {
    long long n, a = 1, b = 0, ans = 1;
    cin >> n;
    vector<int>as();
    while (a <= n){
        b++;
        a *= 2;
    }
    for (int i = 0; i < b; i++){
        ans *= 2;
    }
    cout << ans - 1 << endl;
}

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

int N, A;
int xi[50];
int dp[51][51][2510];

//i:今見ているindex j:それまでに選んだ枚数 k:それまでの合計
int rec(int i, int j, int k) {
	if (dp[i][j][k] != -1) return dp[i][j][k];

	if (i == N) {
		if (j != 0 && k % j == 0 && k / j == A) {
			return dp[i][j][k] = 1;
		}
		return dp[i][j][k] = 0;
	}

	return dp[i][j][k] = rec(i + 1, j, k) + rec(i + 1, j + 1, k + xi[i]);
}

signed main()
{
	cin >> N >> A;
	rep(i,N) cin >> xi[i];
	rep(i,51) rep(j,51) rep(k,2510) dp[i][j][k] = -1;
	cout << rec(0, 0, 0) << endl;
}


Measured memory_bytes: 51328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
int main(){
    ll n,k,r,s,p;
    cin>>n>>k>>r>>s>>p;
    string t;
    cin>>t;
    ll dp[n+5][2]; 
    ll ans = 0;
    rep(j,k){
        bool flg = true;
        for(int i = j;i<t.size();i+=k){
            ll tmp;
            if(t[i]=='r') tmp = p;
            else if(t[i]=='s') tmp = r;
            else tmp = s;
            if(i>=k){
                    if(t[i] == t[i-k] && flg){
                        flg = false;
                    } else if(t[i] == t[i-k] && !flg){
                        flg = true;
                        ans += tmp;
                    } else {
                        ans += tmp;
                        flg = true;
                    }
            } else {
                ans += tmp;
            }
            // cout<<ans<<endl;
        } 
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
#define INF int(1e9)

template<class T,class U> ostream& operator<<(ostream& ost, const pair<T,U> &p) { ost << "(" << p.first << ", " << p.second << ")"; return ost; }
#define ostream_container { ost << "{"; for(const auto &t : v) { if (&t != &*v.begin()) ost << ", "; ost << t; } ost << "}"; return ost; }
template<class T> ostream& operator<<(ostream &ost, const vector<T> &v) ostream_container
template<class T> ostream& operator<<(ostream &ost, const set<T> &v) ostream_container
template<class T,class U> ostream& operator<<(ostream &ost, const map<T,U> &v) ostream_container

template<class H> void recursive_debug(string s, H h) {
    cerr << "\033[33m" << s << " = " << h << endl << "\033[m";
}
template<class H,class... T> void recursive_debug(string s, H h, T... t) {
    int comma = s.find(',');
    cerr << "\033[33m" << s.substr(0,comma) << " = " << h << ", ";
    recursive_debug(s.substr(comma+1), t...);
}
#define debug(...) recursive_debug(#__VA_ARGS__, __VA_ARGS__)


int main(void) {
    int x;
    cin >> x;
    cout << 10 - x/200 << endl;
    return 0;
}


Measured memory_bytes: 3568
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef vector<vector<ll>> matrix;

int n, x;
pipii l[100005]; // <hours, <lower, upper>>

ll gain(pipii a, ll h) {
  assert(h <= x);
  ll ret = 0;
  ret += min(a.first, (int)h) * (ll)a.second.first;
  ret += max(0LL, h - a.first) * (ll)a.second.second;
  return ret;
}

bool can(ll t) {
  ll need = 0;
  for(int i = 0; i < n; i++) {
    need += l[i].first * (ll)l[i].second.first;
  }
  int guaranteed = t/x;
  int rem = t % x;
  ll forceGain = 0;
  for(int i = 0; i <= guaranteed; i++) {
    forceGain += gain(l[i], x);
  }
  if(rem == 0) return forceGain - gain(l[guaranteed], x) >= need;
  for(int i = 0; i < n; i++) {
    if(i < guaranteed) {
      ll realGain = forceGain - gain(l[i], x) + gain(l[i], rem);
      if(realGain >= need) return true;
    }
    else {
      ll realGain = forceGain - gain(l[guaranteed], x) + gain(l[i], rem);
      if(realGain >= need) return true;
    }
  }
  return false;
}

bool cmp(pipii a, pipii b) {
  return gain(a, x) > gain(b, x);
}

void solve() {
  cin >> n >> x;
  for(int i = 0; i < n; i++) {
    cin >> l[i].first >> l[i].second.first >> l[i].second.second;
  }
  sort(l, l+n, cmp);
  ll lhs = 0;
  ll rhs = n * (ll)x;
  while(lhs != rhs) {
    ll mid = (lhs+rhs)/2;
    if(can(mid)) rhs = mid;
    else lhs = mid+1;
  }
  cout << lhs << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

void MAIN() {
  int n, m;
  cin >> n >> m;
  int ans = m * 1900 + (n - m) * 100;
  for (int i = 1; i <= m; i++) {
    ans *= 2;
  }
  cout << ans << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3564
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <functional>
# include <utility>
# include <queue>
# include <stack>
# define MOD 1000000007
# define INF 2000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
std::vector<bool> IsPrime;

void sieve(size_t max) {
	if (max + 1 > IsPrime.size()) {     // resizeで要素数が減らないように
		IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
	}
	IsPrime[0] = false; // 0は素数ではない
	IsPrime[1] = false; // 1は素数ではない

	for (size_t i = 2; i * i <= max; ++i) // 0からsqrt(max)まで調べる
		if (IsPrime[i]) // iが素数ならば
			for (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は
				IsPrime[i * j] = false;      // 素数ではない
}
int main() {
	long long ans = 0, counter = 0, maxi = -1, mini = INF, pass = 0;
	//new
	sieve(110000);
	cin >> pass;
	int i = pass;
	while (true) {
		if (IsPrime[i]==true) {
			cout << i << endl;
			return 0;;
		}
		else {
			i++;
		}
	}
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N, a, min = 1000000001, max = 0;
  
  scanf("%d", &N);
  
  for (int i = 0; i < N; i++){
    scanf("%d", &a);
    if(a < min){
      min = a;
    }
    if(a > max){
      max = a;
    }
  }
  
  printf("%d\n", max - min);
  
  return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var item1 = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();
            var N = item1[0];
            var K = item1[1];
            var count = Console.ReadLine().Split().Select(elem => int.Parse(elem)).Where(elem => elem >= K).Count();

            Console.WriteLine(count);
        }
    }
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> D(N);
    map<int, int> mp;
    for (int i = 0; i < N; ++i) {
        cin >> D[i];
        mp[D[i]]++;
    }
    int M;
    cin >> M;
    vector<int> T(N);
    for (int i = 0; i < M; ++i) {
        cin >> T[i];
        if (mp[T[i]] == 0) {
            cout << "NO" << endl;
            return 0;
        }
        mp[T[i]]--;
    }

    cout << "YES" << endl;
}


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

int main() {
	int n;
	string s;
	cin >> n >> s;
	cout << (count(s.begin(), s.end(), 'R') > count(s.begin(), s.end(), 'B') ? "Yes" : "No") << endl;
}

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

int main() {
  long N, K, x, ans = 0;
  cin >> N >> K;
  
  for (int i = 0; i < N; i++) {
    cin >> x;
    if (x <= K/2) ans += x * 2;
    else ans += (K - x) * 2;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <deque>
#include <stack>
using namespace std;

int main()
{
	//freopen("input.txt", "r", stdin); /*freopen("output.txt","w",stdout);*/
	/*ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);*/
	int n;
	cin>>n;
	long long  a=1,b=1;
	long double  c=1;
	long double res=0;
	for(int i=0;i<n;i++)
	{
		cin>>c;
		res+=1/c;
	}
	cout<<fixed<<setprecision(8)<<pow(res,-1);

	return 0;
}

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

int main()
{
cin>>a;
if (a=="SUN"){
	printf("7");
}
if (a=="SAT"){
	printf("1");
}
if (a=="MON"){
	printf("6");
}
if (a=="TUE"){
	printf("5");
}
if (a=="WED"){
	printf("4");
}
if (a=="THU"){
	printf("3");
}
if (a=="FRI"){
	printf("2");
}
}


Measured memory_bytes: 256
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef tuple<ll,ll,ll> tl3;
// https://atcoder.jp/contests/abc175/tasks/abc175_c
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll x,k,d;
    cin >> x >> k >> d;
    x = abs(x);
    ll temp = x / d;
    ll ans = 0;
    if(temp >= k){
        ans = x - k * d;    
    }
    else{
        ll m = x - temp * d;
        ll t = k - temp;
        if(t%2==0) ans = abs(m);
        else{
            ans = min(abs(m-d), abs(m+d));
        }
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


const int MAX = 1110000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll mod_pow(ll x, ll n, ll mod){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    comb_init();
    cout << comb(n-1, k-1) << endl;
}


Measured memory_bytes: 29236
from networkx import *
N,M = map(int,input().split())
A = [list(map(int,input().split())) for m in range(M)]
G = Graph(A)
ans = 0

for n in range(2,N+1):
  for p in all_simple_paths(G,1,n):
    if len(p)==N:
      ans+=1

print(ans)

Measured memory_bytes: 53196
while 1:
    n,r = map(int,input().split())
    if n == 0 and r == 0:
        break
      
    lists = list(range(1,n+1))
    lists.sort()
    lists.reverse()
    for i in range(r):
        p,c = map(int,input().split())
        tmp = lists[p-1:(p-1)+c]
        lists[p-1:(p-1)+c] = []
        lists = tmp + lists
    print(lists[0])

    



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

using namespace std;
int main() {
	int N,K;
	cin >> N >> K;
	vector<int>A(N);
	for (int n = 0; n < N; ++n) {
		cin >> A[n];
	}
	for (int n = 0; n < N - K; ++n) {
		if (A[n] < A[K+n]) {
			cout << "Yes"<<endl;
		}
		else{
			cout << "No" << endl;
		}
	}
}


Measured memory_bytes: 4048
import numpy as np
mod = 10**9+7
def MatPower(A, k):
    B = np.identity(len(A), dtype = object)
    while k:
        if k&1:
            B = np.dot(A, B)%mod
        A = np.dot(A, A)%mod
        k//=2
    return B
N, K = map(int, input().split())
a = np.array([list(map(int, input().split())) for _ in range(N)], dtype = object)
v = np.array([1]*N, dtype = object).T
An = MatPower(a, K)
v = np.dot(An, v)%mod
ans = 0
for i in range(N):
    ans+=v[i]
    ans%=mod
print(ans)





Measured memory_bytes: 14560
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<i64> a(n), b(n);
	for(int i = 0; i < n; i++) scanf("%lld", &a[i]);
	for(int i = 0; i < n; i++) scanf("%lld", &b[i]);

	auto f = [n](int ind) {
		return (ind + n) % n;
	};

	auto solve = [n, f](std::vector<i64>& a) {
		using P = std::pair<i64, int>;
		
		std::priority_queue<P> qu;
		for(int i = 0; i < n; i++) qu.push({a[i], i});

		i64 count = 0;
		while(!qu.empty()) {
			auto p = qu.top(); qu.pop();
			i64 & val = a[p.second];
			i64 tmp = a[f(p.second + 1)] + a[f(p.second - 1)];

			if(val < tmp or !tmp) continue;

			i64 T = val / tmp;
			count += T;
			val %= tmp;

			qu.push({val, p.second});
		}

		return count;
	};
	auto A = solve(a);
	auto B = solve(b);

	if(a != b) printf("-1\n");
	else printf("%lld\n", std::abs(A - B));
	return 0;
}


Measured memory_bytes: 12980
#include<iostream>
#include<stack>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
    stack<int> S1;
    stack<pair<int,int> > S2;
    char Sdata;
    int sum=0;//计算积水总面积
    for(int i=0;cin>>Sdata;i++)
    {
       // cout<<"cs:"<<i<<endl;
        if(Sdata=='\\')
        S1.push(i);
        else if(Sdata=='/'&&S1.size()>0)
        {
            int j=S1.top();
            int distance=i-j;
            sum+=distance;
          
            S1.pop();
            //下面对该积水处所在S2中代表的数据进行更新
            while(S2.size()>0&&S2.top().first>j)
            {
                distance+=S2.top().second;
                S2.pop();
            }
            S2.push(make_pair(j,distance));
        }

    }
    //数据处理完毕,next
    cout<<sum<<endl;
    cout<<S2.size();
    vector<int> areas;
    while(S2.size()>0)
    {
        areas.push_back(S2.top().second);
       // cout<<"cs:"<<S2.top().second;
        S2.pop();
    }
    //cout<<endl;
    reverse(areas.begin(),areas.end());
    for(int i=0;i<areas.size();i++)
    {
        cout<<" "<<areas[i];
    }

    cout<<endl;
  //  cout<<*(areas.end()-1)<<endl;
    return 0;
}



Measured memory_bytes: 3204
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    al = 'abcdefghijklmnopqrstuvwxyz'
    ret = ''
    while N>0:
        N -=1
        ret += al[N%26]
        N//=26
    print(ret[::-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 9168
S = input()
n = len(S)
mod = 10**9+7
dp = [[0 for _ in range(13)] for _ in range(n+1)]
dp[0][0] = 1
mul = 1
for i in range(n):
    x = S[-(i+1)]
    if x == "?":
        for k in range(10):
            for j in range(13):
                dp[i+1][(k*mul+j)%13] += dp[i][j]
                dp[i+1][(k*mul+j)%13] %= mod
    else:
        k = int(x)
        for j in range(13):
            dp[i+1][(k*mul+j)%13] += dp[i][j]
            dp[i+1][(k*mul+j)%13] %= mod
    mul = mul*10%13
print (dp[n][5])

Measured memory_bytes: 66268
import java.util.Scanner;

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

		int n = sc.nextInt();
		int i = 1;
		int x;
		while(true){
			x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
			}else{
				while(true){
					if(x % 10 == 3){
						System.out.print(" "+i);
						break;
					}
					x = x / 10;
					if (x == 0)break;
				}
			}
			if(++i > n)break;
		}
		System.out.println("");
	}
}


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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

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

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}

int dist[401][401];
char inp[21][21];

int main(){

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

    for(int i = 0; i < 401; i++) {
        for(int j = 0; j < 401; j++) {
            dist[i][j] = 100000000;
            if(i == j) dist[i][j] = 0;
        }
    }

    
    int h,w;
    cin>>h>>w;

    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cin>>inp[i][j];
        }
    }

    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(inp[i][j] == '#') continue;
            int n1 = i*w + j;

            if(i && inp[i-1][j] == '.') {
                int n2 = (i-1)*w + j;
                dist[n1][n2] = 1;
                dist[n2][n1] = 1;
            }

            if(j && inp[i][j-1] == '.') {
                int n2 = i*w + j - 1;
                dist[n1][n2] = 1;
                dist[n2][n1] = 1;
            }

        }
    }

    int n = h*w;

    for(int k = 0; k < n; k++) {
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                if(dist[i][k] + dist[k][j] < dist[i][j]) {
                    dist[i][j] = dist[i][k] + dist[k][j];
                }
            }
        }
    }

    int ans = -1;

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(dist[i][j] == 100000000) continue;
            ans = max(ans, dist[i][j]);
        }
    }

    cout<<ans<<endl;
    


}


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

using namespace std;


#define ff				first
#define ss				second
#define int				long long
#define pb				push_back
#define mp				make_pair
#define pii				pair<int,int>
#define vi				vector<int>
#define mii 			map<int,int>
#define	pqb				priority_queue<int>
#define pqs				priority_queue<int,vi,greater<int> >
#define setbits(x)		__builtin_popcountll(x)
#define zrobits(x)		__builtin_ctzll(x)
#define mod				1000000007
#define inf 			1e18
#define ps(x,y)			fixed<<setprecision(y)<<x
#define mk(arr,n,type)	type *arr = new type[n]
#define w(x)			int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl			'\n'

void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}


bool isPrime(int n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;
	if (n % 2 == 0 || n % 3 == 0)
		return false;
	for (int i = 5; i * i <= n; i += 6)
	{
		if (n % i == 0 || n % (i + 2) == 0)
			return false;

	}
	return true;
}

vector<int> Sieve(int n)
{
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));
	for (int i = 2; i * i <= n; i++)
	{
		if (prime[i])
		{
			for (int j = i * i; j <= n; j += i)
			{
				prime[j] = false;
			}
		}
	}
	vector<int> primes;

	for (int i = 2; i <= n; i++)
	{
		if (prime[i])
			primes.pb(i);
	}
	return primes;
}
map<int, int> primeFactors(int  n)
{
	mii factors;
	while (n % 2 == 0)
	{
		n /= 2;
		factors[2]++;

	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		// int count = 0;
		while (n % i == 0)
		{
			factors[i]++;
			n /= i;
		}
	}
	if (n > 2)
		factors[n]++;
	return factors;
}


// Graph------------------------------------------------------------------------

int32_t main()
{
	FIO;
	// c_p_c();
// --------------------------------------------------
// Never GIVE UP !!!!
	int h, a;
	cin >> h >> a;
	cout << ceil((float)h / a) << endl;
}

Measured memory_bytes: 3812
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

struct S009 {
  template<typename a>
  a operator()(a x, long n) {
    if( n == 0 ) return a(1);
    a t = (*this)(x, n / 2);
    return t * t * (n % 2 ? x : a(1));
  }
};

template<long p = 1000000007>
struct S010 {
  long x;
  S010() : x(0) {}
  S010(long x_) : x(x_ % p) {}
  S010<p> operator + (S010<p> y) const { return (x + y.x) % p; }
  S010<p> operator - (S010<p> y) const { return (x + p - y.x) % p; }
  S010<p> operator * (S010<p> y) const { return (x * y.x) % p; }
  S010<p> operator / (S010<p> y) const { S009 pow_; return x * pow_(y, p-2); }
};
template<long p>
S002& operator >= (S002& r, S010<p>& x) {
  long y;
  r >= y;
  x = S010<p>(y);
  return r;
}
template<long p>
S010<p> operator * (int x, S010<p> y) {
  return x * y.x;
}

struct Solver {
  long n, m;
  std::vector<long> xs;
  std::vector<long> ys;
  typedef S010<> Mod;
  Solver() {
    S002 reader;
    reader >= n >= m >n>= xs >m>= ys;
  }
  void solve() {
    Mod s = 0;
    for(long i = 1; i < n; ++i) {
      s = s + Mod(xs[i] - xs[i-1]) * i * (n - i);
    }
    Mod t = 0;
    for(long i = 1; i < m; ++i) {
      t = t + Mod(ys[i] - ys[i-1]) * i * (m - i);
    }
    Mod res = s * t;
    printf("%ld\n", res.x);
  }
  ~Solver() { fprintf(stderr, "--end--\n"); }
};
 

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

Measured memory_bytes: 1920
s=list(input())
t=list(input())
S={}
T={}
for i in s:
    if i in S.keys():
        S[i]+=1
    else:
        S[i]=1
for i in t:
    if i in T.keys():
        T[i]+=1
    else:
        T[i]=1
Svalues=sorted(S.values())
Tvalues=sorted(T.values())
if Tvalues==Svalues:
    print('Yes')
else:
    print('No')

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

using namespace std;

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

    string S;
    int K;
    cin >> S >> K;
    const int n = S.size();
    if (set<char>(begin(S), end(S)).size() == 1U) {
        cout << (1LL * n * K) / 2 << "\n";
        return 0;
    }
    int cnt1 = 0;
    bool change_last = false;
    for (int i = 1; i < n; ++i) {
        if (S[i] == S[i - 1]) {
            ++cnt1;
            if (i == n - 1) {
                change_last = true;
            }
            ++i;
        }
    }
    int add = 0;
    if (!change_last && S.back() == S[0]) {
        int cnt2 = 1;
        for (int i = 2; i < n; ++i) {
            if (S[i] == S[i - 1]) {
                ++cnt2;
                ++i;
            }
        }
        if (cnt2 > cnt1) {
            add = K - 1;
        }
    }
    cout << 1LL * K * cnt1 + add << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int BIG=2e5+100;
long long freq[BIG];
int main()
{
	long long  n, q,a;
	long long sum=0;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a;
		sum += a;
		freq[a]++;
	}
	long long x, y;
	cin>>q;
	for (int i = 0; i < q; i++)
	{
		cin >> x >> y;
		sum+=(y-x)*freq[x];
		freq[y]+=freq[x];
		freq[x]=0;
		cout <<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 4428
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

ll dsum(ll n) {
    ll r = 0;
    while(n) {
        r += n % 10;
        n /= 10;
    }
    return r;
}

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

    ll k;
    cin >> k;
    ll x = 1, p = 1;
    while(k--) {
        cout << x << endl;
        ll x1 = x + p;
        ll x2 = x + p * 10;
        if(x1 * dsum(x2) <= x2 * dsum(x1))
            x = x1;
        else {
            x = x2;
            p *= 10;
        }
    }

    return 0;
}

Measured memory_bytes: 256
import numpy as np
import itertools

N,M,X = map(int,input().split())

#totallist=[[0]*M]*N
totallist=np.zeros((N,M+1))
for i in range(N):
    totallist[i]=list(map(int,input().split()))


lis=list(range(N))
result = []
print_value =float('inf')
total_test=np.zeros(M+1)
for n in range(1,len(lis)+1):
    for conb in itertools.combinations(lis, n):
        for i in conb:
            total_test=total_test+totallist[i]
            if(np.count_nonzero(total_test[1:]>=X)==M):
                if(print_value>=total_test[0]):
                    print_value=total_test[0]
        total_test=np.zeros(M+1)
if(print_value==float('inf')):
    print(-1)
else:
    print(int(print_value))


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

int main(){
  int n;
  cin >> n;
  vector<int> d(4);
  int a = 3;
  while(a>=0){
	d.push_back(n%10);
    n/=10;
    a--;
  }
  reverse(d.begin(),d.end());
  /*rep(i,4){
    cout << d[i] << endl;
  }*/
  for(int bit=0;bit<(1<<3);bit++){
    string s="";
    int r;
    int sum = d[0];
    for(r=0;r<3;r++){
      if(bit & (1<<r)){
        sum += d[r+1];
        s += "+";
      }else{
        sum -= d[r+1];
        s += "-";
      }
    }
    //cout << s << endl;
    //cout << sum << endl;
    if(sum == 7){
      rep(i,3){
        cout<<d[i]<<s[i];
      }
      cout<<d[3]<<"=7"<<endl;
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 256
N, D = map(int, input().split())
XY = [[] for _ in range(N)]
X = [0] * N
Y = [0] * N
for i in range(N):
    XY[i] = list(map(int, input().split()))
    X[i] = XY[i][0]
    Y[i] = XY[i][1]

ans = 0
for i in range(N):
    if (X[i]**2 + Y[i]**2) ** 0.5 <= D:
        ans += 1
print(ans)


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

ll n,a[100100],sum[200100];

int main(){
  scanf("%lld",&n);
  for(int i=0;i<n;i++)scanf("%lld",&a[i]);
  for(int i=0;i<2*n;i++)sum[i+1] = sum[i] + a[i%n];

  int l = 0, r = 1;
  ll ans = 0, third = sum[n]/3;
  while(l<n){
    while(sum[r]-sum[l] <= third)r++;
    r--;
    ll minv = sum[r]-sum[l];
    ll half = (sum[n] - minv)/2;
    int pos = lower_bound(sum+r, sum+2*n, half + sum[r]) - sum;

    //cout << minv << " " << sum[pos]-sum[r] << " " << sum[l+n]-sum[pos] << endl;
    ll tmp = min(sum[pos]-sum[r], sum[l+n]-sum[pos]);
    if(pos>0)tmp = max(tmp, min(sum[pos-1]-sum[r], sum[l+n]-sum[pos-1]));
    minv = min(minv,tmp);

    ans = max(ans,minv);
    l++;
  }

  printf("%lld\n",ans);
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vin=vector<int>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;

int main(){
  int x,y;
  cin>>x>>y;
  ////////
  ll ans=0;
  ans+=abs(abs(x)-abs(y));
  if(abs(x)<abs(y)){
    if(x<0){
      ans++; 
      if(y<0) {
        ans++;
      }
      
      
    }//x0
   else if(y<0) ans++; 
  }
  
  
  
  else{
    if(x>0){
     ans++;
      if(y>0){
        ans++; 
      }
      
    }
    else if(y>0) ans++;
  }
  
  
  cout<<ans<<endl;
}







Measured memory_bytes: 256
while True:
    q=int(input())
    if q==-1:
        break
    x=q/2
    a=0.00001*q
    while abs(x**3-q)>=a:
        s=x*x
        t=s*x-q
        x-=t/(3*s)
    print(f"{x:.6f}")


Measured memory_bytes: 5680
object Main extends App {
  var count: Long = 0
  val n = io.StdIn.readLine()
  val arr: collection.mutable.ArrayOps[Int] = io.StdIn.readLine().split(' ') map (_.toInt)

  def merge(left: Int, middle: Int, right: Int): Unit = {
    val l = arr.slice(left, middle)
    val r = arr.slice(middle, right)
    val lLen = l.length
    val rLen = r.length

    var i = left
    var li = 0
    var ri = 0

    while(li < lLen && ri < rLen) {
      if (l(li) <= r(ri)) {
        arr(i) = l(li)
        i += 1
        li += 1
      } else {
        arr(i) = r(ri)
        count += (lLen - li)
        i += 1
        ri += 1
      }
    }

    if (li < lLen) while (li < lLen) {arr(i) = l(li); i += 1; li += 1}
    else while (ri < rLen) {arr(i) = r(ri); i += 1; ri += 1}
  }

  def msort(left: Int, right: Int): Unit = {
    val middle = (left+right+1)/2
    if (middle < right) {
      msort(left, middle)
      msort(middle, right)
      merge(left, middle, right)
    } else {
      ()
    }
  }

  msort(0, arr.length)
  println(count)
}

Measured memory_bytes: 220560
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

def main():
    P, Q, R, = list(map(int, input().split()))

    aa = []
    aa.append(P + Q)
    aa.append(P + R)
    aa.append(Q + R)
    # print(aa)
    print(min(aa))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int N, M;
  cin >> N >> M;
  vec A, B;
  set<int> sta, stb;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    A.pb(tmp);
    sta.insert(tmp);
  }
  for (int j = 0; j < M; j++) {
    int tmp;
    cin >> tmp;
    B.pb(tmp);
    stb.insert(tmp);
  }

  sort(ALL(A));
  sort(ALL(B));

  UNIQUE(A);
  UNIQUE(B);

  //元のサイズより小さいなら、重複があったということ
  if (A.size() < N || B.size() < M) {
    cout << 0 << endl;
    return 0;
  }

  int ans = 1;
  for (int i = N * M; i >= 1; i--) {
    bool fa = EXIST(sta, i);
    bool fb = EXIST(stb, i);

    int na = N - (int)(upper_bound(ALL(A), i) - A.begin());
    int nb = M - (int)(upper_bound(ALL(B), i) - B.begin());

    //縦横ともに存在
    if (fa && fb) {
      continue;

      //縦横ともに存在しない
    } else if (!fa && !fb) {
      int tmp = na * nb - (N * M - i);

      if (tmp <= 0) {
        cout << 0 << endl;
        return 0;
      }

      ans *= tmp;
      ans %= MOD;

      //片方に存在
    } else if (fa && !fb) {
      ans *= nb;
      ans %= MOD;
    } else if (!fa && fb) {
      ans *= na;
      ans %= MOD;
    }
  }

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


Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
	public static void main(String[] args) {
		Pattern pt = Pattern.compile("@(\\d)(.)");
		Matcher mt = null;
		String str;
		for (Scanner in = new Scanner(System.in); in.hasNextLine();) {
			str = in.nextLine();
			if (mt == null) {
				mt = pt.matcher(str);
			} else {
				mt.reset(str);
			}
			String s = str;
			while (mt.find()) {
				int n = Integer.parseInt(mt.group(1));
				char[] to = new char[n];
				Arrays.fill(to, mt.group(2).charAt(0));
				s = s.replace(mt.group(0), new String(to));
			}
			System.out.println(s);
		}
	}
}

Measured memory_bytes: 12000
#include<stdio.h>

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

int main()
{
	long long a, b,g,l;
	while (scanf("%lld%lld", &a, &b) != EOF)
	{
		g = gcd(a, b);
		l = b / g * a;
		printf("%lld %lld\n", g, l);
	}
	return 0;
}


Measured memory_bytes: 2684
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll mod = 1000000007;
ll powmod(ll x, ll y) {
    ll res = 1;
    for (ll i = 0; i < y; i++) {
        res = res * x % mod;
    }
    return res;
}
int main() {
	int n;
	cin >> n;
    ll ans = powmod(10, n) - powmod(9, n) - powmod(9, n) + powmod(8, n);
    ans %= mod;
    ans = (ans + mod) % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

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


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

void connection(vector<vector<bool>> &checked, int i, int j, int h, int w) {
    if (!checked.at(i).at(j)) return;
    checked.at(i).at(j) = false;
    for (int x = max(0, i - 1); x <= min(h - 1, i + 1); x++) {
        for (int y = max(0, j - 1); y <= min(w - 1, j + 1); y++) {
            if (x != i || y != j) connection(checked, x, y, h, w);
        }
    }
    return;
}

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while(true) {
        int w, h;
        cin >> w >> h;
        if (h == 0 && w == 0) break;
        
        vector<vector<bool>> checked(h, vector<bool>(w, false));
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                bool a;
                cin >> a;
                checked.at(i).at(j) = a;
            }
        }
        
        int ans = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (checked.at(i).at(j)) {
                    connection(checked, i, j, h, w);
                    ans++;
                }
            }
        }
        
        cout << ans << endl;
    }
    
    return 0;
}



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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String[] nab = str.split(" ");
		int n = Integer.parseInt(nab[0]);
		long a = Long.parseLong(nab[1]);
		long b = Long.parseLong(nab[2]);

		str = input.readLine();
		String[] strx = str.split(" ");
		long[] x = new long[n];
		for(int i=0; i<n; i++){
			x[i] = Long.parseLong(strx[i]);
		}

		long answer = 0;
		for(int i=0; i<n-1; i++){
			if((x[i+1]-x[i])*a > b){
				answer = answer + b;
			}else{
				answer = answer + (x[i+1]-x[i])*a;
			}
		}
		System.out.println(answer);

	}

}



Measured memory_bytes: 54364
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		sc.close();

		long[] dp = new long[20000];
		Arrays.fill(dp, 1000000000);
		dp[0] = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j <= a[i]; j++) {
				dp[j] = Math.min(dp[j], b[i]);
			}
			for (int j = 0; j <= h; j++) {
				dp[j + a[i]] = Math.min(dp[j + a[i]], dp[j] + b[i]);
			}
		}
		System.out.println(dp[h]);
	}
}


Measured memory_bytes: 27144
N=int(input())

N_digit = len(str(N))
if N_digit==1:
    print(N)
    exit()

N_head = N//(10**(N_digit-1))
N_tail = N%10

count = 0
for A in range(1, N+1):
    A_digit = len(str(A))
    A_head  = A//(10**(A_digit-1))
    A_tail  = A%10

    if A_tail==0:
        continue

    if A_head==A_tail:
        count += 1

    for digit in range(2, N_digit+1):
        if digit==N_digit:
            if A_tail < N_head:
                count += 10**(digit-2)
            elif A_tail == N_head:
                if A_head <= N_tail:
                    count += N//10-N_head*(10**(N_digit-2))+1
                else:
                    count += N//10-N_head*(10**(N_digit-2))
            else:
                pass
        else:
            count += 10**(digit-2)
print(count)


Measured memory_bytes: 3064