akhauriyash/Code-Regression huggingface dataset:
import Text.Printf

toRad d = pi * d / 180
height b degC = b * sin (toRad degC)
cosf a b degC = sqrt $ a^2 + b^2 - 2 * a * b * cos (toRad degC)
area a b degC = a * (height b degC) / 2

main = do
  [a, b, degC] <- return . map (\x -> read x :: Double) . words =<< getLine
  let h = height b degC
  putStrLn $ printf "%.08f" $ area a b degC
  putStrLn $ printf "%.08f" $ a + b + (cosf a b degC)
  putStrLn $ printf "%.08f" h
  

Measured memory_bytes: 4312
#include <stdio.h>

int main()
{
  int x, y, gcd = 0, remainer, divisor, xDivisor, yDivisor, smallOne;
  scanf("%d %d", &x, &y);

  if (x > y)
  {
    remainer = x % y;
    smallOne = y;
  }
  else if (y > x)
  {
    remainer = y % x;
    smallOne = x;
  }
  else if (x == y)
  {
    gcd = x;
    printf("%d\n", gcd);
    return 0;
  }

  if (remainer > 0 && smallOne > 0)
  {
    int smallOneIndex;
    int remainderIndex;

    for (divisor = 2; divisor <= remainer; ++divisor)
    {
      if (remainer % divisor == 0 && smallOne % divisor == 0)
      {
        gcd = divisor;
      }
    }
    if (gcd >0){
      printf("%d\n", gcd);
    }else {
      gcd = 1;
      printf("%d\n", gcd);
      return 0;
    }
  }
  else if (remainer == 0)
  {
    gcd = smallOne;
    printf("%d\n", gcd);
    return 0;
  }

  return 0;
}


Measured memory_bytes: 2148
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
#define int long long
#define mod(int)(1000000007)
using namespace std;
const int INF = 1000000000000;
int test[345678], mi[345678], cnt[345678];
signed main() {
	int n, m, sum = 0, ans = 0; cin >> n >> m;
	for (int h = 0; h < n; h++) {
		cin >> test[h];
	}
	mi[0] = test[0];
	for (int h = 1; h < n; h++) {
		mi[h] = min(mi[h - 1], test[h]);
	}
	for (int h = 0; h < n; h++) {
		cnt[h] = test[h] - mi[h]; sum = max(sum, cnt[h]);
	}
	for (int h = 0; h < n; h++) {
		if (cnt[h] == sum)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 5120
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define clear(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


struct Robo
{
	int x, y, dir, cost;
	Robo(int x, int y, int dir, int cost)
		: x(x), y(y), dir(dir), cost(cost) { }
};
bool operator<(const Robo& a, const Robo& b)
{
	return a.cost > b.cost;
}
int main()
{
	int w, h;
	while (cin >> w >> h, w)
	{
		int s[32][32];
		rep (y, h)
			rep (x, w)
				cin >> s[y][x];
		int c[4];
		rep (i, 4)
			cin >> c[i];

		const int INF = 1 << 26;
		int dis[32][32][4];
		rep (y, h)
			rep (x, w)
				rep (i, 4)
					dis[y][x][i] = INF;

		priority_queue<Robo> q;
		dis[0][0][1] = 0;
		q.push(Robo(0, 0, 1, 0));
		while (!q.empty())
		{
			Robo r = q.top(); q.pop();
			if (r.cost > dis[r.y][r.x][r.dir])
				continue;
			else if (r.x == w - 1 && r.y == h - 1)
			{
				cout << r.cost << endl;
				break;
			}

			for (int i = 0; i < 4; ++i)
			{
				int nc = r.cost;
				if (i != s[r.y][r.x])
					nc += c[i];

				int d = 0;
				if (i == 1)
					d = 3;
				else if (i == 2)
					d = 2;
				else if (i == 3)
					d = 1;
				int nd = (r.dir + d) % 4;
				int nx = r.x + dx[nd], ny = r.y + dy[nd];

				if (0 <= nx && nx < w && 0 <= ny && ny < h && nc < dis[ny][nx][nd])
				{
					dis[ny][nx][nd] = nc;
					q.push(Robo(nx, ny, nd, nc));
				}
			}
		}
	}
}

Measured memory_bytes: 0
c=0
f=0
N, M = map(int, input().split())
list = []
for i in range(M):
    a,b=input().split()
    list.append((int(a), int(b)))
 
if M+N==1:
	print(0)
	f=3
else:
	for j in range(M):
		if list[j][0]+list[j][1]==1:
			f=2
			c+=1		
	if c==M and N==1:
		print(0)
	elif c>0:
		print(-1)
			
if f<2:
	for i in range(1,10**N):
		f=0
		for j in range(M):
			if int(i/(10**(N-list[j][0])))%10 != list[j][1]:
				f=1
				break
		if f==0 and i>=10**(N-1):
			print(i)
			break
		
if f==1:
	print(-1)

Measured memory_bytes: 3064
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
A.sort()
max_a = A[-1] + 1
count_a = Counter(A)
dp = [True for i in range(max_a)]
ans = 0

for a in A:
    if dp[a] and count_a[a] == 1:
        ans += 1

    for j in range(a*2, max_a, a):
        dp[j] = False

print(ans)


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

int main(){
	ll N;
	cin >> N;
	vector<ll> A(N);
	rep(i,N){
		cin >> A[i];
	}
	
	int count = 1;
	int ans = 0;
	rep(i,N){
		if(A[i] != count){
			ans++;
		}else{
			count++;
		}
	}
	
	if(ans==N){
		cout << -1 << endl;
	}else{
		cout << ans << endl;
	}
	
    return 0;
}



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

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

	string x;
	set<string> S;

	for (int i = 0; i < N; i++) {
		cin >> x;
		S.insert(x);
	}

	cout << S.size() << endl;
	return 0;
}

Measured memory_bytes: 15668
#include <bits/stdc++.h>
using namespace std;
#define P 1000000007
int main()
{
    int i, j, h, w;
    cin >> h >> w;
    char a[1002][1002];
    for (i = 0; i < h; i++)
    {
        for (j = 0; j < w; j++)
        {
            cin >> a[i][j];
        }
    }
    int dp[1002][1002];
    dp[0][0] = 0;
    for (i = 0; i < h; i++)
    {
        for (j = 0; j < w; j++)
        {
            if (a[i][j] == '#')
                dp[i][j] = 0;
        }
    }
    if (a[0][1] == '.')
        dp[0][1] = 1;
    for (j = 2; j < w; j++)
    {
        if (a[0][j] == '.')
        {
            dp[0][j] = dp[0][j - 1];
        }
        else
            dp[0][j] = 0;
    }
    if (a[1][0] == '.')
        dp[1][0] = 1;

    for (j = 2; j < h; j++)
    {
        if (a[j][0] == '.')
            dp[j][0] = dp[j - 1][0];
        else
            dp[j][0] = 0;
    }

    for (i = 0; i < h; i++)
    {
        for (j = 0; j < w; j++)
        {                  
            if(i*j != 0 && a[i][j] =='.')
            { 
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%P;
            }            


        }
    } 


    cout<<dp[h-1][w-1];

    return (0);
}

Measured memory_bytes: 5120
s = input()

ans_li=[]
for i in range(len(s)):
    if s[i]==str(0):
        ans_li.append(str(0))
    if s[i]==str(1):
        ans_li.append(str(1))
    if s[i]=='B':
        if len(ans_li)==0:
            continue
        del ans_li[-1]
print(''.join(ans_li))

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

int main(){
    string S;
  cin >> S;
  if ((S[5] - '0') * 10 + (S[6] - '0') < 5) {
    cout << "Heisei" << endl;
  }
  else {
    cout << "TBD" << endl;
  }
}


Measured memory_bytes: 256
// AtCoder Grand Contest 012
// C - Tautonym Puzzle

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;


const int MAX_C = 100;

ll N;
vector<int> ans;

int main() {

    cin >> N;

    for (int i = 0; ((N + 1) >> i) > 1; i++) {
        if (((N + 1) >> i) & 1) {
            ans.push_back(MAX_C - i);
        }
        ans.push_back(i + 1);
    }
    for (int i = 0; i < MAX_C; i++) {
        ans.push_back(i + 1);
    }

    cout << ans.size() << endl;
    for (int i = 0; i < (int)ans.size(); i++) {
        cout << ans[i] << (i == (int)ans.size() - 1 ? '\n' : ' ');
    }

    return 0;

}


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

using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

struct edge { int to, cost; edge(int t, int c) : to(t), cost(c) {} };
int V;
vector<edge> g[100001];
int d[100001];
const int inf = 1e8;

void dijkstra(int s) {
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
    fill(d, d+V, inf);
    d[s] = 0;
    que.push(make_pair(0, s));

    while (!que.empty()) {
        pair<int, int> p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i=0; i<g[v].size(); ++i) {
            edge e = g[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(make_pair(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int k;
    cin >> k;
    V = k;
    rep(i, k) {
        edge e1((i+1)%k, 1);
        g[i].push_back(e1);
        edge e2((i*10)%k, 0);
        g[i].push_back(e2);
    }
    deque<int> que;
    dijkstra(1);
    cout << d[0]+1 << endl;
}


Measured memory_bytes: 6780
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>


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 (a > b) { a = b; return 1; } return 0; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

int H, W, c;
vector<vector<int>> a;
int dh[] = { 1,0,-1,0 };
int dw[] = { 0,1,0,-1 };
void init(int h, int w) {
    a.clear(); a.assign(h, vector<int>(w));
}

int dfs(int cur, vector<vector<int>> a) {
    if (cur == 5) {
        if (a[0][0] != c) return 0;
        int res = 0;
        queue<pair<int, int>> q;
        vector<vector<bool>> used(H, vector<bool>(W));
        q.emplace(0, 0);
        used[0][0] = true;
        int t = a[0][0];
        while (!q.empty()) {
            res++;
            int h, w; tie(h, w) = q.front();
            q.pop();
            for (int j = 0; j < 4; j++) {
                int nh = h + dh[j];
                int nw = w + dw[j];
                if (nh < 0 or nh >= H or nw < 0 or nw >= W) continue;
                if (used[nh][nw]) continue;
                if (a[nh][nw] == t) {
                    q.emplace(nh, nw);
                    used[nh][nw] = true;
                }
            }
        }
        return res;
    }
    int res = 0;
    for (int i = 0; i < 6; i++) {
        auto ta = a;
        if (a[0][0] != i) {
            int t = a[0][0];
            ta[0][0] = i;
            queue<pair<int, int>> q;
            q.emplace(0, 0);
            while (!q.empty()) {
                int h, w; tie(h, w) = q.front();
                q.pop();
                for (int j = 0; j < 4; j++) {
                    int nh = h + dh[j];
                    int nw = w + dw[j];
                    if (nh < 0 or nh >= H or nw < 0 or nw >= W) continue;
                    if (ta[nh][nw] == t) {
                        ta[nh][nw] = i;
                        q.emplace(nh, nw);
                    }
                }
            }
        }
        chmax(res, dfs(cur + 1, ta));
    }
    return res;
}
void solve() {
    scanf("%d %d %d", &H, &W, &c); if (H == 0) exit(0);
    c--;
    init(H, W);
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) scanf("%d", &a[i][j]), a[i][j]--;
    printf("%d\n", dfs(0, a));
}

int main()
{
	/*
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    */
    int kkt = 89;
    while (kkt) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3256
S = input()
p_count = 0
g_count = 0
win, lose = 0, 0
for s in S:
    if s == "g":
        if p_count < g_count:
            p_count += 1
            win += 1
        else:
            g_count += 1
    else:
        if p_count < g_count:
            p_count += 1
        else:
            g_count += 1
            lose += 1
print(win - lose)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    string s;
    cin >> s;
    if ((s == "AAA") || s == "BBB") {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 3600
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

int levenshteinDistance(const string &s, const string &t) {
  int n = s.size(), m = t.size();
  vector<vector<int>> dp(n + 1, vector<int>(m + 1));
  rep(i, n + 1) dp[i][0] = i;
  rep(j, m + 1) dp[0][j] = j;
  loop(i, 1, n + 1) loop(j, 1, m + 1) dp[i][j] = min({dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + (s[i - 1] != t[j - 1])});
  return dp[n][m];
}

main {
  string s, t;
  cin >> s >> t;
  cout << levenshteinDistance(s, t) << endl;
}



Measured memory_bytes: 10808
#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 ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int main() {
	int a, b;
	cin >> a >> b;
	cout << max(a * b, max(a + b, a - b)) << endl;
	return 0;
}

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

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

Measured memory_bytes: 4848
#include<stdio.h>

int main()
{
	char s1[100][201],s2[100][201],a1[201],a2[201];
	int c,count,i,t,str,count_s1,count_s2;
	int br=0,judge=0,j,k;
	
	while(1)
	{
		j=0;
		k=0;
		count=0;
		count_s1=0;
		count_s2=0;
		
		while((c=getchar())!='\n')
		{
			if(c=='.')
			{
				br=1;
				break;
			}
			if(c=='"')
			{
				judge=1-judge;
				if(judge)
				{
					count_s1++;
					str=0;
				}
				else s1[count_s1-1][str]='\0';
			}
			if(judge)
			{
				s1[count_s1-1][str]=c;
				str++;
			}
			else
			{
				a1[j]=c;
				j++;
			}
		}
		a1[j]='\0';
		if(br) break;
		
		while((c=getchar())!='\n')
		{
			if(c=='"')
			{
				judge=1-judge;
				if(judge)
				{
					count_s2++;
					str=0;
				}
				else s2[count_s2-1][str]='\0';
			}
			if(judge)
			{
				s2[count_s2-1][str]=c;
				str++;
			}
			else
			{
				a2[k]=c;
				k++;
			}
		}
		a2[k]='\0';
		for(int i=0;;i++)
		{
			if(a1[i]=='\0' && a2[i]=='\0') break;
			if(a1[i]!=a2[i])
			{
				count=2;
				break;
			}
		}
		if(count_s1==count_s2 && count==0)
		{
			for(int i=0;i<count_s1;i++)
			{
				//printf("%s\n",s1[i]);
				//printf("%s\n\n",s2[i]);
				for(int t=0;;t++)
				{
					if(s1[i][t]=='\0'&&s2[i][t]=='\0') break;
					if(s1[i][t]!=s2[i][t])
					{
						count++;
						break;
					}
					
				}
			}
		}
		else count=2;
		if(count==0) printf("IDENTICAL\n");
		else if(count==1) printf("CLOSE\n");
		else printf("DIFFERENT\n");
	}
	return 0;
}


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


int main(){


int n,k;
cin >> n >> k;
vector<int>a(n);


for (int i = 0; i < k; i++){
    int d;
    cin>>d;
    int tmp;
    rep(j,d){
        cin >> tmp;
        tmp--;
        a.at(tmp)++;
}


    }



int ans = 0;
rep(i,n){
    if(a.at(i) == 0){
        ans++;
    }
}

cout << ans << endl;



}

Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<deque>
#include<algorithm>
using namespace std;

int main(){
    string s;
    cin>>s;
    deque<char> dq(s.size());
    for(int i=0;i<s.size();++i) dq[i]=s[i];

    int q;
    cin>>q;
    bool is_reversed=false;
    for(int i=0;i<q;++i){
        int t;
        cin>>t;
        if(t==1) is_reversed=!is_reversed;
        else{
            int f;
            char c;
            cin>>f>>c;
            if(f==1){
                if(!is_reversed) dq.push_front(c);
                else dq.push_back(c);
            }
            else{
                if(!is_reversed) dq.push_back(c);
                else dq.push_front(c);
            }
        }
    }

    if(is_reversed) reverse(dq.begin(),dq.end());
    
    for(auto c:dq) cout<<c;
    cout<<endl;
}

Measured memory_bytes: 4012
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
#define max 1000
int d,n;
int t[max],a[max],b[max],c[max];
bool suit[max][max];
int dp[max][max];
int main(){
    cin>>d>>n;
    for(int i=0;i<d;i++){
      cin>>t[i];
    }
    for(int j=0;j<n;j++){
      cin>>a[j]>>b[j]>>c[j];
    }
    for(int i=0;i<d;i++){
      for(int j=0;j<n;j++){
        suit[i][j]=(t[i]>=a[j]&&t[i]<=b[j]);
      }
    }
    memset(dp,-1,sizeof(dp));
    for(int j=0;j<n;j++){
      if(suit[0][j]==true){
       dp[0][j]=0;
     }
    }
    for(int i=0;i<d-1;i++){
      for(int j=0;j<n;j++){
        if(dp[i][j]>=0) {
           for(int k=0;k<n;k++){
             if(suit[i+1][k]==true){
               if(dp[i+1][k]<dp[i][j]+abs(c[j]-c[k])){
                 dp[i+1][k]=dp[i][j]+abs(c[j]-c[k]);
               }
             }
           }
        }
      }
    }
    int ans=-1;
    for(int j=0;j<n;j++){
      if(dp[d-1][j]>ans){
        ans=dp[d-1][j];
      }
    }
    cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 5284
/*
Reference : https://www.geeksforgeeks.org/maximum-product-subsequence-size-k/
 
 
*/
#include <bits/stdc++.h> 
using namespace std; 
 
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 
bool sortbysecdesc(const pair<int,int> &a, 
                   const pair<int,int> &b) 
{ 
       return a.second>b.second; 
} 
 
/*
Mistakes
 
- while using pairs make sure you comparator datatype it's int by default change it as per the need
- Modify comparator if you want to
*/
#define f first
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll64 int64_t
#define pb push_back
#define pll pair<long long int,long long int>
#define pi pair<int,int>
#define mi map<int,int>
#define ll long long int
#define mll map<long long int,long long int>
#define umi unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define vpi vector<pair<int,int>>
#define vpll vector<pair<long long int,long long int>>
#define mod 1000000007
#define fp(i,x,n) for(int i=x;i<n;i++)
#define fn(i,x,n) for(int i=x;i>n;i--)
#define fpm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define asort_vp_second(vect) sort(vect.begin(), vect.end(), sortbysec)
#define asort_vp_first(vect) sort(vect.begin(), vect.end())
#define dsort_vp_first(vect) sort(vect.begin(), vect.end(), sortinrev) 
#define dsort_vp_second(vect) sort(vect.begin(), vect.end(), sortbysecdesc)
#define vi vector<int>
#define vll vector<long long int>
#define c(x) cout<<x<<endl;
#define M 1000000007
using namespace std; 
#define int long long int
 
 
signed main()
{
    int s;
    cin>>s;
    
    
    int dp[s+10];
    memset(dp,0,sizeof(dp));
    
    fp(i,3,s+1)
    {
        dp[i]=1;
    }
    
    fp(j,0,s+1)
        {
        fp(i,3,s+1)
            {
            if(j-i>0)
            dp[j] = (dp[j] + dp[j-i])%M;
        }
    }
    cout<<dp[s]<<endl;
}

Measured memory_bytes: 3600
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define reg register
#define rep(i, a, b) for (reg int i = (a), i##end = (b); i <= i##end; ++i)
#define dep(i, a, b) for (reg int i = (a), i##end = (b); i >= i##end; --i)

template <typename _typer> inline _typer read() {
    _typer init = 0;
    char ch = getchar(), k = 0;
    for ( ; !isdigit(ch); ch = getchar()) k = (ch == '-');
    for ( ; isdigit(ch); ch = getchar())
        init = (init << 3) + (init << 1) + (ch ^ 48);
    return k ? -init : init;
}
const ll N = 0, INF = 1e9;

/*******************************************************************************
 *
 *
 *
 ******************************************************************************/

int main() {
    int n = read<int>();
    int Ans = 0;
    if (n) Ans += min(9, n);
    if (n >= 100) Ans += min(999 - 99, n - 99);
    if (n >= 10000) Ans += min(99999 - 9999, n - 9999);
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
cnt = 1
for i in range(n):
    if a[i] == cnt:#すねけさんが満足するレンガの砕き方は1,2,3...となってるのが前提なので1の後には2が2の後には3が存在しないとダメ
        cnt += 1
if cnt == 1:
    print(-1)
    exit()
print(n-cnt+1)#cntを1で初期化してるので+1をする

Measured memory_bytes: 24872
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<vector>
#include<cmath>
#include<algorithm>
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define rFOR(i, a, b) for(int i=b-1; i>=a; i--)
#define MAX 10000
typedef long long ll;
using namespace std;

int main(void){
  int n; cin>>n;
  set<int> st;
  rep(i, n){
    int d; cin>>d;
    st.insert(d);
  }
  cout << st.size() << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repc(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
#define DBG(str) cerr<<(str)<<endl;
int main() {
	int n;
	cin >> n;
	if (n >= 1000)cout << "ABD";
	else cout<<"ABC";
	return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <map>
#include <cmath>
#include <bitset>
#include <deque>
#define MAX_N 100
#define MAX_T 200
#define INF 4000000000000000000
#define fst first
#define snd second
typedef long long ll;
typedef std::pair<int,int> ii;
using namespace std;

int main(){
  int n,a;
  cin>>n>>a;
  cout<<n*n-a<<endl;
  return 0;
}


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

int b[200];

int main() {
	int n, ans=0;
	cin>>n;
	for(int i=2; i<=n; i++) cin>>b[i];
	for(int i=2; i<n; i++) ans+=min(b[i], b[i+1]);
	ans+=b[2]+b[n];
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s0 = input()
d = {}
for sk in s0:
    if sk in d.keys():
        d[sk] += 1
    else:
        d[sk] = 1

for i in range(1, n):
    si = input()
    for key in d.keys():
        if d[key] == 0:
            continue
        x = si.count(key)
        if x < d[key]:
            d[key] = x
ans = []
for key, sk in d.items():
    for _ in range(sk):
        ans.append(key)
ans.sort()
print(''.join(ans))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//STANDARD DATA TYPES
#define ll long long
#define llu unsigned long long
#define ld long double
//ADV DATA TYPES
#define pii pair < int , int >
#define pll pair < ll, ll >
#define mp make_pair
#define ff first
#define ss second
//C ++ DS
#define vi vector < int >
#define vll vector < ll >
#define pb push_back
#define pf push_front
#define iter :: iterator
#define all(x) x.begin(),x.end()

//priority_queue < pii, vector < pii >, greater < pii > > pq;
//lower_bound(v.begin(),v.end(),20);//for any sorted container
//CONSTANTS
#define MOD (int)(1e9+7)
#define INF 0x3f3f3f3f
#define MAXN (int)(101)
//MOD OPERATIONS
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
inline ll addmod(ll a, ll val, ll p = MOD) {{if ((a = (a + val)) >= p) a -= p;} return a;}
inline ll submod(ll a, ll val, ll p = MOD) {{if ((a = (a - val)) < 0) a += p;}return a;}
inline ll mult(ll a, ll b, ll p = MOD) {return (ll) a * b % p;}
//DEBUG
#define shout()  {cout << "I'm Here...!!!" << endl;}
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }

int main()
{
	fastio;
	string s;
	cin>>s;
	ll len=s.size();
	ll d;cin>>d;
	vector< vll >dp(d,vll(2,0)),newdp(d,vll(2,0));
	//dp[i][sum][less considered]-considering i digits how many possible ways 
	//to get sum of digits so far %d as sum,if any digit has been decreaased or not
	for(ll i=0;i<len;i++)
	{
		if(i==0)
		{
			for(ll digit=0;digit<=(ll)(s[0]-'0');digit++)
			{
				if(digit<(ll)(s[0]-'0'))
				{
					newdp[digit%d][1]=addmod(newdp[digit%d][1],1);
					
				}
				else
				{
					newdp[digit%d][0]=addmod(newdp[digit%d][0],1);

				}
				//cout<<newdp[digit%d][0]<<" "<<newdp[digit%d][1]<<endl;
			}
			dp=newdp;
			continue;
		}
		fill(newdp.begin(),newdp.end(),vll(2,0));
		for(ll sum=0;sum<d;sum++)
		{
			for(ll less_cons=0;less_cons<=1;less_cons++)
			{
				for(ll dig=0;dig<=9;dig++)
				{
					if(dig>(ll)(s[i]-'0') && !less_cons)break;
					newdp[(sum%d +dig%d)%d][less_cons||(dig<(ll)(s[i]-'0')?1:0)]=addmod(newdp[(sum%d +dig%d)%d][less_cons||(dig<(ll)(s[i]-'0')?1:0)],dp[sum][less_cons]);
				}
			}
		}
		dp=newdp;
	}

	ll res=addmod(newdp[0][0],newdp[0][1]);
	res=submod(res,1);
	cout<<res<<endl;

}


Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <cstdio>
#include<string>
#include<map>
#include <algorithm>
#include <cmath>
#include<vector>
#include<stack>
#define INF 0x3f3f3f3f  
#define maxn 1000000+10
using namespace std;
int a[3];
int main()
{
	for (int i = 0; i < 3; i++)
		cin >> a[i];
	sort(a, a + 3);
	if ((2 * a[2] - a[1] - a[0]) % 2 == 0)
	{
		cout<<(2 * a[2] - a[1] - a[0]) / 2 << endl;
		return 0;
	}
	else
	{
		double x = (2 * a[2] - a[1] - a[0]);
		int y = 0.5*x + 1.5;
		cout << y << endl;
	}
	return 0;
}

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

int main() {
	int n, a[100], v, j;
	cin >> n;
	for (int i = 0; i<n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i<n; i++) {
		for (int k = 0; k<n; k++) {
			cout << a[k];
			if (k != n - 1)cout << " ";
		}
		cout << endl;
		v = a[i];
		j = i - 1;
		while (j >= 0 && a[j]>v) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;
	}
	for (int k = 0; k<n; k++) {
		cout << a[k];
		if (k != n - 1)cout << " ";
	}
	cout << endl;
}


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


int main() {
	int n;
	cin>>n;
	vector<tuple<string,int,int>> list(n);//初期化用は()の利用
	
	for(int i=0;i<n;i++){
		string s;
		int t;
		
		cin>>s>>t;
		t=-t;
		
		list[i]=make_tuple(s,t,i+1);
	}
	
	sort(list.begin(),list.end());
	for(int i=0;i<n;i++)cout<<get<2>(list[i])<<endl;//list[i]でも可
}

//vector,tuple,pairの取り扱いわからんWA

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		int C=sc.nextInt();
		int X=sc.nextInt();
		int count=0;
		for(int i=0;i<=A;i++){
			for(int j=0;j<=B;j++){
				for(int k=0;k<=C;k++){
					if(i*500+j*100+k*50==X){
	count+=1;
					}
				}
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21716
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#define MAX 100
using namespace std;
vector<int> zhongxu,qianxu;
struct node{int key;node *p,*l,*r;};
node *root,*NIL;

void insert(int num){
	node *y=NIL;node *x=root;node *z;
	z=(node *)malloc(sizeof(node ));
	while(x!=NIL){
		y=x;
		if(num<x->key){x=(*x).l;}
		else {x=x->r;}
	}
	z->key=num;z->l=NIL;z->r=NIL;z->p=y;
	if(y==NIL){
		root=z;
	}else if(num>y->key){
		y->r=z;
	}else{y->l=z;}
}
void zhong(node *u){
	if(u->l!=NIL) zhong(u->l);
	cout<<" "<<u->key;
	if(u->r!=NIL) zhong(u->r);
	return ;
}
void qian(node *u){
	cout<<" "<<u->key;
	if(u->l!=NIL) qian(u->l);
	if(u->r!=NIL) qian(u->r);
	return;
}
void print(node *u){
	zhong(u);cout<<endl;
	qian(u);cout<<endl;return;
}
node* find(int num){
	node *p=root;
	 while(p!=NIL&&p->key!=num){
	 	if(num<p->key) p=p->l;
	 	else if(num>p->key) p=p->r;
	 }
	 return p;
}
node* get_min(node *d){
	d=d->r;
	while(d->l!=NIL){
		d=d->l;
	}
	return d;
}
int isroot(node*p){
	if(p->p==NIL) return 1;else return 0;
}
void shan(int num){
	node *p=find(num);
	node *new_node=p;
	if(p->l!=NIL&&p->r!=NIL){
		new_node=get_min(p);p->key=new_node->key;
	}
	node* child;
	if(new_node->l!=NIL){
		child=new_node->l;
	}else child=new_node->r;
	if(child!=NIL) {
		child->p=new_node->p;
		if(isroot(new_node)){
			root=child;
		}else if(new_node->p->l==new_node){
			new_node->p->l=child;
		}else{
			new_node->p->r=child;
		}
	}else{
		if(new_node->p->l==new_node){
			new_node->p->l=NIL;
		}else{
			new_node->p->r=NIL;
		}
	}
	return ;
}
int main(){
	int cnt;int num;
	scanf("%d",&cnt);
	char order[10];
	for(int i=0;i<cnt;i++){
		scanf("%s",&order);
		if(order[0]=='i') {
		scanf("%d",&num);insert(num);
		}
		else if(order[0]=='p') {print(root);
		}else if(order[0]=='f'){scanf("%d",&num);
		if(find(num)!=NIL){cout<<"yes"<<endl;
		}else{
			cout<<"no"<<endl;  
		}
			
		}else if(order[0]=='d'){scanf("%d",&num);
			shan(num);
		}
	}
}


Measured memory_bytes: 21904
--Koch-recursion
type Coord= (Double,Double)

koch_n_vertex::Int -> [Coord]
koch_n_vertex 0 = [(1.0,0.0)]
koch_n_vertex n = let rec = koch_n_vertex (n-1) in
                  let pt1 = map trans1 rec in
                  let pt2 = map trans2 rec in
                  let pt3 = map trans3 rec in
                  let pt4 = map trans4 rec in
                  pt1++pt2++pt3++pt4

trans1::Coord -> Coord
trans1 (x,y) = ((1/3)*x,(1/3)*y)

trans2::Coord -> Coord
trans2 coord = let (x',y')= rotate (pi/3) (trans1 coord) in (x'+(1/3),y')

trans3::Coord -> Coord
trans3 coord = let (x',y')= rotate ((-pi)/3) (trans1 coord) in (x'+(1/2),y'+((sin (pi/3))/3))

trans4::Coord -> Coord
trans4 coord = let (x',y')= trans1 coord in (x'+(2/3),y')

rotate::Double->Coord -> Coord
rotate rad (x,y) = let s = sin rad in let c = cos rad in ((x*c)-(y*s),(x*s)+(y*c))

solver::Int -> [Coord]
solver n = map (\(x,y)-> (100.0*x,100.0*y)) ((0.0,0.0):koch_n_vertex n)

printer::Show a => [(a,a)]-> IO ()
printer [] = return ()
printer ((x,y):xs) = do
  putStr ((show x)++" "++(show y)++"\n")
  printer xs

main::IO()
main = do
  nc<-getLine
  let n= read nc ::Int
  printer (solver n)

Measured memory_bytes: 4776
#include<stdio.h>

int main()
{
 int A, B, C, D;
 int ans=0;;

 scanf("%d %d %d %d",&A,&B,&C,&D);
 if((B>=C)&(D>=B)&(A<=C)) ans = (B-C);
 if((B>=C)&(D<=B)&(A<=C)) ans = (D-C);
 if((A>=C)&(B<=D)&(A<=D)) ans = (B-A);
 if((A>=C)&(D<=B)&(A<=D)) ans = (D-A);
 printf("%d\n",ans);

 return 0;
}

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

int main() {
  int n,m,tmp;
  int64_t sum = 0;
  cin >> n >> m;
  
  priority_queue<int> pr;
  
  for(int i=0;i<n;i++){
    cin >> tmp;
    pr.push(tmp);
  }
  
  for(int i=0;i<m;i++){
    tmp = pr.top();
    pr.pop();
    tmp /= 2;
    pr.push(tmp);
  }
  for(int i=0;i<n;i++){
    sum += pr.top();
    pr.pop();
  }
  
  cout << sum << endl;
  
}


Measured memory_bytes: 892
#include <iostream>

using namespace std;
using ll = long long;

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

int main() {
  int x;
  cin >> x;
  int c500 = x / 500;
  int c5 = (x - c500 * 500) / 5;

  cout << c500 * 1000 + c5 * 5 << '\n';
  return 0;
}


Measured memory_bytes: 256
function Main(input) {

	input = input.split(" ");
	
    let D = parseInt(input[0]);
    let T = parseInt(input[1]);
    let S = parseInt(input[2]);

    let time = D/S;

    if (T >= time) {
        console.log('Yes');
    } else {
        console.log('No');
    }
    
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29680
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, K;
  cin >> N >> M >> K;
  vector<int> Abook(N); //Aの本棚の本を読む時間
  vector<int> Bbook(M); //Bの本棚の本を読む時間
  for (int i = 0; i < N; i++) {
    cin >> Abook[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> Bbook[i];
  }
  long long time = 0; //整数のオーバーフロウ対策
  //Bの本をすべて読んだと仮定して、Bの本をしたから減らしつつAの本を追加して最大値を見る（尺取り法）
  for (int i = 0; i < M; i++) {
    time += Bbook[i];
  }
  int j = M;
  int ans = 0;
  for (int i = 0; i < N + 1; i++) {   
    while (j > 0 && time > K) { // Bの本が尽きず、時間が超過している場合
      j--; 
      time -= Bbook[j]; //Bの残っている一番下の本を諦める
    }
    if (time > K) {
      break;
    } //時間が足りないのでもう一周
    ans = max(ans, i + j); //一応0冊の場合を考慮
    if (i == N) {
      break;
    } //Aの本が尽きたので
    time += Abook[i]; //時間が余ってるのでAの本を足す
  }
  cout << ans << endl;
}


Measured memory_bytes: 4844
// Problem : C - Forbidden List
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_c?lang=en
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)n;i++)
#define REP(i,n) for(int i=0;i<(int)n;i++)
#define ll long long
#define mod 1000000007
const ll INF = 1000000001;
int lcm(int x,int y){
	return x/__gcd(x,y)*y;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    set<int>st;
    for(int i=0;i<m;i++){
    	int x;
    	cin>>x;
    	st.insert(x);
    }
    int ans=INF;
    int diff=INF;
    for(int i=0;i<=101;i++){
    	if(st.count(i))continue;
    	int di=abs(n-i);
    	if(di<diff){
    		diff=di;
    		ans=i;
    	}
    }
    cout<<ans<<endl;
    return 0;
}


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

int N, P;

const int MAX_C = 100;
long long Com[MAX_C][MAX_C];

void calc_com() {
    Com[0][0] = 1;
    for (int i = 1; i < MAX_C; ++i) {
        Com[i][0] = 1;
        for (int j = 1; j < MAX_C; ++j) {
            Com[i][j] = (Com[i-1][j-1] + Com[i-1][j]);
        }
    }
}

int main() {
  calc_com();
  while (cin >> N >> P) {
	long long even = 0, odd = 0;
	for (int i = 0; i < N; ++i) {
	  int a; cin >> a;
	  if (a & 1) ++odd;
	  else ++even;
	}
	long long evenbit = 1LL<<even;
	long long oddbit = 0;
	for (int i = 0; i <= odd; ++i) {
	  if (i % 2 == P) {
		oddbit += Com[odd][i];
	  }
	}
	cout << evenbit * oddbit << endl;
	
  }
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#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 mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    ll A=1,B=1;
    rep(i,n){
        int t,a; cin>>t>>a;
        ll m = max((A+t-1)/t, (B+a-1)/a);
        A = m*t; B = m*a;
    }
    cout<<A+B<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

vector<pair<ll,int>> factorize(ll n) {
  vector<pair<ll,int>> res;
  for (ll i = 2; i*i <= n; ++i) {
    if (n % i) continue;
    res.emplace_back(i,0);
    while (n%i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n,1);
  return res;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  ll n;
  cin >> n;
  auto res = factorize(n);
  ll ans = 0;
  for (auto && x : res) {
    // debug(x.first, x.second);
    ll m = 1;
    while(true) {
      if (m*(m+1)/2 <= x.second && (m+2)*(m+1)/2 > x.second) break;
      m++;
    }
    ans += m;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3656
c = {}
n = gets.to_i
n.times {
  d = gets.chomp
  if c.has_key?(d)
    c[d] += 1
  else
    c[d] = 1
  end
}
n = gets.to_i
n.times {
  d = gets.chomp
  if c.has_key?(d)
    c[d] -= 1
  else
    c[d] = -1
  end
}


puts (c.values + [0]).max


Measured memory_bytes: 1788
import queue
from collections import deque
h,w,n = map(int,input().split())
factrys = [None] * (n + 1)
ss = ["X" * (w + 2)]
for i in range(h):
  s = "X" + input() + "X"
  if "S" in s:
    factrys[0] = (i + 1, s.index("S"))
  for j in range(1,n + 1):
    if str(j) in s:
      factrys[j] = (i + 1, s.index(str(j)))
  ss.append(s)
ss.append("X" * (w + 2))

def bfs(i):
  mp = [[None] * (w + 2) for j in range(h + 2)]
  x,y = factrys[i]
  mp[x][y] = 0
  que = deque()
  que.append((x, y))
  while True:
    (x,y) = que.popleft()
  #  print(i,x,y)
  #  print(mp[x][y])
    if (x,y) == factrys[i + 1]:
      return mp[x][y]
    count = mp[x][y]
    if ss[x + 1][y] != "X" and mp[x + 1][y] is None:
      mp[x + 1][y] = count + 1
      que.append((x + 1, y))
    if ss[x - 1][y] != "X" and mp[x - 1][y] is None:
      mp[x - 1][y] = count + 1
      que.append((x - 1, y))
    if ss[x][y + 1] != "X" and mp[x][y + 1] is None:
      mp[x][y + 1] = count + 1
      que.append((x, y + 1))
    if ss[x][y - 1] != "X" and mp[x][y - 1] is None:
      mp[x][y - 1] = count + 1
      que.append((x, y - 1))

ans = 0
for i in range(n):
  ret = bfs(i)
  if ret is None:
    ans += 0
  else:
    ans += (ret)
print(ans)


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

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

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

/* O(log n)
  - 与えられた区間での最小値を求める
  - 一つの要素の値の変更
*/

static const int MAX_N = 1 << 17;

// セグメント気を持つグローバル配列
int n, dat[2 * MAX_N - 1];

// 初期化 n_個のの要素
void init(int n_) {
  // 簡単のため、要素数を2のべき乗に
  n = 1;
  while (n < n_) {
    n *= 2;
  }

  rep(i, 0, 2 * n - 1) dat[i] = INT_MAX;
};

// k番目の値をaに変更
void update(int k, int a) {
  // 葉の節点
  k += n - 1; //根を0番目としたときの節点番号
  dat[k] = a;
  // 登りながら更新
  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
  }
};

// [a, b)区間の最小値を求める
// 後ろの方の引数は計算の簡単のための引数
// kは接点の番号、l, rはその節点が[l, r)に対応づいていることを表す
// したがって、外からはquery(a, b, 0, 0, n)として呼ぶ
int query(int a, int b, int k, int l, int r) {
  // 交差なし
  if (r <= a || b <= l) {
    return INT_MAX;
  }

  // [a, b) が[l, r)を完全に含んでいる場合
  if (a <= l && r <= b) {
    return dat[k];
  } else {
    int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
};

int main() {
  int n_, q;
  cin >> n_ >> q;
  init(n_);

  int com, x, y;
  rep(i, 0, q) {
    cin >> com >> x >> y;
    if (com == 0) {
      update(x, y);
    }
    if (com == 1) {
      cout << query(x, y+1, 0, 0, n) << endl;
    }
  }

  return 0;
};



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

int main()
{
	int H, W;
	while (1) {
		std::cin >> H >> W;
		if (H == 0 && W == 0)break;

		for (auto i = 0; i < H; i++) {
			for (auto j = 0; j < W; j++) {
				if (i == 0 || i == H - 1 || j == 0 || j == W - 1)
					std::cout << '#';
				else
					std::cout << '.';
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;
	}
}

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

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

int n, m, bit;

inline void printEdge(int u, int v) {
	write(u);
	putchar(' ');
	write(v);
	putchar('\n');
}

int main() {
	read(n);
	for (int i = 0; (1 << i) <= n; ++i)
		if (n == (1 << i)) {
			puts("No");
			return 0;
		}
	puts("Yes");
	printEdge(1, 2), printEdge(2, 3), printEdge(3, n + 1);
	printEdge(n + 1, n + 2), printEdge(n + 2, n + 3);
	for (int i = 4; i + 1 <= n; i += 2) {
		printEdge(1, i), printEdge(i, i + 1);
		printEdge(1, i + n + 1), printEdge(i + n + 1, i + n);
	}
	if (!(n & 1)) {
		for (int i = 0; (1 << i) <= n; ++i)
			if (n & (1 << i)) bit = i;
		printEdge(((1 << bit) ^ 1) + n, n), printEdge(n ^ (1 << bit), n << 1);
	}
	return 0;
}

Measured memory_bytes: 2304
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N,K=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
print(sum(p[:K]))

Measured memory_bytes: 62292
import numpy as np

# print('input >>')
N, K = map(int, (input().split()))
h = []
for _ in range(N):
    h.append(int(input()))

h.sort()
hdiff = [h[i + 1] - h[i] for i in range(len(h) - 1)]
hdiff = np.array(hdiff)
ans = np.sum(hdiff[0:0+K-1])
# print('hdiff: %s' % hdiff)
sum_ = np.sum(hdiff[0:0+K-1])
for i in range(1, N-K+1):
    # print('i %s' % i)
    # print('hdiff[i:i+K-1]: %s' % hdiff[i:i+K-1])]
    sum_ = sum_-hdiff[i-1]+hdiff[i+K-2]
    ans = min(ans, sum_)

# print('----------output----------')
print(ans)

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

int main (){
  int n, m, c;
  cin >> n >> m >> c;
  int b[m];
  int a[n][m];
  int i, j;
  for(i=0;i<m;i++){
    cin >> b[i];
  }
  
  for(j=0;j<n;j++){
    for(i=0;i<m;i++){
      cin >> a[j][i];
    }
  }
  
  int sum, solution = 0;
  
  for(i=0;i<n;i++){
    sum = c;
    for(j=0;j<m;j++){
      sum += b[j]*a[i][j];
    }
    if(sum>0)solution++;
  }
  
  cout << solution << endl;
  return 0;
}


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

using namespace std;
constexpr int MOD = 998'244'353;

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

    int N;
    cin >> N;
    vector<int> D(N), cnt(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> D[i];
        ++cnt[D[i]];
    }
    if (cnt[0] > 1 || D[0] != 0) {
        cout << 0 << "\n";
        return 0;
    }
    int res = 1;
    for (int i = 1; i < N; ++i) {
        for (int j = 0; j < cnt[i]; ++j)
            res = (1LL * res * cnt[i - 1]) % MOD;
    }
    cout << res << "\n";


    return 0;
}

Measured memory_bytes: 1024
# coding: utf-8
"""Snuke's Coloring 2 (ABC Edit)

@author: hijiri.n
@modified: 11-19-2016

"""

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


def solve():
    w, h, N = data()
    rect = [0, w, 0, h]

    for i in range(N):
        x, y, a = data()
        if [1, -1][a % 2] * ([x, y][a > 2] - rect[a - 1]) < 0:
            rect[a - 1] = [x, y][a > 2]
        
        if (rect[1] - rect[0]) <= 0 & (rect[3] - rect[2]) <= 0:
            return 0

    return (rect[1] - rect[0]) * (rect[3] - rect[2])

print(solve())

Measured memory_bytes: 3064