akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

ll solve(ll n, ll k) {
    ll ret = 0;
    eFOR(i, 1, n - 2) {
        eFOR(j, 1, 5)if ((63LL * (i + 1) + 9 * (j + 1) - 63) % 11 == k) {
            ++ret;
        }
    }
    return ret;
}

int main() {
    init();

    ll n, k; cin >> n >> k;
    /*
    1<=j<=5
    sum=63*(i+1)+9*(j+1)-63
    */
    ll a[11] = {};
    eFOR(i, 1, 9) {
        eFOR(j, 1, 5) {
            ++a[(63LL * (i + 1) + 9 * (j + 1) - 63) % 11];
        }
    }
    ll b[11] = {};
    eFOR(i, 1, 10) {
        eFOR(j, 1, 5) {
            ++b[(63LL * (i + 1) + 9 * (j + 1) - 63) % 11];
        }
    }
    ll c[11] = {};
    eFOR(i, 1, 11) {
        eFOR(j, 1, 5) {
            ++c[(63LL * (i + 1) + 9 * (j + 1) - 63) % 11];
        }
    }
    if (n <= 11)cout << solve(n, k) << "\n";
    else {
        ll ans = (n / 11 - 1) * c[k] + solve(n % 11, k);
        if (n % 11 == 0)ans += a[k];
        else if (n % 11 == 1)ans += b[k];
        else ans += c[k];
        cout << ans << "\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

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

int main() {
    int N, K;
    ll max = -1;
    cin >> N >> K;
    vector<ll> P(N), Q(N + 1, 0);
    rep(i, N) { cin >> P.at(i); }
    rep(i, N) { Q.at(i + 1) = 1 + Q.at(i) + P.at(i); }

    rep(i, N + 1 - K) { chmax(max, Q.at(i + K) - Q.at(i)); }
    cout << fixed << max / 2.0 << endl;
}


Measured memory_bytes: 6328
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <limits>
#include <numeric>

using ld = long double;
using ll = long long int;
using ul = unsigned long long int;

namespace lamlib
{
	/* constant */
	constexpr double epsilon = std::numeric_limits<double>::epsilon();

	/* math */
	template<class T> inline T abs(const T &a){ return (a>0) ? a : -a; }
	ul inline digit(const ul &num){ return static_cast<ul>(std::log10(num+epsilon))+1; }

	/* algorithm */
	ul gcd(const ul &a,const ul &b) { return (!b) ? a : gcd(b,a%b); }
	std::vector<bool> eratosthenes(const ul &n)
	{
		std::vector<bool> prime_candidate(n,true);
		prime_candidate[0] = prime_candidate[1] = false;
		for(ul i = 2;i*i < n;++i)
		{
			if(!prime_candidate[i]) continue;
			for(ul j = 2;i*j < n;++j) prime_candidate[i*j] = false;
		}
		return prime_candidate;
	}
	ll rho_method(const ll &n)
	{
		auto f = [&](const ll &xi){ return (xi*xi+1)%n; };
		ll x = 2, y = 2, d = 1;
		while(d == 1)
		{
			x = f(x);
			y = f(f(y));
			d = lamlib::gcd(lamlib::abs(x-y),n);
		}
		return d;
	}
	// 素因数分解(試し割)
	std::vector<ll> prime_factorization_trial(const ll &n)
	{
		ll num = n;
		std::vector<ll> prime;
		for(ll i = 2;i*i <= n;++i)
		{
			while((num%i) == 0)
			{
				prime.emplace_back(i);
				num /= i;
			}
		}
		if(num > 1) prime.emplace_back(num);
		return prime;
	}

	/* string */
	inline ul same_char_count(const std::string s,const char &ch){ return std::count(std::cbegin(s),std::cend(s),ch); }
}

// std::cout << std::fixed << std::setprecision(15) << std::endl;

int main(int argc,char *argv[])
{
	ld a;
	std::string b;
	std::cin >> a >> b;

	ll c = (b[0]-'0')*100 + (b[2]-'0')*10 + (b[3]-'0')*1;
	std::cerr << c << std::endl;
	std::cout << static_cast<ul>((a*c)/100) << std::endl;

	return 0;
}

Measured memory_bytes: 3760
#include "bits/stdc++.h"
using namespace std;
int INF = numeric_limits<int>::max() / 2;
using ll = long long;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,i;
    cin >> n >> i;
    cout << n - i +1 << endl;
    return 0;
}

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

#define mod 998244353

int main() {
    int N;
    cin >> N;
    vector<int>x(N);
    vector<int>y(N);
    vector<pair<int, int>> elements(N);
    for (int i = 0; i < N; ++i) {
      cin >> x[i];
      cin >> y[i];
      elements[i] = make_pair(x[i], y[i]);
    }
    sort(y.begin(), y.end());
    sort(elements.begin(), elements.end());

    // 2の累乗計算
    ll modPow[N+1];
    modPow[0] = 1;
    for (int i = 1; i < N+1; ++i) {
        modPow[i] = modPow[i-1] * 2 % mod;
    }

    ll ans = modPow[N] + mod - 1;
    ans %= mod;
    ans = ans * N % mod;

    vector<int> over;
    for (int i = 0; i < N; ++i) {
        // 左にi個, 右にN-i-1個の点
        int yi = elements[i].second;
        // vector y には自分自身も含まれていることに注意
        auto iter1 = lower_bound(y.begin(), y.end(), yi);
        int low = distance(y.begin(), iter1);
        // 下にlow個, 上にN-low-1個の点

        auto iter2 = lower_bound(over.begin(), over.end(), yi);
        int lowOver = distance(over.begin(), iter2);
        over.insert(iter2, yi);
        
        // 左下にlowOver個, 左上にi-lowOver個の点
        ans = ans + mod + mod + mod + mod;
        ans = ans - modPow[low] - modPow[N-low-1] - modPow[i] - modPow[N-i-1] + 4;
        ans = ans + modPow[lowOver] + modPow[i-lowOver] + modPow[low - lowOver] + modPow[N-low-1-i+lowOver] - 4;
        ans %= mod;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 6136
#include<bits/stdc++.h>
using namespace std;
#define int  long long
#define tc(t)  int t; cin>>t; while(t--)
#define f(n)    for(int i=0;i<n;i++)
#define endl   "\n"







int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    cin>>a>>b;
    int ans=__gcd(a,b);
     int answer=a*b;
     cout<<answer/ans<<endl;

   







}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define INF 1e18
#define N 200010
using namespace std;
int main(){
	long long a[N],i,n,sum=0,pres=0,ans=INF;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	for(i=0;i<n-1;i++)
	{
		pres+=a[i];
		sum-=a[i];
		ans=min(ans,abs(pres-sum));
	}
	cout<<ans<<endl;
	return 0;
}

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

vector<vector<int> > B;

int uraNum(int num) {
  return 7 - num;
}

int large(int num) {
  return num > uraNum(num);
}

int largeNum(int num) {
  return large(num) ? num : uraNum(num);
}

int nokoriLNum(int t, int f) {
  return 15 - largeNum(t) - largeNum(f);
}

int shining(int lt, int lf) {
  if (lt == 6) {
    return lf == 5;
  }
  if (lt == 5) {
    return lf == 4;
  }
  if (lt == 4) {
    return lf == 6;
  }
  return 0;
}

int leftNum(int t, int f) {
  int nln = nokoriLNum(t, f);
  if ((large(t) + large(f) + shining(largeNum(t), largeNum(f))) % 2) {
    return uraNum(nln);
  }
  return nln;
}

int tateF(int t, int f) {
  return large(f) ? t : uraNum(t);
}

bool cankoro(int x, int y, int h) {
  return B[x][y] / 1000 < h;
}

void put(int t, int f, int x, int y) {
  int l = leftNum(t, f);
  int h = B[x][y] / 1000;

  int tx = x;
  int ty = y - (large(f) ? 1 : -1);
  int yx = x - (large(l) ? 1 : -1);
  int yy = y;
  
  if (!cankoro(tx, ty, h) && !cankoro(yx, yy, h)) {
    B[x][y] -= B[x][y] % 1000;
    B[x][y] += t;
    B[x][y] += 1000;
    return;
  }

  int lf = largeNum(f);
  int ll = largeNum(l);
  
  if (lf > ll) {
    if (cankoro(tx, ty, h)) {
      put(uraNum(lf), tateF(t, f), tx, ty);
      return;
    }
    put(uraNum(ll), f, yx, yy);
  } else {
    if (cankoro(yx, yy, h)) {
      put(uraNum(ll), f, yx, yy);
      return;
    }
    put(uraNum(lf), tateF(t, f), tx, ty);
  }
}

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

    if (n == 0) {
      break;
    }
  
    B.resize(2 * n + 1);
    for (int i = 0; i < B.size(); i++) {
      B[i].resize(2 * n + 1);
      fill(B[i].begin(), B[i].end(), 0);
    }

    for (int i = 0; i < n; i++) {
      int t, f;
      cin >> t >> f;

      put(t, f, n, n);
    }

    vector<int> cnt(7);
    fill(cnt.begin(), cnt.end(), 0);
    for (int i = 0; i < B.size(); i++) {
      for (int j = 0; j < B.size(); j++) {
	cnt[B[j][i] % 1000]++;
	//cout << B[j][i] % 1000 << ' ';
      }
      //cout << endl;
    }

    for (int i = 1; i < 7; i++) {
      cout << cnt[i];
      if (i < 6) {
	cout << ' ';
      }
    }
    cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3272
# #include <stdio.h>
# #include <string.h>
# #include <stdlib.h>

# typedef unsigned long long ull;
# typedef   signed long long sll;


# int comp (const void *x, const void *y) {
# 	return *(int*)x - *(int*)y;
# }

# int min (int x, int y) {
# 	return (x < y) ? x : y;
# }

# int solve (ull x, ull y) {
# 	printf("%llu %llu\n", x, y);
# 	if (x > y) {
# 		return (x / y) * 2 + solve(x % y, y);
# 	} else if (x == 0) {
# 		return 0;
# 	} else {
# 		ull s = y / x;
# 		return s * (x + y) - (s * (s-1) / 2) * x + solve(y % x, x);
# 	}
# }

# int main (void) {
# 	ull n, x;
# 	scanf("%llu%llu", &n, &x);
# 	// if ((x << 1) == n) {
# 	// 	printf("%llu\n", 3 * x);
# 	// } else {
# 	// 	printf("%llu\n", 6 * x);
# 	// }
# 	printf("%llu\n", x + solve(x, n-x));
# 	return 0;
# }

def solve (x, y)
	if x > y then
		(x / y) * y * 2 + solve(x % y, y)
	elsif x == 0
		0
	else
		# s = y / x
		# s * (x + y) - (s * (s-1) / 2) * x + solve(y % x, x)
		(x + y) + solve(y-x, x)
	end
end

$n, $x = gets.chomp.split(' ').map{|i| i.to_i(10)}

puts ($x + solve($x, $n - $x))


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

const int MAXN = 2e5 + 5;
int N;
ll C, h[MAXN], dp[MAXN];

inline ll square(ll x) {
	return x * x;
}

struct line {
	ll m, c;
	line(ll _m, ll _c) {
		m = _m;
		c = _c;
	}
	ll value_at(ll x) {
		return m * x + c;
	}
};

deque<line> lines;

bool verify(line& l1, line& l2, line& l3) {
	return (l3.c - l2.c) * (l2.m - l1.m) >= (l2.c - l1.c) * (l3.m - l2.m);
}

void addline(ll _m, ll _c) {
	line newl = line(_m, _c);
	while (lines.size() >= 2 && verify(lines[(int) lines.size() - 2], lines[(int) lines.size() - 1], newl)) {
		lines.pop_back();
	}
	lines.push_back(newl);
}

ll query(ll x) {
	while (lines.size() > 1 && lines[0].value_at(x) > lines[1].value_at(x)) {
		lines.pop_front();
	}
	return lines[0].value_at(x);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> N >> C;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	dp[0] = 0;
	addline(-2 * h[0], square(h[0]) + dp[0]);
	for (int i = 1; i < N; i++) {
		ll temp = query(h[i]);
		dp[i] = temp + square(h[i]) + C;
		addline(-2 * h[i], square(h[i]) + dp[i]);
	}
	cout << dp[N - 1];
	
	return 0;
}


Measured memory_bytes: 8432
#pragma GCC optimize("O3")
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200010


int main() {
	int a[N];
	f(i, N)a[i] = 0;
	int n, k;
	int x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%d %d", &n, &k);
	f(i, n) {
		scanf("%d", &a[i]);
		if (i >= k) {
			if (a[i] > a[i - k])printf("Yes\n");
			else printf("No\n");
		}
	}

	return 0;
}

Measured memory_bytes: 2424
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int total = sc.nextInt();
        for(int x = 0;x <= n;x++){
            for(int y = 0;y <= n;y++){
                int z = n - x - y;
                if(z < 0){
                    continue;
                }
                if(10000*x + 5000*y + 1000*z == total){
                    System.out.printf("%d %d %d\n",x,y,z);
                    return;
                }
            }
        }
        System.out.printf("%d %d %d\n",-1,-1,-1);
    }
}


Measured memory_bytes: 23764
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let mut vs = vec![];
    for i in 0..5 {
    	vs.push(get!());
    }
    let k = get!();
    for i in 0..5 {
    	let d = vs[i] - vs[0];
		if d.abs() > k {
			println!(":(");
			return;
		}
    }
    println!("Yay!");
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;

inline int divCeil(int a, int b){
    return (a+b-1)/b;
}
int main(){
    int n,k;
    cin >> n >> k;
    int ans = divCeil(n-1,k-1);
    cout << ans << endl;
    return 0;
}

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

#define debug(x)	cerr << #x << ' ' << x << endl

using namespace std;

const int N = 1000005;
const int mod = 1e9 + 7;
const int oo = 1e9;

vector <int> sub[N];
int dp[N], n, q, a[N], S[N];
int t[N * 4];
long long bal[N];

void update(int b, int e, int node, int pos, int val){
	if(b == e){	
		t[node] = max(t[node], val);
		return;
	}
	int mid = (b + e) / 2, l = 2 * node, h = l + 1;
	if(pos <= mid) update(b, mid, l, pos, val);
	else update(mid + 1, e, h, pos, val);
	t[node] = max(t[l], t[h]);
}

int query(int b, int e, int node, int x, int y){
	if(y < b || e < x) return -oo;
	if(b >= x && e <= y) return t[node];
	int mid = (b + e) / 2, l = 2 * node, h = l + 1;
	return max(query(b, mid, l, x, y), query(mid + 1, e, h, x, y));
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i){
		scanf("%d", &a[i]);
		S[i] = S[i-1] + a[i];
	}
	fill(t, t + N * 4, -oo);
	scanf("%d", &q);
	int x, y;
	for(int i = 1; i <= q; ++i){
		scanf("%d %d", &x, &y);
		sub[x].push_back(y);
	}
	for(int i = 1; i <= n; ++i){
		update(1, n, 1, i, dp[i - 1] - S[i - 1]);
		for(auto kt : sub[i]){
			dp[kt] = max(dp[kt], S[kt] + max(query(1, n, 1, i, kt), dp[i - 1] - S[i - 1]));
			update(1, n, 1, kt, dp[kt] - S[kt]);
		}
		dp[i] = max(dp[i], dp[i - 1] + (a[i] ^ 1));
	}
	cout << n - dp[n] << endl;
	return 0;
}


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

int main()
{
  int a,b;
  cin >> a >> b;
  if(a == 1) a = 14;
  if(b == 1) b = 14;
  if(a > b) cout << "Alice" << endl;
  else if(a == b) cout << "Draw" << endl;
  else cout << "Bob" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
const int MOD=100000;
int B=1000000;
int dtx[4]={0,1,0,-1};
int dty[4]={1,0,-1,0};
int dkx[4]={0,-1,0,1};
int dky[4]={-1,0,1,0};
bool fld[50][50];
bool used[50][50][50][50];
struct A{int tx,ty,kx,ky,cnt;};
int X,Y;
bool pos(int x,int y){
      if(x<0||x>=X||y<0||y>=Y)return false;
      if(fld[x][y])return false;
      return true;
}
int main(){
      int tx,ty,kx,ky;
      while(cin>>X>>Y&&(X||Y)){
            int ans=-1;
            memset(used,false,sizeof(used));
            cin>>tx>>ty>>kx>>ky;tx--;ty--;kx--;ky--;
            REP(i,Y)REP(j,X)cin>>fld[j][i];
            queue<A>Q;
            Q.push((A){tx,ty,kx,ky,0});
            while(Q.size()){
                  A a=Q.front();Q.pop();
                  if(a.cnt>=100)continue;
                  if(a.tx==a.kx&&a.ty==a.ky){
                        ans=a.cnt;
                        break;
                  }
                  //cout<<a.tx<<" "<<a.ty<<" "<<a.cnt<<" "<<a.kx<<" "<<a.ky<<endl;
                  REP(i,4){
                        int ntx=a.tx+dtx[i],nty=a.ty+dty[i];
                        int nkx=a.kx+dkx[i],nky=a.ky+dky[i];
                        if(!pos(ntx,nty)){ntx=a.tx;nty=a.ty;}
                        if(!pos(nkx,nky)){nkx=a.kx;nky=a.ky;}
                        if(used[ntx][nty][nkx][nky])continue;
                        used[ntx][nty][nkx][nky]=true;
                        Q.push((A){ntx,nty,nkx,nky,a.cnt+1});
                  }
            }
            if(ans==-1)cout<<"NA"<<endl;
            else cout<<ans<<endl;
      }
}

Measured memory_bytes: 7536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  ll ans = INF;
  chmin(ans, 2 * C * X + B * max(0LL, Y - X));
  chmin(ans, 2 * C * Y + A * max(0LL, X - Y));
  chmin(ans, A * X + B * Y);
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [A, B] = [long(input_raw[0]), long(input_raw[1])]
    print (A-1)*(B-1)
if __name__ == '__main__':
    main()

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

int main(){

    ll n; cin >> n;

    vll yakusuu_cnt(n+1);

    rep2(i, 1, n+1){
        for(ll j=1;i*j<=n;j++){
            yakusuu_cnt[i*j]++;
        }
    }

    ll sum = 0;
    rep2(i, 1, n+1) sum += yakusuu_cnt[i]*i;

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 81368
#include <iostream>
#include <string>
#include <stdio.h>

#define N 1000

using namespace std;

int main()
{
	int n;
	int s;
	string str;

	cin >> n;
	cin.ignore();

	for(int i = 0; i < n; i++)
	{
		getline(cin,str);

		for(s = 0; s < N; s++){

		if(str[s] == 'H' && str[s+1] =='o' && str[s+2] == 's' && str[s+3] == 'h' 
			&& str[s+4] == 'i' && str[s+5] == 'n' && str[s+6] == 'o' ){
				
				str[s] = 'H';
				str[s+1] = 'o';
				str[s+2] = 's';
				str[s+3] = 'h';
				str[s+4] = 'i';
				str[s+5] = 'n';
				str[s+6] = 'a';
			}

		}
		cout << str << endl;

	}
}

Measured memory_bytes: 1204
#C
import math
K =int(input())
ans=0
for i in range(1, K+1):
    for j in range(1, K+1):
        tmp_gcd=math.gcd(i,j)
        for k in range(1, K+1):
            ans+=math.gcd(tmp_gcd, k)
print(ans)

Measured memory_bytes: 9168
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static long Solve(int N, int K)
        {
            long a = 0;
            long b = 0;
            for (int i = 1; i <= N; ++i)
            {
                if (i % K == 0) { ++a; }
                else if ((i % K) * 2 == K) { ++b; }
            }
            return a * a * a + b * b * b;
        }
        static void Main(string[] args)
        {
            int[] V = ReadInts();
            Console.WriteLine(Solve(V[0], V[1]));
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int b,i;
  vector <int> v;
  for(i=0;i<5;i++) {
    cin >> b;
    v.push_back(b);
  }
  sort(v.begin(),v.end(),greater<int>());
  cout << v[0];
  for(i=1;i<5;i++) cout << " " << v[i];
  cout << endl;
}

Measured memory_bytes: 1216
using namespace std;
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
ll power(ll x, ll p)
{
  ll res=1;
  while(p)
  {
    if(p%2)
     { res=(res%mod*x%mod+mod)%mod;
      p--,res%=mod;}
    else
      x=(x%mod*x%mod+mod)%mod,p/=2;
   }
  return res%mod;
}
int main()
{
  ll n;
  cin>>n;
  if(n==1)
  {
    cout<<0<<endl;
    return 0;
  }
  ll x = (power(10,n)-2*power(9,n)+power(8,n)%mod+mod)%mod;
  cout<<(x+mod)%mod<<endl;
  return 0;
}


Measured memory_bytes: 3596
macro_rules! input {
    ($ttype:ty) => {
        {
            let mut input = String::new();
            let _= std::io::stdin().read_line(&mut input);
            input.trim().parse::<$ttype>().unwrap()
        }
    };

    ($($ttype:ty),*) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let mut iter = input.trim().split_whitespace();
            (
                $(iter.next().unwrap().parse::<$ttype>().unwrap(),)*
            )
        }
    };

    ($ttype:ty; $x:expr) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let v: Vec<$ttype> = input
                .trim()
                .split_whitespace()
                .map(|x| x.parse().unwrap())
                .collect();
            v
        }
    };

    ($ttype:ty; $x:expr; $y:expr) => {
        {
            use std::io::BufRead;
            let mut matrix = Vec::with_capacity($y);
            for _ in 0..$y {
                let mut input = String::new();
                let stdin = std::io::stdin();
                let _ = stdin.lock().read_line(&mut input);
                let v: Vec<$ttype> = input
                    .trim()
                    .split_whitespace()
                    .map(|x| x.parse().unwrap())
                    .collect();
                matrix.push(v);
            }
            matrix
        }
    };
}

fn countup_target<T: PartialEq>(target: T, vec: Vec<T>) -> usize {
    let mut counter: usize = 0;
    for item in vec {
        if target == item {
            counter += 1;
        }
    }
    counter
}

fn main() {
    let n = input!(usize);
    let mut s_list: Vec<Vec<char>> = Vec::with_capacity(n);
    for _ in 0..n {
        let s = input!(String);
        s_list.push(s.chars().collect());
    }

    s_list.sort_by_key(|x| x.len());
    let mut alphabet_counter: Vec<(_, _)> = Vec::with_capacity(26);
    for alphabet in ('a' as u8)..('z' as u8)+1 {
        let mut counter = usize::max_value();
        for s in s_list.iter() {
            let cnt = countup_target(alphabet as char, s.to_vec());
            if counter > cnt {
                counter = cnt;
            }
        }
        alphabet_counter.push((alphabet as char, counter));
    }

    for &(alphabet, counter) in alphabet_counter.iter() {
        for _ in 0..counter {
            print!("{}", alphabet);
        }
    }
    println!("");
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RREP(i,n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()

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

const int INF = 1e9;
const int MOD = 1e9+7;

int n, k, s;

ll dfs(int n, int k, int s){
    if(n < 0 || s < 0) return 0;
    if(!k){
        if(!s) return 1;
        else return 0;
    }
    ll ret = 0;
    ret += dfs(n - 1, k - 1, s - n);
    ret += dfs(n - 1, k, s);
    return ret;
}

int main(void){
    while(cin >> n >> k >> s, n){
        cout << dfs(n, k, s) << endl;
    }
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

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

    string s;
    cin >> s;

    bool ok = true;
    REP(i, s.length()) {
        if (i == a) {
            if (s[i] != '-') ok = false;
        } else {
            if (s[i] < '0' || '9' < s[i]) ok = false;
        }
    }


    cout << (ok ? "Yes" : "No") <<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[100],sum=0,b[100],m=10,p,n,j=0;
	for(int i=0;i<5;i++)
	{
		cin>>n;
		a[i]=n/10*10+10;
		if(n%10<m&&n%10!=0)
		{
			m=n%10;
			p=i;
		}
		if(n%10==0)
		j++;
	}
	for(int i=0;i<5;i++)
	{
		if(i!=p)
		sum+=a[i];
	}
	sum=sum+a[p]-10+m-j*10;
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
N,K=gets.split.map(&:to_i)
ls=N.times.map{gets.split.map(&:to_i)}
ans=Float::INFINITY
ls.combination(K>=4 ? 4 : K) do |a|
    b=a.transpose
    next if (K>=4 ? 4 : K) != b[0].uniq.size || (K>=4 ? 4 : K) != b[1].uniq.size
    ix,ax=b[0].minmax
    iy,ay=b[1].minmax
    cnt=0
    ls.each do |i|
        x,y=i
        cnt+=1 if ix<=x && x<=ax && iy<=y && y<=ay
    end
    ans = ans > (ax-ix)*(ay-iy) ? (ax-ix)*(ay-iy) : ans if cnt>=K
end
puts ans


Measured memory_bytes: 3836
D = int(input())
c = list(map(int, input().split()))
s = []
for i in range(D):
  s.append(list(map(int, input().split())))
  
sdictlist = []
sdictlistsorted = []
for i in range(D):
  onedict = {}
  for j in range(26):
    onedict[j] = s[i][j]
  sdictlist.append(onedict)
  onesorteddict = sorted(onedict.items(), key=lambda x:x[1], reverse=True)
  sdictlistsorted.append(onesorteddict)

cignorelen = 3
csorted = sorted(c)
csorted = csorted[:cignorelen]
ignorelist = []
for i in range(26):
  if(c[i] in csorted):
    ignorelist.append(i+1)
    
lenpastmax = 14 #26まで設定できる
#26 -> 145419
#25 -> 18657778
#24 -> 40796238
#23 -> 54875726
#22 -> 63195752
#21 -> 66843963
#20 -> 67734290, ign=5 -> 3733319, ign=3 -> 41602078
#18                                ign=3 -> 50909415
pastlist = []
for i in range(D):
  j = 0
  while(sdictlistsorted[i][j][0] in pastlist or sdictlistsorted[i][j][0]+1 in ignorelist):
    j += 1
  print(sdictlistsorted[i][j][0]+1)
  pastlist.append(sdictlistsorted[i][j][0])
  if(len(pastlist)==lenpastmax):
    pastlist.pop(0)


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

using namespace std;

bool D[10];

bool check(int N){
    while(N){
        if(D[N%10]) return false;
        N /= 10;
    }
    return true;
}

int main(){
    int N,K;
    cin >> N >> K;
    for(int i=0;i<K;i++){
        int a; cin >> a;
        D[a] = true;
    }
    while(true){
        if(check(N)){
            cout << N << endl;
            break;
        }
        N++;
    }
    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,true):false;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,true):false;}

int nextInt() {
  int x; scanf("%d", &x); return x;
}

struct BIT {
  int n;
  vector<ll> tree;
  BIT(int n):n(n),tree(n+1) {} 
  void fill(ll val) {
    REP(i, n+1) tree[i] = (i&-i) * val;
  }
  void add(int idx, ll val) {
    for (int x=idx+1; x<=n; x+=x&-x) tree[x] += val;
  }
  ll range(int idx) {
    ll sum=0;
    for (int x=idx+1; x>0; x-=x&-x) sum += tree[x];
    return sum;
  }
};

const int MAX_N = 200000 + 10;
ll a[MAX_N];
ll b[MAX_N];

int main2() {
  int N = nextInt();
  int K = nextInt();
  REP(i, N) a[i] = nextInt() - K;
  b[0] = 0;
  REP(i, N) b[i+1] = b[i] + a[i];
  vector<ll> c(N+1);
  REP(i, N+1) c[i] = b[i];
  sort(c.begin(), c.end());
  c.erase(unique(c.begin(), c.end()), c.end());

  // REP(i, c.size()) cout << c[i] << " "; cout << endl;

  BIT bit(N + 10);

  ll ans = 0;
  REP(i, N+1) {
    int idx = (int)(lower_bound(c.begin(), c.end(), b[i]) - c.begin());
    ans += bit.range(idx);
    bit.add(idx, 1);
  }
  cout << ans << endl;


  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    ll t,n,k,j=0,ans=0,x=0,t1,i;
    cin>>t;
    ll a[t];
    for(i=0;i<t;i++)
        cin>>a[i];
    for(i=0;i<t;i++){
        while((a[j]^x)==(a[j]+x) && j<t){
            x+=a[j];
            j++;
        }
        ans+=j-i;
        x=x^a[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
using namespace std;
using Int = long long;
#define DUMP(range) do{for(auto& x:range){cout<<x<<' ';}cout<<endl;}while(0)
int main()
{
    int N, x; cin >> N >> x;
    vector<int> A(N); for (auto& a : A) cin >> a;
    sort(A.begin(), A.end());
    int ans = 0;
    for (auto a : A) {
        if (a > x) break;
        x -= a;
        ans++;
    }
    if (ans == A.size() && x > 0) ans--;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int inf=1<<30;
vector<int> ans;
vector<int> g[100010];
int n,m;
bool vis[100010];
inline int read(){
    char ch=' ';
	int x=0;
    while(!isdigit(ch))ch=getchar();
    while(isdigit(ch))
	{
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	return x;
}
bool ok(){
	if(ans.size()<2)return false;
	for(int i=0;i<g[ans[0]].size();i++){
		//cout<<g[ans[0]][i]<<" "<<vis[g[ans[0]][i]]<<endl;
		if(!vis[g[ans[0]][i]])return false;
	}
	for(int i=0;i<g[ans[ans.size()-1]].size();i++){
		//cout<<g[ans[ans.size()-1]][i]<<" "<<vis[g[ans[ans.size()-1]][i]]<<endl;
		if(!vis[g[ans[ans.size()-1]][i]])return false;
	}
	//cout<<ans[0]<<" "<<ans[ans.size()-1]<<endl;
	return true;
}
int main(){
	int n,m;
	n=read();m=read();
	int a,b;
	while(m--){
		a=read();b=read();
		if(ans.size()==0){ans.push_back(a);ans.push_back(b);}
		g[a].push_back(b);
		g[b].push_back(a);
	}
	memset(vis,false,sizeof(vis));
	vis[ans[0]]=true;
	vis[ans[1]]=true;
	while(!ok()){
		for(int i=0;i<g[ans[0]].size();i++){
			if(!vis[g[ans[0]][i]]){
			ans.insert(ans.begin(),g[ans[0]][i]);vis[ans[0]]=true;break;}
		}
		for(int i=0;i<g[ans[ans.size()-1]].size();i++){
			if(!vis[g[ans[ans.size()-1]][i]]){
				vis[g[ans[ans.size()-1]][i]]=true;
				ans.push_back(g[ans[ans.size()-1]][i]);
				break;
			}
		}
	}
	cout<<ans.size()<<endl;
	for(int i=0;i<ans.size();i++){
		cout<<ans[i]<<" ";
	}
	return 0;
}

Measured memory_bytes: 6904
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int  a, b, c, k, ans;
  cin >> a >> b >> c >> k;
  if(k <= a){
    ans = k;
  }else if(k <= a+b){
    ans = a;
  }else{
    ans = a - (k - (a + b));
  }
  
  
  cout << ans <<endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstdio>
using namespace std;

#define int long long
#define INF 1e18

int func(string s, string t);

signed main() {
    int x; cin >> x;
    int ans = 0;

    if(x == 1) {
        cout << 1 << endl;
        return 0;
    }
    
    for(int i = 1; i <= x / 2 + 1; i++) {
        for(int j = 2; j <= x / 2 + 1; j++) {
            int tmp = pow(i, j);
            if(tmp <= x) {
                ans = max(ans, tmp);
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 512
import math

n = int(input())
prime = [2,3]
for i in range(5,55556):
	check = True
	for k in range(2,int(i**0.5)+1):
		if i%k == 0:
			check = False
	if check:
		prime.append(i)

ans = []
i = 0
while len(ans) < n:
	if prime[i]%5 == 1:
		ans.append(prime[i])
		i += 1
	else:
		i += 1
	
for i in range(n):
	if i != n-1:
		print(ans[i],end = ' ')
	else:
		print(ans[i])

Measured memory_bytes: 3444
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
dp = [[None]*(n+1) for i in range(64)]
for i in range(1, n+1):
    dp[0][i] = a[i]
for i in range(63):
    for j in range(1, n+1):
        dp[i+1][j] = dp[i][dp[i][j]]

k = format(k, "064b")
now = 1
for i in range(64):
    if k[i] == "1":
        now = dp[~i][now]

print(now)


Measured memory_bytes: 176480
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
char a[100010];
long int n;
int main() 
{
	cin >> n;
	cin >> a;
	for (int i = 0; i <n; i++)
	{
		if (a[i] == '\0')
			break;
		cout << a[i];
	}
	if (strlen(a) > n)
	{
		cout << "..." << endl;
	}
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>

#ifdef TEST
struct test {
    int ans;
} td[] = {
    {},
};
#endif

void
solver(int n, int r)
{
    if(n < 10) {
        printf("%d\n", r + 100 * (10 - n));
    } else {
        printf("%d\n", r);
    }
}

int
main(int argc, char *argv[])
{
    int N, R;
#ifdef TEST
    int tt;
    for(tt = 0; tt < sizeof(td) / sizeof(struct test); tt++) {
        solver();
        printf("%d\n", td[tt].ans);
    }
#endif
    scanf("%d%d", &N, &R);
    solver(N, R);
    return 0;
}

Measured memory_bytes: 128
a,b,c,d = map(int,input().split())

divc = b//c-(a-1)//c
divd = b//d-(a-1)//d
import math
l = c*d//math.gcd(c,d)
divl = b//l-(a-1)//l
print(b-a+1-divc-divd+divl)


Measured memory_bytes: 61928
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

const int maxN = 100005;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

class TaskA {
private:
	Debugger debugger;

public:
	void solveOne(int it){
		int s , w;
		cin >> s >> w;
		cout << (w >= s ? "unsafe":"safe") << endl;

	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskA solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;
long long n, k, mx, a[N], s[N], l[N], r;
int main() {
	int i;
	scanf("%d%d", &n, &k);
	for (i=1; i<=n; i++) {
		scanf("%lld", a+i);
		s[i] = s[i-1] + a[i];
		l[i] = l[i-1] + max(0LL, a[i]);
	}
	for (i=n; i>=k; i--) {
		mx = max(mx, l[i-k] + max(0LL, s[i] - s[i-k]) + r);
		r += max(0LL, a[i]);
	}
	printf("%lld", mx);
	return 0;
}

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

#define FOR( i, m, n )   for( int i = m; i < n; i++ )
#define REP( i, n )      FOR( i, 0, n )
#define ALL( a )         (a).begin(), (a).end()

int main(){
  int h, w, x, y; cin >> h >> w >> x >> y;

  if( ( h * w ) % 2 == 1 ){
    if( ( x + y ) % 2 == 1 ){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, k;
    cin >> n >> k;
    vi g(n);
    int p;
    REP(i, n) {
        cin >> p;
        p--;
        g[i] = p;
    }
    vl c(n);
    REP(i, n) cin >> c[i];

    ll ans = -LINF;
    vb v(n, false);
    REP(i, n) {
        if (v[i]) continue;
        vi h;
        int x = i;
        ll sum = 0;
        while (!v[x]) {
            v[x] = true;
            h.emplace_back(x);
            sum += c[x];
            x = g[x];
        }
        int m = sz(h);
        if (k <= m) {
            ll mx = -LINF;
            REP(j, m) {
                ll t = 0;
                REP(z, k) {
                    t += c[h[(j + z) % m]];
                    chmax(mx, t);
                }
            }
            chmax(ans, mx);
            continue;
        }
        int l = k % m;
        // if (l == 0) l = m;
        ll mx = -INF;
        REP(j, m) {
            ll t = 0;
            REP(z, l) {
                t += c[h[(j + z) % m]];
                chmax(mx, t);
            }
        }
        ll mx2 = -INF;
        REP(j, m) {
            ll t = 0;
            REP(z, m) {
                t += c[h[(j + z) % m]];
                chmax(mx2, t);
            }
        }
        // cout << i << ">> " << sum << ":" << mx << "/" << mx2 << endl;
        if (sum >= 0) {
            chmax(ans, sum * (k / m) + mx);
            chmax(ans, sum * (k / m - 1) + mx2);
        } else {
            chmax(ans, mx2);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N;
    cin >> N;
    for(int i = 1; i <= N; i++) {
        if(i+i*2/25 == N) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}


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

#define ll long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
ll mod = 1e9+7;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,k; cin >> n >> k;
    ll ans=0;
    rep(i,k,n+2){
        ll mini;
        ll maxi;
        mini = (i-1)*i/2;//0からkまで
        maxi = n*i - mini;
        (ans += maxi-mini+1)%=mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3656
/*
                ******
		
        Author: Nguyen Phuc Chuong

                ******
*/

#include <bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	long long ans = 0;
	for (int i = 1; i < n; i++) {
		int t = n / i;
		if (n % i == 0) {
			t--;
		}
		ans += t;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
 
    using namespace std;
    using namespace __gnu_pbds;
 
    #define endl "\n"
    #define fi first
    #define se second
    #define pb push_back
    #define int long long 
    #define ll long long
    #define ld long double
    #define pii pair<ll,ll>
 
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define For(i,n) for(ll i=0;i<n;i++)
 
    #define what(x) cerr << #x << " is " << x << endl;
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;
 
    typedef tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> omultiset;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> oset;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> oset1;
 
/*.....................................................................................................................*/
 
    const ll mod=(ll)1e9+ 7;
 
    ll add(ll x,ll y) {return (x+y)%mod;}
    ll mult(ll x, ll y){return ((x%mod )* (y%mod)) % mod;}
 
    long long binpow(long long x, long long p) 
    {
        if (p == 0) {return 1;} 
    	if (p == 2 || (p & 1)) {return mult(x, binpow(x, p - 1));}
    	return binpow(binpow(x, p / 2), 2);
    }
    ll modinv(ll a) {return binpow(a,mod-2);}
 
    //A.erase(unique(A.begin(),A.end()),A.end());
    double pi=3.141592653589793238462641;
    ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
    const ll  man  =   (int)200005   ,  inf   =   1e18;
 
 
/*......................................................................................................................*/



signed main()
{
    fast;
    int n;
    cin>>n;
    vector<vector<int>>a(n,vector<int>(3));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>a[i][j];
        }
    }
    vector<vector<int>>dp(n,vector<int>(3,0));
    for(int i=0;i<3;i++)
    {
        dp[0][i]=a[0][i];
    }
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            for(int k=0;k<3;k++)
            {
                if(j!=k)
                {
                    dp[i][j]=max(dp[i][j],a[i][j]+dp[i-1][k]);
                }
            }
        }
    }
    int ans=0;
    for(int i=0;i<3;i++)
    {
        ans=max(ans,dp[n-1][i]);
    }
    cout<<ans<<endl;
}   

Measured memory_bytes: 14232
from heapq import*
import sys
r=sys.stdin.readline
def g(n,E,S,G):
 F=[1e7]*-~n;F[S]=0;H=[(0,S)]
 while H:
  c,u=heappop(H)
  if u==G:return c
  for f,v in E[u]:
   t=c+f
   if t<F[v]:F[v]=t;heappush(H,(t,v))
 return-1
def s(n,k):
 E=[[]for _ in[0]*-~n]
 for _ in[0]*k:
  f=r()
  if'0'==f[0]:print(g(n,E,*map(int,f[2:].split())))
  else:c,d,e=map(int,f[2:].split());E[c]+=[(e,d)];E[d]+=[(e,c)]
for e in iter(r,'0 0\n'):s(*map(int,e.split()))


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

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};


ll a[N];
int main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++)
		cin >> a[i];
	ld s = 0.;
	sort(a + 1, a + n + 1);
	s = (a[1] + a[2]) / 2.0;
	for(int i = 3; i <= n; i ++)
	{
		s += a[i];
		s /= 2.0;
	}
	cout << setprecision(5) << fixed << s << '\n';




	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

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

int main()
{
    int n;
    while(cin>>n){
        if(n&1){
            cout<<n/2*(n+1)/2<<endl;
        }else{
            cout<<n*n/4<<endl;
        }
    }
    return 0;
}


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

using namespace std;

int main() {
	int d[2][12],n,i,j,k,c,s;
	while(cin >> n) {
		if (n==0) break;
		for (i=0;i<n;i++) cin >> d[0][i];
		k=0; s=0;
		while(true) {
          for (i=0;i<n;i++) {
			 for (j=0,c=0;j<n;j++) if (d[k][i]==d[k][j]) c++;
			 d[1-k][i]=c;
		 }
         for (i=0,c=0;i<n;i++) if (d[0][i]==d[1][i]) c++;
		 if (c==n) break;
		 s++; k=1-k;
		}
		cout << s << endl;
        for (i=0;i<n;i++) if (i==0) cout << d[0][i]; else cout << ' ' << d[0][i];
		cout << endl;
	}
    return 0;
	}

Measured memory_bytes: 1160