akhauriyash/Code-Regression huggingface dataset:
/*
    author:@bhaskar_8998
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds; 
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;  
typedef long long i64;
typedef vector<int> vi;
typedef vector<long> vl;
typedef pair<int,int>pii;
#define all(A) (A).begin(),(A).end()
#define pb push_back
#define MOD 1000000007
#define fastio() {ios_base::sync_with_stdio(false);cin.tie(NULL);}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    fastio();
    i64 ss[31];
    for(int i=1,ts=2;i<=30;i++){
        ss[i]=ts;
        ts*=2;
    }
    clock_t beg=clock();
    int t=1;
    // cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        unordered_map<int,int> m;
        m.clear();
        for(int i=0,l;i<k;i++){
            cin>>l;
            for(int j=0,ct;j<l;j++){
                cin>>ct;
                m[ct]+=1;
            }
        }
        int ans=0;
        for(int i=1;i<=n;i++){
            if(m[i]==0)ans+=1;
        }
        cout<<ans;
    }

    clock_t end=clock(); 
    fprintf(stderr, "\n%lf sec\n", (double)(end-beg)/(CLOCKS_PER_SEC));
    return 0;
}


    

Measured memory_bytes: 3784
fun main() {
    println(
        when (nextInt() % 10) {
            2, 4, 5, 7, 9 -> "hon"
            0, 1, 6, 8 -> "pon"
            3 -> "bon"
            else -> throw AssertionError()
        }
    )
}

val sc = java.util.Scanner(System.`in`)
fun next(): String = sc.next()
fun nextInt() = sc.nextInt()
fun next2Int() = Pair(nextInt(), nextInt())
fun next3Int() = Triple(nextInt(), nextInt(), nextInt())
fun nextIntArray(size: Int) = IntArray(size) { nextInt() }
fun nextLong() = sc.nextLong()
fun nextLine(): String = sc.nextLine()
fun nextList() = nextLine().split(" ")
fun printYesNo(isYes: Boolean) = println(if (isYes) "Yes" else "No")
fun printString(action: StringBuilder.() -> Unit) = println(buildString(action))


Measured memory_bytes: 36320
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int z=0,y=0;
		int a[]=new int[N];
		while(z<N){
			a[z]=stdIn.nextInt();
			z++;
		}z=0;
		Arrays.sort(a);
		while(z<N){
			if(z==N-1)
				a[z]/=2;
			y+=a[z];
			z++;
		}
		System.out.println(y);
	}
}


Measured memory_bytes: 23892
#!/usr/bin/env python3
h, w, a, b = map(int, input().split())
ans = [[0] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        ans[i][j] = 0 + (j <= a - 1) ^ (i > b - 1)
for x in ans:
    print(*x, sep='')


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

int main(){
    int N, W;
    cin >> N >> W;

    vector< vector<long long> > sum(4);

    long long w0, v;
    cin >> w0 >> v;
    sum[0].push_back(v);

    for(int i = 1 ; i < N ; i++){
        long long w;
        cin >> w >> v;
        sum[w - w0].push_back(v);
    }

    for(int i = 0 ; i < 4 ; i++){
        sort(sum[i].rbegin(), sum[i].rend());
        sum[i].insert(sum[i].begin(), 0LL);

        for(int j = 1 ; j < sum[i].size() ; j++){
            sum[i][j] += sum[i][j - 1];
        }
    }

    long long ans = 0;
    for(int i = 0 ; i < sum[0].size() ; i++){
        for(int j = 0 ; j < sum[1].size() ; j++){
            for(int k = 0 ; k < sum[2].size() ; k++){
                for(int l = 0 ; l < sum[3].size() ; l++){
                    if(w0 * i + (w0 + 1) * j + (w0 + 2) * k + (w0 + 3) * l > W){
                        break;
                    }
                    ans = max(ans, sum[0][i] + sum[1][j] + sum[2][k] + sum[3][l]);
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

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

	int front = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'A')
		{
			front = i - 1;
			break;
		}
	}

	int back = 0;
	for(int i =0;i<s.size();i++)	{
		if(s[i] == 'Z')
		{
			back = i;
		}
	}

	cout << back - front << endl;
}


Measured memory_bytes: 640
<?php
  list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
 
  $n = $c-($a+$b);
 
  if($n<0){
    echo "No";
    exit;
  }
 
  if(4*$a*$b < $n*$n){
    echo "Yes";
  }else{
    echo "No";
  }

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

const int MOD = 1e9 + 7;

const int MAX_A = 1e6;

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

void solve_test() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];

	int g = 0;
	for (int i = 0; i < n; i++)
		g = gcd(g, a[i]);
	if (g != 1) {
		cout << "not coprime\n";
		return;
	}

	vector<int> count(MAX_A + 1);
	for (int i = 0; i < n; i++)
		count[a[i]]++;

	vector<bool> prime(MAX_A + 1, true);
	prime[0] = prime[1] = false;
	for (int i = 2; i <= MAX_A; i++)
		if (prime[i]) {
			int total = 0;
			for (int j = i; j <= MAX_A; j += i) {
				prime[j] = false;
				total += count[j];
			}
			if (total > 1) {
				cout << "setwise coprime\n";
				return;

			}
		}

	cout << "pairwise coprime\n";
}

int32_t main() {
	int T; 
	// cin >> T;
	T = 1;
	while (T--)
		solve_test();

	return 0;
}


Measured memory_bytes: 19080
#include<bits/stdc++.h>
using namespace std;
int n,sumw[300010],sume[300010],ans=1e9;
char c[300010];
int main(){
	scanf("%d",&n);
	scanf("%s",c+1);
	for(int i=1;i<=n;i++){
		sumw[i]=sumw[i-1];
		if(c[i]=='W')sumw[i]++;
	}
	for(int i=n;i>=1;i--){
		sume[i]=sume[i+1];
		if(c[i]=='E')sume[i]++;
	}
	for(int i=1;i<=n;i++){
		ans=min(ans,sumw[i-1]+sume[i+1]);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 2944
#include"bits/stdc++.h"
using namespace std;
int a[100001];
int f[100001];
int main()
{
	int n;
	scanf("%d",&n);
	memset(f+1,0x7f,sizeof(f)-sizeof(f[0]));
	a[0]=1;
	int count=1;
	for(int i=1;(a[count++]=pow(6,i))<=n;i++);
	for(int i=1;(a[count++]=pow(9,i))<=n;i++);
	sort(a,a+count);
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<count&&a[j]<=i;j++)
		{
			f[i]=min(f[i],f[i-a[j]]+1);
		//	printf("%d %d\n",i,f[i]);
		}
	}
	printf("%d",f[n]);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
 
int main(){
  int n,r;
  cin >> n >> r;
  if (n >= 10) {
      cout << r;
  } else {
      cout << r +100*(10-n);
  }
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
c = 0
for i in range(N-1):
    minj = i
    boo = 0
    for j in range(i,N):
        if A[j] < A[minj]:
            minj = j
            boo = 1
    A[i], A[minj] = A[minj], A[i]
    if boo:
        c += 1
print(*A)
print(c)



Measured memory_bytes: 5604
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main() {

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    out(min(a,b) + min(c, d));




    return 0;
}






Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int mINF = 1e9;
const int MOD = 1e9+7;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(){
    int n;cin >> n;
    string s;cin >> s;
    int ans = 1;
    for(int i=0;i<n-1;i++){
        if(s[i]!=s[i+1])ans++;
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define FOR(i, start, end) for(ll i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

int h;
int N;

int search(string str) {
    int cnt = 0;
    bool isValid = str.find('7') != string::npos &&
                   str.find('5') != string::npos &&
                   str.find('3') != string::npos &&
                   stoi(str) <= N;

    if (isValid) {
        cnt++;
    }
    if (str.size() == h) {
        return cnt;
    }

    cnt += search(str + "7");
    cnt += search(str + "5");
    cnt += search(str + "3");

    return cnt;
}

int main(void) {
    cin >> N;
    h = to_string(N).size();

    string buf;
    int ans = search(buf);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(1)
	{
		c=c-b;
		if(c<=0)
		{
		cout<<"Yes";
		return 0;
	    }
	    a=a-d;
	    if(a<=0)
	    {
	    	cout<<"No";
	    	return 0;
		}
	}
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
double EPS = 1e-10;
int inf = 1e9;
Int mod = 1e9+7;

Int n;
double r, theta;
complex<double> p[20];

Int ma;
double dp[20][20][10001];

// void f(Int s, Int t, double d, Int cnt) {
//     ma = max(ma, cnt);
//     for (Int i = 0; i < n; i++) {
//         if (i == s or i == t) continue;
//         complex<double> st = p[t] - p[s];
//         complex<double> tr = p[i] - p[t];
//         double t1 = max(arg(st), arg(tr));
//         double t2 = min(arg(st), arg(tr));
//         double tt = min(t1 - t2, 2.0 * M_PI - (t1 - t2));
//         double dd = d + abs(p[i] - p[t]);
//         if (dd <= r and 0 < tt and tt <= theta and dd < dp[t][i][cnt + 1]) {
//             dp[t][i][cnt + 1] = dd;
//             f(t, i, dd, cnt + 1);
//         }
//     }
// }

int main() {
    cin >> n >> r >> theta;
    theta = theta * M_PI / 180.0;
    for (Int i = 0; i < n; i++) {
        double a, b;
        cin >> a >> b;
        p[i].real(a);
        p[i].imag(b);
    }
    for (Int i = 0; i < 20; i++) {
        for (Int j = 0; j < 20; j++) {
            for (Int k = 0; k <= 10000; k++) {
                dp[i][j][k] = inf;
            }
        }
    }
    queue<tuple<Int, Int, Int>> q;
    for (Int i = 1; i < n; i++) {
        if (abs(p[0] - p[i]) > r) continue;
        q.push(make_tuple(0, i, 1));
        dp[0][i][1] = abs(p[0] - p[i]);
    }
    vector<Int> v[20][20];
    for (Int i = 0; i < n; i++) {
        for (Int j = 0; j < n; j++) {
            for (Int k = 0; k < n; k++) {
                if (i == j or j == k or k == i) continue;
                complex<double> st = p[j] - p[i];
                complex<double> tr = p[k] - p[j];
                double t1 = max(arg(st), arg(tr));
                double t2 = min(arg(st), arg(tr));
                double tt = min(t1 - t2, 2.0 * M_PI - (t1 - t2));
                if (0 - EPS < tt and tt <= theta + EPS) {
                    v[i][j].push_back(k);
                }
            }
        }
    }
    while (not q.empty()) {
        tuple<Int, Int, Int> x = q.front();
        Int s = get<0>(x);
        Int t = get<1>(x);
        Int u = get<2>(x);
        q.pop();
        ma = max(ma, u);
        for (Int i = 0; i < (Int)v[s][t].size(); i++) {
            double dd = dp[s][t][u] + abs(p[v[s][t][i]] - p[t]);
            if (dd <= r + EPS and dd < dp[t][v[s][t][i]][u + 1]) {
                dp[t][v[s][t][i]][u + 1] = dd;
                //f(t, i, dd, cnt + 1);
                q.push(make_tuple(t, v[s][t][i], u + 1));
            }
        }
    }
    dump(ma);
    return 0;
}


Measured memory_bytes: 34840
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int ,int> pii;
typedef pair<ll,ll> pll;
const int INF = 1000000000;
const int maxN = 1010;
const int MOD = 100003;


vector<int> a;
vector<int> b;
int main()
{
	int x,a,b;
	scanf("%d%d%d",&x,&a,&b); 
	if(b<=a)
		printf("delicious\n");
	else if(b>a && (b-a)<=x)
		printf("safe\n");
	else if(b>a && (b-a)>x)
		printf("dangerous\n");
	return 0;
} 


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int calc(int x,int y,int b,int p){
	return ((b>=5 && p>=2)?0.8:1)*(x*b+y*p);
}

int main(){
	int n; scanf("%d",&n);
	rep(_,n){
		int x,y,b,p; scanf("%d%d%d%d",&x,&y,&b,&p);
		printf("%d\n",min(calc(x,y,b,p),calc(x,y,max(b,5),max(p,2))));
	}
	return 0;
}

Measured memory_bytes: 1032
#include<stdio.h>
int main(){int a,b,c,t,u,n=3600,m=60;while(scanf("%d%d%d",&a,&b,&c),a>=0)t=7200-a*n-b*m-c,u=t*3,printf("%02d:%02d:%02d\n%02d:%02d:%02d\n",t/n,t/m%m,t%m,u/n,u/m%m,u%m);return 0;}

Measured memory_bytes: 0
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//
//  
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

template<class T> inline bool chmin(T& a, T b){ if(a>b){a=b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b){ if(a<b){a=b; return 1;} return 0;}

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
const double PI=3.1415926535897932;

//#define __DBG__


void solve(void){
  
  double a, b, x;
  
  cin >> a >> b >> x;
  
  double Vhalf=a*a*b/2;
  double alpha = 0;
  double beta=90;
  
  if(x>Vhalf){ 
    beta = atan(2*b/a-2*x/(a*a*a))*180/PI;
  }
  else if(x<Vhalf){
    alpha = atan(2*x/(a*b*b))*180/PI;
    beta = 90-alpha;
  }
  else
  {
    beta=45;
  }
    
  cout << fixed;
  cout << setprecision(15);
  cout << beta << endl; 

  return;
   
}


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

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

    solve();
 
    return 0;
}




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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:

    ll calc_s(ll s) {
        ll res = 0;
        while(s) {
            res += s % 10;
            s /= 10;
        }
        return res;
    }

    vector<ll> generate_list() {
        vector<pair<ll, double>> candidate, s;
        int num_post_fix = 0;
        set<ll> used;
        while(candidate.empty() or candidate.back().first <= 1e15) {
            repeat(i, 1, 999 + 1) {
                ll v = i; rep(foo, num_post_fix) v = v * 10 + 9;
                if(used.count(v)) continue;
                candidate.emplace_back(v, (double)v / calc_s(v));
                used.insert(v);
            }
            num_post_fix++;
        }
        sort(all(candidate));
        for(int i = candidate.size() - 2; i >= 0; i--) {
            set_min<double>(candidate[i].second, candidate[i + 1].second);
        }
        vector<ll> result;
        for(auto p : candidate) {
            if((double) p.first / calc_s(p.first) <= p.second) result.push_back(p.first);
        }
        return result;
    }

    vector<ll> generate_list2() {
        vector<double> val(100000000);
        vector<ll> result;
        repeat(i, 1, val.size()) {
            val[i] = (double) i / calc_s(i);
        }
        for(int i = val.size() - 1; i > 0; i--) {
            set_min(val[i - 1], val[i]);
        }
        repeat(i, 1, val.size()) {
            if((double) i / calc_s(i) <= val[i]) result.push_back(i);
        }
        return result;
    }

    bool solve() {
        int K; cin >> K;

        auto a = generate_list();

        // auto b = generate_list2();

        rep(i, K) cout << a[i] << endl;

        // rep(i, b.size()) {
        //     if(a[i] != b[i]) {
        //         debug(a[i]); debug(b[i]);
        //         exit(-1);
        //     }
        // }



        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 1020
import java.util.Scanner;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte(){
        if(ptr < buflen){
            return true;
        }else{
            ptr = 0;
            try{
                buflen = in.read(buffer);
            }catch(IOException e){
                e.printStackTrace();
            }
            if(buflen <=0){
                return false;
            }
        }
        return true;
    }

    private int readByte(){
        if(hasNextByte())return buffer[ptr++];
        else return -1;
    }

    private static boolean isPrintableChar(int c){
        return 33<=c && c<=126;
    }
    public boolean hasNext(){
        while(hasNextByte() && !isPrintableChar(buffer[ptr]))ptr++;
        return hasNextByte();
    }

    public String next(){
        if(!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong(){
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b){
            throw new NumberFormatException();
        }
        while(true){
            if('0' <= b && b<='9'){
                n*=10;
                n+=b-'0';
            }else if(b==-1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt(){
        long nl = nextLong();
        if(nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDoutble(){return Double.parseDouble(next());}
}
public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        char[][] s = new char[n][];
        Map<String,Long> map = new HashMap<>();
        Long ii;
        String ss;
        for(int i=0;i<n;i++){
            s[i] = fs.next().toCharArray();
            Arrays.sort(s[i]);
            ss = new String(s[i]);
            ii = map.get(ss);
            if(ii==null){
                map.put(ss,1L);
            }else{
                map.replace(ss,ii+1);
                
            }
        }
        long sum = 0;
        for(Long i : map.values()){
            if(i>1){
                sum+=i*(i-1)/2;
            }
        }
        System.out.println(sum);
        

    }
}

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

int area[18][18];
int a,b,n;
int ans=0;

int saiki(int x,int y){
  //cout << x << ' ' << y << endl;
  if(area[x][y] == -1) return 0;
  if(x == a && y == b) {
    // cout << 'z' << endl;
    return 1;
  }
  ans += saiki(x,y+1);
  ans += saiki(x+1,y);
  return 0;
}

int main(){
  int x,y;
  memset(area,-1,sizeof(area));
  while(1){
    ans=0;
    cin >> a >> b;
    if(a == 0 && b == 0)break;
    for(int i=1;i<=a;i++){
      for(int j=1;j<=b;j++){
	area[i][j]=0;
      }
    }
    cin >> n;
    for(int i=0;i<n;i++){
      cin >> x >> y;
      area[x][y]=-1;
    }
    saiki(1,1);
    cout << ans << endl;
  }
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

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

  int n;
  cin>>n;

  int a[n+1];

  for(int i=1; i<=n; i++) {
    cin>>a[i];
  }

  int dp[n+1];

  memset(dp, -1, sizeof(dp));

  dp[1]=0;
  dp[2]=abs(a[2]-a[1]);

  for(int i=3; i<=n; i++) {
    if(dp[i]==-1) {
      dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
    }
  }

  cout<<dp[n];
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner();
		String s = sc.next();
		int forward = Integer.parseInt(s.substring(0, 2));
		int backward = Integer.parseInt(s.substring(2, 4));
		if(isMonth(forward) && !isMonth(backward))
			System.out.println("MMYY");
		else if(!isMonth(forward) && isMonth(backward))
			System.out.println("YYMM");
		else if(isMonth(forward) && isMonth(backward))
			System.out.println("AMBIGUOUS");
		else if(!isMonth(forward) && !isMonth(backward))
			System.out.println("NA");
	}
	
	static boolean isMonth(int i) {
		return 0 < i && i < 13;
	}
}

class Scanner {
	private static final int SPACE = (int)' ';
	private static final int LINE_END_0 = 13;
	private static final int LINE_END_1 = 10;
	private static final int BEFORE = -1;
	private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	public String next(){
		StringBuilder sb = new StringBuilder();
		
		int length = BEFORE;
		readLoop: while(true) {
			try {
				int value = br.read();
				switch(value) {
				case LINE_END_1:
					if(length == BEFORE)
						break;
					
					if((int)sb.charAt(length) == LINE_END_0)
						sb.deleteCharAt(length);
				case SPACE:
					break readLoop;
				}
				sb.append((char)value);
				length++;

			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return sb.toString();
	}
	
	public String[] nextArray(int length) {
		String[] array = new String[length];
		for(int i = 0; i < length; i++)
			array[i] = next();
		return array;
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}
	
	public double[] nextDoubleArray(int length) {
		double[] array = new double[length];
		for(int i = 0; i < length; i++)
			array[i] = nextDouble();
		return array;
	}
	
	public int nextInt() {
		return Integer.parseInt(next());
	}
	
	public int[] nextIntArray(int length) {
		int[] array = new int[length];
		for(int i = 0; i < length; i++)
			array[i] = nextInt();
		return array;
	}
	
	public long nextLong() {
		return Long.parseLong(next());
	}
	
	public long[] nextLongArray(int length) {
		long[] array = new long[length];
		for(int i = 0; i < length; i++)
			array[i] = nextLong();
		return array;
	}
	
	public boolean ready() {
		try {
			return br.ready();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
}


Measured memory_bytes: 22996
using System;

class Program
{
 static void Main(String[] args)
 {
   var str = Console.ReadLine().Split(' ');
   int[] buttonPushSec = new int[4];
   int bothPushSec = 0;
   int endSec = 0;
   int startSec = 0;
   
   buttonPushSec[0] = int.Parse(str[0]);
   buttonPushSec[1] = int.Parse(str[1]);
   buttonPushSec[2] = int.Parse(str[2]);
   buttonPushSec[3] = int.Parse(str[3]);
   
   if( ( buttonPushSec[1] > buttonPushSec[2] ) && ( ( buttonPushSec[2] > buttonPushSec[0] ) || ( buttonPushSec[3] > buttonPushSec[0] ) ) )
   {
       endSec = ( ( buttonPushSec[1] > buttonPushSec[3] )? buttonPushSec[3]: buttonPushSec[1] );
       startSec = ( ( buttonPushSec[0] > buttonPushSec[2] )? buttonPushSec[0]: buttonPushSec[2] );

       bothPushSec = endSec - startSec;
   }
   
   Console.WriteLine(bothPushSec);
 }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
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;
}



int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    SORT(p);
    ll sum=0;
    for (long long i = 0; i < K; i++) {
        sum+=p[i];
    }
    cout << sum << endl;
    return 0;
}


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


int main () {
	string s;
	int n, q;
	cin >> n >> q;
	cin >> s;

	vector<int> v(s.size(), 0);
	int c = 0;
	for (int i = 0; i < s.size() - 1; i++) {
		if (s[i] == 'A' && s[i+1] == 'C') {
			c++;
		}
		v[i] = c;
	}

	for (int i = 0; i < q; i++) {
		int l, r;
		int res = 0;
		cin >> l >> r;
		l--, r--;
		if (v[r] != v[r-1])
			r = v[r-1];
		else
			r = v[r];
		if (l != 0) {
			if (v[l] != v[l-1])
				l = v[l-1];
			else
				l = v[l];
		}
		res = r - l;
		
		cout << res << endl;
	}

}

Measured memory_bytes: 1408
using System;
class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            var data = line.Split(new char[] { ' ' });
            string s = data[0];
            string t = data[1];
            line = Console.ReadLine();
            data = line.Split(new char[] { ' ' });
            int N = Convert.ToInt16(data[0]);
            int M = Convert.ToInt16(data[1]);
            string U = Console.ReadLine();
            if (U == s)
            {
                N -= 1;
            }
            else if(U== t)
            {
                M -= 1;
            }
            Console.WriteLine(string.Format("{0} {1}",N,M));
        }
}

Measured memory_bytes: 13268
#include<stdio.h>

int main(){
	char string[50][101],X[101];
	int time[50];
	int N,i,c=0;;
	int sleep=0;
	scanf("%d",&N);
	for(i=0;i<N;i++)scanf("%s %d",string[i],&time[i]);
	scanf("%s",&X[0]);
	for(i=0;i<N;i++){
		if(c==1)sleep+=time[i];
		if(strcmp(string[i],X)==0)c=1;
	}
	printf("%d\n",sleep);
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<long> A(1 + N), B(N);
	for (long& i : A) cin >> i;
	for (long& i : B) cin >> i;
	long ans = 0;
	for (int i = N - 1; i >= 0; --i) {
		ans += min(A[1 + i], B[i]) + min(A[i], B[i] - min(A[1 + i], B[i]));
		A[i] -= min(A[i], B[i] - min(A[1 + i], B[i]));
	}
	cout << ans;
}

Measured memory_bytes: 1792
def main():
    N = int(input())
    X = [0] * N
    Y = [0] * N
    H = [0] * N
    for i in range(N):
        X[i], Y[i], H[i] = map(int, input().split())
    ans = []
    for x in range(101):
        for y in range(101):
            tmp = 0
            for i in range(N):
                if H[i] == 0:
                    continue
                else:
                    tmp = H[i] + abs(X[i] - x) + abs(Y[i] - y)
                    break
            for i in range(N):
                if not (H[i] == max(tmp - abs(X[i] - x) - abs(Y[i] - y),0)):
                    break
            else:
                ans = [x,y,tmp]
                break
    if N == 1:
        if H[0] == 0:
            print(X[0],Y[0],H[0])
            exit()
    print(*ans)
            



if __name__ == "__main__":
    main()

Measured memory_bytes: 74608
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define n_l '\n'
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); } 
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef double db;
typedef vector<vi> vvi;
const ll mod=1000000007;
const ll N=200005; //check this
 
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powb(ll a,ll b) {ll res=1;a ; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int main(){
    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
    long double a,b;cin>>a>>b;
    cout<<(long long int)(a*b);
}


Measured memory_bytes: 3788
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as C8

type Pair = (Int, Int)

main :: IO ()
main = do
  [n,m] <- readInts
  ps <- sortOn fst <$> replicateM n readPair
  print $ solve (0,0) m ps
 
-- solve :: Int -> [Pair] -> Int
-- solve m = fst . foldl' f e
--   where
--     e = (0,0)
--     f (!s,!n) (a,b)
--       | n == m    = (s,n)
--       | c > m     = (s+a*(m-n),m)
--       | otherwise = (s+a*b,c)
--       where
--         c = n+b

solve :: Pair -> Int -> [Pair] -> Int
solve (s,_) _ [] = s
solve (s,n) m ((a,b):ps)
    | n == m    = s
    | c > m     = s+a*(m-n)
    | otherwise = solve (s+a*b,c) m ps
  where
    c = n+b

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

readPair :: IO Pair
readPair = do
  [x,y] <- readInts
  return (x,y)

Measured memory_bytes: 56700
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
using namespace std;

void solve(){
  int n, k; cin >> n >> k;
  set<int> st;
  for(int i = 0; i < k; i++){
    int d; cin >> d;
    for(int j = 0; j < d; j++){
      int x; cin >> x;
      st.insert(x);
    }
  }
  cout << n - st.size() << endl;
  return;
}

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


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

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

		String[] str = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int m = Integer.parseInt(str[1]);
		int[][] a = new int[n][m];
		int[] b = new int[m];

		for (int i = 0; i < n; i++) {
			String[] aStr = br.readLine().split(" ");
			for (int j = 0; j < m; j++) {
				a[i][j] = Integer.parseInt(aStr[j]);
			}
		}
		for (int i = 0; i < m; i++) {
			b[i] = Integer.parseInt(br.readLine());
		}
		int sum = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				int c = a[i][j] * b[j];
				sum += c;
			}
			sb.append(sum).append("\n");
			sum = 0;
		}

		System.out.print(sb);
	}
}

Measured memory_bytes: 27528
#include<iostream>
using namespace std;
int main(){
	int k,a,b;
  	cin>>k>>a>>b;
  	int flag=0;
  	for(int i=a;i<=b;i++){
    if(i%k==0)
    {
    	flag=1;
      	break;
    }
    }
  if(flag==0)
    cout<<"NG"<<endl;
  else
    cout<<"OK"<<endl;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if (a + b > c + d){
    cout << "Left" << endl;
  }
  else if (a + b < c + d) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int n,a[1000000];
int binarySearch(int key){
  int left,right,mid;
  left = 0;
  right = n;
  while(left < right){
    mid =(left+right)/2;
    if(a[mid]== key)
    return 1;
    else if(key < a[mid])
      right=mid;
      else
      left=mid+1;


  }
  return 0;


}

int main(){
  int i,q,key,sum=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if( binarySearch(key)) sum++;
  }
  printf("%d\n",sum);

  return 0;
}



Measured memory_bytes: 2080
(defun split (string &key (delimiterp #'(lambda (c) (char= c #\Space))))
  (loop :for beg = (position-if-not delimiterp string)
        :then (position-if-not delimiterp string :start (1+ end))
        :for end = (and beg (position-if delimiterp string :start beg))
        :when beg :collect (subseq string beg end)
        :while end))

(destructuring-bind (a b) (mapcar #'parse-integer (split (read-line)))
  (let ((sum (+ a b)))
    (format t "~a~%" (if (>= sum 10)
                         "error"
                         sum))))


Measured memory_bytes: 15972
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vi nums(n); FOR(i,n) cin >> nums[i];
    sort(nums.begin(),nums.end());
    int ans = 0;
    FOR(i,n){
        F0R(j,i+1,n-1){
            if(nums[j] == nums[i]) continue;
            F0R(k,j+1,n-1){
                if(nums[j] == nums[k]) continue;
                if(nums[i]+nums[j] > nums[k]) ans++;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3656
# -*- coding: utf-8 -*-

import copy
from collections import deque

N = int(input())
aN = [int(input()) for i in range(N)]

aN_sorted = sorted(aN)
aN_sorted = deque(aN_sorted)
aN2 = [0] * N
for i in range(N):
    if i % 2 == 0:
        aN2[i] = aN_sorted.popleft()
    else:
        aN2[i] = aN_sorted.pop()
aN_sorted2 = sorted(aN, reverse=True)
aN_sorted2 = deque(aN_sorted2)
aN3 = [0] * N
for i in range(N):
    if i % 2 == 0:
        aN3[i] = aN_sorted2.popleft()
    else:
        aN3[i] = aN_sorted2.pop()

ans = 0
for i in range(1,N):
    if i == N-1:
        ans += max(abs(aN2[i-1] - aN2[i]), abs(aN2[i] - aN2[0]))
    else:
        ans += abs(aN2[i-1] - aN2[i])
ans2 = 0
for i in range(1,N):
    if i == N-1:
        ans2 += max(abs(aN3[i-1] - aN3[i]), abs(aN3[i] - aN3[0]))
    else:
        ans2 += abs(aN3[i-1] - aN3[i])

print(max(ans, ans2))

Measured memory_bytes: 10044
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Scan()

	cnt, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}

	sc.Scan()
	nums := strings.Split(sc.Text(), " ")

	var a, b, c int
	result := 0

	for i := 0; i < cnt-2; i++ {
		a, e = strconv.Atoi(nums[i])
		b, e = strconv.Atoi(nums[i+1])
		c, e = strconv.Atoi(nums[i+2])
		if a < b && b < c || a > b && b > c {
			result++
		}
	}

	fmt.Println(result)

}

Measured memory_bytes: 640
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
class Main{
	public static void main(String[] args) {
		InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int a[]=new int[5];
              int ans=0;
              for(int i=0;i<5;i++){
                  a[i]=in.nextInt();
              }
              for(int i=0;i<5;i++){
                  if(a[i]==0){
                      ans=i+1;
                  }
              }
              System.out.println(ans);
          }
      } 

Measured memory_bytes: 35892
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

dic = dict()

def search(n, a, b, c, d):
    # print(n, dic)
    if n == 0:
        return 0
    if n == 1:
        return d
    if n in dic:
        return dic[n]

    ret = n * d

    tgt = n // 2
    ret = min(ret, search(tgt, a, b, c, d) + a + d * abs(tgt * 2 - n))
    tgt = (n + 1) // 2
    ret = min(ret, search(tgt, a, b, c, d) + a + d * abs(tgt * 2 - n))

    tgt = n // 3
    ret = min(ret, search(tgt, a, b, c, d) + b + d * abs(tgt * 3 - n))
    tgt = (n + 2) // 3
    ret = min(ret, search(tgt, a, b, c, d) + b + d * abs(tgt * 3- n))

    tgt = n // 5
    ret = min(ret, search(tgt, a, b, c, d) + c + d * abs(tgt * 5 - n))
    tgt = (n + 4) // 5
    ret = min(ret, search(tgt, a, b, c, d) + c + d * abs(tgt * 5 - n))

    dic[n] = ret
    return ret

def solve():
    N, A, B, C, D = getList()
    dic.clear()
    print(search(N, A, B, C, D))

def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    main()
    # solve()







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

int main() {
	int N;
	string S;
	cin >> N >> S;
	long long r = 0, g = 0, b = 0;
	rep(i, N) {
		if (S[i] == 'R') r++;
		if (S[i] == 'G') g++;
		if (S[i] == 'B') b++;
	}
	long long sum = r * g * b;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			int k = (j - i) + j;
			if (k >= N) break;
			if (S[i] != S[j] && S[i] != S[k] && S[j] != S[k]) sum--;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3572
#define z 1000000
a[z],b[z],n,i=1,x,c;main(){for(;i++<z;)a[i]=i;for(i=0;i++<z;)if(a[i])for(b[x++]=i,c=i;c<z;c+=i)a[c]=0;for(;~scanf("%d",&n);){c=0;while(b[c]<=n&&b[c++]);printf("%d\n",c);}exit(0);}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
    //Brick Break
    //每次 C 都做不出几道, 吃力的不行, 带下标的题目描述看不懂, 那 D 更做不出来了?
    //像是在求最长递增子集?
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        for (int i = 0; i < n; i++) A[i] = sc.nextInt();
        System.out.println(helper(A, n));
        sc.close();
    }

    static int helper(int[] A, int n) {
        int index = 0, count = 0, number = 1;
        boolean flag = false;
        while (index < n) {
            if (A[index] == number) {
                flag = true;
                count++;
                number++;
            }
            index++;
        }
        if (flag) return n - count;
        else return -1;
    }
}


Measured memory_bytes: 65636
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}




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


  ll N ; cin >> N ;
  vector<ll> a;

  ll ans = 0;
  ll now = 0;
  a.pb(0);
  rep(i,N){
    ll inp; cin >> inp;
    a.pb(inp);
    ans += (abs(now-inp));
    now = inp;
  }
  ans += abs(now);
  a.pb(0);
  
  rep(i,N+1){
    if(i == 0 ) continue;
    ll num = ans;
    num -= abs(a[i-1]-a[i]);
    num -= abs(a[i]-a[i+1]);
    num += abs(a[i+1]- a[i-1]);
    
    cout << num << endl;
  } 
  
  
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 2164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

int A, B;

int main () {
  cin >> A >> B;

  int ans = 0;
  for(int i = A; i <= B; i++) {
    ans += (i%10 == i/10000) && ((i/10)%10 == (i/1000)%10);
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    int cnt = 0;
    if (A == B) cnt++;
    if (B == C) cnt++;
    if (C == A) cnt++;
    if (cnt == 1){
        cout << "Yes" << endl;
    } else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


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

	int N; cin >> N;

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

	int next = A[0];
	int ans = 1;
	while(next != 2) {
		next = A[next-1];
		ans++;
		if (ans > pow(10,6)) {
			ans = -1;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
int L[10];

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

    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> L[i];
    }

    int mx = *std::max_element(L, L + N),
        sum = std::accumulate(L, L + N, 0);

    if(mx < sum - mx){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
e = []
for _ in range(M):
  u, v, c = map(int, input().split())
  e.append((u, v, -c))
inf = 10 ** 18
d = [inf] * (N + 1)
d[1] = 0
for _ in range(N - 1):
  for u, v, c in e: d[v] = min(d[v], d[u] + c)
loop = []
for u, v, c in e:
  if d[v] > d[u] + c:
    d[v] = min(d[v], d[u] + c)
    loop.append(v)
if len(loop) == 0:
  print(-d[-1])
  exit(0)
for v in loop: d[v] = -inf
for _ in range(N - 1):
  for u, v, c in e:
    if v == N and (d[v] > d[u] + c): break
    d[v] = min(d[v], d[u] + c)
  else: continue
  break
else: 
  print(-d[-1])
  exit(0)
print("inf")

Measured memory_bytes: 74320