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

typedef long long ll;

int main() {
  std::string S;
  std::cin >> S;

  int k = S.length();

  int cnt = 0;
  for(auto c : S) {
    if(c == 'o') ++cnt;
    if(cnt >= 8) break;
  }

  if(15 - k + cnt >= 8) {
    std::cout << "YES" << std::endl;
  } else {
    std::cout << "NO" << std::endl;
  }
}


Measured memory_bytes: 256
N = int(input())
S = input()
S = S[:N] + S[N:][::-1]

import collections

def count(S):
    n = len(S)
    T = []
    for i in range(2**n):
        r, b = '', ''
        for j in range(n):
            if i >> j & 1:
                r += S[j]
            else:
                b += S[j]
        T.append((r, b))
    return collections.Counter(T)

A = count(S[:N])    
B = count(S[N:])

ans  = 0
for a in A:
    if a in B:
        ans += A[a]*B[a]

print(ans)

Measured memory_bytes: 214952
#include <bits/stdc++.h>
#define optimize ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long
#define ld long double
#define vi vector<int>
#define si set<int>
#define vc vector<char>
#define vs vector<string>
#define vb vector<bool>
#define vll vector<ll>
#define vd vector<double>
#define lb(v,x) lower_bound(v.begin(), v.end(), x) - v.begin()
#define up(v,x) upper_bound(v.begin(), v.end(), x) - v.begin() - 1
#define pb push_back
#define lp(i,a,b) for(int i = a ; i <= b ; i ++)
#define rlp(i,a,b) for(int i = b ; i >= a ; i --)
#define a_sort(v) sort(v.begin(), v.end())
#define d_sort(v) sort(v.rbegin(), v.rend())
#define vin(v) for(auto &x : v) cin >> x
#define vout(v) for(auto x : v) cout << x << ' ' ; cout << endl
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pi 3.14159265358979323846264338327950
using namespace std ;
// #define debug

const int MOD = 1E9 + 7 ;
const int N = 1E5 ;

int main() {
    #ifdef debug
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif // debug
    optimize

    int n ; cin >> n ;
    int ac = 0 , wa = 0 , tle = 0 , re = 0 ;
    lp(i, 1, n) {
        string s ; cin >> s ;
        if(s == "AC") ac ++ ;
        if(s == "WA") wa ++ ;
        if(s == "TLE") tle ++ ;
        if(s == "RE") re ++ ;
    }
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n", ac, wa, tle, re) ;
}


Measured memory_bytes: 3712
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <time.h>
#define _USE_MATH_DEFINES
#define LL unsigned long long
#define UN unsigned
using namespace std;
const double PI = acos(-1.0);

int max_num(int ary[], int length) {
	int max = ary[0];
	for (int i = 1; i < length; i++)
		if (max < ary[i]) max = ary[i];
	return max;
}

int max_ord(int ary[], int length) {
	int max;
	max = max_num(ary, length);
	for (int i = 0; i < length; i++) {
		if (ary[i] == max) return i;
	}
	return -1;
}

int min_num(int ary[], int length) {
	int min = ary[0];
	for (int i = 1; i < length; i++)
		if (min > ary[i]) min = ary[i];
	return min;
}

int min_ord(int ary[], int length) {
	int min;
	min = min_num(ary, length);
	for (int i = 0; i < length; i++) {
		if (ary[i] == min) return i;
	}
	return -1;
}

LL gcm(LL a, LL b) {
	LL result = a;
	LL k = 0;
	LL n = b;
	do {
		k = result % n;
		result = n;
		n = k;
	} while (k != 0);
	return result;
}

LL lcm2(LL a, LL b) {
	LL g;
	g = gcm(a, b);
	return a*b / g;
}

LL lcm(LL a, LL b) {
	LL g, n;
	g = gcm(a, b);
	n = gcm(a, g);
	a = a / n;
	b = b / (g / n);
	return a*b;
}

LL lcm_n(LL t[], LL n) {
	LL l;
	l = t[0];
	for (LL i = 0; i < n; i++) {
		l = lcm(l, t[i]);
	}
	return l;
}

int main() {
	LL n, t[100];
	cin >> n;
	for (LL i = 0; i < n; i++) cin >> t[i];
	
	cout << lcm_n(t, n) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N, A, B;
	char S[100001];
	scanf("%d %d %d", &N, &A, &B);
	scanf("%s", S);
	int num_clear = 0, num_abroad = 0;
	for(int i = 0; i < N; i++){
		if(S[i] == 'a'){
			if(num_clear < A + B){
				printf("Yes\n");
				num_clear++;
			}else{
				printf("No\n");
			}
		}else if(S[i] == 'b'){
			num_abroad++;
			if(num_clear < A + B && num_abroad <= B){
				printf("Yes\n");
				num_clear++;
			}else{
				printf("No\n");
			}
		}else{
			printf("No\n");
		}
	}
	return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;
 
 
public class Main {    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h1 = sc.nextInt();
        int m1 = sc.nextInt();
        int h2 = sc.nextInt();
        int m2 = sc.nextInt();
        int k = sc.nextInt();
        int hurry = (h2 * 60 + m2) - (h1 * 60 + m1 )- k;
        sc.close();
        System.out.println(hurry);
    }
}

Measured memory_bytes: 35820
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<char,int>;


int main(){
   int n, a, b, c;
   cin >> n >> a >> b >> c;
   vector<int> L(n);
   rep(i, n)cin >> L[i];
   sort(ALL(L));
   ll res = INF;
   //+-1のやつだけもやる必要あり

   do{
       ll cost = 0;
       vector<int> sums(n, 0);
       rep(i, n){
           if(i == 0)sums[i] = L[i];
           else sums[i] = sums[i - 1] + L[i];
       }
       rep(i, n){
           REP(j, i+1, n-1){
               REP(k, j+1, n-1){
                   ll sum_a = sums[i], sum_b = sums[j] - sums[i], sum_c = sums[k] - sums[j];
                   cost = 10 * (k - 2);
                   cost += abs(a - sum_a) + abs(b - sum_b) + abs(c - sum_c);
                   res = min(res, cost);
               }
           }
       }
   }while(next_permutation(ALL(L)));
   cout << res << endl;
}



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

int main(){
  int i,j,n,m,dp[301][3],v[300][3],cost[300],max;
  string str;
  while(cin >> n >> m){
    for(i=0;i<=m;i++){
      for(j=0;j<3;j++) dp[i][j] = 0;
    }
    for(i=0;i<n;i++){
      getline(cin,str);
      getline(cin,str);
      cin >> cost[i] >> v[i][0] >> v[i][1] >> v[i][2];
    }

    for(i=0;i<=m;i++){
      for(j=0;j<n;j++){
	for(int k=0;k<3;k++){
	  if(i + cost[j] > m) continue;
	  //dp[i+cost[j]][k] = max(dp[i+cost[j]][k],dp[i][k]+v[i][k]);
	  if(dp[i+cost[j]][k] < dp[i][k]+v[j][k]) dp[i+cost[j]][k] = dp[i][k] + v[j][k];
	}
      }
    }

    max = 0;
    for(i=0;i<=m;i++){
      for(j=0;j<3;j++){
	if(max < dp[i][j]) max = dp[i][j];
      }
    }

    cout << max << endl;

  }
  return 0;
}

Measured memory_bytes: 932
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        int[] K = new int[N];
        int[] f = new int[M];
        for(int i=0; i<N; i++) {
            K[i] = Integer.parseInt(sc.next());
            int a = 0;
            for(int j=0; j<K[i]; j++) {
                a = Integer.parseInt(sc.next());
                f[a-1]++;
            }
        }
        int count = 0;
        for(int x : f) {
            if(x == N) {
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

string s, t;
ll cnts[26], cntt[26];
int main() {
    cin>>s>>t;

    REP(i, 0, s.size()){
        cnts[s[i]-'a']++;
    }
    REP(i, 0, t.size()){
        cntt[t[i]-'a']++;
    }

    sort(cnts, cnts+26);
    sort(cntt, cntt+26);

    bool flag=true;
    REP(i, 0, 26){
        if(cnts[i]!=cntt[i]){
            flag=false;
            break;
        }
    }
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <string>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define eb emplace_back
#define in insert
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define FOR(i, n, x) for(int i = x; i < n; i++)
#define OUT(a, e) FOR(i, e, 0) cout << a[i] << ' '
#define OUTV(a) for(auto i : a) cout << i << ' ';
#define maxim(a, n, mx) FOR(i, n, x)mx = max(mx, a[i]);
using namespace std;
const int N = 1e5 + 5, mod = 1e9 + 7;

int main() {
    fast;
    map<int, int> amn;
    amn[1] = 300000;
    amn[2] = 200000;
    amn[3] = 100000;
    int ans = 0;
    int x, y; cin >> x >> y;
    ans = amn[x] + amn[y];
    if(x == y && x == 1)ans += 400000;
    cout << ans;
    return 0;
}



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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

const int mod = 1000000007;

int main() {
  ll n, ans = 0;
  cin >> n;
  vector<ll> a(n), b(n + 1);
  rep(i, n) {
    cin >> a[i];
    b[i + 1] = (b[i] + a[i]) % mod;
  }

  for (int i = 1; i < n; i++) {
    ans += (b[i] * a[i]) % mod;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6424
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

int main(void){
  ll h, w;
  cin >> h >> w;
  
  vector<string> a(h);
  for (int i = 0; i < h; i++){
    cin >> a[i];
  }


  for (int i = 0; i < 201; i++){
    for (int j = 0; j < h; j++){
      int ok = 1;
      for (int k = 0; k < w; k++){
        if (a[j][k] == '#')
          ok = 0;
      }
      if (ok){
        h--;
        for (int k = j; k < h; k++){
          a[k] = a[k+1];
        }
      }
    }

    for (int j = 0; j < w; j++){
      int ok = 1;
      for (int k = 0; k < h; k++){
        if (a[k][j] == '#')
          ok = 0;
      }
      if (ok){
        w--;
        for (int k = j; k < w; k++){
          for (int l = 0; l < h; l++){
            a[l][k] = a[l][k+1];
          }
        }
      }
    }
  }


  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      cout << a[i][j];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
//Int mod = 1e6+3;

int main() {
    Int n;
    cin >> n;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    vector<pair<Int, Int>> res;
    if (a.front() >= 0) {
        Int mi = a.front();
        for (Int i = 1; i < n - 1; i++) {
            res.emplace_back(mi, a[i]);
            mi -= a[i];
        }
        res.emplace_back(a.back(), mi);
        dump(a.back() - mi);
    }
    else if (a.back() < 0) {
        Int mi = a.back();
        for (Int i = n - 2; i >= 0; i--) {
            res.emplace_back(mi, a[i]);
            mi -= a[i];
        }
        dump(mi);
    }
    else {
        vector<Int> b, c;
        for (Int i = 0; i < n; i++) {
            if (a[i] >= 0) {
                b.emplace_back(a[i]);
            }
            else {
                c.emplace_back(a[i]);
            }
        }
        sort(b.begin(), b.end());
        sort(c.begin(), c.end());
        Int bs = (Int)b.size();
        Int cs = (Int)c.size();
        for (Int i = 0; i < (Int)b.size() - 1; i++) {
            res.emplace_back(c[(Int)c.size() - 1], b[i]);
            c[(Int)c.size() - 1] -= b[i];
        }
        for (Int i = 0; i < cs; i++) {
            res.emplace_back(b[bs - 1], c[i]);
            b[bs - 1] -= c[i];
        }
        dump(b.back());
    }
    for (auto v : res) cout << v.fi << " " << v.se << endl;
    return 0;
}

Measured memory_bytes: 5260
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++)
    cin >> A[i];
  sort(A.begin(), A.end());
  cout << A[N-1] - A[0] << endl;
  return 0;
}


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

int main()
{
	int K;
	scanf("%d", &K);
	std::vector<int> dist(K, 1 << 30);
	using pii = std::pair<int, int>;
	std::priority_queue<pii, std::vector<pii>, std::greater<pii>> dij;
	dij.push({1, 1});
	dist[1] = 1;
	while (!dij.empty())
	{
		auto num{dij.top()};
		dij.pop();
		if (num.first > dist[num.second]) continue;
		if (num.second == 0) break;
		if (num.first + 1 < dist[(num.second + 1) % K])
		{
			dij.push({num.first + 1, (num.second + 1) % K});
			dist[(num.second + 1) % K] = num.first + 1;
		}
		if (num.first < dist[num.second * 10 % K])
		{
			dij.push({num.first, num.second * 10 % K});
			dist[num.second * 10 % K] = num.first;
		}
	}
	printf("%d\n", dist[0]);

	return 0;
}

Measured memory_bytes: 1276
n=int(input())
a=list(map(int,input().split()))

a.sort()
a.reverse()

alice,bob=0,0

if n%2 == 0:
    for i in range(int(n/2)):
        alice += a[2*i]
        bob += a[2*i+1]
else:
    for i in range(int((n+1)/2)):
            alice += a[2*i]
            bob += a[2*i+1] if 2*i+1<len(a) else 0

print(alice-bob)


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

#include <atcoder/math>
using namespace atcoder;

int main() {
    ll T;
    cin >> T;
    rep(i, T) {
        int n, m, a, b;
        cin >> n >> m >> a >> b;
        cout << floor_sum(n, m, a, b) << endl;
    }
   return 0;
}

Measured memory_bytes: 3608
//Night's template
//orzakyrt
#include <bits/stdc++.h>
#define R register
#define LL long long
#ifdef __DEBUG__
	#define Debug (fprintf(stderr,"orzyrt\n"),fflush(stderr))
	#define debug(__a...) (fprintf(stderr,__a),fflush(stderr))
	#define setfile(__a) ('orzyrt')
	#define Compile(__a) system("g++ "__a".cpp -lm -o "__a)
#else
	#define Debug ('orzyrt')
	#define debug(__a...) ('orzyrt')
	#define setfile(__a) freopen(__a".in","r",stdin);freopen(__a".out","w",stdout)
	#define Compile(__a) ('orzyrt')
#endif
template<class TT>inline TT Max(R TT a,R TT b){return a<b?b:a;}
template<class TT>inline TT Min(R TT a,R TT b){return a<b?a:b;}
template<class TT>inline TT Abs(R TT a){return a<0?-a:a;}
template<class TT>inline TT cmin(R TT &a,R TT b){(b<a)&&(a=b);}
template<class TT>inline TT cmax(R TT &a,R TT b){(a<b)&&(a=b);}
using namespace std;
template<class TT>inline void read(R TT &x){
	x=0;R bool f=false;R char c=getchar();
	for(;c<48||c>57;c=getchar())f|=(c=='-');
	for(;c>47&&c<58;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	(f)&&(x=-x);
}
//end template

namespace Night{
	const int maxn = 200010;
	int n;
LL addl,addr,ans;
	priority_queue<LL>le; 
	priority_queue<LL,vector<LL>,greater<LL> >ri;
	void pushl(R LL x){le.push(x-addl);}
	void pushr(R LL x){ri.push(x-addr);}
	int main(){
		read(n);
		for(R int l,r,len;n--;){
			read(l);read(r);
			addr+=(len=r-l);
			pushl(r);pushr(r);
			for(R LL tpl,tpr;(tpl=le.top()+addl)>(tpr=ri.top()+addr);){
				ans+=tpl-tpr;
				le.pop();ri.pop();
				pushl(tpr);pushr(tpl);
			}
			addl-=len;
		}
		cout<<ans;
		return 0;
	}
}
int main(){
	return Night::main();
}


Measured memory_bytes: 2036
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>

typedef long double ld;
typedef long long ll;

using namespace std;

int main() {
	string s;
	int k;

	cin >> k >> s;
	if (s.length() > k) {
		for (int i = 0; i < k; i++) {
			cout << s[i];
		}
		cout << "...";
	} else {
		cout << s;
	}
	
	return 0;
}


Measured memory_bytes: 3616
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

n, x = [int(i) for i in input().split()]
xa = [int(i) for i in input().split()]
ans = abs(x - xa[0])

for i in range(n):
    num = abs(x - xa[i])
    ans = gcd(num, ans)
    
print(ans)

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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

ll fib[100];

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

    // input
    ll N;
    cin >> N;

    fib[0] = 1;
    fib[1] = 1;
    FOR(i, 2, 50){
        fib[i] = fib[i-1] + fib[i-2];
    }

    p(fib[N]);
    
    return 0;
}


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

string s,t,ans;
map<string,ll> dp[100][100][2];

void solve(ll index1,ll index2,ll c){
    if(dp[index1][index2][c].count(s) != 0){
        return ;
    }
    if(index1 == s.size() and index2 == t.size()){
        ans = min(s,ans);
        return ;
    }
    if(index1 == s.size()){
        dp[index1][index2][c][s] = 1;
        return ;
    }
    if(index2 == t.size()){
        if(s[index1] == '?'){
            s[index1] = 'a';
            solve(index1+1,index2,c);
            s[index1] = '?';
        }else{
            solve(index1+1,index2,c);
        }
        dp[index1][index2][c][s] = 1;
        return;
    }
    if(c == 0){
         if(s[index1] == '?' or s[index1] == t[index2]){
            char p = s[index1];
            s[index1] = t[index2];
            solve(index1+1,index2+1,1);
            s[index1] = p;
            if(p == '?'){
                s[index1] = 'a';
                solve(index1+1,index2,c);
                s[index1] = '?';
            }else{
                solve(index1+1,index2,c);
            }
        }else{
            solve(index1+1,index2,c);
        }
    }else{
            if(s[index1] == '?' or s[index1] == t[index2]){
                char p = s[index1];
                s[index1] = t[index2];
                solve(index1+1,index2+1,1);
                s[index1] = p;
            }else{
                 dp[index1][index2][c][s] = 1;
                 return;
            }
    }

    dp[index1][index2][c][s] = 1;
    return;
}

int main(){
    cin >> s >> t;
    for(ll i = 0;i < s.size();i++){
        ans += "zz";
    }
    solve(0,0,0);
    if(ans.size() > s.size()){
        cout << "UNRESTORABLE";
    }else{
        cout << ans;
    }
}


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

int f[10010010];
vector<int> prime(10010010, 1);
map<int, int> res;

void sieve_of_eratosthenes(int n) {
    prime[0] = prime[1] = 0;
    for (int i = 2; i * i <= n; i++) {
        if (prime[i] == 1) {
            for (int j = i * i; j <= n; j += i) prime[j] = i;
        }
    }
}

void prime_factorize(ll n) {
    if (n <= 1) return;
    if (prime[n] == 1) {
        res[n]++;
        return;
    }
    res[prime[n]]++;
    prime_factorize(n / prime[n]);
}

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    sieve_of_eratosthenes(n);
    for (int i = 1; i <= n; i++) {
        res = map<int, int>();
        prime_factorize(i);
        int c = 1;
        for (auto p : res) c *= p.second + 1;
        ans += 1LL * i * c;
    }
    cout << ans << endl;
}

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

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

int main() {
  ll a, b;
  cin >> a >> b;
  ll d = gcd(a, b);
  vector<pair<ll, int>> f;
  for (ll i = 2; i * i <= d; i++) {
    if (d % i) continue;
    f.emplace_back(i, 0);
    while (d % i == 0) {
      d /= i;
      f.back().second++;
    }
  }
  if (d != 1) f.emplace_back(d, 1);
  // rep(i, f.size()) cerr << f[i].first << endl;
  cout << f.size() + 1 << endl;
  return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main()
{
	int num;
	cin >> num;
	vector<int> a(num + 1);
	for (int idx = 1; idx < num + 1; ++idx)
	{
		uint32_t ret = 0;
		cin >> a[idx];
	}

	vector<int> b(num + 1, 0);
	vector<int> c;

	for (int idx = num; idx >= 1; --idx)
	{
		// 倍数の個数を取得
		int tmp = 0;
		for (int idx2 = 1; idx2 <= num && idx * idx2 <= num; ++idx2)
		{
			tmp += b[idx * idx2];
		}

		// 違っていれば入れる
		if (tmp % 2 != a[idx])
		{
			c.push_back(idx);
			b[idx] = 1;
		}
	}

	// 結果
	cout << c.size() << endl;
	if (c.size())
	{
		REP(i, c.size())
		{
			cout << c[i] << " ";
			cout << endl;
		}

	}

	return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

const double EPS = 1e-10;

// ツ点
typedef complex<double> P;

namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b)-EPS : imag(a) < imag(b)-EPS;
  }
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
  L(){}
};

P line_cross(const L& l, const L& m) {
  double num = cross(m[1]-m[0], m[0]-l[0]);
  double denom = cross(m[1]-m[0], l[1]-l[0]);
  return P(l[0] + (l[1]-l[0])*num/denom);
}

bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

typedef pair<double, int> pdi;
int main() {
  int N;
  cin >> N;
  while(N--) {
    int ax,ay,bx,by;
    L nw;
    cin >> ax>>ay>>bx>>by;
    nw = L(P(ax,ay),P(bx,by));
    int n;
    cin >> n;
    vector<pdi> v;
    REP(i,n) {
      int x1,y1,x2,y2;
      cin >> x1>>y1>>x2>>y2;
      L l = L(P(x1,y1),P(x2,y2));
      bool o, s;
      cin >> o>> s;

      if (intersectSS(nw, l)) {
        v.push_back(pdi(abs(line_cross(nw,l)-P(ax,ay)), (!o)^s));
      }
    }
    sort(ALL(v));
    int res = 0;
    REP(i, v.size()-1) {
//      cout << v[i].first << endl;
      if (v[i].second^v[i+1].second) res++;
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 940
n=int(input())
a=list(map(int,input().split()))

#箱の状態を記録しておく配列
box=[0]*n


for i in range(n):
  num=n-i

  #まず割って、その数より大きい倍数がいくつあるか探る
  baisu=n//num

  if baisu==1:
    box[num-1]=a[num-1]

  #1～baisu倍の箱の状態を調べる。
  temp=0
  for j in range(2,baisu+1):
    temp+=box[num*j-1]
  box[num-1]=abs(temp%2-a[num-1])

ans=[]
for i in range(n):
  if box[i]==1:
    ans.append(i+1)

if sum(ans)!=0:
  print(len(ans))
  print(*ans)
else:
  print("0")


Measured memory_bytes: 14132
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
      int n,total;
      double aa,a,m;
      
      Scanner sc = new Scanner(System.in);
      while (sc.hasNext()) {
        n = sc.nextInt();
        if (n == 0) break;
        int s[] = new int[n];
        total = 0;
        aa = 0;
        a = 0;
        for (int i=0; i<n; i++) {
          s[i] = sc.nextInt();
          total += s[i];
        }
        m = total / (double)n;
        for (int i=0; i<n; i++) {
          aa += (s[i] - m) * (s[i] - m);
        }
        System.out.println(Math.sqrt(aa / n));
      }
    }
}


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

int main(){
  int N,M;
  int d[2*M];
  cin >> N >> M;
  for(int i = 0;i < 2*M;i++){
    cin >> d[i];
  }
  
  int num[100] = {0};
  for(int j = 0;j < 2*M;j++){
    num[d[j]]++;
  }
  for(int k = 1;k <= N;k++){
    cout << num[k] << endl;
  }
 
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    if (b % a == 0)
      System.out.println(a+b);
    else
      System.out.println(b-a);
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "tst"
using namespace std;
const ll N = 3e5 + 9;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;

ll x,y,a,b,c,R[N],G[N],C[N],i,j;
vector<ll> res;
bool lf(ll x,ll y){
    return x > y;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>x>>y>>a>>b>>c;
    for (i = 1;i <= a;i++) cin>>R[i]; sort(R + 1,R + a + 1,lf);
    for (i = 1;i <= b;i++) cin>>G[i]; sort(G + 1,G + b + 1,lf);
    for (i = 1;i <= c;i++) cin>>C[i]; sort(C + 1,C + c + 1,lf);
    for (i = 1;i <= x;i++) res.push_back(R[i]);
    for (i = 1;i <= y;i++) res.push_back(G[i]);
    sort(res.begin(),res.end(),lf);
    //for (auto i : res) cout<<i<<" "; return 0;
    i = res.size() - 1; j = 1;
    while(true){
        if (i < 0||C[j] <= res[i]) break;
        res[i] = C[j];
        j++; i--;
    }
    ll sum = 0;
    for (auto i : res) sum += i;
    cout<<sum;
}


Measured memory_bytes: 7664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
int main(){
    string s;
    LL ans, s_len;
    ans = 700;
    cin >> s;
    s_len = s.length();
    vector<string> ans_ary(s.length());
    for (int i = 0; i < s.length(); i++) {
//        cout << s.substr(i,1) << endl;
        ans_ary[i] = s.substr(i,1);
        if(ans_ary[i] == "o") ans += 100;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=LLONG_MAX;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n;
  cin>>n;
  vector<int> d(n);
  REP(i,n){
    cin>>d[i];
  }
  sort(d.begin(),d.end());
  
  int l,r;
  l = d[n/2-1];
  r = d[n/2];
  
  int ans;
  ans = r-l;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
function Main(input) {
  var line = input.split('\n')
  var n = line[0]
  var s = line[1]
  if(n%2==1) {
    console.log('No')
    return
  }
  if(s.slice(0,n/2) == s.slice(n/2)) {
    console.log('Yes')
    return
  }
  console.log('No')
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
n = int(input())
w = [input() for _ in range(n)]

flg = True
if len(set(w)) < len(w):
    flg = False
else:
    for i in range(1, n):
        if w[i - 1][-1] == w[i][0]:
            pass
        else:
            flg = False
            break
print('Yes' if flg else 'No')

Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using ll = int64_t;
using Graph = vector<vector<int> >;
const ll M = 1000000007;

int main(){
    int n;
    cin >> n;
    pair<int,int> p[n];
    for(int i=0;i<n;i++){
        cin >> p[i].first >> p[i].second;
    }

    vector<int> num;
    vector<double> dist; 
    for(int i=0;i<n;i++) num.push_back(i);

    //for(int i=0;i<n;i++) cout << num.at(i);
    //cout << endl;
    
    do{
        double l=0;
        for(int i=1;i<n;i++){
            l = pow(pow((p[num[i-1]].first-p[num[i]].first),2)+pow((p[num[i-1]].second-p[num[i]].second),2),0.5);
            //cout << fixed << setprecision(8) << l << endl;
            dist.push_back(l);
        }
    }while(next_permutation(num.begin(),num.end()));

    double sum=0;
    for(int i=0;i<dist.size();i++) sum += dist.at(i);
    /*cout << endl;
    cout << sum << endl;
    cout << dist.size() << endl;
    cout << endl;*/
    int f=1;
    for(int i=1;i<=n;i++) f*=i; 
    cout << fixed << setprecision(8) << sum/f << endl;
}

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

int a[3], ans = 0;

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

	sort(a, a + 3);
	for (int i = 0; i < 2; i++) {
		ans += (a[2] - a[i]) / 2;
		a[i] += (a[2] - a[i]) / 2 * 2;
	}

	sort(a, a + 3);
	if (a[2] == a[1] && a[1] != a[0]) {
		ans += 2;
	}
	else if (a[2] != a[1] && a[1] == a[0]) {
		ans += 1;
	}

	cout << ans << endl;
}

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

using namespace std;

const int MAX_K = 1e5 + 5;

int root [MAX_K];

int find (int u) {
  if (root[u] != u) {
    root[u] = find(root[u]);
  }
  return root[u];
}

void merge (int u, int v) {
  u = find(u);
  v = find(v);

  root[u] = v;
}

int dist [MAX_K];

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

  while (k % 2 == 0) {
    k /= 2;
  }

  while (k % 5 == 0) {
    k /= 5;
  }

  for (int i = 0; i < k; i++) {
    root[i] = i;
  }

  for (int i = 0; i < k; i++) {
    merge(i, (i * 10) % k);
  }

  vector<int> ps;
  int cur = 1;
  do {
    if (cur == 0) {
      cout << 1 << endl;
      return 0;
    }
    
    ps.push_back(cur);
    cur *= 10;
    cur %= k;
  } while (cur != 1);
 
  for (int i = 0; i < k; i++) {
    dist[i] = 1 << 30;
  }

  queue<int> Q;
  Q.push(1);
  dist[1] = 1;
    
  while (!Q.empty()) {
    int p = Q.front();
    Q.pop();

    for (int q : ps) {
      if ((p + q) % k == 0) {
        cout << dist[p] + 1 << endl;
        return 0;
      }

      int nxt = find((p + q) % k);
      if (dist[nxt] > dist[p] + 1) {
        dist[nxt] = dist[p] + 1;
        Q.push(nxt);
      }
    }
  }
}


Measured memory_bytes: 1404
#include <cstdio>
#include <iostream>
#include <unordered_map>
#include <string>
using namespace std;

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

    if( s[2] == s[3] && s[4] == s[5] )
        printf("Yes\n");
    else
        printf("No\n");

}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
	char color_pattern[100001];
	scanf("%s", color_pattern);

	int length = strlen(color_pattern);
	int hamming_distance_a = 0; // the hamming distance to 0 1 0 1...
	int hamming_distance_b = 0; // the hamming distance to 1 0 1 0...
	
	int i;
	for(i = 0; i < length; i++)
	{
		if(i % 2 == 0) {
			if(color_pattern[i] == '1') {
				hamming_distance_a++;
			} else {
				hamming_distance_b++;
			}
		}
		else {
			if(color_pattern[i] == '1') {
				hamming_distance_b++;
			} else {
				hamming_distance_a++;
			}
		}
	}

	int ans;
	ans = hamming_distance_a < hamming_distance_b ?
		hamming_distance_a : hamming_distance_b;
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<iomanip>
#include<sstream>
#include<cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
typedef long long int ll;
typedef long double ld;
const ll inf = (1LL << 60);
const int MOD = 1000000007;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
int n, m, k,d[100],sum = 0;
int sunuke[100];
int main() {
    cin >> n >> k;
    Fill(sunuke, 0);
    rep(i, k) {
        cin >> d[i];
        rep(j, d[i]) {
            cin >> m;
            sunuke[m - 1]++;
        }
    }
    rep(i, n) {
        if (sunuke[i] == 0) sum++;
    }cout << sum << endl;
}

Measured memory_bytes: 3596
s=list(input())
t=list(input())
s.reverse()
t.reverse()
c=0
if len(s)<len(t):
    print("UNRESTORABLE")
    exit()
for i in range(len(s)-len(t)+1):
    if c!=0:
        break
    ss=s[i:i+len(t)]
    f=True
    for j in range(len(t)):
        if ss[j]!=t[j] and ss[j]!="?":
            f=False
    if f:
        s[i:i+len(t)]=t
        c+=1
for i in range(len(s)):
    if s[i]=="?":
        s[i]="a"
if c:
    s.reverse()
    print("".join(s))
else:
    print("UNRESTORABLE")


Measured memory_bytes: 38256
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int N;
	cin >> N;
	vector<int> a(N);
	REP(i, N) cin >> a[i];
	int res = INT_MAX;
	for (int i = -100;i <= 100;i++) {
		int sum = 0;
		REP(j, N) {
			int tmp = i - a[j];
			sum += tmp * tmp;
		}
		res = min(res, sum);
	}
	cout << res << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include <map>
#include<queue>
#include<climits>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef queue<int> IntQueue;
//typedef std::pair<ll, int> pair;



void solve(){
  ll A,B,K;
  cin>>A>>B>>K;
  if (A>=K){
    cout<<A-K<<' '<<B<<endl;
    return;
  }
  else if (B>=(K-A)){
    cout<<0<<' '<<B-(K-A)<<endl;
    return;
  }
  else{
    cout<<0<<' '<<0<<endl;
    return;
  }
 
}

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


Measured memory_bytes: 256
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)

using namespace std;

inline void inp( int &n ) { 
	n=0;    int ch=getcx();int sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

inline void inp1( LL &n ) { 
	n=0;    LL ch=getcx();LL sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

/* Modulo exponentiation */
LL power(LL base, LL exp, LL ans) {
	if(!exp) return ans % MOD;
	if(exp&1) ans = (ans * base) % MOD;
	return power((base * base) % MOD, exp>>1, ans);
}

int main() {
	
	int n, k, i;
	LL seq[MAX];
	cin>>n>>k;
	
	LL ans = k;
	seq[k] = 1;
	
	for(i=k-1;i>0;i--) {
		int q = k/i;
		LL temp = power(q, n, 1);
		for(int j=2*i;j<=k;j+=i) {
			temp = (temp - seq[j] + MOD) % MOD;
		}
		seq[i] = temp;
		ans = (ans + (seq[i] * i) % MOD) % MOD;
	}
	
	cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 4344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

bool cmp(pii a,pii b){
	return a.first<b.first;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;cin >> n >> k;
	vector<pii> a(n);
	rep(i,n) cin >> a.at(i).first >> a.at(i).second;
	sort(a.begin(),a.end(),cmp);
	ll sum=0;
	rep(i,n){
		sum+=a.at(i).second;
		if(sum>=k){
			cout << a.at(i).first << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

ll N;
vec cost(10);
map<ll, ll> m;
ll f (ll a) {
    if (m.count(a)) return m[a];
    ll ret = inf;
    if (a < ret / cost[0]) ret = a * cost[0];
    for (ll k : {2, 3, 5}) {
        // cout << a << " " << k << "\n";
        chmin(ret, f(a/k) + cost[k] + abs(a/k*k-a) * cost[0]);
        chmin(ret, f((a+k-1)/k) + cost[k] + abs((a+k-1)/k*k-a) * cost[0]);
    }

    m[a] = ret;
    return ret;
}

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

    ll T;
    cin >> T;
    while (T--) {
        cin >> N >> cost[2] >> cost[3] >> cost[5] >> cost[0];
        m.clear();
        m[0] = 0;
        m[1] = cost[0];

        cout << f(N) << "\n";

    }
}

Measured memory_bytes: 4356
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b;
	cin>>a>>b;
	for(int j =0 ; j<a;j++)
	{
		if(j==0)
			cout<<string(b+2,'#')<<endl;
		cout<<'#';
		for(int i = 0; i<b; i++)
		{
			char c;
			cin>>c;
			cout<<c;
		}
		cout<<'#'<<endl;
		if(j==a-1)
			cout<<string(b+2,'#');
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin >> k;
    vector<int> g(k, -1);
    rep(i, 0, k) {
        if (i % k != (i * 10) % k) g[i] = (i * 10) % k;
    }
    vector<ll> val(k, (ll)9e18);
    vector<bool> was(k);
    deque<pair<int, int>> dq;
    val[1] = 1;
    dq.emplace_front(1, 0);
    while (!dq.empty()) {
        pair<int, int> p = dq.front();
        int v = p.first;
        dq.pop_front();
        if (was[v]) continue;
        was[v] = true;
        if (g[v] != -1 && val[g[v]] > val[v]) {
            val[g[v]] = val[v];
            dq.emplace_front(g[v], 0);
        }
        if (val[(v + 1) % k] > val[v] + 1) {
            dq.emplace_back((v + 1) % k, 1);
            val[(v + 1) % k] = val[v] + 1;
        }
    }
    cout << val[0] << endl;
    return 0;
}


Measured memory_bytes: 1920
A, B, C = map(int, input().split())
evens = [A%2 == 0, B%2 == 0, C%2 == 0]
even_c = sum(evens)
if even_c == 3 or even_c == 0:
    m = max(A, B, C)
    print(((m-A)+(m-B)+(m-C))//2)
elif even_c == 2:
    a = A+1 if A%2 == 0 else A
    b = B+1 if B%2 == 0 else B
    c = C+1 if C%2 == 0 else C
    m = max(a, b, c)
    print((((m-a)+(m-b)+(m-c))//2)+1)
elif even_c == 1:
    a = A+1 if A%2 != 0 else A
    b = B+1 if B%2 != 0 else B
    c = C+1 if C%2 != 0 else C
    m = max(a, b, c)
    print((((m-a)+(m-b)+(m-c))//2)+1)


Measured memory_bytes: 3064
// abc135a:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

#define upto(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define downto(i,s,e,d) for(int i=(s);i>(e);i-=(d))
#define in(x) cin>>(x)
#define out(x) cout<<(x)
#define oute(x) cout<<(x)<<endl

void p1(vi a){
  upto(i,0,a.size(),1) cout<<a[i]<<",";
}
void p2(vvi &x){
  for(auto v: x){
    cout<<"["; p1(v); cout<<"]\n";
  }
}

int main(){
  int a;in(a);
  int b;in(b);
  // oute(a);//////
  // oute(b);//////

  int c = min(a,b);
  int d = max(a,b);

  upto(k,c,d+1,1){
    if(abs(c-k)==abs(d-k)){
      oute(k);
      return 0;
    }
  }
  oute("IMPOSSIBLE");

}

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

int main() {

//	freopen("readin.txt", "r", stdin);

	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b == c && a % 2 == 0) {
		puts("-1");
		return 0;
	}
	int cc = 0;
	while (!(a % 2 || b % 2 || c % 2)) {
		int ta = a, tb = b, tc = c;
		a = tb / 2 + tc / 2;
		b = ta / 2 + tc / 2;
		c = tb / 2 + ta / 2;
		cc++;
	}
	cout << cc << endl;

	return 0;
}


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


Measured memory_bytes: 2140
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 1e4 + 10;
int H, N;
int A[MAX], B[MAX];
int dp[MAX]; // dp[i] := i 減らすことが出来る最小の消費量

int main(void) {
    cin >> H >> N;
    REP(i, N) {
        cin >> A[i] >> B[i];
    }

    fill(dp, dp + MAX, INF);
    dp[0] = 0;
    REP(i, H) {
        if (dp[i] == INF) continue;
        REP(j, N) {
            chmin(dp[min(i + A[j], H)], dp[i] + B[j]);
        }
    }

    cout << dp[H] << endl;
}


Measured memory_bytes: 384
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, a, b = map(int, input().split())

    mi = a * (n - 1) + b
    ma = b * (n - 1) + a
    print(max(0, ma - mi + 1))


if __name__ == '__main__':
    resolve()


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

typedef long long ll;

int main(){
    using namespace std;
    int N, W;
    cin >> N;
    cin >> W;

    vector<int> weight(N);
    vector<int> value(N);

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

    vector<vector<ll>> dp(N + 1);

    dp[0] = vector<ll>(W + 1);
    for(int i = 0;i < N;i++){
        dp[i + 1] = vector<ll>(W + 1);

        for(int j = 0;j < W + 1;j++){
            if(j < weight[i]){
                dp[i + 1][j] = dp[i][j];
            }else{
                dp[i + 1][j] 
                = max(dp[i][j - weight[i]] + value[i], dp[i][j]);
            }
        }
    }
    
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 82368
#include <stdio.h>
#include <math.h>
#include <stdlib.h>


int 
main(){
	long int x[200000],max,min;
	max=-pow(10,9);//min[0]=-pow(10,9);
	long int i,n;
	scanf("%ld",&n);
	for(i=0;i<n;i++){
		scanf("%ld",&x[i]);
	}
	for(i=0;i<n;i++){
		if(i==0)min=x[i];
		else{
			
			if(max<x[i]-min)max=x[i]-min;
			if(min>x[i])min=x[i];
		}
		//printf("%d<min%ld>\n",i,MM);//min[i]);
	}
	

	printf("%ld\n",max);
 return 0;
}


Measured memory_bytes: 3348
#include<iostream>
#include<vector>
#include<cstring>
#include<queue>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstdlib>
#include <clocale>
#include<cmath>
#include<sstream>
#include<set>
#include<stack>
using namespace std;
const int INF=0x3f3f3f3f;
const int MX=1e4+10;
typedef long long ll;
typedef pair<int ,int> p;
int main(){
	int n;
	string s[MX],t;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>s[i];
	cin>>t;
	int ll=1,rr=1;
	for(int i=1;i<=n;i++){
		int l=0,r=0;
		string x=s[i];
		for(int j=0;j<x.size();j++)
			if(s[i][j]=='?')x[j]='z';
		if(x>=t)r=1;
		for(int j=0;j<x.size();j++)
			if(s[i][j]=='?')x[j]='a';
		if(x<=t)l=1;
		if(r&&l)rr++;
		else if(l)ll++,rr++;
	}
	for(int i=ll;i<=rr;i++)cout<<i<<" \n"[i==rr];
    //system("pause");
    return 0;
}

Measured memory_bytes: 1024