akhauriyash/Code-Regression huggingface dataset:
#include <climits>
#include <cmath>
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
using namespace std;
int main(int, char**)
{
	int d;
	long g;
	cin >> d >> g;
	vector<int> p(d), c(d);
	for (int i = 0; i < d; ++i)
	{
		cin >> p[i] >> c[i];
	}

	int min_count = INT_MAX;
	for (int i = 0; i < (1 << d); ++i)
	{
		long total = 0;
		int count = 0;
		for (int j = 0; j < d; ++j)
		{
			if ((i >> j) & 1)
			{
				total += p[j] * 100 * (j + 1) + c[j];
				count += p[j];
			}
		}

		if (total < g)
		{
			for (int j = d - 1; j >= 0; --j)
			{
				if ((i >> j) & 1)	continue;
				for (int k = 0; k < p[j]; ++k)
				{
					if (total >= g)		break;
					total += 100 * (j + 1);
					++count;
				}
			}
		}
		if (min_count > count)
		{
			min_count = count;
		}
	}
	cout << min_count << endl;
}


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

int a[300][300], b[300][300];

int main(){
	int n;
	scanf("%d", &n);
	f(i, 0, n)f(j, 0, n)scanf("%d", a[i] + j), b[i][j] = a[i][j];
	f(k, 0, n)f(i, 0, n)f(j, 0, n)a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
	f(i, 0, n)f(j, 0, n)if (a[i][j] != b[i][j] || i == j && a[i][j] != 0) { printf("-1\n"); return 0; }
	
	ll an = 0;
	f(i, 0, n)f(j, 0, n){
		bool ok = true;
		f(k, 0, n)if (i != k && j != k && a[i][k] + a[k][j] == a[i][j]) { ok = false; break; }
		if (ok)an += a[i][j];
	}
	printf("%lld\n", an >> 1);
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 10000000
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int t=0;
  while(1){
    int tmp = (60*t+c) % (a+b);
    if(tmp<=a) {
      cout << 60*t+c << endl;
      break;
    }
    t++;
    if(t==INF){
      cout << -1 << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3104
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main() {
  int n;
  readf (" %d", &n);
  auto a = new int[n];
  foreach (t; 0 .. n) {
    readf (" %d", &a[t]);
  }
  sort (a);
  auto m = a[n-1];
  int best = -1;
  foreach (i; 0 .. n) {
    if ( abs (m - 2 * a[i]) < abs (m - 2 * best)) {
      best = a[i];
    }
  }
  writeln (m, " ", best);
}


Measured memory_bytes: 2556
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;

int main(void) {

  int n, q;
  cin >> n >> q;

  int s, t, x, d;
  vector< pair<int, pair<int, int> > > event(2 * n + q);
  rep(i, n) {
    cin >> s >> t >> x;
    event[2 * i].first = s - x;
    event[2 * i].second.first = -1;
    event[2 * i].second.second = x;
    event[2 * i + 1].first = t - x - 1;
    event[2 * i + 1].second.first = 1;
    event[2 * i + 1].second.second = x;
  }
  rep(i, q) {
    cin >> d;
    event[2 * n + i].first = d;
    event[2 * n + i].second.first = 0;
    event[2 * n + i].second.second = i;
  }
  sort(event.begin(), event.end());

  vector<int> ans(q);
  set<int> cm;
  rep(i, 2 * n + q) {
    int a = event[i].first;
    int b = event[i].second.first;
    int c = event[i].second.second;
    if (b == -1) cm.insert(c);
    if (b ==  1) cm.erase(c);
    if (b ==  0) {
      int e = *(cm.begin());
      if (cm.empty()) e = -1;
      ans[c] = e;
    }
  }
  rep(i, q) cout << ans[i] << endl;

  return 0;
}
    


Measured memory_bytes: 18432
import sys
from string import digits

def main():
    n, s = sys.stdin.read().split()

    res = []
    for i in digits:
        x = s.find(i)
        if x == -1:
            continue
        for j in digits:
            y = s.find(j, x+1)
            if y == -1:
                continue
            for k in digits:
                z = s.find(k, y+1)
                if z == -1:
                    continue
                res.append((i, j, k))

    print(len(res))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3772
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main() {
  long long n,ans=0;
  cin >> n;
  string s;
  map<string,int> m;
  for(int i=0; i<n; i++) {
    cin >> s;
    sort(s.begin(),s.end());
    ans+=m[s];
    m[s]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 11136
/*
Sharif Hasan - CSE, PUST
Dec 29, 2019 12: 00 PM 
*/
#include<bits/stdc++.h>
#define br cout<<"\n"

/*STL definations*/
#define pb push_back

#define FOR(i,n) for(i=0;i<n;i++)
#define FROM(a,i,n) for(i=a;i<n;i++)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

/*Main function*/
int main()
{
string a,b;
cin>>a>>b;
cout<<b<<a;br;

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T > void read(T &t) {
	char ch=getchar();
	while (ch<'0'||ch>'9') ch=getchar();
	t=0;
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9');
}
typedef long long ll;
const ll INF=1LL<<50;
const int mx=3000;
int n,sz;
map<ll,int> M;
map<ll,int> cnt;
ll ans;
bool ip[3010];
vector<int> p;
void init() {
	memset(ip,1,sizeof(ip));
	ip[0]=ip[1]=0;
	for (int i=2;i<=mx;i++)
		if (ip[i]) {
			p.push_back(i);
			for (int j=i*i;j<=mx;j+=i)
				ip[j]=0;
		}
	sz=p.size();
}
ll solve(ll x) {
	for (ll i=0;i<sz;i++) {
		ll t=p[i]*p[i]*p[i];
		if (t>x) break;
		while (x%t==0) x/=t;
	}
	return x;
}
ll S(ll x) {
	ll l=1,r=100000;
	while (l<r) {
		ll mid=(l+r+1)>>1;
		if (mid*mid<=x) l=mid;
		else r=mid-1;
	}
	return l;
}
ll T(ll x) {
	ll A=1,B=1;
	for (ll i=0;i<sz;i++) {
		if (p[i]*p[i]*p[i]>x) break;
		int ss=0;
		while (x%p[i]==0) {
			x/=p[i]; ss++;
		}
		if (ss==1) A*=p[i]; else if (ss==2) B*=p[i];
	}
	ll tmp=S(x);
	if (tmp*tmp==x) B*=tmp;
	else A*=x;
	ll res=A*B;
	if (res>INF/A+1) res=INF; else res*=A;
	return res;
}

int main() {
	//freopen("2.txt","r",stdin);
	init();
	read(n);
	for (int i=1;i<=n;i++) {
		ll x; read(x);
		x=solve(x);
		//printf("%lld\n",x);
		M[x]++;
	}
	ans=0;
	for (map<ll,int>::iterator it=M.begin();it!=M.end();it++) {
		ll x=it->first;
		if (cnt[x]) continue;
		ll t=T(x);
		if (x!=t) ans+=max(it->second,M[t]);
		else ans++;
		cnt[t]++;
	}
	printf("%lld\n",ans);
	return 0;
}
 

Measured memory_bytes: 20864
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main(){
	int k;
	cin >> k;
	if(k%2) cout << (k/2) * (k+1)/2 << endl;
	else cout << (k/2) * (k/2) << endl;
	return;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
//#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>


template< typename flow_t >
struct Dinic {
  const flow_t INF;

  struct edge {
    int to;
    flow_t cap;
    int rev;
    bool isrev;
  };

  vector< vector< edge > > graph;
  vector< int > min_cost, iter;

  Dinic(int V) : INF(numeric_limits< flow_t >::max()), graph(V) {}

  void add_edge(int from, int to, flow_t cap) {
    graph[from].emplace_back((edge) {to, cap, (int) graph[to].size(), false});
    graph[to].emplace_back((edge) {from, 0, (int) graph[from].size() - 1, true});
  }

  bool bfs(int s, int t) {
    min_cost.assign(graph.size(), -1);
    queue< int > que;
    min_cost[s] = 0;
    que.push(s);
    while(!que.empty() && min_cost[t] == -1) {
      int p = que.front();
      que.pop();
      for(auto &e : graph[p]) {
        if(e.cap > 0 && min_cost[e.to] == -1) {
          min_cost[e.to] = min_cost[p] + 1;
          que.push(e.to);
        }
      }
    }
    return min_cost[t] != -1;
  }

  flow_t dfs(int idx, const int t, flow_t flow) {
    if(idx == t) return flow;
    for(int &i = iter[idx]; i < graph[idx].size(); i++) {
      edge &e = graph[idx][i];
      if(e.cap > 0 && min_cost[idx] < min_cost[e.to]) {
        flow_t d = dfs(e.to, t, min(flow, e.cap));
        if(d > 0) {
          e.cap -= d;
          graph[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  flow_t max_flow(int s, int t) {
    flow_t flow = 0;
    while(bfs(s, t)) {
      iter.assign(graph.size(), 0);
      flow_t f = 0;
      while((f = dfs(s, t, INF)) > 0) flow += f;
    }
    return flow;
  }

  void output() {
    for(int i = 0; i < graph.size(); i++) {
      for(auto &e : graph[i]) {
        if(e.isrev) continue;
        auto &rev_e = graph[e.to][e.rev];
        cout << i << "->" << e.to << " (flow: " << rev_e.cap << "/" << e.cap + rev_e.cap << ")" << endl;
      }
    }
  }
};



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

  int v,e;
  cin>>v>>e;

  Dinic<int> g(v);
  rep(i,e){
    int a,b,c;
    cin>>a>>b>>c;
    g.add_edge(a,b,c);
  }

  cout<<g.max_flow(0,v-1)<<endl;

}


Measured memory_bytes: 3268
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        s: chars,
        t: chars
    }

    let mut cans = vec![];
    for i in 0..s.len()-t.len()+1 {
        let mut is_ok = true;
        for j in 0..t.len() {
            let k = i + j;
            if !(s[k] == t[j] || s[k] == '?') {
                is_ok = false;
                break;
            }
        }
        if is_ok {
            let mut s2 = s[..].to_vec();
            for j in 0..t.len() {
                s2[j+i] = t[j];
            }
            for j in 0..s.len() {
                if s2[j] == '?' {
                    s2[j] = 'a';
                }
            }
            cans.push(s2);
        }
    }
    if cans.len() == 0 {
        println!("UNRESTORABLE");
    } else {
        cans.sort();
        println!("{}", cans[0] .iter().cloned().collect::<String>());
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define MAX_N 100000

struct UnionFind{
    ll par[MAX_N]; // 親
    ll rank[MAX_N]; // 木の深さ
    ll siz[MAX_N]; // 素集合のサイズ

    // n要素で初期化
    void init(ll n){
        for(ll i=0;i<n;i++){
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }

    // 木の根を求める
    ll root(ll x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = root(par[x]);
        }
    }

    // xとyの属する集合を併合
    bool unite(ll x, ll y){
        x = root(x);
        y = root(y);
        if(x==y) return false; // 併合失敗
        if(rank[x] < rank[y]){
            par[x] = y;
            siz[y] += siz[x];
        }else{
            par[y] = x;
            siz[x] += siz[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
        return true; // 併合成功
    }

    bool issame(ll x, ll y){
        return root(x)==root(y);
    }

    ll size(ll x){
        return siz[root(x)];
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    
    int p[n];
    rep(i, n){
        cin >> p[i];
    }
    
    UnionFind uf;
    uf.init(n);

    rep(i, m){
        int x, y;
        cin >> x >> y;
        uf.unite(--x, --y);
    }

    int ans = 0;
    rep(i, n){
        if(uf.issame(--p[i], i)) ans++;
    }

    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

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

using namespace std;

const long long mod = 1000000007;

long long fact[660];
long long ifact[660];

long long dp[2][330][660];

int N;
int D[330];

void input(){
	scanf("%d", &N);
	for(int i = 0; i < N; ++i){
		scanf("%d", D + i);
	}
}

bool isAll2(){
	for(int i = 0; i < N; ++i){
		if(D[i] != 2) return false;
	}
	return true;
}

void chadd(long long &a, long long b){
	a += b;
	if(a > mod) a -= mod;
}

long long mul(long long a, long long b){
	return (a * b) % mod;
}


long long ex(long long a, long long e){
	if(e == 0) return 1;
	long long tmp = ex(a, e / 2);
	tmp = mul(tmp, tmp);
	if(e % 2 == 1) tmp = mul(tmp, a);
	return tmp;
}

long long inv(long long x){
	return ex(x, mod - 2);
}

long long C(int n, int k){
	long long num = fact[n];
	long long den = mul(ifact[k], ifact[n - k]);
	return mul(num, den);
}

void init(){
	fact[0] = 1;
	ifact[0] = 1;
	for(int i = 1; i < 660; ++i){
		fact[i] = mul(fact[i - 1], i);
		ifact[i] = mul(ifact[i - 1], inv(i));
	}
}

long long solve(){
	init();
	if(isAll2()){
		long long x = fact[N - 1];
		if(x % 2 == 0) return x / 2;
		return (x + mod) / 2;
	}
	int t = 0;
	dp[t][0][0] = 1;
	for(int i = 0; i < N; ++i){
		for(int j = 0; j < 330; ++j){
			for(int k = 0; k < 330; ++k){
				dp[1 - t][j][k] = 0;
			}
		}
		for(int j = 0; j <= i; ++j){
			for(int k = 0; k < 330; ++k){
				// non cycle
				chadd(dp[1 - t][j][k], mul(dp[t][j][k], ifact[D[i] - 1]));
				// cycle
				if(D[i] == 1) continue;
				long long coe = mul(fact[k], ifact[k + D[i] - 2]);
				coe = mul(coe, C(k + D[i] - 2, D[i] - 2));
				long long tmp = mul(dp[t][j][k], coe);
				chadd(dp[1 - t][j + 1][k + D[i] - 2], tmp);
			}
		}
		t = 1 - t;
	}
	long long ans = 0;
	for(int j = 3; j <= N; ++j){
		long long tmp2 = 0;
		for(int k = 1; k <= N; ++k){
			long long tmp = dp[t][j][k];
			tmp = mul(tmp, k);
			chadd(tmp2, tmp);
		}
		tmp2 = mul(tmp2, fact[j - 1]);
		tmp2 = mul(tmp2, fact[N - j - 1]);
		chadd(ans, tmp2);
		//printf("%d %lld\n", j, tmp2);
	}
	if(ans % 2 == 0) return ans / 2;
	return (ans + mod) / 2;
	return ans;
}

int main(){
	input();
	long long ans = solve();
	printf("%lld\n", ans);
	return 0;
}


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

using namespace std;
long long dp[1000009];
int n,k,h[1000000];
long long bt(int i)
{
    if(i>=n-1)
        return 0;
    if(dp[i]!=-1)
        return dp[i];
    long long &ret=dp[i];
    ret=99999990000909999;
    for(int j=1;j<=k && i+j<n;j++)
    {
        ret=min(abs(h[i]-h[i+j])+bt(i+j),ret);
    }
    return ret;
}
int main()
{
    dp[n-1]=0;
    cin>>n>>k;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++)
        cin>>h[i];
    cout<<bt(0);
}


Measured memory_bytes: 14976
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int n;
  cin>>n;
  vector<int>v;
  for(int i=0;i<n;++i) {
    int x;
    cin>>x;
    v.push_back(x);
  }
  int ans=0;
  sort(v.begin(),v.end());
  
  for(int i=0;i<n;++i){
    int x=v[i];
    
    bool f=1;
    for(int j=1;j*j<=x;++j){
      if(x%j==0 and (binary_search(v.begin()+i+1,v.end(),x/j) or binary_search(v.begin()+i+1,v.end(),j) or binary_search(v.begin(),v.begin()+i,j) or binary_search(v.begin(),v.begin()+i,x/j))) 
      {
          f=0;
          break;
      }
      
    }
    if(f) ++ans;
    
  }
  cout<<ans;
}
    
    


Measured memory_bytes: 4252
from itertools import product
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
AB = sorted([a+b for a,b in product(A,B)],reverse=True)[:K]
ans = sorted([a+b for a,b in product(AB,C)],reverse=True)[:K]
for i in ans:
    print(i)

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

inline ll lcm(ll x, ll y)
{
    return x/__gcd(x,y)*y;
}

int main()
{
    int n;
    while(cin >>n,n)
    {
        vector<ll> d(n),v(n);
        rep(i,n) cin >>d[i] >>v[i];

        ll T=1;
        rep(i,n)
        {
            ll G=__gcd(v[i],d[i]);
            T=lcm(T,d[i]/G);
        }

        vector<ll> ans(n);
        rep(i,n) ans[i]=v[i]*T/d[i];

        ll div=ans[0];
        for(int i=1; i<n; ++i) div=__gcd(div,ans[i]);
        rep(i,n) cout << ans[i]/div << endl;
    }
    return 0;
}

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

int main () {
  long long N , ans ;
  cin >> N ;
  long long line[5] ,linei[5];
  for(int i = 0 ; i < 5 ;i++ ) {
    cin >> line[i] ;
    linei[i] = line[i] ;
  }
  sort(line,line+5) ;
  ans += ( N - 1 ) / line[0] + 1 ;
  cout << ans + 4 << endl ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
using P = pair<int, int>;
const ll inf =1e9;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    int n, m; cin >> n >> m;
    vector<int> wa(n);
    vector<int> ac(n);
    for(int i=0; i<n; i++){
        wa[i] = 0;
        ac[i] = 0;
    }
    for(int i=0; i<m; i++){
        int problem_num; cin >> problem_num;
        str problem_result; cin >> problem_result;
        if (problem_result == "WA"){
            if (ac[problem_num-1] == 0){
                wa[problem_num-1] += 1;
            }
        }else{
            if (ac[problem_num-1] == 0){
                ac[problem_num-1] += 1;
            }
        }
    }
    int ans_wa = 0;
    int ans_ac = 0;
    for(int i=0; i<n; i++){
        if (ac[i] != 0){
            ans_wa += wa[i];
            ans_ac += 1;
        }
    }
    cout << ans_ac << " " << ans_wa << endl;
    return 0;
}

Measured memory_bytes: 1024
/*
  AUTHOR:SOURABH
  CREATED:31:05:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pii , null_type, less< pii >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 998244353
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll t,n,i,j,k,c,ans;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>n;
        ans=0;
        for(i=2;i*i<=n;i++)
        {
            if(n%i==0)
            {
                c=0;
                W(n%i==0)
                {
                    n/=i;
                    c++;
                }
                fs(j,1,c+1)
                {
                    if(j*(j+1)<=2*c)k=j;
                    else
                        break;
                }
                ans+=k;
            }
        }
        if(n>1)
            ans+=1;
        cout<<ans;
    }
    return 0;
}








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

int N, A[200000], B[200000];
pair<int,int> C[200000];

signed main() {
  cin >> N;
  for(int i=0; i<N; i++) cin >> A[i] >> B[i];
  for(int i=0; i<N; i++) C[i] = make_pair(B[i], A[i]);

  sort(C, C+N);

  int t = 0;
  for(int i=0; i<N; i++) {
    auto c = C[i];
    if(t + c.second > c.first) {puts("No"); return 0;}
    t += c.second;
  }
  puts("Yes");
}


Measured memory_bytes: 3456
#include<iostream>
#include<cmath>
using namespace std;
bool isprime(int x)
{
	if (x == 2)
	{
    return true;
  }

  if (x < 2 || x%2 == 0)
  {
    return false;
  }

  int i = 3;
  int s = (int)sqrt(double(x));
  while ( i <= s )
  {
    if ( x % i == 0)
	{
		return false;
	}
	else {
    i = i + 2;
	}
  }
 return true;
}

int main()
{	
	int n;
	int sum = 0;
	int a[10000] = {0};
	cin >> n;
	for ( int i = 0; i < n; i++)
	{ 
		cin >> a[i];
	}

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

	for ( int i = 0; i < n; i++ )
	{
		if ( isprime(a[i]) )
		{
			sum++;
		}
	}
	cout << sum << endl;
	return 0;
}


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

int main(void)
{
	int N, a;
	int min = 1000, max = 0;

	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> a;
		if (a < min)	min = a;
		if (a > max)	max = a;
	}

	cout << (max - min) << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
H,W,A,B = map(int,sys.stdin.readline().rstrip().split())
mod = 10**9+7

kaijou = [1]
for i in range(1,H+W-1):
    kaijou.append((kaijou[-1]*i) % mod)

a = 0
for i in range(B):
    b = kaijou[(H-A-1)+i]*pow(kaijou[i],mod-2,mod)*pow(kaijou[H-A-1],mod-2,mod)
    b %= mod
    b *= kaijou[(W+A-2)-i]*pow(kaijou[A-1],mod-2,mod)*pow(kaijou[W-1-i],mod-2,mod)
    b %= mod
    a += b
    a %= mod

c = kaijou[H+W-2]*pow(kaijou[H-1],mod-2,mod)*pow(kaijou[W-1],mod-2,mod)
c %= mod

print((c-a) % mod)

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

char t[20], s[20];
int main() {
	int n; scanf("%d", &n);
	set<string>se;
	rep(i, n) {
		scanf("%s%s", t, s);
		if (!strcmp(t, "insert"))se.insert(s);
		else
			puts(se.find(s) != se.end() ? "yes" : "no");
	}
}

Measured memory_bytes: 29084
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var mojiretu = new char[5 * 100000 + 10];
            var S = ReadLine();
            var Q = Sarray()[0];
            var start = 2 * 100000 + 5;
            var end = start + S.Length;
            var i = 0;
            foreach(var s in S)
                mojiretu[start + i++] = s;

            var hanten = false;
            for (i = 0; i < Q;++i)
            {
                var query = ReadLine().Split();
                if (query[0] == "1")
                {
                    hanten = !hanten;
                    continue;
                }
                var F = query[1];
                var C = query[2][0];
                if ((F == "1" && !hanten) || (F == "2" && hanten))
                {
                    mojiretu[--start] = C;
                }
                else
                {
                    mojiretu[++end - 1] = C;
                }
            }
            if (!hanten)
                for (i = start; i < end; ++i)
                    Write(mojiretu[i]);
            else
                for (i = end - 1; start <= i; --i)
                    Write(mojiretu[i]);
            Out.Flush();
        }
    }
}

Measured memory_bytes: 18876
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define pf push_front
#define ins insert

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

string s;

main(){
	int t;
	cin>>s;
	t=toInt(s);
	int tans=0;
	while(t){
		tans+=t%10;
		t/=10;
	}
	s[0]--;
	for(int i=1;i<s.size();i++){
		s[i]='9';
	}
	t=toInt(s);
	int ans=0;
	while(t){
		ans+=t%10;
		t/=10;
	}
	chmax(ans,tans);
	dans;
}

Measured memory_bytes: 256
#include<map>
#include<cstdio>
#define ll long long
#define fo(i, x, y) for(int i = x; i <= y; i ++)
using namespace std;

const int N = 2e5 + 5;

int n, a[N];

ll ans;


int main() {
	scanf("%d", &n);
	fo(i, 1, n) scanf("%d", &a[i]);
	if(a[1] != 0) {
		printf("-1"); return 0;
	}
	fo(i, 2, n) {
		if(a[i - 1] < a[i] - 1) {
			printf("-1"); return 0;
		}
	}
	ans = a[n];
	fo(i, 2, n)
		if(a[i - 1] + 1 != a[i])
			ans += a[i - 1];
	printf("%lld", ans);
}

Measured memory_bytes: 896
#include<stdio.h>

int main(){
  int i,n,x,y,j;
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  x=a[n-1];
  i=-1;
  for(j=0;j<n;j++){
    if(a[j]<=x){
      i=i+1;
      y=a[i];
      a[i]=a[j];
      a[j]=y;
    }
  }
 
  for(j=0;j<i;j++){
    printf("%d ",a[j]);
  }
  printf("[%d] ",a[i]);
  for(j=i+1;j<n-1;j++){
    printf("%d ",a[j]);
  }
  printf("%d\n",a[n-1]);
  return 0;
}

Measured memory_bytes: 988
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long sum = 0;
        for (int i = 1; i <= n; i++) {
            long y = n / i;
            sum += y * (y + 1) * i / 2;
        }
        System.out.println(sum);
        sc.close(); 
    }
}

Measured memory_bytes: 35764
def main():
    n = int(input())
    x, y = [], []
    for i in range(n):
        xi, yi = map(int, input().split())
        x.append((xi, i))
        y.append((yi, i))

    x.sort()
    y.sort()

    # x[x_ind[i]][1] = i
    x_ind = [0] * n
    y_ind = [0] * n
    for i in range(n):
        x_ind[x[i][1]] = i
        y_ind[y[i][1]] = i

    from heapq import heapify, heappush, heappop

    ans = 0
    seen = [True] * n
    heap = [(0, 0)]
    heapify(heap)
    while len(heap) > 0:
        cost, city = heappop(heap)

        if seen[city]:
            ans += cost
            seen[city] = False

            xi = x_ind[city]
            if xi > 0 and seen[x[xi-1][1]]:
                heappush(heap, (x[xi][0] - x[xi-1][0], x[xi-1][1]))
            if xi < n-1 and seen[x[xi+1][1]]:
                heappush(heap, (x[xi+1][0] - x[xi][0], x[xi+1][1]))
            yi = y_ind[city]
            if yi > 0 and seen[y[yi-1][1]]:
                heappush(heap, (y[yi][0] - y[yi-1][0], y[yi-1][1]))
            if yi < n-1 and seen[y[yi+1][1]]:
                heappush(heap, (y[yi+1][0] - y[yi][0], y[yi+1][1]))
    
    print(ans)

main()

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define EPS (1e-8)

int main() {
	int a, b, c, n;
	while (cin >> a >> b >> c, a || b || c) {
		cin >> n;
		int min1 = min(a, b), min2 = min(max(a, b), c);
		double d = hypot(min1, min2) / 2.0;
		
		REP(i, n) {
			double r;
			scanf("%lf", &r);
			if (r - d > EPS) puts("OK");
			else puts("NA");
		}
	}
	return 0;
}

Measured memory_bytes: 1232
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
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; }

void solve(long long N, long long W, std::vector<long long> w, std::vector<long long> v){
    vector<vll> dp(N+1, vll(W+1, 0));
    REP(i, N){
        REP(j, W+1){
            dp[i+1][j] = dp[i][j];
            if( w[i] <= j){
                chmax(dp[i+1][j], dp[i][j-w[i]]+v[i]);
            }
        }
    }
    cout<<dp[N][W]<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long W;
    scanf("%lld",&W);
    std::vector<long long> w(N);
    std::vector<long long> v(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&w[i]);
        scanf("%lld",&v[i]);
    }
    solve(N, W, std::move(w), std::move(v));
    return 0;
}


Measured memory_bytes: 80256
#include<bits/stdc++.h>
#define MAX_V 100000
using namespace std;
int m,w[100001];
vector<int> vv[100001];
unordered_set<int> st[100001];
int V;
vector<int> G[MAX_V];
vector<int> rG[MAX_V];
vector<int> vs;
bool used[MAX_V];
int cmp[MAX_V];
int C[100001],F[100001],U[100001],ans;
bool UU[100001];


void DFS(int p){
  for(int i=0;i<vv[p].size();i++){
    int mn=min(vv[p][i],p),mx=max(vv[p][i],p);
    if(st[mn].find(mx)==st[mn].end()){
      st[mn].insert(mx);
      G[p].push_back(vv[p][i]);
      rG[vv[p][i]].push_back(p);
      DFS(vv[p][i]);
    }
  }
}

void dfs(int v){
  used[v]=true;
  for(int i=0;i<G[v].size();i++)if(!used[G[v][i]])dfs(G[v][i]);
  vs.push_back(v);
}

void rdfs(int v,int k){
  used[v]=true;
  cmp[v]=k;
  for(int i=0;i<rG[v].size();i++)if(!used[rG[v][i]])rdfs(rG[v][i],k);
}

int scc(){
  for(int v=0;v<V;v++)if(!used[v])dfs(v);
  memset(used,0,sizeof(used));
  int k=0;
  for(int i=vs.size()-1;i>=0;i--)if(!used[vs[i]])rdfs(vs[i],k++);
  return k;
}

bool DFS1(int p){
  if(U[p])return 0;
  U[p]=1;
  bool f=F[cmp[p]]>=2;
  for(int i=0;i<G[p].size();i++)
    f|=DFS1(G[p][i]);
  ans+=w[p]*f;
  return UU[p]=f;
}
bool UUU[100001];
int DFS2(int p){
  if(UUU[p])return 0;
  UUU[p]=1;
  int res=0;
  
  for(int i=0;i<G[p].size();i++)
    res=max(res,DFS2(G[p][i]));  
  return res+(UU[p]?0:w[p]);
}

int main(){
  cin>>V>>m;
  for(int i=0;i<V;i++)cin>>w[i];
  for(int j=0,a,b;j<m;j++){
    cin>>a>>b;a--,b--;
    vv[a].push_back(b),vv[b].push_back(a);
  }
  DFS(0);
  int t=0;
  for(int i=0;i<V;i++)t+=w[i];
  scc();
  for(int i=0;i<V;i++)F[cmp[i]]++;
  DFS1(0);
  cout<<ans+DFS2(0)<<endl;
  return 0;
}

Measured memory_bytes: 42732
#include<iostream>
#include<cstring>
using namespace std;
int main(){
    string s;
    getline(cin,s);
    int count = 1;
    char comp = s[0];
    int i;
    for(i=1;i<s.length();i++){
        if(comp!=s[i]){
            comp = s[i];
            count++;
        }
    }
    cout<<count-1;
    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#include <stdlib.h>
#include <time.h>
#include <chrono>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

ll d;
vector<ll> c(26 + 1, 0);
vector<vector<ll>> s(365 + 1, vector<ll>(26 + 1, 0));

ll scoring(vector<int> t)
{
    ll ans = 0;
    vector<ll> last(26 + 1, 0);

    for (int i = 1; i <= d; i++)
    {
        ans += s[i][t[i]];
        ans -= c[t[i]] * (i - last[t[i]]) * (i - last[t[i]] - 1) / 2;
        last[t[i]] = i;
    }

    for (int i = 1; i <= 26; i++)
    {

        ans -= c[i] * (d - last[i] + 1) * (d - last[i]) / 2;
    }

    return ans;
}

int main(void)
{
    srand(time(NULL));
    cin >> d;

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

    for (int i = 1; i <= d; i++)
    {
        for (int j = 1; j <= 26; j++)
        {
            cin >> s[i][j];
        }
    }

    vector<int> BestT(d + 1, 1);

    for (int i = 1; i <= d; i++)
    {
        BestT[i] = rand() % 26 + 1;
    }

    // printf("%lld\n", scoring(BestT));

    double BestScore = scoring(BestT);
    double score;

    auto start = chrono::system_clock::now();
    vector<int> t(d + 1, 1);

    double T0 = 1e6;
    double T1 = 1e3;
    double TL = 1950;

    ll count = 0;

    while (1)
    {
        ll msec;

        msec = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - start).count();

        if (msec >= TL)
        {
            break;
        }

        double T = powf(T0, 1 - msec / TL) * powf(T1, msec / TL);

        t = BestT;

        t[rand() % d + 1] = rand() % 26 + 1;

        score = scoring(t);

        if (exp((score - BestScore) / T) > 0.5)
        {
            BestT = t;
            BestScore = score;
        }
    }

    for (int i = 1; i <= d; i++)
    {
        printf("%d\n", BestT[i]);
    }

    // printf("%lld\n", scoring(BestT));
}


Measured memory_bytes: 4420
n = int(input())
a = list(map(int, input().split()))
even_list = []
for num in a:
    if num % 2 == 0 :
        even_list.append(num)

deny = 0
for even in even_list :
    if even % 3 != 0 and even % 5 != 0 :
        deny = 1
        break

if deny == 0 :
    print('APPROVED')
else :
    print('DENIED')

Measured memory_bytes: 3064
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
#include<numeric>
#include<queue>
#include<string>
#include<vector>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
ll mod = 1000000007;
using namespace std;
priority_queue<ll int>A;//きゅー
int main(void)
{
	int A, B,a=1;
	scanf("%d%d", &A, &B);
	int count = 0;
	while (true) {
		if (a >= B) {
			printf("%d", count);
			return 0;
		}
		a = a - 1 + A;
		count++;
	}


	return 0;

}


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

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

  ll N = S.length();
  bool ok = false;
  REP(i, 0, N) REP(j, i, N + 1) {
    string s = "";
    REP(k, 0, N) {
      if (i <= k && k < j) continue;
      s += S[k];
    }
    if (s == "keyence") ok = true;
  }
  cout << (ok ? "YES" : "NO") << endl;
}

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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(in.readLine());
		String S = in.readLine();
		
		long[] amt = new long[6];
		
		/*
		 *  0 R
		 *  1 G
		 *  2 B
		 *  
		 *  3 RG
		 *  4 RB
		 *  5 GB
		 */
		
		long sum = 0;
		for (int i = 0; i < N; i++) {
			char c = S.charAt(i);
			
			if (c == 'R') {
				amt[0]++;
				amt[3] += amt[1];
				amt[4] += amt[2];
				
				sum += amt[5];
			}else if (c == 'G') {
				amt[1]++;
				amt[3] += amt[0];
				amt[5] += amt[2];
				
				sum += amt[4];
			}else {
				amt[2]++;
				amt[4] += amt[0];
				amt[5] += amt[1];
				
				sum += amt[3];
			}
		}
		
		for (int i = 0; i < N; i++) {
			for (int j = 1; j <= Math.min(i, N-1-i); j++) {
				char c1 = S.charAt(i-j);
				char c2 = S.charAt(i);
				char c3 = S.charAt(i+j);
				if (c1 != c2 && c1 != c3 && c2 != c3)
					sum--;
			}
		}
		
		System.out.println(sum);
	}
}


Measured memory_bytes: 32940
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		String s = sc.next();
		for (int i = 0; i < mem.length; ++i) {
			for (int j = 0; j < mem[i].length; ++j) {
				mem[i][j] = "";
			}
		}
		System.out.println(f(0, s.length(), s));
	}

	String[][] mem = new String[101][101];

	// [s,t)
	String f(int s, int t, String S) {
		if (t - s == 1) {
			return "()";
		} else if (t - s < 1) {
			return "";
		}
		if (!mem[s][t].equals("")) {
			return mem[s][t];
		}
		String ans = "";
		for (int m = s + 1; m < t; ++m) {
			// [s,m),[m,t)に分割
			ans = next(ans, f(s, m, S) + f(m, t, S));
		}
		if (S.charAt(s) == '(' && S.charAt(t - 1) == ')') {
			ans = next(ans, "(" + f(s + 1, t - 1, S) + ")");
		} else {
			if (S.charAt(s) == '(')
				ans = next(ans, "(" + f(s + 1, t, S) + ")");
			if (S.charAt(t - 1) == ')') {
				ans = next(ans, "(" + f(s, t - 1, S) + ")");
			}
		}
		return mem[s][t] = ans;
	}

	String next(String cur, String ns) {
		if (cur.equals("") || cur.length() > ns.length() || (cur.length() == ns.length() && cur.compareTo(ns) > 0)) {
			return ns;
		} else {
			return cur;
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

Measured memory_bytes: 66708
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
 
#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)
 
int n, a;
int cnt[9];
 
int main(int argc, char **argv) {
	cin >> n;
	CLEAR(cnt);
	REP(i, n) {
		cin >> a;
		++cnt[min(8, a / 400)];
	}
	int res = 0;
	REP(i, 8) if (cnt[i] != 0) ++res;
	cout << max(1, res) << ' ' << (res + cnt[8]) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  double a,b,x;
  cin>>a>>b>>x;
  double v=a*a*b;
  double n;
  if(x<v/2){
    n=x*2/b/a;
    n=atan(n/b)/(double)3.14159265358979*180;
  	n=90-n;
    printf("%.9f\n",n);
  }else{
    n=(v-x)*2/a/a;
    n=atan(n/a)/(double)3.14159265358979*180;
    printf("%.9f\n",n);
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
dic = {}
ss = ['M','A','R','C','H']
for i in range(n):
    s = input()
    if s[0] in ss:
        if s[0] not in dic :
            dic[s[0]] = 0
        dic[s[0]] += 1

from itertools import combinations
key = list(dic.keys())

klist = list(combinations(key,3))
#print(klist)

ans = 0
for i in range(len(klist)):
    ans += dic[klist[i][0]]*dic[klist[i][1]]*dic[klist[i][2]]

print(ans)


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

int main() {
	int a, b, c;
	
	while (true) {
		cin >> a >> b >> c;
		if (a == -1 and b == -1 and c == -1) break;
		
		char grade;
		int sum_point = a + b;
		if (a == -1 or b == -1) {
			grade = 'F';
		} else if (sum_point >= 80) {
			grade = 'A';
		} else if (sum_point >= 65) {
			grade = 'B';
		} else if (sum_point >= 50) {
			grade = 'C';
		} else if (sum_point >= 30) {
			if (c >= 50) grade = 'C';
			else grade = 'D';
		} else {
			grade = 'F';
		}
		
		cout << grade << '\n';
	}
	
	return 0;
}


Measured memory_bytes: 3068
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=1e5+10;
const int mod=1e9+7;
ll a[N],cnt[2];
ll n,k;

int main()
{
    cin>>n>>k;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
    }
    ll ans=0;
    for(ll j = 42; j >= 0; --j)
    {
        cnt[0] = cnt[1] = 0;
        for(int i = 1; i <= n; ++i)
        {
            cnt[(a[i]>>j)&1ll]++;
        }
        if(cnt[0] > cnt[1] && ans + (1ll << j) <= k)
            ans += (1ll << j);
    }

    ll sum = 0;
    for(int i = 1; i <= n; ++i)
    {
        sum += ans ^ a[i];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 4420
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int n;
	long minimum = 1000000, maximum = -1000000, sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++){
		long a;
		cin >> a;
		minimum = min(a, minimum);
		maximum = max(a, maximum);
		sum += a;
	}
	cout << minimum << " " << maximum << " " << sum << endl;
	return 0;
}

Measured memory_bytes: 1168
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<unordered_set>
#include<math.h>
#include<utility>
#include<iomanip>

using namespace std;

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

	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}

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

	int current = sum;
	for (int i = k; i < n; i++) {
		current += v[i] - v[i - k];
		sum = max(sum, current);
	}

	cout << setprecision(9) << (sum + k) / (double) 2;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);++(i))
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);--(i))
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    REP(i,0,n){
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    int ans = 1e9 + 10;
    REP(i,0,n - k + 1){
        ans = min(ans, h[i + k - 1] - h[i]);
    }

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

Measured memory_bytes: 640
n,k=gets.split.map(&:to_i)
r=0
for i in 1..[n-2,11].min
	for j in 1..5
		next if 9*(7*i+j+1)%11!=k
		r+=(n-2)/11+((n-2)%11>=i ? 1 : 0)
	end
end
p r

Measured memory_bytes: 1788
#include<stdio.h>
int main ()
{  int i,n,t,j,k=0,minnumber,a[10000];
   scanf("%d",&n);
   for(i=0;i<n;i++)
   scanf("%d",&a[i]);
   for(i=0;i<n;i++)
   {  minnumber=i;
      for(j=i;j<n;j++)
      if(a[j]<a[minnumber])  minnumber=j;//找出未排序的最小值序号 
      if(minnumber!=i)
	  {  t=a[i];
         a[i]=a[minnumber];
         a[minnumber]=t;
         k++;
      }
   }
   for(i=0;i<n;i++)
   {  if(i>0)  printf(" ");
      printf("%d",a[i]);
   }
   printf("\n");
   printf("%d\n",k);
   return 0; 
}


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

int main(){
  int n;
  cin>>n;
  string s;
  int count=0;
  cin>>s;
  for(int i=0;i<n-2;i++){
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
      count++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)1e5+5;
const int M = (int)3e3+5;
const int Q = 301;
const int logN = 19;

ll dp[M][M];
void solve() {
    int n;
    cin>>n;
    vector<int> a(n+1);
    REP(i,1,n) {
        cin>>a[i];
    }
    REPN(i,n,1) {
        dp[i][i] = a[i];
        REP(j,i+1,n) {
            dp[i][j] = max(a[j]-dp[i][j-1],a[i]-dp[i+1][j]);
        }
    }
    cout<<dp[1][n];
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 70016