akhauriyash/Code-Regression huggingface dataset:
package main

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

func main() {
	defer writer.Flush()
	n, q := ReadInt(), ReadInt()
	t := NewLazySegTree(n)
	for ; q > 0; q-- {
		if ReadInt() == 0 {
			t.Update(ReadInt(), ReadInt()+1, ReadInt())
		} else {
			Println(t.GetSum(ReadInt(), ReadInt()+1))
		}
	}
}

type LazySegTree struct {
	nodes []int
	lazy  []int
}

const Inf = 1 << 62
const None = -Inf

func NewLazySegTree(n_ int) *LazySegTree {
	n := 1
	for n < n_ {
		n <<= 1
	}
	t := &LazySegTree{
		nodes: make([]int, n<<1),
		lazy:  make([]int, n<<1),
	}
	for i := 1; i < len(t.lazy); i++ {
		t.lazy[i] = None
	}
	return t
}

func (t *LazySegTree) lazyEval(k, l, r int) {
	if t.lazy[k] == None {
		return
	}
	t.nodes[k] = t.lazy[k]
	if r-l > 1 {
		t.lazy[k<<1] = t.lazy[k] >> 1
		t.lazy[k<<1+1] = t.lazy[k] >> 1
	}
	t.lazy[k] = None
}

func (t *LazySegTree) Update(a, b, x int) {
	t.updateRecur(a, b, x, 1, 0, len(t.nodes)>>1)
}
func (t *LazySegTree) updateRecur(a, b, x, k, l, r int) {
	t.lazyEval(k, l, r)
	if b <= l || r <= a {
		return
	}
	if a <= l && r <= b {
		t.lazy[k] = x * (r - l)
		t.lazyEval(k, l, r)
	} else {
		t.updateRecur(a, b, x, k<<1, l, (l+r)>>1)
		t.updateRecur(a, b, x, k<<1+1, (l+r)>>1, r)
		t.nodes[k] = t.nodes[k<<1] + t.nodes[k<<1+1]
	}
}

func (t *LazySegTree) GetSum(a, b int) int {
	return t.getSumRecur(a, b, 1, 0, len(t.nodes)>>1)
}
func (t *LazySegTree) getSumRecur(a, b, k, l, r int) int {
	t.lazyEval(k, l, r)
	if b <= l || r <= a {
		return 0
	}
	if a <= l && r <= b {
		return t.nodes[k]
	} else {
		return t.getSumRecur(a, b, k<<1, l, (l+r)>>1) +
			t.getSumRecur(a, b, k<<1+1, (l+r)>>1, r)
	}
}

var scanner = bufio.NewScanner(os.Stdin)

func init() {
	scanner.Buffer(make([]byte, 256), 1e9)
	scanner.Split(bufio.ScanWords)
}
func ReadString() string { scanner.Scan(); return scanner.Text() }
func ReadInt() int {
	a, err := strconv.Atoi(ReadString())
	if err != nil {
		panic(err)
	}
	return a
}

var writer = bufio.NewWriter(os.Stdout)

func Println(a ...interface{}) { fmt.Fprintln(writer, a...) }



Measured memory_bytes: 7404
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000

using namespace std;

int table_4[24][4],table_5[120][5],index_9,m_data[9] = {0,1,2,3,4,5,6,7,8};
int** table_9;

void calc9(){
	int select_num = 5,num,loc_left[5],loc_right[4],left_index,right_index,left_calc[5],right_calc[4];

	index_9 = 0;

	for(int i = 0; i < 512;i++){
		num = 0;
		for(int k = 0; k < 9; k++){
			if(i & (1 << k))num++;
		}
		if(num != select_num)continue;

		left_index = right_index = 0;

		for(int k = 0; k < 9; k++){
			if(i & (1 << k)){
				loc_left[left_index++] = k;
			}else{
				loc_right[right_index++] = k;
			}
		}

		left_index = right_index = 0;

		left_calc[0] = m_data[loc_left[0]],left_calc[1] = m_data[loc_left[1]],left_calc[2] = m_data[loc_left[2]],left_calc[3] = m_data[loc_left[3]],left_calc[4] = m_data[loc_left[4]];
		right_calc[0] = m_data[loc_right[0]],right_calc[1] = m_data[loc_right[1]],right_calc[2] = m_data[loc_right[2]],right_calc[3] = m_data[loc_right[3]];

		for(int k = 0; k < 120; k++){
			for(int p = 0; p < 24; p++){
				for(int a = 0; a < 5; a++){
					table_9[index_9][a] = left_calc[table_5[k][a]];
				}
				for(int a = 0; a < 4; a++){
					table_9[index_9][5+a] = right_calc[table_4[p][a]];
				}
				index_9++;
			}
		}
	}
}


int main(){

	int index_4 = 0;

	for(int a = 0; a < 4; a++){
		for(int b = 0; b < 4; b++){
			for(int c = 0; c < 4; c++){
				for(int d = 0; d < 4; d++){
					if(a != b && a != c && a != d && b != c && b != d && c != d){
						table_4[index_4][0] = a,table_4[index_4][1] = b,table_4[index_4][2] = c,table_4[index_4][3] = d;
						index_4++;
					}
				}
			}
		}
	}

	int index_5 = 0;

	for(int a = 0; a < 5; a++){
		for(int b = 0; b < 5; b++){
			for(int c = 0; c < 5; c++){
				for(int d = 0; d < 5; d++){
					for(int e = 0; e < 5; e++){
						if(a != b && a != c && a != d && a != e && b != c && b != d && b != e && c != d && c != e && d != e){
							table_5[index_5][0] = a,table_5[index_5][1] = b,table_5[index_5][2] = c,table_5[index_5][3] = d,table_5[index_5][4] = e;
							index_5++;
						}
					}
				}
			}
		}
	}



	table_9 = new int*[362880];
	for(int i = 0; i < 362880; i++){
		table_9[i] = new int[9];
	}

	calc9();

	int K,gates[9],jenny[9],count,score_G,score_J,work[9];
	double ans_J,ans_G;
	scanf("%d",&K);

	for(int loop = 0; loop < K; loop++){
		for(int i = 0; i < 9; i++)scanf("%d",&gates[i]);
		for(int i = 0; i < 9; i++)scanf("%d",&jenny[i]);

		count = 0;
		for(int i = 0; i < 362880; i++){
			score_G = 0,score_J = 0;
			for(int k = 0; k < 9; k++){
				work[k] = jenny[table_9[i][k]];

				if(work[k] > gates[k]){
					score_J += work[k] + gates[k];
				}else{
					score_G += gates[k] + work[k];
				}
			}
			if(score_J > score_G)count++;
		}

		ans_J = (double)count/(double)362880;
		ans_G = 1 - ans_J;

		printf("%.5lf %.5lf\n",ans_G,ans_J);
	}

    return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void anss(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=0,res2=INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  ll n,a,b;cin>>n>>a>>b;
  vector<ll> h(n);
  for(i=0;i<n;i++){
    cin>>h[i];
  }
  ll l=0,r=MOD;
  while(abs(r-l)>=2){
    buf=(l+r)/2;
    buf2=0;
    for(i=0;i<n;i++){
      if(h[i]>b*buf){
        buf2+=((h[i]-b*buf)+a-b-1)/(a-b);
      }
    }
    if(buf2<=buf){
      r=buf;
    }
    else l=buf;
  }
  cout<<r<<endl;
  
  return 0;
}

Measured memory_bytes: 1152
import bisect
import sys
sys.setrecursionlimit(10**9)

N = int(input())
A = list(map(int, input().split()))

tree = [[] for i in range(N)]
for i in range(N-1):
  u, v = map(int, input().split())
  tree[u-1].append(v-1); tree[v-1].append(u-1)


ans = [0] * N
ans[0] = 1
INF = 10**10
dp = [INF] * N
dp[0] = A[0]
stack = []
n_stack = []
def dfs(node, par, n):
  global ans
  global dp
  global stack
  children = tree[node]
  for child in children:
    if child == par:
      continue
    num = A[child]
    idx = bisect.bisect_left(dp, num)
    stack.append([idx, dp[idx]])
    n_stack.append(n)
    dp[idx] = num
    n = max(n, idx + 1)
    ans[child] = n
    dfs(child, node, n)
    # 巻き戻し
    idx, num = stack.pop()
    dp[idx] = num
    n = n_stack.pop()

dfs(0, -1, 1)
print(*ans, sep='\n')

Measured memory_bytes: 237396
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 5000100;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
ll COM(ll n,ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// a^n mod を計算する
ll modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

ll dx[8] = { 0,0,-1,1 };
ll dy[8] = { -1,1,0,0 };
ll dp[101010];

//long longしか使わない
//素数は1より大きい
int main() {
	ll n;
	cin >> n;
	vector<ll>cash;
	cash.push_back(1);
	ll six = 6;
	ll nine = 9;
	while (six <= 100000) {
		cash.push_back(six);
		six *= 6;
	}
	while (nine <= 100000) {
		cash.push_back(nine);
		nine *= 9;
	}
	sort(cash.begin(), cash.end());
	ll k = cash.size();
	rep(i, n + 10) {
		dp[i] = INF;
	}
	dp[0] = 0;
	for (ll i = 0;i <= n;++i) {
		for (ll j = 0;j < k;++j) {
			if (i + cash[j] > n)break;
			else {
				dp[i + cash[j]] = min(dp[i + cash[j]], dp[i] + 1);
			}
		}
	}
	cout << dp[n] << endl;
	return 0;
}


Measured memory_bytes: 1024
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join(
            '{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())

uf = UnionFind(N)

for i in range(M):
    A, B = map(int, input().split())
    uf.union(A-1, B-1)

# print(uf.roots())

max_num = 0
for root in uf.roots():
    max_num = max(max_num, uf.size(root))
print(max_num)

Measured memory_bytes: 82612
n = int(input())
a = list(map(int, input().split()))

s1 = 0
SUM = 0
for i in range(len(a)):
    nxt = SUM + a[i]

    # plus
    if i % 2 == 0:
        if nxt > 0:
            SUM = nxt
            ops = 0
        else:
            SUM = 1
            ops = (1 - nxt)
    # minus
    else:
        if nxt < 0:
            SUM = nxt
            ops = 0
        else:
            SUM = -1
            ops = abs(-1 - nxt)

    s1 += ops

s2 = 0
SUM = 0
for i in range(len(a)):
    nxt = SUM + a[i]

    # plus
    if i % 2 == 1:
        if nxt > 0:
            SUM = nxt
            ops = 0
        else:
            SUM = 1
            ops = (1 - nxt)
    # minus
    else:
        if nxt < 0:
            SUM = nxt
            ops = 0
        else:
            SUM = -1
            ops = abs(-1 - nxt)

    s2 += ops

print(min(s1, s2))


Measured memory_bytes: 14464
N, M = gets.split.map(&:to_i)
G = Array.new(N) { Array.new(N, false) }
M.times do
  a, b = gets.split.map(&:to_i).map{|x| x-1}
  G[a][b] = true; G[b][a] = true;
end

count = 0
[*1..N-1].permutation(N-1) do |seq|
  exist = true
  ([0] + seq).each_cons(2) do |a, b|
    exist = false unless G[a][b]
  end
  count += 1 if exist
end
puts count

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


typedef long long ll;


int main(){
    ll W,H,x,y;
    cin>>W>>H>>x>>y;

    int l=0;
    if(x*2==W && y*2==H){
        l=1;
    }
    

    cout<<fixed<<setprecision(9)<<W*H/2.0<<" ";
    cout<<l<<endl;
}


Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
p=get_f

dp=array(N+1,0.0,N+1)
dp[0][0]=1.0
p.each_with_index do|p_,i|
    dp_current,dp_next=dp[i],dp[i+1]
    dp_next[0]=(1-p[i])*dp_current[0]
    0.upto(i).each do|j|
        dp_next[j+1]=dp_current[j]*p_+dp_current[j+1]*(1-p_)
    end
end
puts dp[N][(N/2)+1..N].inject(:+)

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

//省略形
#define rep(i,n) for(auto i=0; i<n ; ++i)
#define REP(i,a,b) for(auto i=a; i<b; ++i)
#define all(v) (v).begin() , (v).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using pii = pair<int , int>;
using pll = pair<long long , long long>;

//よく使う定数
const int INF = 1e9;
const int MOD = 1e9+7;
//逆元
const int INV = 1e9+5;

//UnionFindTree
struct union_find{
  vector<int> data;
  union_find(int size) : data(size , -1) { }

  void merge(int x , int y){
    x = root(x); y = root(y);
    if(x == y) return;
    if(data[y] < data[x]) swap(x , y);
    data[x] += data[y];
    data[y] = x;
    return; 
  }

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

  int root(int x){
    return data[x] < 0 ? x : (data[x] = root(data[x]));
  }

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

//プロトタイプ宣言
void faster(void);
template <class T>
T get_digent(T);
template <class T>
T POW(T , T);
template <class T>
T modpow(T , T , T);
bool is_palindrome(string);

//メモ
//最大公約数:__gcd　|　最小公倍数:__lcm
//回文は反転させて一致すればよい


int main(){
  ll n,k;
  cin >> n >> k;
  n = n%k;
  while((k/2)<n){
    n = abs(n-k);
  }
  cout << n;
}























//同期解除
void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//桁数取得
template <class T>
T get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

//繰り返し自乗法
template <class T>
T POW(T x, T y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} 

//繰り返し自乗法(剰余)
template <class T>
T modpow(T x , T y , T mod){
  if(y == 0) return 1;
  if(y%2 == 1){
    ll temp = modpow(x,y-1,mod);
    return temp*x%mod;
  }
  else{
    ll temp = pow_mod(x,y/2,mod);
    return temp*temp%mod;
  }
}

bool is_palindrome(string s){
    string t(s.rbegin(),s.rend());
    return s == t;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;
const int maxn = 3e5 + 5;
int d[maxn];
int fi(int x) {
    return d[x] == x ? x : d[x] = fi(d[x]);
}
void go() {
    int n, k;
    cin >> n >> k;
    f1(n) {
        d[i] = i;
    }
    int ans = n - 1;
    f(k) {
        int a, b;
        cin >> a >> b;
        a = fi(a);
        b = fi(b);
        if (a ^ b) {
            d[a] = b;
            ans--;
        }
    }
    cout << ans << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }
}

Measured memory_bytes: 4000
#include<bits/stdc++.h>
#define _LIBCPP_DEBUG 0
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;


int main(){

    int N,M; cin>>N>>M;
    priority_queue<ll> pq;

    for (int i = 0; i < N; ++i) {
        ll tmp; cin>>tmp;
        pq.push(tmp);
    }

    for (int i = 0; i < M; ++i) {
        ll tmp = pq.top(); pq.pop();
        tmp /= 2;
        pq.push(tmp);
    }

    ll ans = 0;
    while (!pq.empty()){
        ans += pq.top(); pq.pop();
    }

    cout<<ans<<endl;

    return 0;
}

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

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF (1<<28)
#define int long long
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)

signed main(){
	string s;
	cin>>s;
	if(s.size()==3)
		cout<<s[2]<<s[1]<<s[0]<<endl;
	else cout<<s<<endl;
	return 0;
}

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

//define
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long

//constant
const int MOD = 1000000007;

//typedef
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main()
{
	int n;
	cin >> n;
	vector<int> p(n);
	REP(i, n)
		cin >> p[i];
	vector<int> b(n);
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		a[i] = 1 + i * 3 * 1e4;
	for (int i = 0; i < n; i++)
		b[p[i] - 1] = i - a[p[i] - 1] + 1e8 * 7;
	REP(i, n - 1)
		cout << a[i] << " ";
	cout << a[n - 1] << endl;
	REP(i, n - 1)
		cout << b[i] << " ";
	cout << b[n - 1] << endl;
	return 0;
}

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

int main() {
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector L(N, 0);
  for (int &l : L) cin >> l;

  int ans = INT_MAX;
  int M = pow(4, N);
  for (int bit = 0; bit < M; bit++) {
    int cost = 0, a = 0, b = 0, c = 0;
    for (int i = 0, dig = 1; i < N; i++, dig *= 4) {
      int tmp = bit / dig % 4;
      if (tmp == 1) cost += (a) ? 10 : 0, a += L.at(i);
      if (tmp == 2) cost += (b) ? 10 : 0, b += L.at(i);
      if (tmp == 3) cost += (c) ? 10 : 0, c += L.at(i);
    }
    if (!a || !b || !c) continue;
    cost += abs(A - a) + abs(B - b) + abs(C - c);
    ans = min(ans, cost);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 4028
from collections import defaultdict


def factorize(N):  # 素因数分解
    p = 2
    while p * p <= N:
        if N % p == 0:
            N //= p
            d[p] += 1
        else:
            p += 1
    if N > 1:
        d[N] += 1
    return



n = int(input())
mod = 10 ** 9 + 7

d = defaultdict(int)
for i in range(1, n + 1):
    factorize(i)

ans = 1
for cnt in d.values():
    ans = ans * (cnt + 1) % mod
print(ans)


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;  typedef pair<ll,ll> pii;
typedef vector<int> VI; typedef vector<ll> VL;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
typedef vector<ll> VL;


int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int N; ll K; 
	cin >>N >>K;
	
	VL ct(101010, 0);
	rep(i, N){
		int a,b;
		cin >>a >>b;
		ct[a] += b;
	}
	rep(i, 101000) if(ct[i]>0){
		if(ct[i] >= K){
			cout << i <<"\n";
			return 0;
		}
		K -= ct[i];
	}
	return 0;
}

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

int main()
{
ll n ;
cin >> n ;
ll a , b , c , d ;
cin >> a >> b >> c >> d ;
rep(i,n){
  if(i*c-(n-1-i)*d<=b-a&&b-a<=i*d-(n-1-i)*c){
    cout << "YES" << endl;
    return 0;
  }
}
cout << "NO" << endl;
return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int n, k;
    cin >> n >> k;
    vi b(n);
    rep(i, k) {
        int d;
        cin >> d;
        rep(j, d) {
            int ai;
            cin >> ai;
            --ai;
            b[ai]++;
        }
    }
    int ans = 0;
    rep(i, n) {
        if (b[i]==0) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
use proconio::input;
use itertools::Itertools;

fn main() {
    input! {
        (n, m, q) : (usize, usize, usize),
        cond : [(usize, usize, usize, u64); q]
    }
    let mut res = 0;
    for v in (0..m).combinations_with_replacement(n) {
        let mut score = 0;
        for &c in &cond {
            if v[c.1-1] - v[c.0-1] == c.2 { score += c.3; }
        }
        res = std::cmp::max(res, score);
    }
    println!("{}", res);
}


Measured memory_bytes: 2120
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = [0] * (M)
B = [0] * (M)

for m in range(M):
  A[m], B[m] = map(int, input().split())

dic = [[] for j in range(N)]
for m in range(M):
  dic[A[m]-1].append(H[B[m]-1])
  dic[B[m]-1].append(H[A[m]-1])
ans = 0
for n in range(N):
  if len(dic[n]) == 0:
    ans += 1
  elif H[n] > max(dic[n]):
    ans += 1
print(ans)


Measured memory_bytes: 30760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct app{
  int s,e,c;
  app(){}
  app(int s,int e,int c):s(s),e(e),c(c){}
  bool operator<(const app &a) const{
    return s==a.s?e<a.e:s<a.s;
  }
};
int main(){
  int n;
  while(cin>>n,n){
    vector<app> v;
    for(int i=0;i<n;i++){
      int s,e,c;
      cin>>s>>e>>c;
      v.push_back(app(s,e,c));
    }
    sort(v.begin(),v.end());
    int dp[2][400][400],ans=0;
    memset(dp,0,sizeof(dp));
    for(int i=0;i<(int)v.size();i++){
      memset(dp[1],0,sizeof(dp[1]));
      for(int j=0;j<v[i].s;j++){
	for(int k=0;k<400;k++){
	  dp[1][j][k]=max(dp[1][j][k],dp[0][j][k]);
	  dp[1][k][j]=max(dp[1][k][j],dp[0][k][j]);
	  dp[1][v[i].e][k]=max(dp[1][v[i].e][k],dp[0][j][k]+v[i].c);
	  dp[1][k][v[i].e]=max(dp[1][k][v[i].e],dp[0][k][j]+v[i].c);
	  //cout<<dp[j][k]<<":"<<dp[v[i].e][k]<<" "<<v[i].e<<" "<<k<<" "<<j<<endl;
	  //cout<<dp[k][j]<<":"<<dp[k][v[i].e]<<" "<<k<<" "<<v[i].e<<" "<<j<<endl;
	}
      }
      for(int j=0;j<400;j++)
	for(int k=0;k<400;k++)
	  dp[0][j][k]=max(dp[0][j][k],dp[1][j][k]),ans=max(ans,dp[0][j][k]);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 4284
import sys
S = input()

if not S.islower():sys.exit()
if not ( 3 <= len(S) <= 99 and len(S) % 2 == 1 ): sys.exit()

# whole check
first = int((len(S)-1)/2)
F = S[0:first]
last = int((len(S)+3)/2)
L = S[last-1:]
condition = 0
if S == S[::-1]:
    condition += 1
if F == F[::-1]:
    condition += 1
if L == L[::-1]:
    condition += 1

print('Yes') if condition == 3 else print('No')

Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int ans = 0;
    for (int i = 0; i < 5; ++i) {
        int x;
        cin >> x;
        ans ^= x ^ (i + 1);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
import java.util.*;
import java.util.Scanner ; 
import java.math.BigInteger;

public class Main {
    public static void main(String[] args) {
        int t,n1,n2,n3;
        int [] a = new int[3];
        Scanner sc = new Scanner(System.in);
        t = sc.nextInt();
        while(t>0){
            t--;
            n1 = sc.nextInt();
            n2 = sc.nextInt();
            n3 = sc.nextInt();
            a[0] = n1 ; a[1] = n2 ; a[2]=n3;
            Arrays.sort(a);
            System.out.println((a[2]*a[2]==a[0]*a[0]+a[1]*a[1])? "YES" : "NO" );
        }
    }
}

Measured memory_bytes: 23392
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  string S;
  cin >> A >> B >> S;
  string ans = "Yes";
  for(int i = 0; i < S.size(); i++){
    if(i == A) continue;
    if(S.at(A) == '-' && S[i] != '-'){
      continue;
    }
    ans = "No";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
signed main(){
  int a,b;
  cin>>a>>b;
  if(a>b)
    cout<<a-1<<endl;
  else
    cout<<a<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,d,n;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(a*b>=c*d){
		n=a*b;
	}
	if(a*b<c*d){
		n=c*d;
	}
	printf("%d\n",n);
	return 0;
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline
from collections import *

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def factorize(n):
    fct = []
    
    for i in range(2, int(n**0.5)+1):
        c = 0
        
        while n%i==0:
            n //= i
            c += 1
            
        if c>0:
            fct.append((i, c))
    
    if n>1:
        fct.append((n, 1))
    
    return fct

A, B = map(int, input().split())
fct = factorize(gcd(A, B))
ans = 1+len(fct)
print(ans)

Measured memory_bytes: 38512
#include <iostream>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define lli long long int
using namespace std;
#define S second
#define F first
#define pb push_back 
#define M1 1000000007
#define M2 998244353
#define plli pair<lli,lli>
#define setit set<lli>::iterator seti
#define mapit map<lli,lli> ::iterator mapi
#define MP make_pair
#define MT make_tuple
// map      iterator->first  iterator.first
// map      mp[key]=value
// set      *s.begin()
// vector   v[j]=value
// pair     p.first p.second
// vector of pairs v[j].first v[j].second
// tuple    get<index>(tuple_name)
// vector of tuples get<index>(v[j])  sort(v.begin(),v.end())
//priority queue .top() .pop() .push()
// __gcd(x,y)
#define fr(j,a,b) for(j=a;j<b;j++)


int power(int x, unsigned int y, int p)  
{    int res = 1;    
     x = x % p;
     if (x == 0) return 0;
     while (y > 0)  
     {  if (y & 1)  
        res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
     }  
    return res;  
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lli t,i,m,j,n,x,k,f,g,q,r,w;
    cin>>n;
    x=0;
    for(i=1;i<=n;i++){
        if(i%3!=0&&i%5!=0){
            x=x+i;
        }
    }
    cout<<x;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <cctype>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
typedef string::const_iterator State;
typedef long long ll;
int c[4];

ll expression(State &begin);
ll number(State &begin);
ll factor(State &begin);
ll term1(State &begin);
ll term2(State &begin);


ll number(State &begin){
	ll ret=0;
	while(isdigit(*begin)){
		ret*=10;
		ret+=*begin-'0';
		begin++;
	}
	return ret;
}

ll term2(State &begin){
	ll ret=factor(begin);
	while(1){
		if(*begin=='+' && c[0]==2){
			begin++;
			ret+=factor(begin);
		}else if(*begin=='-' && c[1]==2){
			begin++;
			ret-=factor(begin);
		}else if(*begin=='*' && c[2]==2){
			begin++;
			ret*=factor(begin);
		}else break;
	}
	return ret;
}

ll term1(State &begin){
	ll ret=term2(begin);
	while(1){
		if(*begin=='+' && c[0]>=1){
			begin++;
			ret+=term2(begin);
		}else if(*begin=='-' && c[1]>=1){
			begin++;
			ret-=term2(begin);
		}else if(*begin=='*' && c[2]>=1){
			begin++;
			ret*=term2(begin);
		}else break;
	}
	return ret;
}

ll factor(State &begin){
	if(*begin=='('){
		begin++;
		ll ret=expression(begin);
		begin++;
		return ret;
	}else return number(begin);
}

ll expression(State &begin){
	ll ret=term1(begin);
	while(1){
		if(*begin=='+'){
			begin++;
			if(c[0]==0)ret+=term1(begin);
			if(c[0]>=1)ret+=term2(begin);
		}else if(*begin=='-'){
			begin++;
			if(c[1]==0)ret-=term1(begin);
			if(c[1]>=1)ret-=term2(begin);
		}else if(*begin=='*'){
			begin++;
			if(c[2]==0)ret*=term1(begin);
			if(c[2]>=1)ret*=term2(begin);
		}else break;
	}
	return ret;
}


int main(void){
	string str;
	cin >> str;
	ll res=0;
	for(int i=0;i<3;i++){
		c[0]=i;
		for(int j=0;j<3;j++){
			c[1]=j;
			for(int k=0;k<3;k++){
				c[2]=k;
				State begin=str.begin();
				ll re=expression(begin);
				if(i+j+k==0)res=re;
				else res=max(res,re);
			}
		}
	}
	printf("%lld\n",res);
	return 0;
}

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


int main(){
    int n; cin >> n;
    vector<int> a(n+1); rep(i,n) cin >> a[i+1];
    vector<int> b(n+1); //箱に玉を入れたかどうか
    int j;
    stack<int> memo;
    int ansm = 0;
    for(int i = n; i >= 1; i--){
        if(i >= n/2 + 1){
            if(a[i]){
                b[i] = 1;
                memo.push(i);
                ansm++;
            }else b[i] = 0;
        }else{
            j = 2*i;
            int cnt = 0;
            while(n >= j){
                if(b[j] == 1) cnt++;
                j += i;
            }
            if(cnt%2 != a[i]){
                b[i] = 1;
                memo.push(i);
                ansm++;
            }else b[i] = 0;
        }
    }
    cout << ansm << endl;
    while(!memo.empty()){
        cout << memo.top() << " ";
        memo.pop();
    }
}

Measured memory_bytes: 3072
function Main(input) {
  input = input.split("\n");
  const N = parseInt(input[0],10);
  let ans = 0;
  for (var n = 0; n <= N; n++) {
    if (n % 2 === 0) continue;
    let count = 0;
    for (var i = 1; i <= n; i++) {
      if (n % i === 0) {
        count++;
      }
    }
    if (count === 8) {
      ans++;
    }
  }
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 30556
X, K, D = [int(n) for n in input().split()]
if X < 0:
    X = -X

if X - K * D >= 0:
    print(X - K * D)
else:
    R = X % D
    C = (X - R) // D
    if (K - C) % 2 == 0:
        print(R)
    else:
        print(D - R)
        



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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  
  else if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  
  else {
    cout << "Right" << endl;
  }
  
}  


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

const long long MOD = 1000000007;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;
typedef long long ll;

int N, X, Y, Z;
const int mask = (1<<16) - 1;
int memo[42][(1<<16)];
int zyx[3];

bool have_xyz(int bit, int num){
    if(Z - num < 0) return false;
    zyx[0] = Z - num;
    zyx[1] = Y;
    zyx[2] = X;
    int idx = (Z - num == 0) ? 1 : 0;
    int len = 0;
    for(int i=0;i<16;i++){
        len++;
        if((bit>>i)&1){
            zyx[idx] -= len;
            if(zyx[idx] < 0){
                break;
            }else if(zyx[idx] == 0){
                if(idx == 2){
                    return true;
                }else{
                    idx++;
                }
            }
            len = 0;
        }
    }
    return false;
}

int dfs(int p, int bit){
    if(p == N) return 1;
    if(memo[p][bit] != -1) return memo[p][bit];
    ll ret = 0;
    for(int i=1;i<=10;i++){
        if(have_xyz(bit, i)) continue;
        int nbit = (bit << i) | (1 << (i-1));
        nbit &= mask;
        ret = (ret + dfs(p+1, nbit)) % MOD;
    }
    memo[p][bit] = ret;
    return ret;
}

int main(){
    cin >> N >> X >> Y >> Z;
    memset(memo, -1, sizeof(memo));
    ll ret = dfs(0, 0);
    ll ans = 1;
    for(int i=1;i<=N;i++){
        ans = (ans * 10) % MOD;
    }
    ans = (MOD + ans - ret) % MOD;
    cout << ans << endl;
    return 0;
}


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

#define f(i,a,b) for (int i = a; i < b; i++)

const int mxn = 2e5;

int ans = -1;
int dsu[mxn],sz[mxn];
bool active[mxn];
void init() {
	f(i,0,mxn) dsu[i] = i, sz[i] = 1, active[i] = 0;
}
int root(int v) { return dsu[v] = dsu[v] == v ? v : root(dsu[v]); }
void merge(int v, int w) {
	active[v] = active[w] = 1;
	v = root(v); w = root(w);
	if (v == w) return;
	if (sz[v] < sz[w])
		swap(v,w);
	sz[v] += sz[w]; dsu[w] = v;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif

	int n; cin >> n;
	n++;
	int a[n], b[n];

	f(i,1,n) cin>>a[i];	
	f(i,1,n) cin>>b[i];
	a[0] = b[0] = 0;
	f(i,1,n) a[0]^=a[i];
	f(i,1,n) b[0]^=b[i];

	int c[n],d[n];
	f(i,0,n) c[i] = a[i], d[i] = b[i];
	sort(c,c+n); sort(d,d+n);

	f(i,0,n) if (c[i] != d[i]) {
		cout << -1 << endl;
		return 0;
	}
	
	map<int,int> cp;
	f(i,0,n) cp[a[i]]=0;
	int t = 0;
	for (pair<int,int> pp : cp)
		cp[pp.first] = t++;
	f(i,0,n) a[i] = cp[a[i]],b[i]=cp[b[i]];

	init();
	active[a[0]] = active[b[0]] = 1;
	f(i,1,n) if (a[i] != b[i]) { 
		ans++;
		merge(a[i],b[i]);
	}
	f(i,0,mxn) if (active[i] && dsu[i] == i)
		ans++;
	cout << ans << endl;

#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	
	return 0;
}



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

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 = 1ll << 60;

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;}

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

    int n;
    cin >> n;
    string s[n];
    rep(i, 0, n) cin >> s[i];

    int a = 0, b = 0, rsl = 0, tmp = 0;
    rep(i, 0, n) {
        int si_length = s[i].length();
        if(s[i][si_length - 1] == 'A') a++;
        if(s[i][0] == 'B') b++;
        if(s[i][si_length - 1] == 'A' and s[i][0] == 'B') tmp++;
        rep(j, 0, si_length - 1) {
            if(s[i][j] == 'A' and s[i][j + 1] == 'B') rsl++;
        }
    }

    if(a > 0 and b > 0) {
        if(a == tmp and tmp == b) rsl += a - 1;
        else rsl += min(a, b);
    }
    cout << rsl << endl;
}


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

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

Measured memory_bytes: 3600
# coding: utf-8
# Your code here!
a,b,c,x,y = map(int,input().split())
c *= 2
answer = 0
if x < y:
    answer += c*x + b*(y - x)
    if a + b < c:
        print(a*x+b*y)
    else:
        if b > c:
            print(c*y)
        else:
            print(answer)
elif x > y:
    answer += a*(x-y)+c*y
    if a + b < c:
        print(a*x+b*y)
    else:
        if a > c:
            print(c*x)
        else:
            print(answer)
else:
    answer += c*x
    if a + b < c:
        print(a*x+b*y)
    else:
        print(answer)

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

int main() {
  int n;
  cin >> n;
  ll v[100010][3] = {};
  for (int i = 0; i < n; i++) cin >> v[i][0] >> v[i][1] >> v[i][2];

  ll k[100010][3] = {};
  for (int i = 0; i < 3; i++) k[0][i] = v[0][i];  // 1段目に入れる

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 3; j++) {
      if (j == 0) k[i][0] = max(k[i - 1][1], k[i - 1][2]);
      if (j == 1) k[i][1] = max(k[i - 1][0], k[i - 1][2]);
      if (j == 2) k[i][2] = max(k[i - 1][0], k[i - 1][1]);
      k[i][j] += v[i][j];
    }
  }

  cout << *max_element(k[n], k[n + 1]) << endl;
}


Measured memory_bytes: 4992
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define ALL(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
int per(int n, int r) {
	r = n - r;
	int sum = 1;
	int i;
	for (i = n; i >= r + 1; i--)sum *= i;
	return sum;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};

signed main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (c > a) {
		if (c > a + b) {
			cout << 0 << ' ' << 0 << endl;
		}
		else {
			cout << 0 << ' ' << a + b - c << endl;
		}
	}
	else {
		cout << a - c << ' ' << b << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];

void yes(){
   cout<<"Yes"<<endl;
   //exit (0);
}
void no(){
   cout<<"No"<<endl;
   //exit (0);   
}

int32_t main(){_
      
      int k;
   cin>>n>>k;

   for (int i = 1; i <= n; ++i)
   {
      cin>>a[i];
   }

   for (int i = k+1; i <= n; ++i)
   {
      if (a[i] > a[i-k]){
         yes();
      }
      else{
         no();
      }
   }

   
   

   return 0;
}

Measured memory_bytes: 5216
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,z,w;
  cin>>n>>z>>w;
  vector<int>a(n);
  a.resize(n);
  rep(i,n)cin>>a[i];
  if(n==1){cout<<abs(w-a[n-1])<<endl;return 0;}
  cout<<max(abs(w-a[n-1]),abs(a[n-2]-a[n-1]))<<endl;



  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX_N=200005;
int A[MAX_N];
bool B[MAX_N];
int n;
int val(int pos)
{
	if(B[pos]!=B[pos+1])return n;
	return min(abs(pos-n),abs(pos+1-n));
}
bool check(int m)
{
//	cout<<"check:"<<m<<endl;
	memset(B,false,sizeof(B));
	for(int i=1;i<2*n;i++)if(A[i]>=m)B[i]=true;
	int pos=0,mi=n;
	for(int i=1;i<2*n-1;i++)
	{
		if(val(i)<mi)
		{
			mi=val(i);
			pos=i;
		}
	}
/*	for(int i=1;i<2*n;i++)cout<<B[i]<<" ";
	cout<<endl;*/
	if(pos==0)return n%2?B[n]:!B[n];
	else return B[pos];
}
int main()
{
	cin>>n;
	for(int i=1;i<2*n;i++)cin>>A[i];
	int lb=0,ub=2*n-1;
	while(ub-lb>1)
	{
		int mid=(lb+ub)/2;
		if(check(mid))lb=mid;
		else ub=mid;
	}
	cout<<lb<<endl;
	return 0;
}

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

const int Inf = 2000000007;

int a, b, c, x, y;
int res = Inf;

int main()
{
	scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);
	for (int i = 0; i <= x || i <= y; i++) {
		int cand = i * 2 * c + max(0, (x - i)) * a + max(0, (y - i)) * b;
		res = min(res, cand);
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;


int main() {
//    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    ll n;
    cin >> n;
    ll a[n];
    ll m = INT_MAX;
    ll neg = 0;
    vector<ll> nega;
    ll ps = 0, ns = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] >= 0) {
            m = min(m, a[i]);
            ps += a[i];
        }

        if (a[i] < 0) {
            neg++;
            nega.pb(-a[i]);
            ns += abs(a[i]);
        }
    }

    if (neg % 2 == 0) {
        ll ans = 0;
        for (ll e : a) {
            ans += abs(e);
        }
        cout << ans;
    }

    else {
        sort(nega.begin(), nega.end(), greater<ll>());
        ll last = nega.back();
        nega.pop_back();
        for (ll e : nega) {
            ps += e;
        }

        if (m < last) {
            ps += last - 2 * m;
        }

        else {
            ps -= last;
        }

        cout << ps;
    }



}

Measured memory_bytes: 2040
fun main(args: Array<String>) {
    val s = readLine()!!
    var a = 0
    var sl = s.length
    for (i in 0 until sl){
        var na = 0
        for (j in i until sl){
            if(s[j] == 'A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T'){
                na += 1
            }
            else {
                a = Math.max(a, na)
                na = 0
            }
        }
        a = Math.max(a, na)
    }
    println(a)
}

Measured memory_bytes: 33508
from collections import Counter

N = int(input())
A = Counter(map(int, input().split()))

if len(A.keys()) >= 3:
    print('No')
    exit()

if len(A.keys()) == 1:
    p = list(A.keys())[0]
    print('Yes' if 2 * p <= N or p == N - 1 else 'No')
    exit()

p1, p2 = sorted(A.keys())
print('Yes' if p2 - p1 == 1 and (A[p1] + 1) <= p2 <= (A[p1] + A[p2] // 2) else 'No')


Measured memory_bytes: 22636
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;


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

    ll x = n / (a + b) * a;
    ll y = min(n - n / (a + b) * (a + b), a);

    cout << x + y << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
    int N,K;
    std::cin>>N>>K;
    int ans=1;
    int k=K-1;
    for(int i=0;i<N;++i){
        if(i==0)ans*=K;
        else ans*=k;
    }
    std::cout<<ans<<std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
char m[100][100];
int main()
{
	int a, b, c, x;
	scanf("%d%d%d%d", &a, &b, &c, &x);
	int r = 0;
	for (int i = 0; i <= a; i++)for (int j = 0; j <= b; j++)for (int k = 0; k <= c; k++)r += (x == i * 500 + j * 100 + k * 50);
	printf("%d\n", r);
}

Measured memory_bytes: 384
package main

import "os"
import "fmt"
import "strconv"
import "bufio"
import "strings"


func solve(h int64, w int64, grid []string) int64 {
    var mod int64 = 1e9+7
    // dp := make([][]int64, h)
    // for i := int64(0); i < h; i++ {
    //     for j := int64(0); j < w; j++ {
    //         dp[i] = make([]int64, w)
    //     }
    // }
    dp := [1000][1000]int64{}

    dp[0][0] = 1
    for i := int64(0); i < h; i++ {
        for j := int64(0); j < w; j++ {
            if i == 0 && j == 0 {
                continue
            }
            if i-1 >= 0 && grid[i-1][j] == '.' {
                dp[i][j] += dp[i-1][j]
            }
            if j-1 >= 0 && grid[i][j-1] == '.' {
                dp[i][j] += dp[i][j-1]
            }
            dp[i][j] = dp[i][j] % mod
        }
    }
    return dp[h-1][w-1]
}
func main() {
    scanner := bufio.NewScanner(os.Stdin)
    var h int64 = 0
    var w int64 = 0
    var i int64 = 0
    var grid []string
    for scanner.Scan() {
        if i > 0 && i > h {
            break
        }
        if i == 0 {
            strs := strings.Split(scanner.Text(), " ")
            h, _ = strconv.ParseInt(strs[0], 10, 64)
            w, _ = strconv.ParseInt(strs[1], 10, 64)
        } else {
            if i == 1 {
                grid = make([]string, h)
            }
            grid[i-1] = scanner.Text()
        }
        i++
    }

    fmt.Println(solve(h,w,grid))
}

Measured memory_bytes: 13952