akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;

const int MAX = 30001;
bool isPrime[MAX];
int primes[3250];
int primesSize;

void calcPrimes() {
    fill_n(isPrime, MAX, false);
    isPrime[2] = true;
    primes[0] = 2;
    primesSize = 1;
    for (int i = 3; i < MAX; i += 2) {
        bool add = true;
        for (int j = 0; j < primesSize; j++) {
            if (primes[j] * primes[j] > i) {
                break;
            }
            if (i % primes[j] == 0) {
                add = false;
                break;
            }
        }
        if (add) {
            isPrime[i] = true;
            primes[primesSize++] = i;
        }
    }
}

bool isTriangle(int a, int b, int c) {
    return (abs(a - b) < c) && (c < (a + b));
}

int main() {
    calcPrimes();
    while (true) {
        int t;
        cin >> t;
        if (t == 0) {
            break;
        }
        int res = 0;
        for (int i = 0; i < primesSize; i++) {
            if (primes[i] * 3 > t) {
                break;
            }
            for (int j = i; j < primesSize; j++) {
                if (primes[i] + primes[j] * 2 > t) {
                    break;
                }
                int k = t - primes[i] - primes[j];
                if (isTriangle(primes[i], primes[j], k) && isPrime[k]) {
                    res++;
                }
            }
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 908
#include <bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int N;
    cin>>N;
    int arr[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout<<arr[N-1];
}


Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int x;
	for(int i=1;i<=10000;i++){
		cin>>x;
		if(x==0) break;
		else{
			cout<<"Case "<<i<<": "<<x<<endl;
		}
	}
	return 0;
}

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

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

  long long A_sum = 0;
  for(int i = 0; i < N; i++){
    int a;
    cin >> a;
    A_sum += a;
  }

  cout << ((A_sum >= H)? "Yes": "No") << endl;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;
using ll = long long;
const ll INF = 1010101010;

ll n, m, a, b, add, ans, A[1010101], B[1010101];
string s, str;
char c[1010][1010];
int main() {
	cin >> n;
	cout << (n / 2)*(n - n / 2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long N,i,k,m,M,a;
    cin>>N;
    long long A[N],B[N];
    for(i=0;i<N;i++){
        cin>>A[i];
        B[i]=-1;
    }
    B[0]=A[0];k=0;
    for(i=1;i<N;i++){
        if(A[i]<B[k]+1){
            k++;
            B[k]=A[i];
        }else{
            m=0;M=k;
            while(M-m>1){
                if(A[i]>B[(m+M)/2]){
                    M=(m+M)/2;
                }else{
                    m=(m+M)/2;
                }
            }
            if(A[i]<B[m]+1){
                m++;
            }
            B[m]=A[i];
        }
    }
    k++;
    cout<<k<<endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    string s;  cin >> s;
    if(s[2] == s[3] && s[4] == s[5])  cout << "Yes" << endl;
    else                              cout << "No"  << endl;
	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 

int main() {
    IOS;
    long int n;
    cin>>n;
    string s;
    cin>>s;

    if(n >= 3200)
        cout<<s;
    else
        cout<<"red";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
int main(){
  std::string s;
  std::string t;
  int cnt = 0;
  std::cin >> s >> t;
  for(int i = 0;i<3;i++){
    if(s[i] == t[i]) cnt ++;
  }
  std::cout << cnt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vetcor<ll>
#define vii vector<pii>
#define vll vector<pll>
#define IOS ios_base::sync_with_stdio(false)
using namespace std;
int main(){
	ll n, m, sum = 0;
	cin>>n>>m;
	for(int i = 0; i < m; i++){
		ll a;
		cin>>a;
		sum += a;
	}
	if(sum > n)
		cout<<-1<<endl;
	else
	cout<<n - sum<<endl;
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
 
#define PB push_back
#define MP make_pair
#define ff first
#define ss second
#define ll long long 
#define inf 1000000000
#define iPair pair< ll , ll >
using namespace std;
#define lp(n,i) for(ll i=0;i<n;i++)
#define rlp(n) for(ll i=n-1;i>=0;i--)
#define pq 	priority_queue<int, vector<int> , greater<int> >
 
/*ll pw(ll x, ll  y) ;
ll mi(ll  a) 
{ return pw(a, e-2); } 
 
ll pw(ll x, ll  y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = pw(x, y/2) % e; 
    p = (p * p) % e; 
  
    return (y%2 == 0)? p : (x * p) % e; 
} 
  
  
 bool sortbysec(const pair<int,int> &a,  const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
int mod(string num, int a) 
{ 
    // Initialize result 
    int res = 0; 
  
    // One by one process all digits of 'num' 
    for (int i = 0; i < num.length(); i++) 
         res = (res*10 + (int)num[i] - '0') %a; 
  
    return res; 
} */

int main()
{
ll h,w;
ll en;
en=1000000007;
 cin>>h>>w;
 ll a[h+1][w+1];
   for(ll i=0;i<h+1;i++)
 {
 	for(ll j=0;j<=w;j++)
 	{
 		a[i][j]=0;
	 }
	 
 }
 for(ll i=1;i<h+1;i++)
 {
 	for(ll j=1;j<=w;j++)
 	{
 		char d;
 		 cin>>d;
 		 if(d=='.')a[i][j]=0;
 		 else a[i][j]=-1;
	 }
 }
 a[1][0]=1;a[0][1]=1;
 for(ll i=1;i<=w;i++)
 {
 	if(a[1][i-1]!=-1&&a[1][i]!=-1)a[1][i]+=a[1][i-1];
 
 }
 for(ll i=2;i<=h;i++)
 {	//cout<<a[i][1]<<" ";
 	if(a[i-1][1]!=-1&&a[i][1]!=-1)a[i][1]+=a[i-1][1];
 	//cout<<a[i][1]<<" ";
 }
 for(ll i=2;i<=h;i++)
 {
 	for(ll j=2;j<=w;j++)
 	{
 	if(a[i][j]!=-1){
	 	if(a[i][j-1]!=-1)a[i][j]+=a[i][j-1];
 		a[i][j]%=en;
 		if(a[i-1][j]!=-1)a[i][j]+=a[i-1][j];
 		a[i][j]%=en;
	 }}
 }
 a[h][w]+=en;
 a[h][w]%=en;
 cout<<a[h][w];
  for(ll i=0;i<h+1;i++)
 {
 	for(ll j=0;j<=w;j++)
 	{
 		//cout<<a[i][j]<<" ";
	 }
	 cout<<endl;
 }
	cerr << "\nTime elapsed: " << 1000 * clock()/CLOCKS_PER_SEC << "ms\n";
	return 0;
}
 
 
 
 
 

Measured memory_bytes: 8064
N, M = map(int, input().split())
list = list(map(int, input().split()))

i=0
s=0

while(i<N):
  s+=list[i]
  i+=1

m=s/(4*M)

list.sort(reverse=True)

r="Yes"
j=0

while(j<M):
  if(list[j]<m):
    r="No"
  j+=1
print(r)

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

int n[100100];
int nn,a;
int main()
{
	cin>>nn;
	for(int i=1;i<=nn;i++)
	{
		cin>>a;
		n[a]=i;
	}
	for(int i=1;i<=nn;i++)
	cout<<n[i]<<' ';
	//cout<<endl;
 } 

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    int n, q;
    cin>>n>>q;
    vector<priority_queue<int>> qs(n);
    rep(i, q) {
        int j, t, x;
        cin>>j>>t;
        if (j == 0) {
            cin>>x;
            qs[t].push(x);
        }
        else if (j == 1) {
            if (qs[t].empty()) continue;
            cout<<qs[t].top()<<endl;
        }
        else {
            if (qs[t].empty()) continue;
            qs[t].pop();
        }
    }
}


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

int main(){
  int n, x,count =0;
  cin >> n>>x;
  vector<int> l(n);
  vector<int> d(n+1);
  d[0] = 0;
  for(int i=0; i<n; ++i)cin >> l[i];
  for(int i=1; i<n+1 ; ++i){
    d[i] = d[i-1] + l[i-1];
  }
  for(int i=0; d[i] <= x && i<n+1 ; ++i){
    count++;
  }
  cout << count << endl;
  return 0;
}


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

using namespace std;

int main() {
	string s1, s2, s3;
	cin >> s1;
	cin >> s2;
	cin >> s3;
	printf("%c%c%c\n", toupper(s1[0]), toupper(s2[0]), toupper(s3[0]));
	return 0;	
}


Measured memory_bytes: 256
function main(input) {
  var arr = []
  var input = input.split(" ")
  var result = 0
  input.forEach(function(element) {
  	arr.push(parseInt(element,10))
  })
  delete input
  arr.sort(function(a, b) {
    if (a > b) {
      return 1
    } else {
      return -1
    }
  })
  
  for (var i  = 1; i < arr.length; i++) {
    result += arr[i] - arr[i-1]
  }
  
  console.log(result);
  
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) (flag)?1:0
#define yn(f) cout<<(f?"yes":"no")<<endl
#define Yn(f) cout<<(f?"Yes":"No")<<endl
#define YN(f) cout<<(f?"YES":"NO")<<endl
#define COUT(x) cout<<(x)<<endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

constexpr int MOD=1e9+7;

int main(void){
  int a,b; cin>>a>>b;
  COUT(a*a-b);
}













Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
 
const int maxn = 2e5 + 20;

int cnt, n, k, a[maxn], ans;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		int b;
		cin >> b;
		if (!a[b])
			cnt ++;
		a[b] ++;
	}
	vector<int> v;
	for (int i = 0; i < maxn; i++)
		if (a[i])
			v.pb(a[i]);
	sort (v.begin(), v.end());
	int x = 0;
	while (cnt - x > k)
		ans += v[x++];

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

Measured memory_bytes: 2168
#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<int, int>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

// int main() {
//     ios::sync_with_stdio(false);
//     cin.tie(0);
    
//     ll s;
//     cin >> s;
//     ll y3 = (s+1e9-1)/1e9;
//     ll x3 = 1e9*y3 - s;
//     cout << "0 0 1000000000 1 " << x3 << " " << y3 << endl;
// }

int main(){
	long long s;
	cin>>s;
	
	const int v=1000000000;
	
	int x=(v-s%v)%v;
	int y=(s+x)/v;
	
	cout<<"0 0 1000000000 1 "<<x<<" "<<y<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 
#define PI 3.141592653589793238

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;
typedef gp_hash_table<long int,long int> HashTable;

int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */
   
   long int x,n;
   cin>>x>>n;

   set<long int> s;

   for(long int i = 0; i < n; i++){
     long int val;
     cin>>val;
     s.insert(val);
   }

   for(long int i = 0; i <= 1e10; i++){
     long int minVal = x - i;
     long int maxVal = x + i;
     if(s.find(minVal) == s.end())
      return cout<<minVal,0;
    if(s.find(maxVal) == s.end())
      return cout<<maxVal,0;
   }
  
  return 0;
}

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

using namespace std;

int main() {
	string s;
	cin >> s;
	int ones = 0;
	int zeros = 0;
	int n = (int)s.length();

	for (int i = 0; i < n; i++) {
		if (s[i] == '1') ones++;
		else zeros++;
	}

	cout << min(ones, zeros) * 2;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>

int main(void){
    int n,a,i;

    long int max = -1000000;
    long int min = 1000000;
    long int sum = 0;
    a = 0;
    scanf("%d",&n);
    for(a = 1;a <= n;a++){
        scanf("%d",&i);
        if (i < min) min = i;
        if (i > max) max = i;
        sum +=i;
    }
    printf("%lld %lld %lld\n",min,max,sum);
	return 0;
}

Measured memory_bytes: 600
line = input()
str = list(line)
ans = []
c = 0

for i in str:
    if (i == "1") or (i == "0"):
        ans.append(i)
    elif i == "B":
        if c != 0:
            c -= 1
            del ans[c]
        c -= 1
    c += 1

for i in ans:
    print("".join(i), end = '')

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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }

int n;
ll l[100005], r[100005];
void solve() {
    cin >> n;

    ll left = -inf, right = inf;
    rep(i, n) {
        cin >> l[i] >> r[i];

        ++r[i];
        maxs(left, l[i]);
        mins(right, r[i]);
    }

    ll ans = 0;
    rep(i, n) maxs(ans, max<ll>(0, right - left) + r[i] - l[i]);

    vector<pair<ll, ll>> v(n);
    rep(i, n) { v[i].first = max<ll>(0, r[i] - left); v[i].second = -max<ll>(0, right - l[i]); }
    all(sort, v);

    ll w = inf;
    rep(i, n) {
        v[i].second *= -1;
        if (i != 0) maxs(ans, w + v[i].first);
        mins(w, v[i].second);
    }

    cout << ans << endn;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cmath> 
#include <cctype>

using namespace std;

int main() {
    string a, b;
    cin >> a >> b;
    a += b;
    int num = stoi(a);

    for (int i = 1; i <= 1000; i++) {
        if (num == i * i) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sort(vec) sort(vec.begin(),vec.end())
#define reverse(vec) reverse(vec.begin(),vec.end())
#define unsort(vec); sort(vec);reverse(vec);
#define int long long
long long ans;

int gcd(int x,int y){
	if(y==0) return x;
	else return gcd(y,x%y);
}

int lcm(int x,int y){
	return x*y/gcd(x,y);
}
 
signed main(){
	int n,mi=20;
	cin>>n;
	int a=1;
	while(n>=a*a){
		if(n%a==0){
			int x=a,y=n/a;
			int cnt1=0,cnt2=0;
			for(int i=1;x>=i;i*=10){
				cnt1++;
			}
			for(int i=1;y>=i;i*=10){
				cnt2++;
			}
			cnt1=max(cnt1,cnt2);
			mi=min(mi,cnt1);
		}
		a++;
	}
	cout<<mi<<endl;
}


Measured memory_bytes: 256
n, m, x = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(n)]
ans = 9**9
flag = False

for i in range(2**n):
    cost = 0
    a = [0]*m
    for j in range(n):
        if (i >> j) & 1:
            cost += c[j][0]
            for k in range(m):
                a[k] += c[j][k+1]
    if min(a) >= x:
        flag = True
        ans = min(ans, cost)

print(ans if flag else -1)

Measured memory_bytes: 9208
#include<cstdio>
#include<cstring>
#define mx 1000000
typedef long long LL;
int pri[mx],f[mx];//f[i]荳コi逧?怙蟆冗エ?屏蟄?int num[mx];
bool ispri[mx];
int p = 0;
void Prime()
{
    memset(ispri,true,sizeof(ispri));
    for(int i = 2;i < mx;i++)
    {
        if(ispri[i])pri[p++] = i;
        for(int j = 0;j < p && i*pri[j] < mx;j++)
        {
            int k = pri[j]*i;
            ispri[k] = false;
            //f[k] = pri[j];
            if(i%pri[j] == 0)break;
        }
    }

}
int n;
int ans[mx],tmp;
void pre()
{
    memset(ans,0,sizeof(ans));
    for(int i = 0;i < 1299;i++)
    {
        tmp = pri[i];
        for(int j = i + 1;j < 1299;j++)
        {
            if(tmp > 10000)break;
            ans[tmp]++;
            tmp += pri[j];
        }
    }
}
int main()
{
    Prime();
    pre();
    //for(int i = 0;i <=20;i++)printf("%d\n",pri[i]);
    while(scanf("%d",&n)&&n)
    {
        printf("%d\n",ans[n]);
    }
    return 0;
}

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

int main(){
	int n;
	while(cin>>n,n){
		int table[90005]={};
		
		for(int i=0;i<n;i++){
			int a,b,c;
			scanf("%d:%d:%d",&a,&b,&c);
			table[c+(b*60)+(a*3600)]++;
			scanf("%d:%d:%d",&a,&b,&c);
			table[c+(b*60)+(a*3600)]--;;
			}
			
			int ans=0;
			for(int i=0;i<86401;i++){
				if(0<i)table[i]+=table[i-1];
				if(ans<table[i])ans=table[i];
				}
				cout<<ans<<endl;
		}
		return 0;
	}

Measured memory_bytes: 3392
#include<iostream>

int first, year, n, type, every;
double rate;

int calculate(){
	int a = first, b = 0;
	if(type == 0){
		for(int i=0;i<year;i++){
			b += a * rate;
			a -= every;
		}
		return a + b;
	}
	for(int i=0;i<year;i++){
		a += a * rate - every;
	}
	return a;
}

int main(){
	int m;
	std::cin >> m;
	while(m--){
		std::cin >> first >> year >> n;
		int res = 0;
		for(int i=0;i<n;i++){
			std::cin >> type >> rate >> every;
			res = std::max(res, calculate());
		}

		std::cout << res << std::endl;
	}
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long A, long long B, long long C, long long X, long long Y){
    LL ans = A * X + B * Y;
    ans = min(ans, C * max(X, Y) * 2);
    ans = min(ans, C * X * 2 + max(0LL, Y - X) * B);
    ans = min(ans, C * Y * 2 + max(0LL, X - Y) * A);
    cout << ans << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(A, B, C, X, Y);
    return 0;
}


Measured memory_bytes: 256
use std::io::{stdout, Write, BufWriter};

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{ a: String, b: String }
    let n: i32 = (a + &b).parse().unwrap();
    let maybe_n = (n as f64).sqrt().floor() as i32;
    if maybe_n.pow(2) == n || (maybe_n + 1).pow(2) == n {
        println!("Yes")
    } else {
        println!("No")
    }
}


Measured memory_bytes: 4352
import sys

input=sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()


def II(): return int(input())


def MI(): return map(int,input().split())


def MF(): return map(float,input().split())


def LI(): return list(map(int,input().split()))


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))


# rstrip().decode('utf-8')


def main():
	a,b,c,d=MI()
	print(max(a*c,a*d,b*c,b*d))
	

	

if __name__=="__main__":
	main()


Measured memory_bytes: 9256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;

namespace abc112_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            if(n == 1){
                WriteLine("Hello World");
            }else{
                int a = int.Parse(Console.ReadLine());
                int b = int.Parse(Console.ReadLine());
                WriteLine(a+b);
            }
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>

using namespace std;

int main() {
    int r, g, b, n; cin >> r >> g >> b >> n;
    int ans = 0;
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
            int d = n - r*i - g*j;
            if (d < 0) {
                break;
            }
            if (d % b == 0) {
                ans += 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

#ifdef LOCAL
#include "contest.h"
#else
#define error(args...) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}
string slow(string s) {
    int i = 0;
    int d = 1;
    LL count = 0;
    while(i >= 0 && i < s.size()) {
        count++;
        if(s[i] == 'A') {
            s[i] = 'B';
            d *= -1;
        } else {
            s[i] = 'A';
        }
        i += d;
    }
    error(count);
    return s;
}
string solve(string s, int K) {
    int N = s.size();
    vector<int> state(N);
    REP(i, N) state[i] = (s[i] == 'B' ? 1 : 0);
    int i = 0;
    int b = 0;
    REP(_, K) {
        if(state[i] ^ b) { // B
            i = (i == N-1 ? 0 : i+1);
            b ^= 1;
        } else {
            state[i] ^= 1;
        }
    }
    string res;
    for(int d = 0; d < N; d++) {
        int idx = (i + d) % N;
        res += (state[idx] ^ b ? "B" : "A");
    }
    return res;
}
int main(){
    iostream_init();
    int N, K;
    cin >> N >> K;
    string s;
    cin >> s;
    const int MAX_ITER = 1e8;
    if(K > MAX_ITER) {
        cout << ((K - MAX_ITER) % 2 == 0 ? solve(s, MAX_ITER) : solve(s, MAX_ITER-1)) << endl;
    } else {
        cout << solve(s, K) << endl;
    }
    return 0;
}



Measured memory_bytes: 1944
#!/usr/bin/env python3
import sys

def check(x, lst, k):
    cnt = 0
    for l in lst:
        cnt += (l - 1) // x
    if cnt  <= k:
        return True
    else:
        return False
    

def main():
    input = sys.stdin.readline
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    ng = 0
    ok = 10 ** 9
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid, a, k):
            ok = mid
        else:
            ng = mid
    print(ok)


if __name__ == '__main__':
    main()


Measured memory_bytes: 103176
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int a,b;
  cin >> a >> b;
  cout << (a%2==1&&b%2==1?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
//	cin>>n>>k;
//	cout<<n<<k<<endl;
//string S[100];

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

	bool flag=false;
	if (moji.size()==2){
		if (moji[0]==moji[1]){
			cout<<"1 2"<<endl;
			flag=true;

		}
	}else{

		int now,middle,end;
		for(int i=0;i<moji.size()-2;i++){
			now=i;middle=i+1;end=i+2;
			if (moji[now]==moji[middle]){
				cout<<now+1<<" "<<end+1<<endl;
				flag=true;break;
			}else if(moji[now]==moji[end]){
				cout<<now+1<<" "<<end+1<<endl;
				flag=true;break;
			}else if(moji[middle]==moji[end]){
				cout<<now+1<<" "<<end+1<<endl;
				flag=true;break;
			}
		}

	}
	if (flag==false){
		cout<<-1<<" "<<-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
  int n;
  scanf("%d",&n);
  int c=0;
  for(int i=1;i<=n;i++) {
    int a,b;
    scanf("%d %d",&a,&b);
    if(a==b) {
      c++;
    }else {
      c=0;
    }
    if(c==3) {
      printf("Yes");
      return 0;
    }
  }
  printf("No");
  return 0;
}

Measured memory_bytes: 3820
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
n = int(input())
d=[]
for i in range(n):
    d.append(int(input()))


def bingo(i):
    if i in d:
        return True
    else:
        return False

if bingo(a[0]) and bingo(a[1]) and bingo(a[2]):
    print('Yes')
elif bingo(b[0]) and bingo(b[1]) and bingo(b[2]):
    print('Yes')
elif bingo(c[0]) and bingo(c[1]) and bingo(c[2]):
    print('Yes')
elif bingo(a[1]) and bingo(b[1]) and bingo(c[1]):
    print('Yes')
elif bingo(a[0]) and bingo(b[0]) and bingo(c[0]):
    print('Yes')
elif bingo(a[2]) and bingo(b[2]) and bingo(c[2]):
    print('Yes')
elif bingo(a[2]) and bingo(b[1]) and bingo(c[0]):
    print('Yes')
elif bingo(a[0]) and bingo(b[1]) and bingo(c[2]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cswork
{
    class Program
    {
        class Scanner
        {
            string[] s;
            int i;

            char[] cs = new char[] { ' ' };

            public Scanner()
            {
                s = new string[0];
                i = 0;
            }

            public string next()
            {
                if (i < s.Length) return s[i++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();

                s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
                i = 0;
                return next();
            }

            public int nextInt()
            {
                return int.Parse(next());
            }

            public long nextLong()
            {
                return long.Parse(next());
            }

            public double nextDouble()
            {
                return double.Parse(next());
            }
        }

        public Program() { }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }

        public static List<long> GeneratePrime(long max)
        {
            long prime;
            double sqrtMax = Math.Sqrt(max);
            var primeList = new List<long>();

            List<long> searchList = new List<long>();
            for (long i = 2; i <= max - 1; i++)
            {
                searchList.Add(i);
            }

            do
            {
                prime = searchList.First();
                primeList.Add(prime);
                searchList.RemoveAll(n => n % prime == 0);
            } while (prime < sqrtMax);

            primeList.AddRange(searchList);

            return primeList;
        }

        void Omame()
        {
            cin = new Scanner();
            long A = cin.nextLong();
            long B = cin.nextLong();
            long K = cin.nextLong();

            if(A >= K)
            {
                Console.WriteLine((A - K) + " " + B);
            }
            else
            {
                Console.WriteLine(0 + " " + Math.Max(0,(A + B -K)));
            }
        }
    }
}


Measured memory_bytes: 13268
cnt=0
def merge_sort(S):
    l=len(S)
    mid=int(l/2)
    Left=S[0:mid]
    Right=S[(mid):l]
    global cnt
    
    if l>=2:
        merge_sort(Left) and merge_sort(Right)
    

    Left.append(float('inf'))
    Right.append(float('inf'))

    p=0
    q=0
    for i in range(l):
        if Left[p]<Right[q]:
            S[i]=Left[p]
            p+=1
        else:
            S[i]=Right[q]
            q+=1
    if l!=1 :
        cnt+=l
    
    return S


n=int(input())
S=list(map(int,input().split()))
merge_sort(S)
print(*S)
print(cnt)


Measured memory_bytes: 61652
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007

int main(){
    int n;
    cin>>n;
    vector<int64_t> p(n);
    rep(i,n){
        cin>>p[i];
    }
    int sum=0;
    int tmp;
    rep(i,n-1){
        if(p[i]==i+1){
            tmp=p[i];
            p[i] = p[i+1];
            p[i+1] = tmp;
            sum++; 
        }
    }
    if(p[n-1]== n){
        sum++;
    }
    cout << sum<<endl;
}

Measured memory_bytes: 1024
class node():
    def __init__(self, id, parent, child, depth, type_t):
        self.id = id
        self.parent = parent
        self.child = child
        self.depth = depth
        self.type_t = type_t


def add(t, d, i, parent, depth):
    type_t = 'internal node'
    if d[i][1] == 0:
        type_t = 'leaf'
    if depth == 0:
        type_t = 'root'

    child = []
    if not d[i][1] == 0:
        child = d[i][2:]
    new_node = node(i, parent, d[i][2:], depth, type_t)
    t.append(new_node)
    for c in child:
        add(t, d, c, i, depth + 1)


N = int(input())
tree = []
data = [[] for i in range(N)]
for i in range(N):
    data[i] = [int(i) for i in input().split()]

data.sort(key=lambda x: x[0])

root = [True for i in range(N)]
for d in data:
    for c in d[2:]:
        root[c] = False

for i in range(N):
    if root[i]:
        add(tree, data, i, -1, 0)

tree.sort(key=lambda x: x.id)

for t in tree:
    print(f'node {t.id}: parent = {t.parent}, depth = {t.depth}, {t.type_t}, {t.child}')



Measured memory_bytes: 50320
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
int checksnake(string, int);

int main(void) {
  int n, len;
  char snake[200];
  int type;
  cin >> n;
  for(int i = 0 ; i < n ; i++) {
    scanf("%s", snake);
    len = strlen(snake);
    type = checksnake(snake, len);
    if(type == 1) cout << 'A' << endl;
    else if(type == 2) cout << 'B' << endl;
    else if(type == 3) cout << "NA" << endl;
    for(int a = 0 ; a < 200 ; a++) {
      snake[a] = 0;
    }
    len = 0;
  }
  return 0;
}

int checksnake(string snake, int len) {
  int flag1=0, flag2=0, flag3=0;
  int true_flag=0, true_flag2=0, true_flag3=0;
  int cnt1=0, cnt2=0;
  
  if(true_flag == 0) {
    for(int i = 0 ; i < len - 1 ; i++) {
      if(snake[i] != '>' && snake[i] != '#' && snake[i] != '=' && snake[i] != '\'') { true_flag2 = 1; break; }
      if(snake[i] == '>' && snake[i+1] == '\'') flag2 = 1;
      if(snake[i] == '=' && flag1 == 0 && flag2 == 1) {cnt1++; flag3 = 1; }
      if(snake[i] == '=' && flag1 == 1 && flag2 == 1) {cnt2++; flag3 = 1; }
      if(snake[i] == '#' && flag2 == 1 && flag3 == 1) flag1 = 1;
      //cout << cnt1 << ' ' << cnt2 << endl;
    }
    if(snake[len-1] == '~' && cnt1 == cnt2 && flag2 == 1 && flag3 == 1 && true_flag2 == 0) {
      return 1;
      true_flag = 1;
    }
  }
  
  if(true_flag == 0) {
    for(int i = 0 ; i < len - 2 ; i++) {
      if(snake[i] != '>' && snake[i] != '^' && snake[i] != '=' && snake[i] != 'Q') { true_flag3 = 1; break; }
      if(snake[i] == '>' && snake[i+1] == '^') flag3 = 1;
      if(snake[i] == 'Q' && snake[i+1] == '=' && flag3 == 1) flag1 = 1;
    }
    if(snake[len-2] == '~' && snake[len-1] == '~'  && flag1 == 1 && flag3 == 1 && true_flag3 == 0) {
      return 2;
      true_flag = 1;
    }
  }

  if(true_flag == 0 || true_flag2 == 1 || true_flag3 == 1) {
    return 3;
  }
}

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

int main(){
    long long m, n;
    cin >> m >> n;
    vector<int> a(n);
    long long sum = 0;

    rep(i, n){
        cin >> a.at(i);
        sum += a.at(i);
    }

    long long ans = m - sum;
    

    if(ans >= 0){
        cout << ans << endl;
        } else 
        cout << "-1" << endl;

}


Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.C_Challenge
{
    class ABC_056
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            long x = long.Parse(Console.ReadLine());
            long min = 0, max = 100000;
            while (max - min != 1)
            {
                long mid = (min + max) / 2;
                long sum = (mid * (mid + 1)) / 2;
                long sum2 = ((mid - 1) * mid) / 2;
                //Console.WriteLine(max);
                //Console.WriteLine(mid);
                //Console.WriteLine(min);
                if (sum2 < x && x <= sum)
                {
                    Console.WriteLine(mid);
                    return;
                }
                else if (x <= sum2)
                {
                    max = mid;
                }
                else if (sum < x)
                {
                    min = mid;
                }
            }
            Console.WriteLine(min);
        }
    }
}

Measured memory_bytes: 13140
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std;
const int MAXN = 400005;
int head[MAXN], lazy[MAXN];
struct EDGE
{
	int _next, to;
};
EDGE edge[MAXN];
int _count;
int ans[MAXN];
void Add_Line(int a, int b)
{
	_count++;
	edge[_count]._next = head[a];
	edge[_count].to = b;
	head[a] = _count;
}

void DFS(int NowNode,int fa,int temp)
{
	ans[NowNode]=temp+lazy[NowNode];
	for(int i=head[NowNode];i;i=edge[i]._next)
	{
		int NextNode=edge[i].to;
		if(NextNode==fa)
		{
			continue;
		}
		DFS(NextNode,NowNode,temp+lazy[NowNode]);
	}
}

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);
	for(int i = 1; i < N; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		Add_Line(a, b);
		Add_Line(b, a);
	}
	for(int i = 1; i <= M; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		lazy[a] += b;
	}
	DFS(1,0,0);
	for(int i=1;i<=N;i++)
	{
		printf("%d ",ans[i]);
	}
	return 0;
}



Measured memory_bytes: 17920
z[9][101][101];n,m,t,c,b;char*f="%d%d%d%d\n";main(a){for(;scanf(f+4,&n,&m)*n;){for(memset(z,9,9e4);n--;z[0][a][b]=z[0][b][a]=c)scanf(f,&a,&b,&c,&t),z[1][a][b]=z[1][b][a]=t;for(t=++m;--t;)for(c=m;--c;)for(b=m;--b;)for(a=2;a--;)z[a][b][c]=fmin(z[a][b][c],z[a][b][t]+z[a][t][c]);for(scanf(f+6,&n);n--;printf(f+6,z[a][b][c]))scanf(f+2,&c,&b,&a);}}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int x;
    cin >> x;
    vector<bool> dp(x + 1, false);
    int c[] = {100, 101, 102, 103, 104, 105};
    dp[0] = true;
    for (int i = 1; i <= x; ++i)
        for (int j = 0; j < 6; ++j)
            if (i - c[j] >= 0 && dp[i - c[j]])
                dp[i] = true;
    cout << dp[x];
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

using ld=long double;

vector<long long int> divisor(long long int n) {

	vector<long long int> res;
	for (long long int i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			res.push_back(i);
			if (i * i != n) res.push_back(n / i);
		}
	}
	sort(begin(res), end(res));
	return res;
}
int main() {	
	int N;cin>>N;
	vector<int>ts;
	for (int i = 0; i < N; ++i) {
		int t;cin>>t;
		ts.push_back(t);
	}
	int tmax=*max_element(ts.begin(),ts.end());
	int ans=0;
	auto divs=divisor(tmax);
	for (int i = 0; i < N; ++i) {
		int t=ts[i];
		ans+=*lower_bound(divs.begin(),divs.end(),t)-t;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  long long int n,a,b; cin >> n >> a >> b;
  vector<int> h(n);
  for(int i=0;i<n;i++) cin >> h[i];
  long long int left=0,right = 1000000001;
  a = a - b;
  while(right - left > 1){
  	long long int mid = (right + left) / 2;
    long long int bd = mid * b;
    long long int c=0;
  	for(int i=0;i<n;i++){
    	long long int th = h[i] - bd;
      	if(th > 0) c += (th / a) + (th%a ? 1 : 0);
    }
  	if(mid >= c) right = mid;
    else left = mid;
  }
  cout << right << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

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

	string ans;
	for (int i = 0; S[i]; i++)
	{
		if (S[i] == '0')
			ans += '0';
		if (S[i] == '1')
			ans += '1';
		if (S[i] == 'B' && ans.size() != 0)
			ans = ans.substr(0, (int)ans.size()-1);
	}
	cout << ans << endl;
}



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

const int N = 100005;

int n;
multiset <int> conn[N];
map <int,int> e[N];

void erase(int u, int v) {
	multiset<int>::iterator it = conn[u].find(v);
	conn[u].erase(it);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= 2 * n - 2; ++i) {
		int u, v; cin >> u >> v;
		e[u][v]++; e[v][u]++;
		conn[u].insert(v); conn[v].insert(u);
	}
	queue < pair<int,int> > q;
	for (int i = 1; i <= n; ++i) {
		for (map<int,int>::iterator it = e[i].begin(); it != e[i].end(); ++it) {
			if (it->first > i && e[i][it->first] >= 2) q.push(make_pair(i, it->first));
		}
 	}

 	while(!q.empty()) {
 		int u = q.front().first, v = q.front().second; q.pop();
 		if (conn[u].empty() || conn[v].empty()) continue;
 		if (e[u][v] > 2) return printf("NO\n"), 0;
 		if (conn[u].size() < conn[v].size()) swap(u, v);
 		erase(u, v); erase(u, v); e[u][v] -= 2;
 		erase(v, u); erase(v, u); e[v][u] -= 2;

 		for (auto w : conn[v]) {
 			erase(w, v); e[w][v]--; e[v][w]--;
 			conn[w].insert(u); e[w][u]++;
 			conn[u].insert(w); e[u][w]++;
 			if (e[u][w] >= 2) q.push(make_pair(u,w));
 		}
 		conn[v].clear();
 	}

 	for (int i = 1; i <= n; ++i) if (!conn[i].empty()) return printf("NO\n"), 0;
 	printf("YES\n");
}

Measured memory_bytes: 48512
H,W=list(map(int, input().split()))
N=int(input())
A=list(map(int, input().split()))
L=[0]*(H*W)
n=0
for i in range(N):
  a=A[i]
  L[n:n+a]=[i+1]*a
  n+=a
for i in range(H):
  S=L[i*W:(i+1)*W]
  if i%2==1:
    S=S[::-1]
  print(*S)

Measured memory_bytes: 74308
n = int(input())
a = list(map(int, input().split()))
num = [0] * 100010
ans = 0
for i in range(n):
    num[a[i]] += 1
    ans += a[i]

q = int(input())
for _ in range(q):
    b,c = map(int, input().split())
    ans -= num[b] * b
    ans += num[b] * c
    print(ans)
    num[c] += num[b]
    num[b] = 0


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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  map<int, int> f;
  for(int x=1;x<=100;x++){
    for(int y=1;y<=100;y++){
      for(int z=1;z<=100;z++){
        int n = x*x+y*y+z*z+x*y+y*z+z*x;
        f[n]++;
      }
    }
  }
  int n;cin>>n;
  for(int i=1;i<=n;i++){
    cout<<f[i]<<endl;
  }
  
  return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    ll N, M;
    cin >> N >> M;
    vector<ll> sum;
    sum.push_back(0);
    unordered_map<ll, ll> mp;
    mp[0]++;
    for(int i = 0; i < N; i++) {
        ll in;
        cin >> in;
        sum.push_back((sum.back() + in) % M);
        mp[sum.back()]++;
    }
    ll ans = 0;
    ll val;
    for(int i = 0; i < sum.size(); i++) {
        val = sum[i];
        //cout << i << " " << val << endl;
        ans += mp[val] * (mp[val] - 1) / 2;
        mp[val] = 0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4256
from itertools import product

x1 = int(input())
x2 = input()

R_i = [i for i, x in enumerate(x2) if x == "R"]
G_i = [i for i, x in enumerate(x2) if x == "G"]
B_i = {i for i, x in enumerate(x2) if x == "B"}

R = len(R_i)
G = len(G_i)
B = len(B_i)

xs = map(sorted, product(R_i, G_i))

s = 0
for a in xs:
    k = a[1]*2 - a[0]  # 2j-i
    if k in B_i:
        s +=1
    i = a[0]*2 - a[1]  # 2j-k
    if i in B_i:
        s +=1
    j = (a[0] + a[1]) / 2
    if j.is_integer():
        j = int(j)
        if j in B_i:
            s +=1
print(R*G*B - s)

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

int main(int argc, char *argv[])
{
    char input[4];
	cin >> input;

	if ((input[0] == input[1]) ||
		(input[1] == input[2]) ||
		(input[0] == input[2]))
		cout << "No\n";
	else
		cout << "Yes\n";
	

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		int n;
		cin>>n;
		int a[n];
		int s=0;
		rep(i,0,n){
			cin>>a[i];
			s+=a[i];
		}
		int ans=0;
		rep(i,0,n){
			ans+=a[i]*(s-a[i]);
		}
		cout<<ans/2;
	}   
}     

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

#define int long long
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);

int32_t main(){
	fast;
	int n,k;
	cin >> n >> k;
	
	int ans = k;
	ans *= pow(k-1,n-1);
	cout << ans;
}







Measured memory_bytes: 256