akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
 
struct Item {
	string name;
	int total_time;
	int price;
 
	Item(string name_, int total_time_, int price_):name(name_),total_time(total_time_),price(price_){}
	bool operator>(const Item& other) const {
		if(price * other.total_time != total_time * other.price){
			return (price * other.total_time > total_time * other.price);
		}
		return (name < other.name);
	}
};
 
int main() {
	int N;
	for(;;){
		cin >> N;
		if(N == 0)break;
 
		vector<Item> items;
		for(int i=0;i<N;i++){
			string name;
			int P, A, B, C, D, E, F, S, M;
			cin >> name >> P >> A >> B >> C >> D >> E >> F >> S >> M;
 
			items.push_back(Item(name, (A + B + C) + (D + E) * M, F * M * S - P));
		}
 
		sort(items.begin(), items.end(), greater<Item>());
		for(int i=0;i<N;i++){
			cout << items[i].name << endl;
		}
		cout << "#" << endl;
	}
	return 0;
}

Measured memory_bytes: 1224
H, W = gets.split.map(&:to_i)
field = H.times.map { gets.chomp.split(//) }

def walk(field)
  head = [[0, 0]]
  count = 1
  until head.empty?
    head_new = []
    head.each do |i, j|
      next if i < 0 || H <= i || j < 0 || W <= j
      return count if i == H - 1 && j == W - 1
      next if field[i][j] != '.'
      field[i][j] = '-'
      head_new << [i, j - 1]
      head_new << [i, j + 1]
      head_new << [i - 1, j]
      head_new << [i + 1, j]
    end
    head = head_new
    count += 1
  end
  nil
end

count = walk(field)
if count
  black = field.sum { |e| e.count('#') }
  puts H * W - black - count
else
  puts '-1'
end


Measured memory_bytes: 14508
#include<cstdio>
using namespace std;
int main(){
    int h,w,f[30]={},flag[4]={},ans=1;
    scanf("%d %d",&h,&w);
    char a[100][101];
    for(int i=0;i<h;i++){
        scanf("%s",a[i]);
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            f[a[i][j]-'a']++;
        }
    }
    for(int i=0;i<30;i++){
        flag[f[i]%4]++;
    }
    if(w%2&&h%2){
        if(flag[1]+flag[3]!=1){
            ans=0;
        }
        if(flag[3]+flag[2]>(w+h-2)/2){
            ans=0;
        }
    }
    else if(w%2!=h%2){
        if(flag[1]||flag[3]){
            ans=0;
        }
        if(h%2&&flag[2]>w/2){
            ans=0;
        }
        if(w%2&&flag[2]>h/2){
            ans=0;
        }
    }
    else if(flag[1]||flag[2]||flag[3]){
        ans=0;
    }
    if(ans){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
}

Measured memory_bytes: 128
n=int(input())
l=list(map(int,input().split()))
l.insert(0,0)
l.append(0)
c=0
for i in range(n+1):
  c+=abs(l[i+1]-l[i])
for j in range(1,n+1):
  print(c-abs(l[j]-l[j-1])-abs(l[j+1]-l[j])+abs(l[j+1]-l[j-1]))

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    string s;cin >> s;
    vector<int> v(3);
    REP(i, SZ(s))
    {
        int x = s[i] - 'a';
        v[x] += 1;
    }
    sort(ALL(v));
    if ((v[2] - v[1] == 0 || v[2] - v[1] == 1)&&(v[2] - v[0] == 0 || v[2] - v[0] == 1))
    cout << "YES" <<"\n";
    else
        cout << "NO"
             << "\n";

        return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    vector<ll> S(n + 1, 0);
    for(int i = 0; i < n; ++i)  S[i + 1] = S[i] + a[i];
    ll ans = 1e+15;
    for(int i = 1; i < n; ++i)  chmin(ans, abs(S[i] - (S[n] - S[i])));
    cout << ans << endl;
}

Measured memory_bytes: 3456
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<deque>
#include<iomanip>
#include<set>
#include<unordered_set>
#include<tuple>
#include<map>
#include<memory>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<double> VD;
typedef pair<int, int> P1;
typedef long long int ll;

//number
#define INF 1e9
#define NUM 1000000007

//itr
#define all(x) begin(x),end(x)

//repeat
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define RREPS(i,x) for(int i=((int)(x));i>=0;i--)

//max,min
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

/*ll gcd(ll a, ll b) {
	if (b == 0) return a;
	else return gcd(b, a%b);
}*/

/*ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a * (b / g);
}*/

/*int dig(int a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}*/

//grid template
int x[] = { -1, 0, 1, 0 };
int y[] = { 0,-1,0,1 };
int xx[] = { -1,-1,1,1 };
int yy[] = { 1,-1,1,-1 };

int main() {
	int a, b;
	cin >> a >> b;

	if (a + b >= 10) {
		cout << "error" << endl;
	} else {
		cout << a + b << endl;
	}
}


 

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function (chunk) {
    const n = chunk.toString();
    const r = n.split("\n");
    const output = [];
    const all = ["S 1","S 2","S 3","S 4","S 5","S 6","S 7","S 8","S 9","S 10","S 11","S 12","S 13","H 1","H 2","H 3","H 4","H 5","H 6","H 7","H 8","H 9","H 10","H 11","H 12","H 13","C 1","C 2","C 3","C 4","C 5","C 6","C 7","C 8","C 9","C 10","C 11","C 12","C 13","D 1","D 2","D 3","D 4","D 5","D 6","D 7","D 8","D 9","D 10","D 11","D 12","D 13"];

    for(let i = 0; i<all.length; i++){
        if(r.some(item => item === all[i])===false){
            output.push(all[i]);
        }
    }
    const S = output.filter(item => item.includes("S"));
    const H = output.filter(item => item.includes("H"));
    const C = output.filter(item => item.includes("C"));
    const D = output.filter(item => item.includes("D"));
    S.sort(st);
    H.sort(st);
    C.sort(st);
    D.sort(st);
    S.forEach(x => console.log(x));
    H.forEach(x => console.log(x));
    C.forEach(x => console.log(x));
    D.forEach(x => console.log(x));
});

function st(a, b){
    const x = a.split(" ");
    const y = b.split(" ");
    const d = Number(x[1]);
    const q = Number(y[1]);
    return d - q;
}


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

public class Main {

	static void solve (Scanner in, PrintWriter out, Methods ms) {
		
		TreeMap<String, ArrayList<Integer>> map = new TreeMap<>();
		
		while (in.hasNext() == true) {
		
			String key = in.next();
			int value = in.nextInt();
			
			if (map.containsKey(key) == false) {
				map.put(key, new ArrayList<>());
			}
			map.get(key).add(value);
		}
		
		for (Map.Entry<String, ArrayList<Integer>> e : map.entrySet()) {
			out.println(e.getKey());
			Collections.sort(e.getValue());
			for (int i = 0; i < e.getValue().size(); i++) {
				if (i != 0) out.print(" ");
				out.print(e.getValue().get(i));
			}
			out.println();
		}
		
	}



	public static void main (String[] args) {

		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		Methods ms = new Methods();
		solve(in, out, ms);
		in.close();
		out.close();
	}

	static class Methods {

		public void print (Object... ar) {System.out.println(Arrays.deepToString(ar));}

		public int max (int... ar) {Arrays.sort(ar); return ar[ar.length-1];}

		public int min (int... ar) {Arrays.sort(ar); return ar[0];}

		public long gcd (long a, long b) {return b > 0 ? gcd(b,a%b) : a;}

		public long lcm (long a, long b) {return a / gcd(a,b) * b;}

		public long factorial (int i) {
			if (i == 1) return 1;
			else return i * factorial(i-1);
		}

		public int manhat (int x1, int y1, int x2, int y2) {
			return Math.abs(x1 - x2) + Math.abs(y1 - y2);
		}

		public double euclid (double x1, double y1, double x2, double y2) {
			return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
		}

		public boolean isPrime (int n) {
			if (n == 2) return true;
			if (n < 2 || n % 2 == 0) return false;
			for (int i = 3; i <= Math.sqrt(n); i += 2) if(n % i == 0) return false;
			return true;
		}

	}

}


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

int main()
{
	int N;
	string s;
	char c[10005];

	cin >> N;
	cin >> s;

	for (int i = 0; i < s.size(); i++)
	{
		if (s.at(i) + N > 'Z')
		{
			c[i] = s.at(i) + N - 'Z' + 'A' - 1;
		}
		else c[i] = s.at(i) + N;
		cout << c[i];
	}

	cout << endl;
}

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

using namespace std;

int main(){
	lli n,k;
	cin >> n >> k;
  	vector<lli> vec(n), ans(n-k+1);
	for(int i=0;i<n;i++){
      	cin >> vec[i];
    }
  	sort(vec.begin(),vec.end());
  
  	for(int i=0;i<n-k+1;i++){
    		ans[i]=vec[i+k-1]-vec[i];
    }
  	sort(ans.begin(),ans.end());
  
  	cout << ans[0];
}

Measured memory_bytes: 1792
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int,input().split())) for i in range(N)]
ans = 0
for i in range(N):
   AB = C
   for j in range(M):
      AB += A[i][j] * B[j]
   if AB > 0:
      ans+=1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll=long long;
const ll MOD=100000007;
#define rep(i,a,b) for(ll i=a;i<b;i++)
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
inline constexpr int modf(ll n){
    ll ans=1;
    rep(i,0,n) {ans=ans*(n-i)%MOD;}
    return ans;
}
int main(){
    ll r,g,b,n,cnt=0;
    cin>>r>>g>>b>>n;
    ll i=0,j=0;
    while(i<=n){
        if(i%r==0){
        while(j<=n-i){
            if(j%g==0){
                if((n-i-j)%b==0){
                    cnt++;
                }
            }
            j++;
        }
        j=0;
        }
        i++;
    }
    cout<<cnt;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
 
void main() {
	auto D = readln.split[0].to!int;
	auto c =
		D == 25 ? "Christmas" :
		D == 24 ? "Christmas Eve" :
		D == 23 ? "Christmas Eve Eve" :
		D == 22 ? "Christmas Eve Eve Eve" : "";
	c.writeln;
}


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

const int MOD=1000000007;

ll modpow(ll x, ll n, ll mod) {
  if (n==0) return 1;
  ll res=modpow(x*x%mod, n/2, mod);
  if (n & 1) res=res*x%mod;
  return res;
}

int main() {
  ll n,m; cin>>n>>m;
  ll res=modpow(n,m,MOD);
  cout<<res<<endl;
}



Measured memory_bytes: 3112
import numpy as np

h, w, k = map(int, input().split())
st = []
for _ in range(h):
    l = list(input())
    l = [l[i] for i in range(w)]
    st.append(l)
st = np.array(st)
st = np.where(st=='#', 1, 0)

cnt = 0
for i in range(2**w-1):
    tmp = [1] * w
    for j in range(w):
        if i >> j & 1:
            tmp[j] = 0
    for j in range(2**h-1):
        ker = np.array([tmp]*h)
        for x in range(h):
            if j >> x & 1:
                ker[x,:] = 0
        if np.sum(st * ker) == k:
            cnt+=1
print(cnt)

Measured memory_bytes: 27176
#include <iostream>
#include <vector>
#include <queue>
#include <set>
using namespace std;
 
int main() {
    int n, m; cin >> n >> m;
    vector<set<int>> g(n);
    for (int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;
        g[a - 1].insert(b - 1);
        g[b - 1].insert(a - 1);
    }

    vector<int> group;
    vector<bool> visited(n, false);
    for (int i = 0; i < n; ++i) {
        if (visited[i]) continue;
        visited[i] = true;

        int cidx = group.size();
        group.push_back(1);

        queue<int> que;
        que.push(i);
        while (!que.empty()) {
            int cvtx = que.front(); que.pop();

            for (auto e : g[cvtx]) {
                if (visited[e]) continue;
                visited[e] = true;
                que.push(e);
                ++group[cidx];
            }
        }
    }

    int ans = 0, counter = 0;
    for (int i = 0; i < group.size(); ++i) {
        if (group[i] - counter <= 0) continue;

        ans += group[i] - counter;
        counter += group[i] - counter;
    }

    cout << ans << endl;
}



Measured memory_bytes: 31724
import numpy as np
N, K= map(int,input().split())
h = list(map(int,input().split()))
 
dp = [0] * N
h = np.array(h)
 
dp = np.array([0]*N, dtype=np.int64)
 
for i in range (1, N):
    x = max(0, i - K)
    dp[i] = np.min(dp[x:i] + np.abs(h[i]-h[x:i]))
print(dp[N-1])

Measured memory_bytes: 22728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

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

    vector<int> p(n);
    rep(i,3)
    {
        int m;
        cin >>m;
        while(m--)
        {
            int x;
            cin >>x;
            p[x-1] |= 1<<i;
        }
    }

    int ans = 0;
    rep(i,n) ans += (p[i]==4 || p[i]==6 || p[i]==7);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3072
n, m = map(int, input().split())
ans = [0, 0]
ac = [False for _ in range(n)]
wa = [0 for _ in range(n)]

for _ in range(m):
    tmp, s = input().split()
    p = int(tmp)
    # 正解済みならスキップ
    if(ac[p-1]):
        continue
    # 正解ならAC数とWA数を加算
    if(s == "AC"):
        ans[0] += 1
        ans[1] += wa[p-1]
        ac[p-1] = True
    # 不正解なら暫定WA数を加算
    else:
        wa[p-1] += 1
 
print("{} {}".format(*ans))

Measured memory_bytes: 4656
#include<stdio.h>
#include<string.h>
int min(int a, int b)
{
    if (a < b)
        return a;
    else
        return b;
}
int main()
{
    char s[5003];
    scanf("%s", s);
    int k;
    scanf("%d", &k);
    char a[25005][10];
    int i, j, x, y;
    y = 0;
    int n = strlen(s);
    for (i = 0; i < n; i++)
    {
        for (j = i; j < min(n, i + 5); j++)
        {
            for (x = i; x <= j; x++)
                a[y][x - i] = s[x];
            a[y][x - i] = '\0';
            y++;
        }
    }
    char b[10];
    while (k > 0)
    {
        i = 0;
        while (a[i][0] == '\0')
            i++;
        strcpy(b, a[i]);
        for (; i < y; i++)
        {
            if (strcmp(b, a[i]) > 0 && a[i][0] != '\0')
                strcpy(b, a[i]);
        }
        for (i = 0; i < y; i++)
            if (strcmp(b, a[i]) == 0)
                a[i][0] = '\0';
        k--;
    }
    printf("%s\n", b);
    return 0;
}

Measured memory_bytes: 384
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();
  // 文字列の入力
  // String s = sc.next();
  // 出力
  int num = b*c%2;
 	 //System.out.println((a+b+c) + " " + s);
 	if(num == 0){
 		 	 System.out.println("Even");
 	}else{
 		 	 System.out.println("Odd");
 	}
 }
}


Measured memory_bytes: 21204
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

type Heap struct {
	size  int
	elems [100]int
}

func (heap *Heap) Size() int {
	return heap.size
}

func (heap *Heap) Push(x int) {
	i := heap.size

	for i > 0 {
		p := (i - 1) / 2
		if heap.elems[p] <= x {
			break
		}
		heap.elems[i] = heap.elems[p]
		i = p
	}

	heap.elems[i] = x
	heap.size++
}

func (heap *Heap) Pop() int {
	// 最小値
	ret := heap.elems[0]
	heap.size--
	x := heap.elems[heap.size]

	i := 0
	for i*2+1 < heap.size {
		a, b := i*2+1, i*2+2
		if b < heap.size && heap.elems[b] < heap.elems[a] {
			a = b
		}
		if heap.elems[a] >= x {
			break
		}

		heap.elems[i] = heap.elems[a]
		i = a
	}

	heap.elems[i] = x

	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, k := nextInt(), nextInt()
	v := nextInts(n)

	ans := 0
	suml, minl := 0, new(Heap)
	for l := -1; l < n; l++ {
		if l >= 0 {
			suml += v[l]
			minl.Push(v[l])
		}
		sumr, minr := 0, new(Heap)
		for r := n; l < r && (l+1)+(n-r) <= k; r-- {
			if r < n {
				sumr += v[r]
				minr.Push(v[r])
			}
			val := suml + sumr
			// 取り出す要素
			remr, reml := make([]int, 0), make([]int, 0)
			for d := k - (l + 1) - (n - r); d > 0; d-- {
				if minl.Size() > 0 && minl.elems[0] < 0 && minr.Size() > 0 && minr.elems[0] < 0 {
					if minl.elems[0] < minr.elems[0] {
						rem := minl.Pop()
						reml = append(reml, rem)
						val -= rem
					} else {
						rem := minr.Pop()
						remr = append(remr, rem)
						val -= rem
					}
				} else if minl.Size() > 0 && minl.elems[0] < 0 {
					rem := minl.Pop()
					reml = append(reml, rem)
					val -= rem
				} else if minr.Size() > 0 && minr.elems[0] < 0 {
					rem := minr.Pop()
					remr = append(remr, rem)
					val -= rem
				}
			}
			ans = max(ans, val)
			// 復元
			for i := range reml {
				minl.Push(reml[i])
			}
			for i := range remr {
				minr.Push(remr[i])
			}
		}
	}

	puts(ans)
}


Measured memory_bytes: 1664
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int n, k;
  cin >> n >> k;
  int ans = 0;
  while (n) {
    n /= k;
    ans++;
    if (n == 0) break;
  }
  cout << ans << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
int main(void) {
	int a, b, k;
	cin >> a >> b >> k;

	for(int i=a;i<=b;i++) {
		if((a<=i && i<a+k) || (b-k<i && i<=b)) cout << i << endl;
	}
}

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

using namespace std;

const int BUFFER_SIZE = 1 << 20;
char rb[BUFFER_SIZE], *rp = rb, *rt = rb;
inline char read_char() {
    return rp == rt ? (rt = rb + fread(rb, 1, BUFFER_SIZE, stdin), rp = rb, *rp ++) : *rp ++;
}
inline int read_int() {
    int x = 0;
    char ch = read_char(), flag = 0;
    while (ch != '-' && (ch < '0' || ch > '9')) {
        ch = read_char();
    }
    if (ch == '-') {
        flag = 1;
        ch = read_char();
    }
    for (x = 0; ch >= '0' && ch <= '9'; ch = read_char()) {
        x = x * 10 + (ch - '0');
    }
    return flag ? -x : x;
}

const int MAX_N = 100000 + 5;
const int MAX_M = 200000 + 5;
const int INF32 = 1000000000;

int N, M, d[MAX_N];
int ey[MAX_M << 1], ez[MAX_M], enext[MAX_M << 1], elast[MAX_N];
int nei[MAX_N];
char color[MAX_N];

void dfs(int u, int fa) {
    color[u] = color[fa] == 'W' ? 'B' : 'W';
    for (int j = elast[u]; j; j = enext[j]) {
        if (ey[j] != fa && ez[j >> 1]) {
            dfs(ey[j], u);
        }
    }
}

int main() {
    N = read_int();
    M = read_int();
    for (int i = 1; i <= N; i ++) {
        d[i] = read_int();
    }
    for (int i = 1, j = 2; i <= M; i ++) {
        int x = read_int();
        int y = read_int();
        ey[j] = y;
        enext[j] = elast[x];
        elast[x] = j ++;
        ey[j] = x;
        enext[j] = elast[y];
        elast[y] = j ++;
        if (nei[x] == 0 || d[y] < d[nei[x]] || d[y] == d[nei[x]] && y < nei[x]) {
            nei[x] = y;
        }
        if (nei[y] == 0 || d[x] < d[nei[y]] || d[x] == d[nei[y]] && x < nei[y]) {
            nei[y] = x;
        }
    }
    for (int i = 1; i <= N; i ++) {
        if (d[i] < d[nei[i]]) {
            printf("-1\n");
            return 0;
        }
    }
    for (int i = 1; i <= M; i ++) {
        int x = ey[i << 1];
        int y = ey[i << 1 | 1];
        if (nei[x] == y) {
            ez[i] = d[x];
        } else if (nei[y] == x) {
            ez[i] = d[y];
        }
    }
    for (int i = 1; i <= N; i ++) {
        if (!color[i]) {
            dfs(i, 0);
        }
    }
    printf("%s\n", color + 1);
    for (int i = 1; i <= M; i ++) {
        printf("%d\n", ez[i] ? ez[i] : INF32);
    }
    return 0;
}

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

#define range(bind, start, end) for (int bind = start; bind <= end; bind++)

int main()
{
    range (i, 1, 9)
        range (j, 1, 9)
            cout << i << "x" << j << "=" << i * j << endl;

    return 0;
}

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

void buildMaxHeap(int* arr, size_t size);
void heapMaxify(int* arr, int root, size_t size);
void swap(int* a, int* b);

void printHeap(int* arr, size_t size) {
	for (int i = 1; i <= size; i++) {
		printf(" %d", arr[i]);
		if (i == size)
			printf("\n");
	}
}

int main() {
	unsigned int m, * H;

	scanf("%d", &m);

	H = (int*)malloc((m + 1) * sizeof(int));

	for (int i = 1; i <= m; i++)
		scanf("%d", H + i);

	buildMaxHeap(H, m);
	printHeap(H, m);

	return 0;
}

void buildMaxHeap(int* arr, size_t size) {
	for (int i = floor(size / 2); i > 0; i--)
		heapMaxify(arr, i, size);
}
void heapMaxify(int* arr, int root, size_t size) {
	int left = 2 * root;
	int right = 2 * root + 1;
	int largest = root;

	largest = left <= size && arr[left] > arr[largest] ? left : largest;
	largest = right <= size && arr[right] > arr[largest] ? right : largest;

	if (root != largest) {
		swap(arr + root, arr + largest);
		heapMaxify(arr, largest, size);
	}
}
void swap(int* a, int* b) {
	int temp = *a;
	*a = *b;
	*b = temp;
}


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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

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

const int MOD = 1e9 + 7;
const int INF = INT_MAX / 2;

int main() {
	int N, x; cin >> N >> x;
	bool odd = false;
	rep(i, N) {
		int x; cin >> x;
		if (x % 2) odd = true;
	}
	if (odd) cout << (1LL<<(N - 1)) << endl;
	else cout << (x % 2 == 0 ? 1LL<<N : 0) << endl;
}


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

rl = lambda: list(map(int, input().split()))

x, y, a, b, c = rl()
p = rl()
q = rl()
r = rl()
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
res = sum(sorted(p[:x] + q[:y] + r, reverse=True)[:x+y])
print(res)


Measured memory_bytes: 114412
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int>B(m);
  for(int i; i<m; i++){
      cin >> B.at(i);
  }
  vector<vector<int>>A(n, vector<int>(m));
  for(int i=0; i<n; i++){
      for(int j=0; j<m; j++){
          cin >> A.at(i).at(j);
      }
  }
int cnt=0;
  for(int i=0; i<n; i++){
      int ttl=c;
      for(int j=0; j<m; j++){  
        
        ttl+=B.at(j)*A.at(i).at(j);
      }
      if(ttl>0){
          cnt++;
      }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cctype>
#include<cstring>
#include<algorithm>

using namespace std;

int main()
{
    int a,b,c,d,e,x,y,l;
    cin>>a>>b>>c>>x>>y;
    if(a+b<=2*c)
    {
        e=x*a+y*b;
    }
    else
    {
        if(x>=y)
        {
            d=y;
            l=x-y;
            e=c*2*d;
            if(a<=2*c)
                e+=a*l;
            if(a>2*c)
                e+=2*c*l;
        }
        else
        {
            d=x;
            l=y-x;
            e=c*2*d;
            if(b<=2*c)
                e+=b*l;
            if(b>2*c)
                e+=2*c*l;
        }
    }
    cout<<e<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
	double a, sum;
	while (cin >> a) {
		sum = a;
		for (int i = 2; i <= 10; i++) {
			if (i % 2 == 0)
				a = a * 2;
			else
				a = a / 3;
			sum += a;
		}
		cout << fixed << setprecision(8) << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 5e5 + 13;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int dp[N], h[N];

int main(){
    #ifdef KAZAKH
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> h[i];
        if (i > 1)dp[i] = dp[i-1] + abs(h[i-1]-h[i]);
        if (i > 2){
            dp[i] = min(dp[i], dp[i-2] + abs(h[i-2]-h[i]));
        }
    }
    cout << dp[n];
    return 0;
}


Measured memory_bytes: 1024
import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    (N, M, X) = map(int, input().split())
    A = np.zeros((N,M+1), dtype='int32')
    for i in range(N):
        A[i] = list(map(int, input().split()))
    
    A = A[np.argsort(A[:,0])]

    i = 0
    m = -1
    while i < 2**N:
        i += 1
        c = 0
        sum = np.zeros(M, dtype='int32')
        for j in range(N):
            if i & 2**j == 2**j:
                c += A[j][0]
                sum += A[j][1:]
        if np.all(sum >= X):
            m = c if m < 0 else min(m, c)
    
    print(m)
main()


Measured memory_bytes: 27352
#include <stdio.h>//c??§aoj Ring
#include <string.h>
int main(void)
{
	char s[100];
	char p[100];
	int i, j, count=0, a=0;

	scanf("%s", s);
	scanf("%s", p);

	for (i=0;i<=strlen(s);i++)
	{
		count=0;

		if (p[0] == s[i])
		{
			for (j=0;j<=strlen(p)-1;j++)
			{
				if (strlen(s) > i+j)
				{
					if (s[i+j] != p[j])
					{
						count++;
					}
				}
				else if (strlen(s) <= i+j)
				{
					if (s[i+j-strlen(s)] != p[j])
					{	
						count++;
					}
				}

				else if (count != 0)
				{
					break;
				}
			}

			if (count == 0)
			{
				a=1;
			}
		}
	}
	if (a==1)
	{
		printf("Yes\n");
	}
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 524
n,m = map(int,input().split())
mod = 10 ** 9 + 7
if abs(n - m) > 1:
  print(0)
elif n == m:
  ans = 2
  for i in range(1,n+1):
    ans *= i*i
    ans %= mod
  print(ans)
else:
  ans = 1
  for i in range(1,min(n,m) + 1):
    ans *= i*i
    ans %= mod
  ans *= max(n,m)
  ans %= mod
  print(ans)


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

#define I inline
#define fi first
#define se second
#define R register
#define LL long long
#define mp make_pair
#define reg register int
#define pii pair<int,int>
#define fo(i, a, b) for(reg i = a; i <= b; i++)
#define fd(i, a, b) for(reg i = a; i >= b; i--)
#define cr const reg&
using namespace std;
const int inf = 2147483647;
const int N = 1e6 + 1;

I int _max(cr x, cr y) {return x > y ? x : y;}
I int _min(cr x, cr y) {return x < y ? x : y;}
I LL read() {
	LL x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return x * f;
}
I void ptt(LL x) {if(x >= 10) ptt(x / 10); putchar(x % 10 + '0');}
I void put(LL x) {x < 0 ? putchar('-'), ptt(-x) : ptt(x);}
I void pr1(LL x) {put(x), putchar(' ');}
I void pr2(LL x) {put(x), puts("");}

char ss[N], tt[N];
int n, s[N], suf[N];

I int calc(cr mx) {
	reg hh = 0;
	fo(i, 1, n) {
		tt[i] = ss[i];
		if(ss[i] != '?') continue;
		if(suf[i] + 2 * (hh + 1) <= mx) tt[i] = '1', hh++;
		else tt[i] = '0';
	} reg h1 = 0, h2 = 0; hh = 0;
	fo(i, 1, n) hh += tt[i] == '1' ? 1 : -1, h1 = _max(h1, hh), h2 = _min(h2, hh);
	return h1 - h2;
}

int main() {
	scanf("%s", ss + 1);
	n = strlen(ss + 1);
	reg mx = 0;
	fo(i, 1, n) s[i] = s[i - 1] + (ss[i] == '1' ? 1 : -1), mx = _max(mx, s[i]);
	suf[n] = s[n]; fd(i, n - 1, 1) suf[i] = _max(suf[i + 1], s[i]);
	pr2(_min(calc(mx), calc(mx + 1)));
	return 0;
}



Measured memory_bytes: 13516
using System;

namespace agc021a
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Console.ReadLine();
            var ret = int.Parse(N[0].ToString()) + 9 * (N.Length -1);
            //文字列Nの最上位の桁(0番目)以降の中から9を削除した時のNの長さが0以外の時
            //入力値Nから最上位の桁を1引いて他の桁を9にした値の桁の和が最大
            if(N.Substring(1).Replace("9","").Length != 0) ret -= 1;
            Console.WriteLine(ret);
            //Console.WriteLine(N.Substring(1).Replace("9",""));
        }
    }
}

Measured memory_bytes: 13140
n,k=map(int,input().split())
p=list(map(int,input().split()))
e=[]
for i in range(n):
  e.append((1/p[i])*(p[i]*(1+p[i])/2))

a=0
for i in range(k):
  a+=e[i]

ans=[a]
for i in range(1,n-k+1):
  a=a-e[i-1]+e[i+k-1]
  ans.append(a)

print(max(ans))

Measured memory_bytes: 25604
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MAXN=1000010;

inline void read(int &x) {
    x=0;int f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();};
    while(isdigit(ch)){x=x*10+(ch-'0');ch=getchar();};x*=f;
}

struct edge {
    int x,y,nxt;
} E[MAXN<<1];
int head[MAXN],w[MAXN],ans[MAXN],n,m,tot=0;
struct node {
    int x,id;
} st[MAXN];

bool cmp(node A, node B) {
    return A.x<B.x;
}

inline void addedge(int x,int y) {
    E[++tot].x=x;
    E[tot].y=y;
    E[tot].nxt=head[x];
    head[x]=tot;
}

int main() {
    // freopen("C.in","r",stdin);
    // freopen("C.out","w",stdout);
    memset(head,-1,sizeof head);
    read(n);
    for(int i=1;i<=n;i++) {
        read(w[i]);
        st[i].x=w[i];
        st[i].id=i;
    }
    for(int i=1,j,k;i<n;i++) {
        scanf("%d%d",&j,&k);
        addedge(j,k);
        addedge(k,j);
    }
    sort(st+1,st+1+n,cmp);
    for(int it=1;it<=n;it++) {
        int i=st[it].id;
        bool win=0;
        for(int j=head[i];~j;j=E[j].nxt) {
            int to=E[j].y;
            if(w[to]<w[i]) {
                win|=(ans[to]^1);
            }
        }
        ans[i]=win;
    }
    for(int i=1;i<=n;i++) {
        if(ans[i]){
            printf("%d ",i);
        }
    }
    // fclose(stdin);
    // fclose(stdout);
    return 0;
}

Measured memory_bytes: 10624
#include <iostream>
#include <cstring>
#include <string>
#include <iomanip>
using namespace std;

class Tenki{
public:
    int i,j;
    string S;
    string T;
    void hikaku(string S, string T);
};

void Tenki::hikaku(string S, string T){

    j = 0;
    for(i = 0; i < T.length(); i++){
        if(S[i] == T[i]){
           j = j + 1;
        }
    }

    cout << j << endl;

}


int main(){

    Tenki t;

    cin >> setw(3) >> t.S;

    cin >> setw(3) >> t.T;

    t.hikaku(t.S, t.T);


    return 0;
}

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

int main(){
    int n;
    cin>>n;
    int a[n];
    int x;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int tmp=0;
    int ans=0;
    while(tmp<n){
        int tmp2=a[tmp];
        int cnt=0;
        while(tmp<n&&a[tmp]==tmp2){
            tmp++;
            cnt++;
        }
        ans+=cnt%2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3936
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <functional>

using namespace std;

#define rep(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(itr,c) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

int main(){
  int page;
  string doc;
  map< string, vector<int> > mp;

  while(cin >> doc >> page) mp[doc].push_back(page);

  int i;
  foreach(itr,mp){
    cout << itr->first << endl;
    sort(itr->second.begin(),itr->second.end());
    rep(i,itr->second.size()){
      cout << itr->second[i];
      if(itr->second.size()-1 == i) cout << endl; else cout << ' ';
    }
  }

  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

vi c;
int n, m;

int main()
{
	cin >> n >> m;
	c.resize(n, 0);

	REP(i, m)
	{
		int a, b; cin >> a >> b; --a; --b;
		++c[a];
		++c[b];
	}

	REP(i, n)
		cout << c[i] << endl;
}


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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  int A, B;
  char op;
  cin >> A >> op >> B;

  if (op == '+') cout << A+B << endl;
  else cout << A-B << endl;

  return 0;
}


Measured memory_bytes: 256
main(n,r){for(;scanf("%d",&n),n;printf("%d\n",r)){n=1000-n;for(r=0;n/500;r++)n-=500;for(;n/100;r++)n-=100;for(;n/50;r++)n-=50;for(;n/10;r++)n-=10;for(;n/5;r++)n-=5;for(;n;r++)n--;}exit(0);}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))



int main(){

	int c[3][3],b[3];
	FOR(i,0,3)FOR(j,0,3)cin>>c[i][j];


	for(b[0]=0;b[0]<101;b[0]++){
		for(b[1]=0;b[1]<101;b[1]++){
			for(b[2]=0;b[2]<101;b[2]++){
				ll a[3];
				a[0] = c[0][0]-b[0];
				a[1] = c[1][0]-b[0];
				a[2] = c[2][0]-b[0];
				bool ok = true;
				FOR(i,1,3){
					FOR(j,0,3){
						if(c[j][i]!=a[j]+b[i]){
							ok = false;
						}
					}
				}
				if(ok){
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}
	cout << "No" << endl;
}


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

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = 1e18 + 7;


auto divisor = [](i64 x){
    i64 sq = sqrt(x) + 1;
    vector<i64> ret;
    for(i64 i = 1; i < sq; ++i)
        if(!(x % i)){
            ret.emplace_back(i);
            if(i * i != x)
                ret.emplace_back(x / i);
        }
    sort(ret.begin(), ret.end());
    return ret;
};

auto factoring = [](i64 x){
    i64 sq = sqrt(x) + 1;
    vector<i64> ret;
    if(x == 1){
        ret.emplace_back(1);
        return ret;
    }
    for(i64 i = 2; i < sq; ++i)
        while(x % i == 0){
            ret.emplace_back(i);
            x /= i;
        }
    if(x != 1)
        ret.emplace_back(x);
    return ret;
};

signed main(){
    i64 a, b;
    cin >> a >> b;
    vector<i64> at = divisor(a);
    vector<i64> bt = divisor(b);
    vector<i64> c;
    for(auto& x : at){
        auto it = lower_bound(bt.begin(), bt.end(), x);
        if(it != bt.end() && *it == x){
            c.emplace_back(x);
        }
    }

    i64 ans = 0;
    for(auto& x : c){
        if(factoring(x).size() == 1)
            ++ans;
    }
    cout << ans << endl;
}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

int main(){
  ll i, j;
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(i = 0; i < n; i++)
    cin >> a[i];
  ll result = 0;
  for(i = 0; i < n; i++)
    result += a[i] - 1;
  cout << result << endl;
  

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 25
#define NIL -1
int Height(int);
int Sibling(int);
void Depth(int,int);
void output(int);
struct Node{
  int parent;
  int left;
  int right;
};
struct Node T[MAX];
int n,d[MAX],h[MAX];

int main(){
  int i;
  int u,left,right,id;
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    T[i].parent = NIL;
  }
  for(i = 0; i < n; i++){
    scanf("%d %d %d",&id,&left,&right);
    T[id].left = left;
    T[id].right = right;
    if(left != NIL) T[left].parent = id;
    if(right != NIL) T[right].parent = id;
  }
  for(i = 0; i < n; i++) if(T[i].parent == NIL) u = i;
  Depth(u,0);
  Height(u);
  for(i = 0; i < n; i++) output(i);
  return 0;
}



void Depth(int u,int p){
  d[u] = p;
  if(T[u].right != NIL) Depth(T[u].right,p+1);
  if(T[u].left != NIL) Depth(T[u].left,p+1);
}

int Height(int u){
  int hh=0,H=0;
  if(T[u].left != NIL) hh = Height(T[u].left) + 1;
  if(T[u].right != NIL) H = Height(T[u].right) + 1;
  if(hh > H) return h[u] = hh;
  else return h[u] = H;
}

int Sibling(int u){
  if(T[u].parent == NIL) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL) return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL) return T[T[u].parent].right;
  return NIL;
}

void output(int u){
  int c;
  printf("node %d: parent = %d, sibling = %d, ",u,T[u].parent,Sibling(u));
  c = 0;
  if(T[u].left != NIL) c++;
  if(T[u].right != NIL) c++;
  printf("degree = %d, depth = %d, height = %d, ",c,d[u],h[u]);
  if(T[u].parent == NIL) printf("root\n");
  else if(T[u].left == NIL && T[u].right == NIL) printf("leaf\n");
  else printf("internal node\n");
}



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

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

	for (;;){
		int N;
		cin >> N;
		if (N == 0) break;

		int ans = 0;
		for (int a = 1; a <= N / 2 + 1; a++){
			for (int b = 1; b <= a - 1; b++){
				if (a * (a + 1) - b * (b - 1) == 2 * N) ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <cmath>

bool isPrimeNum(int fig){
	for (int i = 2; i <= sqrt(fig); ++i){
		if( fig % i == 0 ) return false;
	}
	return true;
}

int main(int argc, char const *argv[]){
	int fig,cnt=0;
	while(std::cin>>fig){
		if(isPrimeNum(fig)) cnt++;
	}
	std::cout << cnt << std::endl;
	return 0;
}


Measured memory_bytes: 3112
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func sum(a []int) int {
	ret := 0
	for _, v := range a {
		ret += v
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, m := nextInt(), nextInt()
	a := nextInts(n)
	s := sum(a)

	cnt := 0
	for i := 0; i < n; i++ {
		if a[i]*(4*m) >= s {
			cnt++
		}
	}

	if cnt >= m {
		puts("Yes")
	} else {
		puts("No")
	}
}


Measured memory_bytes: 640
#include <stdio.h>

int main() {
	int n;

	scanf("%d", &n);

	int a[n];
	int i, mh;
	long int total = 0;

	for(i=0; i<n; i++) {
		scanf("%d", &a[i]);
	}

	mh = a[0];

	for(i=1; i<n; i++) {
		if(mh > a[i]) {
			total += mh-a[i];
		} else {
			mh = a[i];
		}
	}

	printf("%ld\n", total);

	return 0;
}


Measured memory_bytes: 2448
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void doIt() {
		new Vampire().main();
	}

	class Vampire{
		final int MAX = Integer.MAX_VALUE;
		void main() {
			while(true) {
				int r = sc.nextInt();
				int n = sc.nextInt();
				if(n == 0 && r == 0)return;
				double ymin[] = new double[41];//xが整数
				double b[] = new double[40];//xが整数+0.5
				Arrays.fill(ymin, MAX);
				for(int i = 0; i < n; i++) {
					int left = sc.nextInt();
					int right = sc.nextInt();
					int h = sc.nextInt();
					
					for(int j = left; j < right; j++) {
						b[j + 20] = Math.max(b[j + 20], h);
					}
					
				}
				ymin[0] = b[0];
				ymin[40] = b[39];
				for(int i = -19; i < 20; i++) {
					ymin[i + 20] = Math.min(b[i + 19], b[i + 20]);
				}
				

				for(int i = -20; i <= 20; i++) {
					if(i <= -r || i >= r) {
						ymin[i + 20] = 21;
					}
					else {
						double x = Math.abs(i);
						double a = Math.acos(x /r);
						double diff = r * Math.sin(a);
						//System.out.println(x + " " + a + " " + diff);
						ymin[i + 20] -= diff;
					}
				}
				double min = 21.0;
				for(int i = 0; i < 41; i++) {
					min = Math.min(min, r + ymin[i]);
				}
				//System.out.println(Arrays.toString(ymin));
				System.out.println(Math.max(min, 0));
			}


		}
	}

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

}


Measured memory_bytes: 36428
n=int(input())
a=list(input())
b=list(input())
c=list(input())
cnt=0

for i in range(len(a)):
  if a[i]==b[i] and a[i]==c[i] and b[i]==c[i]:
    continue
  elif a[i]==b[i] or a[i]==c[i] or b[i]==c[i]:
    cnt+=1
  else:
    cnt+=2

print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
typedef vector<int> Vec;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



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

	int n, k;
	cin >> n >> k;
	cout << min((n + k) % k, k - (n + k) % k) << endl;
	return 0;
}

Measured memory_bytes: 256
object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val ls = List.fill(n)(sc.nextInt)
    println(ls.filter(i => is_prime(i)).size)
  }
  def is_prime2(n: Int): Boolean = {
    if (n == 2) return true
    //val count = (2 to n).filter(i => i * i <= n).filter(j => n % j == 0).size //memory limit exceeded
    val count_seq = for (i <- 2 to n if i * i <= n; if n % i == 0) yield i //memory limit exceeded
    val count = count_seq.size
    if (count == 0) true else false 
  }
  def is_prime(n: Int): Boolean = {
    if (n == 2)
      return true
    var i = 2
    while (i * i <= n){
      if (n%i == 0){
        return false
      }
      i += 1
    }
    return true
  }
}

Measured memory_bytes: 59608