akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;
using static System.Math;

class MainClass
{

    public static void Main(string[] args)
    {
        var _ = LnInts();
        var N = _[0]; var W = _[1];
        var Vs = new long[N][];
        for (var i = 0; i < N; i++)
        {
            Vs[i] = LnLngs();
        }
        var dp = new long[N + 1][];
        for (int i = 0; i < dp.Length; i++)
        {
            dp[i] = new long[100100];
            for (int m = 0; m < dp[i].Length; m++) dp[i][m] = 1000000001L;
        }
        dp[0][0] = 0;
        for (int i = 0; i < N; i++)
        {
            for (int v = 0; v < 100100; v++)
            {
                if (v >= Vs[i][1])
                {
                    dp[i + 1][v] = Min(dp[i + 1][v], dp[i][v - Vs[i][1]] + Vs[i][0]);
                }
                dp[i + 1][v] = Min(dp[i + 1][v], dp[i][v]);
            }
        }
        var n = dp[N];
        var res = 0;
        for (int w = 0; w < n.Length; w++)
        {
            if (n[w] <= W)
            {
                res = res < w ? w : res;
            }
        }
        Console.WriteLine(res);
    }

  
    public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; }
    public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); }
    public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; }
    public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); }
    public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; }
    public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; }
}



Measured memory_bytes: 90944
d = int(input())
c = list(map(int,input().strip().split()))
s = [list(map(int,input().strip().split())) for i in range(d)]
t = [int(input()) for i in range(d)]

last = [0]*26
sat = 0
for day,kind in enumerate(t):
  sat += s[day][kind-1]
  last[kind-1] = day+1
  for l_kind,l_day in enumerate(last):
    sat -= c[l_kind] * (day+1-l_day)
  print(sat)

Measured memory_bytes: 68424
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(),(x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(),v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for(auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for(ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for(int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for(int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for(int i = 0; i < n; ++i){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL));
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const int MAXN = 500001;
const ld EPS = 1e-9;
int hp = 179;

ll powll(ll in, ll count) {
	ll reg = 1;
	for (ll i = 0; i < count; ++i)
		reg *= in;
	return reg;
}

signed main()
{
	fastio();
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ab = abs(a - b);
	int bc = abs(b - c);
	int ca = abs(c - a);

	if (ca <= d || max({ ab, bc }) <= d)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    bool flag = true;
    if(n < 10){
        cout << n << endl;
        return 0;
    }
    rep(i, n - 1)
    {
        ans += 9;
        if(n%10 != 9){
            flag = false;
        }
        n /= 10;
    }
    if(flag){
        ans += n;
    }else{
        ans += n-1;
    }
    cout << ans << endl;
}

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

public class Main {
	static FastReader f = new FastReader();
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		int h = f.nextInt(), w = f.nextInt(), m = f.nextInt();
		int[] row = new int[h], col = new int[w];
		ArrayList<int[]> list = new ArrayList<>();
		while(m-- > 0) {
			int i = f.nextInt() - 1, j = f.nextInt() - 1;
			row[i]++;
			col[j]++;
			list.add(new int[] {i, j});
		}

		int maxI = 0, maxJ = 0;
		HashSet<Integer> setCol = new HashSet<>(), setRow = new HashSet<>();
		for(int i=0;i<h;i++) {
			maxI = Math.max(maxI, row[i]);
		}
		for(int j=0;j<w;j++) {
			maxJ = Math.max(maxJ, col[j]);
		}

		for(int i=0;i<h;i++) {
			if(row[i] == maxI) {
				setRow.add(i);
			}
		}
		for(int j=0;j<w;j++) {
			if(col[j] == maxJ) {
				setCol.add(j);
			}
		}

		int cnt = 0;
		for(int[] i : list) {
			boolean first = setRow.contains(i[0]), second = setCol.contains(i[1]);
			if(first && second) {
				cnt++;
			}
		}

		out.println(maxI+maxJ+(cnt != ((long)setCol.size())*setRow.size()?0:-1));
		out.close();
	}


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

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

		String nextLine() {
			String str = "";

			try {
				str = br.readLine();
			} catch(IOException e) {
				e.printStackTrace();
			}
			return str;
		}

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

		double nextDouble() {
			return Double.parseDouble(next());
		}

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

Measured memory_bytes: 98712
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  N = 2e5 + 5;

char s[N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;cin>>s;
	for(auto c:s){
		if(c=='?') cout<<'D';
		else cout<<c;
	}
	cout<<'\n';
	return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FASTIO cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define ll long long int
#define F first
#define S second
#define pll pair<ll,ll>
#define vl vector<ll>
#define pb push_back

struct compare {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		if ((a.S - a.F) != (b.S - b.F)) return ((a.S - a.F) > (b.S - b.F));
		else return (a.F < b.F);
	}
};

int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	FASTIO;
	ll n, i; cin >> n;
	vl v(n), dp(n, LLONG_MAX);
	for (i = 0; i < n; i++) cin >> v[i];
	dp[0] = 0;
	for (i = 0; i < n; i++) {
		if ((i + 1) < n) dp[i + 1] = min(dp[i + 1], (dp[i] + abs(v[i + 1] - v[i])));
		if ((i + 2) < n) dp[i + 2] = min(dp[i + 2], (dp[i] + abs(v[i + 2] - v[i])));
	}
	cout << dp[n - 1] << endl;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
using ll = int64_t;
constexpr ll mod = ll(1e9 + 7);
#define endl '\n'
 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  int TT = 1;
  // cin >> TT;
  while (TT--) {
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N);
    for (auto& aa : A) cin >> aa;
    deque<ll> dq;
    for (int i = 0; i < K; ++i) {
      dq.push_back(A[i]);
    }
    for (int i = K; i < N; ++i) {
      if (A[i] > dq.front()) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
      dq.pop_front();
      dq.push_back(A[i]);
    }
  }
}


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


using namespace std;


int main(){
  int n; cin >> n;
  
  for(int i = 1; i <= 9; ++i)
    for(int j = 1; j <= 9; ++j)
      if(i*j == n){
        cout<<"Yes\n";
        return 0;
      }
  
  cout<<"No\n";
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;

bool check(int a, int b) {
	return a > b;
}

int solve(int cnt, int x, int y, vint c, vint s, vint f) {
	if (cnt > cnt / f[x]*f[x]) {
		cnt = cnt / f[x] * f[x] + f[x];
	}
	else {
		cnt = cnt / f[x]*f[x];
	}
	if (cnt < s[x]) {
		cnt = s[x];
	}
	cnt += c[x];
	if (x + 1 == y) {
		return cnt;
	}
	else {
		return solve(cnt, x + 1, y, c, s, f);
	}
}

int main() {
	int n;
	cin >> n;
	int cnt = 0;
	int x;
	rep(i, n) {
		cin >> x;
		cnt += x % 2;
	}
	YES(cnt % 2 == 0);
	return 0;
}


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

int main(void){
  string S;
  string T;
  
  cin>>S;
  cin>>T;
  
  if((S.size()+1)!=T.size())
    cout<<"No"<<endl;

  int cnt=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)==T.at(i))
      cnt++;
  }

  if(cnt==S.size())
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 3560
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

n = inp[0]
a = inp
mem = na(10**6+100,false)
mem2 = na(10**6+100,false)
h = {}
max = 10**6+10
n.times do |i|
  h[a[i]] = i
end
a.sort!
ans = 0

n.times do |i|
  next if(mem[a[i]])
  ans += 1 if(a.size == 1 or (a[i]!= a[i-1] and a[i] != a[i+1]))
  ind = a[i]
  pl = a[i]
  while ind <= max
    mem[ind] = true
    ind += pl
  end

end
puts ans


Measured memory_bytes: 53784
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;
constexpr double PI = 3.141592653589793;

using namespace std;

int main() {
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    //分進:60分で1週: 1分で6度
    // h時m分の分進の角度
    double mAngle = 6.0 * m;

    // h時m分の時針の角度
    //時針：12時間で1週：1時間で30度：1分で0.5度
    double hAngle = 30.0 * h + 0.5 * m;
    double angle = hAngle - mAngle > 0.0 ? hAngle - mAngle : mAngle - hAngle;
    double rad = angle * (PI / 180.0);
    double ans2 = a * a + b * b - 2.0 * a * b * cos(rad);
    double ans = sqrt(ans2);
    cout << setprecision(20) << ans << "\n";
    return 0;
}

Measured memory_bytes: 4156
#pragma GCC optimize("Ofast", "unroll-loops")

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

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
// default_random_engine generator;
// mt19937 rnd(1);

const int MAXN = 500;

int dp[MAXN][26];

int solve(string s) {
    int n = sz(s);

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 26; ++j) {
            dp[i + 1][j] = n;
            for (int k = 0; k < 26; ++k) {
                if (j == k) {
                    continue;
                }
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][k] + (s[i] != j + 'a'));
            }
        }
    }
    int res = n;
    for (int i = 0; i < 26; ++i) {
        res = min(res, dp[n][i]);
    }
    return res;
}

int main() {
#ifdef LOCAL
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);  
#endif 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0); 
    cout.precision(12);
    cout << fixed; 

    string s;
    cin >> s;
    int m;
    cin >> m;

    if (m == 1)  {
        cout << solve(s) << endl;
    } else if (m == 2) {
        cout << solve(s + s) << endl;
    } else if (m == 3) {
        cout << solve(s + s + s) << endl;
    } else if (m & 1) { 
        ll a = solve(s);
        ll b = solve(s + s + s);
        cout << a + (b - a) * (m - 1) / 2 << endl;
    } else {
        ll a = solve(s + s);
        ll b = solve(s + s + s + s);
        cout << a + (b - a) * (m - 2) / 2 << endl;
    }


#ifdef LOCAL
    cerr << "Time: " << double(clock()) / CLOCKS_PER_SEC << endl;
#endif
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n, m, c, d, a[10000], b[1440], cnt;
int main() {
	cin >> n; for (int i = 0; i < n; i++) { cin >> c >> d; b[c * 60 + d] = 1; }
	cin >> m; for (int i = 0; i < m; i++) { cin >> c >> d; b[c * 60 + d] = 1; }
	for (int i = 0; i < 1440; i++) {
		if (b[i] == 1) {
			if (cnt) { cout << ' '; }
			cnt++;
			cout << i / 60 << ':';
			if (i % 60 < 10) { cout << '0'; }
			cout << i % 60;
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
int main(){
int W,H,x,y,r;
cin>>W>>H>>x>>y>>r;
if(x+r>W||x-r<0||y+r>H||y-r<0){
    cout<<"No"<<endl;
}

else{
    cout<<"Yes"<<endl;
}
}


Measured memory_bytes: 3116
loop do
    m, f, r = gets.split.map(&:to_i)
    break if m == -1 && f == -1 && r == -1
    
    if m == -1 || f == -1
        puts "F"
        next
    end
    
    sum = m + f
    grade = case sum
    when 80..100
        "A"
    when 65..80
        "B"
    when 50..65
        "C"
    when 30..50
        r >= 50 ? "C" : "D"
    else
        "F"
    end
    puts grade
end

Measured memory_bytes: 8560
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }

const int MAXN = 100000;

int n;
ll d[MAXN];

pair<ll, int> o[MAXN];

int sz[MAXN], par[MAXN]; ll chdst[MAXN];


bool solve() {
	REP(i, n) o[i] = MP(d[i], i); sort(o, o + n);
	//printf("o:"); REP(i, n) printf(" (%lld,%d)", o[i].first, o[i].second); puts("");

	REP(i, n) sz[i] = 1, par[i] = -2, chdst[i] = 0;
	for (int i = n - 1; i >= 1; --i) {
		int at = o[i].second;
		// d[at]-d[par[at]]=n-2*sz[at] -> d[par[at]]=d[at]-n+2*sz[at]
		ll want = d[at] - n + 2 * sz[at];
		int idx = lower_bound(o, o + n, MP(want, -1)) - o; if (idx >= i || o[idx].first != want) return false;
		par[at] = o[idx].second; sz[par[at]] += sz[at]; chdst[par[at]] += chdst[at] + sz[at];
	}

	int root = o[0].second; assert(sz[root] == n); par[root] = -1; return chdst[root] == d[root];
}


void run() {
	scanf("%d", &n); REP(i, n) scanf("%lld", &d[i]);
	if (!solve()) { printf("-1\n"); return; }
	REP(i, n) if (par[i] != -1) printf("%d %d\n", i + 1, par[i] + 1);
}

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


Measured memory_bytes: 5248
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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 int MOD = 1e9+7;
vector<vector<int>> to;
int mx;
void dfs(int now, int prev, int& res) {
  ll num;
  if(prev == -1)
    num = mx-1;
  else
    num = mx-2;
  rep(i, to[now].size()) {
    if(to[now][i] == prev)
      continue;
    res = res*num%MOD;
    dfs(to[now][i], now, res);
    num--;
  }
}

int main(){
  int N, K;
  cin >> N >> K;
  to.resize(N);
  rep(i, N-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  mx = K;
  int res = K;
  dfs(0, -1, res);
  cout << res << endl;
}

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

const int N=505;
int mat[N][2];
int mem[N][N];

int mcm(int l, int r){
  if(l==r)  return mem[l][r]=0;
  if(mem[l][r]!=-1) return mem[l][r];
  int ret = INT_MAX;
  for (int i = l; i < r; ++i){
    int now = mcm(l, i);
    now += mcm(i+1, r);
    now += mat[l][0]*mat[i][1]*mat[r][1];
    ret = min(ret, now);
  }
  return mem[l][r]=ret;
}

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  
  int n;  cin >> n;
  for (int i = 0; i < n; ++i){
    cin >> mat[i][0] >> mat[i][1];
  }
  memset(mem, -1, sizeof(mem));
  cout << mcm(0, n-1) << "\n";
  return 0;
}


Measured memory_bytes: 4228
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int h1,m1,h2,m2,K;
  cin >> h1 >> m1 >> h2 >> m2 >> K;

  int M1=h1*60+m1;
  int M2=h2*60+m2;
  int M=M2-M1;
  cout << M-K << endl;

  return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>

int main(void) {
  int h, w, i, j;
  while (1) {
    scanf(" %d %d", &h, &w);
    if (h == 0 && w == 0)
      return 0;
    for (i = 0; i < h; i++) {
      for (j = 0; j < w; j++) {
	if ((i + j) % 2 == 0)
	  printf("#");
	else
	  printf(".");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}



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

using namespace std;

int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (count(s.begin(),s.end(), s[i]) % 2 == 1) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

const int MAX_N = 10000;

int main(){
    int m, n, i, j;
    cin >> m;
    while(m--){
        cin >> n;
        string t;
        cin >> t;
        int shelf[2][MAX_N+1];
        for(i = 0; i < 2*n+2; i++){
            shelf[i/(n+1)][i%(n+1)] = 0;
        }
        int minc[2]={MAX_N+3,MAX_N+3}, maxc[2]={-1,-1}, count=0;
        for(i = 0; i < 4*n; i++){
            int r = i/2/n, c = (i%(2*n)+1)/2;
            if(t[i]=='Y'){
                shelf[r][c] = 1;
                if(minc[r] > MAX_N) minc[r] = c;
                maxc[r] = c;
            }
        }
        for(i = 0; i < 2; i++){
            for(j = 0; j < n+1; j++){
                count += shelf[i][j];
            }
        }
        count += n;
        if(minc[0] > minc[1]) count++;
        if(maxc[0] < maxc[1]) count++;
        cout << count << endl;
    }
    return 0;
}

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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int l, m, n;
	if(c - a < 0) l = a - c;
	else l = c - a;
	if(c - b < 0) m = b - c;
	else m = c - b;
	if(b - a < 0) n = a - b;
	else n = b - a;
	if(m <= d && n <= d) {
		cout << "Yes";
	} else if(l <= d) {
		cout << "Yes";
	}else {
		cout << "No";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
    // 頂点数と辺数
    int N ; cin >>N;

    // グラフ入力受取
    Graph G(N);
    for (int i = 0; i < N ;i++) {
        int a, b; cin >> a >> b;
        for(int j=0;j<b;j++) {
          int c; cin >>c;
          G[a-1].push_back(c-1);
        }
    }
     // BFS のためのデータ構造
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }

    // 結果出力 (各頂点の頂点 0 からの距離を見る)
    for (int v = 0; v < N; ++v) cout << v+1 << " " << dist[v] << endl;
}


Measured memory_bytes: 3160
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <limits>
#include <numeric>
#include <stack>
#include <queue>
#include <functional>

typedef long long ll;
typedef long double ld;

#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);

#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()

#define rep(i,a,b,c)            for(int i=(a);i<(b);i+=(c))
#define repb(i,a,b,c)           for(int i=(a);i>=(b);i-=(c))
#define ln '\n';
#define mod 1e9 + 7
#pragma warning(disable:4996)

using namespace std;

ll gcd(ll a, ll b) {
	while (a > 0 && b > 0) {
		if (a > b)
			a %= b;
		else
			b %= a;
	}

	return a + b;
}

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

int bitcount(int n) {
	int c = 0;
	while (n > 0) {
		if (n & 1)
			c++;
		n >>= 1;
	}
	return c;
}

struct cmp {
	constexpr bool operator()(pair<int, int>& a, pair<int, int>& b) const {
		return a.second > b.second;
	}
};


void solve() {
}

int main()
{
	fast
		string s;
	cin >> s;
	int res = 0;
	int c = 0;
	for (int i = 0; i <= s.length(); i++)
	{
		if (i < s.length() && s[i] == 'R') {
			c++;
		}
		else {
			res = max(res, c);
			c = 0;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;




int main() {
	int n;
	while (cin >> n&&n > 0) {
		vi v(n);
		rep(i, n)cin >> v[i];
		int ans = 0;
		while (1) {
			map<int, int> m;
			rep(i, n)m[v[i]] += 1;
			vi v2;
			rep(i, n) {
				v2.push_back(m[v[i]]);
			}
			if (v == v2) {
				break;
			}
			v = v2;
			ans++;
		}
		cout << ans << endl;
		rep(i, n) {
			if (i != 0)cout << " ";
			cout << v[i];
		}
		cout << endl;
	}
}

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

int main(){
    int N;
    string a,b;
    vector<char>c;
    cin >> N;
    cin >> a >> b;
    for (int i = 0; i < a.size(); i++){
        c.push_back(a.at(i));
        c.push_back(b.at(i));
    }
    for (int i = 0; i < c.size(); i++){
        cout << c.at(i);
    }
    cout << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int a, b;
	scanf("%d %d",&a,&b);
	if (a == b) {
		printf("a == b\n");
	} else if (a > b) {
		printf("a > b\n");
	} else if (a < b) {
		printf("a < b\n");
	}
	return 0;
}


Measured memory_bytes: 2104
N, K, Q = gets.split.map(&:to_i)
As = Q.times.map { gets.to_i }

counter = As.group_by { |e| e }.map { |n, group| [n, group.size] }.to_h

N.times do |n|
  i = n + 1

  puts(K - Q + counter[i].to_i > 0 ? "Yes" : "No")
end


Measured memory_bytes: 21812
n,m=map(int,input().split());p=list(map(int,input().split()));z=0;import sys;sys.setrecursionlimit(10**9);f=[i for i in range(n)]
def r(f,x):
  if f[x]!=x:f[x]=r(f,f[x])
  return f[x]
def u(f,a,b):
  x,y=r(f,a),r(f,b)
  if x!=y:f[x]=y
for i in range(m):a,b=map(int,input().split());u(f,a-1,b-1)
for i in range(n):z+=r(f,i)==r(f,p[i]-1)
print(z)

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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using edge=pair<int ,llint>;
using Graph=vector<vector<edge>>;

llint n;
Graph G;
vector<llint>dir;

void dfs(int v,int p,int cur){
	dir[v]=cur;
	for(auto e : G[v]){
		if(e.first==p)continue;
		if(e.second & 1)dfs(e.first,v,1-cur);//長さが奇数
		else dfs(e.first,v,cur);
	}
}

void solve(){
	cin >> n;
	G.assign(n, vector<edge>());
	for(int i=0;i<n-1;i++){
		llint a,b,c;
		cin >> a >> b >> c;
		a--;b--;
		G[a].push_back(edge(b,c));
		G[b].push_back(edge(a,c));

	}
	dir.assign(n,0);
	dfs(0,-1,1);
	for(auto d:dir)cout << d << endl;
}

int main() {
  solve();
  return 0;
}


Measured memory_bytes: 10752
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, m;
vector<pair<ll, ll>> v[100000];
bool used[100000];
ll koko[100000];
bool dfs(ll now){
	bool ret = 1;
	for(pair<ll, ll> next : v[now]){
		if(used[next.first]){
			if(koko[next.first] != koko[now] + next.second) return false;
		}else{
			used[next.first] = 1;
			koko[next.first] = koko[now] + next.second;
			ret &= dfs(next.first);
		}
	}
	return ret;
}
int main(){
	cin >> n >> m;
	for(ll i = 0; i < m; i++){
		ll l, r, d; cin >> l >> r >> d;
		v[--l].push_back(pair<ll, ll>(--r, d));
		v[r].push_back(pair<ll, ll>(l, -d));
	}
	bool ans = 1;
	for(ll i = 0; i < n; i++){
		if(!used[i]){
			used[i] = 1;
		}
		ans &= dfs(i);
	}
	cout << (ans ? "Yes\n" : "No\n");
	return 0;
}

Measured memory_bytes: 16512
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    int a,b,c;
    cin >> a >> b >> c;
    if (a+b+c>=22)
    {
        cout << "bust" << endl;
    }
    else
    {
        cout << "win" << endl;
    }

    return 0;
}


Measured memory_bytes: 892
import sys
N,M=map(int,input().split())
_min,_max=map(int,input().split())
for i in range(M-1):
   L,R=map(int,input().split())
   if R<_min or L>_max:
       print(0)
       sys.exit()
   _min,_max=max(_min,L),min(_max,R)
print(_max+1-_min)   

Measured memory_bytes: 3188
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    x, y = ns()

    ans = abs(abs(x) - abs(y))

    if 0 < y < x:
        ans += 2
    elif 0 > x > y:
        ans += 2
    elif x > 0 and y < 0:
        ans += 1
    elif x < 0 and y > 0:
        ans += 1
    elif x > 0 and y == 0:
        ans += 1
    elif x == 0 and y < 0:
        ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10464
from collections import defaultdict as dd
N, K = map(int, input().split())
A = list(map(int, input().split()))
D = dd(int)
for i in range(N):
  D[A[i]] += 1
j = len(D)-K
ans = 0
for i in sorted(D.values()):
  if j <= 0: break
  ans += i
  j -= 1
print (ans)

Measured memory_bytes: 32568
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
ll n, cou[4];
double p[305][305][305];
double ev[305][305][305];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n;
	for (ll i = 0; i < n; i++){
		ll a;
		cin >> a;cou[a]++;
	}
	//~ p[a][b][c] is the probability that you will get to that state
	//~ ev[a][b][c] is the expected value of number of moves to get to get rid of all the 0s, before getting to state a, b, c
	//~ memset(p, 0, sizeof(p));
	//~ memset(ev, 0, sizeof(ev));
	p[cou[1]][cou[2]][cou[3]] = 1;
	
	for (ll c = cou[3]; c >= 0; c--){
		for (ll b = n; b >= 0; b--){
			for (ll a = n; a >= 0; a--){
				if (a == 0 && b == 0 && c == 0)continue;
				if (a+b+c > n)continue;
				double p_waste = (double) (n-(a+b+c))/(double)n;
				double ev_waste = p_waste/(1-p_waste);
				ev[a][b][c] += ev_waste*p[a][b][c];
				//1
				if (a != 0){
					double p_pick = (double)a/(a+b+c);
					p[a-1][b][c] += p[a][b][c] *p_pick;
					ev[a-1][b][c] += ev[a][b][c] *p_pick;
				}
				//2
				if (b!= 0){
					double p_pick = (double)b/(a+b+c);
					p[a+1][b-1][c] += p[a][b][c]*p_pick;
					ev[a+1][b-1][c] += ev[a][b][c]*p_pick;
				}
				//3
				if (c!= 0){
					double p_pick = (double)c/(a+b+c);
					p[a][b+1][c-1] += p[a][b][c]*p_pick;
					ev[a][b+1][c-1] += ev[a][b][c]*p_pick;
				}
			}
		}
	}
	double ans = ev[0][0][0] + cou[1]+2*cou[2]+3*cou[3];
	cout << setprecision(20) << ans;
}


Measured memory_bytes: 438528
from itertools import combinations
N=int(input())
nums={}
for i in "MARCH":
    nums[i]=0
for i in range(N):
    s=input().strip()
    if s[0] in "MARCH":
        nums[s[0]]+=1
ct=0
for a,b,c in combinations("MARCH",3):
    ct+=nums[a]*nums[b]*nums[c]
print(ct)

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

int main()
{
	string S;

	cin >> S;

	bool flg = true;

	for (int i = 0; i < S.length(); i++)
	{
		if (i % 2 == 0)
		{
			if (S[i] == 'L')
			{
				flg = false;
				break;
			}
		}

		if (i % 2 == 1)
		{
			if (S[i] == 'R')
			{
				flg = false;
				break;
			}
		}
	}

	if (flg == true)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
from collections import Counter
s=input()
t=input()

sc=Counter(s)
tc=Counter(t)
if len(sc)!=len(tc):
  print("No")
else:
  for s1,t1 in zip(sorted(sc.items(),key=lambda i: i[1]),sorted(tc.items(),key=lambda i: i[1])):
    if s1[1]!=t1[1]:
      print("No")
      break
  else:
    print("Yes")

Measured memory_bytes: 9624
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include<bits/stdc++.h>
#include<iostream>
#include<iterator>

#define max(a,b) ((a>b)?a:b)                        //finding max
#define min(a,b) ((a<b)?a:b)                        //finding min
#define Max(a,b,c) max(a,max(b,c))                  //finding max between 3 numbers
#define Min(a,b,c) min(a,min(b,c))                  //finding min between 3 numbers
#define Pi acos(-1.0)                               //defining Pi for mathematical uses
#define Clear(a) memset(a,0,sizeof(a))              //clearing memory of an array
#define setfalse(a) memset(a,false,sizeof(a))       //setting the array into false
#define settrue(a) memset(a,true,sizeof(a))         //setting the array into true
#define clrstr(a) memset(a,'\0',sizeof(a))          //setting string array to null
#define open freopen("input.txt","r",stdin)         //opening input file
#define close freopen ("output.txt","w",stdout)     //opening output file
#define Case(a) printf("Case %d: ",a)               //printing case number
#define caseh(a) printf("Case #%d: ",a)             //printing case number having '#'
#define getcase(a) scanf("%d",&a)                   //scanning case number
#define caseloop(a,b) for(a=1;a<=b;a++)             //making case loop
#define EPS 1e-9                                    //small value for avoiding preccesion error
#define LL long long                                //long long short form

using namespace std;

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




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

int main() {

  int n;
  cin >> n;

  for ( int i = 0; i < n; i++ ) {

    double x[4],y[4];
    cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> x[3] >> y[3];

    if ( x[0] == x[1] || x[2] == x[3] ) {

      if ( x[0] == x[1] && x[2] == x[3] ) {
	cout << "YES" << endl;
      }else {
	cout << "NO" << endl;
      }

    }else {

      if ( abs(( y[1] - y[0] ) / ( x[1] - x[0] ) - ( y[3] - y[2] ) / ( x[3] - x[2] )) < 0.000000001 ) {
	cout << "YES" << endl;
      }else {
	cout << "NO" << endl;
      }

    }

  }

  return 0;

}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
 
 
const int MAX = 1000005;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    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 COM(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;
}
 
int main(){
    int N, M, K; cin >> N >> M >> K;
    COMinit();
    ll cost = 0;
    REP(i,N)REP(j,M){
        cost += M*((ll)(i+1)*i/2+(ll)(N-i)*(N-i-1)/2) + N*((ll)(j+1)*j/2+(ll)(M-j)*(M-j-1)/2);
        cost %= MOD;
    }
    cost = (cost*500000004)%MOD;
    cost =(COM(N*M-2,K-2)*cost) %MOD;
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 23680
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> a(n+1);
	a[n] = 1000000001;
	vector<int> b(n+1);
	b[n] = 1000000001;
	vector<int> c(2 * n);
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		a[i] = x;
		b[i] = y;
		c[2 * i] = x; c[2 * i + 1] = y;
	}
	int ca = 0; int cb = 0;
	int ans = 0;
	int ba = 0;
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	for (int i = 0; i < 2*n; i++) {
		int da = 0;
		if (i != 0) {
			if (c[i] == c[i - 1]) {
				da == 1;
			}
		}
		if (da == 0) {
			int si = c[i];
			while (a[ca] <= si) {
				ca++;
				ba++;
			}
			while (b[cb] < si) {
				cb++;
				ba--;
			}
			ans = max(ans, ba);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 4432
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
 
int a, b;
 
int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> a >> b;
	if (a == 1) a += 13;
	if (b == 1) b += 13;
	if (a == b) cout << "Draw" << endl;
	else if (a > b) cout << "Alice" << endl;
	else cout << "Bob" << endl;
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  int n;
  cin>>n;
  
  vector<int> P(n),Q(n);
  rep(i,n) cin>>P[i];
  rep(i,n) cin>>Q[i];
  
  vector<int> A(n);
  rep(i,n) A[i]=i+1;
  
  int cnt=0,a,b;
  do{
    cnt++;
    if(A==P) a=cnt;
    if(A==Q) b=cnt;
  }while(next_permutation(ALL(A)));
  
  cout<<abs(a-b)<<endl;

  return 0;
}

Measured memory_bytes: 3628
import math
import decimal

def hantei(f,p):
    if f*f<p :
        return True
    return False


def nibun2(l,r,p):
    if r == l:
        return l
    f = (l+r+1)//2
    if hantei(f,p):
        return nibun2(f,r,p)
    else:
        return nibun2(l,f-1,p)

r=[]
q=int(input())
for _ in range(q):
    a,b=map(int,input().split())
    p=a*b
    if p ==1:res = 0
    else:
        t = nibun2(0,10**20,p)
        res = t*2-1
        if (p-1)//t ==t:res -= 1
        if a==b:res+=1
    r.append(res)

print("\n".join(map(str,r)))


Measured memory_bytes: 68056
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;
#define rep(i,l,r) for(ll i=l;i<=r;i++)

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

string memo[1000000];
string bina(ll i,ll j){
    if(memo[i]!=""){
        return memo[i];
    }
    ll ii=i;
    string ans="";
    while(i>0){
        if(i%2==1){
            ans='1'+ans;
            i=i/2;
        }else{
            ans='0'+ans;
            i=i/2;
        }
    }
    
    while(ans.size()<j){
        ans='0'+ans;
    }
    memo[ii]=ans;
    
    return ans;
}


int main(){
    string s;cin>>s;
    ll n;n=s.size();
    string b;
    ll ans=0;
    ll sum;
    string ss;
    rep(i,0,pow(2,n-1)-1){
        b=bina(i,n-1);
        sum=0;
        ss=s[0];
        rep(j,0,n-2){
            if(b[j]=='1'){
                sum+=stoll(ss);
                ss=s[j+1];
            }else{
                ss=ss+s[j+1];
            }
        }
        sum+=stoll(ss);
        ans+=sum;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 8064
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
n = 10**5+10
Q = inp()
ch = [False] * (n+5)
for i in range(1,n):
    if is_prime(i):
        ch[i] = True
table = [0] * (n+5)
for i in range(1,n):
    tmp = 0
    if i%2 and ch[i] and ch[(i+1)//2]:
        tmp = 1
    table[i] = table[i-1] + tmp
for _ in range(Q):
    a,b = inpl()
    print(table[b] - table[a-1])

Measured memory_bytes: 80056
package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func main() {
	var n int
	_, _ = fmt.Scanf("%d", &n)
	values := readInt64Slice()
	costs := readInt64Slice()
	var sum int64
	for k, v := range values {
		if v > costs[k] {
			sum += v - costs[k]
		}
	}
	fmt.Println(sum)
}

func readInt64Slice() []int64 {
	line := readStringSlice()
	slice := make([]int64, 0, len(line))
	for _, tmp := range line {
		val, err := strconv.ParseInt(tmp, 10, 64)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		slice = append(slice, val)
	}
	return slice
}
func readFloat64Slice() []float64 {
	line := readStringSlice()
	slice := make([]float64, 0, len(line))
	for _, tmp := range line {
		val, err := strconv.ParseFloat(tmp, 64)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		slice = append(slice, val)

	}
	return slice
}
func readString() string {
	s, _, _ := in.ReadLine()
	return string(s)
}
func readStringSlice() []string {
	line := readString()
	s := strings.Split(line, " ")
	return s
}
func dump(value ...interface{}) {
	for _, v := range value {
		fmt.Printf("%#v\n", v)
	}
}


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


void solve(long long A, long long B, long long H, long long M){
  static const double pi = 3.141592653589793;
  double hm = M;
  hm /= 12;
  double tmp = abs(5*H+hm-M);
  double c = (tmp >= 30) ? 60-tmp : tmp;
  c = 2*A*B * cos(c / 30 * pi);
  double r = pow(A, 2) + pow(B, 2) - c;
  double ans = sqrt(r);
  cout << fixed << setprecision(10) << ans << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long H;
    scanf("%lld",&H);
    long long M;
    scanf("%lld",&M);
    solve(A, B, H, M);
    return 0;
}


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

//a,...,z,aa,ab,...,zy,zz,aaa,aab,...zzy,zzz,aaaa...と犬に名付ける
//N匹目の名前は?(N<=1000000000000001)
//長さnの名前は26^n通りある
int main(){
    long long int N;
    cin >> N;
    string name = "";

    //a,...,zの文字を格納
    char c[26];
    for(int i=0;i<26;++i){
        c[i]='a'+i;
    }

    //文字数を固定して0スタートにする
    N=N-1;
    long long int pow = 26;
    int count=1;//文字数
    while(true){
        if(N>=pow){
            N=N-pow;
            ++count;
        } else {
            break;
        }
        pow=pow*26;
    }

    //文字列を作る
    while(N>0){
        name=c[N%26]+name;
        --count;
        N=N/26;
    }
    //文字数を満たすまでaを追加
    for(int i=0;i<count;++i){
        name='a'+name;
    }

    cout << name << endl;
}


Measured memory_bytes: 3608
#include <stdio.h>

int N =100;

int min(int n,int m){
  int i;
  if(n<=m){
    i = n;
  }
  else i = m;
  return i;
}

int main(){
  int n,X[N+1],Y[N+1][N+1],i,j,k,s;

scanf("%d",&n);
for(i=1;i<=n;i++){
  scanf("%d %d",&X[i-1],&X[i]);
  }
  for(i =1;i<=n;i++){
    Y[i][i]=0;
  }
  for(j=2;j<=n;j++){
    for(i=1;i<=n-j+1;i++){
      k = i+j -1;
      Y[i][k]=(1<<21);
      for(s = i;s <=k-1;s++){
        Y[i][k]=min(Y[i][k],Y[i][s]+Y[s+1][k]+X[i-1]*X[s]*X[k]);
      }
    }
  }
  printf("%d\n",Y[1][n]);
  return 0;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(ll a = 0;a < n;a++)

static const ll INF = 1e15;
static const ll mod = 1e9+7;

template<typename T>
static inline void chmin(T& ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T& ref, const T value) {
    if (ref < value) ref = value;
}

int main() {
    string s;
    cin >> s;
    int n = s.size();
    ll sum = 0;
    rep(i, n) {
        sum += s[i] - '0';
        sum %= 9;
    }
    if (sum) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
    return 0;
}


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


int main() {
	int N;
	std::cin >> N;
	std::vector<int> s(N);
	for (auto& p : s) {
		std::cin >> p;
	}
	int sum = std::accumulate(begin(s), end(s), 0);
	if (sum % 10) {
		std::cout << sum << std::endl;
	}
	else {
		std::sort(begin(s), end(s));
		for (auto& p : s) {
			int ans = sum - p;
			if (ans % 10) {
				std::cout << ans << std::endl;
				return 0;
			}
		}
		std::cout << 0 << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_set>

using namespace std;

//vector<unordered_set<int>> cache; // n -> y
vector<vector<int>> cache; // n -> y

void c(int n, int y, int m, int g, int s) {
    //cout << "n: " << n << ", y: " << y << endl;
    if (cache[n][y])
        return;

    if (y == 0) {
        if (n != 0) {
            return;
        }

        cout << m << " " << g << " " << s << endl;
        exit(0);
    } else if (n == 0) {
        return;
    }

    if (10 <= y) {
        c(n - 1, y - 10, m + 1, g, s);
        if (2 <= n)
            c(n - 2, y - 10, m, g + 2, s);
        if (10 <= n)
            c(n - 10, y - 10, m, g, s + 10);
    }

    if (5 <= y) {
        c(n - 1, y - 5, m, g + 1, s);
        if (5 <= n)
            c(n - 5, y - 5, m, g, s + 5);
    }

    if (1 <= y)
        c(n - 1, y - 1, m, g, s + 1);

    cache[n][y] = 1;
}

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

    cache.resize(2001);
    for (int i = 0; i < cache.size(); i++)
        cache[i].resize(20000);

    if (y <= n * 10000 && n * 1000 <= y)
        c(n, y / 1000, 0, 0, 0);
    cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 156800