akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {

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

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

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

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

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

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

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


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

fn main() {
    input! {
        n: i32,
        y: i32,
    }
    for a in 0..y / 10000 + 1 {
        for b in 0..(y - a * 10000) / 5000 + 1 {
            let c = (y - a * 10000 - b * 5000) / 1000;
            if c == n - a - b {
                println!("{} {} {}", a, b, c);
                return;
            }
        }
    }
    println!("{} {} {}", -1, -1, -1);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

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

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    REP(i,m){
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
    }
    int ans = 0;
    REP(i,m){
        UnionFind uf(n);
        set<int> st;
        REP(j,m) if(i != j) uf.unite(a[j], b[j]);
        REP(i,n) st.insert(uf.root(i));
        if(st.size() != 1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>

int N,M;
//(+,+,+),(+,+,-),(+,-,+),(+,-,-)
//(-,+,+),(-,+,-),(-,-,+),(-,-,-)
long long x[100000];
long long y[100000];
long long z[100000];

long long sum[100000];
int main(){
        long long cnt = 0;
        scanf("%d %d",&N,&M);

        for(int i = 0; i < N; i++){
                scanf("%lld %lld %lld", x+i, y+i, z+i);
        }
        long long maxtotal = 0;
        for(int d = 0; d < 8; d++){
                char dx=(d&4)?1:-1;
                char dy=(d&2)?1:-1;
                char dz=(d&1)?1:-1;
                for(int i = 0; i < N; i++){
                        sum[i] = dx*x[i]+dy*y[i]+dz*z[i];
                }
                std::sort(sum,sum+N);
                long long total = 0;
                for(int i = N-1; i >= N-1-(M-1); i--){
                        total += sum[i];
                }
                if(maxtotal < total) maxtotal = total;
        }

        printf("%lld\n",maxtotal);
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    int hight;
    int low;
    int sa;
    
    public void soleve(){
       Scanner sc = new Scanner(System.in);
	   for(int i=1;i<8;i++){
        hight = sc.nextInt();
        low = sc.nextInt();
		sa = hight-low;
        System.out.println(sa);
	   }
    }
    
    public static void main(String[] args){
        Main obj = new Main();
        obj.soleve();
    }
}

Measured memory_bytes: 17236
N, x = map(int, input().split())
a = list(map(int, input().split()))

count = 0
if a[0] > x:
    count = a[0] - x
    a[0] = x

for i in range(N-1):
    if a[i] + a[i+1] > x:
        tmp = x - a[i]
        count += a[i+1] - tmp
        a[i+1] = tmp

print(count)


Measured memory_bytes: 14132
#include <cstdio>
#include <math.h>

using namespace std;

#define MAX_N 100001

#define deg(x) (45.0 * atan((double)x) / atan(1.0))

/* -----------------------------------------------------------------------------
	型とクラス定義
----------------------------------------------------------------------------- */

/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */
int a, b, x;	

int main () {

	double v0, d;

	// 個数と長さの読込み
	scanf("%d %d %d", &a, &b, &x);

	v0 = a * a * b / 2.0;
	
	if(x <= v0) d = b / ((double)2.0 * x / (a * b));
	else { d = 2.0 * (a * a * b - x) / double(a * a * a); }
					
	printf("%.10lf\n", deg(d));

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
	int a,b;
	int s=0;
	cin>>a>>b;
	if(a>0){
		s=1;
	}else if(a<0 && b>0){
		s=0;
	}else if(a==0 || b==0){
		s=0;
	}else{
		a=b-a;
		if(a%2==0){
			s=-1;
		}else{
			s=1;
		}
	}
	if(s==-1){
		cout<<"Negative"<<endl;
	}else if(s==0){
		cout<<"Zero"<<endl;
	}else if(s==1){
		cout<<"Positive"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
n, s = int(input()), list(set(map(int, input().split())))
q, t = int(input()), list(set(map(int, input().split())))
l = set()
tl = set()
for tt in (t):
    if tt in tl:
        l.add(tt)
        continue
    mi, md, ma = 0, len(s) // 2, len(s) - 1
    for i in range(mi, ma, 1):
        tl.add(s[mi])
        tl.add(s[md])
        tl.add(s[ma])
        if tt in tl:
            l.add(tt)
            break
        elif mi == md or md == ma:
            break
        elif s[md] < tt:
            mi = md
            md = md + ((ma - md) // 2)
        elif s[md] > tt:
            ma = md
            md = md - ((md - mi) // 2)
print(len(l))


Measured memory_bytes: 16196
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

#define MAX_R 10
#define MAX_C 10000
#define MAX_P 1024

using namespace std;

bool field[MAX_R][MAX_C + 1];	//field[0 ~ MAX_R - 1][1 ~ MAX_C]
int Vinc[MAX_R];
int dp[MAX_P][MAX_C + 1];		//dp[0 ~ MAX_P - 1][1 ~ MAX_C]
int sum;
int table[MAX_P];

int R,C;
int ans;


void Vinc_set(){
	int n = 0;
	for(int i = 0;i < R;i++){
		n = 0;
		for(int j = 1;j <= C;j++){
			if(field[i][j]) n++;
			else n--;
		}
		Vinc[i] = n;
	}

	return ;
}

void table_set(int p,int n){
	if(p == 0){
		table[0] = sum;
	}
	for(int i = n;i < R;i++){
		int next = p + (1 << i);
		//printf("###next = %d\n",next);
		//if(next < pow(2,R)){
		table[next] = table[p] + Vinc[i];
		table_set(next,i + 1);
		//}
	}

	return ;
}

void init(){
	for(int i = 0;i < MAX_P;i++){
		for(int j = 1;j <= MAX_C;j++){
			dp[i][j] = 0;
		}
	}
	Vinc_set();
	table_set(0,0);
	/*puts("###table###");
	for(int i = 0;i < pow(2,R);i++){
		printf("###%d:%d\n",i,table[i]);
	}*/

	return ;
}

int calcHinc(int p,int n){
	int num = 0;
	for(int i = 0;i < R;i++){
		if(p & (1 << i)){
			if(field[i][n]) num--;
			else num++;
		}
		else{
			if(field[i][n]) num++;
			else num--;
		}	
	}

	return num;
}

void solve(){

	init();

	for(int i = 0;i < pow(2,R);i++){
		for(int j = 1;j <= C;j++){
			dp[i][j] = max(dp[i][j - 1],dp[i][j - 1] + calcHinc(i,j));
		}
	}

	ans = 0;
	int sum;
	for(int i = 0;i < pow(2,R);i++){
		sum = table[i];
		for(int j = 1;j <= C;j++){
			sum = max(sum,table[i] + dp[i][j]);
		}
		ans = max(ans,sum);
		//printf("###%d:ans = %d\n",i,ans);
	}

	return ;
}

int main(){

	while(true){
		scanf("%d%d",&R,&C);
		if(R == 0 && C == 0) break;
		int fake;
		sum = 0;
		for(int i = 0;i < R;i++){
			for(int j = 1;j <= C;j++){
				scanf("%d",&fake);
				if(fake) field[i][j] = true;
				else{
					field[i][j] = false;
					sum++;
				}
			}
		}
		//printf("###sum = %d\n",sum);

		solve();
	
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 41332
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#include <cstdio>
#include <cstdint>
#include <unistd.h>

using i64 = std::uint_fast32_t;

namespace io {
  constexpr int is = 1 << 17;
  char ib[is], *ip = ib + is, it;
  inline char getc() {
    if (ip == ib + is) { read(STDIN_FILENO, ib, is); ip = ib; }
    return *ip++;
  }
  inline i64 scan() {
    i64 r = 0;
    if (ip + 16 > ib + is) while ((it = getc()) & 16) r = r * 10 + it - '0';
    else while ((it = *ip++) & 16) r = r * 10 + it - '0';
    return r;
  }
  constexpr int os = 1 << 17;
  char ob[os], *op = ob, ot;
  inline void putc(const char c) {
    *op++ = c;
    if (op == ob + os) { write(STDOUT_FILENO, ob, os); op = ob; }
  }
  /* x shoud be greater than or equal to zero */
  inline void print(i64 x) {
    char d[20];
    int i = 0;
    while (true) {
      d[i] = x % 10 + 48;
      x /= 10;
      ++i;
      if (x <= 0) break;
    }
    while (i--) {
      putc(d[i]);
    }
  }
  inline void flush() {
    write(STDOUT_FILENO, ob, op - ob);
  }
}

signed main() {
  using namespace io;
  i64 h = scan();
  i64 n = scan();
  i64 s = 0;
  for (int i = 0; i < n; i++) {
    s += scan();
  }
  if (s >= h) {
    puts("Yes");
  } else {
    puts("No");
  }
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# 貪欲法で解く
X, Y = map(int, input().split()) # X, Yの入力
A = [X] # Aをlistで管理、ひとまずXは入るので入れておく
while A[-1] * 2 <= Y: # A_{i+1} = 2A_iとするのが最善、これをYを超えない範囲で順に追加していく
    A.append(A[-1] * 2)
print(len(A)) # Aの長さ、すなわち解答の出力

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, Y;
    cin >> X >> Y;
    int ans = 0;
    if(X == 1) ans += 300000;
    if(X == 2) ans += 200000;
    if(X == 3) ans += 100000;
    if(Y == 1) ans += 300000;
    if(Y == 2) ans += 200000;
    if(Y == 3) ans += 100000;
    if(X == 1 && Y == 1) ans+= 400000;
    cout << ans << endl;
}


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

int main(){
    int n;
    cin >> n;
    
    vector<int> h(n);
    rep(i, n){
        cin >> h.at(i);
    }
    
    int max_h = 0, count = 0;
    rep(i, n){
        max_h = max(max_h, h.at(i));
        if(h.at(i) >= max_h) count++;
    }
    
    cout << count << endl;
    return 0;
}

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

using namespace std;
int mp[102];
char s[10];
int main()
{
	int n;
	scanf("%d",&n);
	ll ans=1,m=0,a=0,r=0,c=0,h=0;
	memset(mp,0,sizeof(mp));
	for(int i=0;i<n;i++){
		scanf("%s",s);
		if(s[0]=='M') m++;
		else if(s[0]=='A') a++;
		else if(s[0]=='R') r++;
		else if(s[0]=='C') c++;
		else if(s[0]=='H') h++;
 	}
	//ll sm=m+a+r+c+h-(m>0)-(a>0)-(r>0)-(c>0)-(h>0);
	ll cnt=(m>0)+(a>0)+(r>0)+(c>0)+(h>0);
	if(cnt<3) puts("0");
	else if(cnt==3){
		if(a>0) ans=ans*a;
		if(m>0) ans*=m;
		if(r>0) ans*=r;
		if(c>0) ans*=c;
		if(h>0) ans*=h;
		printf("%lld\n",ans);
	}else{
	   ans=m*a*r+m*a*c+m*a*h+a*r*c+a*r*h+r*c*h+m*r*c+m*r*h+a*c*h+m*c*h;
	   printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string s; cin >> s;
    int l = s.size();
    int interval = 0;
    
    for(int i = 0; i < l - 1; i++)
    {
        if(s[i] != s[i + 1]) interval++;
    }

    cout << interval << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,x;
  cin>>n>>x;
  vector<Int> ls(n);
  for(Int i=0;i<n;i++) cin>>ls[i];

  vector<Int> sm(n+1,0);
  for(Int i=0;i<n;i++) sm[i+1]=sm[i]+ls[i];

  Int ans=0;
  for(Int v:sm) if(v<=x) ans++;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
try:
    N, M = map(int, input().split())
    Xi = [int(x) for x in input().split()]

    if N < 1 or N > 10**5:
        exit()
    if M < 1 or M > 10**5:
        exit()
    if M != len(Xi):
        exit()
    for i in Xi:
        if i < -10**5 or i > 10**5:
            exit()
    Xi = sorted(Xi)

    a = []
    for i in range(M-1):
        a.append(Xi[i+1]-Xi[i])

    a = sorted(a, reverse=True)
    s = 0
    # print(a)
    for i in range(N-1):
        # print(a[0])
        a.pop(0)

    for i in a:
        s += abs(i)
    print(s)
except ValueError:
    exit()
except IndexError:
    print(0)


Measured memory_bytes: 13696
a=[]
for i in range(3):
    ai=list(map(int,input().split()))
    a.append(ai)
n=int(input())
b=[]
for i in range(n):
    b.append(int(input()))
    


for i in range(3):
    for j in range(3):
        for k in range(n):
            if a[i][j]==b[k]:
                a[i][j]='b'

flag=False
for i in range(3):
    if a[i][0]==a[i][1] and a[i][1]==a[i][2]:
        flag=True
    if a[0][i]==a[1][i] and a[1][i]==a[2][i]:
        flag=True
if a[0][0]==a[1][1] and a[1][1]==a[2][2]:
    flag=True
if a[0][2]==a[1][1] and a[1][1]==a[2][0]:
    flag=True

if flag:
    print('Yes')
else:
    print('No')




Measured memory_bytes: 3064
import java.util.*;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        char[] s = sc.next().toCharArray();

        int r = 1;
        int res = 0;
        for(int i=0; i<n-1; i++) {
            if(s[i] == s[i+1]) {
                res++;
            } else {
                r++;
            }
        }

        while(k > 0) {
            if(r>=3) {
                res+=2;
                r-=2;
                k-=1;
            } else if(r==2) {
                res+=1;
                r-=1;
                k-=1;
            } else {
                break;
            }
        }

        System.out.println(res);
    }

}


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

int main() {
	char x;
	cin >> x;
	string s = "abcdefghaijklmnopqrstuvwxyz";
	rep(i, 26) {
		if (s[i] == x) {
			cout << s[i + 1];
			return 0;
		}
	}
}

Measured memory_bytes: 256
# 約数
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

cnt = 0
i = 0
primes = []
while cnt < 55:
    n = i*5 + 2
    if len(make_divisors(n)) == 2:
        primes.append(n)
        cnt += 1
    i += 1

N = int(input())
print(*primes[:N])

Measured memory_bytes: 3064
# coding: utf-8

def ncr(n, r, mod):
    ret = 1
    for i in range(1, r+1):
        ret = (ret * (n-i+1) * pow(i, mod-2, mod)) % mod
    return ret


def solve(*args: str) -> str:
    s = int(args[0])
    mod = 10**9+7
    d, r = divmod(s, 3)

    ret = 0
    for i in range(d):
        m = 3*i+r
        ret = (ret + ncr(m+d-i-1, d-i-1, mod)) % mod

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


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

int main(void){
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A), min_a(A);
  vector<int> b(B), min_b(B);
  for(int i = 0; i < A; i++){
    cin >> a[i];
    min_a[i] = a[i];
  }
  for(int j = 0; j < B; j++){
    cin >> b[j];
    min_b[j] = b[j];
  }
  sort(min_a.begin(), min_a.end());
  sort(min_b.begin(), min_b.end());
  int min_s = min_a[0] + min_b[0];
  for(int i = 0; i < M; i++){
   int x, y, c;
    cin >> x >> y >> c;
    int sum = a[x - 1] + b[y - 1] - c;
    if(sum < min_s) min_s = sum;   
  }
  cout << min_s;
  
  return 0;
}

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

int main() {
  int a; 
  int b;
  cin >> a >> b ; 
    
 if ((a-(a/500)*500) <= b){
   
 
  cout << "Yes" << endl;
}
  else{
    cout <<"No" << endl;
  }
}
  




Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int n;
	int p;
	int mx = -1;
	int sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p;
		mx = max(mx, p);
		sum += p;
	}
	sum -= (mx / 2);
	cout << sum << endl;
	return 0;
}

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

int main(){
    ll N,K;cin>>N>>K;
    ll cost[N],dif[N];
    rep(i,N)cin>>cost[i];
    rep(i,N)cin>>dif[i];
    sort(cost,cost+N);
    sort(dif,dif+N,greater<int>());
    ll sum=0;
    rep(i,N)sum+=cost[i];
    if(K>=sum)cout<<0<<endl;
    else{
        ll total=0;
        rep(i,N)total+=cost[i]*dif[i];
        ll left=0,right=total,middle=(left+right)/2;
        while(right!=left+1){
            ll now=0;
            rep(i,N)now+=max((ll)0,cost[i]-middle/dif[i]);
            if(now<=K){
                right=middle;
                middle=(left+right)/2;
            }
            else{
                left=middle;
                middle=(left+right)/2;
            }
        }
        cout<<right<<endl;
    }
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>

using namespace std;

int main(){

    int N;
    int X;
    int L[101];
    int D[101];
    L[0] = 0;
    D[0] = 0;
    D[1] = 0; 
    cin >> N >> X;
    for(int i=1;i<=N;i++){
        cin >> L[i];
    }
    
    int itr=1;
    for(int i=2; i<=N+1; i++){
        D[i] = D[i-1] + L[i-1];
        if(D[i] <= X) itr++;
        else break;
    }
    cout << itr <<endl;

    return 0;
}

Measured memory_bytes: 384
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,i,j,ans=0


    read*, n

    do i=1,n
        j = n/i
        ans = ans + ((j*(j+1))/2)*i
    end do
    print'(i0)', ans
end program main

Measured memory_bytes: 2864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll N,K;
    cin >> N >> K;
    vector<ll> P(N);
    vector<ll> C(N);
    REP(i,N)cin >> P[i];
    REP(i,N)P[i]--;
    REP(i,N)cin >> C[i];
    ll max = -2000000000;
    REP(i,N){
        if(P[i] == -1)continue;
        vector<ll> A(0);
        A.pb(C[i]);
        ll bef = P[i];
        P[i] = -1;
        while(1){
            A.pb(C[bef]);
            ll befo = bef;
            bef = P[bef];
            P[befo] = -1;
            if(bef < 0)break;
            if(P[bef] == -1)break;
        }
        ll score = 0;
        ll nokori = K;
        ll allsum = 0;
        REP(l,A.size())allsum += A[l];
        if(allsum <= 0){
            nokori = min(K,(ll)A.size()-1);
        }else{
            if(nokori/A.size() > 1){
                score += (nokori/A.size()-1)*allsum;
                nokori %= A.size();
                nokori += A.size();
            }
        }
        ll siz = A.size();
        REP(l,siz){
            A.pb(A[l]);
        }
        REP(l,siz){
            A.pb(A[l]);
        }
        vector<ll> rui(A.size()+1);
        REP(i,A.size())rui[i+1] = A[i] + rui[i];
        ll maxpls = -2000000000;
        REP(l,A.size()*2/3){
            REPS(al,nokori){
                if(l+al >= A.size())continue;
                chmax(maxpls,rui[l+al]-rui[l]);
            }
        }
        score += maxpls;
        chmax(max,score);
    }
    cout << max << "\n";
}

Measured memory_bytes: 3800
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
ps = sorted(p,reverse=True)[:X]
qs = sorted(q,reverse=True)[:Y]
r.extend(ps)
r.extend(qs)
rs = sorted(r,reverse=True)
deli = 0
for i in range(0,X+Y):
    deli = deli + rs[i]
print(deli)

Measured memory_bytes: 22832
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


int main() {
	IO;
	int k;
	cin>>k;
	string s;
	cin>>s;
	if(sz(s)<=k) cout<<s<<"\n";
	else cout<<s.substr(0,k)<<"...\n";
	return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    string s; cin>>s;
    stack<int> st;
    int ans=0;
    REP(i,s.size()){
        if(st.empty() or st.top()==s[i]) st.push(s[i]);
        else st.pop(),ans+=2;
    }
    cout<<ans<<endl;
}


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

#define MAXN (100010)

int h[MAXN];

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &h[i]);
    }
    std::sort(h + 1, h + n + 1);
    int hmin = INT32_MAX;
    for (int i = 1; i + k - 1 <= n ; ++i) {
        hmin = std::min(hmin, h[i+k-1] - h[i]);
    }
    printf("%d", hmin);
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin>>n;
    while(n--){
        int a[10],b=0,c=0,i;
        for(i=0;i<10;i++){
            cin>>a[i];
        }
        for(i=0;i<10;i++){
            if(a[i]>b&&a[i]>c){
                if(b>c){
                    b=a[i];
                }
                else{
                    c=a[i];
                }
            }
            else if(a[i]>b&&a[i]<c){
                b=a[i];
            }
            else if(a[i]<b&&a[i]>c){
                b=a[i];
            }
            else{
                break;
            }
        }
        if(i==10){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define endl "\n"

using namespace std;

int main() {

    FIO
    string s; cin >> s;
    int ans = 0, temp = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == 'R') {
            ++temp;
            ans = temp;
        }
        else {
            ans = max(ans, temp);
            temp = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
n, m = map(int, input().split())
count_list = [0 for i in range(n)]
for i in range(m):
	t = list(map(int, input().split()))
	a = t[0]
	b = t[1]
	count_list[a-1] += 1
	count_list[b-1] += 1
for c in count_list:
	print(c)

Measured memory_bytes: 38256
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 100005
struct node{int to,next;}e[N<<1];
struct QaQ{int S,D,id;}q[N];
int head[N],cnt,vis[N],dep[N],n,m,Q;
void add(int x,int y){e[cnt]=(node){y,head[x]};head[x]=cnt++;}
void bfs(int S,int D,int id)
{
	if(vis[S]&&dep[S]>=D)return ;queue<int >q;if(D)q.push(S);dep[S]=D;if(!vis[S])vis[S]=id;
	while(!q.empty())
	{
		int x=q.front();q.pop();
		for(int i=head[x];i!=-1;i=e[i].next)
		{
			int to1=e[i].to;
			if(!vis[to1])
			{
				vis[to1]=id;dep[to1]=dep[x]-1;
				if(dep[to1])q.push(to1);
			}
			if(dep[to1]<dep[x]-1)dep[to1]=dep[x]-1,q.push(to1);
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);memset(head,-1,sizeof(head));
	for(int i=1,x,y;i<=m;i++)scanf("%d%d",&x,&y),add(x,y),add(y,x);
	scanf("%d",&Q);
	for(int i=1;i<=Q;i++)scanf("%d%d%d",&q[i].S,&q[i].D,&q[i].id);
	for(int i=Q;i;i--)bfs(q[i].S,q[i].D,q[i].id);
	for(int i=1;i<=n;i++)printf("%d\n",vis[i]);
}

Measured memory_bytes: 4608
#include <stdio.h>
#include <string.h>

int is_kaibun(const char* str, int from, int to) {
	int i;
	if (from > to) return 0;
	for (i = 0; from + i < to - i; i++) {
		if (str[from + i - 1] != str[to - i - 1]) return 0;
	}
	return 1;
}

int main(void) {
	char S[256];
	int N;
	if (scanf("%255s", S) != 1) return 1;
	N = (int)strlen(S);
	puts(N % 2 != 0 && is_kaibun(S, 1, N) && is_kaibun(S, 1, (N - 1) / 2) && is_kaibun(S, (N + 3) / 2, N) ? "Yes" : "No");
	return 0;
}


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

using namespace std;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n, -1) {};
    int root(int v) {
        if (par[v] < 0) return v;
        return par[v] = root(par[v]);
    }
    int size(int v) {
        return -par[root(v)];
    }
    bool unionSet(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return false;
        if (size(a) > size(b)) swap(a, b);
        par[b] += par[a];
        par[a] = b;
        return true;
    }
    bool isSame(int a, int b) {
        return root(a) == root(b);
    }
};


void solve() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }
    int dx[] = {0, -1, 0, 1};
    int dy[] = {-1, 0, 1, 0};

    auto get = [&](int i, int j) {
        return W * i + j;
    };

    UnionFind uf(H * W);
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            for(int k = 0; k < 4; k++) {
                int tx = j + dx[k];
                int ty = i + dy[k];
                if (tx < 0 || tx >= W || ty < 0 || ty >= H) continue;
                if (S[i][j] != S[ty][tx]) {
                    uf.unionSet(get(i, j), get(ty, tx));
                }
            }
        }
    }

    map<int, ll> black;
    map<int, ll> white;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '.') white[uf.root(get(i, j))]++;
            else black[uf.root(get(i, j))]++;
        }
    }

    ll ans = 0;
    for(auto e : white) {
        ans += e.second * black[e.first];
    }
    cout << ans << endl;
    
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

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

int solve(int n)
{
    int cnt = 0;

    for (int x = 1; x*x < n; ++x) {
        for (int y = 1; x*x + y*y + x*y < n; ++y) {
            for (int z = 1; ; ++z) {
                int s = x*x + y*y + z*z + x*y + y*z + z*x;
                if (s == n) {
                    ++cnt;
                } else if (s > n) {
                    break;
                }
            }
        }
    }

    return cnt;
}

int main()
{
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    for (int i = 1; i <= n; ++i) {
        cout << solve(i) << '\n';
    }
}

Measured memory_bytes: 3540
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		//文字数取得
		int S1 = S.length();
		//S1番目から１文字取り出す。
		String T1 = T.substring(S1-0);
		//Ｔで入力さえた値が、Ｓ+１文字と等しいか
		if(T.equals(S+T1)) {
					System.out.println("Yes");
		}else {
					System.out.println("No");
				}
		sc.close();
		 }
		}

Measured memory_bytes: 39240
#include <bits/stdc++.h>
using namespace std;
int main(){           
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   //freopen("input.in","r",stdin); 
     long long a,b,k;
cin>>a>>b>>k;
   if(a>=k){
     cout<<(a-k)<<" "<<b;
   }
   else  {
      cout<<0<<" "<<(max(0LL,(b-(k-a))));
}
   return 0;              
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
using namespace std;

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    
    int ans = a[0];
    for(int i=0; i<n; i++){
        ans = __gcd(ans, a[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
def resolve():
    a,b,c,k = map(int, input().split())
    ans=0
    if k<a:
        ans+=k
        print(ans)
    else:
        k-=a
        ans+=a
        if k<b:
            print(ans)
        else:
            k-=b
            ans-=k
            print(ans)
resolve()

Measured memory_bytes: 79860
#include<bits/stdc++.h>
 using namespace std;
 int a,b,c,d;
 int main()
 {
     cin>>a>>b>>c>>d;
     if(ceil(c*1.0/b)<=ceil(a*1.0/d))puts("Yes");
     else puts("No");
     return 0;
 }

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

const ll mod = 1e9+7;

int main(){

    int n;
    cin >> n;
    string str = "AGCT";
    vector<string> vec = {"A","G","C","T"};
    vector<string> vec2;
    
    queue<string> que;
    rep(i,4) que.push(vec[i]);
    vector<map<string,ll> > dp(n+1);

    while(!que.empty()){
        string str = que.front();
        que.pop();
        rep(j,4){
            if(str.length() == 2)
                vec2.push_back(str+vec[j]);
            else
                que.push(str+vec[j]);
        }
    }

    for(auto e: vec2){
        if(e == "AGC" || e == "ACG" || e == "GAC"){
            dp[3][e] = 0;
        }else{
            dp[3][e] = 1;
        }
    }

    reps(i,3,n){
        for(auto e: vec2){
            rep(j,4){
                string tmp = e.substr(1,2) + vec[j];
                string tmp2 = e + vec[j];
                string tmp3 = tmp2.substr(0,1) + tmp2.substr(2,2);//A*GC
                string tmp4 = tmp2.substr(0,2) + tmp2.substr(3,1);//AG*C
                
                if(tmp != "AGC" && tmp3 != "AGC" && tmp4 != "AGC" && tmp != "ACG" && tmp != "GAC"){
                    dp[i+1][tmp] = (dp[i+1][tmp] +  dp[i][e]) % mod;
                }
            }
        }
    }
    ll ans = 0;
    for(auto e: vec2){
        ans = (ans + dp[n][e]) % mod;
    }
    cout << ans << endl;
    return 0;
}

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

    using namespace std;

    int main()
    {
        int a,b,c;
        cin>>a>>b>>c;
        if(a==b&&a!=c)cout<<"Yes";
        else if(a==c&&a!=b)cout<<"Yes";
        else if(c==b&&a!=c)cout<<"Yes";
        else cout<<"No";

        return 0;
    }

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        int ans = 0;
        for(int i = 100; i > 0; i--) {
            if(a % i == 0 && b % i == 0) {
                ans++;
            }
            if(ans == k) {
                System.out.println(i);
                break;
            }
        }
    }
}


Measured memory_bytes: 21588
from collections import deque
s = input()
n = len(s)
stack1 = deque()
stack2 = deque()
A = 0
a = 0
for ni in range(n):
    if s[ni] == "\\":
        stack1.append(ni)
    elif s[ni] == "/" and len(stack1) > 0 :
        tmp = stack1.pop()
        A += ni - tmp
        while True:
            if len(stack2) > 0 and stack2[-1][0] > tmp:
                a += stack2.pop()[1]
            else:
                break
        a += ni - tmp
        stack2.append([ni,a])
        a = 0
print(A)
print(len(stack2),*[i[1] for i in stack2])


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

class Program
{
    static int N;
    static int M;

    public static void Main(string[] args)
    {
        N = Input.NextInt();
        M = Input.NextInt();

        var divisors = GetDivisors(M).ToArray();
        Array.Sort(divisors);
        int div = 0;
        for (int i = 0; i < divisors.Length; i++)
        {
            div = divisors[i];
            if (div < N)
                continue;
            if ((M % div) == 0)
            {
                break;
            }
        }

        Console.WriteLine(M / div);
    }

    public static IEnumerable<int> GetDivisors(int n)
    {
        for (int i = 1; i < (int)Math.Sqrt(n) + 1; i++)
        {
            if ((n % i) == 0)
            {
                yield return i;
                if (i != n / i)
                {
                    yield return n / i;
                }
            }
        }
        yield break;
    }
}

public static class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

Measured memory_bytes: 13396
n, m = map(int, input().split())
c = list(map(int, input().split()))
INF = 10**9

# i番目までのコインを使ってj円を支払うときの最小枚数
dp = [[INF] * (n+1) for _ in range(m+1)]
dp[0][0] = 0

for i in range(m):
    for j in range(n+1):
        if j >= c[i]:
            dp[i+1][j] = min(dp[i+1][j-c[i]] + 1, dp[i][j-c[i]] + 1, dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]
    
print(dp[m][n])


Measured memory_bytes: 43776
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <iostream>
#include <string>

#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define PB push_back
#define MP make_pair

#define FOR(i, b, e) for(int i=(b);i<(e);i++)
#define REP(i, n) FOR(i,0,n)

#define ALL(v) (v).begin(),(v).end()

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VPII;

const int MOD = 1000000009;
const int INF = 1e9;

const double EPS = 1e-9;
const double PI = acos(-1.0);

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }

LL A, B;

int main() {
    cin >> A >> B;
    cout << lcm(A, B) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
#define check cout<<"?\n";

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

signed main(){
    io();
    int a, b, c; cin >> a >> b >> c;
    if(b - a + c >= 0){
        cout << b - a + c << '\n';
    }else{
        cout << 0 << '\n';
    } 
    return 0;
}

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

int main(void) {
	int a, b, c, d, e, f, w = 0, s = 0, i, j, k, l;
	scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
	a *= 100;
	b *= 100;
	
	for( i = 0; a*i <= f; i++ ) {
		for( j = 0; a*i+b*j <= f; j++ ) {
			int x = a*i+b*j;
			for ( k = 0; x+c*k <= f; k++ ) {
				for ( l = 0; x+c*k+d*l <= f; l++ ) {
					int y = c*k+d*l;
					if ( x*e >= 100*y && x+y <= f ) {
						if ( s*(x+y) <= w*y ) {
							w = x+y;
							s = y;
						}
					}
				}
			}
		}
	}
	
	printf("%d %d", w, s);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,c;
	cin>>a>>b>>c;
	if(c<b){
		cout<<c*a/b<<endl;
		return 0;
	}
	long long ans1=(b-1)*a/b;
	if(((b-1)*a%b+b*a)/b>a){
		long long u=c/b*b-1;
		cout<<max(a*c/b+a*(c/b),a*u/b+a*(u/b))<<endl;
	}else{
		cout<<ans1<<endl;
	}
} 


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<bitset>
#include<queue>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

int main(){
  int d, t, s;
  cin >> d >> t >> s;
  double time = (double)d / s;
  cout << (10*time <= 10*t? "Yes" : "No") << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

map<int, int> prime_factor(int n) {
	map<int, int> res;
	for(int i = 2; i * i <= n; i++) {
		while(n % i == 0) {
			++res[i];
			n /= i;
		}
	}
	if(n != 1) res[n] = 1;
	return res;
}

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

	int N;
	cin >> N;
	vector<int> a(N);
	rep(i, 0, N) cin >> a[i];


	int rsl = 0;
	rep(i, 0, a.size()) {
		map<int, int> m = prime_factor(a[i]);
		rsl += m[2];
	}

	cout << rsl << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <iomanip>
using namespace std;
int main(void){
    // Your code here!
   long double p=0,k;
    int a,n;
    cin >> n;
    cin >> k;
    for(int i = 1; i < n+1; i++){
        long double m = k /i;
            if(m>1){
                a =1 +  log2(m-0.0001);
            }else{
                a = 0;
            }
        //cout << (double)n*exp2(double(a))<< endl;
        p+=(1/(long double)n/exp2((long double)(a))) ;
    }
    cout<< std::setprecision(10)<< p << endl;


    
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int maxv = 0;

    if (a <= c && c <= b)
        maxv = max(maxv, min(b, d) - c);
    if (c <= a && a <= d)
        maxv = max(maxv, min(b, d) - a);

    OP(maxv);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define set_null(a,n) memset(a,0,sizeof(a))
#define pi acos(-1)
#define ll long long int
#define fr(a,b) for(int i=a;i<b;i++)

int main()
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    while(n>0)
    {
        n=n/k;
        cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}



Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;



int main() {
	ios::sync_with_stdio(false);
	cin >> H >> W >> N;
	int y[100001];
	int x[100001];
	map<pair<int, int>, int>m;
	for (int i = 0; i < N; i++) {
		cin >> y[i] >> x[i];
		for (int j = -1; j <= 1; j++) {
			for (int k = -1; k <= 1; k++) {
				if (y[i] + j >= 1 && y[i] + j <= H&&x[i] + k >= 1 && x[i] + k <= W)m[{y[i] + j, x[i] + k}]++;
			}
		}
	}
	long long int num[10] = {};
	for (auto i : m) {
		if (i.first.first >= 2 && i.first.first <= H - 1 && i.first.second >= 2 && i.first.second <= W - 1) {
			//cout << i.first.first << " " << i.first.second << " " << i.second << endl;
			num[i.second]++;
		}
	}
	num[0] = (H - 2)*(W - 2);
	for (int i = 1; i <= 9; i++)num[0] -= num[i];
	for (int i = 0; i < 10; i++)cout << num[i] << endl;
	return 0;
}


Measured memory_bytes: 57344
#include <bits/stdc++.h>
using namespace std;
int main(){
  int X,Y;
  cin >> X >> Y;
  if((-2*X + Y)%2==0&&(4*X - Y)%2==0&&(-2*X + Y)>=0&&(4 * X - Y)>=0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

const int N = 100000;

int x[N];
long long p[N];

int main()
{
    int n, s;
    scanf("%d%d", &n, &s);
    for (int i = 0, a; i < n; ++ i) {
        scanf("%d%d", x + i, &a);
        p[i] = a;
    }
    int i = 0;
    int j = n - 1;
    long long result = 0;
    while (x[i] < s && s < x[j]) {
        result += x[j] - x[i];
        if (p[i] >= p[j]) {
            while (i < j && p[i] >= p[j]) {
                p[i] += p[j --];
            }
        } else {
            while (i < j && p[i] < p[j]) {
                p[j] += p[i ++];
            }
        }
    }
    if (x[j] <= s) {
        result += s - x[i];
    } else {
        result += x[j] - s;
    }
    printf("%lld\n", result);
}

Measured memory_bytes: 1408
def wf(l, n):
    for i in range(n):
        for j in range(n):
            for k in range(n):
                l[j][k] = min(l[j][k], l[j][i] + l[i][k])
    return l


def main():
    n, m, l = map(int, input().split())

    l1 = [[10 ** 15 for i in range(n)] for i in range(n)]

    for _ in range(m):
        a, b, c = map(int, input().split())
        l1[a - 1][b - 1] = c
        l1[b - 1][a - 1] = c

    l1 = wf(l1, n)

    l2 = [[10 ** 4 for i in range(n)] for i in range(n)]

    for i in range(n):
        for j in range(n):
            if l1[i][j] <= l:
                l2[i][j] = 1

    l2 = wf(l2, n)

    q = int(input())
    lq = []
    for _ in range(q):
        lq.append(list(map(int, input().split())))

    for sq in lq:
        res = l2[sq[0] - 1][sq[1] - 1]
        if res == 10 ** 4:
            print(-1)
        else:
            print(res - 1)


main()


Measured memory_bytes: 77272
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    ll k; cin >> k;
    for(auto& c : s){
        if(c == '1'){
            k--;
        }else{
            cout << c << '\n';
            return 0;
        }
        if(k == 0){
            cout << c << '\n';
            return 0;
        }
    }
}


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

int main(){
  ll X;
  cin >>X;
  ll g,h;
  ll x,y;
  for(ll a=0;a<=1000;a++){
  	for(ll b=-1000;b<a;b++){
    	 y=a*a*a*a*a;
    	 x=b*b*b*b*b;
      if((y-x)==X){g=a,h=b;break;}
    }
  
  }
  cout<<g<<' '<<h;
}  

Measured memory_bytes: 3600