akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ctype.h>
using namespace std;

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int triangle(int a, int b, int c) {
    int maxNum = 0;

    maxNum = max({a, b, c});
    if (a == maxNum) {
        return b * c / 2;
    }
    if (b == maxNum) {
        return a * c / 2;
    }
    if (c == maxNum) {
        return a * b / 2;
    }
}
int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int a, b, c;
    cin >> a >> b >> c;

    // 処理
    // 出力
    cout << triangle(a, b, c) << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

N = int(readline())
MOD = 10**9 + 7
last = [-1]*(3*10**5)
dp = [0]*(N+1)
dp[0] = 1
for i in range(1, N+1):
    c = int(readline())
    if last[c] != -1 and last[c]+1 < i:
        dp[i] = (dp[last[c]] + dp[i-1]) % MOD
    else:
        dp[i] = dp[i-1]
    last[c] = i
print(dp[N])

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

#ifdef DONLINE_JUDGE
//freopen("a.in", "r", stdin);
//freopen("a.out","w",stdout); // console output is better (in most cases)
#else
// add i/o method of specific testing system
#endif

using namespace std;

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

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

    int sum = 0;
    for (int i = a; i <= b; ++i)
    {
        if (c % i == 0)
            ++sum;
    }
    cout << sum << endl;

    return 0;
}


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

int main(void) {
  int N, all_sum = 0, sum_right = 0, ans = 200000;
  cin >> N;
  int W[N];
  for (int i = 0; i < N; i++) {
    cin >> W[i];
    all_sum += W[i];
  }
  for (int i = 0; i < N - 1; i++) {
    sum_right += W[i];
    ans = min(abs(sum_right - (all_sum - sum_right)), ans);
  }
  cout << ans << endl;
  return 0;
}

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

static int top, S[1000];

void push(int x){
  S[++top] = x;
}

int pop(){
  return S[top--];
}

int main(){
  int a, b;
  char c[100];
  while((scanf("%s ", &c))!=EOF){
    if(c[0]=='+'){
      a = pop();
      b = pop();
      push(a+b);
    }else if(c[0]=='-'){
      b = pop();
      a = pop();
      push(a-b);
    }else if(c[0]=='*'){
      a = pop();
      b = pop();
      push(a*b);
    }else{
      push(atoi(c));
    }
  }
  printf("%d\n", pop());
}

Measured memory_bytes: 3176
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<Integer>[] lists = new ArrayList[n];
    int[] col = new int[n];
    int[] part = new int[n];
    long[] diff = new long[n];

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

    void run() {

        for (int i=0; i<n; i++) col[i] = sc.nextInt() - 1;
        for (int i=0; i<n; i++) lists[i] = new ArrayList<>();
        for (int i=0; i<n-1; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            lists[a].add(b);
            lists[b].add(a);
        }

//        System.out.println(lists[0]);

        dfs(0, -1, 0);

        StringBuilder sb = new StringBuilder();

        for (int i=0; i<n; i++) {
            long tmp = n - part[i];
            diff[i] += tmp * (tmp + 1) / 2;
        }

        for (int i=0; i<n; i++) {
            long total = (long)n * (long)(n + 1) / (long)2;
            sb.append( total - diff[i] + "\n");
        }

        System.out.println(sb.toString());

    }

    void dfs(int v, int p, int pSize) {
        int size = pSize;
        for (int next: lists[v]) {
            if (next != p) {
                int tmpCur = part[col[v]];
                int tmpNext = part[col[next]];
                dfs(next, v, tmpNext);
                int total = part[col[next]] - tmpNext;
                long val = total - (part[col[v]] - tmpCur);
                diff[col[v]] += val * (val + 1) / 2;
                size += total;
            }
        }
        size++;
        part[col[v]] = size;
    }
}




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

using namespace std;
const int N = 2e3 + 10;
int a[N], mn[N][N];

int main()
{
  	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, x; cin >> n >> x;
    long long ans = 0;
    for (int i = 0; i < n; i++) cin >> a[i], mn[i][0] = a[i], ans += a[i];
    for (int t = 1; t < n; t++) {
        long long res = 1ll * t * x;
        for (int i = 0; i < n; i++) mn[i][t] = min(mn[(i - 1 + n) % n][t - 1], a[i]), res += mn[i][t];
        ans = min(ans, res);
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 16000
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double[] a = new double[n];
		double[] b = new double[n];
		double[] c = new double[n];
		for (int i = 0; i < n; i++) a[i] = sc.nextLong();
		for (int i = 0; i < n; i++) b[i] = sc.nextLong();
		for (int i = 0; i < n; i++) c[i] = sc.nextLong();

		Arrays.sort(a);
		Arrays.sort(c);

		long answer = 0;
		for (int i = 0; i < n; i++) {
			long ai = Arrays.binarySearch(a, b[i] - 0.1);
			long ci = Arrays.binarySearch(c, b[i] + 0.1);

			answer += (-1 - ai) * (n + ci + 1);
		}

		System.out.println(answer);
	}
}


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


int main()
{
	int N;
	cin>>N;
	vector<ll> A(N);
	rep(i,N) cin>>A[i];
	vector<ll> dp;
	for(int a : A)
	{
		if(dp.size()==0||dp[dp.size()-1]>=a)
		{
			dp.push_back(a);
		}
		else
		{
			int head=-1;
			int tail=dp.size();
			while(tail-head>1)
			{
				int mid=head+(tail-head)/2;
				if(dp[mid]<a)
				{
					tail=mid;
				}
				else
				{
					head=mid;
				}
			}
			dp[tail]=a;
		}
	}
	cout<<dp.size()<<endl;
	return 0;
}


Measured memory_bytes: 5088
#include<bits/stdc++.h>
using namespace std;
long long int n,m,i,j,k,l,arr[100009];
int main()
{
    scanf("%lld %lld %lld",&n,&k,&m);
    for(i=1;i<=k;i++)
        arr[i]=m;
    if(m>n)
        l=1;
    else
        l=m+1;
    for(i=k+1;i<=n;i++)
        arr[i]=l;
    for(i=1;i<=n;i++)
        printf("%lld ",arr[i]);
}


Measured memory_bytes: 2048
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

struct yoko{
	int h;
	int from;
	int to;
	bool operator<(const yoko& right) const {
		return h < right.h;
	}
};

int main() {
	int n, m, a;
	while (cin >> n >> m >> a, n | m | a){
		vector<yoko> y;

		REP(i, m){
			int j, k, l;
			cin >> j >> k >> l;
			y.push_back({ j, k, l });
		}
		sort(y.begin(), y.end());
		reverse(y.begin(), y.end());

		REP(i, y.size()){
			if (a == y[i].from){
				a = y[i].to;
			}
			else if (a == y[i].to){
				a = y[i].from;
			}
		}
		cout << a << endl;
	}
}

Measured memory_bytes: 1240
local n = io.read("*n", "*l")
local t = {}
t["M"], t["A"], t["R"], t["C"], t["H"] = 0, 0, 0, 0, 0
local str, sstr = "", ""
for i = 1, n do
  str = io.read()
  sstr = string.sub(str, 1, 1)
  if(t[sstr] ~= nil) then t[sstr] = t[sstr] + 1 end
end
local sum = 0
sum = sum + t["M"] * t["A"] * t["R"]
sum = sum + t["M"] * t["A"] * t["C"]
sum = sum + t["M"] * t["A"] * t["H"]
sum = sum + t["M"] * t["R"] * t["C"]
sum = sum + t["M"] * t["R"] * t["H"]
sum = sum + t["A"] * t["R"] * t["C"]
sum = sum + t["A"] * t["R"] * t["H"]
sum = sum + t["A"] * t["C"] * t["H"]
sum = sum + t["M"] * t["C"] * t["H"]
sum = sum + t["R"] * t["C"] * t["H"]
print(sum)



Measured memory_bytes: 376
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#define rep(x, l, r) for(int x = l; x <= r; x++)
#define repd(x, r, l) for(int x = r; x >= l; x--)
#define clr(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define MAXN 100005
#define fi first
#define se second
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int INF = 1 << 30;
const int p = 1000000007;
int lowbit(int x){ return x & (-x);}
int fast_power(int a, int b){ int x; for(x = 1; b; b >>= 1){ if(b & 1) x = 1ll * x * a % p; a = 1ll * a * a % p;} return x % p;}

int a[MAXN];
int fac[MAXN], inv[MAXN], fi[MAXN];

int C(int a, int b){
	if(b > a) return 0;
	return 1ll * fac[a] * fi[b] % p * fi[a - b] % p;
}

int main(){
	fac[0] = inv[1] = fi[0] = 1;
	int n, k;
	scanf("%d%d", &n, &k);
	rep(i, 1, n) fac[i] = 1ll * fac[i - 1] * i % p;
	rep(i, 2, n) inv[i] = 1ll * (p - p / i) * inv[p % i] % p;
	rep(i, 1, n) fi[i] = 1ll * fi[i - 1] * inv[i] % p;
	rep(i, 1, n) scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	int ans = 0;
	rep(i, 1, n){
		ans = (ans + p - 1ll * a[i] * C(n - i, k - 1) % p) % p;
		ans = (ans + 1ll * a[i] * C(i - 1, k - 1) % p) % p;
	}
	printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(void){
    int N, A;
    cin >> N;
    string ans = "APPROVED";
    for(int i = 0; i < N; i++){
        cin >> A;
        if(A%2 == 0){
            if((A%3 != 0) && (A%5 != 0)){
                ans = "DENIED";
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// God put a smile upon your face <3

#include <bits/stdc++.h>

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

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

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

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

//    freopen("output.txt", "w", stdout);

    ll t, d, s;

    while(cin >> d >> t >> s)
    {
		n = t * s;

		if(n < d) cout << "No\n";
		else cout << "Yes\n";
    }


}




Measured memory_bytes: 3636
using static System.Math;using static System.Console;using System.Collections.Generic;using System.Linq;using System;using System.Collections;

class Program
{
    #region Reader
    static string ReadStr => Console.ReadLine();
    static string[] ReadStrs => Console.ReadLine().Split(' ');
    static int ReadInt => Convert.ToInt32(Console.ReadLine());
    static int[] ReadInts => Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
    static long ReadLong => Convert.ToInt64(Console.ReadLine());
    static long[] ReadLongs => Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
    #endregion
    #region Method
    const int mod = 1000000007;
    public static int Mod(int a,int mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    public static long Mod(long a, long mod = mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    #endregion


    static void Main()
    {
        int[] VE = ReadInts;
        int V = VE[0];
        int E = VE[1];


        List<int[]>[] roads = new List<int[]>[V];
        for (int i = 0; i < V; i++)
        {
            roads[i] = new List<int[]>();
        }
        for (int i = 0; i < E; i++)
        {
            int[] vs = ReadInts;
            roads[vs[0]].Add(new int[2] { vs[1], vs[2] });
        }

        int infty = 1000000000;
        //コストのbitDP[通った集合,現在の位置]
        int[,] dp = new int[(int)Pow(2, V),V];
        for (int i = 0; i < (int)Pow(2,V); i++)
        {
            for (int j = 0; j < V; j++)
            {
                dp[i, j] = infty;
            }
        }

        dp[0,0] = 0;


        for (int s = 0; s < (int)Pow(2, V); s++)
        {
            int[] bits = ToNSinsu(s, 2, V);
            for (int i = 0; i < V; i++)
            {

                foreach (int[] road in roads[i])
                {
                    if (bits[road[0]] == 1) {
                        continue;
                    }

                    dp[s + (int)Pow(2, road[0]), road[0]] = Min(dp[s + (int)Pow(2, road[0]), road[0]],dp[s, i] + road[1]);
                }
            }
        }

        WriteLine(dp[(int)Pow(2, V) - 1, 0] != infty ? dp[(int)Pow(2, V) - 1, 0] : -1);


    }

    public static int[] ToNSinsu(int i, int baseNum, int digit)
    {
        int[] ans = new int[digit];
        int index = 0;
        while (i >= baseNum)
        {
            int d = i / baseNum;
            int r = i % baseNum;

            ans[index] = r;
            index++;
            i = d;
        }
        ans[index] = i;
        return ans;
    }


}



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

using namespace std;
int main () {
	int x;
	cin>>x;
	int a=x/500;
	int b=x%500;
	int c=b/5;
	int l=x/5;
	//int m=max()
	cout<<a*1000+c*5<<endl;
	return 0;
}



Measured memory_bytes: 256
from sys import stdin
from collections import deque
d=deque(list(stdin.readline().strip()))
N=list(map(int,stdin.readline().strip().split()))[0]
rev=False
for i in range(N):
    Q = list(stdin.readline().strip().split())
    if Q[0]=='1' :
        if rev==False:rev=True
        else:rev=False
    if Q[0]=='2':
        if Q[1]=='1':
            if rev==False:d.appendleft(Q[2])
            else:d.append(Q[2])
        if Q[1]=='2':
            if rev == False:
                d.append(Q[2])
            else:
                d.appendleft(Q[2])
# if rev==False:[print(x,end="") for x in d]
# else:[print(d[x],end="") for x in range(len(d)-1,-1,-1)]
if rev==False:[print(d.popleft(),end="") for x in range(len(d))]
else:[print(d.pop(),end="") for x in range(len(d))]

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


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<setprecision(10)<<fixed;
	
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int t1,t2;
	t1=a/d;
	t2=c/b;
	if(a%d!=0)
		t1++;
	if(c%b!=0)
		t2++;
	//cout<<t1<<" "<<t2<<endl;
	if(t1>=t2)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <cmath>
#define int long long
using namespace std;
const int mo = 2019;
main()
{
    int l,r;
    cin >> l >> r ;
    if( r - l >= 2019 ) { cout << 0 << endl;}
    else
    {
        int ans = 2019;
        for( int i = l; i < r; i++ )
        {
            for( int j = i + 1; j <= r; j++ )
            {
                ans = min( ans, ( i %mo ) * ( j % mo ) % mo );
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }

  bool a;
  for(int i=0;i<N;i++){
    if(A.at(i)%2==0){
      if(A.at(i)%6==0 || A.at(i)%10==0){
        a=true;
      }
      else{
        a=false;
        break;
      }
    }
  }
  if(a){
    cout << "APPROVED" << endl;
  }
  else{
    cout << "DENIED" << endl;
  }
}

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

const int N = 5005;

char s[N], t[N];
vector <int> A[2], B[2];
int n;

int solve(vector <int> a, vector <int> b) {
  if(a.size() < b.size()) swap(a, b);
  int ans = 2e9;
  for(int bef = 0; bef <= a.size(); ++ bef) {
    int res = 0;
    vector <int> A, B; A.clear(); B.clear();
    for(int j = 1; j <= bef; ++ j) B.push_back(0);
    for(int j = 0; j < (int) b.size(); ++ j) B.push_back(b[j]);
    A = a;
    while(A.size() < B.size()) A.push_back(n);
    while(B.size() < A.size()) B.push_back(n);
    for(int j = 0; j < (int) A.size(); ++ j)
      res += abs(A[j] - B[j]);
    ans = min(ans, res);
  }

  for(int bef = 0; bef <= a.size(); ++ bef) {
    int res = 0;
    vector <int> A, B; A.clear(); B.clear();
    for(int j = 1; j <= bef; ++ j) A.push_back(0);
    for(int j = 0; j < (int) a.size(); ++ j) A.push_back(a[j]);
    B = b;
    while(A.size() < B.size()) A.push_back(n);
    while(B.size() < A.size()) B.push_back(n);
    for(int j = 0; j < (int) A.size(); ++ j)
      res += abs(A[j] - B[j]);
    ans = min(ans, res);
  }
  
  return ans;
}

int main() {
  cin >> n;
  scanf("%s", s + 1);
  scanf("%s", t + 1);
  for(int i = 1; i <= n; ++ i) s[i] -= '0', t[i] -= '0';
  for(int i = 1; i < n; ++ i) {
    if(s[i] ^ s[i + 1]) A[s[i]].push_back(i);
    if(t[i] ^ t[i + 1]) B[t[i]].push_back(i);
  }
  if(n <= 2) {
    int ans = 0;
    for(int i = 1; i <= n; ++ i) ans += (s[i] != t[i]);
    cout << ans << endl;
    return 0;
  }
  int ans = 0;
  ans += solve(A[0], B[0]);
  ans += solve(A[1], B[1]);
  cout << ans << endl;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int n; cin >> n;
  vector<vector<int>> x(10, vector<int>(10, 0));

  for(int i = 1; i <= n; ++i) {
    string s = to_string(i);
    int a = s.front()-'0';
    int b = s.back()-'0';
    ++x[a][b];

  }
  int ans = 0;
  for(int i = 1; i < 10; ++i) for(int j = 1; j < 10; ++j) ans += x[i][j]*x[j][i];
  cout << ans << endl;
}

Measured memory_bytes: 3676
SA = list(input())
SB = list(input())
SC = list(input())


card = SA.pop(0)
while True:

    if card == "a":
        if len(SA) == 0:
            print("A")
            break
        card = SA.pop(0)
    elif card == "b":
        if len(SB) == 0:
            print("B")
            break
        card = SB.pop(0)
    elif card == "c":
        if len(SC) == 0:
            print("C")
            break
        card = SC.pop(0)


Measured memory_bytes: 9060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>

#define ll long long
#define sz 205

using namespace std;

int main()
{
    char str[sz];

    scanf("%s",str);

    ll len=strlen(str);

    while(1)
    {
        str[len-1]='\0';

        len--;

        if(len%2==0)
        {
            ll k=len/2,flag=0;

            for(ll i=0; i<len/2; i++)
            {
                if(str[i]!=str[i+k])
                {
                    flag=1;
                    break;
                }
            }

            if(flag==0)
            {
                printf("%lld\n",len);
                break;
            }
        }
    }

    return (0);
}




Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
typedef struct {
  char suit;
  char value;
} Card;
 
void bubbleSort(Card A[], int N) {
  for ( int i = 0; i < N; i++ ) {
    for ( int j = N - 1; j >= i; j-- ) {
      if ( A[j].value < A[j - 1].value ) {
        Card t = A[j];
        A[j] = A[j - 1];
        A[j - 1] = t;
      }
    }
  }
}
 
void selectionSort(Card A[], int N) {
  for ( int i = 0; i < N; i++ ) {
    int minj = i;
    for ( int j = i; j < N; j++ ) {
      if ( A[j].value < A[minj].value ) minj = j;
    }
    Card t = A[i];
    A[i] = A[minj];
    A[minj] = t;
  }
}
 
void print(Card A[], int N) {
  for ( int i = 0; i < N; i++ ) {
    if ( i > 0 ) cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}
 
bool isStable(Card C1[], Card C2[], int N) {
  for ( int i = 0; i < N; i++ ) {
    if ( C1[i].suit != C2[i].suit ) return false;
  }
  return true;
}
 
int main() {
  Card C1[100], C2[100];
  int N;
  char ch;
 
  cin >> N;
  for ( int i = 0; i < N; i++ ) {
    cin >> C1[i].suit >> C1[i].value;
  }
 
  for ( int i = 0; i < N; i++ ) C2[i] = C1[i];
 
  bubbleSort(C1, N);
  selectionSort(C2, N);
 
  print(C1, N);
  cout << "Stable" << endl;
  print(C2, N);
  if ( isStable(C1, C2, N) ) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }
 
  return 0;
}

Measured memory_bytes: 3100
#include<cstdio>
#include<algorithm>
using namespace std;
int a[105];
int n,x;
int main(){
    scanf("%d",&n);
    int sum = 0;
    for(int i = 1;i <= n;i++)
        scanf("%d",&a[i]),sum += a[i];
    if(sum % 10)
        printf("%d\n",sum);
    else{
        sort(a+1,a+1+n);
        for(int i = 1;i <= n;i++){
            if(a[i] % 10 != 0)
                return 0 * printf("%d\n",sum-a[i]);
        }
        printf("0\n");
    }
    return 0;
}

Measured memory_bytes: 128
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String []s=br.readLine().split(" ");
		int H = Integer.parseInt(s[0]);
		int A = Integer.parseInt(s[1]);
		
		if(H%A!=0)
			out.println((H/A)+1);
		else
			out.println((H/A));
	
	}
}




Measured memory_bytes: 20948
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
  using namespace std;
   using namespace std::chrono;      
  using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
 #define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        1e12
 #define sm         -2e18
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;
#define MEM(x,val) memset(x,val,sizeof(x))

 typedef tree<pii, null_type, less<pii>, rb_tree_tag,  
            tree_order_statistics_node_update>  odst; 



void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);
   
    #endif
}


const int Mxn = 1e5+1;
int par[Mxn] ;

int pr(int u)
{
  if(par[u]==u)
  {
    return u;
  }
  return par[u] = pr(par[u]);
}

void uni(int a,int b)
{
  int p1 = pr(a);
  int p2 = pr(b);
  par[p2] = p1;
}
void solve()
{
  int n,m;
  cin >> n >> m;

  forf(i,1,n+1)
  {
    par[i] = i;
  }
  

  forf(i,0,m)
  {
    int x,y;
    cin >> x >> y;
    uni(x,y);
  }

  set<int>g;
  forf(i,1,n+1)
  {
    g.insert(pr(i));
  }

  cout<<sz(g)-1;

}

int32_t main()
{
  pr_init();
  //fastio;
  auto start = high_resolution_clock::now(); 
  solve(); 
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    // cout << "Time taken by function: "
    //      << duration.count() << " microseconds" << endl; 

  return 0;
}

Measured memory_bytes: 8232
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as BS
import Data.Array.Unboxed
import Data.Array.IO
import qualified Data.Vector.Unboxed.Mutable as UM

main = do
  [h,w] <- map (read . BS.unpack) . BS.words <$> BS.getLine
  -- h, w <= 400
  ss <- V.replicateM h BS.getLine
  -- forall s in ss. BS.length s == w
  arr <- newArray ((0,0),(h-1,w-1)) (-1) :: IO (IOUArray (Int,Int) Int)
  num_b_w <- UM.new (h * w) :: IO (UM.IOVector (Int,Int))
  let search :: Int -> Int -> Int -> Int -> IO Int
      search !acc !k !i !j
        | i >= h = return acc
        | j >= w = search acc k (i+1) 0
        | otherwise = do
            v <- readArray arr (i,j)
            when (v == -1) $ do
              if (ss V.! i) `BS.index` j == '#'
                then search_black k i j -- black
                else search_white k i j
            (nb,nw) <- UM.read num_b_w k
            search (acc + nb * nw) (k+1) i (j+1)
      search_black :: Int -> Int -> Int -> IO ()
      search_black !k !i !j
        | i < 0 || j < 0 || i >= h || j >= w = return ()
        | (ss V.! i) `BS.index` j == '#' = do
            v <- readArray arr (i,j)
            when (v == -1) $ do
              writeArray arr (i,j) k
              UM.modify num_b_w (\(b,w) -> (b+1,w)) k
              search_white k (i-1) j
              search_white k i (j-1)
              search_white k (i+1) j
              search_white k i (j+1)
        | otherwise = return ()
      search_white :: Int -> Int -> Int -> IO ()
      search_white !k !i !j
        | i < 0 || j < 0 || i >= h || j >= w = return ()
        | (ss V.! i) `BS.index` j == '.' = do
            v <- readArray arr (i,j)
            when (v == -1) $ do
              writeArray arr (i,j) k
              UM.modify num_b_w (\(b,w) -> (b,w+1)) k
              search_black k (i-1) j
              search_black k i (j-1)
              search_black k (i+1) j
              search_black k i (j+1)
        | otherwise = return ()
  result <- search 0 0 0 0
  {-
  arr' <- freeze arr :: IO (UArray (Int,Int) Int)
  forM_ [0..h-1] $ \i -> do
    print [arr' ! (i,j) | j <- [0..w-1]]
  -}
  print result


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

using namespace std;

const int maxn = 100010;

int n, m;
vector<int> g[maxn];
vector<int> topol;
bool marked[maxn];
int dp[maxn];

void dfs(int v){
	marked[v] = true;
	for (int u: g[v]){
		if (!marked[u]){
			dfs(u);
		}
	}
	topol.push_back(v);
}

int main(){
	cin >> n >> m;
	for (int i = 0; i < m; i++){
		int u, v;
		cin >> u >> v;
		g[u-1].push_back(v-1);
	}
	
	for (int i = 0; i < n; i++){
		if (!marked[i]){
			dfs(i);
		}
	}
	
	int maxPath = 0;
	for (int i = 0; i < n; i++){
		int v = topol.at(i);
		for (int u: g[v]){
			dp[v] = max(dp[v], dp[u] + 1);
		}
		maxPath = max(dp[v], maxPath);
	}
	cout << maxPath << endl;
	return 0;
}


Measured memory_bytes: 8824
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const int Maxn=160010;
int n;
ll ans=0ll;
ll A[Maxn];
ll Cost[Maxn];
ll Prefix[Maxn];
inline int read()
{
    int fl=1,rt=0; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') fl=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){rt=rt*10+ch-'0'; ch=getchar();}
    return fl*rt;
}
void read_ini()
{
	n=read();
	for(int i=1;i<=n;i++) A[i]=read();
}
void Ini_Array()
{
	for(int i=1;i<=n+1;i++) Cost[i]=abs(A[i]-A[i-1]);
	for(int i=1;i<=n+1;i++) Prefix[i]=Prefix[i-1]+Cost[i];
}
void Make_Ans()
{
	for(int i=1;i<=n;i++)
	{
		ans=0;
		ans+=abs(A[i+1]-A[i-1]);
		ans+=Prefix[i-1];
		ans+=Prefix[n+1]-Prefix[i+1];
		printf("%I64d\n",ans);
	}
}
int main()
{
	read_ini();
	Ini_Array();
	Make_Ans();
	return 0;
}

Measured memory_bytes: 8960
#ifdef ConanYu
#include "local.hpp"
#else
#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void Main();
#define debug(...) do { } while(0)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
}
#endif

void Main() {
  int q; cin >> q;
  multiset<int> sa, sb;
  int x = 1000000000;
  ll bs = 0, fa = 0, fb = 0;
  while(q--) {
    int op, a, b; cin >> op;
    if(op == 2) {
      cout << x << " " << ((1ll * x * (ll)(sa.size()) - fa) + (fb - 1ll * x * (ll)(sb.size())) + bs) << "\n";
    } else {
      cin >> a >> b;
      bs += b;
      if(a <= x) {
        sa.insert(a);
        fa += a;
      } else {
        sb.insert(a);
        fb += a;
      }
      while(sa.size() > sb.size()) {
        auto it = sa.end();
        it--;
        sb.insert(*it);
        sa.erase(it);
        fa -= *it;
        fb += *it;
      }
      while(sa.size() < sb.size()) {
        auto it = sb.begin();
        sa.insert(*it);
        sb.erase(it);
        fa += *it;
        fb -= *it;
      }
      auto it = sa.end(); it--;
      x = *it;
    }
  }
}


Measured memory_bytes: 9600
#include <cstdio>
#include <vector>
#include <cstring>

#include <iostream>
#include <queue>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
/**********showtime************/

int main(){
      int a,b;
      cin>>a>>b;
      cout<<(a*3+b)/2<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n,m,x;
	cin>>n>>m;
	while(m--)
	{
		cin>>x;
		n-=x;
	}
	if(n<0)	cout<<"-1"<<endl;
	else	cout<<n<<endl;
 } 

Measured memory_bytes: 3644
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll gcd( ll a, ll b )
{
	ll c = a>b?a:b;
	ll d = a<b?a:b; 
	while(c%d)
	{
		ll e = c%d;
		c = d;
		d = e;
	}
	return d;
}
typedef long long ll;
int main()
{
	int k;
	cin>>k;
	ll sum = 0;
	for( int i=1; i<=k; i++ )
		for( int j=1; j<=k; j++ )
			for( int s=1;s<=k;s++)
				sum += gcd(i,gcd(j,s));
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3652
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n, l, r;
    while(cin >> n >> l >> r) {
        if(n == 0 && l == 0 && r == 0) break;
        vector<int> a(n + 1);
        rep(i, n) {
            cin >> a[i];
        }
        a[n] = 1;
        int ans = 0;
        for(int x = l; x <= r; ++ x) {
            rep(i, n + 1) {
                if(x % a[i] == 0) {
                    if(i % 2 == 0) {
                        ++ ans;
                    }
                    break;
                }
            }
        }
        cout << ans << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}


Measured memory_bytes: 3140
a, b, c, x, y = [int(s) for s in input().split()]
ans = 10 ** 9
for i in range(max(x, y) + 1):
    ans_temp = c * 2 * i + a * max(x - i, 0) + b * max(y - i, 0)
    if ans_temp < ans:
        ans = ans_temp
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
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)
#define all(x) begin(x),end(x)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int n,m;
	cin>>n>>m;
	vector<vector<ip>> pre(n,vector<ip>());
	vector<pair<int,pair<int,int>>> ans;
	REP(i,m){
		int p,y;
		cin>>p>>y;
		pre[--p].push_back(make_pair(y, i));
	}
	rep(i,n)sort(all(pre[i]));
	rep(i,n){
		int cnt = pre[i].size();
		rep(j,cnt){
			ip address = make_pair(i+1, j+1);
			ans.push_back(make_pair(pre[i][j].second, address));
		}
	}
	sort(all(ans));
	rep(i,m){
		printf("%06d%06d\n",ans[i].second.first,ans[i].second.second);
	}
}


Measured memory_bytes: 8308
def main():
	N = int(input())
	W = list(map(int, input().split()))
	total = sum(W)
	cur = W[0]
	ans = abs((total-2*cur))
	for i in range(1, N):
		cur += W[i]
		ans = min(ans, abs((total-2*cur)))
	print(ans)


if __name__ == '__main__':
	main()

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cassert>

using namespace std;

const int DICE_SIZE = 6;
int const CmdCount = 6;
int const RotateLen = 4;

//?????????
//??±?\????????????¢???????????¨?????§?????????
class dice {
  //?????????,?????¢,??±??¢,?\???¢,?????¢,?????¢?????°???
  int values[DICE_SIZE];
public:
  dice (){};
  dice (const dice &d);
  virtual ~dice (){};
  int &operator[](int i){
    assert(0 <= i && i < DICE_SIZE);
    return values[i];
  };
  void docmd(string str);
  void docmd(char c);
  void setTopAndFront(int top,int front);
  void input(void);
  int right(void){return values[2];};
  int top(void){return values[0];};
  int front(void){return values[1];};
  bool Equal(const dice &d);
private:
  void output();
  bool IsArrayEqual(const dice &d);
  int indexs[CmdCount][RotateLen] = {
      {0, 2, 5, 3},
      {3, 5, 2, 0},
      {0, 1, 5, 4},
      {4, 5, 1, 0},
      {3, 1, 2, 4},
      {4, 2, 1, 3}};
  char cmdChar[CmdCount] = {'W', 'E', 'N', 'S','L','R'};
  string toTopCmd[6] = {"","N","W","E","S","NN"};
  string toFrontCmd[6] = {"S","","L","R","LL","N"};
  void move_forward(int *indexs);
  int find_value(int num);
};
dice::dice(const dice &d){
  for(int i = 0; i < DICE_SIZE; i++){
    this->values[i] = d.values[i];
  }
}
void dice::setTopAndFront(int top, int front){
  int idxTop = find_value(top);
  docmd(toTopCmd[idxTop]);
  int idxFront = find_value(front);
  docmd(toFrontCmd[idxFront]);
}
int dice::find_value(int num){
  for(int i = 0; i < DICE_SIZE; i++){
    if(values[i] == num){
      return i;
    }
  }
  assert(false);
}


void dice::docmd(string str){
  for(int i = 0; i < str.length(); i++){
    //cout << "docmd(str[i])" << str[i] << endl;
    docmd(str[i]);
  }
}

void dice::docmd(char c){
  for(int i = 0; i < CmdCount; i++){
    if (c == cmdChar[i]){
      //cout << cmdChar[i];
      move_forward(indexs[i]);
      return;
    }
  }
  assert(false);//????????¨???????????????
}
void dice::move_forward(int *indexs){
  //for(int i = 0; i < 4; i++)cout << indexs[i];
  int temp = values[indexs[0]];
  values[indexs[0]] = values[indexs[1]];
  values[indexs[1]] = values[indexs[2]];
  values[indexs[2]] = values[indexs[3]];
  values[indexs[3]] = temp;
}
void dice::input(void){
  for(int i=0; i < DICE_SIZE; i++){
    int n;
    cin >> n;
    values[i] = n;
  }
}
bool dice::Equal(const dice &d){
  output();
  for(int i = 0; i < DICE_SIZE; i++){
    dice d2 = d;
    d2.docmd(toTopCmd[i]);
    for(int j = 0; j < RotateLen; j++){
      d2.docmd('L');
    //  cout << "d2 is ";
      d2.output();
      if (IsArrayEqual(d2)){
        return true;
      }
    }
  }
  return false;
}
void dice::output(){
/*  for(int i=0;i<DICE_SIZE;i++){
    cout << values[i] << " ";
  }
  cout << endl;*/
}
bool dice::IsArrayEqual(const dice &d){
  for (int i = 0; i < DICE_SIZE; i++) {
    if (d.values[i] != this->values[i]){
      return false;
    }
  }
  return true;
}
int main(int argc, char const *argv[]) {
  dice d1,d2;
  d1.input();
  d2.input();
  if (d1.Equal(d2)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3224
from math import gcd
N = int(input())
A = list(map(int,input().split()))

g = 0
for a in A:
    g = gcd(g,a)
if g > 1:
    print('not coprime')
    exit()

def factorize(n):
    d = set()
    m = 2
    while m*m <= n:
        while n%m == 0:
            n //= m
            d.add(m)
        m += 1
    if n > 1:
        d.add(n)
    return d

st = set()
for a in A:
    fac = factorize(a)
    if fac & st:
        print('setwise coprime')
        exit()
    st |= fac
print('pairwise coprime')

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

using namespace std;

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long>> res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
    long n;
    cin >> n;

    int count = 0;

    auto P = prime_factorize(n);

    for(auto i:P){
        int ex=1;
        while(true){
            if(i.second-ex>=0){
                i.second-=ex;
                ex++;
                count++;
            }else{
                break;
            }
        }
    }
    cout << count << endl;
}

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

using namespace std;

u_int seed = 3;
u_int xor_shift()
{
    seed ^= seed << 1;
    seed ^= seed >> 3;
    seed ^= seed << 10;
    return seed;
}

chrono::system_clock::time_point start_time;
int elapsed()
{
    auto cur = chrono::system_clock::now();
    return chrono::duration_cast<chrono::milliseconds>(cur - start_time).count();
}

// セグ木を使えば二分探索で一点をlog(n)で更新できる これ嘘で，後ろのスコアも変更する必要があるため
// 前からA*とかビームサーチもできそう
// とりあえず焼きなます
// 最初はCを考慮せずに焼きなます(いや，貪欲でいいだろ)
int score = 0;
int d;
vector<int> T, C;
vector<vector<int>> S, last;

// i日目をj番目に
int calc(int i, int to){
    int res = 0;
    int from = T[i];
    res -= S[i][from];
    int l = i == 0 ? -1 : last[i - 1][from];
    for (int j = i; j < d; j++){
        if (last[j][from] != i)
            break;
        res += C[from] * (j - last[j][from]);
        res -= C[from] * (j - l);
    }

    res += S[i][to];
    for (int j = i; j < d; j++){
        if (last[j][to] > i)
            break;
        res += C[to] * (j - last[j][to]);
        res -= C[to] * (j - i);
    }

    return res;
}

void change(int i, int to){
    int from = T[i];
    T[i] = to;
    int l = i == 0 ? -1 : last[i - 1][from];
    for (int j = i; j < d; j++){
        if (last[j][from] != i)
            break;
        last[j][from] = l;
    }

    for (int j = i; j < d; j++){
        if (last[j][to] > i)
            break;
        last[j][to] = i;
    }
}

int calc_overall(){
    int res = 0;
    for (int i = 0; i < d; i++){
        res += S[i][T[i]];
        for (int j = 0; j < 26; j++){
            res -= C[j] * (i - last[i][j]);
        }
    }

    return res;
}


int main(){
    cin >> d;
    start_time = chrono::system_clock::now();
    C.resize(26);
    copy_n(istream_iterator<int>(cin), 26, C.begin());
    S.assign(d, vector<int>(26));
    last.assign(d, vector<int>(26, -1));
    for (auto &s: S)
        copy_n(istream_iterator<int>(cin), 26, s.begin());

    T.resize(d);

    for (int i = 0; i < d; i++){
        // int to = max_element(S[i].begin(), S[i].end()) - S[i].begin();
        int to = xor_shift() % 26;
        T[i] = to;
        for (int j = i; j < d; j++){
            last[j][to] = i;
        }
    }

    auto ans = T;
    score = calc_overall();
    cerr << score << endl;
    int max_score = score;
    const double s_temp = 20000, e_temp = 1;
    const constexpr int L = 1e6;
    double delta = (s_temp - e_temp) / L;
    double temp = s_temp;
    const double sup = pow(2, 32) - 1;

    while (elapsed() < 1950){
        auto i = xor_shift() % d;
        auto to = xor_shift() % 26;
        if (T[i] == to)
            continue;
        auto cost = calc(i, to);
        if (cost > 0 or exp(cost / temp) > xor_shift() / sup){
            change(i, to);
            // cerr << "change: " << i << " " << to << " " << cost << " " << temp << endl;
            score += cost;
        }
        if (score > max_score){
            ans = T;
            max_score = score;
        }
        if (temp > e_temp)
            temp -= delta;
    }

    cerr << temp << endl;
    for (const auto &t: ans)
        cout << t + 1 << endl;

    cerr << max_score << endl;

}

Measured memory_bytes: 4556
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <cmath>
#include <list>
#include <iomanip>
#include <set>
#include <map>
#include <sstream>
#include <string.h>
#include <fstream>
#include <stdio.h>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef vector<int> VI;

#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define RFOR(i,a,b) for(int (i)=(a)-1;(i)>=(b);--(i))
#define MP make_pair
#define MOD 1000000007
#define INF 1000000001
#define PB push_back
#define eps 1e-5
#define X first
#define Y second

int n, x;
int a[201];
int F[201][100001];
LL ans = 0;

LL backtr(int pos, int x)
{
    if (x == 0) {
        return 0;
    }
    
    if (F[pos][x] != -1) {
        return F[pos][x];
    }
    
    LL d = 1;
    LL pos2 = pos;
    while (pos2 != n && a[pos2] > x) {
        d = d * (n - pos2) % MOD;
        pos2++;
    }

    if (pos2 == n) {
        F[pos][x] = d * x % MOD;
        return F[pos][x];
    }
    
    LL ans = 0;
    FOR (p, pos2, n) {
        ans = (ans + backtr(p+1, x%a[p])*d)%MOD;
        d = d * (n - p - 1) % MOD;
    }
    
    F[pos][x] = ans;
    return F[pos][x];
}

int main()
{
    cin >> n >> x;
    FOR (i,0,n+1)
    FOR (j,0,x+1) F[i][j] = -1;
    FOR (i,0,n) cin >> a[i];
    sort(a,a+n);
    reverse(a,a+n);
    cout << backtr(0,x);
}


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

#define ll long long

int main()
{
    ll n, w;
    cin >> n >> w;
    vector<pair<ll, ll>> wv(n + 1);

    for(ll i = 1; i <= n; i++)
    {
        cin >> wv[i].first >> wv[i].second;
    }

    vector<vector<ll>> dp(n + 1, vector<ll>(w + 1));

    for(ll i = 1; i <= n; i++)
    {
        for(ll j = 1; j <= w; j++)
        {
            if(j - wv[i].first >= 0)
            {
                dp[i][j] = max(dp[i - 1][j - wv[i].first] + wv[i].second, dp[i - 1][j]);   
            }
            else
            {
                dp[i][j] = dp[i - 1][j];
            }       
        }
    }

    // for(ll i = 1; i <= n; i++)
    // {
    //     for(ll j = 1; j <= w; j++)
    //     {
    //         cout << dp[i][j] << " ";
    //     }     
    //     cout << "\n";
    // }

    cout << dp[n][w];

    return 0;
}

Measured memory_bytes: 82988
n=int(input())
l=[int(i) for i in input().split()]
m=max(l)
m1=min(l)
def all_pos(l1,ans): 
    for i in range(1,n): 
        if l1[i]>=l1[i-1]: 
            pass 
        else: 
            l1[i]+=l1[i-1]
            ans.append([i,i+1])
    print(len(ans))
    for i in range(len(ans)):
        print(*ans[i])
def all_neg(l,ans):
    for i in range(n-2,-1,-1):
        if l[i]<=l[i+1]:
            pass 
        else:
            l[i]+=l[i+1]
            ans.append([i+2,i+1])
    print(len(ans))
    for i in range(len(ans)):
        print(*ans[i])
m=abs(max(l))
m1=abs(min(l))
if m>=m1:
    ans=[] 
    #add +ve max to all elements all will become pos 
    ind=l.index(max(l))
    for i in range(n): 
        l[i]+=l[ind]
        ans.append([ind+1,i+1])
    all_pos(l,ans)
else:
    ans=[]
    #add min to all elements so that all elements become negative 
    ind=l.index(min(l))
    for i in range(n):
        l[i]+=l[ind]
        ans.append([ind+1,i+1])
    all_neg(l,ans)
       # print(ind+1,i+1)
        

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
int64_t MOD=1000000007;

int main() {
  int N,M;
  cin>>N>>M;
  vector<int> S(M);
  for(int i=0;i<M;i++) cin>>S.at(i);
  sort(S.begin(),S.end());
  reverse(S.begin(),S.end());
  vector<int> R(M-1);
  int64_t ans=0;
  for(int i=0;i<M-1;i++) R.at(i)=S.at(i)-S.at(i+1);
  sort(R.begin(),R.end());
  reverse(R.begin(),R.end());
  for(int i=0;i<M-1;i++){
    if(i<N-1)continue;
    ans+=R.at(i);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024